From 32fdf9272e1a94f8c51274a1758f4feae555341a Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Tue, 27 Dec 2022 18:33:21 +0100 Subject: [PATCH] Cleaning code --- src/MainWindow.cpp | 7 ------- src/MainWindow.hpp | 3 +-- src/base_tab/BaseGameTab.cpp | 7 +++++-- src/base_tab/BaseTab.cpp | 7 +------ src/ochess.cpp | 6 ++++++ src/ochess.hpp | 1 + 6 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index cc83f5b..6fb73c3 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -48,7 +48,6 @@ MainWindow::MainWindow() Bind(wxEVT_AUINOTEBOOK_PAGE_CHANGED, &MainWindow::OnPageChange, this, wxID_ANY); Bind(REFRESH_TAB_TITLE, &MainWindow::OnRefreshTabTitle, this, wxID_ANY); - Bind(NEW_GAME_EVENT, &MainWindow::OnNewGame, this, wxID_ANY); Bind(wxEVT_CLOSE_WINDOW, &MainWindow::OnClose, this); Bind(CLOSE_TAB_EVENT, &MainWindow::OnCloseTabEvent, this, wxID_ANY); Bind(wxEVT_MENU, &MainWindow::OnMenuItemClick, this, wxID_ANY); @@ -234,12 +233,6 @@ void MainWindow::NewGame(bool useFen) { } } -void MainWindow::OnNewGame(wxCommandEvent &event) { - TabInfos *tab = (TabInfos*)event.GetClientData(); - TabInfos *i=NewGame(tab->GetGame()); - i->Link(tab); -} - void MainWindow::OnPageChange(wxAuiNotebookEvent &event) { TabInfos *infos = dynamic_cast(notebook->GetCurrentPage()); if (infos->type != TabInfos::GAME) { diff --git a/src/MainWindow.hpp b/src/MainWindow.hpp index 866a98b..567ce3a 100644 --- a/src/MainWindow.hpp +++ b/src/MainWindow.hpp @@ -19,11 +19,9 @@ class MainWindow : public MainFrame { void OnClose(wxCloseEvent &e); void NewGame(bool useFen); - void OnNewGame(wxCommandEvent &event); void OpenFile(); void OnPageChange(wxAuiNotebookEvent &event); void OnRefreshTabTitle(wxCommandEvent &event); - TabInfos* NewGame(std::shared_ptr game); void OpenSettings(); void NewEngine(); void OnCloseTabEvent(wxCommandEvent &event); @@ -34,5 +32,6 @@ class MainWindow : public MainFrame { void AddPage(wxWindow* window, TabInfos* infos); public: MainWindow(); + TabInfos* NewGame(std::shared_ptr game); void ApplyPreferences(); }; \ No newline at end of file diff --git a/src/base_tab/BaseGameTab.cpp b/src/base_tab/BaseGameTab.cpp index cc2cf3d..54c836f 100644 --- a/src/base_tab/BaseGameTab.cpp +++ b/src/base_tab/BaseGameTab.cpp @@ -6,14 +6,17 @@ BaseGameTab::BaseGameTab(wxFrame *parent, std::shared_ptr base) glm=std::make_shared(game_list); Reset(base); + search_terms->SetHint("e.g: Paul Morphy"); this->Bind(wxEVT_BUTTON, &BaseGameTab::OnDelete, this, ID_DELETE_BUTTON); this->Bind(wxEVT_BUTTON, &BaseGameTab::OnApplyFilter, this, ID_APPLY_FILTER_BUTTON); this->Bind(wxEVT_TEXT_ENTER, &BaseGameTab::OnApplyFilter, this, ID_SEARCH_TERMS); - - search_terms->SetHint("e.g: Paul Morphy"); + this->Bind(wxEVT_LIST_COL_CLICK, [g=glm](wxListEvent& e){ + g->SortBy(e.GetColumn()); + }, wxID_ANY); } + void BaseGameTab::OnApplyFilter(wxCommandEvent &event){ wxString terms=search_terms->GetValue(); if(terms.length()>0){ diff --git a/src/base_tab/BaseTab.cpp b/src/base_tab/BaseTab.cpp index fada2b2..5db4f53 100644 --- a/src/base_tab/BaseTab.cpp +++ b/src/base_tab/BaseTab.cpp @@ -30,12 +30,7 @@ void BaseTab::OnOpenGame(wxListEvent &event){ 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); + wxGetApp().NewGame(this,g); } } diff --git a/src/ochess.cpp b/src/ochess.cpp index 3cfa8be..e9dd94f 100644 --- a/src/ochess.cpp +++ b/src/ochess.cpp @@ -19,6 +19,12 @@ std::vector MyApp::ListTabInfos() { return (tinfos); } +void MyApp::NewGame(TabInfos *tabsrc,std::shared_ptr g){ + MainWindow *w=((MainWindow *)this->GetTopWindow()); + TabInfos *i=w->NewGame(g); + i->Link(tabsrc); // Link opened game to tabsrc +} + wxIMPLEMENT_APP(MyApp); diff --git a/src/ochess.hpp b/src/ochess.hpp index e7c2508..745aa20 100644 --- a/src/ochess.hpp +++ b/src/ochess.hpp @@ -70,6 +70,7 @@ class MyApp : public wxApp { public: virtual bool OnInit(); std::vector ListTabInfos(); + void NewGame(TabInfos *tabsrc,std::shared_ptr g); }; wxDECLARE_APP(MyApp);