@@ -920,13 +920,22 @@ QList<QAction *> QgsDirectoryItem::actions( QWidget *parent )
920920 connect ( createFolder, &QAction::triggered, this , [ = ]
921921 {
922922 bool ok = false ;
923- const QString name = QInputDialog::getText ( parent, tr ( " Create Directory" ), tr ( " Directory name" ), QLineEdit::Normal, QString (), &ok );
923+
924+ QWidget *parentWindow = parent;
925+ while ( parentWindow->parentWidget () )
926+ parentWindow = parentWindow->parentWidget ();
927+
928+ const QString name = QInputDialog::getText ( parentWindow, tr ( " Create Directory" ), tr ( " Directory name" ), QLineEdit::Normal, QString (), &ok );
924929 if ( ok && !name.isEmpty () )
925930 {
926931 QDir dir ( mDirPath );
927- if ( !dir.mkdir ( name ) )
932+ if ( QFileInfo::exists ( dir.absoluteFilePath ( name ) ) )
933+ {
934+ QMessageBox::critical ( parentWindow, tr ( " Create Directory" ), tr ( " The path “%1” already exists." ).arg ( QDir::toNativeSeparators ( dir.absoluteFilePath ( name ) ) ) );
935+ }
936+ else if ( !dir.mkdir ( name ) )
928937 {
929- QMessageBox::warning ( parent , tr ( " Create Directory" ), tr ( " Could not create directory “%1”" ).arg ( QDir::toNativeSeparators ( dir.absoluteFilePath ( name ) ) ) );
938+ QMessageBox::critical ( parentWindow , tr ( " Create Directory" ), tr ( " Could not create directory “%1”. " ).arg ( QDir::toNativeSeparators ( dir.absoluteFilePath ( name ) ) ) );
930939 }
931940 else
932941 {
@@ -936,7 +945,7 @@ QList<QAction *> QgsDirectoryItem::actions( QWidget *parent )
936945 } );
937946 result << createFolder;
938947
939- QAction *sep = new QAction ();
948+ QAction *sep = new QAction ( parent );
940949 sep->setSeparator ( true );
941950 result << sep;
942951
@@ -1522,7 +1531,7 @@ QList<QAction *> QgsProjectHomeItem::actions( QWidget *parent )
15221531 connect ( setHome, &QAction::triggered, this , [ = ]
15231532 {
15241533 QString oldHome = QgsProject::instance ()->homePath ();
1525- QString newPath = QFileDialog::getExistingDirectory ( parent, tr ( " Select Project Home Directory" ), oldHome );
1534+ QString newPath = QFileDialog::getExistingDirectory ( parent-> window () , tr ( " Select Project Home Directory" ), oldHome );
15261535 if ( !newPath.isEmpty () )
15271536 {
15281537 QgsProject::instance ()->setPresetHomePath ( newPath );
0 commit comments