reapack

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

commit d018ca8e052d9e9f455b47063bde704dcdb86206
parent 06e20ad087e1bbb1ca34377222fd4c538771164a
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Sun, 12 Nov 2017 16:20:33 -0500

browser: prevent selection-wide install/update action from installing an older version when the current one is not in the repository

...along with a bit refactoring to keep the code consistent.

Diffstat:
Msrc/browser.cpp | 22+++++++++++-----------
Msrc/browser.hpp | 2+-
Msrc/browser_entry.cpp | 12++++++++----
Msrc/browser_entry.hpp | 5+++--
4 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/src/browser.cpp b/src/browser.cpp @@ -283,7 +283,7 @@ void Browser::fillSelectionMenu(Menu &menu) int selFlags = 0; for(const int index : m_list->selection()) - selFlags |= getEntry(index)->possibleActions(); + selFlags |= getEntry(index)->possibleActions(false); menu.setEnabled(selFlags & Entry::CanInstallLatest, menu.addAction("&Install/update selection", ACTION_LATEST_ALL)); @@ -651,16 +651,16 @@ void Browser::installLatest(const int index, const bool toggle) { const Entry *entry = getEntry(index); - if(entry && entry->latest && entry->latest != entry->current) - setTarget(index, entry->latest, toggle); + if(entry && entry->test(Entry::CanInstallLatest, toggle)) + toggleTarget(index, entry->latest); } void Browser::reinstall(const int index, const bool toggle) { const Entry *entry = getEntry(index); - if(entry && entry->current) - setTarget(index, entry->current, toggle); + if(entry && entry->test(Entry::CanReinstall, toggle)) + toggleTarget(index, entry->current); } void Browser::installVersion(const int index, const size_t verIndex) @@ -679,21 +679,21 @@ void Browser::installVersion(const int index, const size_t verIndex) if(target == entry->current) resetTarget(index); else - setTarget(index, target); + toggleTarget(index, target); } void Browser::uninstall(const int index, const bool toggle) { const Entry *entry = getEntry(index); - if(entry && entry->test(Entry::InstalledFlag) && !entry->test(Entry::ProtectedFlag)) - setTarget(index, nullptr, toggle); + if(entry && entry->test(Entry::CanUninstall, toggle)) + toggleTarget(index, nullptr); } void Browser::togglePin(const int index) { Entry *entry = getEntry(index); - if(!entry) + if(!entry || !entry->test(Entry::CanTogglePin)) return; const bool newVal = !entry->pin.value_or(entry->regEntry.pinned); @@ -711,11 +711,11 @@ bool Browser::hasAction(const Entry *entry) const return count(m_actions.begin(), m_actions.end(), entry) > 0; } -void Browser::setTarget(const int index, const Version *target, const bool toggle) +void Browser::toggleTarget(const int index, const Version *target) { Entry *entry = getEntry(index); - if(toggle && entry->target && *entry->target == target) + if(entry->target && *entry->target == target) entry->target = boost::none; else entry->target = target; diff --git a/src/browser.hpp b/src/browser.hpp @@ -116,7 +116,7 @@ private: // needed) void resetActions(int index); void updateAction(const int index); - void setTarget(const int index, const Version *, bool toggle = true); + void toggleTarget(const int index, const Version *); void resetTarget(int index); void installLatest(int index, bool toggle); diff --git a/src/browser_entry.cpp b/src/browser_entry.cpp @@ -231,15 +231,19 @@ void Browser::Entry::fillMenu(Menu &menu) const menu.addAction(String::format("&About %s", indexName().c_str()), ACTION_ABOUT_REMOTE); } -int Browser::Entry::possibleActions() const +int Browser::Entry::possibleActions(bool allowToggle) const { int flags = 0; - if((test(UninstalledFlag) || test(OutOfDateFlag)) && (!target || *target != latest)) + const auto canSetTarget = [=](const Version *ver) { + return allowToggle || !target || *target != ver; + }; + + if((test(UninstalledFlag) || test(OutOfDateFlag)) && canSetTarget(latest)) flags |= CanInstallLatest; - if(test(InstalledFlag) && !test(ObsoleteFlag) && current && (!target || *target != current)) + if(test(InstalledFlag) && !test(ObsoleteFlag) && current && canSetTarget(current)) flags |= CanReinstall; - if(test(InstalledFlag) && !test(ProtectedFlag) && (!target || *target != nullptr)) + if(test(InstalledFlag) && !test(ProtectedFlag) && canSetTarget(nullptr)) flags |= CanUninstall; if(target ? *target != nullptr : test(InstalledFlag)) flags |= CanTogglePin; diff --git a/src/browser_entry.hpp b/src/browser_entry.hpp @@ -71,9 +71,10 @@ public: void updateRow(const ListView::RowPtr &) const; void fillMenu(Menu &) const; - int possibleActions() const; + int possibleActions(bool allowToggle) const; bool test(Flag f) const { return (m_flags & f) == f; } - bool test(PossibleAction f) const { return (possibleActions() & f) == f; } + bool test(PossibleAction f, bool allowToggle = true) const { + return (possibleActions(allowToggle) & f) == f; } bool operator==(const Entry &o) const; private: