[education/rkward/add_kate_plugin_wrappers] rkward/windows: Add - basic - implementation for new Kate plugin methods

Thomas Friedrichsmeier null at kde.org
Sun May 7 12:37:09 BST 2023


Git commit 46adfd2c41e941092636f74f33ec5bb71a1b19df by Thomas Friedrichsmeier.
Committed on 07/05/2023 at 11:36.
Pushed by tfry into branch 'add_kate_plugin_wrappers'.

Add - basic - implementation for new Kate plugin methods

M  +39   -5    rkward/windows/katepluginintegration.cpp
M  +7    -1    rkward/windows/katepluginintegration.h
M  +25   -1    rkward/windows/rkcommandlog.cpp
M  +3    -1    rkward/windows/rkcommandlog.h

https://invent.kde.org/education/rkward/commit/46adfd2c41e941092636f74f33ec5bb71a1b19df

diff --git a/rkward/windows/katepluginintegration.cpp b/rkward/windows/katepluginintegration.cpp
index b7de51636..eb46622fb 100644
--- a/rkward/windows/katepluginintegration.cpp
+++ b/rkward/windows/katepluginintegration.cpp
@@ -1,6 +1,6 @@
 /*
 katepluginintegration - This file is part of RKWard (https://rkward.kde.org). Created: Mon Jun 12 2017
-SPDX-FileCopyrightText: 2017-2020 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
+SPDX-FileCopyrightText: 2017-2023 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
 SPDX-FileContributor: The RKWard Team <rkward-devel at kde.org>
 SPDX-License-Identifier: GPL-2.0-or-later
 */
@@ -12,6 +12,7 @@ SPDX-License-Identifier: GPL-2.0-or-later
 #include <QVBoxLayout>
 #include <QChildEvent>
 #include <QComboBox>
+#include <QStatusBar>
 
 #include <KPluginFactory>
 #include <KPluginLoader>
@@ -339,10 +340,10 @@ KatePluginIntegrationWindow::~KatePluginIntegrationWindow() {
 }
 
 
-class KatePluginToolWindow : public RKMDIWindow {
+class KatePluginWindow : public RKMDIWindow {
 	Q_OBJECT
 public:
-	KatePluginToolWindow(QWidget *parent) : RKMDIWindow(parent, RKMDIWindow::KatePluginWindow, true) {
+	KatePluginWindow(QWidget *parent, bool tool_window=true) : RKMDIWindow(parent, RKMDIWindow::KatePluginWindow, tool_window) {
 		RK_TRACE (APP);
 
 		QVBoxLayout *layout = new QVBoxLayout(this);
@@ -351,7 +352,7 @@ public:
 		initializeActivationSignals();
 		setFocusPolicy(Qt::ClickFocus);
 	}
-	~KatePluginToolWindow() {
+	~KatePluginWindow() {
 		RK_TRACE (APP);
 	}
 
@@ -386,7 +387,7 @@ QWidget* KatePluginIntegrationWindow::createToolView (KTextEditor::Plugin *plugi
 
 	RK_DEBUG(APP, DL_DEBUG, "createToolView for %p, %s, position %d, %s", plugin, qPrintable(identifier), pos, qPrintable(text));
 	// TODO: Set proper RKMDIWindow:type
-	KatePluginToolWindow *window = new KatePluginToolWindow(RKWorkplace::mainWorkplace()->view());
+	KatePluginWindow *window = new KatePluginWindow(RKWorkplace::mainWorkplace()->view(), true);
 	window->setCaption(text);
 	window->setWindowIcon(icon);
 	RKToolWindowList::registerToolWindow(window, identifier, (RKToolWindowList::Placement) pos, 0);
@@ -408,6 +409,39 @@ bool KatePluginIntegrationWindow::showToolView (QWidget *widget) {
 	return true;
 }
 
+QWidget *KatePluginIntegrationWindow::toolviewForName(const QString &toolviewName) {
+	RK_TRACE(APP);
+	return RKToolWindowList::findToolWindowById(toolviewName);
+}
+
+void KatePluginIntegrationWindow::addWidget(QWidget *widget) {
+	RK_TRACE(APP);
+
+	RK_DEBUG(APP, DL_DEBUG, "addWidget %p: %s", widget, qPrintable(widget->windowTitle()));
+	// TODO: Set proper RKMDIWindow:type
+	KatePluginWindow *window = new KatePluginWindow(RKWorkplace::mainWorkplace()->view(), false);
+	widget->setParent(window);
+	window->setCaption(widget->windowTitle());
+	widget->show();
+	RKWorkplace::mainWorkplace()->addWindow(window);
+}
+
+#include "../rbackend/rcommand.h"
+#include "rkcommandlog.h"
+void KatePluginIntegrationWindow::showMessage(const QVariantMap &map) {
+	RK_TRACE(APP);
+
+	ROutput::ROutputType severity = ROutput::Output;
+	auto type = map["type"].toString();
+	if (type == QStringLiteral("Error")) severity = ROutput::Error;
+	else if (type == QStringLiteral("Warning")) severity = ROutput::Warning;
+	RKCommandLog::getLog()->addOtherMessage(map["text"].toString(), map["categoryicon"].value<QIcon>(), severity);
+}
+
+void KatePluginIntegrationWindow::insertWidgetInStatusbar(QWidget *widget) {
+	RKWorkplace::mainWorkplace()->statusBar()->insertWidget(0, widget);
+}
+
 KXMLGUIFactory *KatePluginIntegrationWindow::guiFactory () {
 	RK_TRACE (APP);
 
diff --git a/rkward/windows/katepluginintegration.h b/rkward/windows/katepluginintegration.h
index 8222fc36e..66cb2316e 100644
--- a/rkward/windows/katepluginintegration.h
+++ b/rkward/windows/katepluginintegration.h
@@ -1,6 +1,6 @@
 /*
 katepluginintegration - This file is part of the RKWard project. Created: Mon Jun 12 2017
-SPDX-FileCopyrightText: 2017-2020 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
+SPDX-FileCopyrightText: 2017-2023 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
 SPDX-FileContributor: The RKWard Team <rkward-devel at kde.org>
 SPDX-License-Identifier: GPL-2.0-or-later
 */
@@ -97,6 +97,12 @@ private slots:
 	void showViewBar(KTextEditor::View *view);
 	void hideViewBar(KTextEditor::View *view);
 	void addWidgetToViewBar(KTextEditor::View *view, QWidget *bar); */
+
+// New in Kate 2023-07, not yet formalized in KTextEditor
+	QWidget *toolviewForName(const QString &toolviewName);
+	void showMessage(const QVariantMap &map);
+	void addWidget(QWidget *widget);
+	void insertWidgetInStatusbar(QWidget *widget);
 private:
 friend class KatePluginIntegrationApp;
 	KTextEditor::MainWindow *main;
diff --git a/rkward/windows/rkcommandlog.cpp b/rkward/windows/rkcommandlog.cpp
index 18fada68b..04af68d29 100644
--- a/rkward/windows/rkcommandlog.cpp
+++ b/rkward/windows/rkcommandlog.cpp
@@ -1,6 +1,6 @@
 /*
 rkcommandlog - This file is part of RKWard (https://rkward.kde.org). Created: Sun Nov 3 2002
-SPDX-FileCopyrightText: 2002-2010 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
+SPDX-FileCopyrightText: 2002-2023 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
 SPDX-FileContributor: The RKWard Team <rkward-devel at kde.org>
 SPDX-License-Identifier: GPL-2.0-or-later
 */
@@ -73,6 +73,30 @@ void RKCommandLog::addInput (RCommand *command) {
 	addInputNoCheck (command);
 }
 
+void RKCommandLog::addOtherMessage(const QString &message, const QIcon &icon, ROutput::ROutputType severity) {
+	RK_TRACE(APP);
+
+	if (!icon.isNull()) {
+		auto doc = log_view->document();
+		QUrl uri = QUrl(QString("internalicon://%1.png").arg(icon.name()));
+		doc->addResource(QTextDocument::ImageResource, uri, QVariant(icon.pixmap(16,16)));
+		QTextImageFormat f;
+		f.setWidth(16);
+		f.setHeight(16);
+		f.setName(uri.toString());;
+		log_view->textCursor().insertImage(f);
+	}
+
+	if (severity != ROutput::Output) {
+		QTextBlockFormat f;
+		f.setBackground(QBrush(QColor(255, 255, 255)));
+		log_view->textCursor().mergeBlockFormat(f);
+	}
+	log_view->insertPlainText(message + '\n');
+	log_view->setFontWeight(QFont::Normal);
+	log_view->setTextColor(Qt::black);
+}
+
 void RKCommandLog::addInputNoCheck (RCommand *command) {
 	RK_TRACE (APP);
 	if (command_input_shown.contains (command)) return;		// already shown
diff --git a/rkward/windows/rkcommandlog.h b/rkward/windows/rkcommandlog.h
index 32e415ef4..dba234ebd 100644
--- a/rkward/windows/rkcommandlog.h
+++ b/rkward/windows/rkcommandlog.h
@@ -1,6 +1,6 @@
 /*
 rkcommandlog - This file is part of the RKWard project. Created: Sun Nov 3 2002
-SPDX-FileCopyrightText: 2002-2010 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
+SPDX-FileCopyrightText: 2002-2023 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
 SPDX-FileContributor: The RKWard Team <rkward-devel at kde.org>
 SPDX-License-Identifier: GPL-2.0-or-later
 */
@@ -30,6 +30,8 @@ public:
 	void addInput (RCommand *command);
 /** Adds output to the log_view-window (i.e. replies received) */
 	void newOutput (RCommand *command, ROutput *output_fragment);
+/** Adds output no originating from R. Note: Currently used from kate plugins, only, see katepluginintegration.cpp */
+	void addOtherMessage(const QString &message, const QIcon &icon, ROutput::ROutputType severity);
 
 	static RKCommandLog *getLog () { return rkcommand_log; };
 


More information about the rkward-tracker mailing list