aboutsummaryrefslogtreecommitdiff
path: root/src/base_tab/AppendGameDialog.cpp
blob: 1ff43105a07219b905ca314325ce635fd2c09c93 (plain)
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
#include "AppendGameDialog.hpp"
#include "MainWindow.hpp"
#include "ochess.hpp"

AppendGameDialog::AppendGameDialog(wxWindow *parent, GameBase *base)
    : AppendGameDialogBF(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();
}