From ea0ea9c93da55be6da61d7ce73c0ceb8343564e2 Mon Sep 17 00:00:00 2001 From: Nate Graham Date: Fri, 28 Jun 2019 09:41:15 -0600 Subject: [PATCH] Add "Open Containing Folder" feature Summary: This patch adds an "Open Containing Folder" menu item to the file menu, similar to other KDE apps like Gwenview that have it there. This action is especially useful for the case when you've downloaded a PDF from the internet that opens itself in Okular. The location of this file may not be clear or easy to find without this feature, and on several occasiona I have found myself wishing for it when this happens. Test Plan: - Delete or move aside `~/.local/config/kxmlgui5/okular/part.rc` - Menu item is enabled and works when there is an open document: {F6940449, size=full} - Menu item is disabled when there is no open document: {F6940448, size=full} Reviewers: #okular, aacid, sander Reviewed By: #okular, aacid Subscribers: shubham, davidhurka, okular-devel Tags: #okular Differential Revision: https://phabricator.kde.org/D22145 --- part.cpp | 14 ++++++++++++++ part.h | 2 ++ part.rc | 3 ++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/part.cpp b/part.cpp index 1cbd9acea..9e8fb3d97 100644 --- a/part.cpp +++ b/part.cpp @@ -59,6 +59,7 @@ #include #include #include +#include #include #include #include @@ -737,6 +738,7 @@ void Part::setupViewerActions() m_save = nullptr; m_saveAs = nullptr; + m_openContainingFolder = nullptr; QAction * prefs = KStandardAction::preferences( this, SLOT(slotPreferences()), ac); if ( m_embedMode == NativeShellMode ) @@ -913,6 +915,12 @@ void Part::setupActions() ac->setDefaultShortcut(m_showPresentation, QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_P)); m_showPresentation->setEnabled( false ); + m_openContainingFolder = ac->addAction(QStringLiteral("open_containing_folder")); + m_openContainingFolder->setText(i18n("Open Con&taining Folder")); + m_openContainingFolder->setIcon( QIcon::fromTheme( QStringLiteral("document-open-folder") ) ); + connect(m_openContainingFolder, &QAction::triggered, this, &Part::slotOpenContainingFolder); + m_openContainingFolder->setEnabled( false ); + QAction * importPS = ac->addAction(QStringLiteral("import_ps")); importPS->setText(i18n("&Import PostScript as PDF...")); importPS->setIcon(QIcon::fromTheme(QStringLiteral("document-import"))); @@ -1571,6 +1579,7 @@ bool Part::openFile() emit enablePrintAction( ok && m_document->printingSupport() != Okular::Document::NoPrinting ); m_printPreview->setEnabled( ok && m_document->printingSupport() != Okular::Document::NoPrinting ); m_showProperties->setEnabled( ok ); + if( m_openContainingFolder ) m_openContainingFolder->setEnabled( ok ); bool hasEmbeddedFiles = ok && m_document->embeddedFiles() && m_document->embeddedFiles()->count() > 0; if ( m_showEmbeddedFiles ) m_showEmbeddedFiles->setEnabled( hasEmbeddedFiles ); m_topMessage->setVisible( hasEmbeddedFiles && Okular::Settings::showOSD() ); @@ -3698,6 +3707,11 @@ void Part::enableStartWithFind(const QString &text) m_textToFindOnOpen = QString(text); } +void Part::slotOpenContainingFolder() +{ + KIO::highlightInFileManager( { QUrl(localFilePath()) } ); +} + } // namespace Okular #include "part.moc" diff --git a/part.h b/part.h index 3958b28ac..1f6db9982 100644 --- a/part.h +++ b/part.h @@ -167,6 +167,7 @@ class OKULARPART_EXPORT Part : public KParts::ReadWritePart, public Okular::Docu Q_SCRIPTABLE Q_NOREPLY void enableStartWithPrint(); Q_SCRIPTABLE Q_NOREPLY void enableExitAfterPrint(); Q_SCRIPTABLE Q_NOREPLY void enableStartWithFind(const QString &text); + Q_SCRIPTABLE void slotOpenContainingFolder(); Q_SIGNALS: void enablePrintAction(bool enable); @@ -374,6 +375,7 @@ class OKULARPART_EXPORT Part : public KParts::ReadWritePart, public Okular::Docu QAction *m_share; #endif QAction *m_showPresentation; + QAction *m_openContainingFolder; KToggleAction* m_showMenuBarAction; KToggleAction* m_showLeftPanel; KToggleAction* m_showBottomBar; diff --git a/part.rc b/part.rc index bf15cac50..8ba1afc4f 100644 --- a/part.rc +++ b/part.rc @@ -1,5 +1,5 @@ - + &File @@ -9,6 +9,7 @@ +