reapack

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

commit 5c47b72847c06074d4c31f066f8defd4349f66b9
parent 6b37b62dabd37a0604cbb1a1fa8ec8ff131895d5
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Thu,  5 Jan 2017 03:36:53 -0500

about: refactoring – move ReaPack pointer up to the dialog

Diffstat:
Msrc/about.cpp | 37+++++++++++++++++++++----------------
Msrc/about.hpp | 10+++++-----
Msrc/browser.cpp | 6+++---
Msrc/manager.cpp | 2+-
Msrc/reapack.cpp | 4++--
5 files changed, 32 insertions(+), 27 deletions(-)

diff --git a/src/about.cpp b/src/about.cpp @@ -45,7 +45,8 @@ enum { ACTION_COPY_URL, ACTION_LOCATE }; -About::About() : Dialog(IDD_ABOUT_DIALOG) +About::About(ReaPack *reapack) + : Dialog(IDD_ABOUT_DIALOG), m_reapack(reapack) { } @@ -269,8 +270,8 @@ void About::updateList() m_list->sort(); } -AboutIndexDelegate::AboutIndexDelegate(const IndexPtr &index, ReaPack *reapack) - : m_index(index), m_reapack(reapack) +AboutIndexDelegate::AboutIndexDelegate(const IndexPtr &index) + : m_index(index) { } @@ -412,12 +413,13 @@ const Package *AboutIndexDelegate::currentPackage() const void AboutIndexDelegate::findInBrowser() { - Browser *browser = m_reapack->browsePackages(); + ReaPack *reapack = m_dialog->reapack(); + Browser *browser = reapack->browsePackages(); if(!browser) return; const Package *pkg = currentPackage(); - const string &name = pkg->displayName(m_reapack->config()->browser.showDescs); + const string &name = pkg->displayName(reapack->config()->browser.showDescs); ostringstream stream; stream << '^' << quoted(name) << "$ ^" << quoted(m_index->name()) << '$'; @@ -436,13 +438,15 @@ void AboutIndexDelegate::aboutPackage() } catch(const reapack_error &) {} - m_dialog->setDelegate(make_shared<AboutPackageDelegate>(pkg, current, m_reapack)); + m_dialog->setDelegate(make_shared<AboutPackageDelegate>(pkg, current)); } void AboutIndexDelegate::itemCopy() { + Config *config = m_dialog->reapack()->config(); + if(const Package *pkg = currentPackage()) - m_dialog->setClipboard(pkg->displayName(m_reapack->config()->browser.showDescs)); + m_dialog->setClipboard(pkg->displayName(config->browser.showDescs)); } void AboutIndexDelegate::install() @@ -458,7 +462,8 @@ void AboutIndexDelegate::install() if(!choice) return; - Remote remote = m_reapack->remote(m_index->name()); + ReaPack *reapack = m_dialog->reapack(); + Remote remote = reapack->remote(m_index->name()); if(!remote) { // In case the user uninstalled the repository while this dialog was opened @@ -468,7 +473,7 @@ void AboutIndexDelegate::install() return; } - const InstallOpts &installOpts = m_reapack->config()->install; + const InstallOpts &installOpts = reapack->config()->install; if(choice == INSTALL_ALL && boost::logic::indeterminate(remote.autoInstall()) && !installOpts.autoInstall) { @@ -482,27 +487,27 @@ void AboutIndexDelegate::install() switch(btn) { case IDYES: remote.setAutoInstall(true); - m_reapack->config()->remotes.add(remote); + reapack->config()->remotes.add(remote); break; case IDCANCEL: return; } } - Transaction *tx = m_reapack->setupTransaction(); + Transaction *tx = reapack->setupTransaction(); if(!tx) return; - m_reapack->enable(remote); + reapack->enable(remote); tx->synchronize(remote, choice == INSTALL_ALL); tx->runTasks(); } -AboutPackageDelegate::AboutPackageDelegate(const Package *pkg, - const VersionName &ver, ReaPack *reapack) - : m_package(pkg), m_current(ver), m_reapack(reapack), +AboutPackageDelegate::AboutPackageDelegate( + const Package *pkg, const VersionName &ver) + : m_package(pkg), m_current(ver), m_index(pkg->category()->index()->shared_from_this()) { } @@ -608,7 +613,7 @@ void AboutPackageDelegate::onCommand(const int id) { switch(id) { case IDC_ACTION: - m_dialog->setDelegate(make_shared<AboutIndexDelegate>(m_index, m_reapack)); + m_dialog->setDelegate(make_shared<AboutIndexDelegate>(m_index)); break; case ACTION_COPY_URL: copySourceUrl(); diff --git a/src/about.hpp b/src/about.hpp @@ -42,7 +42,7 @@ class About : public Dialog { public: typedef std::shared_ptr<AboutDelegate> DelegatePtr; - About(); + About(ReaPack *); void setDelegate(const DelegatePtr &, bool focus = true); template<typename T> bool testDelegate() { return dynamic_cast<T *>(m_delegate.get()) != nullptr; } @@ -51,6 +51,7 @@ public: void setMetadata(const Metadata *, bool substitution = false); void setAction(const std::string &); + ReaPack *reapack() const { return m_reapack; } TabBar *tabs() const { return m_tabs; } RichEdit *desc() const { return m_desc; } ListView *menu() const { return m_menu; } @@ -69,6 +70,7 @@ private: int m_currentIndex; std::map<int, std::vector<const Link *> > m_links; + ReaPack *m_reapack; TabBar *m_tabs; RichEdit *m_desc; ListView *m_menu; @@ -93,7 +95,7 @@ protected: class AboutIndexDelegate : public AboutDelegate { public: - AboutIndexDelegate(const IndexPtr &, ReaPack *); + AboutIndexDelegate(const IndexPtr &); protected: void init(About *) override; @@ -116,13 +118,12 @@ private: IndexPtr m_index; const std::vector<const Package *> *m_packagesData; - ReaPack *m_reapack; About *m_dialog; }; class AboutPackageDelegate : public AboutDelegate { public: - AboutPackageDelegate(const Package *, const VersionName &current, ReaPack *); + AboutPackageDelegate(const Package *, const VersionName &current); protected: void init(About *) override; @@ -142,7 +143,6 @@ private: const Package *m_package; VersionName 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 @@ -857,15 +857,15 @@ void Browser::aboutPackage(const int index, const bool focus) if(entry && entry->package) { m_reapack->about()->setDelegate(make_shared<AboutPackageDelegate>( - entry->package, entry->regEntry.version, m_reapack), focus); + entry->package, entry->regEntry.version), focus); } } void Browser::aboutRemote(const int index, const bool focus) { if(const Entry *entry = getEntry(index)) { - m_reapack->about()->setDelegate(make_shared<AboutIndexDelegate>( - entry->index, m_reapack), focus); + m_reapack->about()->setDelegate( + make_shared<AboutIndexDelegate>(entry->index), focus); } } diff --git a/src/manager.cpp b/src/manager.cpp @@ -420,7 +420,7 @@ void Manager::about(const int index) const Remote &remote = getRemote(index); m_reapack->fetchIndex(remote, [=] (const IndexPtr &index) { if(index) - m_reapack->about()->setDelegate(make_shared<AboutIndexDelegate>(index, m_reapack)); + m_reapack->about()->setDelegate(make_shared<AboutIndexDelegate>(index)); }, handle()); } diff --git a/src/reapack.cpp b/src/reapack.cpp @@ -228,7 +228,7 @@ void ReaPack::aboutSelf() { fetchIndex(remote("ReaPack"), [=] (const IndexPtr &index) { if(index) - about()->setDelegate(make_shared<AboutIndexDelegate>(index, this)); + about()->setDelegate(make_shared<AboutIndexDelegate>(index)); }, m_mainWindow); } @@ -239,7 +239,7 @@ About *ReaPack::about(const bool instantiate) else if(!instantiate) return nullptr; - m_about = Dialog::Create<About>(m_instance, m_mainWindow); + m_about = Dialog::Create<About>(m_instance, m_mainWindow, this); m_about->setCloseHandler([=] (INT_PTR) { Dialog::Destroy(m_about);