EditorManager Class

class Core::EditorManager

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

Header: #include <coreplugin/editormanager/editormanager.h>
Inherits: QObject

Public Types

enum OpenEditorFlag { NoFlags, DoNotChangeCurrentEditor, IgnoreNavigationHistory, DoNotMakeVisible, OpenInOtherSplit, …, AllowExternalEditor }
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()

Signals

void aboutToSave(Core::IDocument *document)
void autoSaved()
void currentDocumentStateChanged()
void currentEditorAboutToChange(Core::IEditor *editor)
void currentEditorChanged(Core::IEditor *editor)
void documentClosed(Core::IDocument *document)
void documentOpened(Core::IDocument *document)
void documentStateChanged(Core::IDocument *document)
void editorAboutToClose(Core::IEditor *editor)
void editorCreated(Core::IEditor *editor, const Utils::FilePath &filePath)
void editorOpened(Core::IEditor *editor)
void editorsClosed(QList<Core::IEditor *> editors)
void saved(Core::IDocument *document)

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(Core::DocumentModel::Entry *entry, Core::EditorManager::OpenEditorFlags flags = NoFlags)
void addCloseEditorListener(const std::function<bool (IEditor *)> &listener)
void addCurrentPositionToNavigationHistory(const QByteArray &saveState = QByteArray())
void addEditor(Core::IEditor *editor, Core::EditorManager::OpenEditorFlags flags = NoFlags)
void addNativeDirAndOpenWithActions(QMenu *contextMenu, Core::DocumentModel::Entry *entry)
void addPinEditorActions(QMenu *contextMenu, Core::DocumentModel::Entry *entry)
void addSaveAndCloseEditorActions(QMenu *contextMenu, Core::DocumentModel::Entry *entry, Core::IEditor *editor = nullptr)
void clearUniqueId(Core::IDocument *document)
bool closeAllDocuments()
bool closeDocuments(const QList<Core::IDocument *> &documents, bool askAboutModifiedEditors = true)
bool closeDocuments(const QList<Core::DocumentModel::Entry *> &entries)
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()
Utils::FilePaths getOpenFilePaths(QFileDialog::Options options = {})
Core::EditorManager *instance()
bool isAutoSaveFile(const QString &filePath)
qint64 maxTextFileSize()
Core::IEditor *openEditor(const Utils::FilePath &filePath, Utils::Id editorId = {}, Core::EditorManager::OpenEditorFlags flags = NoFlags, bool *newEditor = nullptr)
Core::IEditor *openEditorAt(const Utils::Link &link, Utils::Id editorId = {}, Core::EditorManager::OpenEditorFlags flags = NoFlags, bool *newEditor = nullptr)
void openEditorAtSearchResult(const Utils::SearchResultItem &item, Utils::Id editorId = {}, Core::EditorManager::OpenEditorFlags flags = NoFlags, bool *newEditor = nullptr)
Core::IEditor *openEditorWithContents(Utils::Id editorId, QString *titlePattern = nullptr, const QByteArray &contents = QByteArray(), const QString &uniqueId = QString(), Core::EditorManager::OpenEditorFlags flags = NoFlags)
bool openExternalEditor(const Utils::FilePath &filePath, Utils::Id editorId)
void populateOpenWithMenu(QMenu *menu, const Utils::FilePath &filePath)
Core::IDocument::ReloadSetting reloadSetting()
bool saveDocument(Core::IDocument *document)
void setLastEditLocation(const Core::IEditor *editor)
bool skipOpeningBigTextFile(const Utils::FilePath &filePath)
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.

Plugins use the EditorManager to open documents in editors or close them, and to get notified when documents are opened, closed or saved.

Member Type Documentation

enum EditorManager::OpenEditorFlag
flags EditorManager::OpenEditorFlags

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

ConstantValueDescription
Core::EditorManager::NoFlags0Does not use any settings.
Core::EditorManager::DoNotChangeCurrentEditor1Does not switch focus to the newly opened editor.
Core::EditorManager::IgnoreNavigationHistory2Does not add an entry to the navigation history for the opened editor.
Core::EditorManager::DoNotMakeVisible4Does not force the editor to become visible.
Core::EditorManager::OpenInOtherSplit8Opens the document in another split of the window.
Core::EditorManager::DoNotSwitchToDesignMode16Opens the document in the current mode.
Core::EditorManager::DoNotSwitchToEditMode32Opens the document in the current mode.
Core::EditorManager::SwitchSplitIfAlreadyVisible64Switches to another split if the document is already visible there.
Core::EditorManager::DoNotRaise128Prevents raising the Qt Creator window to the foreground.
Core::EditorManager::AllowExternalEditor256Allows opening the file in an external editor.

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

Member Function Documentation

[signal] void EditorManager::aboutToSave(Core::IDocument *document)

This signal is emitted before the document is saved.

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

Activates the editor in the active split using the specified flags.

See also currentEditor().

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

Activates an editor for the document in the active split using the specified flags.

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

Activates an editor for the document specified by entry in the active split using the specified flags.

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

Adds listener to the hooks that are asked if editors may be closed.

When an editor requests to close, all listeners are called. If one of the 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 specified by saveState to the navigation history. If saveState is null (the default), the current state of the active editor is used. Otherwise saveState must be a valid state of the active editor.

See also IEditor::saveState().

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

Makes an IEditor instance editor known to the EditorManager that it did not know before, and activates it using flags.

[static] void EditorManager::addNativeDirAndOpenWithActions(QMenu *contextMenu, Core::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, Core::DocumentModel::Entry *entry)

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

[static] void EditorManager::addSaveAndCloseEditorActions(QMenu *contextMenu, Core::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.

[signal] void EditorManager::autoSaved()

This signal is emitted after auto-save was triggered.

[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 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] 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<Core::DocumentModel::Entry *> &entries)

Closes the documents specified by entries.

Returns whether all documents were closed.

[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.

Usually closeDocuments() is the better alternative.

See also closeDocuments().

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

Closes all open documents except document and pinned files.

[static slot] void EditorManager::closeOtherDocuments()

Closes all open documents except the current document.

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

Returns the document of the currently active editor.

See also currentEditor().

[signal] void EditorManager::currentDocumentStateChanged()

This signal is emitted when the meta data of the current document, for example file name or modified state, changed.

See also IDocument::changed().

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

Returns the currently active editor.

See also currentDocument().

[signal] void EditorManager::currentEditorAboutToChange(Core::IEditor *editor)

This signal is emitted before the current editor changes to editor.

[signal] void EditorManager::currentEditorChanged(Core::IEditor *editor)

This signal is emitted after the current editor changed to editor.

[static] void EditorManager::cutForwardNavigationHistory()

Cuts the forward part of the navigation history, so the user cannot Go Forward anymore (until the user goes backward again).

See also goForwardInNavigationHistory() and addCurrentPositionToNavigationHistory().

[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 as the user specified in the settings.

[signal] void EditorManager::documentClosed(Core::IDocument *document)

This signal is emitted after the document closed, but before it is deleted.

[signal] void EditorManager::documentOpened(Core::IDocument *document)

This signal is emitted after the first editor for document opened in an editor view.

[signal] void EditorManager::documentStateChanged(Core::IDocument *document)

This signal is emitted when the meta data of the document, for example file name or modified state, changed.

See also IDocument::changed().

[signal] void EditorManager::editorAboutToClose(Core::IEditor *editor)

This signal is emitted before editor is closed. This can be used to free resources that were allocated for the editor separately from the editor itself. It cannot be used to prevent the editor from closing. See addCloseEditorListener() for that.

Usually the more appropriate signal to listen to is documentClosed().

See also addCloseEditorListener().

[signal] void EditorManager::editorCreated(Core::IEditor *editor, const Utils::FilePath &filePath)

This signal is emitted after an editor was created for the file at filePath, but before it was opened in an editor view.

[signal] void EditorManager::editorOpened(Core::IEditor *editor)

This signal is emitted after a new editor was opened in an editor view.

Usually the more appropriate signal to listen to is documentOpened().

[signal] void EditorManager::editorsClosed(QList<Core::IEditor *> editors)

This signal is emitted after the editors closed, but before they are deleted.

Usually the more appropriate signal to listen to is documentClosed().

[static] Utils::FilePaths EditorManager::getOpenFilePaths(QFileDialog::Options options = {})

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

The options argument holds various options about how to run the dialog. See the QFileDialog::Options enum for more information about the flags you can pass.

See also DocumentManager::getOpenFileNames() and QFileDialog::Options.

[static slot] void EditorManager::goBackInNavigationHistory()

Goes back in the navigation history.

See also goForwardInNavigationHistory() and addCurrentPositionToNavigationHistory().

[static slot] void EditorManager::goForwardInNavigationHistory()

Goes forward in the navigation history.

See also goBackInNavigationHistory() and addCurrentPositionToNavigationHistory().

[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] Core::EditorManager *EditorManager::instance()

Returns the pointer to the instance. Only use for connecting to signals.

[static] bool EditorManager::isAutoSaveFile(const QString &filePath)

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

[static] qint64 EditorManager::maxTextFileSize()

Returns the maximum file size that should be opened in a text editor.

[static] Core::IEditor *EditorManager::openEditor(const Utils::FilePath &filePath, Utils::Id editorId = {}, Core::EditorManager::OpenEditorFlags flags = NoFlags, bool *newEditor = nullptr)

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

If editorId is Id(), the editor type is derived from the file's MIME type.

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.

See also openEditorAt(), openEditorWithContents(), and openExternalEditor().

[static] Core::IEditor *EditorManager::openEditorAt(const Utils::Link &link, Utils::Id editorId = {}, Core::EditorManager::OpenEditorFlags flags = NoFlags, bool *newEditor = nullptr)

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

Moves the text cursor to the line and column specified in link.

If editorId is Id(), the editor type is derived from the file's MIME type.

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.

See also openEditor(), openEditorAtSearchResult(), openEditorWithContents(), openExternalEditor(), and IEditor::gotoLine().

[static] void EditorManager::openEditorAtSearchResult(const Utils::SearchResultItem &item, Utils::Id editorId = {}, Core::EditorManager::OpenEditorFlags flags = NoFlags, bool *newEditor = nullptr)

Opens the document at the position of the search result item using the editor type editorId and the specified flags.

If editorId is Id(), the editor type is derived from the file's MIME type.

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.

See also openEditorAt().

[static] Core::IEditor *EditorManager::openEditorWithContents(Utils::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 specified 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.

See also clearUniqueId().

[static] bool EditorManager::openExternalEditor(const Utils::FilePath &filePath, Utils::Id editorId)

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

Returns false and displays an error message if editorId is not the ID of an external editor or the external editor cannot be opened.

See also openEditor().

[static] void EditorManager::populateOpenWithMenu(QMenu *menu, const Utils::FilePath &filePath)

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

[static] Core::IDocument::ReloadSetting EditorManager::reloadSetting()

Returns reload behavior settings.

[static slot] void EditorManager::revertToSaved()

Reverts the current document to its last saved state.

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

Saves the changes in document.

Returns whether the operation was successful.

[static slot] void EditorManager::saveDocument()

Saves the current document.

[static slot] void EditorManager::saveDocumentAs()

Saves the current document under a different file name.

[signal] void EditorManager::saved(Core::IDocument *document)

This signal is emitted after the document was saved.

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

Sets the location that was last modified to editor. Used for Window > Go to Last Edit.

[static] bool EditorManager::skipOpeningBigTextFile(const Utils::FilePath &filePath)

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

[static slot] void EditorManager::splitSideBySide()

Splits the editor view horizontally into adjacent views.

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

Returns the list of visible editors.

Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.