Check for filename before selecting
Correct an error caught by @davidosterberg -- the non-native QFileDialog did not behave as expected when not provided with a default filename, so that case is now caught and the `selectFile()` call is bypassed.
This commit is contained in:
@@ -135,6 +135,7 @@ QString FileDialog::getSaveFileName (QWidget * parent, const QString & caption,
|
||||
const QString & filter, QString * selectedFilter, Options options)
|
||||
{
|
||||
QString dirName = dir;
|
||||
bool hasFilename = false;
|
||||
if (dirName.isEmpty()) {
|
||||
dirName = getWorkingDirectory();
|
||||
} else {
|
||||
@@ -144,6 +145,9 @@ QString FileDialog::getSaveFileName (QWidget * parent, const QString & caption,
|
||||
dirName += QLatin1String("/");
|
||||
dirName += fi.fileName();
|
||||
}
|
||||
if (!fi.fileName().isEmpty()) {
|
||||
hasFilename = true;
|
||||
}
|
||||
|
||||
// get the suffix for the filter: use the selected filter if there is one,
|
||||
// otherwise find the first valid suffix in the complete list of filters
|
||||
@@ -207,7 +211,8 @@ QString FileDialog::getSaveFileName (QWidget * parent, const QString & caption,
|
||||
dlg.setFileMode(QFileDialog::AnyFile);
|
||||
dlg.setAcceptMode(QFileDialog::AcceptSave);
|
||||
dlg.setDirectory(dirName);
|
||||
dlg.selectFile(dirName);
|
||||
if (hasFilename)
|
||||
dlg.selectFile(dirName);
|
||||
dlg.setOptions(options);
|
||||
dlg.setNameFilters(filter.split(QLatin1String(";;")));
|
||||
if (selectedFilter && !selectedFilter->isEmpty())
|
||||
|
||||
Reference in New Issue
Block a user