Skip to content

Commit

Permalink
Set default suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
zonkmachine committed Nov 28, 2016
1 parent 68d8152 commit 1fa761e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
24 changes: 22 additions & 2 deletions src/core/Song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1295,9 +1295,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( "(*." );
Expand All @@ -1315,7 +1317,24 @@ void Song::exportProject( bool multiExport )
}
}

const QString exportFileName = efd.selectedFiles()[0] + suffix;
exportFileName += suffix;
if( QFileInfo( exportFileName ).exists() )
{
QMessageBox mb;
mb.setWindowTitle( tr( "Export project" ) );
mb.setText( exportFileName + tr( " already exists. "
"Do you want to replace it?" ) );
mb.setIcon( QMessageBox::Warning );
mb.setStandardButtons(
QMessageBox::Yes | QMessageBox::No );

int answer = mb.exec();
if( answer == QMessageBox::No )
{
return;
}
}

ExportProjectDialog epd( exportFileName, gui->mainWindow(), multiExport );
epd.exec();
}
Expand Down Expand Up @@ -1353,6 +1372,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 );
Expand Down
32 changes: 30 additions & 2 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,13 +957,41 @@ 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( QFile( fname + ".mpt" ).exists() )
{
QMessageBox mb;
mb.setWindowTitle( tr( "Save project" ) );
mb.setText( fname + ".mpt" + tr( " already exists. "
"Do you want to replace it?" ) );
mb.setIcon( QMessageBox::Warning );
mb.setStandardButtons(
QMessageBox::Yes | QMessageBox::No );

int answer = mb.exec();
if( answer == QMessageBox::No )
{
return( false );
}
}
fname += ".mpt";
}
}
Engine::getSong()->guiSaveProjectAs( fname );
if( getSession() == Recover )
Expand Down
1 change: 1 addition & 0 deletions src/tracks/InstrumentTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() &&
Expand Down

0 comments on commit 1fa761e

Please sign in to comment.