Skip to content

Commit

Permalink
Card list sorting is now handled per window (closes #71)
Browse files Browse the repository at this point in the history
  • Loading branch information
twanvl committed Jun 14, 2020
1 parent 14fac16 commit a7336d6
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 26 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
47 changes: 28 additions & 19 deletions src/gui/control/card_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <util/prec.hpp>
#include <gui/control/card_list.hpp>
#include <gui/control/card_list_column_select.hpp>
#include <gui/set/window.hpp> // for sorting all cardlists in a window
#include <gui/util.hpp>
#include <data/game.hpp>
#include <data/field.hpp>
Expand Down Expand Up @@ -44,19 +45,12 @@ CardListBase* CardSelectEvent::getTheCardList() const {

// ----------------------------------------------------------------------------- : CardListBase

vector<CardListBase*> 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() {
Expand Down Expand Up @@ -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<SetWindow*>(wxGetTopLevelParent(this));
if (set_window) {
for (auto card_list : set_window->getCardLists()) {
if (card_list != this) {
card_list->ItemList::sortBy(column, ascending);
}
}
}
}
Expand All @@ -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<SetWindow*>(wxGetTopLevelParent(this));
if (set_window) {
for (auto card_list : set_window->getCardLists()) {
if (card_list != this) {
card_list->rebuild();
}
}
}
}
Expand Down Expand Up @@ -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<SetWindow*>(wxGetTopLevelParent(this));
if (set_window) {
for (auto card_list : set_window->getCardLists()) {
if (card_list != this) {
card_list->SetColumnWidth(col, width);
}
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/gui/control/card_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ class CardListBase : public ItemList, public SetView {
private:
/// Store the column sizes in the settings
void storeColumns();
/// All card lists; used to exchange column sizes
static vector<CardListBase*> card_lists;

// --------------------------------------------------- : Window events
DECLARE_EVENT_TABLE();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/control/item_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class ItemList : public wxListView {
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
Expand Down
4 changes: 4 additions & 0 deletions src/gui/set/cards_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,3 +489,7 @@ void CardsPanel::selectFirstCard() {
if (!set) return; // we want onChangeSet first
card_list->selectFirst();
}

void CardsPanel::getCardLists(vector<CardListBase*>& out) {
out.push_back(card_list);
}
2 changes: 2 additions & 0 deletions src/gui/set/cards_panel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class CardsPanel : public SetWindowPanel {
void selectCard(const CardP& card) override;
void selectFirstCard() override;

void getCardLists(vector<CardListBase*>& out) override;

private:
// --------------------------------------------------- : Controls
wxSizer* s_left;
Expand Down
5 changes: 4 additions & 1 deletion src/gui/set/panel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <data/set.hpp>
#include <gui/card_select_window.hpp>

class CardListBase;
class wxFindReplaceData;

// ----------------------------------------------------------------------------- : SetWindowPanel
Expand Down Expand Up @@ -77,7 +78,9 @@ class SetWindowPanel : public wxPanel, public SetView {
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<CardListBase*>& out) {}

protected:
/// Have any controls been created?
bool isInitialized() const;
Expand Down
3 changes: 3 additions & 0 deletions src/gui/set/random_pack_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,9 @@ void RandomPackPanel::selectionChoices(ExportCardSelectionChoices& out) {
));
}

void RandomPackPanel::getCardLists(vector<CardListBase*>& out) {
if (isInitialized()) out.push_back(card_list);
}

BEGIN_EVENT_TABLE(RandomPackPanel, wxPanel)
EVT_CARD_SELECT(wxID_ANY, RandomPackPanel::onCardSelect)
Expand Down
3 changes: 2 additions & 1 deletion src/gui/set/random_pack_panel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class RandomPackPanel : public SetWindowPanel {
CardP selectedCard() const override;
void selectCard(const CardP& card) override;
void selectionChoices(ExportCardSelectionChoices& out) override;

void getCardLists(vector<CardListBase*>& out) override;

// --------------------------------------------------- : Clipboard

bool canCopy() const override;
Expand Down
4 changes: 4 additions & 0 deletions src/gui/set/stats_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,3 +566,7 @@ void StatsPanel::selectCard(const CardP& card) {
card_list->setCard(card);

}

void StatsPanel::getCardLists(vector<CardListBase*>& out) {
if (isInitialized()) out.push_back(card_list);
}
3 changes: 2 additions & 1 deletion src/gui/set/stats_panel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class StatsPanel : public SetWindowPanel {
// --------------------------------------------------- : Selection
CardP selectedCard() const override;
void selectCard(const CardP& card) override;

void getCardLists(vector<CardListBase*>& out) override;

// --------------------------------------------------- : Data
private:
DECLARE_EVENT_TABLE();
Expand Down
8 changes: 8 additions & 0 deletions src/gui/set/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,14 @@ void SetWindow::selectionChoices(ExportCardSelectionChoices& out) {
out.push_back(make_intrusive<ExportCardSelectionChoice>()); // custom
}

vector<CardListBase*> SetWindow::getCardLists() {
vector<CardListBase*> out;
FOR_EACH(p, panels) {
p->getCardLists(out);
}
return out;
}

// ----------------------------------------------------------------------------- : Window events - close

void SetWindow::onClose(wxCloseEvent& ev) {
Expand Down
6 changes: 5 additions & 1 deletion src/gui/set/window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <gui/card_select_window.hpp>

class SetWindowPanel;
class CardListBase;
class wxFindDialogEvent;
struct CardSelectEvent;

Expand All @@ -30,7 +31,10 @@ class SetWindow : public wxFrame, public SetView {

/// Set the icon of one of the panels
void setPanelIcon(SetWindowPanel* panel, wxBitmap const& icon);


/// Get all card lists on all panels
vector<CardListBase*> getCardLists();

// --------------------------------------------------- : Set actions

private:
Expand Down

0 comments on commit a7336d6

Please sign in to comment.