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
fi.setFile(result);
if (fi.exists()) {
//-- Ask user what to do //-- Ask user what to do
QMessageBox msgBox( QMessageBox msgBox(
QMessageBox::Critical, QMessageBox::Warning,
tr("Invalid File Extension."), tr("File Exists"),
tr("The given extension (.%1) is not a valid extension for this type of file.").arg(userSuffix), tr("%1 already exists.\nDo you want to replace it?").arg(fi.fileName()),
QMessageBox::Cancel, QMessageBox::Cancel,
parent); parent);
msgBox.setDefaultButton(QMessageBox::Cancel); msgBox.addButton(QMessageBox::Retry);
QPushButton *overwriteButton = msgBox.addButton(tr("Replace"), QMessageBox::ActionRole);
msgBox.setDefaultButton(QMessageBox::Retry);
msgBox.setWindowModality(Qt::ApplicationModal); msgBox.setWindowModality(Qt::ApplicationModal);
QPushButton *retryButton = msgBox.addButton(tr("Retry"), QMessageBox::ActionRole); if (msgBox.exec() == QMessageBox::Retry) {
msgBox.exec();
if (msgBox.clickedButton() == retryButton) {
continue; 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