From 9e1b10831a5c89f4f01e39ff5b02021ff6d037d7 Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Fri, 21 Jan 2022 16:48:43 +0800 Subject: [PATCH] feat: open containing folder --- app/actionmanager.cpp | 2 ++ app/actionmanager.h | 1 + app/mainwindow.cpp | 21 +++++++++++++++++++++ app/mainwindow.h | 1 + 4 files changed, 25 insertions(+) diff --git a/app/actionmanager.cpp b/app/actionmanager.cpp index 63d803c..402c8c7 100644 --- a/app/actionmanager.cpp +++ b/app/actionmanager.cpp @@ -52,6 +52,7 @@ void ActionManager::setupAction(MainWindow *mainWindow) CREATE_NEW_ACTION(mainWindow, actionToggleProtectMode); CREATE_NEW_ACTION(mainWindow, actionSettings); CREATE_NEW_ACTION(mainWindow, actionHelp); + CREATE_NEW_ACTION(mainWindow, actionLocateInFileManager); CREATE_NEW_ACTION(mainWindow, actionProperties); CREATE_NEW_ACTION(mainWindow, actionQuitApp); @@ -86,6 +87,7 @@ void ActionManager::retranslateUi(MainWindow *mainWindow) actionToggleProtectMode->setText(QCoreApplication::translate("MainWindow", "Protected mode", nullptr)); actionSettings->setText(QCoreApplication::translate("MainWindow", "Configure...", nullptr)); actionHelp->setText(QCoreApplication::translate("MainWindow", "Help", nullptr)); + actionLocateInFileManager->setText("Open Containing Folder"); // TODO: what should it called? actionProperties->setText(QCoreApplication::translate("MainWindow", "Properties", nullptr)); actionQuitApp->setText(QCoreApplication::translate("MainWindow", "Quit", nullptr)); } diff --git a/app/actionmanager.h b/app/actionmanager.h index 2577fde..9ea6fca 100644 --- a/app/actionmanager.h +++ b/app/actionmanager.h @@ -38,6 +38,7 @@ public: QAction *actionToggleProtectMode; QAction *actionSettings; QAction *actionHelp; + QAction *actionLocateInFileManager; QAction *actionProperties; QAction *actionQuitApp; }; diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp index e18e83a..b7f8855 100644 --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -29,6 +29,8 @@ #include #include #include +#include +#include MainWindow::MainWindow(QWidget *parent) : FramelessWindow(parent) @@ -437,6 +439,9 @@ void MainWindow::contextMenuEvent(QContextMenuEvent *event) menu->addAction(helpAction); if (currentFileUrl.isValid()) { menu->addSeparator(); + if (currentFileUrl.isLocalFile()) { + menu->addAction(m_am->actionLocateInFileManager); + } menu->addAction(propertiesAction); } menu->exec(mapToGlobal(event->pos())); @@ -703,6 +708,22 @@ void MainWindow::on_actionProperties_triggered() ad->deleteLater(); } +void MainWindow::on_actionLocateInFileManager_triggered() +{ + QUrl currentFileUrl = currentImageFileUrl(); + if (!currentFileUrl.isValid()) return; + + QFileInfo fileInfo(currentFileUrl.toLocalFile()); + if (!fileInfo.exists()) return; + +#ifdef Q_OS_WIN + QProcess::startDetached("explorer", QStringList() << "/select," << QDir::toNativeSeparators(fileInfo.absoluteFilePath())); +#else + // maybe use https://www.freedesktop.org/wiki/Specifications/file-manager-interface/ for linux? + QDesktopServices::openUrl(QUrl::fromLocalFile(fileInfo.absolutePath())); +#endif // Q_OS_WIN +} + void MainWindow::on_actionQuitApp_triggered() { quitAppAction(false); diff --git a/app/mainwindow.h b/app/mainwindow.h index e8e7fd1..3017d0b 100644 --- a/app/mainwindow.h +++ b/app/mainwindow.h @@ -91,6 +91,7 @@ private slots: void on_actionSettings_triggered(); void on_actionHelp_triggered(); void on_actionProperties_triggered(); + void on_actionLocateInFileManager_triggered(); void on_actionQuitApp_triggered(); private: