Set default suffix (#2230)

This commit is contained in:
Oskar Wallgren
2016-12-14 15:41:30 +01:00
committed by GitHub
parent 65d193ce1a
commit e1c598ba21
5 changed files with 56 additions and 6 deletions

View File

@@ -44,6 +44,7 @@ public:
// 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();

View File

@@ -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 );

View File

@@ -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 )

View File

@@ -23,10 +23,11 @@
*/
#include <QLayout>
#include <QPushButton>
#include <QFontMetrics>
#include <QLayout>
#include <QLineEdit>
#include <QMessageBox>
#include <QPushButton>
#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;
}

View File

@@ -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() &&