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, …, 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 closeDocuments(const QList<Core::IDocument *> &documents, bool askAboutModifiedEditors = true)
bool closeDocuments(const QList<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()
QStringList getOpenFileNames()
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 Core::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 QString &fileName)
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.

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.

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 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 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(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::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::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] 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] Core::IDocument *EditorManager::currentDocument()

Returns the document of the currently active editor.

See also currentEditor().

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

Returns the currently active editor.

See also currentDocument().

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

[static] QStringList EditorManager::getOpenFileNames()

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

See also DocumentManager::getOpenFileNames().

[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 fileName 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 filePath using the editor type editorId and the specified flags.

Moves the text cursor to the line and column.

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 Core::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 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.

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

Saves the changes in document.

Returns whether the operation was successful.

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

Returns the list of visible editors.

© 2021 The Qt Company Ltd. 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.