Update tab management system

This commit is contained in:
Loic Guegan 2022-12-25 19:30:23 +01:00
parent 5df6e9395c
commit 29f330f307
9 changed files with 83 additions and 3 deletions

View file

@ -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<Game>(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){

View file

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

View file

@ -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<wxWindow *>(i);

View file

@ -1,7 +1,6 @@
#include "ochess.hpp"
class BaseImportTab : public TabBase_TabImport {
TabInfos *main_tab;
public:

View file

@ -23,4 +23,5 @@ public:
void RefreshLabel();
std::shared_ptr<Game> GetGame() { return (std::shared_ptr<Game>(game)); }
std::shared_ptr<GameBase> GetBase() { return (std::shared_ptr<GameBase>(base)); };
void Refresh() {import_tab->RefreshImportLists();};
};

View file

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

View file

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

View file

@ -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<Game> GetGame() = 0;
virtual std::shared_ptr<GameBase> GetBase() = 0;