[education/rkward] rkward: Port RKConsole away from RCommandReceiver

Thomas Friedrichsmeier null at kde.org
Thu Jun 9 15:30:34 BST 2022


Git commit 0ae1ef00580cec4ee705afbd8875715c82325215 by Thomas Friedrichsmeier.
Committed on 09/06/2022 at 14:29.
Pushed by tfry into branch 'master'.

Port RKConsole away from RCommandReceiver

M  +1    -0    rkward/rbackend/rcommand.cpp
M  +2    -0    rkward/rbackend/rcommand.h
M  +23   -25   rkward/rkconsole.cpp
M  +6    -9    rkward/rkconsole.h

https://invent.kde.org/education/rkward/commit/0ae1ef00580cec4ee705afbd8875715c82325215

diff --git a/rkward/rbackend/rcommand.cpp b/rkward/rbackend/rcommand.cpp
index 0c3eb1eb..5b4bcab8 100644
--- a/rkward/rbackend/rcommand.cpp
+++ b/rkward/rbackend/rcommand.cpp
@@ -134,6 +134,7 @@ void RCommand::commandLineIn () {
 		if (receivers[i] == 0) continue;
 		receivers[i]->userCommandLineIn (this);
 	}
+	if (_notifier) _notifier->emitLineIn(this);
 }
 
 QString RCommand::error () const {
diff --git a/rkward/rbackend/rcommand.h b/rkward/rbackend/rcommand.h
index 617f0ec8..43dc982a 100644
--- a/rkward/rbackend/rcommand.h
+++ b/rkward/rbackend/rcommand.h
@@ -71,12 +71,14 @@ signals:
 /** given command has finished (not necessarily successfully) */
 	void commandFinished(RCommand *command);
 	void commandOutput(RCommand *command, const ROutput* output);
+	void commandLineIn(RCommand *command);
 private:
 friend class RCommand;
 	RCommandNotifier();
 	~RCommandNotifier();
 	void emitFinished(RCommand *command) { emit commandFinished(command); };
 	void emitOutput(RCommand *command, const ROutput* output) { emit commandOutput(command, output); };
+	void emitLineIn(RCommand *command) { emit commandLineIn(command); };
 };
 
 /** For introductory information on using RCommand, see \ref UsingTheInterfaceToR 
diff --git a/rkward/rkconsole.cpp b/rkward/rkconsole.cpp
index 3b3e8faf..967d37c3 100644
--- a/rkward/rkconsole.cpp
+++ b/rkward/rkconsole.cpp
@@ -46,7 +46,6 @@ SPDX-License-Identifier: GPL-2.0-or-later
 #include "windows/rkhelpsearchwindow.h"
 #include "windows/rkcodecompletion.h"
 #include "rbackend/rkrinterface.h"
-#include "rbackend/rcommand.h"
 #include "settings/rksettings.h"
 #include "settings/rksettingsmoduleconsole.h"
 #include "settings/rkrecenturls.h"
@@ -487,7 +486,28 @@ void RKConsole::submitCommand () {
 
 	doc->insertLine (doc->lines (), QString ());
 	if (!command.isEmpty ()) {
-		current_command = new RCommand (command, RCommand::User | RCommand::Console, QString (), this);
+		current_command = new RCommand (command, RCommand::User | RCommand::Console);
+		connect(current_command->notifier(), &RCommandNotifier::commandOutput, this, &RKConsole::newOutput);
+		connect(current_command->notifier(), &RCommandNotifier::commandLineIn, this, &RKConsole::userCommandLineIn);
+		current_command->whenFinished(this, [this](RCommand *command) {
+			RK_TRACE(APP);
+			current_command = nullptr;
+
+			if (command->errorSyntax() && command->error().isEmpty()) {
+				doc->insertLine(doc->lines() - 1, i18n("Syntax error\n"));
+			}
+			if (command->errorIncomplete()) {
+				prefix = iprefix;
+				incomplete_command = command->remainingCommand();
+			} else {
+				prefix = nprefix;
+				incomplete_command.clear();
+			}
+
+			commands_history.goToEnd();
+			showPrompt();
+			tryNextInBuffer();
+		});
 		RInterface::issueCommand (current_command);
 		interrupt_command_action->setEnabled (true);
 	} else {
@@ -512,29 +532,7 @@ void RKConsole::commandsListDown (bool context_sensitive) {
 	else qApp->beep ();
 }
 
-void RKConsole::rCommandDone (RCommand *command) {
-	RK_TRACE (APP);
-
-	current_command = 0;
-
-	if (command->errorSyntax () && command->error ().isEmpty ()) {
-		doc->insertLine (doc->lines () - 1, i18n ("Syntax error\n"));
-	}
-
-	if (command->errorIncomplete ()) {
-		prefix = iprefix;
-		incomplete_command = command->remainingCommand ();
-	} else {
-		prefix = nprefix;
-		incomplete_command.clear ();
-	}
-
-	commands_history.goToEnd ();
-	showPrompt ();
-	tryNextInBuffer ();
-}
-
-void RKConsole::newOutput (RCommand *command, ROutput *output) {
+void RKConsole::newOutput (RCommand *command, const ROutput *output) {
 	RK_TRACE (APP);
 
 	int first_line = doc->lines () -1;
diff --git a/rkward/rkconsole.h b/rkward/rkconsole.h
index 39e86832..1753c3e9 100644
--- a/rkward/rkconsole.h
+++ b/rkward/rkconsole.h
@@ -13,7 +13,7 @@ SPDX-License-Identifier: GPL-2.0-or-later
 #include <ktexteditor/document.h>
 #include <ktexteditor/view.h>
 
-#include "rbackend/rcommandreceiver.h"
+#include "rbackend/rcommand.h"
 #include "windows/rkcommandeditorwindow.h"
 #include "windows/rkmdiwindow.h"
 #include "misc/rkcommandhistory.h"
@@ -22,7 +22,6 @@ class QEvent;
 class QKeyEvent;
 class QStringList;
 class QAction;
-class RCommand;
 class KActionCollection;
 class RKConsolePart;
 
@@ -38,7 +37,7 @@ Do not construct directly. Construct an RKConsolePart instead.
 @author Pierre Ecochard
 **/
 
-class RKConsole : public RKMDIWindow, public RCommandReceiver, public RKScriptContextProvider {
+class RKConsole : public RKMDIWindow, public RKScriptContextProvider {
 Q_OBJECT
 public:
 /** Constructor. */
@@ -70,9 +69,10 @@ protected:
 /** Handle keystrokes before they reach the kate-part. Return TRUE if we want the kate-part to ignore it
 \param e the QKeyEvent */
 	bool handleKeyPress (QKeyEvent * e);
-	void rCommandDone (RCommand *command) override;
-/** reimplemented from RCommandReceiver::newOutput () to handle output of console commands */
-	void newOutput (RCommand *command, ROutput *output) override;
+/** handle output of console commands */
+	void newOutput(RCommand *command, const ROutput *output);
+/** display the next line of the command for multi-line commands */
+	void userCommandLineIn(RCommand* command);
 /** reimplemented from QWidget to show the context menu */
 	void contextMenuEvent (QContextMenuEvent * event) override;
 private:
@@ -169,9 +169,6 @@ private:
 	int current_command_displayed_up_to;
 	int skip_command_display_lines;
 	bool previous_chunk_was_piped;
-	
-/** Reimplemented from RCommandReceiver to display the next line of the command */
-	void userCommandLineIn (RCommand* command) override;
 };
 
 /** A part interface to RKConsole. Provides the context-help functionality



More information about the rkward-tracker mailing list