diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index 6bfb2ffea15..18073e1de1d 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -1170,33 +1170,30 @@ Id EditorManagerPrivate::getOpenWithEditorId(const Utils::FilePath &fileName, bo return selectedId; } -static QMap toMap(const QHash &hash) +static QMap toMap(const QHash &hash) { QMap map; auto it = hash.begin(); const auto end = hash.end(); while (it != end) { - map.insert(it.key().name(), it.value()->id().toSetting()); + map.insert(it.key(), it.value()->id().toSetting()); ++it; } return map; } -static QHash fromMap(const QMap &map) +static QHash fromMap(const QMap &map) { const EditorFactories factories = IEditorFactory::allEditorFactories(); - QHash hash; + QHash hash; auto it = map.begin(); const auto end = map.end(); while (it != end) { - const Utils::MimeType mimeType = Utils::mimeTypeForName(it.key()); - if (mimeType.isValid()) { - const Id factoryId = Id::fromSetting(it.value()); - IEditorFactory *factory = Utils::findOrDefault(factories, + const Id factoryId = Id::fromSetting(it.value()); + IEditorFactory *factory = Utils::findOrDefault(factories, Utils::equal(&IEditorFactory::id, factoryId)); - if (factory) - hash.insert(mimeType, factory); - } + if (factory) + hash.insert(it.key(), factory); ++it; } return hash; @@ -1223,7 +1220,7 @@ void EditorManagerPrivate::readSettings() else HostOsInfo::setOverrideFileNameCaseSensitivity(sensitivity); - const QHash preferredEditorFactories = fromMap( + const QHash preferredEditorFactories = fromMap( qs->value(preferredEditorFactoriesKey).toMap()); setUserPreferredEditorTypes(preferredEditorFactories); diff --git a/src/plugins/coreplugin/editormanager/ieditorfactory.cpp b/src/plugins/coreplugin/editormanager/ieditorfactory.cpp index a87b427e62d..6b33314044e 100644 --- a/src/plugins/coreplugin/editormanager/ieditorfactory.cpp +++ b/src/plugins/coreplugin/editormanager/ieditorfactory.cpp @@ -131,7 +131,7 @@ static void mimeTypeFactoryLookup(const Utils::MimeType &mimeType, */ static QList g_editorFactories; -static QHash g_userPreferredEditorTypes; +static QHash g_userPreferredEditorTypes; /*! Creates an IEditorFactory. @@ -190,7 +190,7 @@ const EditorFactories IEditorFactory::preferredEditorTypes(const FilePath &fileP MimeMatchMode::MatchDefaultAndRemote); EditorFactories factories = defaultEditorFactories(mimeType); // user preferred factory to front - IEditorFactory *userPreferred = Internal::userPreferredEditorTypes().value(mimeType); + IEditorFactory *userPreferred = Internal::userPreferredEditorTypes().value(mimeType.name()); if (userPreferred) { factories.removeAll(userPreferred); factories.prepend(userPreferred); @@ -238,7 +238,7 @@ const EditorFactories IEditorFactory::preferredEditorFactories(const FilePath &f factories.prepend(f); }; // user preferred factory to front - IEditorFactory *userPreferred = Internal::userPreferredEditorTypes().value(mimeType); + IEditorFactory *userPreferred = Internal::userPreferredEditorTypes().value(mimeType.name()); if (userPreferred && userPreferred->isInternalEditor()) factories_moveToFront(userPreferred); // open text files > 48 MB in binary editor @@ -328,7 +328,7 @@ void IEditorFactory::setEditorStarter(const std::function Internal::userPreferredEditorTypes() +QHash Internal::userPreferredEditorTypes() { return g_userPreferredEditorTypes; } @@ -336,7 +336,7 @@ QHash Internal::userPreferredEditorTypes() /*! \internal */ -void Internal::setUserPreferredEditorTypes(const QHash &factories) +void Internal::setUserPreferredEditorTypes(const QHash &factories) { g_userPreferredEditorTypes = factories; } diff --git a/src/plugins/coreplugin/editormanager/ieditorfactory_p.h b/src/plugins/coreplugin/editormanager/ieditorfactory_p.h index 338f5ea24df..38d30524f68 100644 --- a/src/plugins/coreplugin/editormanager/ieditorfactory_p.h +++ b/src/plugins/coreplugin/editormanager/ieditorfactory_p.h @@ -3,8 +3,6 @@ #pragma once -#include - #include namespace Core { @@ -13,8 +11,8 @@ class IEditorFactory; namespace Internal { -QHash userPreferredEditorTypes(); -void setUserPreferredEditorTypes(const QHash &factories); +QHash userPreferredEditorTypes(); +void setUserPreferredEditorTypes(const QHash &factories); } // Internal } // Core diff --git a/src/plugins/coreplugin/mimetypesettings.cpp b/src/plugins/coreplugin/mimetypesettings.cpp index 814dd7be20f..0e39eaeb3e4 100644 --- a/src/plugins/coreplugin/mimetypesettings.cpp +++ b/src/plugins/coreplugin/mimetypesettings.cpp @@ -104,7 +104,7 @@ public: QList m_mimeTypes; mutable QHash> m_handlersByMimeType; - QHash m_userDefault; + QHash m_userDefault; }; int MimeTypeSettingsModel::rowCount(const QModelIndex &) const @@ -149,7 +149,7 @@ QVariant MimeTypeSettingsModel::data(const QModelIndex &modelIndex, int role) co } else if (role == Qt::FontRole) { if (column == 1) { const Utils::MimeType &type = m_mimeTypes.at(modelIndex.row()); - if (m_userDefault.contains(type)) { + if (m_userDefault.contains(type.name())) { QFont font = QGuiApplication::font(); font.setItalic(true); return font; @@ -174,9 +174,9 @@ bool MimeTypeSettingsModel::setData(const QModelIndex &index, const QVariant &va const QList handlers = handlersForMimeType(mimeType); QTC_ASSERT(handlers.contains(factory), return false); if (handlers.first() == factory) // selection is the default anyhow - m_userDefault.remove(mimeType); + m_userDefault.remove(mimeType.name()); else - m_userDefault.insert(mimeType, factory); + m_userDefault.insert(mimeType.name(), factory); emit dataChanged(index, index); return true; } @@ -209,8 +209,8 @@ QList MimeTypeSettingsModel::handlersForMimeType(const Utils:: IEditorFactory *MimeTypeSettingsModel::defaultHandlerForMimeType(const Utils::MimeType &mimeType) const { - if (m_userDefault.contains(mimeType)) - return m_userDefault.value(mimeType); + if (m_userDefault.contains(mimeType.name())) + return m_userDefault.value(mimeType.name()); const QList handlers = handlersForMimeType(mimeType); return handlers.isEmpty() ? nullptr : handlers.first(); }