commit 687f52f5e78ebe4d32b1fedb0ad8145eae7fd0d9
parent 060addc9b4f6d0279583bc5fccc9b36106a97e19
Author: cfillion <cfillion@users.noreply.github.com>
Date: Fri, 8 Apr 2016 16:22:56 -0400
add "Refresh repositories" and "Manage repositories" actions in the browser
Diffstat:
4 files changed, 34 insertions(+), 16 deletions(-)
diff --git a/src/browser.cpp b/src/browser.cpp
@@ -42,11 +42,13 @@ enum Action {
ACTION_HISTORY,
ACTION_ABOUT,
ACTION_RESET_ALL,
+ ACTION_REFRESH,
+ ACTION_MANAGE,
};
Browser::Browser(ReaPack *reapack)
: Dialog(IDD_BROWSER_DIALOG), m_reapack(reapack),
- m_loaded(false), m_checkFilter(false), m_currentIndex(-1)
+ m_loading(false), m_loaded(false), m_checkFilter(false), m_currentIndex(-1)
{
}
@@ -155,6 +157,12 @@ void Browser::onCommand(const int id, const int event)
case ACTION_RESET_ALL:
selectionDo(bind(&Browser::resetAction, this, arg::_1));
break;
+ case ACTION_REFRESH:
+ refresh(true);
+ break;
+ case ACTION_MANAGE:
+ m_reapack->manageRemotes();
+ break;
case IDOK:
case IDAPPLY:
if(confirm()) {
@@ -283,6 +291,10 @@ void Browser::selectionMenu()
if(!m_list->hasSelection())
menu.disableAll();
+ menu.addSeparator();
+ menu.addAction(AUTO_STR("Re&fresh repositories"), ACTION_REFRESH);
+ menu.addAction(AUTO_STR("&Manage repositories..."), ACTION_MANAGE);
+
menu.show(rect.left, rect.bottom - 1, handle());
}
@@ -305,8 +317,11 @@ void Browser::checkFilter()
}
}
-void Browser::refresh()
+void Browser::refresh(const bool stale)
{
+ if(m_loading)
+ return;
+
const vector<Remote> &remotes = m_reapack->config()->remotes()->getEnabled();
if(!m_loaded && remotes.empty()) {
@@ -321,7 +336,10 @@ void Browser::refresh()
return;
}
+ m_loading = true;
+
m_reapack->fetchIndexes(remotes, [=] (const vector<IndexPtr> &indexes) {
+ m_loading = false;
m_indexes = indexes;
populate();
@@ -329,7 +347,7 @@ void Browser::refresh()
m_loaded = true;
show();
}
- });
+ }, handle(), stale);
}
void Browser::populate()
diff --git a/src/browser.hpp b/src/browser.hpp
@@ -39,7 +39,7 @@ typedef std::shared_ptr<const Index> IndexPtr;
class Browser : public Dialog {
public:
Browser(ReaPack *);
- void refresh();
+ void refresh(bool stale = false);
protected:
void onInit() override;
@@ -112,6 +112,7 @@ private:
std::vector<IndexPtr> m_indexes;
ReaPack *m_reapack;
+ bool m_loading;
bool m_loaded;
bool m_checkFilter;
int m_currentIndex;
diff --git a/src/reapack.cpp b/src/reapack.cpp
@@ -355,19 +355,16 @@ void ReaPack::browsePackages()
}
void ReaPack::fetchIndex(const Remote &remote,
- const IndexCallback &callback, HWND parent)
+ const IndexCallback &callback, HWND parent, const bool stale)
{
fetchIndexes({remote}, [=] (const vector<IndexPtr> &indexes) {
callback(indexes.empty() ? nullptr : indexes.front());
- }, parent);
+ }, parent, stale);
}
void ReaPack::fetchIndexes(const vector<Remote> &remotes,
- const IndexesCallback &callback, HWND parent)
+ const IndexesCallback &callback, HWND parent, const bool stale)
{
- if(!parent)
- parent = m_mainWindow;
-
// I don't know why, but at least on OSX giving the manager window handle
// (in `parent`) to the progress dialog prevents it from being shown at all
// while still taking the focus away from the manager dialog.
@@ -397,15 +394,16 @@ void ReaPack::fetchIndexes(const vector<Remote> &remotes,
queue->onDone(load);
for(const Remote &remote : remotes)
- doFetchIndex(remote, queue, parent);
+ doFetchIndex(remote, queue, parent, stale);
if(queue->idle())
load();
}
-void ReaPack::doFetchIndex(const Remote &remote, DownloadQueue *queue, HWND parent)
+void ReaPack::doFetchIndex(const Remote &remote, DownloadQueue *queue,
+ HWND parent, const bool stale)
{
- Download *dl = Index::fetch(remote);
+ Download *dl = Index::fetch(remote, stale);
if(!dl)
return;
diff --git a/src/reapack.hpp b/src/reapack.hpp
@@ -76,9 +76,10 @@ public:
void about(const std::string &, HWND parent);
void about(const Remote &, HWND parent);
void browsePackages();
- void fetchIndex(const Remote &remote, const IndexCallback &, HWND);
+ void fetchIndex(const Remote &remote, const IndexCallback &,
+ HWND parent, bool stale = false);
void fetchIndexes(const std::vector<Remote> &,
- const IndexesCallback &, HWND = nullptr);
+ const IndexesCallback &, HWND parent, bool stale = false);
void runTasks();
@@ -88,7 +89,7 @@ private:
Transaction *createTransaction();
bool hitchhikeTransaction();
void registerSelf();
- void doFetchIndex(const Remote &remote, DownloadQueue *, HWND);
+ void doFetchIndex(const Remote &remote, DownloadQueue *, HWND, bool stale);
IndexPtr loadIndex(const Remote &remote, HWND);
std::map<int, ActionCallback> m_actions;