reapack

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

commit 83013e326241985a12b4c150b6afbaf2098969d5
parent 8620cda08d5c7a2173e4496254720f131be0e6bd
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Thu, 17 Mar 2016 23:20:12 -0400

implement action execution from the browser

Diffstat:
Msrc/browser.cpp | 43+++++++++++++++++++++++++++++++++++++++++++
Msrc/browser.hpp | 1+
Msrc/reapack.cpp | 11+++++++++++
Msrc/reapack.hpp | 1+
Msrc/transaction.cpp | 25+++++++++++--------------
Msrc/transaction.hpp | 3+--
6 files changed, 68 insertions(+), 16 deletions(-)

diff --git a/src/browser.cpp b/src/browser.cpp @@ -148,6 +148,15 @@ void Browser::onCommand(const int id) selectionDo(bind(&Browser::resetAction, this, arg::_1)); break; case IDOK: + case IDAPPLY: + if(confirm()) { + apply(); + + if(id == IDAPPLY) + break; + } + else + break; case IDCANCEL: close(); break; @@ -596,6 +605,40 @@ auto Browser::getDisplay() const -> Display return (Display)SendMessage(m_display, CB_GETCURSEL, 0, 0); } +bool Browser::confirm() const +{ + if(m_actions.empty()) + return true; + + const size_t count = m_actions.size(); + + auto_char msg[255] = {}; + auto_snprintf(msg, sizeof(msg), + AUTO_STR("Confirm execution of %zu action%s?\n"), + count, count == 1 ? AUTO_STR("") : AUTO_STR("s")); + + const auto_char *title = AUTO_STR("ReaPack Query"); + const int btn = MessageBox(handle(), msg, title, MB_YESNO); + + return btn == IDYES; +} + void Browser::apply() { + if(m_actions.empty()) + return; + + disable(m_apply); + + for(const auto &pair : m_actions) { + if(pair.second) + m_reapack->install(pair.second); + else + m_reapack->uninstall(pair.first->regEntry); + } + + m_actions.clear(); + m_reapack->runTasks(); + + fillList(); // update state column } diff --git a/src/browser.hpp b/src/browser.hpp @@ -98,6 +98,7 @@ private: void setAction(const int index, const Version *); void selectionDo(const std::function<void (int)> &); Display getDisplay() const; + bool confirm() const; void apply(); void installLatest(int index); diff --git a/src/reapack.cpp b/src/reapack.cpp @@ -177,6 +177,14 @@ void ReaPack::setRemoteEnabled(const Remote &original, const bool enable) }); } +void ReaPack::install(const Version *ver) +{ + if(!hitchhikeTransaction()) + return; + + m_transaction->install(ver, true); +} + void ReaPack::uninstall(const Remote &remote) { if(remote.isProtected()) @@ -491,6 +499,9 @@ Transaction *ReaPack::createTransaction() ShowMessageBox("Nothing to do!", "ReaPack", 0); else Dialog::Show<Report>(m_instance, m_mainWindow, receipt); + + if(m_browser && m_transaction->taskCount() > 0) + m_browser->reload(); }); m_transaction->setCleanupHandler([=] { diff --git a/src/reapack.hpp b/src/reapack.hpp @@ -66,6 +66,7 @@ public: void setRemoteEnabled(const Remote &, bool enable); void enable(const Remote &r) { setRemoteEnabled(r, true); } void disable(const Remote &r) { setRemoteEnabled(r, false); } + void install(const Version *); void uninstall(const Remote &); void uninstall(const Registry::Entry &); void importRemote(); diff --git a/src/transaction.cpp b/src/transaction.cpp @@ -49,7 +49,7 @@ Transaction::Transaction() if(m_installQueue.empty()) finish(); else - installQueued(); + runTasks(); }); } @@ -87,7 +87,7 @@ void Transaction::synchronize(const Remote &remote, const bool isUserAction) m_registry->savepoint(); for(const Package *pkg : ri->packages()) - install(pkg->lastVersion()); + install(pkg->lastVersion(), false); m_registry->restore(); }); @@ -125,8 +125,10 @@ void Transaction::saveIndex(Download *dl, const string &name) it->second(); } -void Transaction::install(const Version *ver) +void Transaction::install(const Version *ver, const bool force) { + m_receipt.setEnabled(true); + const Package *pkg = ver->package(); const Registry::Entry &regEntry = m_registry->getEntry(pkg); @@ -134,7 +136,7 @@ void Transaction::install(const Version *ver) if(regEntry.id) { if(regEntry.versionCode == ver->code()) { - if(allFilesExists(ver->files())) + if(!force && allFilesExists(ver->files())) return; // latest version is really installed, nothing to do here! } else if(regEntry.versionCode < ver->code()) @@ -170,16 +172,6 @@ void Transaction::install(const Version *ver) m_installQueue.push({type, ver, regEntry}); } -void Transaction::installQueued() -{ - while(!m_installQueue.empty()) { - installTicket(m_installQueue.front()); - m_installQueue.pop(); - } - - runTasks(); -} - void Transaction::installTicket(const InstallTicket &ticket) { const Version *ver = ticket.version; @@ -312,6 +304,11 @@ void Transaction::addTask(Task *task) void Transaction::runTasks() { + while(!m_installQueue.empty()) { + installTicket(m_installQueue.front()); + m_installQueue.pop(); + } + while(!m_taskQueue.empty()) { m_taskQueue.front()->start(); m_taskQueue.pop(); diff --git a/src/transaction.hpp b/src/transaction.hpp @@ -57,7 +57,7 @@ public: void setCleanupHandler(const CleanupHandler &cb) { m_cleanupHandler = cb; } void synchronize(const Remote &, bool userAction = true); - void install(const Version *); + void install(const Version *, bool force = false); void uninstall(const Remote &); void uninstall(const Registry::Entry &); void registerAll(const Remote &); @@ -78,7 +78,6 @@ private: void fetchIndex(const Remote &, const IndexCallback &cb); void saveIndex(Download *, const std::string &remoteName); - void installQueued(); void installTicket(const InstallTicket &); void addTask(Task *);