diff --git a/src/base_tab/BaseGameTab.cpp b/src/base_tab/BaseGameTab.cpp index 157358e..fc617a5 100644 --- a/src/base_tab/BaseGameTab.cpp +++ b/src/base_tab/BaseGameTab.cpp @@ -57,7 +57,6 @@ std::shared_ptr BaseGameTab::OpenGame(long gameid, long item) { return g; } } - return nullptr; } diff --git a/src/base_tab/BaseImportTab.cpp b/src/base_tab/BaseImportTab.cpp index b43cb54..422a76f 100644 --- a/src/base_tab/BaseImportTab.cpp +++ b/src/base_tab/BaseImportTab.cpp @@ -2,12 +2,7 @@ #include #include "gamebase/GameBase.hpp" -#define NOTIFY_MANAGE_TAB() \ -{ \ - wxCommandEvent e(REFRESH_MANAGE_TAB,GetId()); \ - ProcessEvent(e); \ -} - +// Foreign events wxDECLARE_EVENT(REFRESH_MANAGE_TAB, wxCommandEvent); BaseImportTab::BaseImportTab(wxFrame *parent, std::shared_ptr db, TabInfos *main_tab): @@ -21,12 +16,13 @@ TabBase_TabImport(parent), main_tab(main_tab), base(db) glm=std::make_shared(game_list); RefreshImportLists(); RefreshPendingImports(); + + opened_db_list->SetHint("No other database open"); + this->Bind(wxEVT_BUTTON, &BaseImportTab::OnLoad, this, ID_LOAD_BUTTON); this->Bind(wxEVT_BUTTON, &BaseImportTab::OnImportGame, this, ID_IMPORT_GAME_BUTTON); this->Bind(wxEVT_BUTTON, &BaseImportTab::OnImportSelection, this, ID_IMPORT_SELECTION); this->Bind(wxEVT_BUTTON, &BaseImportTab::OnImportDatabase, this, ID_IMPORT_DB); - - opened_db_list->SetHint("No other database open"); } void BaseImportTab::OnImportDatabase(wxCommandEvent &event){ @@ -40,25 +36,28 @@ void BaseImportTab::OnImportDatabase(wxCommandEvent &event){ } void BaseImportTab::RefreshPendingImports(){ + // Compute metrics import_ndb=databases_to_import.size(); import_ngames=games_to_import.size(); import_nselect=0; for (auto it = selected_games_to_import.begin(); it != selected_games_to_import.end(); it++){ import_nselect+=it->second.size(); } + // Update message pending_imports->Clear(); if(import_ndb+import_ngames+import_nselect>0){ pending_imports->AppendText(" Pending imports: "+std::to_string(import_ngames+import_nselect)+" games and "+std::to_string(import_ndb)+" databases"); }else pending_imports->SetHint("No pending imports"); - - NOTIFY_MANAGE_TAB(); + // Don't forget to notify BaseManageTab + wxCommandEvent e(REFRESH_MANAGE_TAB,GetId()); + ProcessEvent(e); } void BaseImportTab::RefreshImportLists(){ opened_game_list->Clear(); opened_db_list->Clear(); - for (TabInfos *i : wxGetApp().ListTabInfos()) { + for (TabInfos *i : wxGetApp().ListTabInfos()) { if (i->type == TabInfos::GAME) { wxWindow *win = dynamic_cast(i); opened_game_list->Append(win->GetLabel(),i); @@ -78,8 +77,11 @@ void BaseImportTab::OnImportSelection(wxCommandEvent &event){ while ((selected = game_list->GetNextItem(selected, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED)) != wxNOT_FOUND) { + // Get game id long game_id=glm->GetItemGameId(selected); + // Select the right db hashmap auto &game_list=selected_games_to_import[selected_base->GetFilePath()]; + // If game not in this hasmap add it if(game_list.find(game_id) == game_list.end()){ game_list[game_id]=selected_base->GetGame(glm->GetItemGameId(selected)); glm->MarkItemAsImported(selected); @@ -131,7 +133,6 @@ void BaseImportTab::Reset(std::shared_ptr base){ this->selected_games_to_import.clear(); glm->Clear(); RefreshPendingImports(); - NOTIFY_MANAGE_TAB(); } std::vector> BaseImportTab::GetGameToImport(){ diff --git a/src/base_tab/BaseImportTab.hpp b/src/base_tab/BaseImportTab.hpp index dacf868..9a2386d 100644 --- a/src/base_tab/BaseImportTab.hpp +++ b/src/base_tab/BaseImportTab.hpp @@ -9,10 +9,13 @@ class BaseImportTab : public TabBase_TabImport { TabInfos *main_tab; std::shared_ptr glm; + + // Import states data structures std::vector> games_to_import; std::vector databases_to_import; - /// @brief Old for each pair of DB (file path) and game id, the given game object + /// @brief Hold games for each databases std::unordered_map>> selected_games_to_import; + std::shared_ptr base; std::shared_ptr selected_base; diff --git a/src/base_tab/BaseManageTab.hpp b/src/base_tab/BaseManageTab.hpp index e6bfc71..863754c 100644 --- a/src/base_tab/BaseManageTab.hpp +++ b/src/base_tab/BaseManageTab.hpp @@ -8,9 +8,11 @@ class BaseManageTab : public TabBase_TabManage { - /// @brief Never free the following pointers in that class + /// Never free the following pointers in that class std::shared_ptr glm; std::shared_ptr base; + + /// Pointers for data access BaseImportTab *import_tab; BaseGameTab *games_tab; diff --git a/src/base_tab/BaseTab.hpp b/src/base_tab/BaseTab.hpp index 7782b43..e7e4208 100644 --- a/src/base_tab/BaseTab.hpp +++ b/src/base_tab/BaseTab.hpp @@ -19,7 +19,7 @@ class BaseTab : public TabBase, public TabInfos { /// @brief The last opened game std::shared_ptr game; - /// All sub tabs + /// All sub tabs from this main table BaseGameTab *games_tab; BaseImportTab *import_tab; BaseManageTab *manage_tab;