From 6ce3c6100df98fc9e4e29fba7618e6b6ba96c2f4 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Wed, 20 Sep 2017 09:24:02 +1000 Subject: [PATCH] [FEATURE] Add 'open directory' action to right click menu for folders in browser dock Opens the folder in the OS' file explorer --- python/core/qgsdataitem.sip | 3 +++ src/core/qgsdataitem.cpp | 13 +++++++++++++ src/core/qgsdataitem.h | 2 ++ 3 files changed, 18 insertions(+) diff --git a/python/core/qgsdataitem.sip b/python/core/qgsdataitem.sip index bf1484bffc5..f7ac491fc5e 100644 --- a/python/core/qgsdataitem.sip +++ b/python/core/qgsdataitem.sip @@ -533,6 +533,9 @@ Check if the given path is hidden from the browser model :rtype: bool %End + virtual QList actions(); + + public slots: virtual void childrenCreated(); diff --git a/src/core/qgsdataitem.cpp b/src/core/qgsdataitem.cpp index a4e76a68a16..991b62ed93c 100644 --- a/src/core/qgsdataitem.cpp +++ b/src/core/qgsdataitem.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include "qgis.h" #include "qgsdataitem.h" @@ -852,6 +853,18 @@ bool QgsDirectoryItem::hiddenPath( const QString &path ) return ( idx > -1 ); } +QList QgsDirectoryItem::actions() +{ + QList result; + QAction *openFolder = new QAction( tr( "Open Directory…" ), this ); + connect( openFolder, &QAction::triggered, this, [ = ] + { + QDesktopServices::openUrl( QUrl::fromLocalFile( mDirPath ) ); + } ); + result << openFolder; + return result; +} + void QgsDirectoryItem::childrenCreated() { diff --git a/src/core/qgsdataitem.h b/src/core/qgsdataitem.h index 94cc92df1bb..14c9ccf22c0 100644 --- a/src/core/qgsdataitem.h +++ b/src/core/qgsdataitem.h @@ -476,6 +476,8 @@ class CORE_EXPORT QgsDirectoryItem : public QgsDataCollectionItem //! Check if the given path is hidden from the browser model static bool hiddenPath( const QString &path ); + QList actions() override; + public slots: virtual void childrenCreated() override;