KTextEditor::Application Class
class KTextEditor::ApplicationThis class allows the application that embeds the KTextEditor component to allow it access to application wide information and interactions. More...
Header: | #include <KTextEditor/Application> |
CMake: | find_package(KF6 REQUIRED COMPONENTS TextEditor) target_link_libraries(mytarget PRIVATE KF6::TextEditor) |
Inherits: | QObject |
Public Functions
Application(QObject *parent) | |
KTextEditor::MainWindow * | activeMainWindow() |
bool | closeDocument(KTextEditor::Document *document) |
bool | closeDocuments(const QList<KTextEditor::Document *> &documents) |
QList<KTextEditor::Document *> | documents() |
KTextEditor::Document * | findUrl(const QUrl &url) |
QList<KTextEditor::MainWindow *> | mainWindows() |
KTextEditor::Document * | openUrl(const QUrl &url, const QString &encoding = QString()) |
KTextEditor::Plugin * | plugin(const QString &name) |
bool | quit() |
Signals
void | documentCreated(KTextEditor::Document *document) |
void | documentDeleted(KTextEditor::Document *document) |
void | documentWillBeDeleted(KTextEditor::Document *document) |
void | pluginCreated(const QString &name, KTextEditor::Plugin *plugin) |
void | pluginDeleted(const QString &name, KTextEditor::Plugin *plugin) |
Detailed Description
For example the component can get the current active main window of the application.
The application must pass a pointer to the Application object to the setApplication method of the global editor instance and ensure that this object stays valid for the complete lifetime of the editor.
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.
KTextEditor::Editor::instance()->application() will always return a non-nullptr object to avoid the need for nullptr checks before calling the API.
The same holds for activeMainWindow(), even if no main window is around, you will get a non-nullptr interface object that allows to call the functions of the MainWindow without needs for a nullptr check around it in the client code.
kte_plugin_hosting
Member Function Documentation
Application::Application(QObject *parent)
Construct an Application 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
KTextEditor::MainWindow *Application::activeMainWindow()
Accessor to the active main window. Returns a pointer to the active mainwindow, even if no main window is active you will get a non-nullptr dummy interface that allows you to call interface functions without the need for null checks
bool Application::closeDocument(KTextEditor::Document *document)
Close the given document. If the document is modified, user will be asked for confirmation.
document is the the document to be closed
Returns true on success, otherwise false
bool Application::closeDocuments(const QList<KTextEditor::Document *> &documents)
Close a list of documents. If any of them are modified, user will be asked for confirmation. Use this if you want to close multiple documents at once, as the application might be able to group the "do you really want that" dialogs into one.
documents is the list of documents to be closed
Returns true on success, otherwise false
[signal]
void Application::documentCreated(KTextEditor::Document *document)
This signal is emitted when the document was created.
document document that was created
[signal]
void Application::documentDeleted(KTextEditor::Document *document)
This signal is emitted when the document has been 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
document document that is deleted
[signal]
void Application::documentWillBeDeleted(KTextEditor::Document *document)
This signal is emitted before a document which should be closed is deleted The document is still accessible and usable, but it will be deleted after this signal was send.
document document that will be deleted
QList<KTextEditor::Document *> Application::documents()
Get a list of all documents that are managed by the application. This might contain less documents than the editor has in his documents () list. Returns all documents the application manages, might be empty!
KTextEditor::Document *Application::findUrl(const QUrl &url)
Get the document with the URL. If multiple documents match the searched url, return the first found one.
url is the document's URL
Returns the document with the given url or nullptr, if none found
QList<KTextEditor::MainWindow *> Application::mainWindows()
Get a list of all main windows. Returns all main windows, might be empty!
KTextEditor::Document *Application::openUrl(const QUrl &url, const QString &encoding = QString())
Open the document URL with the given encoding. If the url is empty, a new empty document will be created
url is the document 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 document
KTextEditor::Plugin *Application::plugin(const QString &name)
Get a plugin with the specified name.
name is the plugin's name
Returns pointer to the plugin if a plugin with name is loaded, otherwise nullptr
[signal]
void Application::pluginCreated(const QString &name, KTextEditor::Plugin *plugin)
This signal is emitted when an Plugin was loaded.
name is the name of the plugin
plugin is the new plugin
[signal]
void Application::pluginDeleted(const QString &name, KTextEditor::Plugin *plugin)
This signal is emitted when an Plugin got deleted.
name is the name of the plugin
plugin is the deleted plugin
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
bool Application::quit()
Ask app to quit. The app might interact with the user and decide that quitting is not possible and return false.
Returns true if the app could quit