diff options
| author | Loic Guegan <manzerbredes@mailbox.org> | 2022-12-27 15:58:16 +0100 |
|---|---|---|
| committer | Loic Guegan <manzerbredes@mailbox.org> | 2022-12-27 15:58:16 +0100 |
| commit | c97e151e1be7123d9d15e9ffcff1c46cecbb543a (patch) | |
| tree | a160099d4b1e7f66b22a19d35c0d1a997aca86bb /src/base_tab/BaseImportTab.cpp | |
| parent | f40fd3e7a4c5fd36c977ad5343de4fe7859cbbbe (diff) | |
Improve game import
Diffstat (limited to 'src/base_tab/BaseImportTab.cpp')
| -rw-r--r-- | src/base_tab/BaseImportTab.cpp | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/src/base_tab/BaseImportTab.cpp b/src/base_tab/BaseImportTab.cpp index d7da23b..2daa125 100644 --- a/src/base_tab/BaseImportTab.cpp +++ b/src/base_tab/BaseImportTab.cpp @@ -17,9 +17,9 @@ TabBase_TabImport(parent), main_tab(main_tab), base(db) } void BaseImportTab::OnImportDatabase(wxCommandEvent &event){ - if(std::find(databases_to_import.begin(), databases_to_import.end(), selected_base) == databases_to_import.end()){ - databases_to_import.push_back(selected_base); - selected_games_to_import.clear(); + if(std::find(databases_to_import.begin(), databases_to_import.end(), selected_base->GetFilePath()) == databases_to_import.end()){ + databases_to_import.push_back(selected_base->GetFilePath()); + selected_games_to_import.erase(selected_base->GetFilePath()); glm->Clear(); RefreshPendingImports(); } @@ -29,7 +29,10 @@ void BaseImportTab::OnImportDatabase(wxCommandEvent &event){ void BaseImportTab::RefreshPendingImports(){ int ngames=games_to_import.size(); int ndb=databases_to_import.size(); - int nbselect=selected_games_to_import.size(); + int nbselect=0; + for (auto it = selected_games_to_import.begin(); it != selected_games_to_import.end(); it++){ + nbselect+=it->second.size(); + } pending_imports->Clear(); if(ngames+ndb+nbselect>0){ pending_imports->AppendText(" Pending imports: "+std::to_string(ngames+nbselect)+" games and "+std::to_string(ndb)+" databases"); @@ -55,14 +58,15 @@ void BaseImportTab::RefreshImportLists(){ } void BaseImportTab::OnImportSelection(wxCommandEvent &event){ - if(std::find(databases_to_import.begin(), databases_to_import.end(), selected_base) == databases_to_import.end()){ + if(std::find(databases_to_import.begin(), databases_to_import.end(), selected_base->GetFilePath()) == databases_to_import.end()){ long selected = -1; while ((selected = game_list->GetNextItem(selected, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED)) != wxNOT_FOUND) { long game_id=glm->GetItemGameId(selected); - if(selected_games_to_import.find(game_id) == selected_games_to_import.end()){ - selected_games_to_import[game_id]=selected_base->GetGame(glm->GetItemGameId(selected)); + auto &game_list=selected_games_to_import[selected_base->GetFilePath()]; + if(game_list.find(game_id) == game_list.end()){ + game_list[game_id]=selected_base->GetGame(glm->GetItemGameId(selected)); glm->MarkItemAsImported(selected); } } @@ -85,21 +89,23 @@ void BaseImportTab::OnImportGame(wxCommandEvent &event){ void BaseImportTab::OnLoad(wxCommandEvent &event){ TabInfos *game_tab=(TabInfos*)opened_db_list->GetClientData(opened_db_list->GetSelection()); - selected_base.reset(); - selected_base=game_tab->GetBase(); - glm->Clear(); // Load all games (for now :) - selected_base->Reset(); + glm->Clear(); + selected_base=OpenDatabase(game_tab->GetBase()->GetFilePath()); SHOW_DIALOG_BUSY("Loading database..."); + auto &game_list=selected_games_to_import[selected_base->GetFilePath()]; while (selected_base->NextGame()) { - glm->AddGame( + long id=glm->AddGame( selected_base->GetTag("White"), selected_base->GetTag("Black"), selected_base->GetTag("Event"), selected_base->GetTag("Round"), selected_base->GetTag("Result"), selected_base->GetTag("ECO")); + if(game_list.find(id)!=game_list.end()){ + glm->MarkItemAsImported(id); + } } } @@ -109,13 +115,16 @@ void BaseImportTab::Reset(std::shared_ptr<GameBase> base){ this->databases_to_import.clear(); this->selected_games_to_import.clear(); glm->Clear(); + RefreshPendingImports(); } std::vector<std::shared_ptr<Game>> BaseImportTab::GetGameToImport(){ std::vector<std::shared_ptr<Game>> to_import; for(auto g: games_to_import){to_import.push_back(g);} for (auto it = selected_games_to_import.begin(); it != selected_games_to_import.end(); it++){ - to_import.push_back(it->second); + for (auto it2 = it->second.begin(); it2 != it->second.end(); it2++){ + to_import.push_back(it2->second); + } } return to_import; } |
