Skip to content

Commit faa119f

Browse files
committed
Fix cannot use browser dock to create new folders
1 parent e375d1d commit faa119f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/core/qgsdataitem.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include <QStyle>
3030
#include <QDesktopServices>
3131
#include <QFileDialog>
32+
#include <QInputDialog>
33+
#include <QMessageBox>
3234

3335
#include "qgis.h"
3436
#include "qgsdataitem.h"
@@ -913,6 +915,31 @@ bool QgsDirectoryItem::hiddenPath( const QString &path )
913915
QList<QAction *> QgsDirectoryItem::actions( QWidget *parent )
914916
{
915917
QList<QAction *> result;
918+
919+
QAction *createFolder = new QAction( tr( "New Directory…" ), parent );
920+
connect( createFolder, &QAction::triggered, this, [ = ]
921+
{
922+
bool ok = false;
923+
const QString name = QInputDialog::getText( parent, tr( "Create Directory" ), tr( "Directory name" ), QLineEdit::Normal, QString(), &ok );
924+
if ( ok && !name.isEmpty() )
925+
{
926+
QDir dir( mDirPath );
927+
if ( !dir.mkdir( name ) )
928+
{
929+
QMessageBox::warning( parent, tr( "Create Directory" ), tr( "Could not create directory “%1”" ).arg( QDir::toNativeSeparators( dir.absoluteFilePath( name ) ) ) );
930+
}
931+
else
932+
{
933+
refresh();
934+
}
935+
}
936+
} );
937+
result << createFolder;
938+
939+
QAction *sep = new QAction();
940+
sep->setSeparator( true );
941+
result << sep;
942+
916943
QAction *openFolder = new QAction( tr( "Open Directory…" ), parent );
917944
connect( openFolder, &QAction::triggered, this, [ = ]
918945
{

0 commit comments

Comments
 (0)