diff --git a/include/VersionedSaveDialog.h b/include/VersionedSaveDialog.h index 22fda676fcf..f91eae55ffd 100644 --- a/include/VersionedSaveDialog.h +++ b/include/VersionedSaveDialog.h @@ -44,6 +44,7 @@ class VersionedSaveDialog : public FileDialog // Returns true if file name was changed, returns false if it wasn't static bool changeFileNameVersion( QString &fileName, bool increment ); + static bool fileExistsQuery( QString FileName, QString WindowTitle ); public slots: void incrementVersion(); diff --git a/src/core/Song.cpp b/src/core/Song.cpp index 10eb827e102..ad34c73ed5a 100644 --- a/src/core/Song.cpp +++ b/src/core/Song.cpp @@ -66,6 +66,7 @@ #include "TextFloat.h" #include "TimeLineWidget.h" #include "PeakController.h" +#include "VersionedSaveDialog.h" tick_t MidiTime::s_ticksPerTact = DefaultTicksPerTact; @@ -1295,9 +1296,11 @@ void Song::exportProject( bool multiExport ) efd.setAcceptMode( FileDialog::AcceptSave ); - if( efd.exec() == QDialog::Accepted && !efd.selectedFiles().isEmpty() && !efd.selectedFiles()[0].isEmpty() ) + if( efd.exec() == QDialog::Accepted && !efd.selectedFiles().isEmpty() && + !efd.selectedFiles()[0].isEmpty() ) { QString suffix = ""; + QString exportFileName = efd.selectedFiles()[0]; if ( !multiExport ) { int stx = efd.selectedNameFilter().indexOf( "(*." ); @@ -1315,7 +1318,12 @@ void Song::exportProject( bool multiExport ) } } - const QString exportFileName = efd.selectedFiles()[0] + suffix; + if( VersionedSaveDialog::fileExistsQuery( exportFileName + suffix, + tr( "Save project" ) ) ) + { + exportFileName += suffix; + } + ExportProjectDialog epd( exportFileName, gui->mainWindow(), multiExport ); epd.exec(); } @@ -1353,6 +1361,7 @@ void Song::exportProjectMidi() base_filename = tr( "untitled" ); } efd.selectFile( base_filename + ".mid" ); + efd.setDefaultSuffix( "mid"); efd.setWindowTitle( tr( "Select file for project-export..." ) ); efd.setAcceptMode( FileDialog::AcceptSave ); diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 5d2bb9059eb..502d9bb5a92 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -957,13 +957,29 @@ bool MainWindow::saveProjectAs() sfd.setDirectory( ConfigManager::inst()->userProjectsDir() ); } + // Don't write over file with suffix if no suffix is provided. + QString suffix = ConfigManager::inst()->value( "app", + "nommpz" ).toInt() == 0 + ? "mmpz" + : "mmp" ; + sfd.setDefaultSuffix( suffix ); + if( sfd.exec () == FileDialog::Accepted && !sfd.selectedFiles().isEmpty() && sfd.selectedFiles()[0] != "" ) { QString fname = sfd.selectedFiles()[0] ; - if( sfd.selectedNameFilter().contains( "(*.mpt)" ) && !sfd.selectedFiles()[0].endsWith( ".mpt" ) ) + if( sfd.selectedNameFilter().contains( "(*.mpt)" ) ) { - fname += ".mpt"; + // Remove the default suffix + fname.remove( "." + suffix ); + if( !sfd.selectedFiles()[0].endsWith( ".mpt" ) ) + { + if( VersionedSaveDialog::fileExistsQuery( fname + ".mpt", + tr( "Save project template" ) ) ) + { + fname += ".mpt"; + } + } } Engine::getSong()->guiSaveProjectAs( fname ); if( getSession() == Recover ) diff --git a/src/gui/dialogs/VersionedSaveDialog.cpp b/src/gui/dialogs/VersionedSaveDialog.cpp index 476046371c2..df5071cb43c 100644 --- a/src/gui/dialogs/VersionedSaveDialog.cpp +++ b/src/gui/dialogs/VersionedSaveDialog.cpp @@ -23,10 +23,11 @@ */ -#include -#include #include +#include #include +#include +#include #include "VersionedSaveDialog.h" @@ -137,3 +138,25 @@ void VersionedSaveDialog::decrementVersion() } + + +bool VersionedSaveDialog::fileExistsQuery( QString FileName, QString WindowTitle ) +{ + bool fileExists = false; + if( QFile( FileName ).exists() ) + { + QMessageBox mb; + mb.setWindowTitle( WindowTitle ); + mb.setText( FileName + tr( " already exists. " + "Do you want to replace it?" ) ); + mb.setIcon( QMessageBox::Warning ); + mb.setStandardButtons( + QMessageBox::Yes | QMessageBox::No ); + + if( mb.exec() == QMessageBox::Yes ) + { + fileExists = true; + } + } + return fileExists; +} diff --git a/src/tracks/InstrumentTrack.cpp b/src/tracks/InstrumentTrack.cpp index 151cd29beee..f3e3ea6ed01 100644 --- a/src/tracks/InstrumentTrack.cpp +++ b/src/tracks/InstrumentTrack.cpp @@ -1577,6 +1577,7 @@ void InstrumentTrackWindow::saveSettingsBtnClicked() sfd.setFileMode( FileDialog::AnyFile ); QString fname = m_track->name(); sfd.selectFile( fname.remove(QRegExp("[^a-zA-Z0-9_\\-\\d\\s]")) ); + sfd.setDefaultSuffix( "xpf"); if( sfd.exec() == QDialog::Accepted && !sfd.selectedFiles().isEmpty() &&