[rkward/work/kateintegration] rkward: Clean up plugins before exit, and emit some more signals.

Thomas Friedrichsmeier null at kde.org
Fri Jan 10 09:17:44 GMT 2020


Git commit e9952a83f4ba9b85ba576447a3a8d4426f159190 by Thomas Friedrichsmeier.
Committed on 10/01/2020 at 09:17.
Pushed by tfry into branch 'work/kateintegration'.

Clean up plugins before exit, and emit some more signals.

M  +1    -0    rkward/rkward.cpp
M  +27   -13   rkward/windows/katepluginintegration.cpp
M  +2    -2    rkward/windows/katepluginintegration.h

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

diff --git a/rkward/rkward.cpp b/rkward/rkward.cpp
index c0326fd0..bdfe9249 100644
--- a/rkward/rkward.cpp
+++ b/rkward/rkward.cpp
@@ -157,6 +157,7 @@ RKWardMainWindow::RKWardMainWindow () : KParts::MainWindow ((QWidget *)0, (Qt::W
 	insertChildClient (katePluginIntegration ()->mainWindow ());
 	createShellGUI (true);
 	katePluginIntegration ()->loadPlugin ("katesearchplugin");
+	katePluginIntegration ()->loadPlugin ("katesnippetsplugin");
 	RKXMLGUISyncer::self ()->watchXMLGUIClientUIrc (this);
 
 	// replicate File->import and export menus into the Open/Save toolbar button menus
diff --git a/rkward/windows/katepluginintegration.cpp b/rkward/windows/katepluginintegration.cpp
index 1b467dc9..340f908a 100644
--- a/rkward/windows/katepluginintegration.cpp
+++ b/rkward/windows/katepluginintegration.cpp
@@ -62,6 +62,8 @@ KatePluginIntegrationApp::KatePluginIntegrationApp(QObject *parent) : QObject (p
 		// TODO: remove me
 		qDebug ("%s", qPrintable(info.data.fileName()));
 	}
+	// NOTE: Destructor is too late for this, esp. As plugin destructors will try to unregister from the guiFactory(), and such.
+	connect(RKWardMainWindow::getMain(), &RKWardMainWindow::aboutToQuitRKWard, this, &KatePluginIntegrationApp::saveConfigAndUnload);
 }
 
 KatePluginIntegrationApp::~KatePluginIntegrationApp() {
@@ -98,9 +100,9 @@ QObject* KatePluginIntegrationApp::loadPlugin (const QString& identifier) {
 		if (plugin) {
 			known_plugins[identifier].plugin = plugin;
 			emit KTextEditor::Editor::instance()->application()->pluginCreated(identifier, plugin);
-			mainWindow()->createPluginView(plugin);
-			QObject* created = mainWindow()->pluginView(identifier);
+			QObject* created = mainWindow()->createPluginView(plugin);
 			if (created) {
+				emit mainWindow()->main->pluginViewCreated(identifier, created);
 				KTextEditor::SessionConfigInterface *interface = qobject_cast<KTextEditor::SessionConfigInterface *>(created);
 				if (interface) {
 					// NOTE: Some plugins (noteably the Search in files plugin) will misbehave, unless readSessionConfig has been called!
@@ -115,17 +117,26 @@ QObject* KatePluginIntegrationApp::loadPlugin (const QString& identifier) {
     return 0;
 }
 
-void KatePluginIntegrationApp::savePluginConfig() {
+void KatePluginIntegrationApp::saveConfigAndUnload() {
 	RK_TRACE (APP);
 
-	for (auto it = known_plugins.constBegin(); it !=  known_plugins.constEnd(); ++it) {
+	for (auto it = known_plugins.constBegin(); it != known_plugins.constEnd(); ++it) {
 		KTextEditor::Plugin* plugin = it.value().plugin;
 		if (!plugin) continue;
-		KTextEditor::SessionConfigInterface * interface = qobject_cast<KTextEditor::SessionConfigInterface *>(mainWindow()->pluginView(it.key()));
-		if (!interface) continue;
-		KConfigGroup group = KSharedConfig::openConfig()->group(QStringLiteral("KatePlugin:%1:").arg(it.key()));
-		interface->writeSessionConfig(group);
+		QObject* view = mainWindow()->pluginView(it.key());
+		if (view) {
+			KTextEditor::SessionConfigInterface* interface = qobject_cast<KTextEditor::SessionConfigInterface *>(view);
+			if (interface) {
+				KConfigGroup group = KSharedConfig::openConfig()->group(QStringLiteral("KatePlugin:%1:").arg(it.key()));
+				interface->writeSessionConfig(group);
+			}
+			emit mainWindow()->main->pluginViewDeleted(it.key(), view);
+			delete view;
+		}
+		emit app->pluginDeleted(it.key(), plugin);
+		delete plugin;
 	}
+	known_plugins.clear();
 }
 
 QList<KTextEditor::MainWindow *> KatePluginIntegrationApp::mainWindows() {
@@ -350,13 +361,15 @@ KTextEditor::View *KatePluginIntegrationWindow::activeView() {
 	if (w && w->isType (RKMDIWindow::CommandEditorWindow)) {
 		return static_cast<RKCommandEditorWindow*>(w)->getView();
 	}
-	// NOTE: It looks like some plugins assume this cannot return 0. That's a bug in the plugin, but still one that could
-	//       be quite prevalent, as in kate, that assumption holds. So, to be safe, we create a dummy window on the fly.
+	// NOTE: As far as RKWard is concerned, the active window will most likely be the tool window at this point, while the
+	//       intention will be to get an active window that the tool should operate on. So get the last used window from
+	//       history. (Another option would be to check which window is on top in the view area, but this will be difficult
+	//       for split views.
 	RKMDIWindow* candidate =  RKWorkplace::getHistory()->previousDocumentWindow();
 	if (candidate && candidate->isType(RKMDIWindow::CommandEditorWindow)) return static_cast<RKCommandEditorWindow*>(candidate)->getView();
+	// NOTE: It looks like some plugins assume this cannot return 0. That's a bug in the plugin, but still one that could
+	//       be quite prevalent, as in kate, that assumption holds. So, to be safe, we create a dummy window on the fly.
 	return app->dummyView();
-	// TODO: This probably isn't right: As far as RKWard is concerned, the active window will most likely be the tool window
-	//       at this point, while the intention will be to get an active window that the tool should operate on.
 }
 
 KTextEditor::View *KatePluginIntegrationWindow::activateView(KTextEditor::Document *document) {
@@ -445,12 +458,13 @@ bool KatePluginIntegrationWindow::viewsInSameSplitView(KTextEditor::View* view1,
 	return false;
 }
 
-void KatePluginIntegrationWindow::createPluginView(KTextEditor::Plugin* plugin) {
+QObject* KatePluginIntegrationWindow::createPluginView(KTextEditor::Plugin* plugin) {
 	RK_TRACE (APP);
 
 	QObject *view = plugin->createView(main);
 	plugin_views.insert(plugin, view);
 	connect(plugin, &QObject::destroyed, [&]() { plugin_views.remove(plugin); });
+	return view;
 }
 
 // TODO: Don't forget to make sure to emit all the signals!
diff --git a/rkward/windows/katepluginintegration.h b/rkward/windows/katepluginintegration.h
index 4fb96724..4b706b5b 100644
--- a/rkward/windows/katepluginintegration.h
+++ b/rkward/windows/katepluginintegration.h
@@ -41,7 +41,7 @@ public:
 	KatePluginIntegrationWindow *mainWindow() const { return window; };
 private slots:
 friend class KatePluginIntegrationWindow;
-	void savePluginConfig();
+	void saveConfigAndUnload();
 	// 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();
@@ -100,7 +100,7 @@ private slots:
 private:
 friend class KatePluginIntegrationApp;
 	KTextEditor::MainWindow *main;
-	void createPluginView(KTextEditor::Plugin* plugin);
+	QObject* createPluginView(KTextEditor::Plugin* plugin);
 	QHash<KTextEditor::Plugin*, QObject*> plugin_views;
 
 	KatePluginIntegrationApp *app;



More information about the rkward-tracker mailing list