reapack

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

commit 2cb25492e14e5f5379ac4a9bf77220a9f36266c2
parent 8d5cafcddcaa5121a2e7e4d6b6399e00fc7aaf05
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Sat,  8 Oct 2016 19:18:54 -0400

about pkg: auto-select the current version when opened from the browser

(instead of always selecting the latest version)

Diffstat:
Msrc/about.cpp | 19+++++++++++++------
Msrc/about.hpp | 4+++-
Msrc/browser.cpp | 13+++++++------
3 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/src/about.cpp b/src/about.cpp @@ -405,7 +405,7 @@ void AboutIndexDelegate::findInBrowser() void AboutIndexDelegate::aboutPackage() { const Package *pkg = currentPackage(); - m_dialog->setDelegate(make_shared<AboutPackageDelegate>(pkg, m_reapack)); + m_dialog->setDelegate(make_shared<AboutPackageDelegate>(pkg, nullptr, m_reapack)); } void AboutIndexDelegate::install() @@ -442,8 +442,9 @@ void AboutIndexDelegate::install() tx->runTasks(); } -AboutPackageDelegate::AboutPackageDelegate(const Package *pkg, ReaPack *reapack) - : m_package(pkg), m_reapack(reapack), +AboutPackageDelegate::AboutPackageDelegate(const Package *pkg, + const Version *ver, ReaPack *reapack) + : m_package(pkg), m_current(ver), m_reapack(reapack), m_index(pkg->category()->index()->shared_from_this()) { } @@ -466,15 +467,21 @@ void AboutPackageDelegate::init(About *dialog) dialog->list()->addColumn({AUTO_STR("File"), 474}); dialog->list()->addColumn({AUTO_STR("Action List"), 84}); - for(const Version *ver : m_package->versions()) - dialog->menu()->addRow({make_autostring(ver->name())}); + for(const Version *ver : m_package->versions()) { + const auto index = dialog->menu()->addRow({make_autostring(ver->name())}); + + if(m_current && *ver == *m_current) + dialog->menu()->select(index); + } dialog->menu()->setSortCallback(0, [&] (const int a, const int b) { return m_package->version(a)->compare(*m_package->version(b)); }); dialog->menu()->sortByColumn(0, ListView::DescendingOrder); - dialog->menu()->setSelected(dialog->menu()->rowCount() - 1, true); + + if(!dialog->menu()->hasSelection()) + dialog->menu()->select(dialog->menu()->rowCount() - 1); } void AboutPackageDelegate::updateList(const int index) diff --git a/src/about.hpp b/src/about.hpp @@ -34,6 +34,7 @@ class ReaPack; class RichEdit; class Source; class TabBar; +class Version; struct Link; typedef std::shared_ptr<const Index> IndexPtr; @@ -119,7 +120,7 @@ private: class AboutPackageDelegate : public AboutDelegate { public: - AboutPackageDelegate(const Package *, ReaPack *); + AboutPackageDelegate(const Package *, const Version *current, ReaPack *); protected: void init(About *) override; @@ -134,6 +135,7 @@ private: void copySourceUrl(); const Package *m_package; + const Version *m_current; ReaPack *m_reapack; IndexPtr m_index; // keeps the package loaded in memory const std::vector<const Source *> *m_sources; diff --git a/src/browser.cpp b/src/browser.cpp @@ -511,15 +511,16 @@ void Browser::updateAbout() stopTimer(TIMER_ABOUT); About *about = m_reapack->about(false); - const Entry *entry = getEntry(m_list->currentIndex()); - if(!about || !entry) + if(!about) return; + const auto index = m_list->currentIndex(); + if(about->testDelegate<AboutIndexDelegate>()) - about->setDelegate(make_shared<AboutIndexDelegate>(entry->index, m_reapack), false); - else if(about->testDelegate<AboutPackageDelegate>() && entry->package) - about->setDelegate(make_shared<AboutPackageDelegate>(entry->package, m_reapack), false); + aboutRemote(index); + else if(about->testDelegate<AboutPackageDelegate>()) + aboutPackage(index); } void Browser::refresh(const bool stale) @@ -848,7 +849,7 @@ void Browser::aboutPackage(const int index) const Entry *entry = getEntry(index); if(entry && entry->package) - m_reapack->about()->setDelegate(make_shared<AboutPackageDelegate>(entry->package, m_reapack)); + m_reapack->about()->setDelegate(make_shared<AboutPackageDelegate>(entry->package, entry->current, m_reapack)); } void Browser::aboutRemote(const int index)