forked from qt-creator/qt-creator
Move editor factory search function to recently created private header
Change-Id: I74a9a58c679c265c6d723209705323e83901e040 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -33,7 +33,6 @@
|
||||
#include "ieditorfactory.h"
|
||||
|
||||
#include <coreplugin/idocument.h>
|
||||
#include <utils/mimetypes/mimedatabase.h>
|
||||
|
||||
#include <QList>
|
||||
#include <QObject>
|
||||
@@ -278,50 +277,5 @@ private:
|
||||
QList<std::function<bool(IEditor *)>> m_closeEditorListeners;
|
||||
};
|
||||
|
||||
/* For something that has a 'QStringList mimeTypes' (IEditorFactory
|
||||
* or IExternalEditor), find the one best matching the mimetype passed in.
|
||||
* Recurse over the parent classes of the mimetype to find them. */
|
||||
template <class EditorFactoryLike>
|
||||
static void mimeTypeFactoryLookup(const Utils::MimeType &mimeType,
|
||||
const QList<EditorFactoryLike*> &allFactories,
|
||||
QList<EditorFactoryLike*> *list)
|
||||
{
|
||||
QSet<EditorFactoryLike *> matches;
|
||||
// search breadth-first through parent hierarchy, e.g. for hierarchy
|
||||
// * application/x-ruby
|
||||
// * application/x-executable
|
||||
// * application/octet-stream
|
||||
// * text/plain
|
||||
QList<Utils::MimeType> queue;
|
||||
QSet<QString> seen;
|
||||
queue.append(mimeType);
|
||||
seen.insert(mimeType.name());
|
||||
while (!queue.isEmpty()) {
|
||||
Utils::MimeType mt = queue.takeFirst();
|
||||
// check for matching factories
|
||||
foreach (EditorFactoryLike *factory, allFactories) {
|
||||
if (!matches.contains(factory)) {
|
||||
foreach (const QString &mimeName, factory->mimeTypes()) {
|
||||
if (mt.matchesName(mimeName)) {
|
||||
list->append(factory);
|
||||
matches.insert(factory);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// add parent mime types
|
||||
QStringList parentNames = mt.parentMimeTypes();
|
||||
foreach (const QString &parentName, parentNames) {
|
||||
const Utils::MimeType parent = Utils::mimeTypeForName(parentName);
|
||||
if (parent.isValid()) {
|
||||
int seenSize = seen.size();
|
||||
seen.insert(parent.name());
|
||||
if (seen.size() != seenSize) // not seen before, so add
|
||||
queue.append(parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // Internal
|
||||
} // Core
|
||||
|
@@ -26,7 +26,6 @@
|
||||
#include "ieditorfactory.h"
|
||||
#include "ieditorfactory_p.h"
|
||||
#include "editormanager.h"
|
||||
#include "editormanager_p.h"
|
||||
|
||||
#include <utils/mimetypes/mimedatabase.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
@@ -26,8 +26,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <utils/mimetypes/mimetype.h>
|
||||
#include <utils/mimetypes/mimedatabase.h>
|
||||
|
||||
#include <QHash>
|
||||
#include <QSet>
|
||||
|
||||
namespace Core {
|
||||
|
||||
@@ -38,5 +40,50 @@ namespace Internal {
|
||||
QHash<Utils::MimeType, IEditorFactory *> userPreferredEditorFactories();
|
||||
void setUserPreferredEditorFactories(const QHash<Utils::MimeType, IEditorFactory *> &factories);
|
||||
|
||||
/* For something that has a 'QStringList mimeTypes' (IEditorFactory
|
||||
* or IExternalEditor), find the one best matching the mimetype passed in.
|
||||
* Recurse over the parent classes of the mimetype to find them. */
|
||||
template <class EditorFactoryLike>
|
||||
static void mimeTypeFactoryLookup(const Utils::MimeType &mimeType,
|
||||
const QList<EditorFactoryLike*> &allFactories,
|
||||
QList<EditorFactoryLike*> *list)
|
||||
{
|
||||
QSet<EditorFactoryLike *> matches;
|
||||
// search breadth-first through parent hierarchy, e.g. for hierarchy
|
||||
// * application/x-ruby
|
||||
// * application/x-executable
|
||||
// * application/octet-stream
|
||||
// * text/plain
|
||||
QList<Utils::MimeType> queue;
|
||||
QSet<QString> seen;
|
||||
queue.append(mimeType);
|
||||
seen.insert(mimeType.name());
|
||||
while (!queue.isEmpty()) {
|
||||
Utils::MimeType mt = queue.takeFirst();
|
||||
// check for matching factories
|
||||
foreach (EditorFactoryLike *factory, allFactories) {
|
||||
if (!matches.contains(factory)) {
|
||||
foreach (const QString &mimeName, factory->mimeTypes()) {
|
||||
if (mt.matchesName(mimeName)) {
|
||||
list->append(factory);
|
||||
matches.insert(factory);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// add parent mime types
|
||||
QStringList parentNames = mt.parentMimeTypes();
|
||||
foreach (const QString &parentName, parentNames) {
|
||||
const Utils::MimeType parent = Utils::mimeTypeForName(parentName);
|
||||
if (parent.isValid()) {
|
||||
int seenSize = seen.size();
|
||||
seen.insert(parent.name());
|
||||
if (seen.size() != seenSize) // not seen before, so add
|
||||
queue.append(parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // Internal
|
||||
} // Core
|
||||
|
@@ -25,7 +25,7 @@
|
||||
|
||||
#include "iexternaleditor.h"
|
||||
|
||||
#include "editormanager_p.h"
|
||||
#include "ieditorfactory_p.h"
|
||||
|
||||
namespace Core {
|
||||
|
||||
|
Reference in New Issue
Block a user