forked from qt-creator/qt-creator
EditorManager: Do not instantiate MimeTypes during startup
Which would trigger reading the MIME database, which is not needed at that point in time. We persist the map of MIME type to custom default factories via the MIME type names anyway, so just stay with that. Change-Id: I7570432573b16700e00811fe409d43a2db6c5347 Reviewed-by: David Schulz <david.schulz@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -1170,33 +1170,30 @@ Id EditorManagerPrivate::getOpenWithEditorId(const Utils::FilePath &fileName, bo
|
||||
return selectedId;
|
||||
}
|
||||
|
||||
static QMap<QString, QVariant> toMap(const QHash<Utils::MimeType, IEditorFactory *> &hash)
|
||||
static QMap<QString, QVariant> toMap(const QHash<QString, IEditorFactory *> &hash)
|
||||
{
|
||||
QMap<QString, QVariant> 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<Utils::MimeType, IEditorFactory *> fromMap(const QMap<QString, QVariant> &map)
|
||||
static QHash<QString, IEditorFactory *> fromMap(const QMap<QString, QVariant> &map)
|
||||
{
|
||||
const EditorFactories factories = IEditorFactory::allEditorFactories();
|
||||
QHash<Utils::MimeType, IEditorFactory *> hash;
|
||||
QHash<QString, IEditorFactory *> 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<Utils::MimeType, IEditorFactory *> preferredEditorFactories = fromMap(
|
||||
const QHash<QString, IEditorFactory *> preferredEditorFactories = fromMap(
|
||||
qs->value(preferredEditorFactoriesKey).toMap());
|
||||
setUserPreferredEditorTypes(preferredEditorFactories);
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ static void mimeTypeFactoryLookup(const Utils::MimeType &mimeType,
|
||||
*/
|
||||
|
||||
static QList<IEditorFactory *> g_editorFactories;
|
||||
static QHash<Utils::MimeType, IEditorFactory *> g_userPreferredEditorTypes;
|
||||
static QHash<QString, IEditorFactory *> 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<bool(const FilePath &,
|
||||
/*!
|
||||
\internal
|
||||
*/
|
||||
QHash<Utils::MimeType, IEditorFactory *> Internal::userPreferredEditorTypes()
|
||||
QHash<QString, IEditorFactory *> Internal::userPreferredEditorTypes()
|
||||
{
|
||||
return g_userPreferredEditorTypes;
|
||||
}
|
||||
@@ -336,7 +336,7 @@ QHash<Utils::MimeType, IEditorFactory *> Internal::userPreferredEditorTypes()
|
||||
/*!
|
||||
\internal
|
||||
*/
|
||||
void Internal::setUserPreferredEditorTypes(const QHash<Utils::MimeType, IEditorFactory *> &factories)
|
||||
void Internal::setUserPreferredEditorTypes(const QHash<QString, IEditorFactory *> &factories)
|
||||
{
|
||||
g_userPreferredEditorTypes = factories;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <utils/mimeutils.h>
|
||||
|
||||
#include <QHash>
|
||||
|
||||
namespace Core {
|
||||
@@ -13,8 +11,8 @@ class IEditorFactory;
|
||||
|
||||
namespace Internal {
|
||||
|
||||
QHash<Utils::MimeType, IEditorFactory *> userPreferredEditorTypes();
|
||||
void setUserPreferredEditorTypes(const QHash<Utils::MimeType, IEditorFactory *> &factories);
|
||||
QHash<QString, IEditorFactory *> userPreferredEditorTypes();
|
||||
void setUserPreferredEditorTypes(const QHash<QString, IEditorFactory *> &factories);
|
||||
|
||||
} // Internal
|
||||
} // Core
|
||||
|
||||
@@ -104,7 +104,7 @@ public:
|
||||
|
||||
QList<Utils::MimeType> m_mimeTypes;
|
||||
mutable QHash<Utils::MimeType, QList<IEditorFactory *>> m_handlersByMimeType;
|
||||
QHash<Utils::MimeType, IEditorFactory *> m_userDefault;
|
||||
QHash<QString, IEditorFactory *> 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<IEditorFactory *> 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<IEditorFactory *> 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<IEditorFactory *> handlers = handlersForMimeType(mimeType);
|
||||
return handlers.isEmpty() ? nullptr : handlers.first();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user