[rkward/work/kateintegration] rkward: Add show/hide actions for all plugin tool windows, too.

Thomas Friedrichsmeier null at kde.org
Wed Jan 15 10:19:20 GMT 2020


Git commit 1be68638d8836f564448bf2087c76da5a83db981 by Thomas Friedrichsmeier.
Committed on 15/01/2020 at 10:19.
Pushed by tfry into branch 'work/kateintegration'.

Add show/hide actions for all plugin tool windows, too.

M  +5    -2    rkward/rkward.cpp
M  +2    -1    rkward/windows/katepluginintegration.cpp
M  +32   -10   rkward/windows/rktoplevelwindowgui.cpp
M  +2    -1    rkward/windows/rktoplevelwindowgui.h
M  +3    -10   rkward/windows/rktoplevelwindowgui.rc

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

diff --git a/rkward/rkward.cpp b/rkward/rkward.cpp
index 58db192e..be3b2a07 100644
--- a/rkward/rkward.cpp
+++ b/rkward/rkward.cpp
@@ -159,10 +159,13 @@ RKWardMainWindow::RKWardMainWindow () : KParts::MainWindow ((QWidget *)0, (Qt::W
 	katePluginIntegration ()->loadPlugin ("katesearchplugin");
 	katePluginIntegration ()->loadPlugin ("kateprojectplugin");
 	katePluginIntegration ()->loadPlugin ("katesnippetsplugin");
-	// This is pretty silly, but while loading plugins the katePluginIntegration-client may gain new actions and thus needs
-	// to be reloaded. We cannot - currently, KF5.65 - delay loading it, because plugins rely on it having a GUI factory.
+	// 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 ());
+	toplevel_actions->initToolWindowActions ();
+	factory()->removeClient (toplevel_actions);
+	factory()->addClient (toplevel_actions);
 	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 a8fdf0a9..6dfb2234 100644
--- a/rkward/windows/katepluginintegration.cpp
+++ b/rkward/windows/katepluginintegration.cpp
@@ -31,6 +31,7 @@
 #include <KSharedConfig>
 #include <KConfigGroup>
 #include <KXMLGUIFactory>
+#include <KLocalizedString>
 
 #include "../rkward.h"
 #include "rkworkplace.h"
@@ -467,7 +468,7 @@ 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");
+			window->setCaption(i18nc("Tab title", "Search in Scripts"));
 			RKCommonFunctions::removeContainers(client, QStringList() << "search_in_files", true);
 		}
 	}
diff --git a/rkward/windows/rktoplevelwindowgui.cpp b/rkward/windows/rktoplevelwindowgui.cpp
index cd36ce5b..94a715a4 100644
--- a/rkward/windows/rktoplevelwindowgui.cpp
+++ b/rkward/windows/rktoplevelwindowgui.cpp
@@ -2,7 +2,7 @@
                           rktoplevelwindowgui  -  description
                              -------------------
     begin                : Tue Apr 24 2007
-    copyright            : (C) 2007, 2009, 2011 by Thomas Friedrichsmeier
+    copyright            : (C) 2007-2020 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -26,6 +26,8 @@
 #include <kshortcutsdialog.h>
 
 #include <QWhatsThis>
+#include <QDomDocument>
+#include <QDomElement>
 
 #include "../rkconsole.h"
 #include "../windows/robjectbrowser.h"
@@ -82,15 +84,7 @@ RKTopLevelWindowGUI::RKTopLevelWindowGUI (KXmlGuiWindow *for_window) : QObject (
 	next_action->setIcon (QIcon (RKCommonFunctions::getRKWardDataDir () + "icons/window_forward.png"));
 	actionCollection ()->setDefaultShortcut (next_action, Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_Tab);
 
-	QAction *action;
-	foreach (const RKToolWindowList::ToolWindowRepresentation& rep, RKToolWindowList::registeredToolWindows ()) {
-		action = actionCollection ()->addAction ("window_show_" + rep.id, this, SLOT (toggleToolView()));
-		action->setText (i18n ("Show/Hide %1", rep.window->shortCaption ()));
-		action->setIcon (rep.window->windowIcon ());
-		actionCollection ()->setDefaultShortcut (action, rep.default_shortcut);
-		action->setProperty ("rk_toolwindow_id", rep.id);
-	}
-	action = actionCollection ()->addAction ("window_activate_docview", this, SLOT(activateDocumentView()));
+	QAction* action = actionCollection ()->addAction ("window_activate_docview", this, SLOT(activateDocumentView()));
 	action->setText (i18n ("Activate Document view"));
 	actionCollection ()->setDefaultShortcut (action, Qt::AltModifier + Qt::Key_0);
 
@@ -107,6 +101,34 @@ RKTopLevelWindowGUI::~RKTopLevelWindowGUI () {
 	RK_TRACE (APP);
 }
 
+void RKTopLevelWindowGUI::initToolWindowActions () {
+	RK_TRACE (APP);
+
+	// Tool window actions
+	QString action_tag ("Action");
+	QString name_attr ("name");
+	QDomDocument doc = xmlguiBuildDocument ();
+	if  (doc.documentElement ().isNull ()) doc = domDocument ();
+	QDomElement menu = doc.elementsByTagName("Menu").at (1).toElement (); // NOTE: this is known to be the "Windows"-Menu
+	QDomElement ref = menu.firstChildElement (action_tag);
+	while (!ref.isNull() && ref.attribute (name_attr) != QLatin1String ("window_show_PLACEHOLDER")) {
+		ref = ref.nextSiblingElement (action_tag);
+	}
+	QAction *action;
+	foreach (const RKToolWindowList::ToolWindowRepresentation& rep, RKToolWindowList::registeredToolWindows ()) {
+		QString id = QLatin1String ("window_show_") + rep.id;
+		action = actionCollection ()->addAction (id, this, SLOT (toggleToolView()));
+		action->setText (i18n ("Show/Hide %1", rep.window->shortCaption ()));
+		action->setIcon (rep.window->windowIcon ());
+		actionCollection ()->setDefaultShortcut (action, rep.default_shortcut);
+		action->setProperty ("rk_toolwindow_id", rep.id);
+		QDomElement e = doc.createElement (action_tag);
+		e.setAttribute (name_attr, id);
+		menu.insertBefore (e, ref);
+	}
+	setXMLGUIBuildDocument (doc);
+}
+
 void RKTopLevelWindowGUI::configureShortcuts () {
 	RK_TRACE (APP);
 
diff --git a/rkward/windows/rktoplevelwindowgui.h b/rkward/windows/rktoplevelwindowgui.h
index d6777469..f0521a9e 100644
--- a/rkward/windows/rktoplevelwindowgui.h
+++ b/rkward/windows/rktoplevelwindowgui.h
@@ -2,7 +2,7 @@
                           rktoplevelwindowgui  -  description
                              -------------------
     begin                : Tue Apr 24 2007
-    copyright            : (C) 2007, 2009, 2011 by Thomas Friedrichsmeier
+    copyright            : (C) 2007-2020 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -32,6 +32,7 @@ class RKTopLevelWindowGUI : public QObject, public KXMLGUIClient {
 public:
 	explicit RKTopLevelWindowGUI (KXmlGuiWindow *for_window);
 	~RKTopLevelWindowGUI ();
+	void initToolWindowActions ();
 public slots:
 	// windows menu
 	/** Raise the help search window */
diff --git a/rkward/windows/rktoplevelwindowgui.rc b/rkward/windows/rktoplevelwindowgui.rc
index fbe116a5..aca6a59a 100644
--- a/rkward/windows/rktoplevelwindowgui.rc
+++ b/rkward/windows/rktoplevelwindowgui.rc
@@ -1,5 +1,5 @@
 <!DOCTYPE kpartgui>
-<kpartgui name="rkward_toplevel" version="610">
+<kpartgui name="rkward_toplevel" version="710">
 	<MenuBar>
 		<Merge/>
 		<Menu name="window"><text>&Window</text>
@@ -10,15 +10,8 @@
 				<Action name="prev_window"/>
 				<Action name="next_window"/>
 				<Separator/>
-				<Action name="window_show_workspace"/>
-				<Action name="window_show_filebrowser"/>
-				<Action name="window_show_commandlog"/>
-				<Action name="window_show_pendingjobs"/>
-				<Action name="window_show_console"/>
-				<Action name="window_show_helpsearch"/>
-				<Action name="window_show_debugconsole"/>
-				<Action name="window_show_debugframes"/>
-				<Action name="window_show_rkdebugmessages"/>
+				<!-- NOTE: Actions for showing / hiding the various tool views are added below this placeholder, dynamically. Since some of those are plugins, their ids cannot be hardcoded, here. -->
+				<Action name="window_show_PLACEHOLDER"/>
 				<Separator/>
 				<Action name="window_activate_docview"/>
 			</Menu>



More information about the rkward-tracker mailing list