Core: Fix filter when selected is not registered

Without this patch a warning will be triggered on Windows and
the selected filter is not chosen on all platforms when saving
a file, e.g. a json file.

Change-Id: Id6de0eddcac83369596f68d50494f10b70c30b15
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Marcus Tillmanns
2023-05-26 14:50:16 +02:00
parent aa2e8e3cb8
commit 9719bcfd2e

View File

@@ -856,7 +856,7 @@ FilePath DocumentManager::getSaveFileNameWithExtension(const QString &title, con
FilePath DocumentManager::getSaveAsFileName(const IDocument *document)
{
QTC_ASSERT(document, return {});
const QString filter = allDocumentFactoryFiltersString();
QString filter = allDocumentFactoryFiltersString();
const FilePath filePath = document->filePath();
QString selectedFilter;
FilePath fileDialogPath = filePath;
@@ -876,6 +876,9 @@ FilePath DocumentManager::getSaveAsFileName(const IDocument *document)
if (selectedFilter.isEmpty())
selectedFilter = Utils::mimeTypeForName(document->mimeType()).filterString();
if (!filter.contains(selectedFilter))
filter.prepend(selectedFilter + QLatin1String(";;"));
return getSaveFileName(Tr::tr("Save File As"),
fileDialogPath,
filter,