Skip to content

Commit

Permalink
Merge pull request #5220 from nyalldawson/open_folder
Browse files Browse the repository at this point in the history
[FEATURE] Add 'open directory' action to right click menu for folders in browser dock
  • Loading branch information
nyalldawson committed Sep 20, 2017
2 parents 825a323 + 21fc2e1 commit e6169d8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
3 changes: 3 additions & 0 deletions python/core/qgsdataitem.sip
Expand Up @@ -533,6 +533,9 @@ Check if the given path is hidden from the browser model
:rtype: bool
%End

virtual QList<QAction *> actions();



public slots:
virtual void childrenCreated();
Expand Down
18 changes: 16 additions & 2 deletions src/core/qgsdataitem.cpp
Expand Up @@ -27,6 +27,7 @@
#include <QTreeWidgetItem>
#include <QVector>
#include <QStyle>
#include <QDesktopServices>

#include "qgis.h"
#include "qgsdataitem.h"
Expand Down Expand Up @@ -669,7 +670,7 @@ QgsDataCollectionItem::~QgsDataCollectionItem()
//-----------------------------------------------------------------------

QgsDirectoryItem::QgsDirectoryItem( QgsDataItem *parent, const QString &name, const QString &path )
: QgsDataCollectionItem( parent, name, path )
: QgsDataCollectionItem( parent, QDir::toNativeSeparators( name ), path )
, mDirPath( path )
, mRefreshLater( false )
{
Expand All @@ -678,7 +679,7 @@ QgsDirectoryItem::QgsDirectoryItem( QgsDataItem *parent, const QString &name, co
}

QgsDirectoryItem::QgsDirectoryItem( QgsDataItem *parent, const QString &name, const QString &dirPath, const QString &path )
: QgsDataCollectionItem( parent, name, path )
: QgsDataCollectionItem( parent, QDir::toNativeSeparators( name ), path )
, mDirPath( dirPath )
, mRefreshLater( false )
{
Expand All @@ -688,6 +689,7 @@ QgsDirectoryItem::QgsDirectoryItem( QgsDataItem *parent, const QString &name, co

void QgsDirectoryItem::init()
{
setToolTip( QDir::toNativeSeparators( mDirPath ) );
}

QIcon QgsDirectoryItem::icon()
Expand Down Expand Up @@ -852,6 +854,18 @@ bool QgsDirectoryItem::hiddenPath( const QString &path )
return ( idx > -1 );
}

QList<QAction *> QgsDirectoryItem::actions()
{
QList<QAction *> 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()
{
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsdataitem.h
Expand Up @@ -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<QAction *> actions() override;


public slots:
virtual void childrenCreated() override;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsbrowserdockwidget_p.cpp
Expand Up @@ -234,7 +234,7 @@ void QgsBrowserDirectoryProperties::setItem( QgsDataItem *item )
if ( !item )
return;

mPathLabel->setText( directoryItem->dirPath() );
mPathLabel->setText( QDir::toNativeSeparators( directoryItem->dirPath() ) );
mDirectoryWidget = new QgsDirectoryParamWidget( directoryItem->dirPath(), this );
mLayout->addWidget( mDirectoryWidget );
}
Expand Down

0 comments on commit e6169d8

Please sign in to comment.