From 29f330f307e35acf9dba3a8456dec330ef578dd7 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Sun, 25 Dec 2022 19:30:23 +0100 Subject: [PATCH] Update tab management system --- src/MainWindow.cpp | 10 ++++++ src/MainWindow.hpp | 1 + src/base_tab/BaseImportTab.cpp | 2 ++ src/base_tab/BaseImportTab.hpp | 1 - src/base_tab/BaseTab.hpp | 1 + src/gui.cpp | 6 +++- src/gui.h | 1 + src/ochess.hpp | 1 + tools/wxFrameBuilder.fbp | 63 +++++++++++++++++++++++++++++++++- 9 files changed, 83 insertions(+), 3 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index a0e2ce6..7e50150 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -53,6 +53,7 @@ MainWindow::MainWindow() Bind(wxEVT_MENU, &MainWindow::OnMenuItemClick, this, wxID_ANY); Bind(REFRESH_ENGINE_LIST, &MainWindow::OnRefreshEngineList, this, wxID_ANY); Bind(CLOSE_LINKED_TAB, &MainWindow::OnCloseTabLinkedTo, this, wxID_ANY); + Bind(wxEVT_AUINOTEBOOK_PAGE_CLOSED, &MainWindow::OnAuiNotebookPageClosed, this, wxID_ANY); // Add new game tab by default NewGame(std::shared_ptr(new Game())); @@ -66,10 +67,19 @@ void MainWindow::AddPage(wxWindow* window, TabInfos* infos){ window->SetClientData(infos); notebook->AddPage(window, window->GetLabel()); notebook->SetSelection(notebook->GetPageIndex(window)); + // Refresh tab that require knowledge on other tabs + for(auto i: wxGetApp().ListTabInfos()){i->Refresh();} +} + +void MainWindow::OnAuiNotebookPageClosed(wxAuiNotebookEvent& event){ + // Refresh tab that require knowledge on other tabs + for(auto i: wxGetApp().ListTabInfos()){i->Refresh();} } void MainWindow::OnCloseTabEvent(wxCommandEvent &event) { notebook->DeletePage(notebook->GetSelection()); + // Refresh tab that require knowledge on other tabs + for(auto i: wxGetApp().ListTabInfos()){i->Refresh();} } void MainWindow::OnCloseTabLinkedTo(wxCommandEvent &event){ diff --git a/src/MainWindow.hpp b/src/MainWindow.hpp index 5bff035..866a98b 100644 --- a/src/MainWindow.hpp +++ b/src/MainWindow.hpp @@ -29,6 +29,7 @@ class MainWindow : public MainFrame { void OnCloseTabEvent(wxCommandEvent &event); void OnRefreshEngineList(wxCommandEvent &event); void OnMenuItemClick(wxCommandEvent &event); + void OnAuiNotebookPageClosed(wxAuiNotebookEvent& event); void OnCloseTabLinkedTo(wxCommandEvent &event); void AddPage(wxWindow* window, TabInfos* infos); public: diff --git a/src/base_tab/BaseImportTab.cpp b/src/base_tab/BaseImportTab.cpp index 4fa9045..8396847 100644 --- a/src/base_tab/BaseImportTab.cpp +++ b/src/base_tab/BaseImportTab.cpp @@ -7,6 +7,8 @@ RefreshImportLists(); } void BaseImportTab::RefreshImportLists(){ + opened_game_list->Clear(); + opened_db_list->Clear(); for (TabInfos *i : wxGetApp().ListTabInfos()) { if (i->type == TabInfos::GAME) { wxWindow *win = dynamic_cast(i); diff --git a/src/base_tab/BaseImportTab.hpp b/src/base_tab/BaseImportTab.hpp index 2076027..7a0237e 100644 --- a/src/base_tab/BaseImportTab.hpp +++ b/src/base_tab/BaseImportTab.hpp @@ -1,7 +1,6 @@ #include "ochess.hpp" class BaseImportTab : public TabBase_TabImport { - TabInfos *main_tab; public: diff --git a/src/base_tab/BaseTab.hpp b/src/base_tab/BaseTab.hpp index 788ba45..da70af4 100644 --- a/src/base_tab/BaseTab.hpp +++ b/src/base_tab/BaseTab.hpp @@ -23,4 +23,5 @@ public: void RefreshLabel(); std::shared_ptr GetGame() { return (std::shared_ptr(game)); } std::shared_ptr GetBase() { return (std::shared_ptr(base)); }; + void Refresh() {import_tab->RefreshImportLists();}; }; \ No newline at end of file diff --git a/src/gui.cpp b/src/gui.cpp index ae717a5..b122cb1 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -616,10 +616,14 @@ TabBase_TabImport::TabBase_TabImport( wxWindow* parent, wxWindowID id, const wxP wxBoxSizer* bSizer33; bSizer33 = new wxBoxSizer( wxHORIZONTAL ); + m_staticText29 = new wxStaticText( this, wxID_ANY, wxT("Database:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticText29->Wrap( -1 ); + bSizer33->Add( m_staticText29, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); + opened_db_list = new wxComboBox( this, wxID_ANY, wxT("No other databases opened"), wxDefaultPosition, wxDefaultSize, 0, NULL, 0 ); bSizer33->Add( opened_db_list, 100, wxALL|wxEXPAND, 5 ); - import_from_db_button = new wxButton( this, wxID_ANY, wxT("Import Selected Games"), wxDefaultPosition, wxDefaultSize, 0 ); + import_from_db_button = new wxButton( this, wxID_ANY, wxT("Import Selection"), wxDefaultPosition, wxDefaultSize, 0 ); bSizer33->Add( import_from_db_button, 0, wxALL, 5 ); diff --git a/src/gui.h b/src/gui.h index 347cd89..ddf67e3 100644 --- a/src/gui.h +++ b/src/gui.h @@ -342,6 +342,7 @@ class TabBase_TabImport : public wxPanel wxButton* import_from_game_button; wxStaticLine* m_staticline4; wxStaticText* from_db_label; + wxStaticText* m_staticText29; wxComboBox* opened_db_list; wxButton* import_from_db_button; wxListCtrl* game_list; diff --git a/src/ochess.hpp b/src/ochess.hpp index 9b3bd3e..da9107b 100644 --- a/src/ochess.hpp +++ b/src/ochess.hpp @@ -52,6 +52,7 @@ public: bool is_linked; TabInfos(Type type_) : type(type_), id(tab_count), is_linked(false) { tab_count++; wxLogDebug("Tabid=%d",(int)id); } void Link(TabInfos *tab); + virtual void Refresh(){}; virtual void ApplyPreferences() = 0; virtual std::shared_ptr GetGame() = 0; virtual std::shared_ptr GetBase() = 0; diff --git a/tools/wxFrameBuilder.fbp b/tools/wxFrameBuilder.fbp index 2e67c94..2a654ce 100644 --- a/tools/wxFrameBuilder.fbp +++ b/tools/wxFrameBuilder.fbp @@ -6244,6 +6244,67 @@ bSizer33 wxHORIZONTAL none + + 5 + wxALIGN_CENTER_VERTICAL|wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Database: + 0 + + 0 + + + 0 + + 1 + m_staticText29 + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + 5 wxALL|wxEXPAND @@ -6347,7 +6408,7 @@ 0 0 wxID_ANY - Import Selected Games + Import Selection 0