reapack

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

commit 8017e1ae892a2e709a3c04a033a02e9c5e47e4f2
parent a0b7c1ea0b81ffefdf8f45e297abd0a44ee0366e
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Sat, 16 Apr 2016 22:52:51 -0700

don't interrupt REAPER use when displaying post-import message boxes

Diffstat:
Msrc/import.cpp | 17+++++------------
Msrc/import.hpp | 4+++-
Msrc/reapack.cpp | 21++++++++++++++-------
Msrc/reapack.hpp | 2+-
4 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/src/import.cpp b/src/import.cpp @@ -18,22 +18,15 @@ #include "import.hpp" #include "download.hpp" -#include "encoding.hpp" #include "errors.hpp" #include "index.hpp" #include "reapack.hpp" #include "remote.hpp" #include "resource.hpp" -#include <reaper_plugin_functions.h> - -#ifndef _WIN32 // for SWELL -#define SetWindowTextA SetWindowText -#endif - using namespace std; -const char *Import::TITLE = "ReaPack: Import a repository"; +const auto_char *Import::TITLE = AUTO_STR("ReaPack: Import a repository"); Import::Import(ReaPack *reapack) : Dialog(IDD_IMPORT_DIALOG), m_reapack(reapack), m_download(nullptr) @@ -42,7 +35,7 @@ Import::Import(ReaPack *reapack) void Import::onInit() { - SetWindowTextA(handle(), TITLE); + SetWindowText(handle(), TITLE); m_url = getControl(IDC_URL); m_progress = getControl(IDC_PROGRESS); @@ -110,7 +103,7 @@ void Import::fetch() if(state != Download::Success) { const string msg = "Download failed: " + dl->contents(); - ShowMessageBox(msg.c_str(), TITLE, MB_OK); + MessageBox(handle(), make_autostring(msg).c_str(), TITLE, MB_OK); SetFocus(m_url); return; } @@ -136,7 +129,7 @@ bool Import::import() try { IndexPtr index = Index::load({}, m_download->contents().c_str()); - m_reapack->import({index->name(), m_download->url()}); + m_reapack->import({index->name(), m_download->url()}, handle()); close(); @@ -144,7 +137,7 @@ bool Import::import() } catch(const reapack_error &e) { const string msg = "The received file is invalid: " + string(e.what()); - ShowMessageBox(msg.c_str(), TITLE, MB_OK); + MessageBox(handle(), make_autostring(msg).c_str(), TITLE, MB_OK); return false; } } diff --git a/src/import.hpp b/src/import.hpp @@ -20,6 +20,8 @@ #include "dialog.hpp" +#include "encoding.hpp" + #include <string> class Download; @@ -28,7 +30,7 @@ class ReaPack; class Import : public Dialog { public: - static const char *TITLE; + static const auto_char *TITLE; Import(ReaPack *); diff --git a/src/reapack.cpp b/src/reapack.cpp @@ -228,16 +228,20 @@ void ReaPack::importRemote() }); } -void ReaPack::import(const Remote &remote) +void ReaPack::import(const Remote &remote, HWND parent) { + if(!parent) + parent = m_mainWindow; + RemoteList *remotes = m_config->remotes(); const Remote &existing = remotes->get(remote.name()); if(!existing.isNull()) { if(existing.isProtected()) { - ShowMessageBox( - "This repository is protected and cannot be overwritten.", Import::TITLE, MB_OK); + MessageBox(parent, + AUTO_STR("This repository is protected and cannot be overwritten."), + Import::TITLE, MB_OK); return; } @@ -246,14 +250,17 @@ void ReaPack::import(const Remote &remote) " is already configured with a different URL.\r\n" "Do you want to overwrite it?"; - if(ShowMessageBox(msg.c_str(), Import::TITLE, MB_YESNO) != IDYES) + const auto answer = MessageBox(parent, make_autostring(msg).c_str(), + Import::TITLE, MB_YESNO); + + if(answer != IDYES) return; } else if(existing.isEnabled()) { const string msg = remote.name() + " is already configured.\r\nNothing to do!"; - ShowMessageBox(msg.c_str(), Import::TITLE, MB_OK); + MessageBox(parent, make_autostring(msg).c_str(), Import::TITLE, MB_OK); return; } @@ -264,7 +271,7 @@ void ReaPack::import(const Remote &remote) m_config->write(); const string msg = remote.name() + " has been enabled."; - ShowMessageBox(msg.c_str(), Import::TITLE, MB_OK); + MessageBox(parent, make_autostring(msg).c_str(), Import::TITLE, MB_OK); return; } @@ -281,7 +288,7 @@ void ReaPack::import(const Remote &remote) const string msg = remote.name() + " has been successfully imported into your repository list."; - ShowMessageBox(msg.c_str(), Import::TITLE, MB_OK); + MessageBox(parent, make_autostring(msg).c_str(), Import::TITLE, MB_OK); } void ReaPack::manageRemotes() diff --git a/src/reapack.hpp b/src/reapack.hpp @@ -70,7 +70,7 @@ public: void uninstall(const Remote &); void uninstall(const Registry::Entry &); void importRemote(); - void import(const Remote &); + void import(const Remote &, HWND = 0); void manageRemotes(); void aboutSelf(); void about(const std::string &, HWND parent);