diff --git a/src/gui/control/card_list.cpp b/src/gui/control/card_list.cpp index 93dfc0c8..ccf300ee 100644 --- a/src/gui/control/card_list.cpp +++ b/src/gui/control/card_list.cpp @@ -481,7 +481,23 @@ bool CardListBase::compareItems(void* a, void* b) const { // compare sort keys int cmp = smart_compare( va->getSortKey(), vb->getSortKey() ); if (cmp != 0) return cmp < 0; - // equal values, compare alternate sort key + // equal values, compare alternate sort keys + if (sort_by_column2 != sort_by_column && sort_by_column2 >= 0) { + FieldP sort_field2 = column_fields[sort_by_column2]; + ValueP va2 = reinterpret_cast(a)->data[sort_field2]; + ValueP vb2 = reinterpret_cast(b)->data[sort_field2]; + assert(va2 && vb2); + int cmp = smart_compare( va2->getSortKey(), vb2->getSortKey() ); + if (cmp != 0) return cmp < 0; + if (sort_by_column3 != sort_by_column && sort_by_column3 != sort_by_column2 && sort_by_column3 >= 0) { + FieldP sort_field3 = column_fields[sort_by_column3]; + ValueP va3 = reinterpret_cast(a)->data[sort_field3]; + ValueP vb3 = reinterpret_cast(b)->data[sort_field3]; + assert(va3 && vb3); + int cmp = smart_compare( va3->getSortKey(), vb3->getSortKey() ); + if (cmp != 0) return cmp < 0; + } + } if (alternate_sort_field) { ValueP va = reinterpret_cast(a)->data[alternate_sort_field]; ValueP vb = reinterpret_cast(b)->data[alternate_sort_field]; @@ -521,6 +537,8 @@ void CardListBase::rebuild() { GameSettings& gs = settings.gameSettingsFor(*set->game); sort_ascending = gs.sort_cards_ascending; sort_by_column = -1; + sort_by_column2 = -1; + sort_by_column3 = -1; long i = 0; FOR_EACH(f, column_fields) { if (f->name == gs.sort_cards_by) { diff --git a/src/gui/control/item_list.cpp b/src/gui/control/item_list.cpp index 01ebc91a..608f92d2 100644 --- a/src/gui/control/item_list.cpp +++ b/src/gui/control/item_list.cpp @@ -16,7 +16,7 @@ ItemList::ItemList(Window* parent, int id, long additional_style, bool multi_sel) : wxListView(parent, id, wxDefaultPosition, wxDefaultSize, additional_style | wxLC_REPORT | wxLC_VIRTUAL | (multi_sel ? 0 : wxLC_SINGLE_SEL)) , selected_item_pos(-1) - , sort_by_column(-1), sort_ascending(true) + , sort_by_column(-1), sort_by_column2(-1), sort_by_column3(-1), sort_ascending(true) { // create image list wxImageList* il = new wxImageList(18,14); @@ -262,7 +262,9 @@ void ItemList::onColumnClick(wxListEvent& ev) { } else { new_sort_by_column = -1; // 3rd click on same column -> don't sort } - } else { + } else { + sort_by_column3 = sort_by_column2; + sort_by_column2 = sort_by_column; sort_ascending = true; } sortBy(new_sort_by_column, sort_ascending); diff --git a/src/gui/control/item_list.hpp b/src/gui/control/item_list.hpp index b47a0b49..91836534 100644 --- a/src/gui/control/item_list.hpp +++ b/src/gui/control/item_list.hpp @@ -107,6 +107,8 @@ protected: 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 + long sort_by_column2; ///< Previous column used for sorting, or -1 if not sorted + long sort_by_column3; ///< Previous previous column used for sorting, or -1 if not sorted (stable sort aint workin so we doing this I guess) bool sort_ascending; ///< Sort order vector sorted_list; ///< Sorted list of items, can be considered a map: pos->item