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
|
#include "BaseTab.hpp"
#include <wx/filename.h>
BaseTab::BaseTab(wxFrame *parent, std::string base_file)
: BasePanelBF(parent), TabInfos(TabInfos::BASE), base(NULL) {
game_list->InsertColumn(0, L"id", wxLIST_FORMAT_LEFT, 50);
game_list->InsertColumn(1, L"White", wxLIST_FORMAT_LEFT, 200);
game_list->InsertColumn(2, L"Black", wxLIST_FORMAT_LEFT, 200);
game_list->InsertColumn(3, L"Event", wxLIST_FORMAT_LEFT, 150);
game_list->InsertColumn(4, L"Round", wxLIST_FORMAT_LEFT, 100);
game_list->InsertColumn(5, L"Result", wxLIST_FORMAT_LEFT, 200);
game_list->InsertColumn(6, L"ECO", wxLIST_FORMAT_LEFT, 200);
this->Bind(wxEVT_BUTTON, &BaseTab::OnBim, this, wxID_ANY);
this->Bind(wxEVT_LIST_ITEM_ACTIVATED, &BaseTab::OnOpenGame, this, wxID_ANY);
current_base->SetLabel(base_file);
LoadFile(base_file);
}
void BaseTab::OnBim(wxCommandEvent &event) {}
void BaseTab::OnOpenGame(wxListEvent &event) {
wxLogDebug("Open!");
long id = std::stoi(event.GetItem().GetText().ToStdString());
Game *g = base->GetGame(id);
if (g != NULL) {
wxCommandEvent newGameEvent(NEW_GAME_EVENT, GetId());
newGameEvent.SetEventObject(this);
newGameEvent.SetClientData(g);
ProcessEvent(newGameEvent);
}
}
void BaseTab::ApplyPreferences() {}
void BaseTab::LoadFile(std::string path) {
wxFileName file(path);
wxString ext = file.GetExt().Lower();
if (ext == "pgn") {
base = new PGNGameBase(path);
SetLabel(file.GetName()+ "(PGN)");
}
if (base != NULL) {
long id = 0;
while (base->NextGame()) {
long index =
game_list->InsertItem(0, std::to_string(id)); // want this for col. 1
game_list->SetItem(index, 1, base->GetTag("White"));
game_list->SetItem(index, 2, base->GetTag("Black"));
game_list->SetItem(index, 3, base->GetTag("Event"));
game_list->SetItem(index, 4, base->GetTag("Round"));
game_list->SetItem(index, 5, base->GetTag("Result"));
game_list->SetItem(index, 6, base->GetTag("ECO"));
id++;
}
}
wxCommandEvent event(REFRESH_TAB_TITLE, GetId());
event.SetEventObject(this);
ProcessEvent(event);
}
|