reapack

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

commit 26bfba123b83717c841178d658a63c51c6afe2b1
parent e52fe573332c25f0356aacaaf2924264c7fbd374
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Sat, 13 Feb 2016 01:27:21 -0500

implement the About ReaPack menu action

Diffstat:
Msrc/about.cpp | 39+++++++++++++++++++++++++++++++++++++--
Msrc/about.hpp | 5++++-
Msrc/main.cpp | 5++++-
Msrc/manager.cpp | 27+--------------------------
Msrc/reapack.cpp | 9+++++++++
Msrc/reapack.hpp | 1+
6 files changed, 56 insertions(+), 30 deletions(-)

diff --git a/src/about.cpp b/src/about.cpp @@ -36,15 +36,25 @@ using namespace std; enum { ACTION_HISTORY = 300 }; -About::About(const Remote *remote, const RemoteIndex *index) - : Dialog(IDD_ABOUT_DIALOG), m_remote(remote), m_index(index), +About::About(const Remote *remote) + : Dialog(IDD_ABOUT_DIALOG), m_remote(remote), m_index(nullptr), m_currentCat(-255) { RichEdit::Init(); } +About::~About() +{ + delete m_index; +} + void About::onInit() { + if(!load()) { + close(); + return; + } + m_about = createControl<RichEdit>(IDC_ABOUT); m_cats = createControl<ListView>(IDC_CATEGORIES, ListView::Columns{ @@ -127,6 +137,31 @@ void About::onContextMenu(HWND target, const int x, const int y) menu.show(x, y, handle()); } +bool About::load() +{ + try { + m_index = RemoteIndex::load(m_remote->name()); + return true; + } + catch(const reapack_error &e) { + const auto_string &desc = make_autostring(e.what()); + + auto_char msg[512] = {}; + auto_snprintf(msg, sizeof(msg), + AUTO_STR("ReaPack could not read %s's index.\n\n") + + AUTO_STR("Synchronize your packages and try again.\n") + AUTO_STR("If the problem persist, contact the repository maintainer.\n\n") + + AUTO_STR("[Error description: %s]"), + make_autostring(m_remote->name()).c_str(), desc.c_str() + ); + + MessageBox(parent(), msg, AUTO_STR("ReaPack Warning"), MB_OK); + return false; + } +} + void About::populate() { auto_char title[255] = {}; diff --git a/src/about.hpp b/src/about.hpp @@ -36,7 +36,9 @@ struct Link; class About : public Dialog { public: enum { EnableResult = 100 }; - About(const Remote *, const RemoteIndex *); + + About(const Remote *); + ~About(); protected: void onInit() override; @@ -44,6 +46,7 @@ protected: void onContextMenu(HWND, int x, int y) override; private: + bool load(); void populate(); void updatePackages(); void updateInstalledFiles(); diff --git a/src/main.cpp b/src/main.cpp @@ -88,7 +88,8 @@ static void menuHook(const char *name, HMENU handle, int f) menu.addSeparator(); - menu.addAction(AUTO_STR("About ReaPack v0.1"), 0); + menu.addAction(AUTO_STR("About ReaPack v0.1"), + NamedCommandLookup("_REAPACK_ABOUT")); } extern "C" REAPER_PLUGIN_DLL_EXPORT int REAPER_PLUGIN_ENTRYPOINT( @@ -120,6 +121,8 @@ extern "C" REAPER_PLUGIN_DLL_EXPORT int REAPER_PLUGIN_ENTRYPOINT( reapack->setupAction("REAPACK_MANAGE", "ReaPack: Manage remotes...", &reapack->configAction, bind(&ReaPack::manageRemotes, reapack)); + reapack->setupAction("REAPACK_ABOUT", bind(&ReaPack::about, reapack)); + plugin_register("hookcommand", (void *)commandHook); plugin_register("hookcustommenu", (void *)menuHook); diff --git a/src/manager.cpp b/src/manager.cpp @@ -208,32 +208,7 @@ void Manager::about() void Manager::showAbout(const Remote &remote) { - const RemoteIndex *index; - - try { - index = RemoteIndex::load(remote.name()); - } - catch(const reapack_error &e) { - const auto_string &desc = make_autostring(e.what()); - - auto_char msg[512] = {}; - auto_snprintf(msg, sizeof(msg), - AUTO_STR("ReaPack could not read %s's index.\n\n") - - AUTO_STR("Synchronize your packages and try again.\n") - AUTO_STR("If the problem persist, contact the repository maintainer.\n\n") - - AUTO_STR("[Error description: %s]"), - make_autostring(remote.name()).c_str(), desc.c_str() - ); - - MessageBox(handle(), msg, AUTO_STR("ReaPack Warning"), MB_OK); - return; - } - - unique_ptr<const RemoteIndex> ptr(index); - - switch(Dialog::Show<About>(instance(), handle(), &remote, index)) { + switch(Dialog::Show<About>(instance(), handle(), &remote)) { case About::EnableResult: setRemoteEnabled(true); break; diff --git a/src/reapack.cpp b/src/reapack.cpp @@ -17,6 +17,7 @@ #include "reapack.hpp" +#include "about.hpp" #include "config.hpp" #include "errors.hpp" #include "import.hpp" @@ -254,6 +255,14 @@ void ReaPack::manageRemotes() }); } +void ReaPack::about() +{ + const Remote &remote = m_config->remotes()->get("ReaPack"); + requireIndex(remote, [=] { + Dialog::Show<About>(m_instance, m_mainWindow, &remote); + }); +} + Transaction *ReaPack::createTransaction() { if(m_transaction) { diff --git a/src/reapack.hpp b/src/reapack.hpp @@ -56,6 +56,7 @@ public: void importRemote(); void import(const Remote &); void manageRemotes(); + void about(); void runTasks();