aboutsummaryrefslogtreecommitdiff
path: root/src/MainWindow.cpp
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2022-12-24 22:30:20 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2022-12-24 22:30:20 +0100
commitd298c59206ccb8c3e511fad9884e1cb0bd98b793 (patch)
treef2c725e865522c7430566a54e89c3426e799bf66 /src/MainWindow.cpp
parent418b2e7f600551062af6beb81cd105287d9ce59a (diff)
Update db management
Diffstat (limited to 'src/MainWindow.cpp')
-rw-r--r--src/MainWindow.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp
index 9ab8d00..deb2b8b 100644
--- a/src/MainWindow.cpp
+++ b/src/MainWindow.cpp
@@ -9,6 +9,8 @@ wxDEFINE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent);
wxDEFINE_EVENT(NEW_GAME_EVENT, wxCommandEvent);
wxDEFINE_EVENT(CLOSE_TAB_EVENT, wxCommandEvent);
wxDEFINE_EVENT(REFRESH_ENGINE_LIST, wxCommandEvent);
+wxDEFINE_EVENT(CLOSE_LINKED_TAB, wxCommandEvent);
+
/// ---------- MainWindow ----------
@@ -50,6 +52,7 @@ MainWindow::MainWindow()
Bind(CLOSE_TAB_EVENT, &MainWindow::OnCloseTabEvent, this, wxID_ANY);
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);
// Add new game tab by default
NewGame(std::shared_ptr<Game>(new Game()));
@@ -69,6 +72,11 @@ void MainWindow::OnCloseTabEvent(wxCommandEvent &event) {
notebook->DeletePage(notebook->GetSelection());
}
+void MainWindow::OnCloseTabLinkedTo(wxCommandEvent &event){
+ TabInfos *infos=(TabInfos*)event.GetClientData();
+ CloseTabLinkedTo(infos->id);
+}
+
void MainWindow::OnMenuItemClick(wxCommandEvent &event) {
std::uint32_t id = event.GetId();
if (id == wxID_EXIT) {
@@ -132,8 +140,7 @@ void MainWindow::NewEngine() {
try {
engine = new uciadapter::UCI(path);
EngineTab *bt = new EngineTab((wxWindow *)notebook, engine, path);
- notebook->AddPage(bt, bt->GetLabel());
- notebook->SetSelection(notebook->GetPageIndex(bt));
+ AddPage(bt,bt);
} catch (...) {
SHOW_DIALOG_ERROR("Could not communicate with the engine");
}
@@ -173,11 +180,16 @@ void MainWindow::OnClose(wxCloseEvent &e) {
}
void MainWindow::CloseTabLinkedTo(long id){
- for(int i=0;i<notebook->GetPageCount();i++){
+ int i=0;
+ while(i<notebook->GetPageCount()){
wxWindow *page=notebook->GetPage(i);
TabInfos* infos=(TabInfos*)page->GetClientData();
if(infos->is_linked && infos->linked_id==id){
notebook->DeletePage(i);
+ i=0; // Restart to page 0 since notebook updated
+ }
+ else {
+ i++;
}
}
}
@@ -190,8 +202,7 @@ void MainWindow::OpenFile() {
std::string path = openFileDialog.GetPath().ToStdString();
// Test base tab
BaseTab *bt = new BaseTab((wxFrame *)notebook, path);
- notebook->AddPage(bt, bt->GetLabel());
- notebook->SetSelection(notebook->GetPageIndex(bt));
+ AddPage(bt,bt);
}
}