- Extending Qt Creator Manual
- QtCreator
- IEditorFactory
- Extending Qt Creator Manual 21.0.0-beta1

# Core::IEditorFactory Class

class Core::IEditorFactory

The IEditorFactory class creates suitable editors for documents according to their MIME type. More...

Header: | `#include <coreplugin/editormanager/ieditorfactory.h>`

- List of all members, including inherited members

## Public Functions

Core::IEditor * | createEditor() const
QString | displayName() const
int | id() const
QStringList | mimeTypes() const
Utils::Result<> | startEditor(const Utils::FilePath &filePath)

## Static Public Members

const Core::EditorFactories | allEditorFactories()
const Core::EditorFactories | defaultEditorFactories(const Utils::MimeType &mimeType)
const Core::EditorFactories | preferredEditorFactories(const Utils::FilePath &filePath)

## Protected Functions

| IEditorFactory()
void | addMimeType(const QString &mimeType)
void | setDisplayName(const QString &displayName)
void | setEditorCreator(const std::function<IEditor *()> &creator)
void | setEditorStarter(const std::function<Utils::Result<> (const Utils::FilePath &)> &starter)
void | setMimeTypes(const QStringList &mimeTypes)

## Detailed Description

When a user wants to edit or create a document, the EditorManager scans all IEditorFactory instances for suitable editors and selects one to create an editor.

Implementations should set the properties of the IEditorFactory subclass in their constructor with IEditorFactory::setId(), IEditorFactory::setDisplayName(), IEditorFactory::setMimeTypes(), and IEditorFactory::setEditorCreator().

IEditorFactory instances automatically register themselves in Qt Creator in their constructor.

There are two varieties of editors: internal and external. Internal editors open within the main editing area of Qt Creator. An IEditorFactory instance defines an internal editor by using the setEditorCreator() function. External editors are external applications and are defined by using the setEditorStarter() function. The user can access them from the Open With dialog.

See also Core::IEditor, Core::IDocument, and Core::EditorManager.

## Member Function Documentation

### `[protected]` IEditorFactory::IEditorFactory()

Creates an IEditorFactory.

Registers the IEditorFactory in Qt Creator.

### `[protected]` void IEditorFactory::addMimeType(const QString &mimeType)

Adds mimeType to the list of MIME types supported by this editor type.

See also mimeTypes() and setMimeTypes().

### `[static]` const Core::EditorFactories IEditorFactory::allEditorFactories()

Returns all registered internal and external editors.

### Core::IEditor *IEditorFactory::createEditor() const

Creates an internal editor.

Uses the function set with setEditorCreator() to create the editor.

See also setEditorCreator().

### `[static]` const Core::EditorFactories IEditorFactory::defaultEditorFactories(const Utils::MimeType &mimeType)

Returns all available internal and external editors for the mimeType in the default order: editor types are ordered by MIME type hierarchy, internal editors first.

### QString IEditorFactory::displayName() const

Returns a user-visible description of the editor type.

See also setDisplayName().

### int IEditorFactory::id() const

Returns the ID of the editors' document type.

See also setId().

### QStringList IEditorFactory::mimeTypes() const

Returns the list of supported MIME types of this editor type.

See also addMimeType() and setMimeTypes().

### `[static]` const Core::EditorFactories IEditorFactory::preferredEditorFactories(const Utils::FilePath &filePath)

Returns the available editor factories for filePath in order of preference. That is the default order for the document's MIME type but with a user overridden default editor first, and the binary editor as the very first item if a text document is too large to be opened as a text file.

### `[protected]` void IEditorFactory::setDisplayName(const QString &displayName)

Sets the displayName of the editor type. This is for example shown in the Open With menu and the MIME type preferences.

See also displayName().

### `[protected]` void IEditorFactory::setEditorCreator(const std::function<IEditor *()> &creator)

Sets the function that is used to create an editor instance in createEditor() to creator.

This is mutually exclusive with the use of setEditorStarter().

See also createEditor().

### `[protected]` void IEditorFactory::setEditorStarter(const std::function<Utils::Result<> (const Utils::FilePath &)> &starter)

Sets the function that is used to open a file for a given `FilePath` to starter.

The function should return `true` on success, or return `false` and set the `QString` to an error message at failure.

This is mutually exclusive with the use of setEditorCreator().

### `[protected]` void IEditorFactory::setMimeTypes(const QStringList &mimeTypes)

Sets the MIME types supported by the editor type to mimeTypes.

See also addMimeType() and mimeTypes().

### Utils::Result<> IEditorFactory::startEditor(const Utils::FilePath &filePath)

Opens the file at filePath in an external editor.

Returns `Utils::ResultOk` on success or `Utils::ResultError` on failure.