[rkward-cvs] SF.net SVN: rkward:[2899] trunk/rkward/rkward
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Thu Jun 24 13:04:28 UTC 2010
Revision: 2899
http://rkward.svn.sourceforge.net/rkward/?rev=2899&view=rev
Author: tfry
Date: 2010-06-24 13:04:28 +0000 (Thu, 24 Jun 2010)
Log Message:
-----------
Enabled / disable device history actions.
Modified Paths:
--------------
trunk/rkward/rkward/rbackend/rinterface.cpp
trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R
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/rbackend/rinterface.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rinterface.cpp 2010-06-24 13:03:37 UTC (rev 2898)
+++ trunk/rkward/rkward/rbackend/rinterface.cpp 2010-06-24 13:04:28 UTC (rev 2899)
@@ -384,6 +384,10 @@
window_catcher->stop (QString (request->call[1]).toInt ());
MUTEX_UNLOCK;
}
+ } else if (call == "updateDeviceHistory") {
+ if (request->call.count () >= 3) {
+ window_catcher->updateHistory (request->call.mid (1));
+ }
#endif // DISABLE_RKWINDOWCATCHER
} else if (call == "wdChange") {
RKWardMainWindow::getMain ()->updateCWD ();
Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R 2010-06-24 13:03:37 UTC (rev 2898)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R 2010-06-24 13:04:28 UTC (rev 2899)
@@ -23,7 +23,10 @@
.rk.do.call ("endOpenX11", as.character (dev.cur ()));
- if (!is.preview.device) rk.record.plot$onAddDevice (duplicateId = dupFrom, deviceId = dev.cur ())
+ if (!is.preview.device) {
+ rk.record.plot$onAddDevice (duplicateId = dupFrom, deviceId = dev.cur ())
+ rk.record.plot$.rk.graph.history.gui ()
+ }
invisible (x)
}
@@ -65,14 +68,6 @@
}
}
-".rk.graph.history.gui" <- function (deviceId = dev.cur())
-{
- # this function is called whenever the history length changes (ie, increases, for now)
- # or the position changes in any device.
- # see public_graphics.R :: rk.record.plot
- invisible ()
-}
-
"plot.new" <- function ()
{
if (dev.cur() == 1) rk.screen.device ()
Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R 2010-06-24 13:03:37 UTC (rev 2898)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R 2010-06-24 13:04:28 UTC (rev 2899)
@@ -90,7 +90,7 @@
if (class (try (unsavedPlot <- recordPlot(), silent=TRUE)) != 'try-error') {
current [[deviceId]] <<- length(recorded) + 1L
recorded [[current [[deviceId]]]] <<- unsavedPlot
- .rk.graph.history.gui (deviceId)
+ .rk.graph.history.gui ()
}
} else if (force) {
if (class (try (unsavedPlot <- recordPlot(), silent=TRUE)) != 'try-error') {
@@ -113,7 +113,7 @@
if (n > 0 && n <= length(recorded)) {
current [[deviceId]] <<- n
replayPlot(recorded[[n]])
- .rk.graph.history.gui (deviceId)
+ .rk.graph.history.gui ()
}
else message("replay: 'n' not in valid range: ", n)
dev.set (cur.deviceId)
@@ -135,7 +135,7 @@
recorded <<- list()
current <<- as.list(0)
newPlotExists <<- as.list(FALSE)
- .rk.graph.history.gui (deviceId)
+ .rk.graph.history.gui ()
}
printPars <- function ()
{
@@ -152,6 +152,20 @@
}
invisible ()
}
+ .rk.graph.history.gui <- function ()
+ {
+ # this function is called whenever the history length changes (ie, increases, for now)
+ # or the position changes in any device.
+ # see public_graphics.R :: rk.record.plot
+ history_length <- length (recorded)
+ positions <- NULL
+ for (dev_num in 1:length (current)) {
+ positions <- c (positions, dev_num, current[[dev_num]])
+ }
+ .rk.do.call ("updateDeviceHistory", as.character (c (history_length, positions)));
+ invisible (NULL)
+ }
+
env
}
rk.record.plot <- rk.record.plot ()
Modified: trunk/rkward/rkward/windows/rkcatchedx11windowpart.rc
===================================================================
--- trunk/rkward/rkward/windows/rkcatchedx11windowpart.rc 2010-06-24 13:03:37 UTC (rev 2898)
+++ trunk/rkward/rkward/windows/rkcatchedx11windowpart.rc 2010-06-24 13:04:28 UTC (rev 2899)
@@ -9,6 +9,11 @@
<Action name="device_copy_to_output"/>
<Action name="device_copy_to_r_object"/>
<Merge/>
+ <Menu name="history"><text>&History</text>
+ <Action name="plot_prev"/>
+ <Action name="plot_record"/>
+ <Action name="plot_next"/>
+ </Menu>
</Menu>
<Menu name="view"><text>&View</text>
<Action name="toggle_fixed_size"/>
@@ -20,9 +25,11 @@
<Merge/>
<Separator/>
</Menu>
- <Action name="plot_prev"/>
- <Action name="plot_curr"/>
- <Action name="plot_next"/>
<Merge/>
</MenuBar>
+ <ToolBar name="mdiToolBar">
+ <Action name="plot_prev"/>
+ <Action name="plot_record"/>
+ <Action name="plot_next"/>
+ </ToolBar>
</kpartgui>
\ No newline at end of file
Modified: trunk/rkward/rkward/windows/rkwindowcatcher.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkwindowcatcher.cpp 2010-06-24 13:03:37 UTC (rev 2898)
+++ trunk/rkward/rkward/windows/rkwindowcatcher.cpp 2010-06-24 13:04:28 UTC (rev 2899)
@@ -60,6 +60,23 @@
last_cur_device = new_cur_device;
}
+void RKWindowCatcher::updateHistory (QStringList params) {
+ RK_TRACE (MISC);
+ RK_ASSERT (params.length () >= 1);
+ RK_ASSERT ((params.length () % 2) == 1)
+
+ int history_length = params[0].toInt ();
+ for (int i = 1; i < (params.length () - 1); i += 2) {
+ RKCaughtX11Window* window = RKCaughtX11Window::getWindow (params[i].toInt ());
+ if (window) {
+ int position = params[i+1].toInt ();
+ window->updateHistoryActions (history_length, position);
+ } else {
+ RK_DO (qDebug ("Device %d is not managed, while trying to update history", params[i].toInt ()), RBACKEND, DL_DEBUG);
+ }
+ }
+}
+
///////////////////////////////// END RKWindowCatcher //////////////////////////////////
/**************************************************************************************/
//////////////////////////////// BEGIN RKCaughtX11Window //////////////////////////////
@@ -89,16 +106,22 @@
#include "../misc/rksaveobjectchooser.h"
#include "../plugin/rkcomponentcontext.h"
+// static
+QHash<int, RKCaughtX11Window*> RKCaughtX11Window::device_windows;
+
RKCaughtX11Window::RKCaughtX11Window (WId window_to_embed, int device_number) : RKMDIWindow (0, X11Window) {
RK_TRACE (MISC);
embedded = window_to_embed;
RKCaughtX11Window::device_number = device_number;
+ RK_ASSERT (!device_windows.contains (device_number));
+ device_windows.insert (device_number, this);
error_dialog = new RKProgressControl (0, i18n ("An error occurred"), i18n ("An error occurred"), RKProgressControl::DetailedError);
setPart (new RKCaughtX11WindowPart (this));
initializeActivationSignals ();
setFocusPolicy (Qt::ClickFocus);
+ updateHistoryActions (0, 0);
QVBoxLayout *layout = new QVBoxLayout (this);
layout->setContentsMargins (0, 0, 0, 0);
@@ -165,6 +188,8 @@
RKCaughtX11Window::~RKCaughtX11Window () {
RK_TRACE (MISC);
+ RK_ASSERT (device_windows.contains (device_number));
+ device_windows.remove (device_number);
capture->close ();
#ifdef Q_WS_X11
@@ -321,20 +346,33 @@
RK_TRACE (MISC);
RKGlobals::rInterface ()->issueCommand ("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);
}
-void RKCaughtX11Window::currentPlot () {
+void RKCaughtX11Window::recordCurrentPlot () {
RK_TRACE (MISC);
RKGlobals::rInterface ()->issueCommand ("rk.current.plot (" + QString::number (device_number) + ')', RCommand::App, i18n ("Add current plot in device number %1", device_number), error_dialog);
+ updateHistoryActions (history_length+1, history_length);
}
void RKCaughtX11Window::previousPlot () {
RK_TRACE (MISC);
RKGlobals::rInterface ()->issueCommand ("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);
}
+void RKCaughtX11Window::updateHistoryActions (int history_length, int position) {
+ RK_TRACE (MISC);
+
+ RKCaughtX11Window::history_length = history_length;
+ RKCaughtX11Window::history_position = position;
+
+ plot_prev_action->setEnabled (position > 1);
+ plot_next_action->setEnabled ((history_length > 0) && (position < history_length));
+}
+
///////////////////////////////// END RKCaughtX11Window ///////////////////////////////
/**************************************************************************************/
//////////////////////////////// BEGIN RKCaughtX11WindowPart //////////////////////////
@@ -367,12 +405,15 @@
action = actionCollection ()->addAction ("plot_prev", window, SLOT (previousPlot()));
// action->setText (i18n ("Restore previous plot"));
action->setText (i18n ("<"));
- action = actionCollection ()->addAction ("plot_curr", window, SLOT (currentPlot()));
-// action->setText (i18n ("Add current plot"));
+ window->plot_prev_action = (KAction*) action;
+ action = actionCollection ()->addAction ("plot_record", window, SLOT (recordCurrentPlot()));
+// action->setText (i18n ("Add current plot to history"));
action->setText (i18n ("+"));
+ window->plot_record_action = (KAction*) action;
action = actionCollection ()->addAction ("plot_next", window, SLOT (nextPlot()));
// action->setText (i18n ("Advance to next plot"));
action->setText (i18n (">"));
+ window->plot_next_action = (KAction*) action;
action = actionCollection ()->addAction ("device_activate", window, SLOT (activateDevice()));
action->setText (i18n ("Make active"));
Modified: trunk/rkward/rkward/windows/rkwindowcatcher.h
===================================================================
--- trunk/rkward/rkward/windows/rkwindowcatcher.h 2010-06-24 13:03:37 UTC (rev 2898)
+++ trunk/rkward/rkward/windows/rkwindowcatcher.h 2010-06-24 13:04:28 UTC (rev 2899)
@@ -68,6 +68,9 @@
/** end looking out for new R X11 windows. If a new window was in fact created, this is captured by creating an RKCaughtX11Window
@param new_cur_device the new active device number, i.e. the device number of the created window */
void stop (int new_cur_device);
+/** called from the R backend when the device history needs to be updated
+ at param params the serialized parameters as supplied from R */
+ void updateHistory (QStringList params);
private:
int last_cur_device;
};
@@ -75,8 +78,11 @@
#include "rkmdiwindow.h"
+#include <QHash>
+
class RKCaughtX11WindowPart;
class KToggleAction;
+class KAction;
class QXEmbedCopy;
class QScrollArea;
class KVBox;
@@ -103,6 +109,9 @@
void prepareToBeAttached ();
/** see prepareToBeAttached (). Reenable the dynamic_size_action */
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);
public slots:
/** Fixed size action was (potentially) toggled. Update to the new state */
void fixedSizeToggled ();
@@ -122,7 +131,7 @@
void duplicateDevice ();
void previousPlot ();
- void currentPlot ();
+ void recordCurrentPlot ();
void nextPlot ();
private slots:
void doEmbed ();
@@ -134,6 +143,8 @@
QScrollArea *scroll_widget;
KVBox *box_widget;
RKProgressControl *error_dialog;
+
+ static QHash<int, RKCaughtX11Window*> device_windows;
#ifdef Q_WS_WIN
QWinHost *capture;
#elif defined Q_WS_X11
@@ -145,6 +156,12 @@
bool dynamic_size;
KToggleAction *dynamic_size_action;
+ KAction *plot_prev_action;
+ KAction *plot_next_action;
+ KAction *plot_record_action;
+
+ int history_length;
+ int history_position;
};
/** Provides a KPart interface for RKCaughtX11Window. */
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