Commit ea0ea9c9 authored by Nate Graham's avatar Nate Graham 🔩

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
parent 24e66a25
......@@ -59,6 +59,7 @@
#include <KFilterBase>
#include <KFilterDev>
#include <KIO/Job>
#include <KIO/OpenFileManagerWindowJob>
#include <KJobWidgets>
#include <KMessageBox>
#include <KPasswordDialog>
......@@ -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"
......
......@@ -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;
......
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<kpartgui name="okular_part" version="40">
<kpartgui name="okular_part" version="41">
<MenuBar>
<Menu name="file"><text>&amp;File</text>
<Action name="get_new_stuff" group="file_open"/>
......@@ -9,6 +9,7 @@
<Action name="file_reload" group="file_save"/>
<Action name="file_print" group="file_print"/>
<Action name="file_print_preview" group="file_print"/>
<Action name="open_containing_folder" group="file_print"/>
<Action name="properties" group="file_print"/>
<Action name="embedded_files" group="file_print"/>
<Action name="file_export_as" group="file_print"/>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment