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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Sat Jan 29 21:14:28 UTC 2011


Revision: 3403
          http://rkward.svn.sourceforge.net/rkward/?rev=3403&view=rev
Author:   tfry
Date:     2011-01-29 21:14:27 +0000 (Sat, 29 Jan 2011)

Log Message:
-----------
Add menu actions for loading / saving command history.

Modified Paths:
--------------
    trunk/rkward/rkward/rkconsole.cpp
    trunk/rkward/rkward/rkconsole.h
    trunk/rkward/rkward/rkconsolepart.rc

Modified: trunk/rkward/rkward/rkconsole.cpp
===================================================================
--- trunk/rkward/rkward/rkconsole.cpp	2011-01-29 09:56:31 UTC (rev 3402)
+++ trunk/rkward/rkward/rkconsole.cpp	2011-01-29 21:14:27 UTC (rev 3403)
@@ -40,6 +40,9 @@
 #include <ktexteditor/configinterface.h>
 #include <ktexteditor/markinterface.h>
 #include <kxmlguifactory.h>
+#include <kfiledialog.h>
+#include <kio/netaccess.h>
+#include <ktemporaryfile.h>
 
 #include "rkglobals.h"
 #include "rkward.h"
@@ -784,7 +787,6 @@
 	RK_TRACE (APP);
 	if ((!command.isEmpty ()) && (commands_history.isEmpty () || commands_history.last() != command)) { // don't add empty or duplicate lines
 		commands_history.append (command);
-		history_editing_line = QString ();
 	}
 
 	if (RKSettingsModuleConsole::maxHistoryLength ()) {
@@ -793,6 +795,10 @@
 			commands_history.pop_front ();
 		}
 	}
+
+	history_editing_line = QString ();
+	commands_history_position = commands_history.constEnd ();
+	command_edited = false;
 }
 
 void RKConsole::setCommandHistory (const QStringList &new_history, bool append) {
@@ -804,6 +810,47 @@
 	addCommandToHistory (QString ());	// side-effect of checking history length
 }
 
+void RKConsole::userLoadHistory (const KUrl &_url) {
+	RK_TRACE (APP);
+
+	KUrl url = _url;
+	if (url.isEmpty ()) {
+		url = KFileDialog::getOpenUrl (KUrl (), i18n ("*.Rhistory|R history files (*.Rhistory)\n*|All files (*)"), this, i18n ("Select command history file to load"));
+		if (url.isEmpty ()) return;
+	}
+
+	QString tempfile;
+	KIO::NetAccess::download (url, tempfile, this);
+
+	QFile file (tempfile);
+	if (!file.open (QIODevice::Text | QIODevice::ReadOnly)) return;
+	setCommandHistory (QString (file.readAll ()).split ('\n', QString::SkipEmptyParts), false);
+	file.close ();
+
+	KIO::NetAccess::removeTempFile (tempfile);
+}
+
+void RKConsole::userSaveHistory (const KUrl &_url) {
+	RK_TRACE (APP);
+
+	KUrl url = _url;
+	if (url.isEmpty ()) {
+		url = KFileDialog::getSaveUrl (KUrl (), i18n ("*.Rhistory|R history files (*.Rhistory)\n*|All files (*)"), this, i18n ("Select filename to save command history")
+#if KDE_IS_VERSION(4,4,0)
+		                                    , KFileDialog::ConfirmOverwrite
+#endif
+		                                   );
+		if (url.isEmpty ()) return;
+	}
+
+	KTemporaryFile tempfile;
+	tempfile.open ();
+	tempfile.write (QString (commandHistory ().join ("\n") + "\n").toLocal8Bit ().data ());
+	tempfile.close ();
+
+	KIO::NetAccess::upload (tempfile.fileName (), url, this);
+}
+
 QString RKConsole::cleanedSelection () {
 	RK_TRACE (APP);
 
@@ -892,6 +939,11 @@
 	addProxyAction ("view_dynamic_word_wrap");
 	addProxyAction ("view_inc_font_sizes");
 	addProxyAction ("view_dec_font_sizes");
+
+	KAction *action = ac->addAction ("loadhistory", this, SLOT (userLoadHistory ()));
+	action->setText (i18n ("Import command history..."));
+	action = ac->addAction ("savehistory", this, SLOT (userSaveHistory ()));
+	action->setText (i18n ("Export command history..."));
 }
 
 void RKConsole::pipeUserCommand (const QString &command) {

Modified: trunk/rkward/rkward/rkconsole.h
===================================================================
--- trunk/rkward/rkward/rkconsole.h	2011-01-29 09:56:31 UTC (rev 3402)
+++ trunk/rkward/rkward/rkconsole.h	2011-01-29 21:14:27 UTC (rev 3403)
@@ -175,6 +175,9 @@
 /** Adds a chunk of commands to the input buffer
 \param batch a QString containing the batch of commands to be executed */
 	void submitBatch (const QString &batch);
+
+	void userLoadHistory (const KUrl &url=KUrl ());
+	void userSaveHistory (const KUrl &url=KUrl ());
 private:
 /** Commands can be queued in the console in four different places:
 1) The not-yet-executed remainder of a previous incomplete command.

Modified: trunk/rkward/rkward/rkconsolepart.rc
===================================================================
--- trunk/rkward/rkward/rkconsolepart.rc	2011-01-29 09:56:31 UTC (rev 3402)
+++ trunk/rkward/rkward/rkconsolepart.rc	2011-01-29 21:14:27 UTC (rev 3403)
@@ -1,9 +1,12 @@
 <!DOCTYPE kpartgui>
-<kpartgui name="rkward_console" version="54">
+<kpartgui name="rkward_console" version="540">
 	<MenuBar>
 		<Menu name="file"><text>&File</text>
+			<Separator />
+			<Action name="loadhistory"/>
+			<Action name="savehistory"/>
 			<Action name="file_print"/>
-			<Separator group="print_merge" />
+			<Separator />
 			<Action name="file_export_html"/>
 		</Menu>
 		<Menu name="edit"><text>&Edit</text>


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