[rkward] /: Reload UI after loading / unloading kate plugins.

Thomas Friedrichsmeier null at kde.org
Sat Mar 28 10:28:25 GMT 2020


Git commit 88a2ed0660490efbe390e61b8e9f4032d4407a3a by Thomas Friedrichsmeier.
Committed on 28/03/2020 at 10:28.
Pushed by tfry into branch 'master'.

Reload UI after loading / unloading kate plugins.

M  +3    -1    ChangeLog
M  +1    -3    rkward/rkward.cpp
M  +2    -20   rkward/settings/rksettingsmodulekateplugins.cpp
M  +0    -1    rkward/settings/rksettingsmodulekateplugins.h
M  +25   -1    rkward/windows/katepluginintegration.cpp
M  +2    -0    rkward/windows/katepluginintegration.h

https://commits.kde.org/rkward/88a2ed0660490efbe390e61b8e9f4032d4407a3a

diff --git a/ChangeLog b/ChangeLog
index 2aca6b11..7895895a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,7 +3,9 @@
 * TODO: Bring new code hinting features to the console window!
 - On unix-systems, RKWard can now be run without installation
 - Kate addons are now supported within RKWard. Intially, search-in-files, snippets, and projects are loaded by default
-  * TODO: Allow to configure which (additional) plugins get loaded
+  * TODO: Some plugins still have UI issues. E.g.:
+    - SQL plugin fails to add toplevel menu
+    - Text filter plugin always shows menu entry, but should be limited to script windows
 
 --- Version 0.7.1 - Jan-23-2020
 - Code hinting in script editor windows has been reworked, and now also completes argument names
diff --git a/rkward/rkward.cpp b/rkward/rkward.cpp
index bee83621..86d02d45 100644
--- a/rkward/rkward.cpp
+++ b/rkward/rkward.cpp
@@ -157,11 +157,9 @@ RKWardMainWindow::RKWardMainWindow () : KParts::MainWindow ((QWidget *)0, (Qt::W
 	insertChildClient (toplevel_actions = new RKTopLevelWindowGUI (this));
 	insertChildClient (katePluginIntegration ()->mainWindow ());
 	createShellGUI (true);
-	RKSettingsModuleKatePlugins::loadPlugins ();
 	// This is pretty convoluted, but while loading plugins the katePluginIntegration-client may gain new actions and thus needs
 	// to be reloaded. We cannot - currently, KF5.65 - delay loading the UI defintion(s), because plugins rely on it having a GUI factory.
-	factory()->removeClient (katePluginIntegration ()->mainWindow ());
-	factory()->addClient (katePluginIntegration ()->mainWindow ());
+	katePluginIntegration ()->loadPlugins (RKSettingsModuleKatePlugins::pluginsToLoad ());
 	toplevel_actions->initToolWindowActions ();
 	factory()->removeClient (toplevel_actions);
 	factory()->addClient (toplevel_actions);
diff --git a/rkward/settings/rksettingsmodulekateplugins.cpp b/rkward/settings/rksettingsmodulekateplugins.cpp
index b3fb5e55..81ab1340 100644
--- a/rkward/settings/rksettingsmodulekateplugins.cpp
+++ b/rkward/settings/rksettingsmodulekateplugins.cpp
@@ -39,7 +39,7 @@ RKSettingsModuleKatePlugins::RKSettingsModuleKatePlugins(RKSettings *gui, QWidge
 
 	QVBoxLayout *vbox = new QVBoxLayout(this);
 	vbox->setContentsMargins(0, 0, 0, 0);
-	vbox->addWidget(RKCommonFunctions::wordWrappedLabel(i18n("Kate plugins to load in RKWard. Note that some loaded plugins will not become visible until certain conditions are met, e.g. you are loading a version controlled file for the <i>Project</i> plugin. Also, not all plugins listed here may make much sense in the context of RKWard.")));
+	vbox->addWidget(RKCommonFunctions::wordWrappedLabel(i18n("Kate plugins to load in RKWard. Note that some loaded plugins will not become visible until certain conditions are met, e.g. you are loading a version controlled file for the <i>Project</i> plugin. Also, many of the plugins listed here do not make a whole lot of sense in the context of RKWard.")));
 
 	plugin_table = new QTreeWidget();
 	plugin_table->setHeaderLabels(QStringList() << QString() << i18n("Name") << i18n("Description"));
@@ -77,25 +77,7 @@ void RKSettingsModuleKatePlugins::applyChanges() {
 			plugins_to_load.append (item->data(1, Qt::UserRole).toString());
 		}
 	}
-	loadPlugins();
-}
-
-void RKSettingsModuleKatePlugins::loadPlugins() {
-	RK_TRACE(SETTINGS);
-
-	KatePluginIntegrationApp *pluginapp = RKWardMainWindow::getMain()->katePluginIntegration();
-	foreach (const QString &key, pluginapp->known_plugins.keys()) {
-		auto info = pluginapp->known_plugins.value(key);
-		if (plugins_to_load.contains(key)) {
-			if (!info.plugin) {
-				pluginapp->loadPlugin(key);
-			}
-		} else {
-			if (info.plugin) {
-				pluginapp->unloadPlugin(key);
-			}
-		}
-	}
+	RKWardMainWindow::getMain()->katePluginIntegration()->loadPlugins(plugins_to_load);
 }
 
 void RKSettingsModuleKatePlugins::save(KConfig *config) {
diff --git a/rkward/settings/rksettingsmodulekateplugins.h b/rkward/settings/rksettingsmodulekateplugins.h
index 0da4ed8f..d1e454e3 100644
--- a/rkward/settings/rksettingsmodulekateplugins.h
+++ b/rkward/settings/rksettingsmodulekateplugins.h
@@ -41,7 +41,6 @@ public:
 	QString caption() override;
 
 	static QStringList pluginsToLoad() { return plugins_to_load; };
-	static void loadPlugins();
 private:
 	QTreeWidget *plugin_table;
 
diff --git a/rkward/windows/katepluginintegration.cpp b/rkward/windows/katepluginintegration.cpp
index 79659a4d..b8f38c08 100644
--- a/rkward/windows/katepluginintegration.cpp
+++ b/rkward/windows/katepluginintegration.cpp
@@ -129,6 +129,30 @@ QObject* KatePluginIntegrationApp::loadPlugin (const QString& identifier) {
     return 0;
 }
 
+void KatePluginIntegrationApp::loadPlugins(const QStringList& plugins) {
+	RK_TRACE (APP);
+
+	bool changes = false;
+	foreach (const QString &key, known_plugins.keys()) {
+		auto info = known_plugins.value(key);
+		if (plugins.contains(key)) {
+			if (!info.plugin) {
+				loadPlugin(key);
+				changes = true;
+			}
+		} else {
+			if (info.plugin) {
+				unloadPlugin(key);
+				changes = true;
+			}
+		}
+	}
+
+	if (!changes) return;
+	RKWardMainWindow::getMain()->factory()->removeClient(mainWindow());
+	RKWardMainWindow::getMain()->factory()->addClient(mainWindow());
+}
+
 void KatePluginIntegrationApp::unloadPlugin(const QString &identifier) {
 	RK_TRACE (APP);
 
@@ -536,7 +560,7 @@ QObject* KatePluginIntegrationWindow::createPluginView(KTextEditor::Plugin* plug
 	RK_TRACE (APP);
 
 	// HACK: Currently, plugins will add themselves to the main window's UI, without asking. We don't want that, as
-	//       our MDI windows are enabled / disabled on activation. To hack around this, the catch the added clients,
+	//       our MDI windows are enabled / disabled on activation. To hack around this, we catch the added clients,
 	//       and put them, where they belong.
 	connect(factory(), &KXMLGUIFactory::clientAdded, this, &KatePluginIntegrationWindow::catchXMLGUIClientsHack);
 	active_plugin = plugin;
diff --git a/rkward/windows/katepluginintegration.h b/rkward/windows/katepluginintegration.h
index 65d77185..b50b89f8 100644
--- a/rkward/windows/katepluginintegration.h
+++ b/rkward/windows/katepluginintegration.h
@@ -39,7 +39,9 @@ public:
 	KatePluginIntegrationApp(QObject *parent);
 	~KatePluginIntegrationApp();
 	QObject* loadPlugin(const QString& identifier);
+	/** Loads the given plugins, *and* unloads all others. */
 	void unloadPlugin(const QString& identifier);
+	void loadPlugins(const QStringList &plugins);
 	KatePluginIntegrationWindow *mainWindow() const { return window; };
 private slots:
 friend class KatePluginIntegrationWindow;



More information about the rkward-tracker mailing list