aboutsummaryrefslogtreecommitdiff
path: root/src/base_tab/BaseTab.cpp
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2022-12-26 12:51:48 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2022-12-26 12:51:48 +0100
commit1d78e106adf4cc5894f299d597c02a9b7e508173 (patch)
tree04e722a73340082f6c2b06d9901bb705f762eead /src/base_tab/BaseTab.cpp
parent2bd85f53bcaeb12090b9ac2d4cf7c781b280e678 (diff)
Debug database tab
Diffstat (limited to 'src/base_tab/BaseTab.cpp')
-rw-r--r--src/base_tab/BaseTab.cpp52
1 files changed, 43 insertions, 9 deletions
diff --git a/src/base_tab/BaseTab.cpp b/src/base_tab/BaseTab.cpp
index 78b546e..05ff907 100644
--- a/src/base_tab/BaseTab.cpp
+++ b/src/base_tab/BaseTab.cpp
@@ -3,34 +3,68 @@
#include <wx/filename.h>
BaseTab::BaseTab(wxFrame *parent, std::string base_file)
- : TabBase(parent), TabInfos(TabInfos::BASE){
+ : TabBase(parent), TabInfos(TabInfos::BASE), base_file(base_file){
+
+ // First open the database
+ OpenDatabase(base_file);
// Games tab
- games_tab=new BaseGameTab((wxFrame *)notebook,base_file,this);
+ games_tab=new BaseGameTab((wxFrame *)notebook,base,this);
notebook->AddPage(games_tab, "Games list",true); // true for selecting the tab
// Import tab
import_tab=new BaseImportTab((wxFrame *)notebook,this);
notebook->AddPage(import_tab, "Import games");
// Manage tab
- manage_tab=new BaseManageTab((wxFrame *)notebook);
+ manage_tab=new BaseManageTab((wxFrame *)notebook, base, games_tab->glm);
notebook->AddPage(manage_tab, "Manage database");
- RefreshLabel();
- this->Bind(OPEN_GAME_EVENT, &BaseTab::OnNewGame, this, wxID_ANY);
+ // Refresh dynamic elements of the database (tab title, available db for import etc.)
+ Refresh();
+
+ // Bindings
+ this->Bind(OPEN_GAME_EVENT, &BaseTab::OnOpenGame, this, wxID_ANY);
+ this->Bind(wxEVT_BUTTON, &BaseTab::OnSave, this, ID_SAVE_BUTTON);
+
}
-void BaseTab::OnNewGame(wxCommandEvent &event){
+void BaseTab::OnOpenGame(wxCommandEvent &event){
std::shared_ptr<Game> *g = (std::shared_ptr<Game>*)event.GetClientData();
this->game=*g;
+
+ // Ask MainFrame to open a new game
+ // TODO: Simplify that is, use wxWidget main app to do it
wxCommandEvent newGameEvent(NEW_GAME_EVENT, GetId());
newGameEvent.SetEventObject(this);
newGameEvent.SetClientData((TabInfos*)this);
ProcessEvent(newGameEvent);
}
-void BaseTab::ApplyPreferences() {}
+void BaseTab::Refresh(){
+ import_tab->RefreshImportLists();
+ 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();
+ if (ext == "pgn") {
+ base.reset();
+ base = std::shared_ptr<GameBase>(new PGNGameBase(dbpath));
+ }
+}
+
+void BaseTab::OnSave(wxCommandEvent &event) {
+ std::vector<std::shared_ptr<GameBase>> dummy_empty_base;
+ base->Save(games_tab->GetDeletedGameIds(), dummy_empty_base, games_tab->GetEditedGames());
+
+ // Close all opened games in this database
+ wxCommandEvent closeLinkedTabEvent(CLOSE_LINKED_TAB, GetId());
+ closeLinkedTabEvent.SetClientData((TabInfos*)this);
+ ProcessEvent(closeLinkedTabEvent);
-void BaseTab::RefreshLabel(){
- SetLabel("Database XX");
+ // Reopen the saved database
+ OpenDatabase(base_file);
+ games_tab->Reset(base);
+ manage_tab->Reset(base);
} \ No newline at end of file