Improve game list manager

This commit is contained in:
Loic Guegan 2022-12-25 17:30:22 +01:00
parent cd9f55f5ad
commit f7eab5a593
3 changed files with 37 additions and 15 deletions

View file

@ -31,20 +31,9 @@ void BaseGameTab::OnImport(wxCommandEvent &event) {
}
void BaseGameTab::OnDelete(wxCommandEvent &event) {
long selected = -1;
while ((selected = game_list->GetNextItem(selected, wxLIST_NEXT_ALL,
wxLIST_STATE_SELECTED)) !=
wxNOT_FOUND) {
wxListItem listItem;
listItem.m_itemId = selected; // sets row
listItem.m_col = 0; // sets column
game_list->GetItem(listItem); // gets item
deleted.push_back(std::stoi(listItem.GetText().ToStdString()));
for (std::uint32_t &i : deleted) {
wxLogDebug("%d", i);
}
game_list->SetItemBackgroundColour(selected, *wxRED);
for(auto i: glm->GetSelectedItems()){
deleted.push_back(glm->GetItemGameId(i));
glm->MarkItemAsDeleted(i);
}
}
@ -87,7 +76,7 @@ void BaseGameTab::OnOpenGame(wxListEvent &event) {
wxLogDebug("Open game");
edited[id]=*g;
deleted.push_back(id);
game_list->SetItemBackgroundColour(event.GetIndex(), *wxGREEN);
glm->MarkItemAsOpen(event.GetIndex());
wxCommandEvent openGameEvent(OPEN_GAME_EVENT, GetId());
openGameEvent.SetEventObject(this);
openGameEvent.SetClientData(g);

View file

@ -39,3 +39,32 @@ void GameListManager::Clear(){
void GameListManager::ClearDisplayedRow(){
game_list->DeleteAllItems();
}
void GameListManager::MarkItemAsOpen(long item){
game_list->SetItemBackgroundColour(item, *wxGREEN);
}
void GameListManager::MarkItemAsDeleted(long item){
game_list->SetItemBackgroundColour(item, *wxRED);
}
std::vector<long> GameListManager::GetSelectedItems(){
std::vector<long> items;
long selected = -1;
while ((selected = game_list->GetNextItem(selected, wxLIST_NEXT_ALL,
wxLIST_STATE_SELECTED)) !=
wxNOT_FOUND) {
items.push_back(selected);
}
return(items);
}
long GameListManager::GetItemGameId(long item){
wxListItem listItem;
listItem.m_itemId = item; // sets row
listItem.m_col = 0; // sets column to Id (column 0)
game_list->GetItem(listItem); // gets item
return std::stol(listItem.GetText().ToStdString());
}

View file

@ -22,4 +22,8 @@ public:
GameListManager(wxListCtrl *game_list);
void AddGame(CType White,CType Black,CType Event,CType Round, CType Result, CType Eco);
void Clear();
void MarkItemAsOpen(long item);
void MarkItemAsDeleted(long item);
std::vector<long> GetSelectedItems();
long GetItemGameId(long item);
};