commit a676f44f872c8d3eff609287f679257243da0251
parent a819bf6cfbb79098d3ecdb6639ed46b44f430ab2
Author: cfillion <cfillion@users.noreply.github.com>
Date: Tue, 24 Oct 2017 05:59:58 -0400
browser: re-sort even when updating the status cell of a single row
Diffstat:
2 files changed, 38 insertions(+), 19 deletions(-)
diff --git a/src/browser.cpp b/src/browser.cpp
@@ -134,25 +134,25 @@ void Browser::onCommand(const int id, const int event)
actionsButton();
break;
case ACTION_LATEST:
- installLatest(m_currentIndex);
+ currentDo(bind(&Browser::installLatest, this, _1, true));
break;
case ACTION_LATEST_ALL:
installLatestAll();
break;
case ACTION_REINSTALL:
- reinstall(m_currentIndex);
+ currentDo(bind(&Browser::reinstall, this, _1, true));
break;
case ACTION_REINSTALL_ALL:
selectionDo(bind(&Browser::reinstall, this, _1, false));
break;
case ACTION_UNINSTALL:
- uninstall(m_currentIndex);
+ currentDo(bind(&Browser::uninstall, this, _1, true));
break;
case ACTION_UNINSTALL_ALL:
selectionDo(bind(&Browser::uninstall, this, _1, false));
break;
case ACTION_PIN:
- togglePin(m_currentIndex);
+ currentDo(bind(&Browser::togglePin, this, _1));
break;
case ACTION_ABOUT_PKG:
aboutPackage(m_currentIndex);
@@ -192,7 +192,7 @@ void Browser::onCommand(const int id, const int event)
break;
default:
if(id >> 8 == ACTION_VERSION)
- installVersion(m_currentIndex, id & 0xff);
+ currentDo(bind(&Browser::installVersion, this, _1, id & 0xff));
else if(id >> 8 == ACTION_FILTERTYPE) {
m_typeFilter = static_cast<Package::Type>(id & 0xff);
fillList();
@@ -745,21 +745,17 @@ void Browser::updateAction(const int index)
m_list->removeRow(index);
else
m_list->row(index)->setCell(0, entry->displayState());
-
- if(m_actions.empty())
- disable(m_applyBtn);
- else
- enable(m_applyBtn);
}
-void Browser::selectionDo(const function<void (int)> &func)
+void Browser::listDo(const function<void (int)> &func, const vector<int> &indexes)
{
ListView::BeginEdit edit(m_list);
int lastSize = m_list->rowCount();
int offset = 0;
- for(const int index : m_list->selection()) {
+ // Assumes the index vector is sorted
+ for(const int index : indexes) {
func(index - offset);
// handle row removal
@@ -771,6 +767,21 @@ void Browser::selectionDo(const function<void (int)> &func)
if(offset) // rows were deleted
updateDisplayLabel();
+
+ if(m_actions.empty())
+ disable(m_applyBtn);
+ else
+ enable(m_applyBtn);
+}
+
+void Browser::currentDo(const function<void (int)> &func)
+{
+ listDo(func, {m_currentIndex});
+}
+
+void Browser::selectionDo(const function<void (int)> &func)
+{
+ listDo(func, m_list->selection());
}
auto Browser::currentView() const -> View
diff --git a/src/browser.hpp b/src/browser.hpp
@@ -102,22 +102,30 @@ private:
void fillMenu(Menu &);
bool isFiltered(Package::Type) const;
bool hasAction(const Entry *) const;
- void setTarget(const int index, const Version *, bool toggle = true);
- void resetTarget(int index);
- void resetActions(int index);
- void updateAction(const int index);
+ void listDo(const std::function<void (int)> &, const std::vector<int> &);
+ void currentDo(const std::function<void (int)> &);
void selectionDo(const std::function<void (int)> &);
View currentView() const;
void copy();
bool confirm() const;
bool apply();
- void installLatest(int index, bool toggle = true);
+ // Only call the following functions using currentDo or selectionDo (listDo)
+ // (so that the display label is updated and the list sorted and filtered as
+ // needed)
+ void resetActions(int index);
+ void updateAction(const int index);
+ void setTarget(const int index, const Version *, bool toggle = true);
+ void resetTarget(int index);
+
+ void installLatest(int index, bool toggle);
void installLatestAll();
- void reinstall(int index, bool toggle = true);
+ void reinstall(int index, bool toggle);
void installVersion(int index, size_t verIndex);
- void uninstall(int index, bool toggle = true);
+ void uninstall(int index, bool toggle);
void togglePin(int index);
+
+ // these can be called directly because they don't use updateAction()
void aboutRemote(int index, bool focus = true);
void aboutPackage(int index, bool focus = true);