KTextEditor::MainWindow Class

class KTextEditor::MainWindow

This class allows the application that embeds the KTextEditor component to allow it to access parts of its main window. More...

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

Public Types

enum ToolViewPosition { Left, Right, Top, Bottom }

Public Functions

MainWindow(QObject *parent)
virtual ~MainWindow() override
KTextEditor::View *activateView(KTextEditor::Document *document)
(since 6.0) void activateWidget(QWidget *widget)
KTextEditor::View *activeView()
(since 6.0) QWidget *activeWidget()
(since 5.98) bool addWidget(QWidget *widget)
void addWidgetToViewBar(KTextEditor::View *view, QWidget *bar)
bool closeSplitView(KTextEditor::View *view)
bool closeView(KTextEditor::View *view)
QWidget *createToolView(KTextEditor::Plugin *plugin, const QString &identifier, KTextEditor::MainWindow::ToolViewPosition pos, const QIcon &icon, const QString &text)
QWidget *createViewBar(KTextEditor::View *view)
void deleteViewBar(KTextEditor::View *view)
KXMLGUIFactory *guiFactory()
bool hideToolView(QWidget *widget)
void hideViewBar(KTextEditor::View *view)
bool moveToolView(QWidget *widget, KTextEditor::MainWindow::ToolViewPosition pos)
KTextEditor::View *openUrl(const QUrl &url, const QString &encoding = QString())
QObject *pluginView(const QString &name)
(since 6.0) bool removeWidget(QWidget *widget)
(since 5.98) bool showMessage(const QVariantMap &message)
(since 5.63) bool showPluginConfigPage(KTextEditor::Plugin *plugin, int page)
bool showToolView(QWidget *widget)
void showViewBar(KTextEditor::View *view)
void splitView(Qt::Orientation orientation)
QList<KTextEditor::View *> views()
bool viewsInSameSplitView(KTextEditor::View *view1, KTextEditor::View *view2)
(since 6.0) QWidgetList widgets()
QWidget *window()

Signals

void pluginViewCreated(const QString &name, QObject *pluginView)
void pluginViewDeleted(const QString &name, QObject *pluginView)
void unhandledShortcutOverride(QEvent *e)
void viewChanged(KTextEditor::View *view)
void viewCreated(KTextEditor::View *view)
(since 6.0) void widgetAdded(QWidget *widget)
(since 6.0) void widgetRemoved(QWidget *widget)

Detailed Description

For example the component can get a place to show view bar widgets (e.g. search&replace, goto line, ...). This is useful to e.g. have one place inside the window to show such stuff even if the application allows the user to have multiple split views available per window.

The application must pass a pointer to the MainWindow object to the createView method on view creation and ensure that this main window stays valid for the complete lifetime of the view.

It must not reimplement this class but construct an instance and pass a pointer to a QObject that has the required slots to receive the requests.

kte_plugin_hosting

Member Type Documentation

enum MainWindow::ToolViewPosition

Toolview position. A toolview can only be at one side at a time.

ConstantValueDescription
KTextEditor::MainWindow::Left0Left side
KTextEditor::MainWindow::Right1Right side
KTextEditor::MainWindow::Top2Top side
KTextEditor::MainWindow::Bottom3Bottom side

Member Function Documentation

MainWindow::MainWindow(QObject *parent)

Construct an MainWindow wrapper object. The passed parent is both the parent of this QObject and the receiver of all interface calls via invokeMethod.

parent is the object the calls are relayed to

[override virtual noexcept] MainWindow::~MainWindow()

Virtual Destructor

KTextEditor::View *MainWindow::activateView(KTextEditor::Document *document)

Activate the view with the corresponding document. If none exist for this document, create one

document is the document

Returns activated view of this document, return nullptr if not possible

[since 6.0] void MainWindow::activateWidget(QWidget *widget)

activate widget. If the widget is not present in the window, it will be added to the window

widget is the widget to activate

This function was introduced in 6.0.

KTextEditor::View *MainWindow::activeView()

Access the active view. Returns active view, nullptr if not available

[since 6.0] QWidget *MainWindow::activeWidget()

returns the currently active widget. It can be a non-KTextEditor::View widget or a KTextEditor::View

This function was introduced in 6.0.

[since 5.98] bool MainWindow::addWidget(QWidget *widget)

Add a widget to the main window. This is useful to show non-KTextEditor::View widgets in the main window. The host application should try to manage this like some KTextEditor::View (e.g. as a tab) and provide the means to close it.

widget is the widget to add

Returns success, if false, the plugin needs to take care to show the widget itself, otherwise the main window will take ownership of the widget

This function was introduced in 5.98.

void MainWindow::addWidgetToViewBar(KTextEditor::View *view, QWidget *bar)

Add a widget to the view bar.

view is the view for which the view bar is used

bar is the widget, shall have the viewBarParent() as parent widget

bool MainWindow::closeSplitView(KTextEditor::View *view)

Close the split view that contains the given view.

view is the view.

Returns true if the split view was closed.

bool MainWindow::closeView(KTextEditor::View *view)

Close selected view

view is the view to close

Returns true if view was closed

QWidget *MainWindow::createToolView(KTextEditor::Plugin *plugin, const QString &identifier, KTextEditor::MainWindow::ToolViewPosition pos, const QIcon &icon, const QString &text)

Create a new toolview with unique identifier at side pos with icon and caption text. Use the returned widget to embedd your widgets.

plugin is the plugin which owns this tool view

identifier is unique identifier for this toolview

pos is the position for the toolview, if we are in session restore, this is only a preference

icon is the icon to use in the sidebar for the toolview

text is translated text (i18n()) to use in addition to icon

Returns created toolview on success, otherwise NULL

QWidget *MainWindow::createViewBar(KTextEditor::View *view)

Try to create a view bar for the given view.

view is the view for which we want a view bar

Returns suitable widget that can host view bars widgets or nullptr

void MainWindow::deleteViewBar(KTextEditor::View *view)

Delete the view bar for the given view.

view is the view for which we want to delete the view bar

KXMLGUIFactory *MainWindow::guiFactory()

Accessor to the XMLGUIFactory.

Returns the mainwindow's KXMLGUIFactory, nullptr if not available

bool MainWindow::hideToolView(QWidget *widget)

Hide the toolview widget.

widget is the toolview to hide, where the widget was constructed by createToolView().

Returns true on success, otherwise false

void MainWindow::hideViewBar(KTextEditor::View *view)

Hide the view bar for the given view

view is the view for which the view bar is used

bool MainWindow::moveToolView(QWidget *widget, KTextEditor::MainWindow::ToolViewPosition pos)

Move the toolview widget to position pos.

widget is the toolview to move, where the widget was constructed by createToolView().

pos is the new position to move the widget to

Returns true on success, otherwise false

KTextEditor::View *MainWindow::openUrl(const QUrl &url, const QString &encoding = QString())

Open the document URL with the given encoding.

url is the document's URL

encoding is the preferred encoding. If encoding is QString() the encoding will be guessed or the default encoding will be used.

Returns a pointer to the created view for the new document, if a document with this url is already existing, its view will be activated, return nullptr if not possible

QObject *MainWindow::pluginView(const QString &name)

Get a plugin view for the plugin with with identifier name.

name is the plugin's name

Returns pointer to the plugin view if a plugin with name is loaded and has a view for this mainwindow, otherwise NULL

[signal] void MainWindow::pluginViewCreated(const QString &name, QObject *pluginView)

This signal is emitted when the view of some Plugin is created for this main window.

name is the name of the plugin

pluginView is the new plugin view

[signal] void MainWindow::pluginViewDeleted(const QString &name, QObject *pluginView)

This signal is emitted when the view of some Plugin got deleted.

Warning: Do not access the data referenced by the pointer, it is already invalid. Use the pointer only to remove mappings in hash or maps

name is the name of the plugin

pluginView is the deleted plugin view

[since 6.0] bool MainWindow::removeWidget(QWidget *widget)

remove this widget from this mainwindow. The widget will be deleted afterwards

widget is the widget to be removed

Returns true on success

This function was introduced in 6.0.

[since 5.98] bool MainWindow::showMessage(const QVariantMap &message)

Display a message to the user. The host application might show this inside a dedicated output view.

message is the incoming message we shall handle

Returns true, if the host application was able to handle the message, else false

details of message format:

message text, will be trimmed before output

message["text"] = i18n("your cool message")

the text will be split in lines, all lines beside the first can be collapsed away

message type, we support at the moment

message["type"] = "Error" message["type"] = "Warning" message["type"] = "Info" message["type"] = "Log"

this is take from https://microsoft.github.io/language-server-protocol/specification#window_showMessage MessageType of LSP

will lead to appropriate icons/... in the output view

a message should have some category, like Git, LSP, ....

message["category"] = i18n(...)

will be used to allow the user to filter for

one can additionally provide a categoryIcon

message["categoryIcon"] = QIcon(...)

the categoryIcon icon QVariant must contain a QIcon, nothing else!

A string token can be passed to allow to replace messages already send out with new ones. That is useful for e.g. progress output

message["token"] = "yourmessagetoken"

This function was introduced in 5.98.

[since 5.63] bool MainWindow::showPluginConfigPage(KTextEditor::Plugin *plugin, int page)

Shows the plugin's config page. The page specifies which config page will be shown, see KTextEditor::Plugin::configPages().

Returns true on success, otherwise false

This function was introduced in 5.63.

bool MainWindow::showToolView(QWidget *widget)

Show the toolview widget.

widget is the toolview to show, where the widget was constructed by createToolView().

Returns true on success, otherwise false TODO add focus parameter: bool showToolView (QWidget *widget, bool giveFocus );

void MainWindow::showViewBar(KTextEditor::View *view)

Show the view bar for the given view

view is the view for which the view bar is used

void MainWindow::splitView(Qt::Orientation orientation)

Split current view space according to orientation

orientation defines the split orientation (horizontal or vertical)

[signal] void MainWindow::unhandledShortcutOverride(QEvent *e)

This signal is emitted for every unhandled ShortcutOverride in the window

e is the responsible event

[signal] void MainWindow::viewChanged(KTextEditor::View *view)

This signal is emitted whenever the active view changes.

view is the new active view

[signal] void MainWindow::viewCreated(KTextEditor::View *view)

This signal is emitted whenever a new view is created

view is the view that was created

QList<KTextEditor::View *> MainWindow::views()

Get a list of all views for this main window.

It is beneficial if the list is sorted by most recently used, as the library will e.g. try to use the most recent used url() by walking over this list for save and other such things.

Returns all views, might be empty!

bool MainWindow::viewsInSameSplitView(KTextEditor::View *view1, KTextEditor::View *view2)

Returns true if the given views view1 and view2 share the same split view, false otherwise.

[signal, since 6.0] void MainWindow::widgetAdded(QWidget *widget)

Emitted when a widget was added to this window.

widget is the widget that was added

This function was introduced in 6.0.

[signal, since 6.0] void MainWindow::widgetRemoved(QWidget *widget)

Emitted when a widget was added to this window.

widget is the widget that was removed

This function was introduced in 6.0.

[since 6.0] QWidgetList MainWindow::widgets()

returns the list of non-KTextEditor::View widgets in this main window.

This function was introduced in 6.0.

See also addWidget.

QWidget *MainWindow::window()

Get the toplevel widget.

Returns the real main window widget, nullptr if not available