feat: apply filtering to game list, correct selections after filtering

Will need to propogate these filtering options to the other places these things are present, there's a dedicated variant for just the stylesheet dialog window and also the Style tab.
This commit is contained in:
Brendan Hagan
2022-06-19 23:38:38 -04:00
parent 52f1724449
commit 766a99fbc4
5 changed files with 55 additions and 17 deletions
+41 -13
View File
@@ -34,18 +34,26 @@ NewSetWindow::NewSetWindow(Window* parent)
stylesheet_list = new PackageList (this, ID_STYLESHEET_LIST, wxHORIZONTAL, false);
wxStaticText* game_text = new wxStaticText(this, ID_GAME_LIST, _LABEL_("game type"));
wxStaticText* stylesheet_text = new wxStaticText(this, ID_STYLESHEET_LIST, _LABEL_("style type"));
filter = new FilterCtrl(this, ID_STYLESHEET_FILTER, _LABEL_("search stylesheet list"), _HELP_("search stylesheet list control"));
filter->setFilter(filter_value);
game_filter = new FilterCtrl(this, ID_GAME_FILTER, _LABEL_("search game list"), _HELP_("search game list control"));
game_filter->setFilter(game_filter_value);
stylesheet_filter = new FilterCtrl(this, ID_STYLESHEET_FILTER, _LABEL_("search stylesheet list"), _HELP_("search stylesheet list control"));
stylesheet_filter->setFilter(stylesheet_filter_value);
// init sizer
wxSizer* s = new wxBoxSizer(wxVERTICAL);
s->Add(game_text, 0, wxALL, 4);
s->Add(game_list, 0, wxEXPAND | (wxALL & ~wxTOP), 4);
wxSizer* s2 = new wxBoxSizer(wxHORIZONTAL);
s2->Add(stylesheet_text, 0, wxALL & ~wxLEFT, 4);
s2->AddSpacer(2);
s2->Add(filter, 0, wxALL & ~wxRIGHT, 4);
s2->Add(game_text, 0, wxALL & ~wxLEFT, 4);
s2->AddSpacer(2);
s2->Add(game_filter, 0, wxALL & ~wxRIGHT, 4);
s->Add(s2);
s->Add(game_list, 0, wxEXPAND | (wxALL & ~wxTOP), 4);
wxSizer* s3 = new wxBoxSizer(wxHORIZONTAL);
s3->Add(stylesheet_text, 0, wxALL & ~wxLEFT, 4);
s3->AddSpacer(2);
s3->Add(stylesheet_filter, 0, wxALL & ~wxRIGHT, 4);
s->Add(s3);
s->Add(stylesheet_list, 0, wxEXPAND | (wxALL & ~wxTOP), 4);
s->Add(CreateButtonSizer(wxOK | wxCANCEL) , 0, wxEXPAND | wxALL, 8);
s->SetSizeHints(this);
@@ -87,12 +95,31 @@ void NewSetWindow::onStyleSheetSelect(wxCommandEvent&) {
settings.gameSettingsFor(*game).default_stylesheet = stylesheet->name();
UpdateWindowUI(wxUPDATE_UI_RECURSE);
}
void NewSetWindow::onStyleSheetActivate(wxCommandEvent&) {
done();
}
void NewSetWindow::onFilterUpdate(wxCommandEvent&) {
stylesheet_list->setFilter(filter->getFilter<PackageData>());
void NewSetWindow::onGameFilterUpdate(wxCommandEvent&) {
if (game_list->hasSelection()) {
GameP existingGameSelection = game_list->getSelection<Game>(false);
game_list->setFilter(game_filter->getFilter<PackageData>());
game_list->select(existingGameSelection->name());
}
else {
game_list->setFilter(game_filter->getFilter<PackageData>());
}
}
void NewSetWindow::onStylesheetFilterUpdate(wxCommandEvent&) {
if (stylesheet_list->hasSelection()) {
StyleSheetP existingStylesheetSelection = stylesheet_list->getSelection<StyleSheet>(false);
stylesheet_list->setFilter(stylesheet_filter->getFilter<PackageData>());
stylesheet_list->select(existingStylesheetSelection->name());
}
else {
stylesheet_list->setFilter(stylesheet_filter->getFilter<PackageData>());
}
}
void NewSetWindow::OnOK(wxCommandEvent&) {
@@ -128,10 +155,11 @@ void NewSetWindow::onIdle(wxIdleEvent& ev) {
}
BEGIN_EVENT_TABLE(NewSetWindow, wxDialog)
EVT_GALLERY_SELECT(ID_GAME_LIST, NewSetWindow::onGameSelect)
EVT_GALLERY_SELECT(ID_STYLESHEET_LIST, NewSetWindow::onStyleSheetSelect)
EVT_GALLERY_ACTIVATE(ID_STYLESHEET_LIST, NewSetWindow::onStyleSheetActivate)
EVT_COMMAND_RANGE(ID_STYLESHEET_FILTER, ID_STYLESHEET_FILTER, wxEVT_COMMAND_TEXT_UPDATED, NewSetWindow::onFilterUpdate)
EVT_GALLERY_SELECT(ID_GAME_LIST, NewSetWindow::onGameSelect)
EVT_GALLERY_SELECT(ID_STYLESHEET_LIST, NewSetWindow::onStyleSheetSelect)
EVT_GALLERY_ACTIVATE(ID_STYLESHEET_LIST, NewSetWindow::onStyleSheetActivate)
EVT_COMMAND_RANGE(ID_STYLESHEET_FILTER, ID_STYLESHEET_FILTER, wxEVT_COMMAND_TEXT_UPDATED, NewSetWindow::onStylesheetFilterUpdate)
EVT_COMMAND_RANGE(ID_GAME_FILTER, ID_GAME_FILTER, wxEVT_COMMAND_TEXT_UPDATED, NewSetWindow::onGameFilterUpdate)
EVT_BUTTON (wxID_OK, NewSetWindow::OnOK)
EVT_UPDATE_UI (wxID_ANY, NewSetWindow::onUpdateUI)
EVT_IDLE ( NewSetWindow::onIdle)