[rkward/work/kateintegration] rkward: A few more bits of adjusting plugin UI

Thomas Friedrichsmeier null at kde.org
Tue Jan 14 09:01:31 GMT 2020


Git commit 1f35917bbb5c83ffc56883a1dc3a5c602f6ffbff by Thomas Friedrichsmeier.
Committed on 14/01/2020 at 09:01.
Pushed by tfry into branch 'work/kateintegration'.

A few more bits of adjusting plugin UI

M  +28   -15   rkward/misc/rkcommonfunctions.cpp
M  +2    -2    rkward/misc/rkcommonfunctions.h
M  +3    -2    rkward/windows/katepluginintegration.cpp

https://commits.kde.org/rkward/1f35917bbb5c83ffc56883a1dc3a5c602f6ffbff

diff --git a/rkward/misc/rkcommonfunctions.cpp b/rkward/misc/rkcommonfunctions.cpp
index d65c9241..5df8ec5f 100644
--- a/rkward/misc/rkcommonfunctions.cpp
+++ b/rkward/misc/rkcommonfunctions.cpp
@@ -63,7 +63,16 @@ namespace RKCommonFunctions {
 		}
 	}
 
-	void moveContainer (KXMLGUIClient *client, const QString &tagname, const QString &name, const QString &to_name, bool recursive) {
+	void moveContainer (KXMLGUIClient *client, const QString &tagname, const QString &name, const QString &to_name, bool recursive, bool flatten) {
+		// recurse first
+		if (recursive) {
+			QList<KXMLGUIClient*> children = client->childClients ();
+			QList<KXMLGUIClient*>::const_iterator it;
+			for (it = children.constBegin (); it != children.constEnd (); ++it) {
+				moveContainer (*it, tagname, name, to_name, true);
+			}
+		}
+
 		QDomDocument doc = client->xmlguiBuildDocument ();
 		if  (doc.documentElement ().isNull ()) doc = client->domDocument ();
 	
@@ -73,33 +82,37 @@ namespace RKCommonFunctions {
 		QDomElement from_elem;
 		QDomElement to_elem;
 
-		QDomNodeList list = e.elementsByTagName (tagname);
+		const QString name_attr ("name");
+		const QDomNodeList list = e.elementsByTagName (tagname);
 		int count = list.count ();
 		for (int i = 0; i < count; ++i) {
-			QDomElement elem = list.item (i).toElement ();
+			const QDomElement elem = list.item (i).toElement ();
 			if (elem.isNull ()) continue;
-			if (elem.attribute ("name") == name) {
+			if (elem.attribute (name_attr) == name) {
 				from_elem = elem;
-			} else if (elem.attribute ("name") == to_name) {
+			} else if (elem.attribute (name_attr) == to_name) {
 				to_elem = elem;
 			}
 		}
 
+		if (from_elem.isNull ()) return;
+		if (to_elem.isNull ()) {  // if no place to move to, just rename (Note: children will be moved, below)
+			to_elem = from_elem.cloneNode (false).toElement ();
+			to_elem.setAttribute (name_attr, to_name);
+			from_elem.parentNode().appendChild(to_elem);
+		}
 		// move
 		from_elem.parentNode ().removeChild (from_elem);
-		to_elem.appendChild (from_elem);
+		if (flatten) {
+			while (from_elem.hasChildNodes()) {
+				to_elem.appendChild (from_elem.firstChild());
+			}
+		} else {
+			to_elem.appendChild (from_elem);
+		}
 
 		// set result
 		client->setXMLGUIBuildDocument (doc);
-
-		// recurse
-		if (recursive) {
-			QList<KXMLGUIClient*> children = client->childClients ();
-			QList<KXMLGUIClient*>::const_iterator it;
-			for (it = children.constBegin (); it != children.constEnd (); ++it) {
-				moveContainer (*it, tagname, name, to_name, true);
-			}
-		}
 	}
 
 	QString getCurrentSymbol (const QString &context_line, int cursor_pos, bool strict) {
diff --git a/rkward/misc/rkcommonfunctions.h b/rkward/misc/rkcommonfunctions.h
index 34683fc9..650cd16c 100644
--- a/rkward/misc/rkcommonfunctions.h
+++ b/rkward/misc/rkcommonfunctions.h
@@ -2,7 +2,7 @@
                           rkcommonfunctions  -  description
                              -------------------
     begin                : Mon Oct 17 2005
-    copyright            : (C) 2005, 2006, 2007, 2009, 2010, 2011 by Thomas Friedrichsmeier
+    copyright            : (C) 2005-2020 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -36,7 +36,7 @@ namespace RKCommonFunctions {
 /** remove containers (actions, menus, etc.) with attribute 'name="..."' from KXMLGUIClient from s XML gui, where "..." is any of the strings in names. If recursive, also removes those containers from child clients. */
 	void removeContainers (KXMLGUIClient *from, const QStringList &names, bool recursive);
 /** move container (action, menu, etc.) with tagname "tagname" and attribute 'name="..."' to be a child node of the tag with tagname=tagname and attribute name=to_name. Can be used to make a top-level menu a sub-menu of another menu instead */
-	void moveContainer (KXMLGUIClient *client, const QString &tagname, const QString &name, const QString &to_name, bool recursive);
+	void moveContainer (KXMLGUIClient *client, const QString &tagname, const QString &name, const QString &to_name, bool recursive, bool flatten=false);
 
 /** Get the base directory where RKWard data files are stored */
 	QString getRKWardDataDir ();
diff --git a/rkward/windows/katepluginintegration.cpp b/rkward/windows/katepluginintegration.cpp
index 79f73179..a8fdf0a9 100644
--- a/rkward/windows/katepluginintegration.cpp
+++ b/rkward/windows/katepluginintegration.cpp
@@ -37,6 +37,7 @@
 #include "rkworkplaceview.h"
 #include "rkcommandeditorwindow.h"
 #include "../misc/rkdummypart.h"
+#include "../misc/rkcommonfunctions.h"
 #include "../settings/rksettingsmodulecommandeditor.h"
 
 #include "../debug.h"
@@ -467,9 +468,10 @@ void fixupPluginUI(const QString &id, int num_of_client, KXMLGUIClient* client,
 	if (num_of_client == 0) {
 		if (id == QStringLiteral("katesearchplugin")) {
 			window->setCaption("Search in Scripts");
-			// TODO
+			RKCommonFunctions::removeContainers(client, QStringList() << "search_in_files", true);
 		}
 	}
+	RKCommonFunctions::moveContainer(client, "Menu", "tools", "edit", true, true);
 }
 
 QObject* KatePluginIntegrationWindow::createPluginView(KTextEditor::Plugin* plugin) {
@@ -514,7 +516,6 @@ void KatePluginIntegrationWindow::catchXMLGUIClientsHack(KXMLGUIClient* client)
 
 // TODO: Don't forget to make sure to emit all the signals!
 //       - MainWindow signals
-//       - pluginDeleted
 // TODO: Apply plugin specific hacks as needed (e.g. moving "Tool" menu, removing broken actions)
 // TODO: new RKToplevelWindowGUI should be called after all plugins are loaded (and have registered their tool views). However
 //       that may be a problem, if there is no KXMLGUIFactory around, yet. So, annoyingly, we need to create the GUI, before we



More information about the rkward-tracker mailing list