From a2a4cbdb3f60e2ea77da7376edc852d3effdfb89 Mon Sep 17 00:00:00 2001 From: darylE Date: Mon, 26 Feb 2024 11:40:03 -0500 Subject: [PATCH] More tweaks to the import dialog #4364 --- xLights/xLightsImportChannelMapDialog.cpp | 41 +++++++++++++++++------ 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/xLights/xLightsImportChannelMapDialog.cpp b/xLights/xLightsImportChannelMapDialog.cpp index cde9a5659..5192e8f39 100644 --- a/xLights/xLightsImportChannelMapDialog.cpp +++ b/xLights/xLightsImportChannelMapDialog.cpp @@ -69,6 +69,24 @@ int wxCALLBACK MyCompareFunctionDescEffects(wxIntPtr item1, wxIntPtr item2, wxIn return it1 == it2 ? 0 : ((it1 < it2) ? 1 : -1); } +int wxCALLBACK MyCompareFunctionAscName(wxIntPtr item1, wxIntPtr item2, wxIntPtr sortData) +{ + wxListCtrl* list = (wxListCtrl*)sortData; + auto i1 = list->GetItemText(item1, 0); + auto i2 = list->GetItemText(item2, 0); + + return i1.Cmp(i2); +} + +int wxCALLBACK MyCompareFunctionDescName(wxIntPtr item1, wxIntPtr item2, wxIntPtr sortData) +{ + wxListCtrl* list = (wxListCtrl*)sortData; + auto i1 = list->GetItemText(item1, 0); + auto i2 = list->GetItemText(item2, 0); + + return i2.Cmp(i1); +} + class MDDropSource : public wxDropSource { xLightsImportChannelMapDialog* _window; @@ -197,13 +215,8 @@ int xLightsImportTreeModel::Compare(const wxDataViewItem& item1, const wxDataVie else { return NumberAwareStringCompareRev(node1->_node.ToStdString(), node2->_node.ToStdString()); } - } else if (node1->_strand != "" && node2->_strand != "") { - if (ascending) { - return NumberAwareStringCompare(node1->_strand.ToStdString(), node2->_strand.ToStdString()); - } - else { - return NumberAwareStringCompareRev(node1->_strand.ToStdString(), node2->_strand.ToStdString()); - } + } else if (node1->_strand != "" && node2->_strand != "") { // dont sort the submodels + return 1; } else { @@ -808,6 +821,7 @@ bool xLightsImportChannelMapDialog::InitImport(std::string checkboxText) { TreeListCtrl_Mapping->Freeze(); TreeListCtrl_Mapping->AssociateModel(_dataModel); TreeListCtrl_Mapping->AppendColumn(new wxDataViewColumn("Model", new wxDataViewTextRenderer("string", wxDATAVIEW_CELL_INERT, wxALIGN_LEFT), 0, 150, wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE)); + TreeListCtrl_Mapping->GetColumn(0)->SetSortOrder(true); TreeListCtrl_Mapping->AppendColumn(new wxDataViewColumn("Map To", new wxDataViewTextRenderer("string", wxDATAVIEW_CELL_ACTIVATABLE, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL), 1, 150, wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE)); if (_allowColorChoice) { TreeListCtrl_Mapping->AppendColumn(new wxDataViewColumn("Color", new ColorRenderer(), 2, 150, wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE)); @@ -929,6 +943,7 @@ void xLightsImportChannelMapDialog::PopulateAvailable(bool ccr) _sortOrder = 1; ListCtrl_Available->SortItems(MyCompareFunctionAsc, (wxIntPtr)ListCtrl_Available); + ListCtrl_Available->ShowSortIndicator(0, true); // Set Autosize Width after it is populated or it doesn't work ListCtrl_Available->SetColumnWidth(0, wxLIST_AUTOSIZE); @@ -1831,10 +1846,14 @@ void xLightsImportChannelMapDialog::OnListCtrl_AvailableColumnClick(wxListEvent& if (event.m_col == 0) { if (_sortOrder == 0) { _sortOrder = 1; - ListCtrl_Available->SortItems(MyCompareFunctionAsc, (wxIntPtr)ListCtrl_Available); - } else { + ListCtrl_Available->SortItems(MyCompareFunctionAsc, (wxIntPtr)ListCtrl_Available); // put it back in start order as otherwise this does not work + ListCtrl_Available->SortItems(MyCompareFunctionAscName, (wxIntPtr)ListCtrl_Available); + ListCtrl_Available->ShowSortIndicator(0, true); + } else { _sortOrder = 0; - ListCtrl_Available->SortItems(MyCompareFunctionDesc, (wxIntPtr)ListCtrl_Available); + ListCtrl_Available->SortItems(MyCompareFunctionAsc, (wxIntPtr)ListCtrl_Available); // put it back in start order as otherwise this does not work + ListCtrl_Available->SortItems(MyCompareFunctionDescName, (wxIntPtr)ListCtrl_Available); + ListCtrl_Available->ShowSortIndicator(0, false); } } else if (event.m_col == 1) @@ -1843,10 +1862,12 @@ void xLightsImportChannelMapDialog::OnListCtrl_AvailableColumnClick(wxListEvent& _sortOrder = 4; ListCtrl_Available->SortItems(MyCompareFunctionAsc, (wxIntPtr)ListCtrl_Available); // put it back in start order as otherwise this does not work ListCtrl_Available->SortItems(MyCompareFunctionAscEffects, (wxIntPtr)ListCtrl_Available); + ListCtrl_Available->ShowSortIndicator(1, true); } else { _sortOrder = 3; ListCtrl_Available->SortItems(MyCompareFunctionAsc, (wxIntPtr)ListCtrl_Available); // put it back in start order as otherwise this does not work ListCtrl_Available->SortItems(MyCompareFunctionDescEffects, (wxIntPtr)ListCtrl_Available); + ListCtrl_Available->ShowSortIndicator(1, false); } } }