1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
#include "BaseImportTab.hpp"
#include <algorithm>
#include "gamebase/GameBase.hpp"
BaseImportTab::BaseImportTab(wxFrame *parent, std::shared_ptr<GameBase> db, TabInfos *main_tab):
TabBase_TabImport(parent), main_tab(main_tab), base(db)
{
glm=std::make_shared<GameListManager>(game_list);
RefreshImportLists();
RefreshPendingImports();
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){
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();
glm->Clear();
RefreshPendingImports();
}
else SHOW_DIALOG_INFO("Database already prepared for import");
}
void BaseImportTab::RefreshPendingImports(){
int ngames=games_to_import.size();
int ndb=databases_to_import.size();
int nbselect=selected_games_to_import.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");
}else
pending_imports->SetHint("No pending imports");
}
void BaseImportTab::RefreshImportLists(){
opened_game_list->Clear();
opened_db_list->Clear();
for (TabInfos *i : wxGetApp().ListTabInfos()) {
if (i->type == TabInfos::GAME) {
wxWindow *win = dynamic_cast<wxWindow *>(i);
opened_game_list->Append(win->GetLabel(),i);
opened_game_list->SetSelection(0);
}
else if (i->type == TabInfos::BASE && i->id != main_tab->id) {
wxWindow *win = dynamic_cast<wxWindow *>(i);
opened_db_list->Append(win->GetLabel(),i);
opened_db_list->SetSelection(0);
}
}
}
void BaseImportTab::OnImportSelection(wxCommandEvent &event){
if(std::find(databases_to_import.begin(), databases_to_import.end(), selected_base) == 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));
glm->MarkItemAsImported(selected);
}
}
}
else {
SHOW_DIALOG_INFO("Database already prepared for import");
}
RefreshPendingImports();
}
void BaseImportTab::OnImportGame(wxCommandEvent &event){
TabInfos *game_tab=(TabInfos*)opened_game_list->GetClientData(opened_game_list->GetSelection());
std::shared_ptr<Game> g=game_tab->GetGame();
if(std::find(games_to_import.begin(), games_to_import.end(), g) == games_to_import.end()){ wxLogDebug("Import!");
games_to_import.push_back(g);
RefreshPendingImports();
}
else SHOW_DIALOG_INFO("Game already prepared for import");
}
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();
SHOW_DIALOG_BUSY("Loading database...");
while (selected_base->NextGame()) {
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"));
}
}
void BaseImportTab::Reset(std::shared_ptr<GameBase> base){
this->base=base;
this->games_to_import.clear();
this->databases_to_import.clear();
glm->Clear();
}
|