Skip to content

Commit

Permalink
Correctly parent actions
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Oct 3, 2018
1 parent faa119f commit 5774b9a
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/core/qgsdataitem.cpp
Expand Up @@ -920,13 +920,22 @@ QList<QAction *> QgsDirectoryItem::actions( QWidget *parent )
connect( createFolder, &QAction::triggered, this, [ = ]
{
bool ok = false;
const QString name = QInputDialog::getText( parent, tr( "Create Directory" ), tr( "Directory name" ), QLineEdit::Normal, QString(), &ok );

QWidget *parentWindow = parent;
while ( parentWindow->parentWidget() )
parentWindow = parentWindow->parentWidget();

const QString name = QInputDialog::getText( parentWindow, tr( "Create Directory" ), tr( "Directory name" ), QLineEdit::Normal, QString(), &ok );
if ( ok && !name.isEmpty() )
{
QDir dir( mDirPath );
if ( !dir.mkdir( name ) )
if ( QFileInfo::exists( dir.absoluteFilePath( name ) ) )
{
QMessageBox::critical( parentWindow, tr( "Create Directory" ), tr( "The path “%1” already exists." ).arg( QDir::toNativeSeparators( dir.absoluteFilePath( name ) ) ) );
}
else if ( !dir.mkdir( name ) )
{
QMessageBox::warning( parent, tr( "Create Directory" ), tr( "Could not create directory “%1”" ).arg( QDir::toNativeSeparators( dir.absoluteFilePath( name ) ) ) );
QMessageBox::critical( parentWindow, tr( "Create Directory" ), tr( "Could not create directory “%1”." ).arg( QDir::toNativeSeparators( dir.absoluteFilePath( name ) ) ) );
}
else
{
Expand All @@ -936,7 +945,7 @@ QList<QAction *> QgsDirectoryItem::actions( QWidget *parent )
} );
result << createFolder;

QAction *sep = new QAction();
QAction *sep = new QAction( parent );
sep->setSeparator( true );
result << sep;

Expand Down Expand Up @@ -1522,7 +1531,7 @@ QList<QAction *> QgsProjectHomeItem::actions( QWidget *parent )
connect( setHome, &QAction::triggered, this, [ = ]
{
QString oldHome = QgsProject::instance()->homePath();
QString newPath = QFileDialog::getExistingDirectory( parent, tr( "Select Project Home Directory" ), oldHome );
QString newPath = QFileDialog::getExistingDirectory( parent->window(), tr( "Select Project Home Directory" ), oldHome );
if ( !newPath.isEmpty() )
{
QgsProject::instance()->setPresetHomePath( newPath );
Expand Down

0 comments on commit 5774b9a

Please sign in to comment.