[Sciviews-commits] r91 - in komodo/SciViews-K: content content/js locale/en-GB locale/fr-FR skin skin/images
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Jan 12 16:37:03 CET 2009
Author: prezez
Date: 2009-01-12 16:37:03 +0100 (Mon, 12 Jan 2009)
New Revision: 91
Added:
komodo/SciViews-K/skin/images/Date.png
komodo/SciViews-K/skin/images/S3.png
komodo/SciViews-K/skin/images/S4.png
komodo/SciViews-K/skin/images/delete.png
komodo/SciViews-K/skin/images/environment.png
komodo/SciViews-K/skin/images/filter-a.png
komodo/SciViews-K/skin/images/formula.png
komodo/SciViews-K/skin/images/glm.png
komodo/SciViews-K/skin/images/images4.png
komodo/SciViews-K/skin/images/lm.png
komodo/SciViews-K/skin/images/lme.png
komodo/SciViews-K/skin/images/object.png
komodo/SciViews-K/skin/images/package_add.png
komodo/SciViews-K/skin/images/package_delete.png
komodo/SciViews-K/skin/images/package_go.png
komodo/SciViews-K/skin/images/package_green.png
komodo/SciViews-K/skin/images/standardGeneric.png
komodo/SciViews-K/skin/images/stop.png
komodo/SciViews-K/skin/images/toggle_close.png
komodo/SciViews-K/skin/images/toggle_open.png
Modified:
komodo/SciViews-K/content/js/robjects.js
komodo/SciViews-K/content/overlay.xul
komodo/SciViews-K/locale/en-GB/sciviewsk.dtd
komodo/SciViews-K/locale/fr-FR/sciviewsk.dtd
komodo/SciViews-K/skin/images/
komodo/SciViews-K/skin/images/array.png
komodo/SciViews-K/skin/images/character.png
komodo/SciViews-K/skin/images/data.frame.png
komodo/SciViews-K/skin/images/dist.png
komodo/SciViews-K/skin/images/empty.png
komodo/SciViews-K/skin/images/factor.png
komodo/SciViews-K/skin/images/filter.png
komodo/SciViews-K/skin/images/function.png
komodo/SciViews-K/skin/images/integer.png
komodo/SciViews-K/skin/images/list.png
komodo/SciViews-K/skin/images/logical.png
komodo/SciViews-K/skin/images/matrix.png
komodo/SciViews-K/skin/images/numeric.png
komodo/SciViews-K/skin/images/package.png
komodo/SciViews-K/skin/images/ts.png
komodo/SciViews-K/skin/sciviewsk.css
Log:
Rewritten, recursive R-objects list (requires svMisc::lsObj function).
Modified icons to match the "silk icon set" style.
Modified: komodo/SciViews-K/content/js/robjects.js
===================================================================
--- komodo/SciViews-K/content/js/robjects.js 2009-01-12 14:17:15 UTC (rev 90)
+++ komodo/SciViews-K/content/js/robjects.js 2009-01-12 15:37:03 UTC (rev 91)
@@ -1,227 +1,1191 @@
-// SciViews-K R objects functions
-// Define the 'sv.r.objects' namespace
-// Copyright (c) 2008, Romain Francois
-// Contribution from Philippe Grosjean
-
-////////////////////////////////////////////////////////////////////////////////
-// data objects:
-//
-// objectList // List of objects to display
-// searchPaths // List of search paths in R
-//
-//==============================================================================
-// functions :
-//
-// sv.r.objects.searchpath(); // Show/hide the search path listbox
-// sv.r.objects.getPackageList(); // Query R for the search path
-// sv.r.objects._processPackageList(data); // Callback to process this list
-// sv.r.objects.displayPackageList(goback); // Display the search path items
-// sv.r.objects.addObjectList(pack); // Get list of objects from R
-// sv.r.objects._processObjectList(data); // Callback to process list of objects
-// sv.r.objects.displayObjectList(goback); // Display the objects in the tree
-// sv.r.objects.packageSelectedEvent(event); // Process click event in the list
-// sv.r.objects.packageSelected(pack, status); // Change package selection
-// sv.r.objects.__isSelected(p); // Is a package selected?
-// sv.r.objects.__addPackageToSelection(p); // Add a package to the list of sel
-// sv.r.objects.__removePackageFromSelection(p); // Remove a package from sel
-//
-////////////////////////////////////////////////////////////////////////////////
-//
-// TODO:
-// Autorefresh of R Objects from R + do not refresh if R Objects is not visible
-// Remember the selection in the path list persitently
-// Tooltips for objects
-// Context menu calculated from R
-// Drag&drop of objects to a buffer
-////////////////////////////////////////////////////////////////////////////////
-
-// Define the 'sv.r.objects' namespace
-if (typeof(sv.r.objects) == 'undefined')
- sv.r.objects = {
- objectList: [],
- searchPaths: []
- }
-
-// Show/hide the search path listbox
-sv.r.objects.searchpath = function() {
- var split = document.getElementById("sciviews_robjects_splitter");
- var state = split.getAttribute("state");
- if (state == "collapsed") {
- state = "open";
- } else {
- state = "collapsed";
- }
- split.setAttribute("state", state);
-}
-
-// Get the list of packages on the search path from R
-sv.r.objects.getPackageList = function() {
- var cmd = 'cat(objSearch(sep = ",", compare = FALSE))';
- sv.r.evalCallback(cmd, sv.r.objects._processPackageList);
-};
-
-// Callback to process the list of packages in the search path from R
-sv.r.objects._processPackageList = function(data) {
- if (data == "") { return; } // No changes
- sv.r.objects.searchPaths = data.replace(/[\n\r]/g, "").split(/,/);
- sv.r.objects.displayPackageList();
-};
-
-// Display the list of packages in the search path
-sv.r.objects.displayPackageList = function(goback) {
- var pack;
- var node = document.getElementById("sciviews_robjects_searchpath_listbox");
- sv.tools.e4x2dom.clear(node);
-
- var item;
- var packs = sv.r.objects.searchPaths;
- var k = 0;
- var ischecked = "false";
- for(var i = 0; i < packs.length; i++) {
- pack = packs[i]
- if (sv.r.objects.__isSelected(pack)) {
- ischecked = "true";
- } else {
- ischecked = "false";
- }
- item =
- <listitem type="checkbox" label={pack} checked={ischecked}
- onclick="sv.r.objects.packageSelectedEvent(event)"
- spid={packs[i]}
- />;
- sv.tools.e4x2dom.append(item, node, k);
- k++;
- }
- sv.r.objects.displayObjectList(false);
-};
-
-// Ask R for the list of objects in an environment
-sv.r.objects.addObjectList = function(pack) {
- var id = sv.prefs.getString("sciviews.client.id", "SciViewsK");
- var cmd = 'cat(objList(id = "' + id + '_' + pack + '", envir = "' + pack +
- '", all.info = TRUE, sep = ",", compare = FALSE), sep = "\\n")';
- sv.r.evalCallback(cmd, sv.r.objects._processObjectList);
-};
-
-// Callback to process the list of objects in an environment
-sv.r.objects._processObjectList = function(data) {
- if (data == "") { return; } //no changes
- var lines = data.split("\n");
- var rx = /,/;
- var item, line;
- var pack;
- var idx;
-
- for (var i = 0; i < lines.length; i++) {
- if (rx.test(lines[i])) {
- line = lines[i].split(",");
- pack = line[0];
- if (sv.r.objects.objectList[pack] == undefined) {
- sv.r.objects.objectList[pack] = [];
- idx = 0;
- } else {
- idx = sv.r.objects.objectList[pack].length;
- }
- sv.r.objects.objectList[pack][idx] =
- new Array(line[1], line[2], line[3], line[4], line[5]);
- }
- }
- sv.r.objects.displayObjectList();
-};
-
-// Display the list of objects in the tree
-sv.r.objects.displayObjectList = function(goback) {
- var tb = document.getElementById("sciviews_robjects_filterbox");
- var obRx = new RegExp(tb.value);
-
- var node = document.getElementById("sciviews_robjects_objects_tree_main");
- sv.tools.e4x2dom.clear(node);
- // var k = 0;
- var currentPack;
- var currentFun;
-
- for (var pack in sv.r.objects.objectList) {
- currentPack = sv.r.objects.objectList[pack];
- item =
- <treeitem container="true" open="true">
- <treerow>
- <treecell label={pack} properties="package" />
- <treecell label="" />
- <treecell label="" />
- <treecell label="" />
- </treerow>
- <treechildren />
- </treeitem>;
- item.treechildren.treeitem = new XMLList();
- for (var i = 0; i < currentPack.length; i++) {
- currentFun = currentPack[i];
- if (obRx.test(currentFun[0])) {
- item.treechildren.treeitem +=
- <treeitem >
- <treerow>
- <treecell label={currentFun[0]}
- properties={currentFun[3].replace(".", "-" )} />
- <treecell label={currentFun[1]} />
- <treecell label={currentFun[2]} />
- <treecell label={currentFun[3]} />
- </treerow>
- </treeitem>;
- }
- }
- sv.tools.e4x2dom.appendTo(item, node);
- // k++;
- }
- if(goback) tb.focus();
-};
-
-// Change the display status of a package by clicking an item in the list
-sv.r.objects.packageSelectedEvent = function(event) {
- var cb = event.target;
- var status = cb.checked;
- var spid = cb.getAttribute("spid");
- sv.r.objects.packageSelected(spid, status);
-};
-
-// Process selection/deselection of packages
-sv.r.objects.packageSelected = function(pack, status) {
- if (status) {
- sv.r.objects.__addPackageToSelection(pack);
- } else {
- sv.r.objects.__removePackageFromSelection(pack);
- }
-};
-
-// Function that indicates whether a package is selected
-sv.r.objects.__isSelected = function(p) {
- for (var pack in sv.r.objects.objectList){
- if(pack == p) return(true);
- }
- return(false);
-};
-
-// Add content of package to the tree
-sv.r.objects.__addPackageToSelection = function(p) {
- if(sv.r.objects.debug) ko.statusBar.AddMessage("adding package" + p, "R", 5000, true)
- sv.r.objects.addObjectList(p);
-};
-
-// Remove content of the package from the tree
-sv.r.objects.__removePackageFromSelection = function(p) {
- if(sv.r.objects.debug) ko.statusBar.AddMessage("removing package" + p, "R", 5000, true)
- sv.r.objects.objectList = sv.tools.array.removeItem(sv.r.objects.objectList, p);
- sv.r.objects.displayObjectList();
-};
-
-// Make sure to check .GlobalEnv at the beginning
-// TODO: persitently save user's selection using Komodo mechanism
-// sv.r.objects.packageSelected(".GlobalEnv", true);
-
-sv.r.objects.debug = false ;
-
-sv.robjects.refreshPackage = function(pack){
- if( sv.r.objects.__isSelected(pack) ){
- // TODO: there is probably a better way
- sv.r.objects.packageSelected(".GlobalEnv", false);
- sv.r.objects.packageSelected(".GlobalEnv", true);
- }
-}
+//TODO: sort inserted child nodes, restoring natural order of sub-elements (add orderIndex property to inserted elements)
+//TODO: resolve filtering modes: should sub-object be filtered too?
+//TODO: quoting non-syntactic sub-names inserted into text
+//TODO: preserve opened sub-objects on refresh
+//TODO: context menu for search-paths list
+//TODO: "remove" command: Shift + Command - removes immediatelly (confirmation box first), Command - adds R code to the current document
+//TODO: renaming objects on the list - editable names
+
+
+//sv.r.objects = rObjectsTree;
+
+/*
+
+rObjectsTree properties and methods:
+TODO: complete this documentation, clean up the code
+
+visibleData - displayed data
+treeData - original tree data
+isInitialized
+atomSvc
+
+// functions/properties to implement 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
+getCellValue
+cycleHeader
+selectionChanged
+cycleCell
+performAction
+performActionOnCell
+getRowProperties
+getCellProperties
+getColumnProperties
+canDrop
+drop
+
+// other //
+
+iconTypes - icons to display
+filterBy
+createVisibleData - create visibleData from treeData
+sort
+applyFilter
+filter
+getFilter
+addVItems
+addVIChildren
+getVItem
+foldAll
+getSelectedRows
+
+toString - textual representation of the tree for debug purposes
+
+init - initialize
+refreshAll
+removeSelected
+getSelectedNames
+insertName
+setFilterBy
+
+// Event handling //
+contextOnShow
+do
+onEvent
+listObserver - drag & drop handler
+
+_parseObjectList
+_addObjectList
+_removeObjectList
+packageSelected
+_addSubObject, _parseSubObjectList - should be merged with _addObjectList and _parseObjectList
+
+// search path box methods: //
+
+getPackageList
+_processPackageList
+toggleViewSearchPath
+displayPackageList
+packageSelectedEvent
+packageListObserver
+packageListKeyEvent
+searchPaths
+
+*/
+
+
+
+var rObjectsTree = {
+ debug: false,
+ visibleData : [],
+ treeData: [],
+ isInitialized: false,
+
+ treeBox: null,
+ selection: null,
+
+ iconTypes: ['array', 'character', 'data.frame', 'Date', 'dist', 'empty',
+ 'factor', 'function', 'glm', 'integer', 'list', 'lm', 'lme',
+ 'logical', 'matrix', 'numeric', 'object', 'objects', 'package',
+ 'standardGeneric', 'S3', 'S4', 'ts', 'environment', 'formula'],
+
+ filterBy: 0, // filter by name by default
+
+ createVisibleData: function(){
+ if (!this.isInitialized) {
+ this.init();
+ return;
+ }
+
+ var rowsBefore = this.visibleData.length;
+ this.visibleData = [];
+ this.addVItems(this.treeData, -1, 0);
+ var rowsChanged = this.visibleData.length - rowsBefore;
+
+ if (rowsChanged) {
+ this.treeBox.rowCountChanged(0, rowsChanged);
+ }
+ this.treeBox.invalidateRange(this.treeBox.getFirstVisibleRow(),
+ this.treeBox.getLastVisibleRow());
+ },
+
+
+ sort: function(column) {
+ var columnName;
+ var tree = document.getElementById("sciviews_robjects_objects_tree");
+
+ var order = tree.getAttribute("sortDirection") == "ascending" ? 1 : -1;
+
+ try {
+ var currentElement = this.visibleData[this.selection.currentIndex].origItem;
+ } catch (e) {
+ var currentElement = null;
+ }
+
+ //if the column is passed and it's already sorted by that column, reverse sort
+ if (column) {
+ columnName = column.id;
+ if (tree.getAttribute("sortResource") == columnName) {
+ order *= -1;
+ }
+ } else {
+ columnName = tree.getAttribute("sortResource");
+ }
+
+ var colNames = ["r-name", "r-dims", "r-class", "r-group", "r-fullName"];
+ var sCol = colNames.indexOf(columnName);
+
+ var defaultSortCol = 0;
+ if (typeof(sCol) == "undefined")
+ sCol = 0;
+
+ if (typeof(order) == "undefined")
+ order = 1;
+
+ function _sortCompare(a, b) {
+ if (a.sortData[sCol] > b.sortData[sCol]) return 1 * order;
+ if (a.sortData[sCol] < b.sortData[sCol]) return -1 * order;
+
+ if (sCol != defaultSortCol) {
+ if (a.sortData[defaultSortCol] > b.sortData[defaultSortCol]) return 1;
+ if (a.sortData[defaultSortCol] < b.sortData[defaultSortCol]) return -1;
+ }
+ return 0;
+ }
+
+ function _sortCompareName(a, b) {
+ if (a.sortData[defaultSortCol] > b.sortData[defaultSortCol]) return 1;
+ if (a.sortData[defaultSortCol] < b.sortData[defaultSortCol]) return -1;
+ return 0;
+ }
+
+ function _sortRecursive(arr) {
+ arr.sort(_sortCompare);
+ for (var i in arr) {
+ if (typeof (arr[i].children) == "object") {
+ _sortRecursive(arr[i].children);
+ }
+ }
+ }
+
+ //setting these will make the sort option persist
+ tree.setAttribute("sortDirection", order == 1 ? "ascending" : "descending");
+ tree.setAttribute("sortResource", columnName);
+
+ var cols = tree.getElementsByTagName("treecol");
+ for (var i = 0; i < cols.length; i++) {
+ cols[i].removeAttribute("sortDirection");
+ }
+
+ document.getElementById(columnName).setAttribute("sortDirection", order == 1 ? "ascending" : "descending");
+
+ // sort packages always by name:
+ this.treeData.sort(_sortCompareName);
+ for (var i in this.treeData) {
+ if (typeof (this.treeData[i].children) == "object") {
+ _sortRecursive(this.treeData[i].children);
+ }
+ }
+
+ this.createVisibleData();
+
+ if (currentElement) {
+ this.selection.select(currentElement.index);
+ this.treeBox.ensureRowIsVisible(currentElement.index);
+ }
+ },
+
+ _parseObjectList: function(data, tv) {
+ // when used as a callback, this = window, have to use rObjectsTree instead
+
+ if (data == "") { return; } //no changes
+ var lines = data.split("\n");
+
+ var item, line, pack, idx;
+ var sep = ';';
+ var packIdx = [], packAdded = [];
+ for (var i = 0; i < rObjectsTree.treeData.length; i++) {
+ packIdx[i] = rObjectsTree.treeData[i].name;
+ }
+
+ var isList, dimNumeric, p, dim, dimRegExp = /^(\d+x)*\d+$/;
+
+ for (var i = 0; i < lines.length; i++) {
+ if (lines[i].indexOf(sep) != -1) {
+ line = lines[i].split(sep);
+
+ if (line.length < 4)
+ continue;
+
+ pack = line[0];
+ p = packIdx.indexOf(pack);
+
+ if (p == -1) { // create new top level branch
+ p = packIdx.push(pack) - 1;
+
+ rObjectsTree.treeData.push({
+ name: pack,
+ fullName: pack,
+ children: [],
+ type: "environment",
+ class: "package",
+ isOpen: true,
+ sortData: [pack.toLowerCase(), 0, "package", "package"],
+ index: -1,
+ parentObject: rObjectsTree.treeData
+ });
+ packAdded.push(pack);
+ } else if (packAdded.indexOf(pack) == -1) {
+ rObjectsTree.treeData[p].children = [];
+ packAdded.push(pack);
+ }
+
+ dimNumeric = 1;
+ if (dimRegExp.test(line[2])) {
+ dim = line[2].split('x');
+ for (var j in dim)
+ dimNumeric *= parseInt(dim[j]);
+ }
+ rObjectsTree.treeData[p].children.push({
+ name: line[1],
+ fullName: line[1],
+ dims: line[2],
+ group: line[3],
+ class: line[4],
+ list: line[5].trim() == "TRUE" || line[3] == "S4", // hack to enable browsing S4 objects slots
+ // TODO: change this in objList?
+ type: "object",
+ childrenLoaded: false,
+ isOpen: false,
+ env: pack,
+ sortData: [line[1].toLowerCase(), dimNumeric, line[4].toLowerCase(), line[3].toLowerCase()],
+ index: -1,
+ parentObject: rObjectsTree.treeData[p]
+ });
+ }
+ }
+
+ var currentElement = rObjectsTree.treeData[p];
+ rObjectsTree.sort();
+ if (packAdded.length == 1 && currentElement.index != -1)
+ rObjectsTree.treeBox.ensureRowIsVisible(currentElement.index);
+
+ },
+
+ _addObjectList: function(pack) {
+
+ pack = pack.replace("\\", "\\\\");
+
+ var id = sv.prefs.getString("sciviews.client.id", "SciViewsK");
+ //var cmd = 'cat(unlist(objList(id = "' + id + '_' + pack + '", envir = "' + pack +
+ // '", all.info = TRUE, sep = ";", compare = FALSE)), sep = "\\n")';
+
+ // for use with modified objList
+ var cmd = 'print(objList(id = "' + id + '_' + pack + '", envir = "' + pack +
+ '", all.info = TRUE, compare = FALSE), sep = ";", sep2 = "\\n")';
+
+ if (this.debug)
+ sv.cmdout.append(cmd);
+ sv.r.evalCallback(cmd, this._parseObjectList, this);
+ },
+
+ _removeObjectList: function(pack) {
+ for (var i = 0; i < this.treeData.length; i++) {
+ if (this.treeData[i].name == pack) {
+ this.treeData.splice(i, 1);
+ break;
+ }
+ }
+ this.createVisibleData();
+
+ },
+
+
+ packageSelected: function(pack, status) {
+ if (status) {
+ rObjectsTree._addObjectList(pack);
+ } else {
+ rObjectsTree._removeObjectList(pack);
+ }
+ },
+
+ _addSubObject: function(obj, idx) {
+ var objName = obj.origItem.name;
+ // objList does not quote non syntactic names, so we do it here:
+ if (
+ obj.level == 1
+ && objName.search(/^[a-z\.][\w\._]*$/i) == -1)
+ objName = "`" + objName + "`";
+ else
+ objName = obj.origItem.fullName;
+
+ var env = obj.origItem.env.replace("\\", "\\\\");
+
+ var cmd = 'cat(lsObj("' + objName + '", "' + env + '", sep = ";;"), sep="\\n")';
+
+ if (this.debug)
+ sv.cmdout.append(cmd);
+
+ sv.r.evalCallback(cmd, this._parseSubObjectList, obj);
+ },
+
+ _parseSubObjectList: function(data, obj) {
+ var sep = ';;';
+ if (data == "") { //no changes
+ obj.isContainer = false;
+ rObjectsTree.treeBox.invalidateRow(obj.origItem.index);
+ return;
+ }
+
+
+ var lines = data.split("\n");
+ var origItem = obj.origItem;
+ origItem.childrenLoaded = true;
+
+ var childType = origItem.group == "function"? "args" : "sub-object";
+ var dimNumeric, dim, dimRegExp = /^(\d+x)*\d+$/;
+
+ origItem.children = [];
+ for (var i = 0; i < lines.length; i++) {
+ if (lines[i].indexOf(sep) != -1) {
+ line = lines[i].split(sep);
+ if (line.length < 7)
+ continue;
+
+ dimNumeric = 1;
+ if (dimRegExp.test(line[3])) {
+ dim = line[3].split('x');
+ for (var j in dim)
+ dimNumeric *= parseInt(dim[j]);
+ }
+
+ origItem.children.push({
+ name: line[1],
+ fullName: line[2],
+ dims: line[3],
+ group: line[5],
+ class: line[4],
+ list: line[6].trim() == "TRUE",
+ type: childType,
+ childrenLoaded: false,
+ isOpen: false,
+ env: line[0],
+ sortData: [line[1].toLowerCase(), dimNumeric, line[4].toLowerCase(), line[5].toLowerCase()],
+ index: -1,
+ parentObject: origItem
+ });
+ }
+ }
+
+ obj.childrenLength = origItem.children.length;
+ rObjectsTree.toggleOpenState(origItem.index);
+ },
+
+ applyFilter: function() {
+ this.filter = this.getFilter();
+ this.createVisibleData();
+ },
+
+ filter: function(x) { return true; },
+ getFilter: function() {
+ var tb = document.getElementById("sciviews_robjects_filterbox");
+
+ var obRx, filterRegExp, test;
+
+ if (!tb.value)
+ return function(x) { return true; }
+
+ try {
+ obRx = new RegExp(tb.value, "i");
+ tb.className = "";
+ return function(x) { return (obRx.test(x)); }
+ } catch (e) {
+ obRx = tb.value;
+ tb.className = "badRegEx";
+ return function(x) { return(x.indexOf(obRx) > -1); }
+ }
+ },
+
+ addVItems: function(item, parentIndex, level, parentUid) {
+ if (typeof(item) == "undefined")
+ return(parentIndex);
+ if (typeof(level) == "undefined") level = -1;
+ if (!parentUid) parentUid = "";
+ if (!parentIndex) parentIndex = 0;
+
+ var idx = parentIndex;
+ var len = item.length;
+ var conditionalView;
+ var filterBy = this.filterBy;
+
+ for (var i = 0; i < len; i++) {
+ if (level == 1 && !this.filter(item[i].sortData[filterBy])) { //item[i].class != "package" &&
+ item[i].index = -1;
+ continue;
+ // set conditionalView = true if any child nodes pass fitering
+ //conditionalView = true;
+ } else {
+ //conditionalView = false;
+ }
+ idx++;
+ var vItem = this.getVItem(item[i], idx, level,
+ i == 0, i == len - 1,
+ parentIndex, parentUid);
+ this.visibleData[idx] = vItem;
+
+ if (vItem.isContainer && vItem.isOpen && vItem.childrenLength > 0) {
+ var idxBefore = idx;
+ idx = this.addVItems(item[i].children, idx, level + 1, vItem.uid + "»");
+
+ // no children is visible:
+ if (idxBefore == idx) {
+ vItem.isContainerEmpty = true;
+ // if this item was to be viewed on condition any children is visible, remove this item:
+ /*if (conditionalView) {
+ this.visibleData.pop();
+ idx--;
+ }*/
+ }
+ //print(idx + "<-" + idxBefore);
+ }
+ }
+
+ return idx;
+ },
+
+ // attaches one level list of child items to an item
+ addVIChildren: function(vItem, parentIndex, isOpen) {
+ var children = vItem.origItem.children;
+
+ vItem.isOpen = isOpen;
+
+ var len = children.length;
+ vItem.children = [];
+ var idx = parentIndex;
+ for (var i = 0; i < len; i++) {
+ if (vItem.level == 0 && !this.filter(children[i].name)) {
+ children[i].index = -1;
+ continue;
+ }
+ idx++;
+ vItem.children
+ .push(this.getVItem(children[i], idx, vItem.level + 1,
+ i == 0, i == len - 1,
+ isOpen? parentIndex : 0, // closed subtree elements have 0-based parentIndex
+ vItem.uid + "»"));
+ }
+
+ vItem.isContainerEmpty = vItem.children.length == 0;
+
+ },
+
+ getVItem: function(obj, index, level, first, last, parentIndex, parentUid) {
+ var vItem = {};
+
+ if (obj.group == "list" || obj.group == "function" || obj.list) {
+ vItem.isContainer = true;
+ vItem.isContainerEmpty = false;
+ vItem.childrenLength =
+ (typeof(obj.children) == "undefined")? 0 : obj.children.length;
+ vItem.isOpen = (typeof(obj.isOpen) != "undefined") && obj.isOpen;
+ vItem.isList = true;
+ } else {
+ vItem.isContainer = typeof(obj.children) != "undefined";
+ vItem.isContainerEmpty = vItem.isContainer && (obj.children.length == 0);
+ vItem.childrenLength = vItem.isContainer? obj.children.length : 0;
+ vItem.isList = false;
+ }
+ vItem.isOpen = (typeof(obj.isOpen) != "undefined") && obj.isOpen;
+
+ vItem.uid = parentUid + obj.name;
+ vItem.parentIndex = parentIndex;
+ vItem.level = level;
+ vItem.first = first;
+ vItem.last = last;
+ vItem.labels = [obj.name, obj.dims, obj.group, obj.class, obj.fullName];
+ vItem.origItem = obj;
+ vItem.origItem.index = index;
+
+ return vItem;
+ },
+
+
+ foldAll: function(open) {
+ if (!this.rowCount)
+ return;
+ var idx = this.selection.currentIndex;
+ if (idx == -1)
+ idx = 0;
+
+ var curItem = this.visibleData[idx].origItem;
+ var parentObject = curItem.parentObject;
+ if (parentObject) {
+ var siblings;
+ if (parentObject.children) {
+ siblings = parentObject.children;
+ } else {
+ siblings = parentObject;
+ }
+ for (var i = 0; i < siblings.length; i++) {
+ if (siblings[i].isOpen == open) {
+ this.toggleOpenState(siblings[i].index);
+ }
+ }
+ }
+ },
+
+ toggleOpenState: function(idx) {
+ var vd = this.visibleData;
+ var item = vd[idx];
+ if (!item) {
+ //print(idx);
+ return;
+ }
+
+ if (item.isList && !item.origItem.isOpen && !item.origItem.childrenLoaded) {
+ this._addSubObject(item, idx);
+ return;
+ }
+
+ var rowsChanged;
+
+ var iLevel = item.level;
+
+ if (!item.childrenLength) {
+ return;
+ }
+
+ if (item.origItem.isOpen) { // closing subtree
+ var k;
+ for (k = idx + 1; k < vd.length && vd[k].level > iLevel; k++) { }
+ rowsChanged = k - idx - 1;
+ item.children = vd.splice(idx + 1, rowsChanged);
+
+ // make parentIndexes of child rows relative:
+ for (var i = 0; i < item.children.length; i++) {
+ item.children[i].parentIndex -= idx;
+ }
+
+ // decrease parentIndexes of subsequent rows:
+ for (var i = idx + 1; i < vd.length; i++) {
+ if (vd[i].parentIndex > idx)
+ vd[i].parentIndex -= rowsChanged;
+ vd[i].origItem.index = i;
+ }
+
+
+ } else { // opening subtree
+ if (typeof(item.children) == "undefined") {
+ this.addVIChildren(item, idx, false);
+ }
+
+ // filter child items
+ var insertItems = [];
+ for (var i = 0; i < item.children.length; i++) {
+ //if (this.filter(item.children[i].origItem.name)) {
+ insertItems.push(item.children[i]);
+ //}
+ }
+
+ rowsChanged = insertItems.length;
+ // change parentIndexes of child rows from relative to absolute
+ for (var i = 0; i < insertItems.length; i++) {
+ insertItems[i].parentIndex += idx;
+ insertItems[i].origItem.index = i + idx + 1;
+ }
+
+ var vd2 = vd.slice(0, idx + 1).concat(insertItems, vd.slice(idx + 1));
+ // increase parentIndexes of subsequent rows:
+ for (var i = idx + 1 + insertItems.length; i < vd2.length; i++) {
+ if (vd2[i].parentIndex > idx)
+ vd2[i].parentIndex += rowsChanged;
+ vd2[i].origItem.index = i;
+ }
+ this.visibleData = vd2;
+ item.children = null;
+ }
+ item.origItem.isOpen = !item.origItem.isOpen;
+ if (rowsChanged)
+ this.treeBox.rowCountChanged(idx + 1, (item.origItem.isOpen? 1 : -1) * rowsChanged);
+
+ this.treeBox.invalidateRow(idx);
+ },
+
+ get rowCount() { return this.visibleData.length; },
+ setTree: function(treeBox) { this.treeBox = treeBox; },
+
+ setCellText: function(idx, col, value) {
+ this.visibleData[idx].labels[col.index] = value;
+ },
+ setCellValue: function(idx, col, value) {
+ },
+
+ getCellText: function(idx, column) {
+ return this.visibleData[idx].labels[column.index];
+ //+":" + this.visibleData[idx].level;
+ },
+ isContainer: function(idx) {
+ return this.visibleData[idx].isContainer;
+ },
+ isContainerOpen: function(idx) { return this.visibleData[idx].origItem.isOpen; },
+ isContainerEmpty: function(idx) { return this.visibleData[idx].isContainerEmpty; },
+ isSeparator: function(idx) { return false; },
+ isSorted: function() { return false; },
+ isEditable: function(idx, column) { return false; },
+
+ getParentIndex: function(idx) { return this.visibleData[idx].parentIndex; },
+ getLevel: function(idx) { return this.visibleData[idx].level; },
+ hasNextSibling: function(idx, after){ return !this.visibleData[idx].last; },
+ getImageSrc: function(row, col) {
+ if (col.index == 0) {
+ var Class = this.visibleData[row].origItem.class;
+ if (Class == "package" && this.visibleData[row].origItem.name.indexOf("package") != 0) {
+ Class = "package_green";
+ } else if (this.iconTypes.indexOf(Class) == -1) {
+ Class = this.visibleData[row].origItem.group;
+ if (this.iconTypes.indexOf(Class) == -1) {
+ return "";
+ }
+ }
+ return "chrome://sciviewsk/skin/images/" + Class + ".png";
+ } else
+ return "";
+ },
+
+ getProgressMode : function(idx,column) {},
+ getCellValue: function(idx, column) {},
+ cycleHeader: function(col, elem) {},
+ selectionChanged: function() {},
+ cycleCell: function(idx, column) {},
+ performAction: function(action) {},
+ performActionOnCell: function(action, index, column) { },
+ getRowProperties: function(idx, props) {
+ var item = this.visibleData[idx]
+ var origItem = item.origItem;
+
+ props.AppendElement(this.atomSvc.getAtom("type-" + origItem.type));
+ props.AppendElement(this.atomSvc.getAtom("class-" + origItem.class));
+
+ if (item.last) {
+ props.AppendElement(this.atomSvc.getAtom("lastChild"));
+ }
+ if (item.first) {
+ props.AppendElement(this.atomSvc.getAtom("firstChild"));
+ }
+ },
+ getCellProperties: function(idx, column, props) {
+ if (column.id == "r-name") {
+ props.AppendElement(this.atomSvc.getAtom("icon"));
+ var item = this.visibleData[idx]
+ var origItem = item.origItem;
+ props.AppendElement(this.atomSvc.getAtom("type-" + origItem.type));
+ props.AppendElement(this.atomSvc.getAtom("class-" + origItem.class));
+ props.AppendElement(this.atomSvc.getAtom("group-" + origItem.group));
+
+ }
+ },
+ getColumnProperties: function(column, element, prop) {},
+
+ toString: function() {
+ var vd = this.visibleData;
+ var ret = "", indent;
+ ret = "length: " + vd.length + "\n";
+ for (var i = 0; i < vd.length; i++) {
+ indent = ""; for (var j = 0; j < vd[i].level; j++) { indent += "+ "; }
+
+ ret += vd[i].origItem.index + indent + " ^"+ vd[i].parentIndex + "-> " + vd[i].uid + " (" + vd[i].name + ")" +
+ (vd[i].isContainer? "*" : "" )
+ + "\n";
+ }
+ return ret;
+ },
+
+ getSelectedRows: function() {
+ var start = new Object();
+ var end = new Object();
+ var rows = new Array();
+
+ var numRanges = this.selection.getRangeCount();
+ for (var t = 0; t < numRanges; t++){
+ this.selection.getRangeAt(t, start, end);
+ for (var v = start.value; v <= end.value; v++){
+ rows.push(v);
+ }
+ }
+ return(rows);
+ },
+
+ // Drag'n'drop support
+ listObserver: {
+ onDragStart: function (event, transferData, action) {
+ var namesArr = rObjectsTree.getSelectedNames(event.ctrlKey);
+ transferData.data = new TransferData();
+ transferData.data.addDataForFlavour("text/unicode", namesArr.join(', '));
+ return true;
+ }
+ },
+
+ canDrop: function() { return false; },
+ drop: function(idx, orientation) {},
+
+
+ init: function() {
+ this.atomSvc = Components.classes["@mozilla.org/atom-service;1"]
+ .getService(Components.interfaces.nsIAtomService);
+ this.visibleData = [];
+ this._addObjectList(".GlobalEnv");
+ this.getPackageList();
+ this.isInitialized = true;
+
+ document.getElementById("sciviews_robjects_objects_tree").view = rObjectsTree;
+ this.treeBox.scrollToRow(0);
+ }
+
+};
+
+// Get the list of packages on the search path from R
+rObjectsTree.getPackageList = function(refreshObjects) {
+ var cmd = 'cat(objSearch(sep = ";;", compare = FALSE))';
+ sv.r.evalCallback(cmd, rObjectsTree._processPackageList, refreshObjects);
+};
+
+// Callback to process the list of packages in the search path from R
+rObjectsTree._processPackageList = function(data, refreshObjects) {
+ if (data == "") { return; } // No changes
+ rObjectsTree.searchPaths = data.replace(/[\n\r]/g, "").split(";;");
+ rObjectsTree.displayPackageList(refreshObjects);
+};
+
+
+
+rObjectsTree.toggleViewSearchPath = function(event) {
+ var what = event.target.tagName;
+ var broadcaster = document.getElementById("cmd_robjects_viewSearchPath");
+ var box = document.getElementById(broadcaster.getAttribute("box"));
+
+ if (what == "splitter" || what == "grippy") {
+ var state = document.getElementById("sciviews_robjects_splitter")
+ .getAttribute("state");
+ broadcaster.setAttribute("checked", state != "collapsed");
+ } else {
+ box.collapsed = !box.collapsed;
+ broadcaster.setAttribute("checked", !box.collapsed);
+ broadcaster.setAttribute("state", box.collapsed? "collapsed" : "open");
+ }
+
+ if (!box.collapsed) {
+ if (!rObjectsTree.searchPaths.length) {
+ rObjectsTree.getPackageList();
+ }
+ }
+}
+
+
+// Display the list of packages in the search path
+rObjectsTree.displayPackageList = function(refreshObjects) {
+ 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(rObjectsTree.treeData.length);
+ for (var i = 0; i < selectedPackages.length; i++) {
+ selectedPackages[i] = rObjectsTree.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);
+ item.setAttribute("oncommand", "rObjectsTree.packageSelectedEvent(event);");
+
+ node.appendChild(item);
+ }
+
+ if (refreshObjects)
+ rObjectsTree.refreshAll();
+};
+
+
+// Change the display status of a package by clicking an item in the list
+rObjectsTree.packageSelectedEvent = function(event) {
+ var el = event.target;
+ var pack = el.getAttribute("label");
+ if (el.checked) {
+ this._addObjectList(pack);
+ } else {
+ this._removeObjectList(pack);
+ }
+ //print(el.checked);
+};
+
+
+rObjectsTree.refreshAll = function () {
+ var selectedPackages = new Array(rObjectsTree.treeData.length);
+ for (var i = 0; i < selectedPackages.length; i++)
+ selectedPackages[i] = rObjectsTree.treeData[i].name;
+
+ rObjectsTree.treeData = [];
+ sv.r.evalCallback('invisible(sapply(c("' + selectedPackages.join('","') + '"), function(x) cat(x, objList(envir = x, sep=";", all.info = TRUE, compare = FALSE), sep="\\n")))', rObjectsTree._parseObjectList);
+}
+
+rObjectsTree.removeSelected = function() {
+ var view = ko.views.manager.currentView;
+ if (!view)
+ return false;
+ view.setFocus();
+
+ var scimoz = view.scimoz;
+ var item, type, name, vItem, cmd = [];
+ var ObjectsToRm = {}, envToDetach = [];
+
+ var rows = this.getSelectedRows();
+
+ for (i in rows) {
+ vItem = this.visibleData[rows[i]];
+ item = vItem.origItem;
+ name = item.fullName;
+ type = item.type;
+
+ switch (type){
+ case "environment":
+ if (name != ".GlobalEnv" && name != "TempEnv") {
+ envToDetach.push(name);
+ cmd.push("detach(\"" + name + "\")");
+ }
+ break;
+ case "object":
+ case "sub-object":
+ var env = item.env;
+ thisItem:
+ if (envToDetach.indexOf(env) == -1) {
+ var parent = vItem;
+ while (parent && parent.parentIndex && parent.parentIndex != -1) {
+ parent = this.visibleData[parent.parentIndex].origItem;
+
+ if (!parent
+ || (ObjectsToRm[env] && (ObjectsToRm[env].indexOf(parent.fullName) != -1))
+ || (parent.type == "environment" && (envToDetach.indexOf(parent.name) != -1))) {
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/sciviews -r 91
More information about the Sciviews-commits
mailing list