[education/rkward/devel/workspace_output] rkward/windows: Add UI to switch between registered output windows.

Thomas Friedrichsmeier null at kde.org
Thu Mar 3 20:58:43 GMT 2022


Git commit bda03cafbf65abe9b3c5eeb60a3f4f325bff35c0 by Thomas Friedrichsmeier.
Committed on 03/03/2022 at 20:58.
Pushed by tfry into branch 'devel/workspace_output'.

Add UI to switch between registered output windows.

M  +30   -5    rkward/windows/rktoplevelwindowgui.cpp
M  +6    -3    rkward/windows/rktoplevelwindowgui.h

https://invent.kde.org/education/rkward/commit/bda03cafbf65abe9b3c5eeb60a3f4f325bff35c0

diff --git a/rkward/windows/rktoplevelwindowgui.cpp b/rkward/windows/rktoplevelwindowgui.cpp
index d8b834aa..39cbb479 100644
--- a/rkward/windows/rktoplevelwindowgui.cpp
+++ b/rkward/windows/rktoplevelwindowgui.cpp
@@ -29,6 +29,7 @@
 #include <QWhatsThis>
 #include <QDomDocument>
 #include <QDomElement>
+#include <QMenu>
 
 #include "../rkconsole.h"
 #include "../windows/robjectbrowser.h"
@@ -43,6 +44,7 @@
 #include "../misc/rkstandardicons.h"
 #include "../misc/rkprogresscontrol.h"
 #include "../misc/rkcommonfunctions.h"
+#include "../misc/rkoutputdirectory.h"
 #include "../plugin/rkcomponentmap.h"
 #include "../dialogs/rkerrordialog.h"
 #include "../rbackend/rkrinterface.h"
@@ -90,9 +92,12 @@ RKTopLevelWindowGUI::RKTopLevelWindowGUI(KXmlGuiWindow *for_window) : QObject(fo
 	action->setText (i18n ("Activate Document view"));
 	actionCollection ()->setDefaultShortcut (action, Qt::AltModifier + Qt::Key_0);
 
-	action = actionCollection ()->addAction ("output_show", this, SLOT (slotOutputShow()));
-	action->setText (i18n ("Show &Output"));
-	action->setIcon (RKStandardIcons::getIcon (RKStandardIcons::WindowOutput));
+	action = new QAction(i18n("Show Output"));
+	action->setMenu(output_windows_menu = new QMenu());
+	connect(output_windows_menu, &QMenu::aboutToShow, this, &RKTopLevelWindowGUI::populateOutputWindowsMenu);
+	connect(output_windows_menu, &QMenu::triggered, this, &RKTopLevelWindowGUI::slotOutputShow);
+	action->setIcon(RKStandardIcons::getIcon(RKStandardIcons::WindowOutput));
+	actionCollection()->addAction("output_show", action);
 
 	// settings
 	KStandardAction::keyBindings (this, SLOT (configureShortcuts()), actionCollection ());
@@ -226,10 +231,30 @@ void RKTopLevelWindowGUI::activateDocumentView () {
 	if (window) window->activate ();
 }
 
-void RKTopLevelWindowGUI::slotOutputShow () {
+void RKTopLevelWindowGUI::slotOutputShow(QAction *action) {
 	RK_TRACE(APP);
 
-	RKWorkplace::mainWorkplace()->openOutputWindow(QUrl());
+	QString id = action->data().toString();
+	RKOutputDirectory *dir = RKOutputDirectory::findOutputById(id);
+	if (!dir) return; // Could happen in corner case, if dir got deleted, while menu is shown
+	dir->view(true);
+}
+
+void RKTopLevelWindowGUI::populateOutputWindowsMenu() {
+	RK_TRACE(APP);
+
+	output_windows_menu->clear();
+	auto outputs = RKOutputDirectory::allOutputs();
+	for (int i = 0; i < outputs.size(); ++i) {
+		auto dir = outputs[i];
+		QString title = dir->caption();
+		if (dir->isActive()) {
+			title.append(' ');
+			title.append(i18n("[Active]"));
+		}
+		QAction* action = output_windows_menu->addAction(title);
+		action->setData(dir->getId());
+	}
 }
 
 void RKTopLevelWindowGUI::nextWindow () {
diff --git a/rkward/windows/rktoplevelwindowgui.h b/rkward/windows/rktoplevelwindowgui.h
index 7691b837..259fe62d 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-2020 by Thomas Friedrichsmeier
+    copyright            : (C) 2007-2022 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -26,6 +26,7 @@ class KXmlGuiWindow;
 class RKMDIWindow;
 class QAction;
 class KHelpMenu;
+class QMenu;
 
 /** represents the common portions of the GUI for top level windows: The help menu, and the windows menu */
 class RKTopLevelWindowGUI : public QObject, public KXMLGUIClient {
@@ -40,8 +41,9 @@ public slots:
 	void showHelpSearch ();
 	/** Activate the current (non tools) window in the workspace */
 	void activateDocumentView ();
-	/** ensure output window is shown. */
-	void slotOutputShow ();
+	/** Show an output window */
+	void slotOutputShow(QAction *action);
+	void populateOutputWindowsMenu();
 
 	// help menu
 	/** Show the starting page of RKWard help */
@@ -72,6 +74,7 @@ private:
 	QAction *next_action;
 	void toggleToolView (RKMDIWindow *tool_window);
 	KHelpMenu *help_menu_dummy;
+	QMenu* output_windows_menu;
 };
 
 #endif


More information about the rkward-tracker mailing list