commit 984b6830dd148d522a396a7ab6c8f1c27412f18a
parent 0dcc91292ef2d857be6aa25109810ab00f3d5459
Author: cfillion <cfillion@users.noreply.github.com>
Date: Wed, 21 Sep 2016 19:29:20 -0400
refactor about dialog usage
Diffstat:
6 files changed, 31 insertions(+), 47 deletions(-)
diff --git a/src/about.cpp b/src/about.cpp
@@ -137,6 +137,8 @@ void About::setDelegate(const DelegatePtr &delegate)
// Though I have no idea why...
InvalidateRect(handle(), nullptr, true);
#endif
+
+ show();
}
void About::setTitle(const string &what)
diff --git a/src/browser.cpp b/src/browser.cpp
@@ -17,13 +17,13 @@
#include "browser.hpp"
+#include "about.hpp"
#include "config.hpp"
#include "encoding.hpp"
#include "errors.hpp"
#include "index.hpp"
#include "menu.hpp"
#include "reapack.hpp"
-#include "report.hpp"
#include "resource.hpp"
#include "transaction.hpp"
@@ -517,7 +517,7 @@ void Browser::refresh(const bool stale)
m_loading = true;
- m_reapack->fetchIndexes(remotes, [=] (vector<IndexPtr> indexes) {
+ m_reapack->fetchIndexes(remotes, [=] (const vector<IndexPtr> &indexes) {
// if the user wanted to close the window while we were downloading stuff
if(m_loaded && !isVisible()) {
close();
@@ -526,10 +526,7 @@ void Browser::refresh(const bool stale)
m_loading = false;
- // keep the old indexes around a little bit longer for use by #populate
- indexes.swap(m_indexes);
-
- populate();
+ populate(indexes);
if(!m_loaded) {
m_loaded = true;
@@ -545,7 +542,7 @@ void Browser::setFilter(const string &newFilter)
SetFocus(m_filterHandle);
}
-void Browser::populate()
+void Browser::populate(const vector<IndexPtr> &indexes)
{
try {
Registry reg(Path::prefixRoot(Path::REGISTRY));
@@ -561,14 +558,14 @@ void Browser::populate()
// thus causing the wrong package to be selected!
m_visibleEntries.clear();
- for(const IndexPtr &index : m_indexes) {
+ for(const IndexPtr &index : indexes) {
for(const Package *pkg : index->packages())
- m_entries.push_back(makeEntry(pkg, reg.getEntry(pkg)));
+ m_entries.push_back(makeEntry(pkg, reg.getEntry(pkg), index));
// obsolete packages
for(const Registry::Entry ®Entry : reg.getEntries(index->name())) {
if(!index->find(regEntry.category, regEntry.package))
- m_entries.push_back({InstalledFlag | ObsoleteFlag, regEntry});
+ m_entries.push_back({InstalledFlag | ObsoleteFlag, regEntry, index});
}
}
@@ -619,7 +616,8 @@ void Browser::transferActions()
disable(m_applyBtn);
}
-auto Browser::makeEntry(const Package *pkg, const Registry::Entry ®Entry)
+auto Browser::makeEntry(const Package *pkg,
+ const Registry::Entry ®Entry, const IndexPtr &index)
const -> Entry
{
const auto &instOpts = m_reapack->config()->install;
@@ -644,7 +642,7 @@ auto Browser::makeEntry(const Package *pkg, const Registry::Entry ®Entry)
if(!latest)
latest = pkg->lastVersion(true);
- return {flags, regEntry, pkg, latest, current};
+ return {flags, regEntry, index, pkg, latest, current};
}
void Browser::fillList()
@@ -824,13 +822,13 @@ void Browser::aboutPackage(const int index)
const Entry *entry = getEntry(index);
if(entry && entry->package)
- m_reapack->about(entry->package);
+ m_reapack->about()->setDelegate(make_shared<AboutPackageDelegate>(entry->package, m_reapack));
}
void Browser::aboutRemote(const int index)
{
if(const Entry *entry = getEntry(index))
- m_reapack->about(getRemote(*entry), handle());
+ m_reapack->about()->setDelegate(make_shared<AboutIndexDelegate>(entry->index, m_reapack));
}
void Browser::installLatest(const int index, const bool toggle)
diff --git a/src/browser.hpp b/src/browser.hpp
@@ -67,6 +67,7 @@ private:
int flags;
Registry::Entry regEntry;
+ IndexPtr index;
const Package *package;
const Version *latest;
const Version *current;
@@ -100,10 +101,10 @@ private:
UninstalledView,
};
- Entry makeEntry(const Package *, const Registry::Entry &) const;
+ Entry makeEntry(const Package *, const Registry::Entry &, const IndexPtr &) const;
bool fillContextMenu(Menu &, int index);
- void populate();
+ void populate(const std::vector<IndexPtr> &);
void transferActions();
bool match(const Entry &) const;
void checkFilter();
@@ -136,7 +137,6 @@ private:
void aboutRemote(int index);
void aboutPackage(int index);
- std::vector<IndexPtr> m_indexes;
ReaPack *m_reapack;
bool m_loading;
bool m_loaded;
diff --git a/src/manager.cpp b/src/manager.cpp
@@ -17,6 +17,7 @@
#include "manager.hpp"
+#include "about.hpp"
#include "config.hpp"
#include "encoding.hpp"
#include "import.hpp"
@@ -326,7 +327,11 @@ void Manager::setChange(const int increment)
void Manager::about(const int index)
{
- m_reapack->about(getRemote(index), handle());
+ const Remote &remote = getRemote(index);
+ m_reapack->fetchIndex(remote, [=] (const IndexPtr &index) {
+ if(index)
+ m_reapack->about()->setDelegate(make_shared<AboutIndexDelegate>(index, m_reapack));
+ }, handle());
}
void Manager::copyUrl()
diff --git a/src/reapack.cpp b/src/reapack.cpp
@@ -224,13 +224,16 @@ Remote ReaPack::remote(const string &name) const
void ReaPack::aboutSelf()
{
- about(remote("ReaPack"), m_mainWindow);
+ fetchIndex(remote("ReaPack"), [=] (const IndexPtr &index) {
+ if(index)
+ about()->setDelegate(make_shared<AboutIndexDelegate>(index, this));
+ }, m_mainWindow);
}
-void ReaPack::setupAbout()
+About *ReaPack::about()
{
if(m_about)
- return;
+ return m_about;
m_about = Dialog::Create<About>(m_instance, m_mainWindow);
@@ -238,30 +241,8 @@ void ReaPack::setupAbout()
Dialog::Destroy(m_about);
m_about = nullptr;
});
-}
-
-void ReaPack::about(const Remote &remote, HWND parent)
-{
- if(!remote)
- return;
- fetchIndex(remote, [=] (const IndexPtr &index) {
- // do nothing if the index could not be loaded
- if(!index)
- return;
-
- setupAbout();
- m_about->setDelegate(std::make_shared<AboutIndexDelegate>(index, this));
- m_about->show();
-
- }, parent);
-}
-
-void ReaPack::about(const Package *pkg)
-{
- setupAbout();
- m_about->setDelegate(std::make_shared<AboutPackageDelegate>(pkg, this));
- m_about->show();
+ return m_about;
}
Browser *ReaPack::browsePackages()
diff --git a/src/reapack.hpp b/src/reapack.hpp
@@ -72,8 +72,7 @@ public:
void importRemote();
void manageRemotes();
void aboutSelf();
- void about(const Remote &, HWND parent);
- void about(const Package *);
+ About *about();
Browser *browsePackages();
void refreshManager();
void refreshBrowser();
@@ -92,7 +91,6 @@ private:
void registerSelf();
void doFetchIndex(const Remote &remote, DownloadQueue *, HWND, bool stale);
IndexPtr loadIndex(const Remote &remote, HWND);
- void setupAbout();
std::map<int, ActionCallback> m_actions;