From c97e151e1be7123d9d15e9ffcff1c46cecbb543a Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Tue, 27 Dec 2022 15:58:16 +0100 Subject: Improve game import --- src/base_tab/BaseTab.cpp | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) (limited to 'src/base_tab/BaseTab.cpp') diff --git a/src/base_tab/BaseTab.cpp b/src/base_tab/BaseTab.cpp index 8b58ca9..6866da1 100644 --- a/src/base_tab/BaseTab.cpp +++ b/src/base_tab/BaseTab.cpp @@ -1,12 +1,11 @@ #include "BaseTab.hpp" -#include "AppendGameDialog.hpp" #include BaseTab::BaseTab(wxFrame *parent, std::string base_file) : TabBase(parent), TabInfos(TabInfos::BASE), base_file(base_file){ // First open the database - OpenDatabase(base_file); + base=OpenDatabase(base_file); // Games tab games_tab=new BaseGameTab((wxFrame *)notebook,base,this); @@ -45,34 +44,23 @@ void BaseTab::Refresh(){ SetLabel(wxFileName(base->GetFilePath()).GetName()+" [DB]"); // Propagated to MainWindow tab title automatically by wxWidget } -void BaseTab::OpenDatabase(std::string dbpath) { - wxFileName file(dbpath); - wxString ext = file.GetExt().Lower(); - wxLogDebug("Here"); - if (ext == "pgn") { - if(!file.Exists()) - PGNGameBase::CreateDatabaseFile(dbpath); - base.reset(); - base = std::shared_ptr(new PGNGameBase(dbpath)); - } -} - void BaseTab::OnSave(wxCommandEvent &event) { - // Build new games + SHOW_DIALOG_BUSY("Apply all changes. Take a coffee, this process can takes time..."); + // First import games std::vector> new_games=games_tab->GetEditedGames(); for(auto g: import_tab->GetGameToImport()){ new_games.push_back(g); } - SHOW_DIALOG_BUSY("Apply all changes. Take a coffee, this process can takes time..."); base->Save(games_tab->GetDeletedGameIds(), import_tab->GetDatabaseToImport(), new_games); - + // Close all opened games in this database wxCommandEvent closeLinkedTabEvent(CLOSE_LINKED_TAB, GetId()); closeLinkedTabEvent.SetClientData((TabInfos*)this); ProcessEvent(closeLinkedTabEvent); // Reopen the saved database - OpenDatabase(base_file); + base.reset(); + base=OpenDatabase(base_file); games_tab->Reset(base); manage_tab->Reset(base); import_tab->Reset(base); -- cgit v1.2.3