From 53090ab2a300c413257ae9aa8b5b6592a029c9b7 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Tue, 27 Dec 2022 17:35:17 +0100 Subject: Cleaning code --- src/base_tab/BaseTab.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/base_tab/BaseTab.cpp') diff --git a/src/base_tab/BaseTab.cpp b/src/base_tab/BaseTab.cpp index 6866da1..fada2b2 100644 --- a/src/base_tab/BaseTab.cpp +++ b/src/base_tab/BaseTab.cpp @@ -8,8 +8,7 @@ BaseTab::BaseTab(wxFrame *parent, std::string base_file) base=OpenDatabase(base_file); // Games tab - games_tab=new BaseGameTab((wxFrame *)notebook,base,this); - glm=games_tab->glm; + games_tab=new BaseGameTab((wxFrame *)notebook,base); notebook->AddPage(games_tab, "Games list",true); // true for selecting the tab // Import tab import_tab=new BaseImportTab((wxFrame *)notebook,base,this); @@ -22,21 +21,22 @@ BaseTab::BaseTab(wxFrame *parent, std::string base_file) Refresh(); // Bindings - this->Bind(OPEN_GAME_EVENT, &BaseTab::OnOpenGame, this, wxID_ANY); this->Bind(wxEVT_BUTTON, &BaseTab::OnSave, this, ID_SAVE_BUTTON); + this->Bind(wxEVT_LIST_ITEM_ACTIVATED, &BaseTab::OnOpenGame, this, ID_TABGAMES_GAME_LIST); } - -void BaseTab::OnOpenGame(wxCommandEvent &event){ - std::shared_ptr *g = (std::shared_ptr*)event.GetClientData(); - this->game=*g; - - // Ask MainFrame to open a new game - // TODO: Simplify that is, use wxWidget main app to do it - wxCommandEvent newGameEvent(NEW_GAME_EVENT, GetId()); - newGameEvent.SetEventObject(this); - newGameEvent.SetClientData((TabInfos*)this); - ProcessEvent(newGameEvent); +void BaseTab::OnOpenGame(wxListEvent &event){ + long gameid=std::stol(event.GetItem().GetText().ToStdString()); + std::shared_ptr g = games_tab->OpenGame(gameid,event.GetIndex()); + if(g){ + game=g; + // Ask MainFrame to open a new game + // TODO: Simplify that is, use wxWidget main app to do it + wxCommandEvent newGameEvent(NEW_GAME_EVENT, GetId()); + newGameEvent.SetEventObject(this); + newGameEvent.SetClientData((TabInfos*)this); + ProcessEvent(newGameEvent); + } } void BaseTab::Refresh(){ -- cgit v1.2.3