reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

commit 717ba84604faa1e1b1c69aff6c83089bfdaf470f
parent 19eb74526fa09e5507fc70757a0ba638cfb01763
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Wed,  3 Feb 2016 19:47:55 -0500

enable list view sorting on the repository list

Diffstat:
Msrc/listview.cpp | 41++++++++++++++++++++++++++++++++++-------
Msrc/listview.hpp | 3++-
Msrc/manager.cpp | 3+++
Msrc/resource.rc | 4++--
4 files changed, 41 insertions(+), 10 deletions(-)

diff --git a/src/listview.cpp b/src/listview.cpp @@ -72,11 +72,12 @@ int ListView::addRow(const Row &content) return item.iItem; } -void ListView::replaceRow(const int index, const Row &content) +void ListView::replaceRow(int index, const Row &content) { m_rows[index] = content; const int cols = min(m_columnSize, (int)content.size()); + index = translate(index); for(int i = 0; i < cols; i++) { auto_char *text = const_cast<auto_char *>(content[i].c_str()); @@ -84,20 +85,28 @@ void ListView::replaceRow(const int index, const Row &content) } } -void ListView::removeRow(const int index) +void ListView::removeRow(const int userIndex) { - ListView_DeleteItem(handle(), index); - m_rows.erase(m_rows.begin() + index); + // translate to view index before fixing lParams + const int viewIndex = translate(userIndex); // shift lParam to reflect the new row indexes + map<int, int> translations; const int size = rowCount(); - for(int i = index; i < size; i++) { + for(int i = userIndex + 1; i < size; i++) + translations[translate(i)] = i - 1; + + for(const auto &it : translations) { LVITEM item{}; - item.iItem = i; + item.iItem = it.first; item.mask |= LVIF_PARAM; - item.lParam = i; + item.lParam = it.second; ListView_SetItem(handle(), &item); } + + ListView_DeleteItem(handle(), viewIndex); + m_rows.erase(m_rows.begin() + userIndex); + } void ListView::resizeColumn(const int index, const int width) @@ -228,3 +237,21 @@ void ListView::onColumnClick(LPARAM lParam) sortByColumn(col, order); } + +int ListView::translate(const int userIndex) const +{ + if(m_sortColumn < 0) + return userIndex; + + for(int viewIndex = 0; viewIndex < rowCount(); viewIndex++) { + LVITEM item{}; + item.iItem = viewIndex; + item.mask |= LVIF_PARAM; + ListView_GetItem(handle(), &item); + + if(item.lParam == userIndex) + return viewIndex; + } + + return -1; +} diff --git a/src/listview.hpp b/src/listview.hpp @@ -49,7 +49,7 @@ public: bool hasSelection() const; int currentIndex() const; - int rowCount() { return (int)m_rows.size(); } + int rowCount() const { return (int)m_rows.size(); } void onSelect(const Callback &callback) { m_onSelect.connect(callback); } void onDoubleClick(const Callback &callback) @@ -63,6 +63,7 @@ private: void addColumn(const Column &); void setSortArrow(bool); void onColumnClick(LPARAM lpnmlistview); + int translate(int index) const; int m_columnSize; int m_sortColumn; diff --git a/src/manager.cpp b/src/manager.cpp @@ -136,6 +136,7 @@ void Manager::onContextMenu(HWND target, const int x, const int y) void Manager::refresh() { + InhibitControl lock(m_list); m_list->clear(); for(const Remote &remote : *m_reapack->config()->remotes()) { @@ -143,6 +144,8 @@ void Manager::refresh() m_list->addRow(makeRow(remote)); } + m_list->sort(); + #ifdef LVSCW_AUTOSIZE_USEHEADER m_list->resizeColumn(2, LVSCW_AUTOSIZE_USEHEADER); #endif diff --git a/src/resource.rc b/src/resource.rc @@ -31,8 +31,8 @@ FONT DIALOG_FONT CAPTION "ReaPack Configuration" BEGIN LTEXT "Remote repositories:", IDC_LABEL, 5, 5, 320, 10 - CONTROL "", IDC_LIST, WC_LISTVIEW, WS_BORDER | LVS_REPORT | LVS_SINGLESEL | - LVS_SHOWSELALWAYS | LVS_NOSORTHEADER | WS_TABSTOP, 5, 18, 320, 136 + CONTROL "", IDC_LIST, WC_LISTVIEW, LVS_REPORT | LVS_SINGLESEL | + LVS_SHOWSELALWAYS | WS_BORDER | WS_TABSTOP, 5, 18, 320, 136 PUSHBUTTON "&Import...", IDC_IMPORT, 5, 160, 45, 14 DEFPUSHBUTTON "&OK", IDOK, 240, 160, 40, 14 PUSHBUTTON "&Cancel", IDCANCEL, 284, 160, 40, 14