Add default filename for exports
When exporting a single file, the filename defaults to the current FCStd
name plus a dash and the name of the object. If multiple objects are
selected, the default is the basename of the FCStd file. No extension is
added. This behavior is controllable via two hidden preferences,
BaseApp/Preferences/General/ExportDefaultFilenameSingle
BaseApp/Preferences/General/ExportDefaultFilenameMultiple
_Allow regeneration of default on new exports_
If an export has been done and it used the default filename, on the next
export regenerate the filename (potentially updating the selected object
name in that filename) instead of just defaulting to the last name.
_Search for extension in chosen filter first_
Originally the file dialog simply searched for the first available extension
in the overall filter list. This commit modifies it to first check the
selected extension, and only if that is empty to search the full filter
list. This section of code only runs if a default filename is set but
does not have an extension ("suffix" in Qt's terms).
This commit is contained in:
@@ -145,13 +145,21 @@ QString FileDialog::getSaveFileName (QWidget * parent, const QString & caption,
|
||||
dirName += fi.fileName();
|
||||
}
|
||||
|
||||
// get the suffix for the filter
|
||||
// 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
|
||||
const QString *filterToSearch;
|
||||
if (selectedFilter != nullptr) {
|
||||
filterToSearch = selectedFilter;
|
||||
}
|
||||
else {
|
||||
filterToSearch = &filter;
|
||||
}
|
||||
QRegExp rx;
|
||||
rx.setPattern(QLatin1String("\\s(\\(\\*\\.\\w{1,})\\W"));
|
||||
int index = rx.indexIn(filter);
|
||||
int index = rx.indexIn(*filterToSearch);
|
||||
if (index != -1) {
|
||||
// get the suffix with the leading dot
|
||||
QString suffix = filter.mid(index+3, rx.matchedLength()-4);
|
||||
QString suffix = filterToSearch->mid(index+3, rx.matchedLength()-4);
|
||||
if (fi.suffix().isEmpty())
|
||||
dirName += suffix;
|
||||
}
|
||||
@@ -199,6 +207,7 @@ QString FileDialog::getSaveFileName (QWidget * parent, const QString & caption,
|
||||
dlg.setFileMode(QFileDialog::AnyFile);
|
||||
dlg.setAcceptMode(QFileDialog::AcceptSave);
|
||||
dlg.setDirectory(dirName);
|
||||
dlg.selectFile(dirName);
|
||||
dlg.setOptions(options);
|
||||
dlg.setNameFilters(filter.split(QLatin1String(";;")));
|
||||
if (selectedFilter && !selectedFilter->isEmpty())
|
||||
|
||||
Reference in New Issue
Block a user