Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set default suffix in "Save as..." file save dialog #2230

Merged
merged 1 commit into from
Dec 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/VersionedSaveDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
13 changes: 11 additions & 2 deletions src/core/Song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#include "TextFloat.h"
#include "TimeLineWidget.h"
#include "PeakController.h"
#include "VersionedSaveDialog.h"


tick_t MidiTime::s_ticksPerTact = DefaultTicksPerTact;
Expand Down Expand Up @@ -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( "(*." );
Expand All @@ -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();
}
Expand Down Expand Up @@ -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 );
Expand Down
20 changes: 18 additions & 2 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
27 changes: 25 additions & 2 deletions src/gui/dialogs/VersionedSaveDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
*/


#include <QLayout>
#include <QPushButton>
#include <QFontMetrics>
#include <QLayout>
#include <QLineEdit>
#include <QMessageBox>
#include <QPushButton>

#include "VersionedSaveDialog.h"

Expand Down Expand Up @@ -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;
}
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