Commit 189299f3 authored by dogmaphobic's avatar dogmaphobic

Appending required extension when it is not the one used (when in strict mode).

Added a dialog asking the user about overwritting an existing file.
parent 1e8545f7
...@@ -130,7 +130,6 @@ QString QGCFileDialog::getSaveFileName(QWidget* parent, ...@@ -130,7 +130,6 @@ QString QGCFileDialog::getSaveFileName(QWidget* parent,
if (_validateExtension(filter, userSuffix)) { if (_validateExtension(filter, userSuffix)) {
return result; return result;
} }
#if 0 //-- If we ever want to propose replacing the extension, we can guess the replacement below
//-- Do we have a default extension? //-- Do we have a default extension?
QString localDefaultSuffix; QString localDefaultSuffix;
if (!defaultSuffix) { if (!defaultSuffix) {
...@@ -139,23 +138,30 @@ QString QGCFileDialog::getSaveFileName(QWidget* parent, ...@@ -139,23 +138,30 @@ QString QGCFileDialog::getSaveFileName(QWidget* parent,
defaultSuffix = &localDefaultSuffix; defaultSuffix = &localDefaultSuffix;
} }
Q_ASSERT(defaultSuffix->isEmpty() == false); Q_ASSERT(defaultSuffix->isEmpty() == false);
QString proposed = fi.completeBaseName(); //-- Forcefully append our desired extension
proposed += "."; result += ".";
proposed += *defaultSuffix; result += *defaultSuffix;
#endif //-- Check and see if this new file already exists
//-- Ask user what to do fi.setFile(result);
QMessageBox msgBox( if (fi.exists()) {
QMessageBox::Critical, //-- Ask user what to do
tr("Invalid File Extension."), QMessageBox msgBox(
tr("The given extension (.%1) is not a valid extension for this type of file.").arg(userSuffix), QMessageBox::Warning,
QMessageBox::Cancel, tr("File Exists"),
parent); tr("%1 already exists.\nDo you want to replace it?").arg(fi.fileName()),
msgBox.setDefaultButton(QMessageBox::Cancel); QMessageBox::Cancel,
msgBox.setWindowModality(Qt::ApplicationModal); parent);
QPushButton *retryButton = msgBox.addButton(tr("Retry"), QMessageBox::ActionRole); msgBox.addButton(QMessageBox::Retry);
msgBox.exec(); QPushButton *overwriteButton = msgBox.addButton(tr("Replace"), QMessageBox::ActionRole);
if (msgBox.clickedButton() == retryButton) { msgBox.setDefaultButton(QMessageBox::Retry);
continue; msgBox.setWindowModality(Qt::ApplicationModal);
if (msgBox.exec() == QMessageBox::Retry) {
continue;
} else if (msgBox.clickedButton() == overwriteButton) {
return result;
}
} else {
return result;
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment