reapack

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

commit 3f171446662ca7bc2d28a3f5dad44107acdf91a8
parent 341a26e3e1d9659e9c9b60e773820c59b9adc2a1
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Mon, 20 Jun 2016 23:22:23 -0400

listview: allow user to collapse columns

Diffstat:
Msrc/browser.cpp | 2+-
Msrc/listview.cpp | 24++++++++++++++++++++----
Msrc/listview.hpp | 14++++++++++++--
3 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/src/browser.cpp b/src/browser.cpp @@ -80,7 +80,7 @@ void Browser::onInit() SendMessage(m_view, CB_SETCURSEL, 0, 0); m_list = createControl<ListView>(IDC_PACKAGES, ListView::Columns{ - {AUTO_STR(""), 23}, + {AUTO_STR("Status"), 23, ListView::NoLabelFlag}, {AUTO_STR("Package"), 380}, {AUTO_STR("Category"), 150}, {AUTO_STR("Version"), 80}, diff --git a/src/listview.cpp b/src/listview.cpp @@ -58,8 +58,10 @@ void ListView::addColumn(const Column &col) item.mask |= LVCF_WIDTH; item.cx = adjustWidth(col.width); - item.mask |= LVCF_TEXT; - item.pszText = const_cast<auto_char *>(col.text.c_str()); + if(!col.test(NoLabelFlag)) { + item.mask |= LVCF_TEXT; + item.pszText = const_cast<auto_char *>(col.label.c_str()); + } ListView_InsertColumn(handle(), columnCount(), &item); m_cols.push_back(col); @@ -123,7 +125,7 @@ void ListView::resizeColumn(const int index, const int width) ListView_SetColumnWidth(handle(), index, adjustWidth(width)); } -int ListView::columnSize(const int index) const +int ListView::columnWidth(const int index) const { return ListView_GetColumnWidth(handle(), index); } @@ -396,11 +398,25 @@ void ListView::headerMenu(const int x, const int y) enum { ACTION_RESTORE = 800 }; Menu menu; + + for(int i = 0; i < columnCount(); i++) { + const auto id = menu.addAction(m_cols[i].label.c_str(), i | (1 << 8)); + + if(columnWidth(id)) + menu.check(id); + } + + menu.addSeparator(); menu.addAction(AUTO_STR("Reset columns"), ACTION_RESTORE); + const int id = menu.show(x, y, handle()); if(id == ACTION_RESTORE) restoreDefaults(); + else if(id >> 8 == 1) { + const int col = id & 0xff; + resizeColumn(col, columnWidth(col) ? 0 : m_cols[col].width); + } } bool ListView::restore(const string &data, const int userVersion) @@ -503,7 +519,7 @@ string ListView::save() const while(true) { stream << order[i] << FIELD_END - << columnSize(i); + << columnWidth(i); if(++i < columnCount()) stream << RECORD_END; diff --git a/src/listview.hpp b/src/listview.hpp @@ -32,7 +32,17 @@ class ListView : public Control { public: enum SortOrder { AscendingOrder, DescendingOrder }; - struct Column { auto_string text; int width; }; + enum ColumnFlag { + NoLabelFlag = 1<<0, + }; + + struct Column { + auto_string label; + int width; + int flags; + + bool test(ColumnFlag f) const { return (flags & f) != 0; } + }; typedef std::vector<Column> Columns; typedef std::vector<auto_string> Row; @@ -46,7 +56,7 @@ public: void replaceRow(int index, const Row &); void removeRow(int index); void resizeColumn(int index, int width); - int columnSize(int index) const; + int columnWidth(int index) const; void sort(); void sortByColumn(int index, SortOrder order = AscendingOrder, bool user = false); void clear();