Commit 173aae37 authored by Jan Paul Batrina's avatar Jan Paul Batrina Committed by Nicolás Alvarez
Browse files

Add some of the missing KTextEditor interface methods

Only the methods that are used internally in KTextEditor
were added, so e.g. Application::closeDocuments() which
is used in some Kate plugins was not implemented.

With this commit, the vi-mode commands :q, :close, etc.
will now work properly, especially the command :only
which previously resulted to an infinite loop.

All implementations were based on the corresponding
method's behavior in Kate.

BUG: 441908
parent 729c0ac8
Pipeline #95973 passed with stage
in 11 minutes and 11 seconds
......@@ -16,6 +16,7 @@
#include <KTextEditor/Application>
#include <sublime/area.h>
#include <sublime/container.h>
#include <sublime/view.h>
#include <sublime/viewbarcontainer.h>
......@@ -23,6 +24,7 @@
#include "uicontroller.h"
#include "documentcontroller.h"
#include "plugincontroller.h"
#include "sessioncontroller.h"
#include "mainwindow.h"
#include "textdocument.h"
......@@ -216,6 +218,18 @@ KTextEditor::Document *Application::openUrl(const QUrl &url, const QString &enco
return doc->textDocument();
}
KTextEditor::Document *Application::findUrl(const QUrl &url) const
{
auto doc = Core::self()->documentControllerInternal()->documentForUrl(url);
return doc ? doc->textDocument() : nullptr;
}
bool Application::quit() const
{
Core::self()->sessionController()->emitQuitSession();
return true;
}
MainWindow::MainWindow(KDevelop::MainWindow *mainWindow)
: QObject(mainWindow)
, m_mainWindow(mainWindow)
......@@ -298,6 +312,68 @@ KTextEditor::View *MainWindow::activateView(KTextEditor::Document *doc)
return activeView();
}
bool MainWindow::closeView(KTextEditor::View *kteView)
{
if (!kteView) {
return false;
}
const auto areas = m_mainWindow->areas();
for (auto* area : areas) {
const auto views = area->views();
for (auto* view : views) {
if (toKteView(view) == kteView) {
area->closeView(view);
return true;
}
}
}
return false;
}
bool MainWindow::closeSplitView(KTextEditor::View *kteView)
{
return closeView(kteView);
}
bool MainWindow::viewsInSameSplitView(KTextEditor::View *kteView1, KTextEditor::View *kteView2) const
{
if (!kteView1 || !kteView2) {
return false;
}
if (kteView1 == kteView2) {
return true;
}
bool view1Found = false;
bool view2Found = false;
const auto containers = m_mainWindow->containers();
for (const auto* container : containers) {
const auto views = container->views();
for (auto* view : views) {
const KTextEditor::View *kteView = toKteView(view);
if (kteView == kteView1) {
view1Found = true;
} else if (kteView == kteView2) {
view2Found = true;
}
if (view1Found && view2Found) {
// both views found in the same container
return true;
}
}
if (view1Found != view2Found) {
// only one view being found implies that the other is in a different container
return false;
}
}
return false;
}
QObject *MainWindow::pluginView(const QString &id) const
{
return m_pluginViews.value(id);
......
......@@ -42,8 +42,11 @@ public Q_SLOTS:
QList<KTextEditor::Document *> documents();
KTextEditor::Document *openUrl(const QUrl &url, const QString &encoding = QString());
KTextEditor::Document *findUrl(const QUrl &url) const;
bool closeDocument(KTextEditor::Document *document) const;
bool quit() const;
};
class MainWindow : public QObject
......@@ -69,6 +72,9 @@ public Q_SLOTS:
QObject *pluginView(const QString &id) const;
void splitView(Qt::Orientation orientation);
bool closeView(KTextEditor::View *kteView);
bool closeSplitView(KTextEditor::View *kteView);
bool viewsInSameSplitView(KTextEditor::View* kteView1, KTextEditor::View* kteView2) const;
QWidget *createViewBar(KTextEditor::View *view);
void deleteViewBar(KTextEditor::View *view);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment