Commit 2d5d62fd authored by Eike Ziller's avatar Eike Ziller

Restrict suggested file filters to registered supported mime types

When using File > Open File or Project, and with Save As.
It was containing all mime types registered in Qt Creator, including the
default one from freedesktop.org, most of them being not interesting.

Task-number: QTCREATORBUG-17913
Change-Id: Ic5e49b27b566eb41419240b78a6cd99b233aeb07
Reviewed-by: Tobias Hunger's avatarTobias Hunger <tobias.hunger@qt.io>
parent 2a651bf4
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "icore.h" #include "icore.h"
#include "idocument.h" #include "idocument.h"
#include "idocumentfactory.h"
#include "coreconstants.h" #include "coreconstants.h"
#include <coreplugin/diffservice.h> #include <coreplugin/diffservice.h>
...@@ -710,6 +711,33 @@ bool DocumentManager::saveDocument(IDocument *document, const QString &fileName, ...@@ -710,6 +711,33 @@ bool DocumentManager::saveDocument(IDocument *document, const QString &fileName,
return ret; return ret;
} }
template<typename FactoryType>
QSet<QString> filterStrings()
{
QSet<QString> filters;
for (FactoryType *factory : ExtensionSystem::PluginManager::getObjects<FactoryType>()) {
for (const QString &mt : factory->mimeTypes()) {
const QString filter = mimeTypeForName(mt).filterString();
if (!filter.isEmpty())
filters.insert(filter);
}
}
return filters;
}
QString DocumentManager::allDocumentFactoryFiltersString(QString *allFilesFilter = 0)
{
const QSet<QString> uniqueFilters = filterStrings<IDocumentFactory>()
+ filterStrings<IEditorFactory>();
QStringList filters = uniqueFilters.toList();
filters.sort();
const QString allFiles = Utils::allFilesFilterString();
if (allFilesFilter)
*allFilesFilter = allFiles;
filters.prepend(allFiles);
return filters.join(QLatin1String(";;"));
}
QString DocumentManager::getSaveFileName(const QString &title, const QString &pathIn, QString DocumentManager::getSaveFileName(const QString &title, const QString &pathIn,
const QString &filter, QString *selectedFilter) const QString &filter, QString *selectedFilter)
{ {
...@@ -771,7 +799,7 @@ QString DocumentManager::getSaveFileNameWithExtension(const QString &title, cons ...@@ -771,7 +799,7 @@ QString DocumentManager::getSaveFileNameWithExtension(const QString &title, cons
QString DocumentManager::getSaveAsFileName(const IDocument *document) QString DocumentManager::getSaveAsFileName(const IDocument *document)
{ {
QTC_ASSERT(document, return QString()); QTC_ASSERT(document, return QString());
const QString filter = Utils::allFiltersString(); const QString filter = allDocumentFactoryFiltersString();
const QString filePath = document->filePath().toString(); const QString filePath = document->filePath().toString();
QString selectedFilter; QString selectedFilter;
QString fileDialogPath = filePath; QString fileDialogPath = filePath;
......
...@@ -84,6 +84,8 @@ public: ...@@ -84,6 +84,8 @@ public:
const QString &fileName = QString(), const QString &fileName = QString(),
bool *isReadOnly = nullptr); bool *isReadOnly = nullptr);
static QString allDocumentFactoryFiltersString(QString *allFilesFilter);
static QStringList getOpenFileNames(const QString &filters, static QStringList getOpenFileNames(const QString &filters,
const QString &path = QString(), const QString &path = QString(),
QString *selectedFilter = nullptr); QString *selectedFilter = nullptr);
......
...@@ -2726,7 +2726,7 @@ void EditorManager::addCloseEditorListener(const std::function<bool (IEditor *)> ...@@ -2726,7 +2726,7 @@ void EditorManager::addCloseEditorListener(const std::function<bool (IEditor *)>
QStringList EditorManager::getOpenFileNames() QStringList EditorManager::getOpenFileNames()
{ {
QString selectedFilter; QString selectedFilter;
const QString &fileFilters = Utils::allFiltersString(&selectedFilter); const QString &fileFilters = DocumentManager::allDocumentFactoryFiltersString(&selectedFilter);
return DocumentManager::getOpenFileNames(fileFilters, QString(), &selectedFilter); return DocumentManager::getOpenFileNames(fileFilters, QString(), &selectedFilter);
} }
......
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