commit df4958e06eab108f11c708e9a547cdc86458d29c
parent 31933946c6f09e706dd86f664f1cf551e42780f4
Author: cfillion <cfillion@users.noreply.github.com>
Date: Sun, 21 Aug 2016 15:59:11 -0400
about repo: add "find in browser" action in the package context menu
Diffstat:
6 files changed, 52 insertions(+), 11 deletions(-)
diff --git a/src/about.cpp b/src/about.cpp
@@ -17,6 +17,7 @@
#include "about.hpp"
+#include "browser.hpp"
#include "encoding.hpp"
#include "errors.hpp"
#include "index.hpp"
@@ -36,7 +37,7 @@
using namespace std;
-enum { ACTION_ABOUT_PKG = 300, ACTION_COPY_URL };
+enum { ACTION_ABOUT_PKG = 300, ACTION_FIND_IN_BROWSER, ACTION_COPY_URL };
About::About() : Dialog(IDD_ABOUT_DIALOG)
{
@@ -355,6 +356,7 @@ bool AboutIndexDelegate::fillContextMenu(Menu &menu, const int index) const
if(index < 0)
return false;
+ menu.addAction(AUTO_STR("Find in the &browser"), ACTION_FIND_IN_BROWSER);
menu.addAction(AUTO_STR("About this &package"), ACTION_ABOUT_PKG);
return true;
@@ -363,6 +365,9 @@ bool AboutIndexDelegate::fillContextMenu(Menu &menu, const int index) const
void AboutIndexDelegate::onCommand(const int id)
{
switch(id) {
+ case ACTION_FIND_IN_BROWSER:
+ findInBrowser();
+ break;
case ACTION_ABOUT_PKG:
aboutPackage();
break;
@@ -372,15 +377,41 @@ void AboutIndexDelegate::onCommand(const int id)
}
}
-void AboutIndexDelegate::aboutPackage()
+const Package *AboutIndexDelegate::currentPackage() const
{
const int index = m_dialog->list()->currentIndex();
if(index < 0)
+ return nullptr;
+ else
+ return m_packagesData->at(index);
+}
+
+void AboutIndexDelegate::findInBrowser()
+{
+ const Package *pkg = currentPackage();
+ if(!pkg)
+ return;
+
+ Browser *browser = m_reapack->browsePackages();
+ if(!browser)
return;
- const Package *pkg = m_packagesData->at(index);
- m_dialog->setDelegate(make_shared<AboutPackageDelegate>(pkg, m_reapack));
+ string filter = "\"";
+ filter += pkg->displayName(m_reapack->config()->browser.showDescs);
+ filter += "\" \"";
+ filter += m_index->name();
+ filter += '"';
+
+ browser->setFilter(filter);
+}
+
+void AboutIndexDelegate::aboutPackage()
+{
+ const Package *pkg = currentPackage();
+
+ if(pkg)
+ m_dialog->setDelegate(make_shared<AboutPackageDelegate>(pkg, m_reapack));
}
void AboutIndexDelegate::install()
diff --git a/src/about.hpp b/src/about.hpp
@@ -100,6 +100,8 @@ protected:
private:
void initInstalledFiles();
+ const Package *currentPackage() const;
+ void findInBrowser();
void aboutPackage();
void install();
diff --git a/src/browser.cpp b/src/browser.cpp
@@ -167,9 +167,7 @@ void Browser::onCommand(const int id, const int event)
m_checkFilter = true;
break;
case IDC_CLEAR:
- SetWindowText(m_filterHandle, AUTO_STR(""));
- checkFilter();
- SetFocus(m_filterHandle);
+ setFilter({});
break;
case IDC_SELECT:
m_list->selectAll();
@@ -540,6 +538,13 @@ void Browser::refresh(const bool stale)
}, handle(), stale);
}
+void Browser::setFilter(const string &newFilter)
+{
+ SetWindowText(m_filterHandle, make_autostring(newFilter).c_str());
+ checkFilter();
+ SetFocus(m_filterHandle);
+}
+
void Browser::populate()
{
try {
diff --git a/src/browser.hpp b/src/browser.hpp
@@ -44,6 +44,7 @@ class Browser : public Dialog {
public:
Browser(ReaPack *);
void refresh(bool stale = false);
+ void setFilter(const std::string &);
protected:
void onInit() override;
diff --git a/src/reapack.cpp b/src/reapack.cpp
@@ -263,18 +263,18 @@ void ReaPack::about(const Package *pkg)
m_about->show();
}
-void ReaPack::browsePackages()
+Browser *ReaPack::browsePackages()
{
if(m_browser) {
m_browser->setFocus();
- return;
+ return m_browser;
}
else if(m_tx) {
ShowMessageBox(
"This feature cannot be used while packages are being installed. "
"Try again later.", "Browse packages", MB_OK
);
- return;
+ return nullptr;
}
m_browser = Dialog::Create<Browser>(m_instance, m_mainWindow, this);
@@ -282,6 +282,8 @@ void ReaPack::browsePackages()
Dialog::Destroy(m_browser);
m_browser = nullptr;
});
+
+ return m_browser;
}
void ReaPack::fetchIndex(const Remote &remote,
diff --git a/src/reapack.hpp b/src/reapack.hpp
@@ -74,7 +74,7 @@ public:
void aboutSelf();
void about(const Remote &, HWND parent);
void about(const Package *);
- void browsePackages();
+ Browser *browsePackages();
void refreshManager();
void refreshBrowser();