[rkward-cvs] SF.net SVN: rkward: [992] trunk/rkward

tfry at users.sourceforge.net tfry at users.sourceforge.net
Tue Dec 5 14:40:27 UTC 2006


Revision: 992
          http://svn.sourceforge.net/rkward/?rev=992&view=rev
Author:   tfry
Date:     2006-12-05 06:40:27 -0800 (Tue, 05 Dec 2006)

Log Message:
-----------
Run script editor commands through console by default, corresponding option, and some restructurings in RKConsole

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/rkward/rbackend/rcommand.h
    trunk/rkward/rkward/rkconsole.cpp
    trunk/rkward/rkward/rkconsole.h
    trunk/rkward/rkward/rkward.cpp
    trunk/rkward/rkward/rkward.h
    trunk/rkward/rkward/settings/rksettingsmoduleconsole.cpp
    trunk/rkward/rkward/settings/rksettingsmoduleconsole.h
    trunk/rkward/rkward/windows/rkcommandeditorwindowpart.cpp

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2006-12-05 11:40:33 UTC (rev 991)
+++ trunk/rkward/ChangeLog	2006-12-05 14:40:27 UTC (rev 992)
@@ -1,3 +1,4 @@
+- Script editor commands are piped through the console (by default; this is configurable)
 - (Cleanups: scatterplot plugin moved to plots, use "<-" instead of "=")
 
 --- Version 0.4.2 - Dec-04-2006

Modified: trunk/rkward/rkward/rbackend/rcommand.h
===================================================================
--- trunk/rkward/rkward/rbackend/rcommand.h	2006-12-05 11:40:33 UTC (rev 991)
+++ trunk/rkward/rkward/rbackend/rcommand.h	2006-12-05 14:40:27 UTC (rev 992)
@@ -195,6 +195,7 @@
 	void addReceiver (RCommandReceiver *receiver);
 /** Remove a receiver from the list. This may be needed when a listener wants to self-destruct, to make sure we don't try to send any further info there */
 	void removeReceiver (RCommandReceiver *receiver);
+	void addTypeFlag (int flag) { _type |= flag; };
 private:
 friend class RThread;
 friend class RInterface;

Modified: trunk/rkward/rkward/rkconsole.cpp
===================================================================
--- trunk/rkward/rkward/rkconsole.cpp	2006-12-05 11:40:33 UTC (rev 991)
+++ trunk/rkward/rkward/rkconsole.cpp	2006-12-05 14:40:27 UTC (rev 992)
@@ -29,6 +29,7 @@
 #include <kactioncollection.h>
 #include <kconfig.h>
 #include <kapplication.h>
+#include <kmessagebox.h>
 
 #include "rkglobals.h"
 #include "rkward.h"
@@ -43,6 +44,9 @@
 
 #include "debug.h"
 
+// static
+RKConsole* RKConsole::main_console = 0;
+
 RKConsole::RKConsole () : QWidget (0) {
 	RK_TRACE (APP);
 
@@ -123,7 +127,9 @@
 	hinter = new RKFunctionArgHinter (this, view);
 	
 	setCaption (i18n ("R Console"));
-	
+	part = new RKConsolePart (this);
+	initializeActions (part->actionCollection ());
+
 	nprefix = "> ";
 	iprefix = "+ ";
 	prefix = nprefix;
@@ -323,7 +329,7 @@
 	} else if (e->type () == QEvent::MouseButtonPress){
 		QMouseEvent *m = (QMouseEvent *)e;
 		if (m->button() == Qt::RightButton) {
-			emit (popupMenuRequest (m->globalPos ()));
+			doPopupMenu (m->globalPos ());
 			return (true);
 		}
 		return (false);
@@ -388,7 +394,7 @@
 	if (!currentCommand ().isEmpty ()) {
 		current_command = new RCommand (c, RCommand::User | RCommand::Console, QString::null, this);
 		RKGlobals::rInterface ()->issueCommand (current_command);
-		emit (doingCommand (true));
+		interrupt_command_action->setEnabled (true);
 	} else {
 		tryNextInBatch ();
 	}
@@ -495,7 +501,7 @@
 	}
 
 	current_command = 0;
-	emit (doingCommand (false));
+	interrupt_command_action->setEnabled (false);
 }
 
 void RKConsole::paste () {
@@ -572,77 +578,109 @@
 	RKSettings::configureSettings (RKSettings::Console, this);
 }
 
-///################### END RKConsole ########################
-///################### BEGIN RKConsolePart ####################
-
-RKConsolePart::RKConsolePart () : KParts::Part (0) {
+void RKConsole::slotInterruptCommand () {
 	RK_TRACE (APP);
+	RK_ASSERT (current_command || command_incomplete);
+	RK_DO (qDebug("received interrupt signal in console"), APP, DL_DEBUG);
 
-	KInstance* instance = new KInstance ("rkward");
-	setInstance (instance);
+	commands_batch.clear ();
+	if (command_incomplete) {
+		resetIncompleteCommand ();
+	} else {
+		RKGlobals::rInterface ()->cancelCommand (current_command);
+	}
+}
 
-	setWidget (RKConsolePart::console = new RKConsole ());
-	connect (console, SIGNAL (doingCommand (bool)), this, SLOT (setDoingCommand (bool)));
+void RKConsole::showContextHelp () {
+	RK_TRACE (APP);
+	RKGlobals::helpDialog ()->getContextHelp (currentCommand (), currentCursorPositionInCommand ());
+}
 
-	setXMLFile ("rkconsolepart.rc");
+void RKConsole::initializeActions (KActionCollection *ac) {
+	RK_TRACE (APP);
 
-	context_help = new KAction (i18n ("&Function reference"), KShortcut ("F2"), this, SLOT (showContextHelp ()), actionCollection (), "function_reference");
-	interrupt_command = new KAction (i18n ("Interrupt running command"), KShortcut ("Ctrl+C"), this, SLOT (slotInterruptCommand ()), actionCollection (), "interrupt");
-	interrupt_command->setIcon ("player_stop");
-	interrupt_command->setEnabled (false);
+	context_help_action = new KAction (i18n ("&Function reference"), KShortcut ("F2"), this, SLOT (showContextHelp ()), ac, "function_reference");
+	interrupt_command_action = new KAction (i18n ("Interrupt running command"), KShortcut ("Ctrl+C"), this, SLOT (slotInterruptCommand ()), ac, "interrupt");
+	interrupt_command_action->setIcon ("player_stop");
+	interrupt_command_action->setEnabled (false);
 // ugly HACK: we need this to override the default Ctrl+C binding
-	interrupt_command->setShortcut ("Ctrl+C");
+	interrupt_command_action->setShortcut ("Ctrl+C");
 
-	copy = new KAction (i18n ("Copy selection"), 0, console, SLOT (copy ()), actionCollection (), "rkconsole_copy");
-	KStdAction::clear (console, SLOT (clear ()), actionCollection (), "rkconsole_clear");
-	paste = KStdAction::paste (console, SLOT (paste ()), actionCollection (), "rkconsole_paste");
-	new KAction (i18n ("Configure"), 0, console, SLOT (configure ()), actionCollection (), "rkconsole_configure");
-
-	connect (console, SIGNAL (popupMenuRequest (const QPoint &)), this, SLOT (makePopupMenu (const QPoint &)));
+	copy_action = new KAction (i18n ("Copy selection"), 0, this, SLOT (copy ()), ac, "rkconsole_copy");
+	KStdAction::clear (this, SLOT (clear ()), ac, "rkconsole_clear");
+	paste_action = KStdAction::paste (this, SLOT (paste ()), ac, "rkconsole_paste");
+	new KAction (i18n ("Configure"), 0, this, SLOT (configure ()), ac, "rkconsole_configure");
 }
 
-RKConsolePart::~RKConsolePart () {
+void RKConsole::pipeUserCommand (RCommand *command) {
 	RK_TRACE (APP);
+
+	if (RKSettingsModuleConsole::pipeUserCommandsThroughConsole ()) {
+		RKConsole::mainConsole ()->pipeCommandThroughConsoleLocal (command);
+	} else {
+		RKGlobals::rInterface ()->issueCommand (command);
+	}
 }
 
-void RKConsolePart::showContextHelp () {
+void RKConsole::pipeCommandThroughConsoleLocal (RCommand *command) {
 	RK_TRACE (APP);
-	RKGlobals::helpDialog ()->getContextHelp (console->currentCommand (), console->currentCursorPositionInCommand ());
+
+	emit (raiseWindow ());
+	if (isBusy () || (!currentCommand ().isEmpty ())) {
+		int res = KMessageBox::questionYesNo (this, i18n ("You have configured RKWrad to run script commands through the console. However, the console is currently busy (either a command is running, or you have started to enter text in the console). Do you want to bypass the console this one time, or do you want to try again later?"), i18n ("Console is busy"), KGuiItem (i18n ("Bypass console")), KGuiItem (i18n ("Cancel")));
+		if (res == KMessageBox::Yes) {
+			RKGlobals::rInterface ()->issueCommand (command);
+		}
+	} else {
+		QString text = command->command ();
+		text.replace ("\n", QString ("\n") + iprefix);
+		doc->insertText (doc->numLines () - 1, QString (nprefix).length (), text);
+		command->addReceiver (this);
+		command->addTypeFlag (RCommand::Console);
+		current_command = command;
+		RKGlobals::rInterface ()->issueCommand (command);
+	}
 }
 
-void RKConsolePart::setDoingCommand (bool busy) {
+void RKConsole::doPopupMenu (const QPoint &pos) {
 	RK_TRACE (APP);
 
-	interrupt_command->setEnabled (busy || console->command_incomplete);
+	copy_action->setEnabled (hasSelectedText ());
+
+	part->showPopupMenu (pos);
+
+	copy_action->setEnabled (true);
 }
 
-void RKConsolePart::slotInterruptCommand () {
+///################### END RKConsole ########################
+///################### BEGIN RKConsolePart ####################
+
+
+RKConsolePart::RKConsolePart (RKConsole *console) : KParts::Part (0) {
 	RK_TRACE (APP);
-	RK_ASSERT (console->current_command || console->command_incomplete);
-	RK_DO (qDebug("received interrupt signal in console"), APP, DL_DEBUG);
 
-	console->commands_batch.clear ();
-	if (console->command_incomplete) {
-		console->resetIncompleteCommand ();
-	} else {
-		RKGlobals::rInterface ()->cancelCommand (console->current_command);
-	}
-	setDoingCommand (false);
+	KInstance* instance = new KInstance ("rkward");
+	setInstance (instance);
+
+	setWidget (console);
+
+	setXMLFile ("rkconsolepart.rc");
 }
 
-void RKConsolePart::makePopupMenu (const QPoint &pos) {
+RKConsolePart::~RKConsolePart () {
 	RK_TRACE (APP);
+}
 
+void RKConsolePart::showPopupMenu (const QPoint &pos) {
+	RK_TRACE (APP);
+
 	QPopupMenu *menu = static_cast<QPopupMenu *> (factory ()->container ("rkconsole_context_menu", this));
-	copy->setEnabled (console->hasSelectedText ());
 
 	if (!menu) {
 		RK_ASSERT (false);
 		return;
 	}
 	menu->exec (pos);
-
-	copy->setEnabled (true);
 }
 
 #include "rkconsole.moc"

Modified: trunk/rkward/rkward/rkconsole.h
===================================================================
--- trunk/rkward/rkward/rkconsole.h	2006-12-05 11:40:33 UTC (rev 991)
+++ trunk/rkward/rkward/rkconsole.h	2006-12-05 14:40:27 UTC (rev 992)
@@ -31,6 +31,8 @@
 class QStringList;
 class KAction;
 class RCommand;
+class KActionCollection;
+class RKConsolePart;
 
 /**
 \brief Provides an R-like console.
@@ -47,6 +49,11 @@
 class RKConsole : public QWidget, public RCommandReceiver, public RKScriptContextProvider {
 Q_OBJECT
 public:
+/** Constructor. */
+	RKConsole ();
+/** Destructor */
+	~RKConsole ();
+
 /** Submits a batch of commands, line by line.
 \param batch a QString containing the batch of commands to be executed */
 	void submitBatch (QString batch);
@@ -62,21 +69,24 @@
 	void resetIncompleteCommand ();
 	void doTabCompletion ();
 	bool provideContext (unsigned int line_rev, QString *context, int *cursor_position);
+
+	static RKConsole *mainConsole () { return main_console; };
+	static void setMainConsole (RKConsole *console) { main_console = console; };
+
+	bool isBusy () { return (current_command || command_incomplete); };
+/** Run a user command (through console, if applicable */
+	static void pipeUserCommand (RCommand *command);
+
+	RKConsolePart *getPart () { return part; };
+signals:
+	void raiseWindow ();
 protected:
-/** Constructor. Protected. Construct an RKConsolePart instead */
-	RKConsole ();
-/** Destructor */
-	~RKConsole ();
-
 /** 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);
 /** reimplemented from RCommandReceiver::newOutput () to handle output of console commands */
 	void newOutput (RCommand *command, ROutput *output);
-signals:
-	void doingCommand (bool busy);
-	void popupMenuRequest (const QPoint &pos);
 private:
 friend class RKConsolePart;
 	bool eventFilter (QObject *o, QEvent *e);
@@ -127,7 +137,21 @@
 	Kate::View *view;
 	RKFunctionArgHinter *hinter;
 
+	static RKConsole *main_console;
+
 	bool tab_key_pressed_before;
+
+	KAction* context_help_action;
+	KAction* interrupt_command_action;
+	KAction* copy_action;
+	KAction* paste_action;
+
+	void initializeActions (KActionCollection *ac);
+	void pipeCommandThroughConsoleLocal (RCommand *command);
+
+	RKConsolePart *part;
+
+	void doPopupMenu (const QPoint &pos);
 public slots:
 /** We intercept paste commands and get them executed through submitBatch.
 @sa submitBatch */
@@ -136,6 +160,10 @@
 /** Clear the view, and add a prompt at the top. */
 	void clear ();
 	void configure ();
+/** show context help on the current word */
+	void showContextHelp ();
+/** interrupt current command. */
+	void slotInterruptCommand ();
 };
 
 /** A part interface to RKConsole. Provides the context-help functionality
@@ -143,28 +171,15 @@
 @author Thomas Friedrichsmeier */
 
 class RKConsolePart : public KParts::Part {
-	Q_OBJECT
-public:
-/** constructor.
+friend class RKConsole;
+protected:
+/** constructor. Protected. Meant to the created by the RKConsole itself
 @param console The console for this part */
-	RKConsolePart ();
+	RKConsolePart (RKConsole *console);
 /** destructor */
 	~RKConsolePart ();
-public slots:
-/** show context help on the current word */
-	void showContextHelp ();
-	void setDoingCommand (bool busy);
-/** interrupt current command. */
-	void slotInterruptCommand ();
-	void makePopupMenu (const QPoint &pos);
-private:
-	KAction* context_help;
-	KAction* interrupt_command;
-	KAction* copy;
-	KAction* paste;
-	KAction* clear;
 
-	RKConsole *console;
+	void showPopupMenu (const QPoint &pos);
 };
 
 #endif

Modified: trunk/rkward/rkward/rkward.cpp
===================================================================
--- trunk/rkward/rkward/rkward.cpp	2006-12-05 11:40:33 UTC (rev 991)
+++ trunk/rkward/rkward/rkward.cpp	2006-12-05 14:40:27 UTC (rev 992)
@@ -191,11 +191,13 @@
 	addToolWindow (RKGlobals::rcontrol, KDockWidget::DockBottom, getMainDockWidget (), 10);
 	RKGlobals::rcontrol->hide ();		// this line is important! RControlWindow must do some initializations on first show, and be hidden until then.
 
-	RKConsolePart *consolepart = new RKConsolePart ();
-	consolepart->widget ()->setIcon (SmallIcon ("konsole"));
-	consolepart->widget ()->setName ("r_console");
-	addToolWindow (consolepart->widget (), KDockWidget::DockBottom, getMainDockWidget (), 10);
-	partManager ()->addPart (consolepart, false);
+	RKConsole *console = new RKConsole ();
+	console->setIcon (SmallIcon ("konsole"));
+	console->setName ("r_console");
+	console_view = addToolWindow (console, KDockWidget::DockBottom, getMainDockWidget (), 10);
+	connect (console, SIGNAL (raiseWindow ()), this, SLOT (raiseConsole ()));
+	partManager ()->addPart (console->getPart (), false);
+	RKConsole::setMainConsole (console);
 	
 	RKGlobals::helpdlg = new KHelpDlg (0);
 	RKGlobals::helpDialog ()->setIcon (SmallIcon ("help"));
@@ -520,6 +522,15 @@
 	}
 }
 
+void RKWardMainWindow::raiseConsole () {
+	RK_TRACE (APP);
+	console_view->show ();
+	KMdiChildView *window = activeWindow ();
+	if (window) {
+		window->activate ();
+	}
+}
+
 void RKWardMainWindow::invokeRHelp () {
 	RK_TRACE (APP);
 

Modified: trunk/rkward/rkward/rkward.h
===================================================================
--- trunk/rkward/rkward/rkward.h	2006-12-05 11:40:33 UTC (rev 991)
+++ trunk/rkward/rkward/rkward.h	2006-12-05 14:40:27 UTC (rev 992)
@@ -136,6 +136,8 @@
 	void showAboutApplication ();
 	/** raises the watch window */
 	void raiseWatch ();
+	/** raises the console window */
+	void raiseConsole ();
 	/** creates a new (empty) data.frame */
 	void slotNewDataFrame ();
 	/** open a file and load it into the document*/
@@ -221,6 +223,7 @@
 	KAction* configure;
 
 	KMdiToolViewAccessor *watch_view;
+	KMdiToolViewAccessor *console_view;
 	KMdiToolViewAccessor *search_help_view;
 	
 	friend class RKSettingsModule;

Modified: trunk/rkward/rkward/settings/rksettingsmoduleconsole.cpp
===================================================================
--- trunk/rkward/rkward/settings/rksettingsmoduleconsole.cpp	2006-12-05 11:40:33 UTC (rev 991)
+++ trunk/rkward/rkward/settings/rksettingsmoduleconsole.cpp	2006-12-05 14:40:27 UTC (rev 992)
@@ -34,6 +34,7 @@
 bool RKSettingsModuleConsole::save_history;
 uint RKSettingsModuleConsole::max_history_length;
 uint RKSettingsModuleConsole::max_console_lines;
+bool RKSettingsModuleConsole::pipe_user_commands_through_console;
 
 RKSettingsModuleConsole::RKSettingsModuleConsole (RKSettings *gui, QWidget *parent) : RKSettingsModule (gui, parent) {
 	RK_TRACE (SETTINGS);
@@ -57,6 +58,13 @@
 	connect (max_console_lines_spinner, SIGNAL (valueChanged (int)), this, SLOT (changedSetting (int)));
 	vbox->addWidget (max_console_lines_spinner);
 
+	vbox->addSpacing (2*RKGlobals::spacingHint ());
+
+	pipe_user_commands_through_console_box = new QCheckBox (i18n ("Run commands from script editor through console"), this);
+	pipe_user_commands_through_console_box->setChecked (pipe_user_commands_through_console);
+	connect (pipe_user_commands_through_console_box, SIGNAL (stateChanged (int)), this, SLOT (changedSetting (int)));
+	vbox->addWidget (pipe_user_commands_through_console_box);
+
 	vbox->addStretch ();
 }
 
@@ -77,6 +85,7 @@
 	config->writeEntry ("save history", save_history);
 	config->writeEntry ("max history length", max_history_length);
 	config->writeEntry ("max console lines", max_console_lines);
+	config->writeEntry ("pipe user commands through console", pipe_user_commands_through_console);
 }
 
 //static
@@ -87,6 +96,7 @@
 	save_history = config->readBoolEntry ("save history", true);
 	max_history_length = config->readNumEntry ("max history length", 100);
 	max_console_lines = config->readNumEntry ("max console lines", 500);
+	pipe_user_commands_through_console = config->readBoolEntry ("pipe user commands through console", true);
 }
 
 //static
@@ -123,6 +133,7 @@
 	save_history = save_history_box->isChecked ();
 	max_history_length = max_history_length_spinner->value ();
 	max_console_lines = max_console_lines_spinner->value ();
+	pipe_user_commands_through_console = pipe_user_commands_through_console_box->isChecked ();
 }
 
 void RKSettingsModuleConsole::save (KConfig *config) {

Modified: trunk/rkward/rkward/settings/rksettingsmoduleconsole.h
===================================================================
--- trunk/rkward/rkward/settings/rksettingsmoduleconsole.h	2006-12-05 11:40:33 UTC (rev 991)
+++ trunk/rkward/rkward/settings/rksettingsmoduleconsole.h	2006-12-05 14:40:27 UTC (rev 992)
@@ -45,6 +45,7 @@
 	static bool saveHistory () { return save_history; };
 	static uint maxHistoryLength () { return max_history_length; };
 	static uint maxConsoleLines () { return max_console_lines; };
+	static bool pipeUserCommandsThroughConsole () { return pipe_user_commands_through_console; };
 
 	static QStringList loadCommandHistory ();
 	static void saveCommandHistory (const QStringList &list);
@@ -56,8 +57,10 @@
 	static bool save_history;
 	static uint max_history_length;
 	static uint max_console_lines;
+	static bool pipe_user_commands_through_console;
 
 	QCheckBox *save_history_box;
+	QCheckBox *pipe_user_commands_through_console_box;
 	KIntSpinBox *max_history_length_spinner;
 	KIntSpinBox *max_console_lines_spinner;
 };

Modified: trunk/rkward/rkward/windows/rkcommandeditorwindowpart.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkcommandeditorwindowpart.cpp	2006-12-05 11:40:33 UTC (rev 991)
+++ trunk/rkward/rkward/windows/rkcommandeditorwindowpart.cpp	2006-12-05 14:40:27 UTC (rev 992)
@@ -26,6 +26,7 @@
 
 #include "rkcommandeditorwindow.h"
 #include "../rkglobals.h"
+#include "../rkconsole.h"
 #include "../rbackend/rinterface.h"
 #include "../debug.h"
 
@@ -63,7 +64,7 @@
 
 	if (command_editor->getSelection ().isEmpty () || command_editor->getSelection ().isNull ()) return;
 
-	RKGlobals::rInterface ()->issueCommand (new RCommand (command_editor->getSelection (), RCommand::User, QString::null));
+	RKConsole::pipeUserCommand (new RCommand (command_editor->getSelection (), RCommand::User, QString::null));
 }
 
 void RKCommandEditorWindowPart::slotRunLine() {
@@ -71,7 +72,7 @@
 
 	if (command_editor->getLine ().isEmpty () || command_editor->getLine().isNull ()) return;
 
-	RKGlobals::rInterface ()->issueCommand (new RCommand (command_editor->getLine (), RCommand::User, QString::null));
+	RKConsole::pipeUserCommand (new RCommand (command_editor->getLine (), RCommand::User, QString::null));
 }
 
 
@@ -79,8 +80,8 @@
 	RK_TRACE (COMMANDEDITOR);
 
 	if (command_editor->getText ().isEmpty () || command_editor->getText ().isNull ()) return;
-		
-	RKGlobals::rInterface ()->issueCommand (new RCommand (command_editor->getText (), RCommand::User, QString::null));
+
+	RKConsole::pipeUserCommand (new RCommand (command_editor->getText (), RCommand::User, QString::null));
 }
 
 void RKCommandEditorWindowPart::slotFunctionReference () {


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rkward-tracker mailing list