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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Mon Sep 6 10:46:53 UTC 2010


Revision: 2999
          http://rkward.svn.sourceforge.net/rkward/?rev=2999&view=rev
Author:   tfry
Date:     2010-09-06 10:46:53 +0000 (Mon, 06 Sep 2010)

Log Message:
-----------
Add drop-down list of plots in history

Modified Paths:
--------------
    trunk/rkward/rkward/misc/rkstandardicons.cpp
    trunk/rkward/rkward/misc/rkstandardicons.h
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R
    trunk/rkward/rkward/windows/rkcatchedx11windowpart.rc
    trunk/rkward/rkward/windows/rkwindowcatcher.cpp
    trunk/rkward/rkward/windows/rkwindowcatcher.h

Modified: trunk/rkward/rkward/misc/rkstandardicons.cpp
===================================================================
--- trunk/rkward/rkward/misc/rkstandardicons.cpp	2010-09-05 20:47:28 UTC (rev 2998)
+++ trunk/rkward/rkward/misc/rkstandardicons.cpp	2010-09-06 10:46:53 UTC (rev 2999)
@@ -65,6 +65,7 @@
 	icons[ActionDocumentInfo] = KIcon ("documentinfo.png");
 	icons[ActionFlagGreen] = KIcon ("flag-green.png");
 	icons[ActionSnapshot] = KIcon ("list-add.png");
+	icons[ActionListPlots] = KIcon ("view-preview.png");
 	icons[ActionRemovePlot] = KIcon ("list-remove.png");
 	icons[ActionWindowDuplicate] = KIcon ("window-duplicate.png");
 

Modified: trunk/rkward/rkward/misc/rkstandardicons.h
===================================================================
--- trunk/rkward/rkward/misc/rkstandardicons.h	2010-09-05 20:47:28 UTC (rev 2998)
+++ trunk/rkward/rkward/misc/rkstandardicons.h	2010-09-06 10:46:53 UTC (rev 2999)
@@ -65,6 +65,7 @@
 		ActionDocumentInfo,
 		ActionFlagGreen,
 		ActionSnapshot,
+		ActionListPlots,
 		ActionRemovePlot,
 		ActionWindowDuplicate,
 

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R	2010-09-05 20:47:28 UTC (rev 2998)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R	2010-09-06 10:46:53 UTC (rev 2999)
@@ -328,6 +328,13 @@
 		record (deviceId)
 		replay(n = length(recorded), deviceId)
 	}
+	showPlot <- function(deviceId = dev.cur(), index)
+	{
+		# TODO: record might remove a plot form history, thus changing the indices!
+		record (deviceId)
+		index = max (as.integer (index), 1L)
+		replay(n = min (length (recorded), index))
+	}
 	clearHistory <- function ()
 	{
 		isDuplicate <<- FALSE
@@ -359,10 +366,11 @@
 		ndevs <- length (deviceIds)
 		if (ndevs>0) {
 			positions <- character (1 + 2 * ndevs)
-			positions [1] <- length (recorded) # coerced as character
-			positions [2 * (1:ndevs)] <- deviceIds
-			positions [1 + 2 * (1:ndevs)] <- unlist (histPositions[deviceIds], use.names = FALSE)
-			.rk.do.call ("updateDeviceHistory", positions);
+			positions [2 * (1:ndevs) - 1] <- deviceIds
+			positions [2 * (1:ndevs)] <- unlist (histPositions[deviceIds], use.names = FALSE)
+			labels <- NULL
+			if (length (recorded) > 0) labels <- sapply (1:length (recorded), .get.oldplot.call)
+			.rk.do.call ("updateDeviceHistory", c (length (recorded), labels, positions));
 		}
 		#print (positions) # DEBUG
 		invisible (NULL)
@@ -483,6 +491,10 @@
 	rk.record.plot$showLast (deviceId)
 	rk.record.plot$printPars ()
 }
+"rk.goto.plot" <- function (deviceId = dev.cur (), index=1) {
+	rk.record.plot$showPlot (deviceId, index)
+	rk.record.plot$printPars ()
+}
 "rk.replaceby.plot" <- function (deviceId = dev.cur ())
 {
 	rk.record.plot$replaceby (deviceId)

Modified: trunk/rkward/rkward/windows/rkcatchedx11windowpart.rc
===================================================================
--- trunk/rkward/rkward/windows/rkcatchedx11windowpart.rc	2010-09-05 20:47:28 UTC (rev 2998)
+++ trunk/rkward/rkward/windows/rkcatchedx11windowpart.rc	2010-09-06 10:46:53 UTC (rev 2999)
@@ -12,6 +12,8 @@
 			<Separator/>
 		</Menu>
 		<Menu name="history"><text>&History</text>
+			<Action name="plot_list"/>
+			<Separator/>
 			<Action name="plot_first"/>
 			<Action name="plot_prev"/>
 			<Action name="plot_next"/>
@@ -42,6 +44,7 @@
 		<Separator/>
 		<Action name="device_copy_to_output"/>
 		<Separator/>
+		<Action name="plot_list"/>
 		<Action name="plot_prev"/>
 		<Action name="plot_next"/>
 		<Separator/>

Modified: trunk/rkward/rkward/windows/rkwindowcatcher.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkwindowcatcher.cpp	2010-09-05 20:47:28 UTC (rev 2998)
+++ trunk/rkward/rkward/windows/rkwindowcatcher.cpp	2010-09-06 10:46:53 UTC (rev 2999)
@@ -68,11 +68,12 @@
 	RK_ASSERT ((params.count () % 2) == 1)
 
 	int history_length = params[0].toInt ();
-	for (int i = 1; i < (params.count () - 1); i += 2) {
+	QStringList labels = params.mid (1, history_length);
+	for (int i = history_length + 1; i < (params.count () - 1); i += 2) {
 		RKCaughtX11Window* window = RKCaughtX11Window::getWindow (params[i].toInt ());
 		if (window) {
 			int position = params[i+1].toInt ();
-			window->updateHistoryActions (history_length, position);
+			window->updateHistoryActions (history_length, position, labels);
 		} else {
 			RK_DO (qDebug ("Device %d is not managed, while trying to update history", params[i].toInt ()), RBACKEND, DL_DEBUG);
 		}
@@ -107,6 +108,7 @@
 #include <QCloseEvent>
 
 #include <ktoggleaction.h>
+#include <kselectaction.h>
 #include <kdialog.h>
 #include <knuminput.h>
 #include <kvbox.h>
@@ -137,7 +139,7 @@
 	setPart (new RKCaughtX11WindowPart (this));
 	initializeActivationSignals ();
 	setFocusPolicy (Qt::ClickFocus);
-	updateHistoryActions (0, 0);
+	updateHistoryActions (0, 0, QStringList ());
 
 	status_popup = new KPassivePopup (this);
 	status_popup->setTimeout (0);
@@ -382,7 +384,6 @@
 	RK_TRACE (MISC);
 
 	RCommand* c = new RCommand ("rk.next.plot (" + QString::number (device_number) + ')', RCommand::App, i18n ("Load next plot in device number %1", device_number), error_dialog);
-	//updateHistoryActions (history_length, history_position+1);
 	setStatusMessage (i18n ("Loading plot from history"), c);
 	RKGlobals::rInterface ()->issueCommand (c);
 }
@@ -391,7 +392,6 @@
 	RK_TRACE (MISC);
 
 	RCommand* c = new RCommand ("rk.previous.plot (" + QString::number (device_number) + ')', RCommand::App, i18n ("Load previous plot in device number %1", device_number), error_dialog);
-	//updateHistoryActions (history_length, history_position-1);
 	setStatusMessage (i18n ("Loading plot from history"), c);
 	RKGlobals::rInterface ()->issueCommand (c);
 }
@@ -400,7 +400,6 @@
 	RK_TRACE (MISC);
 
 	RCommand* c = new RCommand ("rk.first.plot (" + QString::number (device_number) + ')', RCommand::App, i18n ("Load first plot in device number %1", device_number), error_dialog);
-	//updateHistoryActions (history_length, 1);
 	setStatusMessage (i18n ("Loading plot from history"), c);
 	RKGlobals::rInterface ()->issueCommand (c);
 }
@@ -409,11 +408,18 @@
 	RK_TRACE (MISC);
 
 	RCommand* c = new RCommand ("rk.last.plot (" + QString::number (device_number) + ')', RCommand::App, i18n ("Load last plot in device number %1", device_number), error_dialog);
-	//updateHistoryActions (history_length, history_length);
 	setStatusMessage (i18n ("Loading plot from history"), c);
 	RKGlobals::rInterface ()->issueCommand (c);
 }
 
+void RKCaughtX11Window::gotoPlot (int index) {
+	RK_TRACE (MISC);
+
+	RCommand* c = new RCommand ("rk.goto.plot (" + QString::number (device_number) + ", " + QString::number (index+1) + ')', RCommand::App, i18n ("Load plot %1 in device number %2", index, device_number), error_dialog);
+	setStatusMessage (i18n ("Loading plot from history"), c);
+	RKGlobals::rInterface ()->issueCommand (c);
+}
+
 void RKCaughtX11Window::replacebyCurrentPlot () {
 	RK_TRACE (MISC);
 
@@ -442,7 +448,7 @@
 	RKGlobals::rInterface ()->issueCommand ("rk.record.plot$showPlotInfo (" + QString::number (device_number) + ")", RCommand::App, i18n ("Plot properties (device number %1)", device_number), error_dialog);
 }
 
-void RKCaughtX11Window::updateHistoryActions (int history_length, int position) {
+void RKCaughtX11Window::updateHistoryActions (int history_length, int position, const QStringList &labels) {
 	RK_TRACE (MISC);
 
 	RKCaughtX11Window::history_length = history_length;
@@ -452,6 +458,11 @@
 	plot_prev_action->setEnabled (position > 1);
 	plot_next_action->setEnabled ((history_length > 0) && (position < history_length));
 	plot_last_action->setEnabled ((history_length > 0) && (position < history_length));
+	QStringList _labels = labels;
+	if (position > history_length) _labels.append (i18n ("<Unsaved plot>"));
+	plot_list_action->setItems (_labels);
+	plot_list_action->setCurrentItem (history_position - 1);
+	plot_list_action->setEnabled (history_length > 0);
 
 	plot_replaceby_action->setEnabled (history_length > 0);
 	plot_remove_action->setEnabled (history_length > 0);
@@ -529,6 +540,11 @@
  	action->setText (i18n ("Last plot"));
 	action->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionMoveLast));
 	window->plot_last_action = (KAction*) action;
+	action = window->plot_list_action = new KSelectAction (i18n ("Go to plot"), 0);
+	window->plot_list_action->setToolBarMode (KSelectAction::MenuMode);
+	action->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionListPlots));
+	actionCollection ()->addAction ("plot_list", action);
+	connect (action, SIGNAL (triggered(int)), window, SLOT (gotoPlot(int)));
 
 	action = actionCollection ()->addAction ("plot_replaceby", window, SLOT (replacebyCurrentPlot()));
  	action->setText (i18n ("Overwrite previous plot"));

Modified: trunk/rkward/rkward/windows/rkwindowcatcher.h
===================================================================
--- trunk/rkward/rkward/windows/rkwindowcatcher.h	2010-09-05 20:47:28 UTC (rev 2998)
+++ trunk/rkward/rkward/windows/rkwindowcatcher.h	2010-09-06 10:46:53 UTC (rev 2999)
@@ -87,6 +87,7 @@
 class RKCaughtX11WindowPart;
 class KToggleAction;
 class KAction;
+class KSelectAction;
 class QXEmbedCopy;
 class QScrollArea;
 class KVBox;
@@ -116,7 +117,7 @@
 	void prepareToBeDetached ();
 /** returns the window corresponding the to given R device number (or 0 if no such window exists) */
 	static RKCaughtX11Window* getWindow (int device_number) { return device_windows.value (device_number); };
-	void updateHistoryActions (int history_length, int position);
+	void updateHistoryActions (int history_length, int position, const QStringList &labels);
 /** Set a status message to be shown in a popup inside the window. The message persists until the given R command has finished, or until this function is called with an empty string.
 This should be used, when the plot is currently out-of-date (e.g. when loading a plot from history), _not_ when the window
 is simply busy (e.g. when saving the current plot to history). */
@@ -144,6 +145,7 @@
 	void previousPlot ();
 	void nextPlot ();
 	void lastPlot ();
+	void gotoPlot (int index);
 	void replacebyCurrentPlot ();
 	void removeCurrentPlot ();
 	void clearHistory ();
@@ -185,6 +187,7 @@
 	KAction *plot_remove_action;
 	KAction *plot_clear_history_action;
 	KAction *plot_properties_action;
+	KSelectAction *plot_list_action;
 
 	KPassivePopup* status_popup;
 	RCommand* status_change_command;


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