[rkward] rkward: Actually load / unload kate plugins as configured.

Thomas Friedrichsmeier null at kde.org
Sat Mar 28 09:51:43 GMT 2020


Git commit d0defb6e0595898042f35d80741e56fa9f0d629f by Thomas Friedrichsmeier.
Committed on 28/03/2020 at 09:50.
Pushed by tfry into branch 'master'.

Actually load / unload kate plugins as configured.

M  +2    -3    rkward/rkward.cpp
M  +1    -0    rkward/settings/rksettings.cpp
M  +72   -36   rkward/settings/rksettingsmodulekateplugins.cpp
M  +10   -12   rkward/settings/rksettingsmodulekateplugins.h
M  +23   -14   rkward/windows/katepluginintegration.cpp
M  +1    -0    rkward/windows/katepluginintegration.h

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

diff --git a/rkward/rkward.cpp b/rkward/rkward.cpp
index be3b2a07..bee83621 100644
--- a/rkward/rkward.cpp
+++ b/rkward/rkward.cpp
@@ -55,6 +55,7 @@
 #include "settings/rksettingsmodulegeneral.h"
 #include "settings/rksettingsmoduleoutput.h"
 #include "settings/rksettingsmodulecommandeditor.h"
+#include "settings/rksettingsmodulekateplugins.h"
 #include "rbackend/rkrinterface.h"
 #include "core/robjectlist.h"
 #include "core/renvironmentobject.h"
@@ -156,9 +157,7 @@ RKWardMainWindow::RKWardMainWindow () : KParts::MainWindow ((QWidget *)0, (Qt::W
 	insertChildClient (toplevel_actions = new RKTopLevelWindowGUI (this));
 	insertChildClient (katePluginIntegration ()->mainWindow ());
 	createShellGUI (true);
-	katePluginIntegration ()->loadPlugin ("katesearchplugin");
-	katePluginIntegration ()->loadPlugin ("kateprojectplugin");
-	katePluginIntegration ()->loadPlugin ("katesnippetsplugin");
+	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 ());
diff --git a/rkward/settings/rksettings.cpp b/rkward/settings/rksettings.cpp
index 9270cadc..61d0c771 100644
--- a/rkward/settings/rksettings.cpp
+++ b/rkward/settings/rksettings.cpp
@@ -204,6 +204,7 @@ void RKSettings::enableApply () {
 
 #define FOREACH_SETTINGS_MODULE(X)           \
 	RKSettingsModuleGeneral::X;  /* always handle this first (esp., when loading settings), as it contains the base path for rkward files */ \
+	RKSettingsModuleKatePlugins::X;          \
 	RKSettingsModulePlugins::X;          \
 	RKSettingsModuleR::X;                \
 	RKSettingsModuleRPackages::X;        \
diff --git a/rkward/settings/rksettingsmodulekateplugins.cpp b/rkward/settings/rksettingsmodulekateplugins.cpp
index dd6e105c..b3fb5e55 100644
--- a/rkward/settings/rksettingsmodulekateplugins.cpp
+++ b/rkward/settings/rksettingsmodulekateplugins.cpp
@@ -19,9 +19,12 @@
 
 #include <QTreeWidget>
 #include <QVBoxLayout>
+#include <QLabel>
+
 #include <KPluginMetaData>
 #include <KLocalizedString>
-#include <QLabel>
+#include <KConfigGroup>
+#include <KConfig>
 
 #include "../windows/katepluginintegration.h"
 #include "../misc/rkcommonfunctions.h"
@@ -31,59 +34,92 @@
 
 QStringList RKSettingsModuleKatePlugins::plugins_to_load;
 
-RKSettingsModuleKatePlugins::RKSettingsModuleKatePlugins (RKSettings *gui, QWidget *parent) : RKSettingsModule (gui, parent) {
-	RK_TRACE (SETTINGS);
+RKSettingsModuleKatePlugins::RKSettingsModuleKatePlugins(RKSettings *gui, QWidget *parent) : RKSettingsModule(gui, parent) {
+	RK_TRACE(SETTINGS);
 
-	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.")));
+	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.")));
 
-	plugin_table = new QTreeWidget ();
-	plugin_table->setHeaderLabels (QStringList () << QString () << i18n ("Name") << i18n ("Description"));
-	KatePluginIntegrationApp *pluginapp = RKWardMainWindow::getMain()->katePluginIntegration ();
+	plugin_table = new QTreeWidget();
+	plugin_table->setHeaderLabels(QStringList() << QString() << i18n("Name") << i18n("Description"));
+	KatePluginIntegrationApp *pluginapp = RKWardMainWindow::getMain()->katePluginIntegration();
 	foreach (const QString &key, pluginapp->known_plugins.keys()) {
 		QTreeWidgetItem *item = new QTreeWidgetItem();
-		KPluginMetaData plugindata = pluginapp->known_plugins.value (key).data;
-		item->setData (1, Qt::DisplayRole, plugindata.name ());
-		item->setData (2, Qt::DisplayRole, plugindata.description ());
-		item->setData (1, Qt::DecorationRole, QIcon::fromTheme (plugindata.iconName ()));
-		item->setFlags (Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
-		item->setCheckState (0, plugins_to_load.contains (key) ? Qt::Checked : Qt::Unchecked);
-		plugin_table->addTopLevelItem (item);
+		KPluginMetaData plugindata = pluginapp->known_plugins.value(key).data;
+		item->setData(1, Qt::DisplayRole, plugindata.name());
+		item->setData(2, Qt::DisplayRole, plugindata.description());
+		item->setData(1, Qt::DecorationRole, QIcon::fromTheme(plugindata.iconName()));
+		item->setData(1, Qt::UserRole, key);
+		item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
+		item->setCheckState(0, plugins_to_load.contains(key) ? Qt::Checked : Qt::Unchecked);
+		plugin_table->addTopLevelItem(item);
 	}
-	plugin_table->resizeColumnToContents (0);
-	plugin_table->resizeColumnToContents (1);
-	vbox->addWidget (plugin_table);
-}
+	plugin_table->resizeColumnToContents(0);
+	plugin_table->resizeColumnToContents(1);
+	plugin_table->sortItems(1, Qt::AscendingOrder);
+	vbox->addWidget(plugin_table);
 
-RKSettingsModuleKatePlugins::~RKSettingsModuleKatePlugins () {
-	RK_TRACE (SETTINGS);
+	connect(plugin_table, &QTreeWidget::itemChanged, this, &RKSettingsModuleKatePlugins::change);
 }
 
-void RKSettingsModuleKatePlugins::applyChanges () {
-	RK_TRACE (SETTINGS);
+RKSettingsModuleKatePlugins::~RKSettingsModuleKatePlugins() {
+	RK_TRACE(SETTINGS);
 }
 
-void RKSettingsModuleKatePlugins::save (KConfig *config) {
-	RK_TRACE (SETTINGS);
+void RKSettingsModuleKatePlugins::applyChanges() {
+	RK_TRACE(SETTINGS);
+
+	plugins_to_load.clear();
+	for (int i = plugin_table->topLevelItemCount() - 1; i >= 0; --i) {
+		QTreeWidgetItem *item = plugin_table->topLevelItem(i);
+		if (item->checkState(0) == Qt::Checked) {
+			plugins_to_load.append (item->data(1, Qt::UserRole).toString());
+		}
+	}
+	loadPlugins();
 }
 
-void RKSettingsModuleKatePlugins::saveSettings (KConfig *config) {
-	RK_TRACE (SETTINGS);
+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);
+			}
+		}
+	}
 }
 
-void RKSettingsModuleKatePlugins::loadSettings (KConfig *config) {
-	RK_TRACE (SETTINGS);
+void RKSettingsModuleKatePlugins::save(KConfig *config) {
+	RK_TRACE(SETTINGS);
+
+	saveSettings(config);
 }
 
-QString RKSettingsModuleKatePlugins::caption () {
-	RK_TRACE (SETTINGS);
+void RKSettingsModuleKatePlugins::saveSettings(KConfig *config) {
+	RK_TRACE(SETTINGS);
 
-	return i18n ("Kate Plugins");
+	KConfigGroup cg = config->group("Kate Plugins");
+	cg.writeEntry("Plugins to load", plugins_to_load);
 }
 
-void RKSettingsModuleKatePlugins::settingChanged () {
-	RK_TRACE (SETTINGS);
-	change ();
+void RKSettingsModuleKatePlugins::loadSettings(KConfig *config) {
+	RK_TRACE(SETTINGS);
+
+	KConfigGroup cg = config->group("Kate Plugins");
+	plugins_to_load = cg.readEntry("Plugins to load", QStringList() << "katesearchplugin" << "kateprojectplugin" << "katesnippetsplugin");
 }
 
+QString RKSettingsModuleKatePlugins::caption() {
+	RK_TRACE(SETTINGS);
+
+	return i18n("Kate Plugins");
+}
diff --git a/rkward/settings/rksettingsmodulekateplugins.h b/rkward/settings/rksettingsmodulekateplugins.h
index f9eb51a9..0da4ed8f 100644
--- a/rkward/settings/rksettingsmodulekateplugins.h
+++ b/rkward/settings/rksettingsmodulekateplugins.h
@@ -27,23 +27,21 @@ class QTreeWidget;
 @author Thomas Friedrichsmeier
 */
 class RKSettingsModuleKatePlugins : public RKSettingsModule {
-	Q_OBJECT
 public:
-	RKSettingsModuleKatePlugins (RKSettings *gui, QWidget *parent);
-	~RKSettingsModuleKatePlugins ();
+	RKSettingsModuleKatePlugins(RKSettings *gui, QWidget *parent);
+	~RKSettingsModuleKatePlugins();
 
-	void applyChanges () override;
-	void save (KConfig *config) override;
+	void applyChanges() override;
+	void save(KConfig *config) override;
 
-	static void saveSettings (KConfig *config);
-	static void loadSettings (KConfig *config);
-	static void validateSettingsInteractive (QList<RKSettingsWizardPage*>*) {};
+	static void saveSettings(KConfig *config);
+	static void loadSettings(KConfig *config);
+	static void validateSettingsInteractive(QList<RKSettingsWizardPage*>*) {};
 
-	QString caption () override;
+	QString caption() override;
 
-	static QStringList pluginsToLoad () { return plugins_to_load; };
-public slots:
-	void settingChanged ();
+	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 58685681..79659a4d 100644
--- a/rkward/windows/katepluginintegration.cpp
+++ b/rkward/windows/katepluginintegration.cpp
@@ -129,24 +129,33 @@ QObject* KatePluginIntegrationApp::loadPlugin (const QString& identifier) {
     return 0;
 }
 
+void KatePluginIntegrationApp::unloadPlugin(const QString &identifier) {
+	RK_TRACE (APP);
+
+	if (!known_plugins.contains(identifier)) return;
+	PluginInfo &info = known_plugins[identifier];
+	if (!info.plugin) return;
+
+	QObject* view = mainWindow()->pluginView(identifier);
+	if (view) {
+		KTextEditor::SessionConfigInterface* interface = qobject_cast<KTextEditor::SessionConfigInterface *>(view);
+		if (interface) {
+			KConfigGroup group = KSharedConfig::openConfig()->group(QStringLiteral("KatePlugin:%1:").arg(identifier));
+			interface->writeSessionConfig(group);
+		}
+		emit mainWindow()->main->pluginViewDeleted(identifier, view);
+		delete view;
+	}
+	emit app->pluginDeleted(identifier, info.plugin);
+	delete info.plugin;
+	info.plugin = 0;
+}
+
 void KatePluginIntegrationApp::saveConfigAndUnload() {
 	RK_TRACE (APP);
 
 	for (auto it = known_plugins.constBegin(); it != known_plugins.constEnd(); ++it) {
-		KTextEditor::Plugin* plugin = it.value().plugin;
-		if (!plugin) continue;
-		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;
+		unloadPlugin (it.key());
 	}
 	known_plugins.clear();
 }
diff --git a/rkward/windows/katepluginintegration.h b/rkward/windows/katepluginintegration.h
index aa948dfb..65d77185 100644
--- a/rkward/windows/katepluginintegration.h
+++ b/rkward/windows/katepluginintegration.h
@@ -39,6 +39,7 @@ public:
 	KatePluginIntegrationApp(QObject *parent);
 	~KatePluginIntegrationApp();
 	QObject* loadPlugin(const QString& identifier);
+	void unloadPlugin(const QString& identifier);
 	KatePluginIntegrationWindow *mainWindow() const { return window; };
 private slots:
 friend class KatePluginIntegrationWindow;



More information about the rkward-tracker mailing list