From e601902dd5a9f023594fef6a0f4995e59b4d9a0e Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Sat, 26 Feb 2022 20:34:42 +0100 Subject: Improve engine managemen --- src/engine_tab/EngineTab.cpp | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) (limited to 'src/engine_tab/EngineTab.cpp') diff --git a/src/engine_tab/EngineTab.cpp b/src/engine_tab/EngineTab.cpp index ae9b447..ca2880f 100644 --- a/src/engine_tab/EngineTab.cpp +++ b/src/engine_tab/EngineTab.cpp @@ -1,20 +1,27 @@ #include "EngineTab.hpp" -EngineTab::EngineTab(wxWindow *parent, uciadapter::UCI *engine,std::string engine_path_or_name) +EngineTab::EngineTab(wxWindow *parent, uciadapter::UCI *engine, + std::string engine_path_or_name) : EngineTabBF(parent), TabInfos(TabInfos::ENGINE), enginePath(engine_path_or_name), engine(engine) { SetLabel("New Engine"); engine_location->SetValue(engine_path_or_name); - confGroup = "engines/bob"; CONFIG_OPEN(conf); - conf->DeleteGroup(confGroup); - bool configExists = conf->HasGroup(confGroup); - conf->Write(confGroup + "/path", wxString(engine_path_or_name)); - CONFIG_CLOSE(conf); - if (!configExists) { - InitConfiguration(); + // conf->DeleteGroup(confGroup); + engineName = "NewEngine"; + confGroup = "engines/" + engineName; + std::uint32_t key = 2; + while (conf->HasGroup(confGroup)) { + engineName = "NewEngine" + std::to_string(key); + confGroup = "engines/" + engineName; + key++; } + engine_name->SetValue(engineName); + + // conf->Write(confGroup + "/path", wxString(engine_path_or_name)); + CONFIG_CLOSE(conf); + InitConfiguration(); // Build wxPropertyGrid according to engine configuration CONFIG_OPEN(conf2); @@ -43,10 +50,27 @@ EngineTab::EngineTab(wxWindow *parent, uciadapter::UCI *engine,std::string engin CONFIG_CLOSE(conf2); Bind(wxEVT_BUTTON, &EngineTab::OnSave, this, ENGINE_SAVE_CONF_BUTTON); + Bind(wxEVT_BUTTON, &EngineTab::OnDelete, this, ENGINE_DELETE_CONF_BUTTON); +} + +void EngineTab::OnDelete(wxCommandEvent &event) { + CONFIG_OPEN(conf); + conf->DeleteGroup(confGroup); + CONFIG_CLOSE(conf); + + wxCommandEvent closeTabEvent(CLOSE_TAB_EVENT, GetId()); + closeTabEvent.SetEventObject(this); + ProcessEvent(closeTabEvent); } void EngineTab::OnSave(wxCommandEvent &event) { CONFIG_OPEN(conf2); + wxString new_engine_name = engine_name->GetValue(); + if (new_engine_name != engineName) { + conf2->RenameGroup(confGroup, "engines/" + new_engine_name); + engineName = new_engine_name; + confGroup = "engines/" + engineName; + } long index; std::string optsPath = confGroup + "/options"; conf2->SetPath(optsPath); -- cgit v1.2.3