aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2023-02-01 12:00:24 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2023-02-01 12:00:24 +0100
commite0babeaf88b2a434b10ffb65824440b1adfaa151 (patch)
tree7ec40bc44f1c9ed72f6f455c28dd58a5d373a370
parentd9818df8791730130adc5349e863b35de0e1c351 (diff)
Improve management of engines tabs
-rw-r--r--src/MainWindow.cpp11
-rw-r--r--src/engine_tab/EngineTab.cpp1
-rw-r--r--src/engine_tab/EngineTab.hpp1
-rw-r--r--src/ochess.cpp8
-rw-r--r--src/ochess.hpp2
5 files changed, 22 insertions, 1 deletions
diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp
index 27eda12..3a67975 100644
--- a/src/MainWindow.cpp
+++ b/src/MainWindow.cpp
@@ -120,9 +120,18 @@ void MainWindow::OnMenuItemClick(wxCommandEvent &event) {
wxMenuItemList items = manageMenu->GetMenuItems();
for (wxMenuItem *item : items) {
if (item->GetId() == id) {
+ std::uint32_t engine_id=item->GetId()-100;
+ // Check if not already opened
+ for(auto i: wxGetApp().ListTabInfos()){
+ if(i->type==TabInfos::ENGINE && i->GetEngineId()==engine_id){
+ wxGetApp().FocusOnTab(i);
+ return;
+ }
+ }
+ // Open engine configuration tag:
wxLogDebug("Selected %s", item->GetItemLabel());
EngineTab *et = new EngineTab((wxWindow *)notebook,
- item->GetId()-100);
+ engine_id);
AddPage(et,et);
}
}
diff --git a/src/engine_tab/EngineTab.cpp b/src/engine_tab/EngineTab.cpp
index 345a650..4c3f82d 100644
--- a/src/engine_tab/EngineTab.cpp
+++ b/src/engine_tab/EngineTab.cpp
@@ -38,6 +38,7 @@ EngineTab::EngineTab(wxWindow *parent, std::uint32_t id)
SetLabel(name);
engine_name->SetValue(name);
engine_location->SetValue(conf->Read(confGroup + "/path"));
+ engine_id=id;
CONFIG_CLOSE(conf);
// Load existing configuration
diff --git a/src/engine_tab/EngineTab.hpp b/src/engine_tab/EngineTab.hpp
index 975ddf6..fc90436 100644
--- a/src/engine_tab/EngineTab.hpp
+++ b/src/engine_tab/EngineTab.hpp
@@ -21,6 +21,7 @@ public:
void ApplyPreferences() {}
std::shared_ptr<Game> GetGame() { return nullptr; }
std::shared_ptr<GameBase> GetBase() { return nullptr; }
+ std::uint32_t GetEngineId() { return engine_id; };
void OnSave(wxCommandEvent &event);
void OnDelete(wxCommandEvent &event);
}; \ No newline at end of file
diff --git a/src/ochess.cpp b/src/ochess.cpp
index 5ef3522..62a5c04 100644
--- a/src/ochess.cpp
+++ b/src/ochess.cpp
@@ -51,6 +51,14 @@ std::vector<TabInfos *> MyApp::ListTabInfos() {
return (tinfos);
}
+void MyApp::FocusOnTab(TabInfos * toFocus){
+ wxAuiNotebook *notebook = ((MainWindow *)this->GetTopWindow())->notebook;
+ for (int i = 0; i < notebook->GetPageCount(); i++) {
+ if(dynamic_cast<TabInfos *>(notebook->GetPage(i))->id== toFocus->id)
+ notebook->SetSelection(i);
+ }
+}
+
Openings &MyApp::GetBook() { return Book; }
void MyApp::NewGame(TabInfos *tabsrc, std::shared_ptr<Game> g) {
diff --git a/src/ochess.hpp b/src/ochess.hpp
index d5b7c16..6317c2f 100644
--- a/src/ochess.hpp
+++ b/src/ochess.hpp
@@ -64,6 +64,7 @@ public:
virtual void ApplyPreferences() {};
virtual std::shared_ptr<Game> GetGame() = 0;
virtual std::shared_ptr<GameBase> GetBase() = 0;
+ virtual std::uint32_t GetEngineId() { return 0; };
};
@@ -76,6 +77,7 @@ public:
Openings Book;
virtual bool OnInit();
std::vector<TabInfos *> ListTabInfos();
+ void FocusOnTab(TabInfos *);
void NewGame(TabInfos *tabsrc,std::shared_ptr<Game> g);
void NewGame(std::shared_ptr<Game> g);
Openings& GetBook();