[rkward/work/kateintegration] rkward: Proof-of-concept for loading a kate plugin.

Thomas Friedrichsmeier null at kde.org
Mon Jan 6 09:36:47 GMT 2020


Git commit d4046946e2dd6899689ca14e0028e5a1a965d77d by Thomas Friedrichsmeier.
Committed on 06/01/2020 at 09:36.
Pushed by tfry into branch 'work/kateintegration'.

Proof-of-concept for loading a kate plugin.

This is not anywhere near useable, so far, but we can now load the find-in-file plugin and display it - somewhere.

M  +2    -0    rkward/rkward.cpp
M  +67   -7    rkward/windows/katepluginintegration.cpp
M  +13   -4    rkward/windows/katepluginintegration.h

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

diff --git a/rkward/rkward.cpp b/rkward/rkward.cpp
index 9d7b6c73..152dfa0a 100644
--- a/rkward/rkward.cpp
+++ b/rkward/rkward.cpp
@@ -470,6 +470,8 @@ 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 22b1561f..efa68b1c 100644
--- a/rkward/windows/katepluginintegration.cpp
+++ b/rkward/windows/katepluginintegration.cpp
@@ -2,7 +2,7 @@
                           katepluginintegration  -  description
                              -------------------
     begin                : Mon Jun 12 2017
-    copyright            : (C) 2017 by Thomas Friedrichsmeier
+    copyright            : (C) 2017-2020 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -17,21 +17,81 @@
 
 #include "katepluginintegration.h"
 
-#include "../debug.h"
-
 #include <QWidget>
+#include <QFileInfo>
+#include <QVBoxLayout>
+
+#include <KPluginFactory>
+#include <KPluginLoader>
+#include <KPluginMetaData>
+#include <KTextEditor/Editor>
+#include <KTextEditor/Application>
+#include <KTextEditor/Plugin>
+
+#include "../rkward.h"
+
+#include "../debug.h"
 
-KatePluginIntegration::KatePluginIntegration (QObject *parent) : QObject (parent) {
+KatePluginIntegration::KatePluginIntegration (QObject *parent) : QObject (parent), KXMLGUIClient () {
 	RK_TRACE (APP);
-	RKDebug (APP, DL_ERROR, "ctor");
 
 	main = new KTextEditor::MainWindow (this);
+
+	// enumerate all available kate plugins
+	QVector<KPluginMetaData> plugins = KPluginLoader::findPlugins (QStringLiteral ("ktexteditor"), [](const KPluginMetaData &md) { return md.serviceTypes().contains(QLatin1String("KTextEditor/Plugin")); });
+    for (int i = plugins.size() -1; i >= 0; --i) {
+		KPluginMetaData &plugin = plugins[i];
+		// Note: creates a lookup-table *and* eliminates potential dupes later in the search path 
+		known_plugins.insert (idForPlugin (plugin), plugin);
+
+		qDebug ("%s", qPrintable(plugin.fileName()));
+	}
 }
 
 QWidget * KatePluginIntegration::createToolView (KTextEditor::Plugin *plugin, const QString &identifier, KTextEditor::MainWindow::ToolViewPosition pos, const QIcon &icon, const QString &text) {
 	RK_TRACE (APP);
 	RKDebug (APP, DL_ERROR, "createToolView");
-	
-	return new QWidget ();
+
+	QWidget *dummy = new QWidget();
+	dummy->setLayout (new QVBoxLayout ());
+//	dummy->show();
+	return dummy;
+}
+
+bool KatePluginIntegration::showToolView (QWidget *widget) {
+	RK_TRACE (APP);
+	RKDebug (APP, DL_ERROR, "showToolView");
+	widget->show ();
+	return true;
 }
 
+QObject* KatePluginIntegration::loadPlugin (const QString& identifier) {
+	RK_TRACE (APP);
+
+	if (!known_plugins.contains (identifier)) {
+		RK_DEBUG (APP, DL_WARNING, "Plugin %s is not known", qPrintable (identifier));
+		return 0;
+	}
+
+	KPluginFactory *factory = KPluginLoader (known_plugins[identifier].fileName ()).factory ();
+	if (factory) {
+		KTextEditor::Plugin *plugin = factory->create<KTextEditor::Plugin> (this, QVariantList () << identifier);
+		if (plugin) {
+			emit KTextEditor::Editor::instance ()->application ()->pluginCreated (identifier, plugin);
+			plugin->createView (main);
+			return plugin;
+		}
+	}
+
+    return 0;
+}
+
+KXMLGUIFactory *KatePluginIntegration::guiFactory () {
+	RK_TRACE (APP);
+
+	return RKWardMainWindow::getMain()->guiFactory();
+}
+
+QString KatePluginIntegration::idForPlugin(const KPluginMetaData &plugin) const {
+	return QFileInfo(plugin.fileName()).baseName();
+}
diff --git a/rkward/windows/katepluginintegration.h b/rkward/windows/katepluginintegration.h
index 1d5b2c43..413f5b83 100644
--- a/rkward/windows/katepluginintegration.h
+++ b/rkward/windows/katepluginintegration.h
@@ -2,7 +2,7 @@
                           katepluginintegration  -  description
                              -------------------
     begin                : Mon Jun 12 2017
-    copyright            : (C) 2017 by Thomas Friedrichsmeier
+    copyright            : (C) 2017-2020 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -18,17 +18,26 @@
 #ifndef KATEPLUGININTEGRATION_H
 #define KATEPLUGININTEGRATION_H
 
-#include <ktexteditor/mainwindow.h>
+#include <KTextEditor/MainWindow>
+#include <KPluginMetaData>
+#include <KXMLGUIClient>
 
-class KatePluginIntegration : public QObject {
+#include <QMap>
+
+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);
 private:
 	KTextEditor::MainWindow *main;
+	QMap<QString, KPluginMetaData> known_plugins;
+	QString idForPlugin(const KPluginMetaData &plugin) const;
 };
 
-#endif
\ No newline at end of file
+#endif



More information about the rkward-tracker mailing list