[Sciviews-commits] r453 - in komodo/SciViews-K/content: . js
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Feb 28 07:27:38 CET 2012
Author: phgrosjean
Date: 2012-02-28 07:27:38 +0100 (Tue, 28 Feb 2012)
New Revision: 453
Modified:
komodo/SciViews-K/content/RObjectsOverlay.xul
komodo/SciViews-K/content/js/commands.js
komodo/SciViews-K/content/js/r.js
komodo/SciViews-K/content/js/robjects.js
komodo/SciViews-K/content/js/sciviews.js
komodo/SciViews-K/content/rObjects2Pane.xul
Log:
Incorporation of SciViews-K-dev into SciViews-K (part V, robjects.js code)
Modified: komodo/SciViews-K/content/RObjectsOverlay.xul
===================================================================
--- komodo/SciViews-K/content/RObjectsOverlay.xul 2012-02-27 15:46:20 UTC (rev 452)
+++ komodo/SciViews-K/content/RObjectsOverlay.xul 2012-02-28 06:27:38 UTC (rev 453)
@@ -53,21 +53,21 @@
<script type="application/x-javascript" src="chrome://sciviewsk/content/js/robjects.js"/>
<popupset id="extensionPopupSet">
- <menupopup id="rObjectsContext" onpopupshowing="sv.r.objects.contextOnShow(event);">
+ <menupopup id="rObjectsContext" onpopupshowing="sv.robjects.contextOnShow(event);">
<menuitem id="menu_robjects_insertfullname"
class="primary_menu_item"
- oncommand="sv.r.objects.insertName(true)"
+ oncommand="sv.robjects.insertName(true)"
accesskey="F"
label="&sciviews.robjects.insFullName;"
acceltext="Ins" />
<menuitem id="menu_cmd_robjects_insertquoted"
label="&sciviews.robjects.insertQuoted;"
- oncommand="sv.r.objects.insertName(false, true);"
+ oncommand="sv.robjects.insertName(false, true);"
accesskey="&sciviews.robjects.insertQuoted.acc;"
acceltext="Shift+Ins" />
<menuitem id="menu_robjects_insertname"
label="&sciviews.robjects.insName;"
- oncommand="sv.r.objects.insertName(false)"
+ oncommand="sv.robjects.insertName(false)"
accesskey="I"
acceltext="Ctrl+Ins" />
@@ -75,14 +75,14 @@
<menuitem id="cmd_robjects_removeobj"
label="&sciviews.robjects.rmObj;"
- oncommand="sv.r.objects.removeSelected(event.shiftKey)"
+ oncommand="sv.robjects.removeSelected(event.shiftKey)"
accesskey="R"
acceltext="Del"
testDisableIf="t:noDelete"
key="key_cmd_delete" />
<menuitem id="menu_cmd_robjects_deletenow"
label="&sciviews.robjects.deleteNow;"
- oncommand="sv.r.objects.removeSelected(true);"
+ oncommand="sv.robjects.removeSelected(true);"
class="menuitem-iconic list-item-remove-icon"
acceltext="Shift+Del"
testDisableIf="t:noDelete"
@@ -92,22 +92,22 @@
<menuitem id="cmd_robjects_summary"
label="&sciviews.robjects.summary;"
- oncommand="sv.r.objects.do('summary')"
+ oncommand="sv.robjects.do('summary')"
testDisableIf="t:isFunction t:isEnvironment"
accesskey="S" />
<menuitem id="cmd_robjects_print"
label="&sciviews.robjects.print;"
- oncommand="sv.r.objects.do('print')"
+ oncommand="sv.robjects.do('print')"
testDisableIf="t:isPackage"
accesskey="P" />
<menuitem id="cmd_robjects_plot"
label="&sciviews.robjects.plot;"
- oncommand="sv.r.objects.do('plot')"
+ oncommand="sv.robjects.do('plot')"
testDisableIf="t:isFunction t:isEnvironment"
accesskey="O"/>
<menuitem id="cmd_robjects_str"
label="&sciviews.robjects.str;"
- oncommand="sv.r.objects.do('str')"
+ oncommand="sv.robjects.do('str')"
testDisableIf="t:isPackage"
accesskey="T"/>
@@ -115,12 +115,12 @@
<menuitem id="menu_cmd_robjects_selectall"
label="&sciviews.robjects.selectAll;"
- oncommand="sv.r.objects.selection.selectAll();"
+ oncommand="sv.robjects.selection.selectAll();"
accesskey="&sciviews.robjects.selectAll.acc;"
acceltext="Ctrl+A" />
<menuitem id="menu_cmd_robjects_selectsiblings"
label="&sciviews.robjects.selectSiblings;"
- oncommand="sv.r.objects.selectAllSiblings(sv.r.objects.selection.currentIndex);"
+ oncommand="sv.robjects.selectAllSiblings(sv.robjects.selection.currentIndex);"
accesskey="&sciviews.robjects.selectSiblings.acc;"
acceltext="Ctrl+Shift+A" />
@@ -129,13 +129,13 @@
<menuitem id="menu_cmd_robjects_write_table"
class="menuitem-iconic save-buffer-icon"
label="&sciviews.robjects.write_table;"
- oncommand="sv.r.objects.do('write.table')"
+ oncommand="sv.robjects.do('write.table')"
testDisableIf="t:cannotSaveToFile"
accesskey="T"/>
<menuitem id="menu_cmd_robjects_save"
class="menuitem-iconic save-buffer-icon"
label="&sciviews.robjects.save;"
- oncommand="sv.r.objects.do('save')"
+ oncommand="sv.robjects.do('save')"
testDisableIf="t:cannotSave"
accesskey="S" />
@@ -143,7 +143,7 @@
<menuitem id="menu_cmd_robjects_help"
label="&sciviews.robjects.help;"
- oncommand="sv.r.objects.do('help')"
+ oncommand="sv.robjects.do('help')"
class="menuitem-iconic help-icon"
testDisableIf="t:multipleSelection t:noHelp"
accesskey="H" />
@@ -155,7 +155,7 @@
tooltiptext="&sciviews.robjects.tab;: &sciviews.robjects.showHide;"
label="&sciviews.robjects.showHide;" splitter="bottom_splitter"
box="robjects_searchpath_panel"
- oncommand="sv.r.objects.toggleViewSearchPath(event);"
+ oncommand="sv.robjects.toggleViewSearchPath(event);"
checked="true" state="open"/>
</broadcasterset>
@@ -180,7 +180,7 @@
<tabs id="project_toolbox_tabs">
<tab id="sciviews_robjects_tab" label="&sciviews.robjects.tab;"
insertbefore="project_tab, places_tab"
- onclick="sv.r.objects.getPackageList(false);"
+ onclick="sv.robjects.getPackageList(false);"
tooltiptext="&sciviews.robjects.tip;"/>
</tabs> <!-- or insertafter="project_tab,codebrowser_tab" -->
<tabpanels id="project_toolbox_tabpanels">
@@ -193,8 +193,8 @@
tooltiptext="&sciviews.robjects.refresh.tip;"
buttonstyle="pictures"
label="&sciviews.robjects.refresh;" class="refresh-icon"
- oncommand="sv.r.objects.getPackageList(true);"/>
- <!-- or oncommand="sv.r.objects.refreshAll();"-->
+ oncommand="sv.robjects.getPackageList(true);"/>
+ <!-- or oncommand="sv.robjects.refreshAll();"-->
<toolbarbutton id="sciviews_robjects_searchpath_button"
observes="cmd_robjects_viewSearchPath"
buttonstyle="pictures" class="searchPath-icon"
@@ -248,21 +248,21 @@
<menuitem id="sciviews_robjects_context_filterByName"
label="&sciviews.robjects.filterByName;"
checked="true" accesskey="n" type="checkbox"
- oncommand="sv.r.objects.setFilterBy(this, 'name')"/>
+ oncommand="sv.robjects.setFilterBy(this, 'name')"/>
<menuitem id="sciviews_robjects_context_filterByClass"
label="&sciviews.robjects.filterByClass;"
accesskey="c" type="checkbox"
- oncommand="sv.r.objects.setFilterBy(this, 'class')"/>
+ oncommand="sv.robjects.setFilterBy(this, 'class')"/>
<menuitem id="sciviews_robjects_context_filterByGroup"
label="&sciviews.robjects.filterByGroup;"
accesskey="g" type="checkbox"
- oncommand="sv.r.objects.setFilterBy(this, 'group')"/>
+ oncommand="sv.robjects.setFilterBy(this, 'group')"/>
<menuseparator/>
<menuitem id="sciviews_robjects_context_clrFilter"
label="&sciviews.robjects.clrFilter;" accesskey="l"
- oncommand="document.getElementById('sciviews_robjects_filterbox').value = ''; sv.r.objects.applyFilter();"/>
+ oncommand="document.getElementById('sciviews_robjects_filterbox').value = ''; sv.robjects.applyFilter();"/>
</menupopup>
</toolbarbutton>
@@ -271,7 +271,7 @@
tooltiptext="&sciviews.robjects.filter.tip;"
style="min-width: 40px; max-width: 200px; margin-right: 0px;"
class="search-box"
- oncommand="sv.r.objects.applyFilter();"
+ oncommand="sv.robjects.applyFilter();"
emptytext="&sciviews.robjects.filterEmptyText;"/>
</hbox>
@@ -279,11 +279,11 @@
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);"
- ondraggesture="nsDragAndDrop.startDrag(event, sv.r.objects.packageListObserver);"
- onkeypress="sv.r.objects.packageListKeyEvent(event);"
- oncommand="sv.r.objects.packageSelectedEvent(event);"/>
+ ondragdrop="nsDragAndDrop.drop(event, sv.robjects.packageListObserver);"
+ ondragover="nsDragAndDrop.dragOver(event, sv.robjects.packageListObserver);"
+ ondraggesture="nsDragAndDrop.startDrag(event, sv.robjects.packageListObserver);"
+ onkeypress="sv.robjects.packageListKeyEvent(event);"
+ oncommand="sv.robjects.packageSelectedEvent(event);"/>
</vbox>
<splitter id="sciviews_robjects_splitter" collapse="before"
@@ -297,37 +297,37 @@
persist="sortDirection sortResource"
sortDirection="ascending" sortResource="r-name"
enableColumnDrag="true"
- onselect="sv.r.objects.onEvent(event);"
- onkeypress="sv.r.objects.onEvent(event);">
+ onselect="sv.robjects.onEvent(event);"
+ onkeypress="sv.robjects.onEvent(event);">
<treecols>
<treecol id="r-name" label="&sciviews.robjects.Name;"
primary="true" sortActive="true"
persist="width ordinal hidden"
- onclick="sv.r.objects.sort(this);" ordinal="1" flex="4"/>
+ onclick="sv.robjects.sort(this);" ordinal="1" flex="4"/>
<splitter class="tree-splitter" ordinal="2"/>
<treecol id="r-dims" label="&sciviews.robjects.Dims;"
persist="width ordinal hidden"
- onclick="sv.r.objects.sort(this);" flex="1" ordinal="3"/>
+ onclick="sv.robjects.sort(this);" flex="1" ordinal="3"/>
<splitter class="tree-splitter" ordinal="4"/>
<treecol id="r-group" label="&sciviews.robjects.Group;"
flex="2" hidden="true" persist="width ordinal hidden"
- onclick="sv.r.objects.sort(this);" ordinal="5"/>
+ onclick="sv.robjects.sort(this);" ordinal="5"/>
<splitter class="tree-splitter" ordinal="6"/>
<treecol id="r-class" label="&sciviews.robjects.Class;"
flex="2" hidden="true" persist="width ordinal hidden"
- onclick="sv.r.objects.sort(this);" ordinal="7"/>
+ onclick="sv.robjects.sort(this);" ordinal="7"/>
<splitter class="tree-splitter" ordinal="8"/>
<treecol id="r-fullName" label="&sciviews.robjects.FullName;"
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);"
- ondragdrop="nsDragAndDrop.drop(event, sv.r.objects.listObserver);"
- ondragover="nsDragAndDrop.dragOver(event, sv.r.objects.listObserver);"
- onclick="sv.r.objects.onEvent(event);"
- ondblclick="sv.r.objects.onEvent(event);"
+ ondraggesture="nsDragAndDrop.startDrag(event, sv.robjects.listObserver);"
+ ondragdrop="nsDragAndDrop.drop(event, sv.robjects.listObserver);"
+ ondragover="nsDragAndDrop.dragOver(event, sv.robjects.listObserver);"
+ onclick="sv.robjects.onEvent(event);"
+ ondblclick="sv.robjects.onEvent(event);"
context="rObjectsContext">
</treechildren>
</tree>
@@ -338,12 +338,12 @@
<toolbarbutton id="sciviews_robjects_foldAll_button"
label="Fold All" buttonstyle="pictures"
class="robjects-fold-all-icon"
- oncommand="sv.r.objects.foldAll(true);"
+ oncommand="sv.robjects.foldAll(true);"
tooltiptext="&sciviews.robjects.foldAll;"/>
<toolbarbutton id="sciviews_robjects_ExpandAll_button"
label="Expand All" buttonstyle="pictures"
class="robjects-expand-all-icon"
- oncommand="sv.r.objects.foldAll(false);"
+ oncommand="sv.robjects.foldAll(false);"
tooltiptext="&sciviews.robjects.unfoldAll;"/>
</hbox>
</vbox>
Modified: komodo/SciViews-K/content/js/commands.js
===================================================================
--- komodo/SciViews-K/content/js/commands.js 2012-02-27 15:46:20 UTC (rev 452)
+++ komodo/SciViews-K/content/js/commands.js 2012-02-28 06:27:38 UTC (rev 453)
@@ -448,7 +448,7 @@
'cmd_svRHelpContext': ['sv.r.help("", false);', XisRDoc | XRRunning],
'cmd_svRHelpSearch': ['sv.r.search();', XisRDoc | XRRunning],
'cmd_svRObjStructure': ['sv.r.display("", "structure");', XisRDoc | XRRunning],
- 'cmd_svRObjRefreshDisplay': ['ko.uilayout.ensureTabShown("sciviews_robjects_tab", true); sv.r.objects.getPackageList(true);', XRRunning],
+ 'cmd_svRObjRefreshDisplay': ['ko.uilayout.ensureTabShown("sciviews_robjects_tab", true); sv.robjects.getPackageList(true);', XRRunning],
'cmd_svRObjList': ['sv.r.eval("ls()");', XRRunning],
'cmd_svRObjRemove': ['sv.r.eval("rm(list = ls())");', XRRunning],
'cmd_svRActiveDF': ['sv.r.obj();', XRRunning],
Modified: komodo/SciViews-K/content/js/r.js
===================================================================
--- komodo/SciViews-K/content/js/r.js 2012-02-27 15:46:20 UTC (rev 452)
+++ komodo/SciViews-K/content/js/r.js 2012-02-28 06:27:38 UTC (rev 453)
@@ -62,7 +62,7 @@
// sv.r.kpfTranslate(kpfFile); // Translate a project
// sv.r.kpzTranslate(kpzFile); // Translate a package
//
-// Note: sv.r.objects is implemented in robjects.js
+// Note: sv.robjects is implemented in robjects.js
// sv.rconsole functions are implemented in rconsole.js
//
// sv.r.pkg namespace: /////////////////////////////////////////////////////////
@@ -185,7 +185,7 @@
sv.cmdout.clear(false);
// Reset the objects explorer
// PhG: this seems to cause problems => don't use this yet!
- //sv.r.objects.clearPackageList();
+ //sv.robjects.clearPackageList();
}
// Print some text (command or results) in the local R console
@@ -1548,7 +1548,7 @@
// Clear the R-relative statusbar message
ko.statusBar.AddMessage("", "SciViews-K");
// Clear the objects browser
- sv.r.objects.clearPackageList();
+ sv.robjects.clearPackageList();
// TODO: from SciViews-K-dev... adapt here?
//setTimeout(function() sv.command.updateRStatus(
// sv.rconn.testRAvailability()), 1000);
Modified: komodo/SciViews-K/content/js/robjects.js
===================================================================
--- komodo/SciViews-K/content/js/robjects.js 2012-02-27 15:46:20 UTC (rev 452)
+++ komodo/SciViews-K/content/js/robjects.js 2012-02-28 06:27:38 UTC (rev 453)
@@ -1,100 +1,11 @@
// SciViews-K R objects explorer functions
-// Define the 'sv.r.objects' tree and implement RObjectsOverlay functions
+// Define the 'sv.robjects' tree and implement RObjectsOverlay functions
// Copyright (c) 2009, Kamil Barton & Ph. Grosjean (phgrosjean at sciviews.org)
// License: MPL 1.1/GPL 2.0/LGPL 2.1
////////////////////////////////////////////////////////////////////////////////
-// sv.r.objects properties and methods
-//TODO: complete this documentation, clean up the code
+// sv.robjects namespace (not intended for external use)
+//TODO: list of functions here...
//
-///// These variables store all the information ////////////////////////////////
-// treeData - original tree data
-// visibleData - displayed data
-//
-///// Functions/properties to implement the tree view object ///////////////////
-// treeBox - treeBoxObject
-// selection - tree selection object
-// toggleOpenState
-// rowCount
-// setTree
-// setCellText
-// setCellValue
-// getCellText
-// isContainer
-//isContainerOpen
-// isContainerEmpty
-//isSeparator
-// isSorted
-// isEditable
-// getParentIndex
-// getLevel
-// hasNextSibling
-// getImageSrc
-// getProgressMode - not used, not really needed
-// getCellValue
-// cycleHeader
-// selectionChanged
-// cycleCell - not used, not really needed
-// performAction
-// performActionOnCell
-// getRowProperties
-// getCellProperties
-// getColumnProperties
-// canDrop - always false (but may be later, with svIO functions?)
-// drop - not needed so far
-//
-///// Other ////////////////////////////////////////////////////////////////////
-///// Private methods
-// _createVisibleData () - create visibleData from treeData
-// _addObjectList(pack)
-// _parseObjectList(data, packSelected)
-// _removeObjectList(pack)
-// _addSubObject(obj)
-// _parseSubObjectList(data, obj)
-// _getFilter()
-// _addVItems(item, parentIndex, level, parentUid)
-// _addVIChildren(vItem, parentIndex, isOpen)
-// _getVItem(obj, index, level, first, last, parentIndex, parentUid)
-//TODO: _addSubObject, _parseSubObjectList - should be possibly merged with
-// _addObjectList and _parseObjectList
-//
-///// Private properties
-// iconTypes - icons to display
-// debug - well, you know...
-// isInitialized
-// atomSvc
-//
-///// Public methods not belonging to the tree object implementation
-// sort
-// applyFilter
-// filter
-// foldAll
-// getSelectedRows
-// toString - textual representation of the tree for debugging purposes
-// init - initialize
-// refreshAll()
-// refreshGlobalEnv(data); // R sends data to refresh the global environment
-// removeSelected
-// getSelectedNames
-// insertName
-// setFilterBy
-//
-///// Event handling
-// contextOnShow
-// do
-// onEvent
-// listObserver - drag & drop handler
-//
-///// Search path box methods
-// _processPackageList - private method
-// getPackageList
-// clearPackageList - clear the list of packages and object explorer content
-// toggleViewSearchPath
-// displayPackageList
-// packageSelectedEvent
-// packageListObserver
-// packageListKeyEvent
-// searchPaths
-//
////////////////////////////////////////////////////////////////////////////////
//TODO: identify packages by pos rather than name (allow for non-unique names)
//TODO: context menu for search-paths list
@@ -103,7 +14,7 @@
//TODO: add a checkbutton to show also hidden objects (starting with a dot)
//TODO: delegate context menu calculation to R
//TODO: smart refresh: keep opened nodes, preserve scrolling
-//TODO: automatic refresh of the browser from R
+//TODO: automatic refresh of the objects browser from R
////////////////////////////////////////////////////////////////////////////////
/*
@@ -121,11 +32,9 @@
*/
//var sv = parent.sv;
+sv.robjects = {};
-// TODO: make this a sv.robjects.tree instead!
-sv.r.objects = {};
-
-// sv.r.objects constructor
+// sv.robjects constructor
(function () {
// Item separator for objList
var sep = ";;";
@@ -955,37 +864,64 @@
// this.treeBox.scrollToRow(0);
//};
+ // Get the list of packages on the search path from R
+ this.getPackageList = function () {
+ var cmd = 'cat(objSearch(sep = "' + sep + '", compare = FALSE))';
+ sv.r.evalCallback(cmd, _this.processPackageList);
+ };
+
// Callback to process the list of packages in the search path from R
- this.processPackageList = function _processPackageList (data, refreshObjects) {
+ this.processPackageList = function _processPackageList (data) {
if (data == "") return;
_this.searchPaths = data.replace(/[\n\r]/g, "").split(sep);
- _this.displayPackageList(refreshObjects);
+ _this.displayPackageList();
};
- // Get the list of packages on the search path from R
- this.getPackageList = function (refreshObjects) {
- //, testR /* = true*/,
- //testVersion /* = false*/) {
- //if (testR === undefined || testR == null) testR = true;
- //if (testVersion === undefined || testVersion == null)
- // testVersion = true;
-
-// if (testR && !sv.r.test(testVersion, testVersion)) return;
-
- var cmd = 'cat(objSearch(sep = "' + sep + '", compare = FALSE))';
- sv.r.evalCallback(cmd, _this.processPackageList, refreshObjects);
+ // Display the list of packages in the search path
+ this.displayPackageList = function () {
+ // refreshObjects is made optional and is true in this case
+ if (refreshObjects === undefined) refreshObjects = true;
+ var pack;
+ var node = document
+ .getElementById("sciviews_robjects_searchpath_listbox");
+ while (node.firstChild)
+ node.removeChild(node.firstChild);
+ var packs = _this.searchPaths;
+ var selectedPackages = _this.treeData.map(function(x) x.name);
+ // Display at least .GlobalEnv
+ if (!selectedPackages.length) selectedPackages.push(".GlobalEnv");
+ for(var i = 0; i < packs.length; i++) {
+ pack = packs[i];
+ var item = document.createElement("listitem");
+ item.setAttribute("type", "checkbox");
+ item.setAttribute("label", pack);
+ item.setAttribute("checked", selectedPackages.indexOf(pack) != -1);
+ node.appendChild(item);
+ }
+
+ if (selectedLabel != null) {
+ for (var i = 0; i < node.itemCount; i++) {
+ if (node.getItemAtIndex(i).label == selectedLabel) {
+ node.selectedIndex = i;
+ break;
+ }
+ }
+ } else {
+ node.selectedIndex = 0;
+ }
};
// 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.displayPackageList();
+ _this.parseObjListResult("Env=.GlobalEnv\nObj=\n");
}
this.toggleViewSearchPath = function (event) {
var what = event.target.tagName;
- var broadcaster = document.getElementById("cmd_robjects_viewSearchPath");
+ var broadcaster = document
+ .getElementById("cmd_robjects_viewSearchPath");
var box = document.getElementById(broadcaster.getAttribute("box"));
if (what == "splitter" || what == "grippy") {
@@ -1000,75 +936,34 @@
}
if (!box.collapsed) {
- if (!_this.searchPaths.length) _this.getPackageList();
+ //if (!_this.searchPaths.length) _this.getPackageList();
+ _this.smartRefresh();
}
}
- // Display the list of packages in the search path
- this.displayPackageList = function (refreshObjects) {
- // refreshObjects is made optional and is true in this case
- if (refreshObjects === undefined) refreshObjects = true;
- var pack;
- var node = document
- .getElementById("sciviews_robjects_searchpath_listbox");
- while(node.firstChild)
- node.removeChild(node.firstChild);
- var packs = this.searchPaths;
-
- var selectedPackages = new Array(_this.treeData.length);
- for (var i = 0; i < selectedPackages.length; i++)
- selectedPackages[i] = _this.treeData[i].name;
-
- for(var i = 0; i < packs.length; i++) {
- pack = packs[i];
- var item = document.createElement("listitem");
- item.setAttribute("type", "checkbox");
- item.setAttribute("label", pack);
- item.setAttribute("checked", selectedPackages.indexOf(pack) != -1);
- node.appendChild(item);
- }
-
- if (refreshObjects) _this.refreshAll();
- };
-
// Change the display status of a package by clicking an item in the list
this.packageSelectedEvent = function (event) {
var el = event.target;
var pack = el.getAttribute("label");
- if (!pack)
- return;
+ if (!pack) return;
if (el.checked) {
- _addObject(pack, "", _parseObjectList, pack);
+ //_addObject(pack, "", _parseObjectList, pack);
+ _addObject(pack, "", _this.parseObjListResult);
} else {
_removeObjectList(pack);
}
};
+
+ this.refreshAll = _this.smartRefresh; /// XXX - merge all *refresh* into one
- this.refreshAll = function () {
- var selectedPackages = new Array(_this.treeData.length);
- for (var i = 0; i < selectedPackages.length; i++)
- selectedPackages[i] = _this.treeData[i].name;
-
- if (selectedPackages.length == 0)
- selectedPackages.push('.GlobalEnv');
-
- var cmd = 'invisible(sapply(c("' + selectedPackages.join('","') +
- '"), function(x) ' + 'print(objList(envir = x, all.info = FALSE,' +
- ' compare = FALSE), sep = "' + sep +
- '", raw.output = TRUE, header = TRUE)))';
- sv.log.debug(cmd);
- sv.r.evalCallback(cmd, _parseObjectList);
- }
-
- this.refreshGlobalEnv = function (data) {
- if(!data) {
- _addObject(".GlobalEnv", "", _parseObjectList, ".GlobalEnv");
+ this.refreshGlobalEnv = function refreshGlobalEnv (data) {
+ if (!data) {
+ _addObject(".GlobalEnv", "", _this.parseObjListResult);
} else {
- _parseObjectList(data);
+ _this.parseObjListResult(data);
}
}
- //TODO: on package deletion -> remove it also from the search path
this.removeSelected = function (doRemove) {
var item, type, name, vItem, cmd = [];
var rmItems = {}, ObjectsToRemove = {}, envToDetach = [];
@@ -1100,7 +995,8 @@
var parent = vItem;
while (parent && parent.parentIndex &&
parent.parentIndex != -1) {
- parent = this.visibleData[parent.parentIndex].origItem;
+ parent = this.visibleData[parent.parentIndex]
+ .origItem;
if (!parent || (rmItems[env] &&
(rmItems[env].indexOf(parent.fullName) != -1))
@@ -1110,7 +1006,6 @@
}
if (typeof(rmItems[env]) == "undefined")
rmItems[env] = [];
-
rmItems[env].push(name);
if (type == "sub-object") {
@@ -1137,7 +1032,8 @@
}
for (var i in envToDetach) {
- cmd.push('detach("' + envToDetach[i].addslashes() + '")');
+ cmd.push('detach("' + envToDetach[i].addslashes() +
+ '", unload = TRUE)');
for (var j in _this.treeData) {
if (_this.treeData[j].name == envToDetach[i]) {
_this.treeData.splice(j, 1);
@@ -1162,7 +1058,10 @@
if (doRemove) {
// Remove immediately
- sv.r.evalCallback(cmd.join("\n"), sv.cmdout.append);
+ sv.r.evalCallback(cmd.join("\n"), function(res) {
+ print(res);
+ if (envToDetach.length) _this.smartRefresh();
+ });
} else {
// Insert commands to current document
var view = ko.views.manager.currentView;
@@ -1259,117 +1158,133 @@
return;
}
-this.contextOnShow = function (event) {
+ this.contextOnShow = function (event) {
var currentIndex = _this.selection.currentIndex;
- if (currentIndex == -1) return;
+ if (currentIndex == -1) return;
- var isEnvironment, isPackage, isInPackage, noDelete, isFunction;
- var item, type, name;
- item = _this.visibleData[currentIndex].origItem;
- type = item.class;
- name = item.fullName;
+ var isEnvironment, isPackage, isInPackage, noDelete, isFunction;
+ var item, type, name;
+ item = _this.visibleData[currentIndex].origItem;
+ type = item.class;
+ name = item.fullName;
- isEnvironment = item.type == "environment";
- isPackage = isEnvironment && (item.name.indexOf("package:") == 0);
- isInPackage = !isPackage && item.env &&
- (item.env.indexOf("package:") == 0);
+ isEnvironment = item.type == "environment";
+ isPackage = isEnvironment && (item.name.indexOf("package:") == 0);
+ isInPackage = !isPackage && item.env &&
+ (item.env.indexOf("package:") == 0);
- noDelete = (isEnvironment && (nonDetachable.indexOf(name) != -1))
- || isInPackage;
- isFunction = type == "function";
+ noDelete = (isEnvironment && (nonDetachable.indexOf(name) != -1))
+ || isInPackage;
+ isFunction = type == "function";
- var cannotSaveToFile = ["data.frame", "matrix", "table"].indexOf(item.class) == -1;
- var cannotSave = _this.selectedItemsOrd.filter(function(x)
- x.type == 'object' && x.group != 'function').length == 0;
+ var cannotSaveToFile = ["data.frame", "matrix", "table"]
+ .indexOf(item.class) == -1;
+ var cannotSave = _this.selectedItemsOrd.filter(function (x)
+ x.type == 'object' && x.group != 'function').length == 0;
- var multipleSelection = _this.selection.count > 1;
+ var multipleSelection = _this.selection.count > 1;
- // Help can be shown only for one object:
- var noHelp = !isPackage || !isInPackage;
+ // Help can be shown only for one object:
+ var noHelp = !isPackage || !isInPackage;
- //var menuNode = document.getElementById("rObjectsContext");
- var menuItems = event.target.childNodes;
- var testDisableIf, disable = false;
+ //var menuNode = document.getElementById("rObjectsContext");
+ var menuItems = event.target.childNodes;
+ var testDisableIf, disable = false;
- for(var i = 0; i < menuItems.length; i++) {
- if (!menuItems[i].hasAttribute('testDisableIf')) continue;
- testDisableIf = menuItems[i].getAttribute('testDisableIf').split(/\s+/);
- disable = false;
+ for (var i = 0; i < menuItems.length; i++) {
+ if (!menuItems[i].hasAttribute('testDisableIf')) continue;
+ testDisableIf = menuItems[i].getAttribute('testDisableIf')
+ .split(/\s+/);
+ disable = false;
- for(var j = 0; j < testDisableIf.length && !disable; j++) {
- switch(testDisableIf[j]){
- case 't:multipleSelection':
+ for (var j = 0; j < testDisableIf.length && !disable; j++) {
+ switch(testDisableIf[j]){
+ case 't:multipleSelection':
disable = multipleSelection;
break;
- case 't:noHelp':
+ case 't:noHelp':
disable = noHelp;
break;
- case 't:isFunction':
+ case 't:isFunction':
disable = isFunction;
break;
- case 't:isEnvironment':
+ case 't:isEnvironment':
disable = isEnvironment;
break;
- case 't:isPackage':
+ case 't:isPackage':
disable = isPackage;
break;
- case 't:cannotSaveToFile':
+ case 't:cannotSaveToFile':
disable = cannotSaveToFile;
break;
- case 't:cannotSave':
+ case 't:cannotSave':
disable = cannotSave;
break;
- case 't:noDelete':
+ case 't:noDelete':
disable = noDelete;
break;
- default: ;
+ default: ;
+ }
}
+ //print( menuItems[i].id + ": " + testDisableIf + " = " + disable);
+ menuItems[i].setAttribute('disabled', disable);
}
- //print( menuItems[i].id + ": " + testDisableIf + " = " + disable);
- menuItems[i].setAttribute('disabled', disable);
- }
}
this.do = function (action) {
var obj = _this.selectedItemsOrd;
- var command;
- switch(action) {
- case 'save':
+
+ switch(action) {
+ case 'save':
// Select only objects:
- obj = obj.filter(function(x) { if(x.type != "object") {
- _this.selection.toggleSelect(x.index); return false }
- else return true});
+ obj = obj.filter(function (x) {
+ if (x.type != "object") {
+ _this.selection.toggleSelect(x.index); return false
+ } else {
+ return(true);
+ }
+ });
var dup = sv.tools.array.duplicates(obj.map(function(x) x.name));
- if(dup.length &&
- ko.dialogs.okCancel("Objects with the same names from different" +
- "environments selected. Following object will be taken from the " +
+ if (dup.length && ko.dialogs.okCancel(
+ "Objects with the same names from different environments " +
+ "selected. Following object will be taken from the " +
"foremost location in the search path: " + dup.join(', '),
"Cancel") == "Cancel") return;
var fileName = (obj.length == 1)? obj[0].name
.replace(/[\/\\:\*\?"<>\|]/g, '_') : '';
- var dir = sv.tools.file.pathFromURI(ko.places.manager.currentPlace);
+ try {
+ var dir = sv.tools.file
+ .pathFromURI(ko.places.manager.currentPlace);
+ // In the code in SciViews-K-dev, current R working dir is used
+ //var dir = sv.file.path(sv.rconn.evalAtOnce("cat(getwd())"));
+ } catch(e) { return; }
+
fileName = sv.fileOpen(dir, fileName + '.RData', '',
["R data (*.RData)|*.RData"], false, true, oFilterIdx = {});
if (!fileName) return;
- command = 'save(list=c(' + obj.map(function(x) '"' + x.name + '"')
- .join(',') + '), file="' + fileName.addslashes() + '")';
-
- sv.r.eval(command);
- break;
+ // PhG: I want the simplest syntax as possible
+ //var cmd = 'save(list = c(' + obj.map(function(x) '"' + x.name + '"')
+ // .join(',') + '), file = "' + fileName.addslashes() + '")';
+ var cmd = 'save(' + obj.name.join(', ') + ', file = "' +
+ fileName.addslashes() + '")';
+ sv.r.eval(cmd);
+ break;
+
// Special handling for help
case 'help':
for (i in obj) {
// Help only for packages and objects inside a package
- if (obj[i].fullName.indexOf("package:") == 0) {
- sv.r.help("", obj[i].fullName.replace(/^package:/, ''));
- } else if (obj[i].env.indexOf("package:") == 0) {
- sv.r.help(obj[i].fullName, obj[i].env.replace(/^package:/, ''));
+ if (obj[i].fullName.indexOf("package:") == 0) {
+ sv.r.help("", obj[i].fullName.replace(/^package:/, ''));
+ } else if (obj[i].env.indexOf("package:") == 0) {
+ sv.r.help(obj[i].fullName, obj[i].env
+ .replace(/^package:/, ''));
} else {
sv.r.help(obj[i].fullName);
}
@@ -1379,12 +1294,17 @@
//TODO: dump data for objects other than 'data.frame'
case 'write.table':
case 'writeToFile':
- var cmd = [], expr;
+ var expr;
for (i in obj) {
- expr = "evalq(" + obj[i].fullName +
- ", envir = as.environment(\"" +
- obj[i].env.addslashes() + "\"))";
+ // PhG: I want the simplest expression as possible
+ if (obj[i].env == ".GlobalEnv") {
+ expr = obj[i].fullName;
+ } else {
+ expr = "evalq(" + obj[i].fullName +
+ ", envir = as.environment(\"" +
+ obj[i].env.addslashes() + "\"))";
+ }
sv.r.saveDataFrame(expr, '', obj[i].name);
}
break;
@@ -1395,13 +1315,18 @@
case 'str':
case 'names':
default:
- var cmd = [];
+ var cmds = [];
for (i in obj) {
- cmd.push(action + "(evalq(" + obj[i].fullName +
- ", envir = as.environment(\"" +
- obj[i].env.addslashes() + "\")))");
+ // PhG: I want the simplest expression as possible
+ if (obj[i].env == ".GlobalEnv") {
+ cmds.push(action + "(" + obj[i].fullName + ")");
+ } else {
+ cmds.push(action + "evalq(" + obj[i].fullName +
+ ", envir = as.environment(\"" +
+ obj[i].env.addslashes() + "\"))");
+ }
}
- sv.r.eval(cmd.join("\n"));
+ sv.r.eval(cmds.join("\n"));
}
//var view = ko.views.manager.currentView;
@@ -1414,14 +1339,14 @@
this.selectedItemsOrd = [];
-this.onEvent = function on_Event(event) {
+ this.onEvent = function on_Event(event) {
switch (event.type) {
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/sciviews -r 453
More information about the Sciviews-commits
mailing list