[Sciviews-commits] r108 - in komodo/SciViews-K/content/js: . tools
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Feb 3 14:39:31 CET 2009
Author: prezez
Date: 2009-02-03 14:39:29 +0100 (Tue, 03 Feb 2009)
New Revision: 108
Modified:
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/js/tools/io.js
Log:
Various changes to sv.* functions.
New functions: sv.io.fileExists and sv.io.tempFile
Temporary file is now generated in Komodo without help of R.
Modified: komodo/SciViews-K/content/js/r.js
===================================================================
--- komodo/SciViews-K/content/js/r.js 2009-02-03 13:28:52 UTC (rev 107)
+++ komodo/SciViews-K/content/js/r.js 2009-02-03 13:39:29 UTC (rev 108)
@@ -139,51 +139,91 @@
}
// Set the current working directory (to current buffer dir, or ask for it)
-sv.r.setwd = function (ask) {
- var res = false;
+sv.r.setwd = function (dir, ask, type) {
+ // TODO: simplify this:
+ // for compatibility with previous versions
+ switch (arguments.length) {
+ case 1:
+ type = dir;
+ dir = null;
+ ask = false;
+ break;
+ case 2:
+ type = dir;
+ dir = null;
+ break;
+ default:
+ }
- var kv = ko.views.manager.currentView;
- if (!kv) {
- return false;
+ var getDirFromR = "";
+
+ if (!dir || (sv.io.fileExists(dir) == 2)) { // if dir doesn't exist or unspecified
+ //alert(dir + ":" + type)
+ checkType:
+ switch (type) {
+ case "this":
+ break;
+ case "session":
+ getDirFromR = "getOption(\"R.initdir\")";
+ //sv.r.eval(".odir <- setwd(getOption(\"R.initdir\"))");
+ break;
+ case "previous":
+ //sv.r.eval("if (exists(\".odir\")) .odir <- setwd(.odir); getwd()");
+ getDirFromR = "if (exists(\".odir\")) .odir else getwd()";
+ break;
+ case "init":
+ //sv.r.eval(".odir <- setwd(getOption(\"R.initdir\"))");
+ getDirFromR = "getOption(\"R.initdir\")";
+ break;
+ case "current":
+ getDirFromR = "getwd()";
+ ask = true; // assume ask is always true in shis case
+ break;
+ case "file":
+ var kv = ko.views.manager.currentView;
+ if (kv) {
+ kv.setFocus();
+ if (!kv.document.isUntitled) {
+ // if not, look for current file directory
+ dir = kv.document.file.dirName;
+ }
+ break;
+ }
+ case "project":
+ default:
+ dir = "";
+ // try to set current project dir ar default directory
+ var ap = ko.projects.manager.getCurrentProject();
+ var kv = ko.views.manager.currentView;
+ if (ap != null) {
+ dir = ko.projects.getDefaultDirectory(ap);
+ } else {
+ type = "file";
+ break checkType;
+ }
+ }
}
- kv.setFocus();
+ if (getDirFromR) {
+ var cmd = "cat(path.expand(" + getDirFromR + "))";
- if (ask == null) {
- if (!kv.document.isUntitled) {
- //alert("File is not saved yet. Unable to get its directory!");
- res = sv.r.eval(".odir <- setwd(\"" + kv.document.file.dirName.replace(/\\/g, "/") + "\")");
- res = true;
- }
- } else if (ask == "session") {
- res = sv.r.eval(".odir <- setwd(getOption(\"R.initdir\"))");
- res = true;
- } else if (ask == "previous") {
- res = sv.r.eval("if (exists(\".odir\")) .odir <- setwd(.odir); getwd()");
- res = true;
- }
+ sv.r.evalCallback(cmd, function(curDir) {
+ if (navigator.platform.search(/^Win/) == 0)
+ curDir = curDir.replace(/\//g, "\\");
+ sv.r.setwd(curDir, ask, "this");
+ });
+ return;
+ }
- if (!res){
- // try to set current project dir ar default directory
- var ap = ko.projects.manager.getCurrentProject();
- if (ap != null) {
- dir = ko.projects.getDefaultDirectory(ap);
- } else if (!kv.document.isUntitled) {
- // if not, look for current file directory
- dir = kv.document.file.dirName;
- } else {
- dir = "";
- }
-
+ if (ask || !dir) {
dir = ko.filepicker.getFolder(dir, "Choose working directory");
+ }
- if (dir != null) {
- res = sv.r.eval(".odir <- setwd(\"" + dir.replace(/\\/g, "/") + "\")");
- }
- res = true;
- }
-
- return res;
+ if (dir != null) {
+ sv.r.evalHidden(".odir <- setwd(\"" + dir.replace(/\\/g, "\\\\") + "\")");
+ sv.cmdout.message("Current R's working directory is: \"" + dir + "\"", 10000);
+ }
+ return;
}
// Run current selection or line buffer in R
@@ -253,7 +293,8 @@
var file = kv.document.file.path.replace(/\\/g, "/");
- if (what == null) what = "all"; // Default value
+ if (!what)
+ what = "all"; // Default value
// Special case: if "all" and document is saved, source the original file
if (what == "all" && !(kv.document.isUntitled || kv.document.isDirty)) {
@@ -263,23 +304,19 @@
// else, save all or part in the temporary file and source that file.
// After executing, tell R to delete it.
var code = (what == "all")? ke.text : sv.getTextRange(what);
- sv.cmdout.clear();
- sv.cmdout.append(':> source("' + file + '*") # unsaved buffer: ' + what);
+ //sv.cmdout.clear();
+ sv.cmdout.append(':> source("' + file + '*") # unsaved buffer (' + what + ')');
- sv.r.evalCallback(
- // ask R about temporary filename. There should be easier way to do it.
- "cat(tempfile('sv'))",
- function(file, text) {
- sv.io.writefile(file, text, 'utf-8', false);
+ var tempFile = sv.io.tempFile();
+ sv.io.writefile(tempFile, code, 'utf-8', false);
+ tempFile = tempFile.replace(/\\/g, "\\\\");
- file = file.replace(/\\/g, "/");
- res = sv.r.evalCallback(
- 'source("' + file + '", encoding = "utf-8"); unlink("' + file + '");',
- sv.cmdout.append
- );
- },
- code);
+ var cmd = 'source("' + tempFile + '", encoding = "utf-8");\nunlink("' + tempFile + '");';
+ sv.r.evalCallback(cmd, function(data) {
+ sv.cmdout.append(sv.tools.strings.removeLastCRLF(data));
+ sv.cmdout.append(":>");
+ });
}
} catch(e) {
return e;
@@ -290,6 +327,9 @@
// Send whole or a part of the current buffer to R
// place cursor at next line
sv.r.send = function(what) {
+ sv.cmdout.message("sv.r.send "+what, 3000);
+ //alert("sv.r.send "+what);
+
var res = false;
var kv = ko.views.manager.currentView;
if (!kv)
@@ -303,9 +343,11 @@
var code = sv.getTextRange(what, true);
if (code) {
+ // indent multiline commands to make the output look nicer
+ code = code.replace(/\r?\n/g, "\n ")
res = sv.r.eval(code);
}
- if (what == "line" || what == "linetoend" || what == "para")
+ if (what == "line" || what == "linetoend") // || what == "para"
ke.charRight();
} catch(e) {
Modified: komodo/SciViews-K/content/js/robjects.js
===================================================================
--- komodo/SciViews-K/content/js/robjects.js 2009-02-03 13:28:52 UTC (rev 107)
+++ komodo/SciViews-K/content/js/robjects.js 2009-02-03 13:39:29 UTC (rev 108)
@@ -1,1239 +1,1249 @@
-//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: renaming objects on the list - editable names
-
-//"remove" command: Shift + Command - removes immediatelly (confirmation box first), Command - adds R code to the current document
-
-
-//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 - not really needed
-getCellValue
-cycleHeader
-selectionChanged
-cycleCell - not really needed
-performAction
-performActionOnCell
-getRowProperties
-getCellProperties
-getColumnProperties
-canDrop - always false
-drop - not needed so far
-
-// 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,
- //debug: true,
- 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 == "" || (data.trim() == "An empty objects list") )
- return; //no changes
-
- var lines = data.split(/\r?\n/);
-
- // get rid of the "Objects list:" line
- if (lines[0].indexOf("Objects list:") != -1)
- lines.shift()
-
- 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] == "TRUE",
- 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) {
- // need this for attached files on windows:
- pack = pack.replace("\\", "\\\\");
-
- var id = sv.prefs.getString("sciviews.client.id", "SciViewsK");
-
- // for use with modified objList
- var cmd = 'print(objList(id = "' + id + '_' + pack + '", envir = "' + pack +
- '", all.info = TRUE, compare = FALSE), sep = ";", eol = "\\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) {
- 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 id = sv.prefs.getString("sciviews.client.id", "SciViewsK");
-
- var cmd = 'print(objList(id = "' + id + '_' + env + '_' + objName + '", envir = "' + env +
- '", object = "' + objName + '", all.info = FALSE, compare = FALSE), sep = ";;", eol = "\\n")';
-
-
- if (this.debug)
- sv.cmdout.append(cmd);
-
- sv.r.evalCallback(cmd, this._parseSubObjectList, obj);
- },
-
- _parseSubObjectList: function(data, obj) {
- var sep = ';;';
-
- var lines = data.split(/\r?\n/);
-
- if (data == "" || (data.trim() == "An empty objects list") || lines.length < 4) {
- obj.isContainer = false;
- rObjectsTree.treeBox.invalidateRow(obj.origItem.index);
- return;
- }
-
- // get rid of the "Objects list:" line
- if (lines[0].indexOf("Objects list:") != -1)
- lines.shift()
-
- var env = lines[0].substr(lines[0].lastIndexOf("=") + 1).trim(); // Environment - 1st line
- var treeParent = lines[1].substr(lines[1].lastIndexOf("=") + 1).trim(); // parent object - 2ng line
-
- var vd = rObjectsTree.visibleData;
- if (!obj) { // reloading sub-lists without passing parent tree item - not used yet
- if (treeParent) {
- // TODO: smarter way to do it than searching through all items
- for (var i = 0; i < vd.length; i++) {
- if (vd[i].origItem.env == env && vd[i].orgItem.fullName == treeParent) {
- obj = vd[i];
- break;
- }
- }
- } else {
- // TODO: search for pkgs on top level
- }
- }
-
- 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 = 2; i < lines.length; i++) {
- if (lines[i].indexOf(sep) != -1) {
- line = lines[i].split(sep);
- if (line.length < 6)
- continue;
-
- dimNumeric = 1;
- if (dimRegExp.test(line[3])) {
- dim = line[2].split(/x/);
- for (var j in dim)
- dimNumeric *= parseInt(dim[j]);
- }
-
- origItem.children.push({
- name: line[0],
- fullName: line[1],
- dims: line[2],
- group: line[3],
- class: line[4],
- list: line[5] == "TRUE",
- type: childType,
- childrenLoaded: false,
- isOpen: false,
- env: env,
- sortData: [line[0].toLowerCase(), dimNumeric, line[4].toLowerCase(), line[3].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);
- 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;
-
- if (selectedPackages.length == 0)
- selectedPackages.push('.GlobalEnv');
-
- // for use with modified objList
- var cmd = 'invisible(sapply(c("' + selectedPackages.join('","') + '"), function(x) print(objList(envir = x, all.info = TRUE, compare = FALSE), sep = ";")))';
- sv.r.evalCallback(cmd, rObjectsTree._parseObjectList);
-
-}
-
-rObjectsTree.removeSelected = function(doRemove) {
- var view = ko.views.manager.currentView;
- if (!view)
- return false;
- view.setFocus();
-
- var scimoz = view.scimoz;
- var item, type, name, vItem, cmd = [];
- var rmItems = {}, ObjectsToRemove = {}, envToDetach = [], ObjectsToSetNull = {};
-
- 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);
- 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
- || (rmItems[env] && (rmItems[env].indexOf(parent.fullName) != -1))
- || (parent.type == "environment" && (envToDetach.indexOf(parent.name) != -1))) {
- break thisItem;
- }
-
- }
- if (typeof rmItems[env] == "undefined")
- rmItems[env] = [];
-
- rmItems[env].push(name);
-
- if (type == "sub-object") {
- if (typeof ObjectsToSetNull[env] == "undefined")
- ObjectsToSetNull[env] = [];
-
- ObjectsToSetNull[env].push(name);
-
- } else {
- if (typeof ObjectsToRemove[env] == "undefined")
- ObjectsToRemove[env] = [];
- ObjectsToRemove[env].push(name);
- }
-
- var siblings = item.parentObject.children;
- for (var j in siblings) {
- if (siblings[j] == item) {
- siblings.splice(j, 1);
- break;
- }
- }
- }
- break;
- default:
- }
- }
-
- this.createVisibleData();
-
-
-
- for (i in envToDetach)
- cmd.push('detach("' + envToDetach[i] + '")');
-
- for (var env in ObjectsToRemove)
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/sciviews -r 108
More information about the Sciviews-commits
mailing list