KTextEditor::Editor Class

class KTextEditor::Editor

Accessor interface for the KTextEditor framework. More...

Header: #include <KTextEditor/Editor>
CMake: find_package(KF6 REQUIRED COMPONENTS TextEditor)
target_link_libraries(mytarget PRIVATE KF6::TextEditor)
Inherits: QObject

Public Functions

virtual const KAboutData &aboutData() const = 0
(since 5.63) void addVariableExpansion(const QList<QWidget *> &widgets, const QStringList &variables = QStringList()) const
virtual KTextEditor::Application *application() const = 0
virtual QStringList commandList() const = 0
virtual QList<KTextEditor::Command *> commands() const = 0
virtual void configDialog(QWidget *parent) = 0
virtual KTextEditor::ConfigPage *configPage(int number, QWidget *parent) = 0
virtual int configPages() const = 0
virtual KTextEditor::Document *createDocument(QObject *parent) = 0
QString defaultEncoding() const
virtual QList<KTextEditor::Document *> documents() = 0
(since 6.0) QString expandText(const QString &text, KTextEditor::View *view) const
(since 5.57) bool expandVariable(const QString &variable, KTextEditor::View *view, QString &output) const
(since 5.80) QFont font() const
virtual KTextEditor::Command *queryCommand(const QString &cmd) const = 0
(since 5.57) bool registerVariableMatch(const QString &name, const QString &description, KTextEditor::Editor::ExpandFunction expansionFunc)
(since 5.57) bool registerVariablePrefix(const QString &prefix, const QString &description, KTextEditor::Editor::ExpandFunction expansionFunc)
(since 5.79) const KSyntaxHighlighting::Repository &repository() const
virtual void setApplication(KTextEditor::Application *application) = 0
(since 5.79) KSyntaxHighlighting::Theme theme() const
(since 6.0) bool unregisterVariable(const QString &variableName)

Signals

(since 5.79) void configChanged(KTextEditor::Editor *editor)
void documentCreated(KTextEditor::Editor *editor, KTextEditor::Document *document)
(since 5.79) void repositoryReloaded(KTextEditor::Editor *editor)

Static Public Members

KTextEditor::Editor *instance()

Protected Functions

Editor(KTextEditor::EditorPrivate *impl)
virtual ~Editor() override

Detailed Description

Introduction

The Editor part can either be accessed through the static accessor Editor::instance() or through the KParts component model (see kte_design_part). The Editor singleton provides general information and configuration methods for the Editor, for example KAboutData by using aboutData().

The Editor has a list of all opened documents. Get this list with documents(). To create a new Document call createDocument(). The signal documentCreated() is emitted whenever the Editor created a new document.

Configuration

The config dialog can be shown with configDialog(). Instead of using the config dialog, the config pages can also be embedded into the application's config dialog. To do this, configPages() returns the number of config pages that exist and configPage() returns the requested page. The configuration are saved automatically by the Editor.

Note: It is recommended to embed the config pages into the main application's config dialog instead of using a separate config dialog, if the config dialog does not look cluttered then. This way, all settings are grouped together in one place.

Command Line Commands

With Commands it is possible to add new commands to the command line. These Command%s then are added to all document View%s. Common use cases include commands like find or setting document variables. The list of all registered commands can be obtained either through commandList() or through commands(). Further, a specific command can be obtained through queryCommand(). For further information, read the Command API documentation.

See also KTextEditor::Document, KTextEditor::ConfigPage, and KTextEditor::Command.

Member Function Documentation

[protected] Editor::Editor(KTextEditor::EditorPrivate *impl)

Constructor.

Create the Editor object and pass it the internal implementation to store a d-pointer.

impl d-pointer to use

[override virtual noexcept protected] Editor::~Editor()

Virtual destructor.

[pure virtual] const KAboutData &Editor::aboutData() const

Get the about data of this Editor part. Returns about data

[since 5.63] void Editor::addVariableExpansion(const QList<QWidget *> &widgets, const QStringList &variables = QStringList()) const

Adds a QAction to the widget in widgets that whenever focus is gained. When the action is invoked, a non-modal dialog is shown that lists all variables. If variables is non-empty, then only the variables in variables are listed.

The supported QWidgets in the widgets argument currently are:

This function was introduced in 5.63.

[pure virtual] KTextEditor::Application *Editor::application() const

Current hosting application, if any set. Returns current application object or a dummy interface that allows you to call the functions will never return a nullptr

See also setApplication().

[pure virtual] QStringList Editor::commandList() const

Get a list of available command line strings. Returns command line strings

See also commands().

[pure virtual] QList<KTextEditor::Command *> Editor::commands() const

Get a list of all registered commands. Returns list of all commands

See also queryCommand() and commandList().

[signal, since 5.79] void Editor::configChanged(KTextEditor::Editor *editor)

This signal is emitted whenever the editor configuration is changed.

editor is the editor whose config has changed

This function was introduced in 5.79.

[pure virtual] void Editor::configDialog(QWidget *parent)

Show the editor's config dialog. Changes will be applied to the editor and the configuration changes are saved.

Note: Instead of using the config dialog, the config pages can be embedded into your own config dialog by using configPages() and configPage().

parent is parent widget

[pure virtual] KTextEditor::ConfigPage *Editor::configPage(int number, QWidget *parent)

Get the config page with the number, config pages from 0 to configPages()-1 are available if configPages() > 0. Configuration changes done over this widget are automatically saved.

number is the config page index

parent is the parent widget for the config page

Returns created config page or NULL, if the number is out of bounds

See also configPages().

[pure virtual] int Editor::configPages() const

Get the number of available config pages. If a number < 1 is returned, it does not support config pages. Returns number of config pages

See also configPage().

[pure virtual] KTextEditor::Document *Editor::createDocument(QObject *parent)

Create a new document object with parent.

For each created document, the signal documentCreated() is emitted.

parent is the document's parent object

Returns new KTextEditor::Document object

See also documents() and documentCreated().

QString Editor::defaultEncoding() const

Get the current default encoding for this Editor part. Returns default encoding

[signal] void Editor::documentCreated(KTextEditor::Editor *editor, KTextEditor::Document *document)

The editor emits this signal whenever a document was successfully created.

editor is a pointer to the Editor singleton which created the new document

document is the newly created document instance

See also createDocument().

[pure virtual] QList<KTextEditor::Document *> Editor::documents()

Get a list of all documents of this editor. Returns list of all existing documents

See also createDocument().

[since 6.0] QString Editor::expandText(const QString &text, KTextEditor::View *view) const

Expands arbitrary text that may contain arbitrary many variables. On success, the expanded text is written to output.

Returns the expanded text.

This function was introduced in 6.0.

[since 5.57] bool Editor::expandVariable(const QString &variable, KTextEditor::View *view, QString &output) const

Expands a single variable, writing the expanded value to output.

Returns true on success, otherwise false.

This function was introduced in 5.57.

[since 5.80] QFont Editor::font() const

Get the current global editor font. Might change during runtime, configChanged() will be emitted in that cases. Individual views might have set different fonts, can be queried with the "font" key via

Returns current global font for all views

This function was introduced in 5.80.

See also KTextEditor::ConfigInterface::configValue().

[static] KTextEditor::Editor *Editor::instance()

Accessor to get the Editor instance.

Note: This object will stay alive until QCoreApplication terminates. You shall not delete it yourself. There is only ONE Editor instance of this per process.

Returns Editor controller, after initial construction, will live until QCoreApplication is terminating.

[pure virtual] KTextEditor::Command *Editor::queryCommand(const QString &cmd) const

Query for the command cmd. If the command cmd does not exist the return value is NULL.

cmd is the name of command to query for

Returns the found command or NULL if no such command exists

[since 5.57] bool Editor::registerVariableMatch(const QString &name, const QString &description, KTextEditor::Editor::ExpandFunction expansionFunc)

Registers a variable called name for exact matches. For instance, a variable called "CurrentDocument:Path" could be registered which then expands to the path the current document.

Returns true on success, false if the variable could not be registered, e.g. because it already was registered previously.

This function was introduced in 5.57.

[since 5.57] bool Editor::registerVariablePrefix(const QString &prefix, const QString &description, KTextEditor::Editor::ExpandFunction expansionFunc)

Registers a variable for arbitrary text that matches the specified prefix. For instance, a variable called "ENV:" could be registered which then expands arbitrary environment variables, e.g. ENV:HOME would expand to the user's home directory.

Note: A colon ':' is used as separator for the prefix and the text after the colon that should be evaluated.

Returns true on success, false if a prefix could not be registered, e.g. because it already was registered previously.

This function was introduced in 5.57.

[since 5.79] const KSyntaxHighlighting::Repository &Editor::repository() const

Get read-only access to the syntax highlighting repository the editor uses. Might be reloaded during runtime, repositoryReloaded() will be emitted in that cases.

Returns syntax repository used by the editor

This function was introduced in 5.79.

[signal, since 5.79] void Editor::repositoryReloaded(KTextEditor::Editor *editor)

This signal is emitted whenever the editor syntax repository is reloaded. Can be used to e.g. re-instantiate syntax definitions that got invalidated by the repository reload.

editor is the editor whose repository was reloaded

This function was introduced in 5.79.

[pure virtual] void Editor::setApplication(KTextEditor::Application *application)

Set the global application object. This will allow the editor component to access the hosting application.

application is the application object (if the argument is a nullptr, this will reset the application back to a dummy interface)

See also application().

[since 5.79] KSyntaxHighlighting::Theme Editor::theme() const

Get the current global theme. Might change during runtime, configChanged() will be emitted in that cases. Individual views might have set different themes,

Returns current global theme for all views

This function was introduced in 5.79.

See also KTextEditor::View::theme().

[since 6.0] bool Editor::unregisterVariable(const QString &variableName)

Unregisters a variable that was previously registered with registerVariableMatch() or registerVariablePrefix().

variableName is the variable's name

Returns true if the variable was successfully unregistered, and false if the variable did not exist.

This function was introduced in 6.0.