diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index deb2b8b..53403ba 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -73,8 +73,19 @@ void MainWindow::OnCloseTabEvent(wxCommandEvent &event) { } void MainWindow::OnCloseTabLinkedTo(wxCommandEvent &event){ - TabInfos *infos=(TabInfos*)event.GetClientData(); - CloseTabLinkedTo(infos->id); + TabInfos *infosEvent=(TabInfos*)event.GetClientData(); + // Now close all tabs in the notebook related to the one in the event + int i=0; + while(iGetPageCount()){ + wxWindow *page=notebook->GetPage(i); + TabInfos* infos=(TabInfos*)page->GetClientData(); + if(infos->is_linked && infos->linked_id==infosEvent->id){ + notebook->DeletePage(i); // Remove page + i=0; // Restart to page 0 since notebook updated (we just remove one page) + } + else + i++; + } } void MainWindow::OnMenuItemClick(wxCommandEvent &event) { @@ -104,7 +115,6 @@ void MainWindow::OnMenuItemClick(wxCommandEvent &event) { } else if (id == 5) { OpenFile(); } else if (id == 6) { - CloseTabLinkedTo(1); NewEngine(); } } @@ -179,20 +189,6 @@ void MainWindow::OnClose(wxCloseEvent &e) { e.Skip(); } -void MainWindow::CloseTabLinkedTo(long id){ - int i=0; - while(iGetPageCount()){ - 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++; - } - } -} void MainWindow::OpenFile() { wxFileDialog openFileDialog(this, _("Open file"), "", "", diff --git a/src/MainWindow.hpp b/src/MainWindow.hpp index f705173..94131fc 100644 --- a/src/MainWindow.hpp +++ b/src/MainWindow.hpp @@ -32,7 +32,6 @@ class MainWindow : public MainFrame { void OnMenuItemClick(wxCommandEvent &event); void OnCloseTabLinkedTo(wxCommandEvent &event); void AddPage(wxWindow* window, TabInfos* infos); - void CloseTabLinkedTo(long id); public: MainWindow(); void ApplyPreferences(); diff --git a/src/base_tab/BaseGameTab.cpp b/src/base_tab/BaseGameTab.cpp index ae652cc..a652478 100644 --- a/src/base_tab/BaseGameTab.cpp +++ b/src/base_tab/BaseGameTab.cpp @@ -70,7 +70,7 @@ void BaseGameTab::OnSave(wxCommandEvent &event) { edited_games.end()); // Add edited game (since they are also deleted) base->Save(deleted, new_games_bases, new_games); - // CLose all opened games in this database + // Close all opened games in this database wxCommandEvent closeLinkedTabEvent(CLOSE_LINKED_TAB, GetId()); closeLinkedTabEvent.SetClientData(main_tab); ProcessEvent(closeLinkedTabEvent); @@ -82,17 +82,23 @@ void BaseGameTab::OnSave(wxCommandEvent &event) { } void BaseGameTab::OnOpenGame(wxListEvent &event) { - wxLogDebug("Open!"); long id = std::stoi(event.GetItem().GetText().ToStdString()); std::shared_ptr *g = new std::shared_ptr(base->GetGame(id)); if (g != NULL) { - edited[id]=*g; - deleted.push_back(id); - game_list->SetItemBackgroundColour(event.GetIndex(), *wxGREEN); - wxCommandEvent openGameEvent(OPEN_GAME_EVENT, GetId()); - openGameEvent.SetEventObject(this); - openGameEvent.SetClientData(g); - ProcessEvent(openGameEvent); + if(edited.find(id) != edited.end()){ + // TODO: Focus on the game tab and if close reopen it + wxLogDebug("Already opened!"); + } + else { + wxLogDebug("Open game"); + edited[id]=*g; + deleted.push_back(id); + game_list->SetItemBackgroundColour(event.GetIndex(), *wxGREEN); + wxCommandEvent openGameEvent(OPEN_GAME_EVENT, GetId()); + openGameEvent.SetEventObject(this); + openGameEvent.SetClientData(g); + ProcessEvent(openGameEvent); + } } } diff --git a/src/base_tab/BaseImportTab.cpp b/src/base_tab/BaseImportTab.cpp index 8b7cb1f..6c3ef5d 100644 --- a/src/base_tab/BaseImportTab.cpp +++ b/src/base_tab/BaseImportTab.cpp @@ -4,5 +4,5 @@ BaseImportTab::BaseImportTab(wxFrame *parent): TabBase_TabImport(parent) { - + } diff --git a/src/gui.cpp b/src/gui.cpp index 5e109cb..3169b1e 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -551,7 +551,7 @@ TabBase_TabGames::TabBase_TabGames( wxWindow* parent, wxWindowID id, const wxPoi import_button = new wxButton( this, ID_IMPORT_BUTTON, wxT("Import games"), wxDefaultPosition, wxDefaultSize, 0 ); bottom_sizer->Add( import_button, 0, wxALL, 5 ); - delete_button = new wxButton( this, ID_DELETE_BUTTON, wxT("Delete selection"), wxDefaultPosition, wxDefaultSize, 0 ); + delete_button = new wxButton( this, ID_DELETE_BUTTON, wxT("Mark as deleted"), wxDefaultPosition, wxDefaultSize, 0 ); bottom_sizer->Add( delete_button, 0, wxALL, 5 ); diff --git a/tools/wxFrameBuilder.fbp b/tools/wxFrameBuilder.fbp index 90d1b9a..0f96547 100644 --- a/tools/wxFrameBuilder.fbp +++ b/tools/wxFrameBuilder.fbp @@ -5569,7 +5569,7 @@ 0 0 ID_DELETE_BUTTON - Delete selection + Mark as deleted 0