Improve menus id management

This commit is contained in:
Loic Guegan 2023-02-01 21:27:42 +01:00
parent a575fea2bc
commit e5f2b524b4
2 changed files with 8 additions and 5 deletions

View file

@ -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

View file

@ -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);