diff --git a/window.cpp b/window.cpp index 662a66b..3fc50b0 100644 --- a/window.cpp +++ b/window.cpp @@ -24,6 +24,8 @@ #include #include #include +#include +#include Window::Window(const QVector &configs, const QString &dbpath) { this->userEntryButtons = generateEntryButtons(configs); @@ -57,6 +59,28 @@ void Window::initTreeWidgets() treeFileSearchResults.setHeaderLabels(headers); treeFileSearchResults.header()->setSectionResizeMode(QHeaderView::ResizeToContents); connect(&treeFileSearchResults, &QTreeWidget::itemActivated, this, &Window::treeSearchItemActivated); + treeFileSearchResults.setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu); + connect(&treeFileSearchResults, &QTreeWidget::customContextMenuRequested, this, &Window::showSearchResultsContextMenu); +} + + +void Window::showSearchResultsContextMenu(const QPoint &point) +{ + QTreeWidgetItem *item = treeFileSearchResults.itemAt(point); + if(item == nullptr) + { + return; + } + QMenu menu("Test", this); + menu.addAction("Copy filename to clipboard", [&] { QGuiApplication::clipboard()->setText(item->text(0));}); + menu.addAction("Copy full path to clipboard", [&] { QGuiApplication::clipboard()->setText(item->text(1)); }); + menu.addAction("Open containing folder", [&] { + QFileInfo pathinfo(item->text(1)); + QString dir = pathinfo.absolutePath(); + QDesktopServices::openUrl(QUrl::fromLocalFile(dir)); + + }); + menu.exec(QCursor::pos()); } QVector Window::generateEntryButtons(const QVector &configs) diff --git a/window.h b/window.h index 1484fc5..963b3e6 100644 --- a/window.h +++ b/window.h @@ -69,6 +69,7 @@ class Window : public QWidget void handleSearchResults(const QVector &results); void handleCancelledSearch(); void treeSearchItemActivated(QTreeWidgetItem *item, int i); + void showSearchResultsContextMenu(const QPoint &point); signals: void beginFileSearch(const QString &query); void beginContentSearch(const QString &query);