reapack

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

commit c7bc5117e424051eab5d6bae8a22f51c43ceeae1
parent b093b692bf7981017e60233cac6d830821093bf8
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Sat, 26 Aug 2017 21:26:52 -0400

listview: update individual cells without replacing the whole row

Diffstat:
Msrc/browser.cpp | 2+-
Msrc/listview.cpp | 28+++++++++++++++-------------
Msrc/listview.hpp | 13+++++++++----
Msrc/manager.cpp | 25++++++++++++++-----------
Msrc/manager.hpp | 7+++----
5 files changed, 42 insertions(+), 33 deletions(-)

diff --git a/src/browser.cpp b/src/browser.cpp @@ -745,7 +745,7 @@ void Browser::updateAction(const int index) updateDisplayLabel(); } else { - m_list->replaceRow(index, entry->makeRow()); + m_list->setCell(index, 0, entry->displayState()); m_list->sort(); // TODO: only re-sort if sorted by status column } diff --git a/src/listview.cpp b/src/listview.cpp @@ -72,8 +72,10 @@ int ListView::addColumn(const Column &col) return index; } -int ListView::addRow(const Row &content) +int ListView::addRow(const Row &row) { + assert(row.size() == m_cols.size()); + LVITEM item{}; item.iItem = rowCount(); @@ -82,25 +84,25 @@ int ListView::addRow(const Row &content) ListView_InsertItem(handle(), &item); - m_rows.resize(item.iItem + 1); // make room for the new row - replaceRow(item.iItem, content, false); + for(size_t i = 0; i < m_cols.size(); i++) + updateCellText(item.iItem, i, row[i]); + + m_rows.push_back(row); return item.iItem; } -void ListView::replaceRow(int index, const Row &content, const bool isUserIndex) +void ListView::setCell(int row, int index, const Cell &cell) { - assert(content.size() == m_cols.size()); + updateCellText(translate(row), index, cell); - m_rows[index] = content; - - if(isUserIndex) - index = translate(index); + m_rows[row][index] = cell; +} - for(int i = 0; i < columnCount(); i++) { - auto_char *text = const_cast<auto_char *>(content[i].value.c_str()); - ListView_SetItemText(handle(), index, i, text); - } +void ListView::updateCellText(int viewRowIndex, int cellIndex, const Cell &cell) +{ + ListView_SetItemText(handle(), viewRowIndex, cellIndex, + const_cast<auto_char *>(cell.value.c_str())); } void ListView::removeRow(const int userIndex) diff --git a/src/listview.hpp b/src/listview.hpp @@ -46,6 +46,7 @@ public: }; struct Cell { + Cell() : data(nullptr) {} Cell(const auto_char *val, void *ptr = nullptr) : value(val), data(ptr) {} Cell(const auto_string &val, void *ptr = nullptr) : value(val), data(ptr) {} @@ -77,19 +78,22 @@ public: ListView(HWND handle, const Columns & = {}); - int addRow(const Row &); + int addRow(const Row &row); const Row &row(int index) const { return m_rows[index]; } - void replaceRow(int index, const Row &, bool isUserIndex = true); + void setCell(int row, int index, const Cell &); void removeRow(int index); int rowCount() const { return (int)m_rows.size(); } - bool empty() const { return rowCount() < 1; } + bool empty() const { return m_rows.empty(); } + void clear(); void reset(); + void autoSizeHeader(); + int currentIndex() const; int itemUnderMouse() const; + int scroll() const; void setScroll(int); - void autoSizeHeader(); void setSelected(int index, bool select); void select(int index) { setSelected(index, true); } @@ -130,6 +134,7 @@ private: }; static int adjustWidth(int); + void updateCellText(int viewRowIndex, int cellIndex, const Cell &); void setExStyle(int style, bool enable); void setSortArrow(bool); void handleDoubleClick(); diff --git a/src/manager.cpp b/src/manager.cpp @@ -24,6 +24,7 @@ #include "errors.hpp" #include "filedialog.hpp" #include "import.hpp" +#include "listview.hpp" #include "menu.hpp" #include "progress.hpp" #include "reapack.hpp" @@ -325,7 +326,12 @@ void Manager::refresh() if(m_uninstall.count(remote)) continue; - const int index = m_list->addRow(makeRow(remote)); + ListView::Row row(3, ListView::Cell{}); + row[0] = make_autostring(remote.name()); + row[1] = make_autostring(remote.url()); + + const int index = m_list->addRow(row); + updateEnabledCell(index, remote); if(find(selected.begin(), selected.end(), remote.name()) != selected.end()) m_list->select(index); @@ -334,6 +340,12 @@ void Manager::refresh() m_list->sort(); } +void Manager::updateEnabledCell(int index, const Remote &remote) +{ + m_list->setCell(index, 2, isRemoteEnabled(remote) ? + AUTO_STR("Enabled") : AUTO_STR("Disabled")); +} + void Manager::setMods(const ModsCallback &cb, const bool updateRow) { for(const int index : m_list->selection()) { @@ -362,7 +374,7 @@ void Manager::setMods(const ModsCallback &cb, const bool updateRow) } if(updateRow) - m_list->replaceRow(index, makeRow(remote)); + updateEnabledCell(index, remote); } if(updateRow) @@ -737,15 +749,6 @@ void Manager::reset() disable(m_apply); } -ListView::Row Manager::makeRow(const Remote &remote) const -{ - const auto_string &name = make_autostring(remote.name()); - const auto_string &url = make_autostring(remote.url()); - - return {name, url, isRemoteEnabled(remote) ? - AUTO_STR("Enabled") : AUTO_STR("Disabled")}; -} - Remote Manager::getRemote(const int index) const { if(index < 0 || index > m_list->rowCount() - 1) diff --git a/src/manager.hpp b/src/manager.hpp @@ -20,13 +20,13 @@ #include "dialog.hpp" -#include "listview.hpp" - #include <boost/logic/tribool.hpp> #include <boost/optional.hpp> #include <map> #include <set> +class ListView; +class Menu; class Remote; struct NetworkOpts; @@ -55,10 +55,9 @@ private: typedef std::function<void (const Remote &, RemoteMods *)> ModsCallback; - ListView::Row makeRow(const Remote &) const; - Remote getRemote(int index) const; bool fillContextMenu(Menu &, int index) const; + void updateEnabledCell(int index, const Remote &); void setMods(const ModsCallback &, bool updateRow); void setRemoteEnabled(bool); bool isRemoteEnabled(const Remote &) const;