From e5f2b524b4ca055803105995ffa37a7a1ecd5352 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Wed, 1 Feb 2023 21:27:42 +0100 Subject: [PATCH] Improve menus id management --- src/MainWindow.cpp | 12 +++++++----- src/MainWindow.hpp | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index c11e25b..9bbdd00 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -17,7 +17,7 @@ wxDEFINE_EVENT(CLOSE_LINKED_TAB, wxCommandEvent); MainWindow::MainWindow() : MainFrame(NULL, wxID_ANY, "OChess: The Open Chess software", wxDefaultPosition, wxSize(1500, 1000)), - prefsEditor(nullptr) { + prefsEditor(nullptr), engine_count(0) { SetStatusText("OChess v"+std::string(OCHESS_VERSION)); /// File menu @@ -43,7 +43,8 @@ MainWindow::MainWindow() wxCommandEvent dummy(REFRESH_ENGINE_LIST, GetId()); OnRefreshEngineList(dummy); - menu_help->Append(8, "About", "OChess Informations"); + // Help menu + menu_help->Append(wxID_ABOUT, "About", "OChess Informations"); Bind(wxEVT_AUINOTEBOOK_PAGE_CHANGED, &MainWindow::OnPageChange, this, wxID_ANY); @@ -115,10 +116,10 @@ void MainWindow::OnCloseTabLinkedTo(wxCommandEvent &event){ } void MainWindow::OnMenuItemClick(wxCommandEvent &event) { - std::uint32_t id = event.GetId(); + int id = event.GetId(); if (id == wxID_EXIT) { Close(true); - } else if (id >= 100) { // Engine from manage menu + } else if (id >= 100 && id <=(100+engine_count)) { // Engine from manage menu wxMenuItemList items = manageMenu->GetMenuItems(); for (wxMenuItem *item : items) { if (item->GetId() == id) { @@ -173,7 +174,7 @@ void MainWindow::OnMenuItemClick(wxCommandEvent &event) { } } else if (id == 7) { // Create new engine NewEngine(); - } else if (id == 8) { // Create new engine + } else if (id == wxID_ABOUT) { // Create new engine ShowAbout(); } } @@ -196,6 +197,7 @@ void MainWindow::OnRefreshEngineList(wxCommandEvent &event) { manageMenu->Append(100 + id, engine_name, "Configure " + engine_name); id++; } while (conf->GetNextGroup(engine_id, index)); + engine_count=id; } CONFIG_CLOSE(conf); ApplyPreferences(); // Propagate informations to the tabs that require it diff --git a/src/MainWindow.hpp b/src/MainWindow.hpp index 8c541dd..e59c7ec 100644 --- a/src/MainWindow.hpp +++ b/src/MainWindow.hpp @@ -17,6 +17,7 @@ wxDECLARE_EVENT(CLOSE_LINKED_TAB, wxCommandEvent); class MainWindow : public MainFrame { wxPreferencesEditor *prefsEditor; wxMenu *manageMenu; + int engine_count; void OnClose(wxCloseEvent &e); void NewGame(bool useFen);