ochess/src/base_tab/AppendGameDialog.cpp

44 lines
1.3 KiB
C++
Raw Normal View History

2022-02-26 12:30:07 +01:00
#include "AppendGameDialog.hpp"
#include "MainWindow.hpp"
#include "ochess.hpp"
AppendGameDialog::AppendGameDialog(wxWindow *parent, GameBase *base)
2022-02-28 13:02:27 +01:00
: DialogAppendGame(parent), base(base) {
2022-02-26 12:30:07 +01:00
2022-02-26 14:22:17 +01:00
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);
}
2022-02-26 12:30:07 +01:00
}
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;
2022-02-26 12:48:52 +01:00
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);
2022-02-26 12:30:07 +01:00
this->Close();
}