reapack

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

commit a7212d7d28006eb1ce718e0df50bcdcca44e1b66
parent 09095a71c9c285f4120f04573962c8151d401326
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Tue, 24 Oct 2017 00:33:23 -0700

listview: disable GUI updates when filtering on Windows, re-sort after updating status cell on apply and refactoring

Diffstat:
Msrc/about.cpp | 6++----
Msrc/browser.cpp | 8+++-----
Msrc/control.cpp | 3++-
Msrc/listview.cpp | 2+-
Msrc/listview.hpp | 15++++++++++++++-
Msrc/manager.cpp | 8+++-----
6 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/src/about.cpp b/src/about.cpp @@ -152,9 +152,9 @@ void About::setDelegate(const DelegatePtr &delegate, const bool focus) for(const int control : controls) hide(getControl(control)); + ListView::BeginEdit menuEdit(m_menu); m_delegate = delegate; m_delegate->init(this); - m_menu->endEdit(); m_currentIndex = -255; updateList(); @@ -265,13 +265,11 @@ void About::updateList() if((index < 0 && m_currentIndex != -255) || index == m_currentIndex) return; - InhibitControl lock(m_list); + ListView::BeginEdit edit(m_list); m_list->clear(); m_delegate->updateList(index); m_currentIndex = index; - - m_list->endEdit(); } AboutIndexDelegate::AboutIndexDelegate(const IndexPtr &index) diff --git a/src/browser.cpp b/src/browser.cpp @@ -509,7 +509,7 @@ void Browser::transferActions() void Browser::fillList() { - InhibitControl freeze(m_list); + ListView::BeginEdit edit(m_list); const int scroll = m_list->scroll(); @@ -537,7 +537,6 @@ void Browser::fillList() } m_list->setScroll(scroll); - m_list->endEdit(); // restore selection only after having sorted the table // in order to get the same scroll position as before if possible @@ -757,7 +756,7 @@ void Browser::updateAction(const int index) void Browser::selectionDo(const function<void (int)> &func) { - InhibitControl freeze(m_list); + ListView::BeginEdit edit(m_list); int lastSize = m_list->rowCount(); int offset = 0; @@ -771,8 +770,6 @@ void Browser::selectionDo(const function<void (int)> &func) offset++; lastSize = newSize; } - - m_list->endEdit(); // re-sort if required } auto Browser::currentView() const -> View @@ -842,6 +839,7 @@ bool Browser::apply() if(!tx->runTasks()) { // this is an asynchronous transaction // update the state column right away to give visual feedback + ListView::BeginEdit edit(m_list); for(int i = 0, count = m_list->rowCount(); i < count; ++i) updateAction(i); } diff --git a/src/control.cpp b/src/control.cpp @@ -37,7 +37,8 @@ void InhibitControl::inhibitRedraw(const bool inhibit) s_lock.insert({m_handle, this}); else { s_lock.erase(m_handle); - InvalidateRect(m_handle, nullptr, true); + RedrawWindow(m_handle, nullptr, nullptr, + RDW_ERASE | RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN); } #endif } diff --git a/src/listview.cpp b/src/listview.cpp @@ -251,9 +251,9 @@ void ListView::filter() void ListView::setFilter(const string &newFilter) { if(m_filter != newFilter) { + ListView::BeginEdit edit(this); m_filter = newFilter; m_dirty |= NeedFilterFlag; - endEdit(); } } diff --git a/src/listview.hpp b/src/listview.hpp @@ -91,6 +91,18 @@ public: int compare(const Cell &, const Cell &) const; }; + // Use before modifying the list's content. It will re-sort and/or re-filter the + // list automatically when destructed and, on Windows, also prevents flickering. + class BeginEdit { + public: + BeginEdit(ListView *lv) : m_list(lv), m_inhibit(lv) {} + ~BeginEdit() { m_list->endEdit(); } + + private: + ListView *m_list; + InhibitControl m_inhibit; + }; + typedef std::vector<Column> Columns; typedef boost::signals2::signal<void ()> VoidSignal; @@ -133,7 +145,6 @@ public: void sortByColumn(int index, SortOrder order = AscendingOrder, bool user = false); void setFilter(const std::string &); - void endEdit(); void restoreState(Serializer::Data &); void saveState(Serializer::Data &) const; @@ -145,7 +156,9 @@ public: protected: friend Row; + friend BeginEdit; void updateCell(int row, int cell); + void endEdit(); private: struct Sort { diff --git a/src/manager.cpp b/src/manager.cpp @@ -309,7 +309,7 @@ bool Manager::onKeyDown(const int key, const int mods) void Manager::refresh() { - InhibitControl lock(m_list); + ListView::BeginEdit edit(m_list); const vector<int> selection = m_list->selection(); vector<string> selected(selection.size()); @@ -334,8 +334,6 @@ void Manager::refresh() if(find(selected.begin(), selected.end(), remote.name()) != selected.end()) m_list->select(row->index()); } - - m_list->endEdit(); } void Manager::updateEnabledCell(int index, const Remote &remote) @@ -345,6 +343,8 @@ void Manager::updateEnabledCell(int index, const Remote &remote) void Manager::setMods(const ModsCallback &cb, const bool updateRow) { + ListView::BeginEdit edit(m_list); + for(const int index : m_list->selection()) { const Remote &remote = getRemote(index); @@ -373,8 +373,6 @@ void Manager::setMods(const ModsCallback &cb, const bool updateRow) if(updateRow) updateEnabledCell(index, remote); } - - m_list->endEdit(); // re-sort if required } void Manager::setRemoteEnabled(const bool enabled)