commit 1572cacf853d71a32ca05e820ca6ab3f47d63fd5
parent ca155cdcf527862e602e3a4c54b5c11bf766538c
Author: cfillion <cfillion@users.noreply.github.com>
Date: Sun, 10 Jul 2016 22:45:04 -0400
about: add "Copy source URL" feature
Diffstat:
2 files changed, 51 insertions(+), 5 deletions(-)
diff --git a/src/about.cpp b/src/about.cpp
@@ -34,7 +34,7 @@
using namespace std;
-enum { ACTION_ABOUT_PKG = 300 };
+enum { ACTION_ABOUT_PKG = 300, ACTION_COPY_URL };
AboutDialog::AboutDialog(const Metadata *metadata)
: Dialog(IDD_ABOUT_DIALOG), m_metadata(metadata), m_currentIndex(-255)
@@ -339,6 +339,18 @@ AboutPackage::AboutPackage(const Package *pkg)
{
}
+void AboutPackage::onCommand(const int id, const int event)
+{
+ switch(id) {
+ case ACTION_COPY_URL:
+ copySourceUrl();
+ break;
+ default:
+ AboutDialog::onCommand(id, event);
+ break;
+ }
+}
+
const string &AboutPackage::what() const
{
return m_package->name();
@@ -354,8 +366,7 @@ ListView *AboutPackage::createMenu()
ListView *AboutPackage::createList()
{
return createControl<ListView>(IDC_LIST, ListView::Columns{
- {AUTO_STR("File"), 251},
- {AUTO_STR("Source"), 251},
+ {AUTO_STR("File"), 502},
{AUTO_STR("Main"), 50},
});
}
@@ -383,6 +394,9 @@ void AboutPackage::populate()
});
menu()->sortByColumn(0, ListView::DescendingOrder);
menu()->setSelected(menu()->rowCount() - 1, true);
+
+ list()->onContextMenu(bind(&AboutPackage::fillContextMenu,
+ this, placeholders::_1, placeholders::_2));
}
void AboutPackage::updateList(const int index)
@@ -395,15 +409,41 @@ void AboutPackage::updateList(const int index)
stream << *ver;
SetWindowText(report(), make_autostring(stream.str()).c_str());
+ vector<const Source *> uniqueSources;
+
const auto &sources = ver->sources();
for(auto it = sources.begin(); it != sources.end();) {
const Path &path = it->first;
const Source *src = it->second;
- list()->addRow({make_autostring(path.join()), make_autostring(src->url()),
+ list()->addRow({make_autostring(path.join()),
make_autostring(src->isMain() ? "Yes" : "No")});
+ uniqueSources.push_back(src);
+
// skip duplicate files
do { it++; } while(it != sources.end() && path == it->first);
}
+
+ swap(m_sources, uniqueSources);
+}
+
+bool AboutPackage::fillContextMenu(Menu &menu, const int) const
+{
+ if(list()->currentIndex() < 0)
+ return false;
+
+ menu.addAction(AUTO_STR("Copy source URL"), ACTION_COPY_URL);
+
+ return true;
+}
+
+void AboutPackage::copySourceUrl()
+{
+ const int index = list()->currentIndex();
+
+ if(index < 0)
+ return;
+
+ setClipboard(m_sources[index]->url());
}
diff --git a/src/about.hpp b/src/about.hpp
@@ -30,6 +30,7 @@ class Menu;
class Metadata;
class Package;
class RichEdit;
+class Source;
class TabBar;
struct Link;
@@ -87,7 +88,7 @@ protected:
void updateList(int) override;
private:
- bool fillContextMenu(Menu &, int index) const;
+ bool fillContextMenu(Menu &, int) const;
void updateInstalledFiles();
void aboutPackage();
@@ -104,11 +105,16 @@ protected:
ListView *createMenu() override;
ListView *createList() override;
+ void onCommand(int, int) override;
void populate() override;
void updateList(int) override;
private:
+ bool fillContextMenu(Menu &, int) const;
+ void copySourceUrl();
+
const Package *m_package;
+ std::vector<const Source *> m_sources;
};
#endif