ochess/src/base_tab/BaseTab.cpp
2022-02-24 15:22:56 +01:00

53 lines
No EOL
1.7 KiB
C++

#include "BaseTab.hpp"
#include <wx/filename.h>
BaseTab::BaseTab(wxFrame *parent)
: 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, 200);
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"Result", wxLIST_FORMAT_LEFT, 200);
this->Bind(wxEVT_BUTTON, &BaseTab::OnBim, this, wxID_ANY);
this->Bind(wxEVT_LIST_ITEM_ACTIVATED, &BaseTab::OnOpenGame, this, wxID_ANY);
}
void BaseTab::OnBim(wxCommandEvent &event) {
//LoadFile("/home/loic/hartwig.pgn");
}
void BaseTab::OnOpenGame(wxListEvent &event) {
wxLogDebug("Open!");
long id=std::stoi(event.GetItem().GetText().ToStdString());
Game *g = base->GetGame(id);
if (g != NULL) {
wxLogDebug("Open game: %s", g->GetTag("White"));
}
}
void BaseTab::ApplyPreferences() {}
void BaseTab::LoadFile(std::string path) {
wxFileName file(path);
wxString ext = file.GetExt().Lower();
if (ext == "pgn") {
base = new PGNGameBase(path);
}
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"));
id++;
}
}
}