From a7336d66e114a93dc26a477b9bbc82b585f07902 Mon Sep 17 00:00:00 2001 From: Twan van Laarhoven Date: Sun, 14 Jun 2020 21:39:23 +0200 Subject: [PATCH] Card list sorting is now handled per window (closes #71) --- CHANGES.txt | 3 ++ src/gui/control/card_list.cpp | 47 ++++++++++++++++++------------- src/gui/control/card_list.hpp | 2 -- src/gui/control/item_list.hpp | 2 +- src/gui/set/cards_panel.cpp | 4 +++ src/gui/set/cards_panel.hpp | 2 ++ src/gui/set/panel.hpp | 5 +++- src/gui/set/random_pack_panel.cpp | 3 ++ src/gui/set/random_pack_panel.hpp | 3 +- src/gui/set/stats_panel.cpp | 4 +++ src/gui/set/stats_panel.hpp | 3 +- src/gui/set/window.cpp | 8 ++++++ src/gui/set/window.hpp | 6 +++- 13 files changed, 66 insertions(+), 26 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 60fbb894..584c938c 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -6,6 +6,9 @@ -- HEAD: new items added as changes are made ------------------------------------------------------------------------------ +Features: + * Sorting of the card list can now be changed per window + Bug fixes: * Fixed: keywords after atoms were not showing up (#67) * Fixed: multiple keywords that matched in the same place both showed reminder text. (#70) diff --git a/src/gui/control/card_list.cpp b/src/gui/control/card_list.cpp index 704dbb73..5b38de0f 100644 --- a/src/gui/control/card_list.cpp +++ b/src/gui/control/card_list.cpp @@ -9,6 +9,7 @@ #include #include #include +#include // for sorting all cardlists in a window #include #include #include @@ -44,19 +45,12 @@ CardListBase* CardSelectEvent::getTheCardList() const { // ----------------------------------------------------------------------------- : CardListBase -vector CardListBase::card_lists; - CardListBase::CardListBase(Window* parent, int id, long additional_style) : ItemList(parent, id, additional_style, true) -{ - // add to the list of card lists - card_lists.push_back(this); -} +{} CardListBase::~CardListBase() { storeColumns(); - // remove from list of card lists - card_lists.erase(remove(card_lists.begin(), card_lists.end(), this)); } void CardListBase::onBeforeChangeSet() { @@ -263,10 +257,15 @@ void CardListBase::rebuild() { } void CardListBase::sortBy(long column, bool ascending) { - // sort all card lists for this game - FOR_EACH(card_list, card_lists) { - if (card_list->set && card_list->set->game == set->game) { - card_list->ItemList::sortBy(column, ascending); + ItemList::sortBy(column, ascending); + storeColumns(); + // sort all other card lists in this window + SetWindow* set_window = dynamic_cast(wxGetTopLevelParent(this)); + if (set_window) { + for (auto card_list : set_window->getCardLists()) { + if (card_list != this) { + card_list->ItemList::sortBy(column, ascending); + } } } } @@ -287,14 +286,19 @@ void CardListBase::storeColumns() { else gs.sort_cards_by = wxEmptyString; gs.sort_cards_ascending = sort_ascending; } + void CardListBase::selectColumns() { CardListColumnSelectDialog wnd(this, set->game); if (wnd.ShowModal() == wxID_OK) { - // rebuild all card lists for this game storeColumns(); - FOR_EACH(card_list, card_lists) { - if (card_list->set && card_list->set->game == set->game) { - card_list->rebuild(); + // rebuild all card lists this window + rebuild(); + SetWindow* set_window = dynamic_cast(wxGetTopLevelParent(this)); + if (set_window) { + for (auto card_list : set_window->getCardLists()) { + if (card_list != this) { + card_list->rebuild(); + } } } } @@ -335,9 +339,14 @@ void CardListBase::onColumnResize(wxListEvent& ev) { storeColumns(); int col = ev.GetColumn(); int width = GetColumnWidth(col); - FOR_EACH(card_list, card_lists) { - if (card_list != this && card_list->set && card_list->set->game == set->game) { - card_list->SetColumnWidth(col, width); + // update this and all other card lists in this window + SetColumnWidth(col, width); + SetWindow* set_window = dynamic_cast(wxGetTopLevelParent(this)); + if (set_window) { + for (auto card_list : set_window->getCardLists()) { + if (card_list != this) { + card_list->SetColumnWidth(col, width); + } } } } diff --git a/src/gui/control/card_list.hpp b/src/gui/control/card_list.hpp index fd3be012..4d93b8b8 100644 --- a/src/gui/control/card_list.hpp +++ b/src/gui/control/card_list.hpp @@ -134,8 +134,6 @@ public: private: /// Store the column sizes in the settings void storeColumns(); - /// All card lists; used to exchange column sizes - static vector card_lists; // --------------------------------------------------- : Window events DECLARE_EVENT_TABLE(); diff --git a/src/gui/control/item_list.hpp b/src/gui/control/item_list.hpp index cc411ebb..029b61fd 100644 --- a/src/gui/control/item_list.hpp +++ b/src/gui/control/item_list.hpp @@ -102,7 +102,7 @@ protected: wxSize DoGetBestClientSize() const override; // --------------------------------------------------- : Data - VoidP selected_item; ///< The currently selected item + VoidP selected_item; ///< The currently selected item long selected_item_pos; ///< Position of the selected item in the sorted_list, or -1 if no card is selected long sort_by_column; ///< Column to use for sorting, or -1 if not sorted bool sort_ascending; ///< Sort order diff --git a/src/gui/set/cards_panel.cpp b/src/gui/set/cards_panel.cpp index 3cf1a4b5..db8cd192 100644 --- a/src/gui/set/cards_panel.cpp +++ b/src/gui/set/cards_panel.cpp @@ -489,3 +489,7 @@ void CardsPanel::selectFirstCard() { if (!set) return; // we want onChangeSet first card_list->selectFirst(); } + +void CardsPanel::getCardLists(vector& out) { + out.push_back(card_list); +} \ No newline at end of file diff --git a/src/gui/set/cards_panel.hpp b/src/gui/set/cards_panel.hpp index 85bdae28..9971ec30 100644 --- a/src/gui/set/cards_panel.hpp +++ b/src/gui/set/cards_panel.hpp @@ -75,6 +75,8 @@ public: void selectCard(const CardP& card) override; void selectFirstCard() override; + void getCardLists(vector& out) override; + private: // --------------------------------------------------- : Controls wxSizer* s_left; diff --git a/src/gui/set/panel.hpp b/src/gui/set/panel.hpp index 2e575633..243fa894 100644 --- a/src/gui/set/panel.hpp +++ b/src/gui/set/panel.hpp @@ -12,6 +12,7 @@ #include #include +class CardListBase; class wxFindReplaceData; // ----------------------------------------------------------------------------- : SetWindowPanel @@ -77,7 +78,9 @@ public: virtual void selectCard(const CardP& card) {} ///< Switch the view to another card, can be null virtual void selectFirstCard() {} ///< Switch the view to the first card virtual void selectionChoices(ExportCardSelectionChoices& out) {} ///< Card subsets that can be exported from this panel - + + virtual void getCardLists(vector& out) {} + protected: /// Have any controls been created? bool isInitialized() const; diff --git a/src/gui/set/random_pack_panel.cpp b/src/gui/set/random_pack_panel.cpp index 3cfcd419..8d2f41d0 100644 --- a/src/gui/set/random_pack_panel.cpp +++ b/src/gui/set/random_pack_panel.cpp @@ -632,6 +632,9 @@ void RandomPackPanel::selectionChoices(ExportCardSelectionChoices& out) { )); } +void RandomPackPanel::getCardLists(vector& out) { + if (isInitialized()) out.push_back(card_list); +} BEGIN_EVENT_TABLE(RandomPackPanel, wxPanel) EVT_CARD_SELECT(wxID_ANY, RandomPackPanel::onCardSelect) diff --git a/src/gui/set/random_pack_panel.hpp b/src/gui/set/random_pack_panel.hpp index b20e9fd1..0aa77ed1 100644 --- a/src/gui/set/random_pack_panel.hpp +++ b/src/gui/set/random_pack_panel.hpp @@ -56,7 +56,8 @@ public: CardP selectedCard() const override; void selectCard(const CardP& card) override; void selectionChoices(ExportCardSelectionChoices& out) override; - + void getCardLists(vector& out) override; + // --------------------------------------------------- : Clipboard bool canCopy() const override; diff --git a/src/gui/set/stats_panel.cpp b/src/gui/set/stats_panel.cpp index 5978463b..f31ddc29 100644 --- a/src/gui/set/stats_panel.cpp +++ b/src/gui/set/stats_panel.cpp @@ -566,3 +566,7 @@ void StatsPanel::selectCard(const CardP& card) { card_list->setCard(card); } + +void StatsPanel::getCardLists(vector& out) { + if (isInitialized()) out.push_back(card_list); +} diff --git a/src/gui/set/stats_panel.hpp b/src/gui/set/stats_panel.hpp index 7f167704..1de78b8e 100644 --- a/src/gui/set/stats_panel.hpp +++ b/src/gui/set/stats_panel.hpp @@ -42,7 +42,8 @@ public: // --------------------------------------------------- : Selection CardP selectedCard() const override; void selectCard(const CardP& card) override; - + void getCardLists(vector& out) override; + // --------------------------------------------------- : Data private: DECLARE_EVENT_TABLE(); diff --git a/src/gui/set/window.cpp b/src/gui/set/window.cpp index d7afd521..2e166913 100644 --- a/src/gui/set/window.cpp +++ b/src/gui/set/window.cpp @@ -388,6 +388,14 @@ void SetWindow::selectionChoices(ExportCardSelectionChoices& out) { out.push_back(make_intrusive()); // custom } +vector SetWindow::getCardLists() { + vector out; + FOR_EACH(p, panels) { + p->getCardLists(out); + } + return out; +} + // ----------------------------------------------------------------------------- : Window events - close void SetWindow::onClose(wxCloseEvent& ev) { diff --git a/src/gui/set/window.hpp b/src/gui/set/window.hpp index 657a73c6..f7726f88 100644 --- a/src/gui/set/window.hpp +++ b/src/gui/set/window.hpp @@ -14,6 +14,7 @@ #include class SetWindowPanel; +class CardListBase; class wxFindDialogEvent; struct CardSelectEvent; @@ -30,7 +31,10 @@ public: /// Set the icon of one of the panels void setPanelIcon(SetWindowPanel* panel, wxBitmap const& icon); - + + /// Get all card lists on all panels + vector getCardLists(); + // --------------------------------------------------- : Set actions private: