reapack

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

commit bb563b4764d75f4a33de4416411f9b87bdfd1a0c
parent 62f2c935e64cf9cba9f1662f8d7c091c54e29bd3
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Wed, 21 Sep 2016 22:10:54 -0400

refactor timers and stop the browser's filter timer when idle

Diffstat:
Msrc/browser.cpp | 25+++++++++++++------------
Msrc/browser.hpp | 4+---
Msrc/dialog.cpp | 6++++--
Msrc/dialog.hpp | 2+-
Msrc/import.cpp | 6++++--
5 files changed, 23 insertions(+), 20 deletions(-)

diff --git a/src/browser.cpp b/src/browser.cpp @@ -52,9 +52,11 @@ enum Action { ACTION_MANAGE, }; +enum Timers { TIMER_FILTER = 100 }; + Browser::Browser(ReaPack *reapack) : Dialog(IDD_BROWSER_DIALOG), m_reapack(reapack), - m_loading(false), m_loaded(false), m_checkFilter(false), m_currentIndex(-1) + m_loading(false), m_loaded(false), m_currentIndex(-1) { } @@ -128,8 +130,6 @@ void Browser::onInit() return a.latest->time().compare(b.latest->time()); }); - m_filterTimer = startTimer(200); - Dialog::onInit(); setAnchor(m_filterHandle, AnchorRight); setAnchor(getControl(IDC_CLEAR), AnchorLeftRight); @@ -164,7 +164,8 @@ void Browser::onCommand(const int id, const int event) displayButton(); break; case IDC_FILTER: - m_checkFilter = true; + if(event == EN_CHANGE) + startTimer(200, TIMER_FILTER, false); break; case IDC_CLEAR: setFilter({}); @@ -283,8 +284,11 @@ void Browser::onClose() void Browser::onTimer(const int id) { - if(id == m_filterTimer) - checkFilter(); + switch(id) { + case TIMER_FILTER: + updateFilter(); + break; + } } void Browser::onSelection() @@ -493,12 +497,9 @@ void Browser::toggleDescs() fillList(); } -void Browser::checkFilter() +void Browser::updateFilter() { - if(!m_checkFilter) - return; - - m_checkFilter = false; + stopTimer(TIMER_FILTER); auto_string wideFilter(4096, 0); GetWindowText(m_filterHandle, &wideFilter[0], (int)wideFilter.size()); @@ -554,7 +555,7 @@ void Browser::refresh(const bool stale) void Browser::setFilter(const string &newFilter) { SetWindowText(m_filterHandle, make_autostring(newFilter).c_str()); - checkFilter(); + updateFilter(); // don't wait for the timer, update now! SetFocus(m_filterHandle); } diff --git a/src/browser.hpp b/src/browser.hpp @@ -108,7 +108,7 @@ private: void populate(const std::vector<IndexPtr> &); void transferActions(); bool match(const Entry &) const; - void checkFilter(); + void updateFilter(); void fillList(); std::string getValue(Column, const Entry &entry) const; ListView::Row makeRow(const Entry &) const; @@ -141,10 +141,8 @@ private: ReaPack *m_reapack; bool m_loading; bool m_loaded; - bool m_checkFilter; int m_currentIndex; - int m_filterTimer; Filter m_filter; boost::optional<Package::Type> m_typeFilter; std::vector<Entry> m_entries; diff --git a/src/dialog.cpp b/src/dialog.cpp @@ -286,14 +286,16 @@ void Dialog::setEnabled(const bool enabled, HWND handle) EnableWindow(handle, enabled); } -int Dialog::startTimer(const int ms, int id) +int Dialog::startTimer(const int ms, int id, const bool replace) { if(id == 0) { if(m_timers.empty()) id = 1; else - id = *m_timers.rbegin(); + id = *m_timers.rbegin() + 1; } + else if(!replace && m_timers.count(id)) + return 0; m_timers.insert(id); SetTimer(m_handle, id, ms, nullptr); diff --git a/src/dialog.hpp b/src/dialog.hpp @@ -99,7 +99,7 @@ public: void boundedMove(int x, int y); bool hasFocus() const; void setFocus(); - int startTimer(int elapse, int id = 0); + int startTimer(int elapse, int id = 0, bool replace = true); void stopTimer(int id); void setClipboard(const std::string &); void setClipboard(const std::vector<std::string> &); diff --git a/src/import.cpp b/src/import.cpp @@ -213,10 +213,12 @@ void Import::setWaiting(const bool wait) setEnabled(!wait, m_url); #ifndef PBM_SETMARQUEE + const int timerId = 1; + if(wait) - startTimer(42, 1); + startTimer(42, timerId); else - stopTimer(1); + stopTimer(timerId); m_fakePos = 0; SendMessage(m_progress, PBM_SETPOS, 0, 0);