[Sciviews-commits] r192 - komodo/SciViews-K komodo/SciViews-K/content komodo/SciViews-K/content/js komodo/SciViews-K/content/js/tools pkg/svGUI pkg/svGUI/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Sep 19 16:28:26 CEST 2009
Author: phgrosjean
Date: 2009-09-19 16:28:26 +0200 (Sat, 19 Sep 2009)
New Revision: 192
Modified:
komodo/SciViews-K/content/RObjectsOverlay.xul
komodo/SciViews-K/content/js/prefs.js
komodo/SciViews-K/content/js/r.js
komodo/SciViews-K/content/js/robjects.js
komodo/SciViews-K/content/js/socket.js
komodo/SciViews-K/content/js/tools/strings.js
komodo/SciViews-K/sciviewsk-0.8.1-ko.xpi
pkg/svGUI/NEWS
pkg/svGUI/R/guiRefresh.R
Log:
Better automatic handling of object browser and active objects
Modified: komodo/SciViews-K/content/RObjectsOverlay.xul
===================================================================
--- komodo/SciViews-K/content/RObjectsOverlay.xul 2009-09-17 23:20:28 UTC (rev 191)
+++ komodo/SciViews-K/content/RObjectsOverlay.xul 2009-09-19 14:28:26 UTC (rev 192)
@@ -196,7 +196,7 @@
emptytext="&sciviews.robjects.filterEmptyText;"/>
</hbox>
<vbox id="robjects_searchpath_panel"
- persist="height collapsed" flex="1">
+ persist="height collapsed" state="collapsed" flex="1">
<listbox flex="1" id="sciviews_robjects_searchpath_listbox"
ondragdrop="nsDragAndDrop.drop(event, sv.r.objects.packageListObserver);"
ondragover="nsDragAndDrop.dragOver(event, sv.r.objects.packageListObserver);"
@@ -235,7 +235,7 @@
onclick="sv.r.objects.sort(this);" ordinal="7"/>
<splitter class="tree-splitter" ordinal="8"/>
<treecol id="r-fullName" label="&sciviews.robjects.FullName;"
- persist="width ordinal hidden" flex="1" ordinal="9"/>
+ persist="width ordinal hidden" flex="1" hidden="true" ordinal="9"/>
</treecols>
<treechildren id="sciviews_robjects_objects_tree_main"
ondraggesture="nsDragAndDrop.startDrag(event, sv.r.objects.listObserver);"
Modified: komodo/SciViews-K/content/js/prefs.js
===================================================================
--- komodo/SciViews-K/content/js/prefs.js 2009-09-17 23:20:28 UTC (rev 191)
+++ komodo/SciViews-K/content/js/prefs.js 2009-09-19 14:28:26 UTC (rev 192)
@@ -108,15 +108,14 @@
// Should be reset to a more useful value during first use of R
sv.prefs.setString("r.active.data.frame", "<df>", true);
sv.prefs.setString("r.active.lm", "<lm>", true);
-ko.statusBar.AddMessage("Data: <none>, linear model: <none>", "Rref", 0, false);
-sv.prefs.mru("var", true, "", "|");
-sv.prefs.mru("var2", true, "", "|");
-sv.prefs.mru("x", true, "", "|");
-sv.prefs.mru("x2", true, "", "|");
-sv.prefs.mru("y", true, "", "|");
-sv.prefs.mru("factor", true, "", "|");
-sv.prefs.mru("factor2", true, "", "|");
-sv.prefs.mru("blockFactor", true, "", "|");
+sv.prefs.mru("var", true, "");
+sv.prefs.mru("var2", true, "");
+sv.prefs.mru("x", true, "");
+sv.prefs.mru("x2", true, "");
+sv.prefs.mru("y", true, "");
+sv.prefs.mru("factor", true, "");
+sv.prefs.mru("factor2", true, "");
+sv.prefs.mru("blockFactor", true, "");
//// (re)initialize a series of MRU for snippets' %ask constructs //////////////
Modified: komodo/SciViews-K/content/js/r.js
===================================================================
--- komodo/SciViews-K/content/js/r.js 2009-09-17 23:20:28 UTC (rev 191)
+++ komodo/SciViews-K/content/js/r.js 2009-09-19 14:28:26 UTC (rev 192)
@@ -46,6 +46,7 @@
// sv.r.obj(objClass); // Set active object for objClass (data.frame if omitted)
// sv.r.obj_select(data); // The callback for sv.r.obj() to select an object
// sv.r.obj_refresh_dataframe(data); // Refresh active data frame's MRUs
+// sv.r.obj_refresh_lm(data); // Refresh active 'lm' object
// sv.r.obj_message(); // Refresh statusbar message about active df and lm
// sv.r.initSession(dir, datadir, scriptdir, reportdir);
// sv.r.setSession(dir, datadir, scriptdir, reportdir, saveOld, loadNew);
@@ -139,11 +140,10 @@
} else {
// Possibly refresh the GUI by running SciViews-specific
// R task callbacks and make sure R Objects pane is updated
- sv.r.evalHidden("try(guiRefresh(force = TRUE), " +
- "silent = TRUE)");
+ sv.r.evalCallback("try(guiRefresh(force = TRUE), " +
+ "silent = TRUE)", function () {
+ sv.r.objects.getPackageList(true); });
}
- // Make sure the R Objects explorer is updated
-
}
//xtk.domutils.fireEvent(window, 'r_app_started_closed');
window.updateCommands('r_app_started_closed');
@@ -388,6 +388,11 @@
var text = sv.getTextRange(breakLine? "linetobegin" : "line", true);
ko.commands.doCommand('cmd_newlineExtra');
if (text != "") res = sv.r.eval(text);
+ } else {
+ var res = sv.r.eval(ke.selText);
+ ke.currentPos = ke.selectionEnd; // We want to go past the highest pos
+ ke.selectionStart = ke.selectionEnd; // Collapse selection
+ ko.commands.doCommand('cmd_newlineExtra');
}
} catch(e) {
return e;
@@ -722,6 +727,8 @@
datname = datname.replace(/^[a-zA-Z0-9._ ]*[(]/, "");
datname = datname.replace(/[)]$/, "");
res = sv.r.eval('data(' + datname + ')');
+ // Activate this dataset now and refresh corresponding MRU lists
+ sv.r.obj_refresh_dataframe(datname);
}
}
return(res);
@@ -897,6 +904,19 @@
'}, cache = "")\n' +
'cat(.active.data.frame$fun(), sep = "")',
sv.r.obj_refresh_dataframe);
+ } else if (objclass == "lm") {
+ // Refresh the default lm object in R session
+ res = sv.r.evalCallback(
+ '.active.lm <- list(object = "' + objname +
+ '", fun = function () {\n' +
+' if (exists(.active.lm$object, envir = .GlobalEnv)) {\n' +
+' obj <- get(.active.lm$object, envir = .GlobalEnv)\n' +
+' res <- paste(.active.lm$object, class(obj), sep = "\t")\n' +
+' return(.active.lm$cache <<- res)\n' +
+' } else return(.active.lm$cache <<- NULL)\n' +
+ '}, cache = "")\n' +
+ 'cat(.active.lm$fun(), sep = "")',
+ sv.r.obj_refresh_lm);
} else {
// Not implemented yet for other objects!
//alert("Update of MRU lists not implemented yet for other " +
@@ -915,12 +935,17 @@
// Display which objects (data frame and lm model, as for Rcmdr) are currently
// active in the Komodo statusbar
sv.r.obj_message = function () {
+ // Get the directory of current session
+ var ses = sv.prefs.getString("sciviews.session.dir", "~");
+ ses = sv.tools.strings.filename(ses);
+ // Get currently active data frame
var df = sv.prefs.getString("r.active.data.frame", "<none>");
if (df == "<df>") df = "<none>";
+ // Get currently active 'lm' object
var lm = sv.prefs.getString("r.active.lm", "<none>")
if (lm == "<lm>") lm = "<none>";
- ko.statusBar.AddMessage("Data: " + df + ", linear model: " + lm, "Rref", 0,
- false);
+ ko.statusBar.AddMessage("R session: " + ses + ", data: " + df +
+ ", linear model: " + lm, "Rstatus", 0, false);
}
// Callback for sv.r.obj_select to refresh the MRUs associated with data frames
@@ -928,16 +953,16 @@
ko.statusBar.AddMessage("", "R");
// If we got nothing, then the object does not exists any more... clear MRUs
if (data == "<<<data>>>") {
- var oldobj = sv.prefs.getString("r.active.data.frame", "");
+ //var oldobj = sv.prefs.getString("r.active.data.frame", "");
sv.prefs.setString("r.active.data.frame", "<df>", true); // Default value
- sv.prefs.mru("var", true, "", "|");
- sv.prefs.mru("var2", true, "", "|");
- sv.prefs.mru("x", true, "", "|");
- sv.prefs.mru("x2", true, "", "|");
- sv.prefs.mru("y", true, "", "|");
- sv.prefs.mru("factor", true, "", "|");
- sv.prefs.mru("factor2", true, "", "|");
- sv.prefs.mru("blockFactor", true, "", "|");
+ sv.prefs.mru("var", true, "");
+ sv.prefs.mru("var2", true, "");
+ sv.prefs.mru("x", true, "");
+ sv.prefs.mru("x2", true, "");
+ sv.prefs.mru("y", true, "");
+ sv.prefs.mru("factor", true, "");
+ sv.prefs.mru("factor2", true, "");
+ sv.prefs.mru("blockFactor", true, "");
// Update message in the statusbar
sv.r.obj_message();
return(false);
@@ -982,6 +1007,30 @@
return(true);
}
+// Callback for sv.r.obj_select to refresh the MRUs associated with lm objects
+sv.r.obj_refresh_lm = function (data) {
+ ko.statusBar.AddMessage("", "R");
+ // If we got nothing, then the object does not exists any more... clear MRUs
+ if (data == "<<<data>>>") {
+ //var oldobj = sv.prefs.getString("r.active.lm", "");
+ sv.prefs.setString("r.active.lm", "<lm>", true); // Default value
+ // Update message in the statusbar
+ sv.r.obj_message();
+ return(false);
+ }
+
+ var items = data.split("\n");
+ // First item contains the name of the active object and its class
+ var item = sv.tools.strings.removeLastCRLF(items[0]).split("\t");
+ var objname = item[0];
+ var objclass = item[1];
+ // Make sure r.active.data.frame pref is set to obj
+ sv.prefs.setString("r.active." + objclass, objname, true);
+ // Update message in the statusbar
+ sv.r.obj_message();
+ return(true);
+}
+
// Initialize R session preferences in Komodo
// use sv.r.setSession() except at startup!
sv.r.initSession = function (dir, datadir, scriptdir, reportdir) {
@@ -1109,8 +1158,11 @@
// TODO: report if we load something or not
sv.r.escape('cat("Session directory is now ' + dir +
'\n", file = stderr())');
- // We most probably need to update the R Objects browser
- sv.r.objects.getPackageList(true);
+ // Refresh active objects support
+
+ // We most probably need to update the R Objects browser and active objs
+ //sv.r.objects.getPackageList(true); // Old command, but refresh only object browser
+ sv.r.evalHidden("try(guiRefresh(force = TRUE), silent = TRUE)");
});
// TODO: possibly open the Komodo project associated with this session
@@ -1128,7 +1180,12 @@
null, "Exiting R");
if (response == "Cancel") { return; }
}
+ // Quit R
sv.r.eval('q("' + response.toLowerCase() + '")');
+ // Clear the R-relative statusbar message
+ ko.statusBar.AddMessage("", "Rstatus");
+ // Clear the objects browser
+ sv.r.objects.clearPackageList();
}
Modified: komodo/SciViews-K/content/js/robjects.js
===================================================================
--- komodo/SciViews-K/content/js/robjects.js 2009-09-17 23:20:28 UTC (rev 191)
+++ komodo/SciViews-K/content/js/robjects.js 2009-09-19 14:28:26 UTC (rev 192)
@@ -87,6 +87,7 @@
///// Search path box methods
// _processPackageList - private method
// getPackageList
+// clearPackageList - clear the list of packages and object explorer content
// toggleViewSearchPath
// displayPackageList
// packageSelectedEvent
@@ -937,6 +938,13 @@
sv.r.evalCallback(cmd, _processPackageList, refreshObjects);
};
+ // Clear the list of packages on the search path (when quitting R)
+ this.clearPackageList = function () {
+ _this.searchPaths = [];
+ _this.displayPackageList(false);
+ _parseObjectList("Env=.GlobalEnv\n");
+ }
+
this.toggleViewSearchPath = function (event) {
var what = event.target.tagName;
var broadcaster = document.getElementById("cmd_robjects_viewSearchPath");
Modified: komodo/SciViews-K/content/js/socket.js
===================================================================
--- komodo/SciViews-K/content/js/socket.js 2009-09-17 23:20:28 UTC (rev 191)
+++ komodo/SciViews-K/content/js/socket.js 2009-09-19 14:28:26 UTC (rev 192)
@@ -386,13 +386,15 @@
sv.prefs.getString("r.csv.dec.arg", ".") +
'); options(OutSep = ' +
sv.prefs.getString("r.csv.sep.arg", ",") +
- '); cat(localeToCharset()[1])', false, null,
- function (s) {
+ '); invisible(guiRefresh(force = TRUE)); cat(localeToCharset()[1])',
+ false, null, function (s) {
_this.charset = s;
if (this.debug) sv.log.debug(s);
});
- // Update also the R Object browser
- sv.r.objects.getPackageList(true);
+ // Update also the R Object browser and active objects lists
+ //sv.r.objects.getPackageList(true); // old code refreshing only object browser
+ // New code is: sv.r.eval("guiRefresh(force = TRUE)");
+ // ... and it is integrated in the command above!
}
// [PhG] The following command raises an error on my Mac
Modified: komodo/SciViews-K/content/js/tools/strings.js
===================================================================
--- komodo/SciViews-K/content/js/tools/strings.js 2009-09-17 23:20:28 UTC (rev 191)
+++ komodo/SciViews-K/content/js/tools/strings.js 2009-09-19 14:28:26 UTC (rev 192)
@@ -5,7 +5,8 @@
////////////////////////////////////////////////////////////////////////////////
// sv.tools.strings.replaceCRLF(str, code); // Replace LF and CR by 'code'
// sv.tools.strings.removeLastCRLF(str); // Remove last CR and/or LF
-// sv.tools.strings.toRegex(str); // changes a string to a regex
+// sv.tools.strings.toRegex(str); // Changes a string to a regex
+// sv.tools.strings.filename(str); // Get filename/last dir from path
//
// Additional methods to String objects ////////////////////////////////////////
// String.prototype.trim(); // Trim function for String
@@ -39,7 +40,21 @@
return(str);
}
+// Get filename or last directory name in a file path
+sv.tools.strings.filename = function (str) {
+ // Under Windows, replace \ by /
+ if (navigator.platform.indexOf("Win") > -1) {
+ str = str.replace(/[\\]/g, "/");
+ }
+ // Remove last trailing '/'
+ str = str.replace(/\/$/, "");
+ // Split into components
+ items = str.split("/");
+ // Return last component
+ return(items[items.length - 1]);
+}
+
//// Additional methods to String objects //////////////////////////////////////
// Trim function for String
String.prototype.trim = function () {
Modified: komodo/SciViews-K/sciviewsk-0.8.1-ko.xpi
===================================================================
(Binary files differ)
Modified: pkg/svGUI/NEWS
===================================================================
--- pkg/svGUI/NEWS 2009-09-17 23:20:28 UTC (rev 191)
+++ pkg/svGUI/NEWS 2009-09-19 14:28:26 UTC (rev 192)
@@ -4,6 +4,9 @@
* Use of svTaskCallbackManager() of svSocket >= 0.9-48 to register task
callback that are also executed after each R code send by socket clients.
+* guiRefresh() now clears active items and MRU lists in Komodo for non-defined
+ active data frames and lm objects.
+
== Changes in svGUI 0.9-45
Modified: pkg/svGUI/R/guiRefresh.R
===================================================================
--- pkg/svGUI/R/guiRefresh.R 2009-09-17 23:20:28 UTC (rev 191)
+++ pkg/svGUI/R/guiRefresh.R 2009-09-19 14:28:26 UTC (rev 192)
@@ -29,6 +29,12 @@
sep = ""), data = res)
}
}
+ # Make sure to clear active data frame and active lm object in case none
+ # are defined in the current session
+ if (!".active.data.frame" %in% aObjs)
+ koCmd('sv.r.obj_refresh_dataframe("<<<data>>>");');
+ if (!".active.lm" %in% aObjs)
+ koCmd('sv.r.obj_refresh_lm("<<<data>>>");');
# Refresh object browser (only data from .GlobalEnv)
lst <- objList(envir = .GlobalEnv, all.info = FALSE, compare = TRUE)
if (length(lst$Name) > 0) {
More information about the Sciviews-commits
mailing list