EditorManager Class | Extending Qt Creator Manual

- Extending Qt Creator Manual
- EditorManager
- Extending Qt Creator Manual 4.12.3

# EditorManager Class

class Core::EditorManager

The EditorManager class manages the editors created for files according to their MIME type. More...

Header: | #include <EditorManager>

- List of all members, including inherited members

## Public Types

enum | OpenEditorFlag { NoFlags, DoNotChangeCurrentEditor, IgnoreNavigationHistory, DoNotMakeVisible, CanContainLineAndColumnNumber, …, SwitchSplitIfAlreadyVisible }
flags | OpenEditorFlags

## Public Slots

bool | closeAllEditors(bool askAboutModifiedEditors = true)
void | closeOtherDocuments()
void | goBackInNavigationHistory()
void | goForwardInNavigationHistory()
void | gotoOtherSplit()
void | revertToSaved()
void | saveDocument()
void | saveDocumentAs()
void | splitSideBySide()

## Static Public Members

void | activateEditor(Core::IEditor *editor, Core::EditorManager::OpenEditorFlags flags = NoFlags)
Core::IEditor * | activateEditorForDocument(Core::IDocument *document, Core::EditorManager::OpenEditorFlags flags = NoFlags)
void | activateEditorForEntry(DocumentModel::Entry *entry, Core::EditorManager::OpenEditorFlags flags = NoFlags)
void | addCloseEditorListener(const std::function<bool (IEditor *)> &listener)
void | addCurrentPositionToNavigationHistory(const QByteArray &saveState = QByteArray())
void | addNativeDirAndOpenWithActions(QMenu *contextMenu, DocumentModel::Entry *entry)
void | addPinEditorActions(QMenu *contextMenu, DocumentModel::Entry *entry)
void | addSaveAndCloseEditorActions(QMenu *contextMenu, DocumentModel::Entry *entry, Core::IEditor *editor = nullptr)
void | clearUniqueId(Core::IDocument *document)
bool | closeAllDocuments()
bool | closeDocument(Core::IDocument *document, bool askAboutModifiedEditors = true)
void | closeDocument(DocumentModel::Entry *entry)
bool | closeDocuments(const QList<Core::IDocument *> &documents, bool askAboutModifiedEditors = true)
bool | closeDocuments(const QList<DocumentModel::Entry *> &entries)
void | closeEditor(Core::IEditor *editor, bool askAboutModifiedEditors = true)
bool | closeEditors(const QList<Core::IEditor *> &editorsToClose, bool askAboutModifiedEditors = true)
void | closeOtherDocuments(Core::IDocument *document)
Core::IDocument * | currentDocument()
Core::IEditor * | currentEditor()
void | cutForwardNavigationHistory()
Utils::TextFileFormat::LineTerminationMode | defaultLineEnding()
QTextCodec * | defaultTextCodec()
QStringList | getOpenFileNames()
void | hideEditorStatusBar(const QString &id)
bool | isAutoSaveFile(const QString &fileName)
qint64 | maxTextFileSize()
Core::IEditor * | openEditor(const QString &fileName, Core::Id editorId = Id(), Core::EditorManager::OpenEditorFlags flags = NoFlags, bool *newEditor = nullptr)
Core::IEditor * | openEditorAt(const QString &fileName, int line, int column = 0, Core::Id editorId = Id(), Core::EditorManager::OpenEditorFlags flags = NoFlags, bool *newEditor = nullptr)
void | openEditorAtSearchResult(const Core::SearchResultItem &item, Core::EditorManager::OpenEditorFlags flags = NoFlags)
Core::IEditor * | openEditorWithContents(Core::Id editorId, QString *titlePattern = nullptr, const QByteArray &contents = QByteArray(), const QString &uniqueId = QString(), Core::EditorManager::OpenEditorFlags flags = NoFlags)
bool | openExternalEditor(const QString &fileName, Core::Id editorId)
void | populateOpenWithMenu(QMenu *menu, const QString &fileName)
IDocument::ReloadSetting | reloadSetting()
bool | restoreState(const QByteArray &state)
bool | saveDocument(Core::IDocument *document)
QByteArray | saveState()
void | setLastEditLocation(const Core::IEditor *editor)
void | setReloadSetting(IDocument::ReloadSetting behavior)
void | setSessionTitleHandler(Core::EditorManager::WindowTitleHandler handler)
void | setWindowTitleAdditionHandler(Core::EditorManager::WindowTitleHandler handler)
void | showEditorStatusBar(const QString &id, const QString &infoText, const QString &buttonText = QString(), QObject *object = nullptr, const std::function<void ()> &function = {})
bool | skipOpeningBigTextFile(const QString &filePath)
Core::EditorManager::FilePathInfo | splitLineAndColumnNumber(const QString &fullFilePath)
QList<Core::IEditor *> | visibleEditors()

## Detailed Description

Whenever a user wants to edit or create a file, the EditorManager scans all IEditorFactory interfaces for suitable editors. The selected IEditorFactory is then asked to create an editor, as determined by the MIME type of the file.

Users can split the editor view or open the editor in a new window when to work on and view multiple files on the same screen or on multiple screens. For more information, see Splitting the Editor View.

## Member Type Documentation

### enum EditorManager::OpenEditorFlag
flags EditorManager::OpenEditorFlags

This enum holds settings for opening a file in an editor.

Constant | Value | Description
--- | --- | ---
`Core::EditorManager::NoFlags` | `0` | Does not use any settings.
`Core::EditorManager::DoNotChangeCurrentEditor` | `1` | Does not switch focus to the newly opened editor.
`Core::EditorManager::IgnoreNavigationHistory` | `2` | Does not add an entry to the navigation history for the opened editor.
`Core::EditorManager::DoNotMakeVisible` | `4` | Does not force the editor to become visible.
`Core::EditorManager::CanContainLineAndColumnNumber` | `8` | If the file path contains line and column numbers, opens the file in an editor and jumps to the line and column.
`Core::EditorManager::OpenInOtherSplit` | `16` | Opens the document in another split of the window.
`Core::EditorManager::DoNotSwitchToDesignMode` | `32` | Opens the document in the current mode.
`Core::EditorManager::DoNotSwitchToEditMode` | `64` | Opens the document in the current mode.
`Core::EditorManager::SwitchSplitIfAlreadyVisible` | `128` | Switches to another split if the document is already visible there.

The OpenEditorFlags type is a typedef for QFlags<OpenEditorFlag>. It stores an OR combination of OpenEditorFlag values.

## Member Function Documentation

### `[static slot]` bool EditorManager::closeAllEditors(bool askAboutModifiedEditors = true)

Closes all open editors. If askAboutModifiedEditors is `true`, prompts users to save their changes before closing the editors.

Returns whether all editors were closed.

### `[static slot]` void EditorManager::closeOtherDocuments()

Closes all open documents except the current document.

### `[static slot]` void EditorManager::goBackInNavigationHistory()

Goes back in the navigation history.

### `[static slot]` void EditorManager::goForwardInNavigationHistory()

Goes forward in the navigation history.

### `[static slot]` void EditorManager::gotoOtherSplit()

Moves focus to another split, creating it if necessary. If there's no split and no other window, a side-by-side split is created. If the current window is split, focus is moved to the next split within this window, cycling. If the current window is not split, focus is moved to the next window.

### `[static slot]` void EditorManager::revertToSaved()

Reverts the current document to its last saved state.

### `[static slot]` void EditorManager::saveDocument()

Saves the current document.

### `[static slot]` void EditorManager::saveDocumentAs()

Saves the current document under a different file name.

### `[static slot]` void EditorManager::splitSideBySide()

Splits the editor view horizontally into adjacent views.

### `[static]` void EditorManager::activateEditor(Core::IEditor *editor, Core::EditorManager::OpenEditorFlags flags = NoFlags)

Activates the editor editor using the editor settings specified by flags.

### `[static]` Core::IEditor *EditorManager::activateEditorForDocument(Core::IDocument *document, Core::EditorManager::OpenEditorFlags flags = NoFlags)

Activates the editor for the document specified by document in the current view using the editor settings specified by flags.

### `[static]` void EditorManager::activateEditorForEntry(DocumentModel::Entry *entry, Core::EditorManager::OpenEditorFlags flags = NoFlags)

Activates the editor for the document specified by entry using the editor settings specified by flags.

### `[static]` void EditorManager::addCloseEditorListener(const std::function<bool (IEditor *)> &listener)

Provides a hook for plugins to veto on closing editors.

When an editor requests a close, all listeners are called. If one of the listener calls returns `false`, the process is aborted and the event is ignored. If all calls return `true`, editorAboutToClose() is emitted and the event is accepted.

### `[static]` void EditorManager::addCurrentPositionToNavigationHistory(const QByteArray &saveState = QByteArray())

Adds the current cursor position to the navigation history specified by saveState.

### `[static]` void EditorManager::addNativeDirAndOpenWithActions(QMenu *contextMenu, DocumentModel::Entry *entry)

Adds the native directory handling and open with menu items for the document entry to the context menu contextMenu.

### `[static]` void EditorManager::addPinEditorActions(QMenu *contextMenu, DocumentModel::Entry *entry)

Adds the pin editor menu items for the document entry to the context menu contextMenu.

### `[static]` void EditorManager::addSaveAndCloseEditorActions(QMenu *contextMenu, DocumentModel::Entry *entry, Core::IEditor *editor = nullptr)

Adds save, close and other editor context menu items for the document entry and editor editor to the context menu contextMenu.

### `[static]` void EditorManager::clearUniqueId(Core::IDocument *document)

Clears the unique ID of document.

See also openEditorWithContents().

### `[static]` bool EditorManager::closeAllDocuments()

Closes all open documents except pinned files.

Returns whether all editors were closed.

### `[static]` bool EditorManager::closeDocument(Core::IDocument *document, bool askAboutModifiedEditors = true)

Closes document. If askAboutModifiedEditors is `true`, prompts users to save their changes before closing the document.

Returns whether the document was closed.

### `[static]` void EditorManager::closeDocument(DocumentModel::Entry *entry)

Closes the document specified by entry.

### `[static]` bool EditorManager::closeDocuments(const QList<Core::IDocument *> &documents, bool askAboutModifiedEditors = true)

Closes documents. If askAboutModifiedEditors is `true`, prompts users to save their changes before closing the documents.

Returns whether the documents were closed.

### `[static]` bool EditorManager::closeDocuments(const QList<DocumentModel::Entry *> &entries)

Closes the documents specified by entries.

Returns whether all documents were closed.

### `[static]` void EditorManager::closeEditor(Core::IEditor *editor, bool askAboutModifiedEditors = true)

Closes editor. If askAboutModifiedEditors is `true`, prompts users to save their changes before closing the editor.

### `[static]` bool EditorManager::closeEditors(const QList<Core::IEditor *> &editorsToClose, bool askAboutModifiedEditors = true)

Closes the editors specified by editorsToClose. If askAboutModifiedEditors is `true`, prompts users to save their changes before closing the editor.

Returns whether all editors were closed.

### `[static]` void EditorManager::closeOtherDocuments(Core::IDocument *document)

Closes all open documents except document and pinned files.

### `[static]` Core::IDocument *EditorManager::currentDocument()

Returns the document of the currently active editor.

### `[static]` Core::IEditor *EditorManager::currentEditor()

Returns the currently active editor.

### `[static]` void EditorManager::cutForwardNavigationHistory()

Cuts forward in the navigation history.

### `[static]` Utils::TextFileFormat::LineTerminationMode EditorManager::defaultLineEnding()

Returns the default line ending as the user specified in the settings.

### `[static]` QTextCodec *EditorManager::defaultTextCodec()

Returns the default text codec for the locale.

### `[static]` QStringList EditorManager::getOpenFileNames()

Asks the user for a list of files to open and returns the choice.

See also QFileDialog::getOpenFileNames().

### `[static]` void EditorManager::hideEditorStatusBar(const QString &id)

Hides the editor status bar specified by id.

### `[static]` bool EditorManager::isAutoSaveFile(const QString &fileName)

Returns whether fileName is an auto-save file created by Qt Creator.

### `[static]` qint64 EditorManager::maxTextFileSize()

Returns the maximum file size.

### `[static]` Core::IEditor *EditorManager::openEditor(const QString &fileName, Core::Id editorId = Id(), Core::EditorManager::OpenEditorFlags flags = NoFlags, bool *newEditor = nullptr)

Opens the document specified by fileName using the editor type specified by editorId and the settings specified by flags.

If newEditor is not `nullptr`, and a new editor instance was created, it is set to `true`. If an existing editor instance was used, it is set to `false`.

### `[static]` Core::IEditor *EditorManager::openEditorAt(const QString &fileName, int line, int column = 0, Core::Id editorId = Id(), Core::EditorManager::OpenEditorFlags flags = NoFlags, bool *newEditor = nullptr)

Opens the document specified by fileName to line and column using the editor type specified by editorId and the settings specified by flags.

If newEditor is not `nullptr`, and a new editor instance was created, it is set to `true`. If an existing editor instance was used, it is set to `false`.

### `[static]` void EditorManager::openEditorAtSearchResult(const Core::SearchResultItem &item, Core::EditorManager::OpenEditorFlags flags = NoFlags)

Opens the document at the position of the search hit item in the editor using the settings specified by flags.

### `[static]` Core::IEditor *EditorManager::openEditorWithContents(Core::Id editorId, QString *titlePattern = nullptr, const QByteArray &contents = QByteArray(), const QString &uniqueId = QString(), Core::EditorManager::OpenEditorFlags flags = NoFlags)

Opens contents in an editor of the type editorId using the settings specified by flags.

The editor is given a display name based on titlePattern. If a non-empty uniqueId is specified and an editor with that unique ID is found, it is re-used. Otherwise, a new editor with that unique ID is created.

Returns the new or re-used editor.

### `[static]` bool EditorManager::openExternalEditor(const QString &fileName, Core::Id editorId)

Opens the document specified by fileName in the external editor specified by editorId.

If editorId is not the ID of an external editor or the external editor cannot be opened, returns `false` and displays an error message.

### `[static]` void EditorManager::populateOpenWithMenu(QMenu *menu, const QString &fileName)

Populates the Open With menu menu with editors that are suitable for opening the document fileName.

### `[static]` IDocument::ReloadSetting EditorManager::reloadSetting()

Returns reload behavior settings.

See also setReloadSetting().

### `[static]` bool EditorManager::restoreState(const QByteArray &state)

Restores the editor to state.

Returns `true` if the editor state can be restored.

### `[static]` bool EditorManager::saveDocument(Core::IDocument *document)

Saves the changes in document.

Returns whether the operation was successful.

### `[static]` QByteArray EditorManager::saveState()

Returns the serialized state of all non-temporary editors.

### `[static]` void EditorManager::setLastEditLocation(const Core::IEditor *editor)

Sets the location that was last modified to editor.

### `[static]` void EditorManager::setReloadSetting(IDocument::ReloadSetting behavior)

Sets editor reaload behavior settings to behavior.

See also reloadSetting().

### `[static]` void EditorManager::setSessionTitleHandler(Core::EditorManager::WindowTitleHandler handler)

Sets the session title addition handler to handler.

### `[static]` void EditorManager::setWindowTitleAdditionHandler(Core::EditorManager::WindowTitleHandler handler)

Sets the window title addition handler to handler.

### `[static]` void EditorManager::showEditorStatusBar(const QString &id, const QString &infoText, const QString &buttonText = QString(), QObject *object = nullptr, const std::function<void ()> &function = {})

Shows the editor status bar object with the id, infoText, buttonText, and function.

### `[static]` bool EditorManager::skipOpeningBigTextFile(const QString &filePath)

Returns whether the document specified by filePath should be opened even though it is big. Depending on the settings, might ask the user to decide whether the file should be opened.

Returns the path to the file that was skipped.

### `[static]` Core::EditorManager::FilePathInfo EditorManager::splitLineAndColumnNumber(const QString &fullFilePath)

Returns the file path fullFilePath with appended line and column information split into file path, line, and column components.

The following patterns are supported: `filepath.txt:19`, `filepath.txt:19:12`, `filepath.txt+19`, `filepath.txt+19+12`, and `filepath.txt(19)`.

### `[static]` QList<Core::IEditor *> EditorManager::visibleEditors()

Returns the list of visible editors.