ochess/src/base_tab/AppendGameDialog.cpp
2022-02-28 13:02:27 +01:00

44 lines
No EOL
1.3 KiB
C++

#include "AppendGameDialog.hpp"
#include "MainWindow.hpp"
#include "ochess.hpp"
AppendGameDialog::AppendGameDialog(wxWindow *parent, GameBase *base)
: DialogAppendGame(parent), base(base) {
for (TabInfos *i : MAINWIN->ListTabInfos()) {
if (i->type == TabInfos::GAME || i->type == TabInfos::BASE) {
wxWindow *win = dynamic_cast<wxWindow *>(i);
game_list->Append(win->GetLabel());
tinfos.push_back(i);
}
}
Bind(wxEVT_BUTTON, &AppendGameDialog::OnCancel, this,
ID_DIALOG_CANCEL_BUTTON);
Bind(wxEVT_BUTTON, &AppendGameDialog::OnImport, this,
ID_DIALOG_IMPORT_BUTTON);
}
void AppendGameDialog::OnCancel(wxCommandEvent &event) { this->Close(); }
void AppendGameDialog::OnImport(wxCommandEvent &event) {
std::vector<std::uint32_t> to_ignore;
std::vector<GameBase *> new_games_bases;
std::vector<Game *> new_games;
wxArrayInt selections;
game_list->GetSelections(selections);
for (int &i : selections) {
TabInfos *tinfo = tinfos[i];
if (tinfo->type == TabInfos::BASE) {
new_games_bases.push_back(static_cast<GameBase *>(tinfo->GetBase()));
} else if (tinfo->type == TabInfos::GAME) {
new_games.push_back(static_cast<Game *>(tinfo->GetGame()));
}
}
base->Save(to_ignore, new_games_bases, new_games);
this->Close();
}