[rkward/work/kateintegration] rkward: Create dummies for all the needed interface functions, and start implementing a few easy ones.

Thomas Friedrichsmeier null at kde.org
Mon Jan 6 20:42:51 GMT 2020


Git commit a08925849c86f20cca89befcac9b509cbb7b4eed by Thomas Friedrichsmeier.
Committed on 06/01/2020 at 20:40.
Pushed by tfry into branch 'work/kateintegration'.

Create dummies for all the needed interface functions, and start implementing a few easy ones.

Search in files-plugin now works to some degree.

M  +2    -2    rkward/rkward.cpp
M  +190  -4    rkward/windows/katepluginintegration.cpp
M  +52   -7    rkward/windows/katepluginintegration.h
M  +3    -1    rkward/windows/rkcommandeditorwindow.h

https://commits.kde.org/rkward/a08925849c86f20cca89befcac9b509cbb7b4eed

diff --git a/rkward/rkward.cpp b/rkward/rkward.cpp
index 152dfa0a..34bc8dcc 100644
--- a/rkward/rkward.cpp
+++ b/rkward/rkward.cpp
@@ -154,7 +154,9 @@ RKWardMainWindow::RKWardMainWindow () : KParts::MainWindow ((QWidget *)0, (Qt::W
 	setHelpMenuEnabled (false);
 	setXMLFile ("rkwardui.rc");
 	insertChildClient (toplevel_actions = new RKTopLevelWindowGUI (this));
+	insertChildClient (katePluginIntegration ());
 	createShellGUI (true);
+	katePluginIntegration ()->loadPlugin ("katesearchplugin");
 	RKXMLGUISyncer::self ()->watchXMLGUIClientUIrc (this);
 
 	// replicate File->import and export menus into the Open/Save toolbar button menus
@@ -470,8 +472,6 @@ void RKWardMainWindow::initToolViewsAndR () {
 	RKToolWindowList::registerToolWindow (RKDebugMessageWindow::instance (), "rkdebugmessages", RKToolWindowList::Nowhere, 0);
 
 	RKWorkplace::mainWorkplace ()->placeToolWindows ();
-	katePluginIntegration ()->loadPlugin ("katesearchplugin");
-//	insertChildClient (katePluginIntegration ());
 }
 
 void RKWardMainWindow::initActions() {  
diff --git a/rkward/windows/katepluginintegration.cpp b/rkward/windows/katepluginintegration.cpp
index efa68b1c..9a0661f4 100644
--- a/rkward/windows/katepluginintegration.cpp
+++ b/rkward/windows/katepluginintegration.cpp
@@ -29,13 +29,19 @@
 #include <KTextEditor/Plugin>
 
 #include "../rkward.h"
+#include "rkworkplace.h"
+#include "rkcommandeditorwindow.h"
 
 #include "../debug.h"
 
 KatePluginIntegration::KatePluginIntegration (QObject *parent) : QObject (parent), KXMLGUIClient () {
 	RK_TRACE (APP);
 
-	main = new KTextEditor::MainWindow (this);
+	// This one is passed to each created plugin
+	main = new KTextEditor::MainWindow(this);
+	// While this one may be accessed from plugins via KTextEditor::Editor::instance()->application()
+	KatePluginIntegration2 *buddy = new KatePluginIntegration2(this);
+	KTextEditor::Editor::instance()->setApplication (buddy->app);
 
 	// enumerate all available kate plugins
 	QVector<KPluginMetaData> plugins = KPluginLoader::findPlugins (QStringLiteral ("ktexteditor"), [](const KPluginMetaData &md) { return md.serviceTypes().contains(QLatin1String("KTextEditor/Plugin")); });
@@ -46,6 +52,7 @@ KatePluginIntegration::KatePluginIntegration (QObject *parent) : QObject (parent
 
 		qDebug ("%s", qPrintable(plugin.fileName()));
 	}
+	// TODO
 }
 
 QWidget * KatePluginIntegration::createToolView (KTextEditor::Plugin *plugin, const QString &identifier, KTextEditor::MainWindow::ToolViewPosition pos, const QIcon &icon, const QString &text) {
@@ -56,6 +63,7 @@ QWidget * KatePluginIntegration::createToolView (KTextEditor::Plugin *plugin, co
 	dummy->setLayout (new QVBoxLayout ());
 //	dummy->show();
 	return dummy;
+	// TODO
 }
 
 bool KatePluginIntegration::showToolView (QWidget *widget) {
@@ -63,6 +71,11 @@ bool KatePluginIntegration::showToolView (QWidget *widget) {
 	RKDebug (APP, DL_ERROR, "showToolView");
 	widget->show ();
 	return true;
+	// TODO
+}
+
+QString KatePluginIntegration::idForPlugin(const KPluginMetaData &plugin) const {
+	return QFileInfo(plugin.fileName()).baseName();
 }
 
 QObject* KatePluginIntegration::loadPlugin (const QString& identifier) {
@@ -84,14 +97,187 @@ QObject* KatePluginIntegration::loadPlugin (const QString& identifier) {
 	}
 
     return 0;
+	// TODO
 }
 
 KXMLGUIFactory *KatePluginIntegration::guiFactory () {
 	RK_TRACE (APP);
 
-	return RKWardMainWindow::getMain()->guiFactory();
+	// We'd rather like to add the plugin to our own RKMDIWindows, rather than
+	// allowing it direct access to the guiFactory()
+	qDebug ("%p", sender());
+	return factory ();
+	// TODO
 }
 
-QString KatePluginIntegration::idForPlugin(const KPluginMetaData &plugin) const {
-	return QFileInfo(plugin.fileName()).baseName();
+QWidget *KatePluginIntegration::window() {
+	RK_TRACE (APP);
+	return 0;
+	// TODO
+}
+
+QList<KTextEditor::View *> KatePluginIntegration::views() {
+	RK_TRACE (APP);
+
+	QList<RKMDIWindow*> w = RKWorkplace::mainWorkplace()->getObjectList(RKMDIWindow::CommandEditorWindow);
+	QList<KTextEditor::View*> ret;
+	for (int i = 0; i < w.size (); ++i) {
+		ret.append (static_cast<RKCommandEditorWindow*>(w[i])->getView());
+	}
+	return ret;
+}
+
+KTextEditor::View *KatePluginIntegration::activeView() {
+	RK_TRACE (APP);
+
+	RKMDIWindow *w = RKWorkplace::mainWorkplace()->activeWindow (RKMDIWindow::AnyWindowState);
+	if (w && w->isType (RKMDIWindow::CommandEditorWindow)) {
+		return static_cast<RKCommandEditorWindow*>(w)->getView();
+	}
+	return 0;
+}
+
+KTextEditor::View *KatePluginIntegration::activateView(KTextEditor::Document *document) {
+	RK_TRACE (APP);
+	return 0;
+	// TODO
+}
+
+KTextEditor::View *KatePluginIntegration::openUrl(const QUrl &url, const QString &encoding) {
+	RK_TRACE (APP);
+	return 0;
+	// TODO
+}
+
+QWidget *KatePluginIntegration::createViewBar(KTextEditor::View *view) {
+	RK_TRACE (APP);
+	return 0;
+	// TODO
+}
+
+QObject *KatePluginIntegration::pluginView(const QString &name) {
+	RK_TRACE (APP);
+	return 0;
+	// TODO
+}
+
+void KatePluginIntegration::addWidgetToViewBar(KTextEditor::View* view, QWidget* bar) {
+	RK_TRACE (APP);
+	// TODO
+}
+
+bool KatePluginIntegration::closeSplitView(KTextEditor::View* view) {
+	RK_TRACE (APP);
+	return false;
+	// TODO
+}
+
+bool KatePluginIntegration::closeView(KTextEditor::View* view) {
+	RK_TRACE (APP);
+	return false;
+	// TODO
+}
+
+void KatePluginIntegration::deleteViewBar(KTextEditor::View* view) {
+	RK_TRACE (APP);
+	// TODO
+}
+
+bool KatePluginIntegration::hideToolView(QWidget* widget) {
+	RK_TRACE (APP);
+	return false;
+	// TODO
+}
+
+void KatePluginIntegration::hideViewBar(KTextEditor::View* view) {
+	RK_TRACE (APP);
+	// TODO
+}
+
+bool KatePluginIntegration::moveToolView(QWidget* widget, KTextEditor::MainWindow::ToolViewPosition pos) {
+	RK_TRACE (APP);
+	// TODO
+	return false;
+}
+
+void KatePluginIntegration::showViewBar(KTextEditor::View* view) {
+	RK_TRACE (APP);
+	// TODO
+}
+
+void KatePluginIntegration::splitView(Qt::Orientation orientation) {
+	RK_TRACE (APP);
+	// TODO
+}
+
+bool KatePluginIntegration::viewsInSameSplitView(KTextEditor::View* view1, KTextEditor::View* view2) {
+	RK_TRACE (APP);
+	// TODO
+	return false;
+}
+
+///  BEGIN  KTextEditor::Application interface
+
+KatePluginIntegration2::KatePluginIntegration2(KatePluginIntegration *_buddy) : QObject (_buddy) {
+	RK_TRACE (APP);
+	buddy = _buddy;
+	app = new KTextEditor::Application (this);
+}
+
+KatePluginIntegration2::~KatePluginIntegration2() {
+	RK_TRACE (APP);
+}
+
+QList<KTextEditor::MainWindow *> KatePluginIntegration2::mainWindows() {
+	RK_TRACE (APP);
+	QList<KTextEditor::MainWindow *> ret;
+	ret.append (buddy->main);
+	return ret;
+}
+
+KTextEditor::MainWindow *KatePluginIntegration2::activeMainWindow() {
+	RK_TRACE (APP);
+	return buddy->main;
+}
+
+QList<KTextEditor::Document *> KatePluginIntegration2::documents() {
+	RK_TRACE (APP);
+
+	QList<RKMDIWindow*> w = RKWorkplace::mainWorkplace()->getObjectList(RKMDIWindow::CommandEditorWindow);
+	QList<KTextEditor::Document*> ret;
+	for (int i = 0; i < w.size (); ++i) {
+		KTextEditor::View *v = static_cast<RKCommandEditorWindow*>(w[i])->getView(); 
+		if (v) ret.append (v->document());
+	}
+	return ret;
+}
+
+KTextEditor::Document *KatePluginIntegration2::findUrl(const QUrl &url) {
+	RK_TRACE (APP);
+	return 0;
+	// TODO
+}
+
+KTextEditor::Document *KatePluginIntegration2::openUrl(const QUrl &url, const QString &encoding) {
+	RK_TRACE (APP);
+	return 0;
+	// TODO
+}
+
+bool KatePluginIntegration2::closeDocument(KTextEditor::Document *document) {
+	RK_TRACE (APP);
+	return false;
+	// TODO
+}
+
+bool KatePluginIntegration2::closeDocuments(const QList<KTextEditor::Document *> &documents) {
+	RK_TRACE (APP);
+	return false;
+	// TODO
+}
+
+KTextEditor::Plugin *KatePluginIntegration2::plugin(const QString &name) {
+	RK_TRACE (APP);
+	return 0;
+	// TODO
 }
diff --git a/rkward/windows/katepluginintegration.h b/rkward/windows/katepluginintegration.h
index 413f5b83..f08738a2 100644
--- a/rkward/windows/katepluginintegration.h
+++ b/rkward/windows/katepluginintegration.h
@@ -19,6 +19,7 @@
 #define KATEPLUGININTEGRATION_H
 
 #include <KTextEditor/MainWindow>
+#include <KTextEditor/Application>
 #include <KPluginMetaData>
 #include <KXMLGUIClient>
 
@@ -27,17 +28,61 @@
 class KatePluginIntegration : public QObject, public KXMLGUIClient {
 Q_OBJECT
 public:
-	KatePluginIntegration (QObject *parent);
-	KTextEditor::MainWindow *mainWindow () const { return main; };
-	QObject* loadPlugin (const QString& identifier);
-public slots:
-	QWidget *createToolView (KTextEditor::Plugin *plugin, const QString &identifier, KTextEditor::MainWindow::ToolViewPosition pos, const QIcon &icon, const QString &text);
-	KXMLGUIFactory *guiFactory ();
-	bool showToolView (QWidget *widget);
+	KatePluginIntegration(QObject *parent);
+	KTextEditor::MainWindow *mainWindow() const { return main; };
+	QObject* loadPlugin(const QString& identifier);
+private slots:
+	// These are the implementations of the KTextEditor::MainWindow interface.
+	// NOTE that they  are not technically overrides, but get invoked via QMetaObject::invokeMethod()
+	QWidget *createToolView(KTextEditor::Plugin *plugin, const QString &identifier, KTextEditor::MainWindow::ToolViewPosition pos, const QIcon &icon, const QString &text);
+	KXMLGUIFactory *guiFactory();
+	QWidget *window();
+	QList<KTextEditor::View *> views();
+	KTextEditor::View *activeView();
+	KTextEditor::View *activateView(KTextEditor::Document *document);
+	KTextEditor::View *openUrl(const QUrl &url, const QString &encoding = QString());
+	bool closeView(KTextEditor::View *view);
+	void splitView(Qt::Orientation orientation);
+	bool closeSplitView(KTextEditor::View *view);
+	bool viewsInSameSplitView(KTextEditor::View *view1, KTextEditor::View *view2);
+	QWidget *createViewBar(KTextEditor::View *view);
+	void deleteViewBar(KTextEditor::View *view);
+	void addWidgetToViewBar(KTextEditor::View *view, QWidget *bar);
+	void showViewBar(KTextEditor::View *view);
+	void hideViewBar(KTextEditor::View *view);
+	bool moveToolView(QWidget *widget, KTextEditor::MainWindow::ToolViewPosition pos);
+	bool showToolView(QWidget *widget);
+	bool hideToolView(QWidget *widget);
+	QObject *pluginView(const QString &name);
 private:
+friend class KatePluginIntegration2;
 	KTextEditor::MainWindow *main;
 	QMap<QString, KPluginMetaData> known_plugins;
 	QString idForPlugin(const KPluginMetaData &plugin) const;
 };
 
+/** This class provides implementations for the KTextEditor::Application interface. I'd love to merge it into
+ *  KatePluginIntegration, but this is not possible due to a name clash in one of the slots (openUrl()). */
+class KatePluginIntegration2 : public QObject {
+	Q_OBJECT
+public:
+	KatePluginIntegration2(KatePluginIntegration *_buddy);
+	~KatePluginIntegration2();
+private slots:
+	// And these are the implementations of the KTextEditor::Application interface.
+	// NOTE that they are not technically overrides, but get invoked via QMetaObject::invokeMethod()
+	QList<KTextEditor::MainWindow *> mainWindows();
+	KTextEditor::MainWindow *activeMainWindow();
+	QList<KTextEditor::Document *> documents();
+	KTextEditor::Document *findUrl(const QUrl &url);
+	KTextEditor::Document *openUrl(const QUrl &url, const QString &encoding = QString());
+	bool closeDocument(KTextEditor::Document *document);
+	bool closeDocuments(const QList<KTextEditor::Document *> &documents);
+	KTextEditor::Plugin *plugin(const QString &name);
+private:
+friend class KatePluginIntegration;
+	KatePluginIntegration *buddy;
+	KTextEditor::Application *app;
+};
+
 #endif
diff --git a/rkward/windows/rkcommandeditorwindow.h b/rkward/windows/rkcommandeditorwindow.h
index 1691d7df..5abc2cfa 100644
--- a/rkward/windows/rkcommandeditorwindow.h
+++ b/rkward/windows/rkcommandeditorwindow.h
@@ -2,7 +2,7 @@
                           rkcommandeditorwindow  -  description
                              -------------------
     begin                : Mon Aug 30 2004
-    copyright            : (C) 2004-2019 by Thomas Friedrichsmeier
+    copyright            : (C) 2004-2020 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -152,6 +152,8 @@ public:
 	void currentHelpContext (QString* symbol, QString* package) override;
 
 	void highlightLine (int linenum);
+/** Returns the (main, non-preview) texteditor view in this editor. */
+	KTextEditor::View* getView () const { return m_view; };
 public slots:
 /** update Tab caption according to the current url. Display the filename-component of the URL, or - if not available - a more elaborate description of the url. Also appends a "[modified]" if appropriate */
 	void updateCaption ();



More information about the rkward-tracker mailing list