Skip to content

Commit

Permalink
Make save as initial path default to current project path instead
Browse files Browse the repository at this point in the history
of last used path

This is more logical (as you're more likely to want to save
a copy of the project somewhere near the original as opposed
to wherever the last project was saved (which is effectively
random!))
  • Loading branch information
nyalldawson committed Aug 8, 2018
1 parent d90348d commit 91c6556
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/app/qgisapp.cpp
Expand Up @@ -5939,23 +5939,34 @@ bool QgisApp::fileSave()

void QgisApp::fileSaveAs()
{
// Retrieve last used project dir from persistent settings
QgsSettings settings;
QString lastUsedDir = settings.value( QStringLiteral( "UI/lastProjectDir" ), QDir::homePath() ).toString();
QString defaultPath;
// First priority is to default to same path as existing file
const QString currentPath = QgsProject::instance()->absoluteFilePath();
if ( !currentPath.isEmpty() )
{
defaultPath = currentPath;
}
else
{
// Retrieve last used project dir from persistent settings
QgsSettings settings;
defaultPath = settings.value( QStringLiteral( "UI/lastProjectDir" ), QDir::homePath() ).toString();
defaultPath += + '/' + QgsProject::instance()->title();
}

const QString qgsExt = tr( "QGIS files" ) + " (*.qgs *.QGS)";
const QString zipExt = tr( "QGZ files" ) + " (*.qgz)";
QString filter;
QString path = QFileDialog::getSaveFileName( this,
tr( "Save Project As" ),
lastUsedDir + '/' + QgsProject::instance()->title(),
defaultPath,
zipExt + ";;" + qgsExt, &filter );
if ( path.isEmpty() )
return;

QFileInfo fullPath( path );

settings.setValue( QStringLiteral( "UI/lastProjectDir" ), fullPath.path() );
QgsSettings().setValue( QStringLiteral( "UI/lastProjectDir" ), fullPath.path() );

if ( filter == zipExt )
{
Expand Down

0 comments on commit 91c6556

Please sign in to comment.