[Sciviews-commits] r456 - komodo/SciViews-K/content komodo/SciViews-K/content/js komodo/SciViews-K/skin pkg/svMisc pkg/svMisc/R pkg/svMisc/man pkg/svTools/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Mar 4 23:36:41 CET 2012


Author: phgrosjean
Date: 2012-03-04 23:36:41 +0100 (Sun, 04 Mar 2012)
New Revision: 456

Added:
   komodo/SciViews-K/content/pkgman.xbl
   komodo/SciViews-K/content/pkgman.xul
   komodo/SciViews-K/skin/pkgman.css
   pkg/svMisc/R/pkgMan.R
   pkg/svMisc/man/pkgMan.Rd
Removed:
   komodo/SciViews-K/content/RPkgManager.xul
   komodo/SciViews-K/skin/pkgManager.css
Modified:
   komodo/SciViews-K/content/js/commands.js
   komodo/SciViews-K/skin/.DS_Store
   komodo/SciViews-K/skin/sciviewsk.css
   pkg/svMisc/DESCRIPTION
   pkg/svMisc/NAMESPACE
   pkg/svMisc/NEWS
   pkg/svMisc/R/parseText.R
   pkg/svMisc/R/rjson.R
   pkg/svMisc/man/pkg.Rd
   pkg/svMisc/man/rjson.Rd
   pkg/svTools/R/packages.R
Log:
Incorporation of SciViews-K-dev changes into SciViews-K, R package manager (part VIII)

Deleted: komodo/SciViews-K/content/RPkgManager.xul
===================================================================
--- komodo/SciViews-K/content/RPkgManager.xul	2012-03-03 17:27:07 UTC (rev 455)
+++ komodo/SciViews-K/content/RPkgManager.xul	2012-03-04 22:36:41 UTC (rev 456)
@@ -1,394 +0,0 @@
-<?xml version="1.0"?>
-<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0/LGPL 2.1
-
- The contents of this file are subject to the Mozilla Public License
- Version 1.1 (the "License"); you may not use this file except in
- compliance with the License. You may obtain a copy of the License at
- http://www.mozilla.org/MPL/
-
- Software distributed under the License is distributed on an "AS IS"
- basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- License for the specific language governing rights and limitations
- under the License.
-
- The Original Code is SciViews-K by Philippe Grosjean et al.
-
- Contributor(s):
-   Kamil Barton
-   ActiveState Software Inc (code inspired from)
-
- Alternatively, the contents of this file may be used under the terms of
- either the GNU General Public License Version 2 or later (the "GPL"), or
- the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- in which case the provisions of the GPL or the LGPL are applicable instead
- of those above. If you wish to allow use of your version of this file only
- under the terms of either the GPL or the LGPL, and not to allow others to
- use your version of this file under the terms of the MPL, indicate your
- decision by deleting the provisions above and replace them with the notice
- and other provisions required by the GPL or the LGPL. If you do not delete
- the provisions above, a recipient may use your version of this file under
- the terms of any one of the MPL, the GPL or the LGPL.
-
- ***** END LICENSE BLOCK ***** -->
-
-<!DOCTYPE overlay PUBLIC "-//MOZILLA//DTD XUL V1.0//EN"
-"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
-
-<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
-<?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?>
-<?xml-stylesheet href="chrome://komodo/skin/bindings/buttons.css" type="text/css"?>
-<?xml-stylesheet href="chrome://komodo/skin/bindings/sidebar.css" type="text/css"?>
-<?xml-stylesheet href="chrome://komodo/skin/" type="text/css"?>
-<?xml-stylesheet href="chrome://komodo/skin/global/global.css" type="text/css"?>
-<?xml-stylesheet href="chrome://komodo/skin/bindings/scrolltabs.css" type="text/css"?>
-<?xml-stylesheet href="chrome://sciviewsk/skin/pkgManager.css" type="text/css"?>
-
-<window id="RPackageManager" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
-	height="500" width="500" persist="width height"
-	style="min-height: 500px; min-width: 500px;" title="Manage R Packages">
-
-<script type="text/javascript">
-<![CDATA[
-//TODO: 	use xbl bindings
-// 		list of available packages at CRAN
-// 		repository selection + custom repositories
-// 		installing packages - to be finished
-// 		add pkgManager() common function for svMisc - wrap commands into it
-
-var sv;
-var packages = {};
-
-function pkgLoadToggle (pkg, button) {
-		var item = document.getElementById(pkg);
-		var loaded = item.getAttribute("loaded") == "true";
-		var cmd = loaded? "detach(package:" + pkg + ")" :
-				"library(" + pkg + ")";
-
-		button.setAttribute("label", (loaded? "Detaching" : "Loading") + " package...");
-		button.setAttribute("disabled", "true");
-
-		// sv.log.debug(loaded + cmd);
-
-		sv.r.evalCallback(cmd, function(data) {
-				sv.cmdout.append(":> " + cmd);
-				sv.cmdout.append(data);
-				reloadList();
-		}, cmd);
-}
-
-function pkgRemove (pkg, button) {
-		var item = document.getElementById(pkg);
-		var loaded = item.getAttribute("loaded") == "true";
-		var cmd = 'remove.packages("' + pkg + '", lib = installed.packages()["' +
-				pkg + '", "LibPath"])';
-
-		button.setAttribute("label", "Removing package...");
-		button.setAttribute("disabled", "true");
-
-		sv.r.evalCallback(cmd, function(data) {
-				sv.cmdout.append(":> " + cmd);
-				sv.cmdout.append(data + "\n:> \n");
-				reloadList();
-		}, cmd);
-}
-
-function pkgUpdate () {
-		var theUpdatesList = document.getElementById("TheUpdatesList");
-		var x = theUpdatesList.getElementsByTagName("checkbox");
-		var toBeUpdated = [];
-		for (var i = 0; i < x.length; i++) {
-				if (x[i].checked)
-						toBeUpdated.push(x[i].getAttribute("package"));
-		}
-}
-
-function addcslashes (str, charlist) {
-		str = str.replace(
-				new RegExp('([' + charlist.replace(/([\[\]\(\)\\])/g, "\\$1") + '])', "g"),
-				"\\$1");
-
-		if (charlist.indexOf("\n") >-1)
-				str = str.replace(/\n/g, "n");
-		if (charlist.indexOf("\t") >-1)
-				str = str.replace(/\t/g, "t");
-		if (charlist.indexOf("\f") >-1)
-				str = str.replace(/\f/g, "f");
-		if (charlist.indexOf("\r") >-1)
-				str = str.replace(/\r/g, "r");
-		if (charlist.indexOf("\0") >-1)
-				str = str.replace(/\000/g, "0");
-		return str;
-}
-
-function reloadList () {
-
-		var theList = document.getElementById("TheList");
-		sv.r.evalCallback('pkgManList()', function (data) {
-				data = data.replace(/\r\n/g, "\n");
-				data = data.split(/\n{2,4}/);
-
-				var selectIdx = theList.selectedIndex;
-
-				var newPackages = [], pkgs = [], pkg, name, required, loaded;
-
-				for (i in data) {
-						pkg = data[i].split("\t");
-						if (pkg.length < 6)
-							break;
-						pkgs[i] = pkg;
-						newPackages.push(pkg[0]);
-				}
-
-				var items = theList.childNodes;
-
-				var j, curItem;
-				for (var i = 0; i < items.length; i++) {
-						curItem = theList.getItemAtIndex(i);
-						j = newPackages.indexOf(curItem.id);
-						if (j == -1) {
-								theList.removeChild(curItem);
-						} else {
-								theList.replaceChild(getRichListItem(pkgs[j]), curItem);
-						}
-				}
-
-				for (var i = 0; i < newPackages.length; i++) {
-						if (i + 1 > theList.itemCount) {
-								theList.appendChild(getRichListItem(pkgs[i]));
-						} else if (items[i].id != newPackages[i]) {
-								theList.insertBefore(getRichListItem(pkgs[i]), theList.getItemAtIndex(i));
-						}
-				}
-
-				theList.removeAttribute("empty");
-				if (selectIdx != -1) {
-						if (selectIdx + 1 > theList.itemCount)
-								selectIdx = theList.itemCount - 1;
-						theList.selectItem(theList.getItemAtIndex(selectIdx))
-				}
-
-				//
-				//for (i in data) {
-				//	  pkg = data[i].split("\t");
-				//	  theList.appendChild(getRichListItem(pkg));
-				//}
-
-		});
-}
-
-function getRichListItem (pkg) {
-		name = pkg[0];
-		required = pkg[4] == "TRUE";
-		loaded = pkg[3] == "TRUE";
-
-		var item = document.createElement("richlistitem");
-		item.setAttribute("name", name);
-		item.setAttribute("id", name);
-		item.setAttribute("loaded", loaded );
-		item.setAttribute("required", required && loaded);
-		item.setAttribute("flex", "1");
-		var vbox = item.appendChild(document.createElement("vbox"));
-		vbox.setAttribute("flex", "1");
-		var titleEl = vbox.appendChild(document.createElement("description"));
-
-		titleEl.className = "title";
-		titleEl.setAttribute("value", name + " (" + pkg[1] + ")");
-
-		var descrEl = vbox.appendChild(document.createElement("description"));
-		descrEl.className = "description";
-		descrEl.setAttribute("crop", "end");
-		descrEl.setAttribute("value", pkg[2].replace(/\n/g, " "));
-
-		var descrFullEl = vbox.appendChild(document.createElement("description"));
-		descrFullEl.className = "description-full";
-		descrFullEl.appendChild(document.createTextNode(pkg[2]));
-
-		var buttonBox = vbox.appendChild(document.createElement("hbox"));
-
-		buttonBox.appendChild(document.createElement("spacer"));
-		buttonBox.setAttribute("flex", "1");
-		buttonBox.setAttribute("align", "right");
-		buttonBox.className = "buttons";
-
-		var button = buttonBox.appendChild(document.createElement("button"));
-		button.setAttribute("label", loaded? "Detach package" : "Load package");
-		//if (required && loaded)
-		//	  button.setAttribute("disabled", "true");
-
-		button.setAttribute("oncommand", "pkgLoadToggle(\""+ pkg[0] + "\", this);");
-		//button.oncommand = ;
-		var button2 = buttonBox.appendChild(document.createElement("button"));
-		button2.setAttribute("label", "Remove package");
-		button2.setAttribute("oncommand", "pkgRemove(\""+ pkg[0] + "\", this);");
-		return (item);
-}
-
-function getUpdateItem (pkg) {
-		var name = pkg[0];
-		var ver = pkg[1];
-		var newVer = pkg[3];
-
-		var item = document.createElement("richlistitem");
-		item.setAttribute("name", "update-" + name);
-		item.setAttribute("id", "update-" + name);
-		item.setAttribute("update", true);
-
-		item.setAttribute("flex", "1");
-		var vbox = item.appendChild(document.createElement("vbox"));
-		vbox.setAttribute("flex", "1");
-
-		var titlebox = vbox.appendChild(document.createElement("hbox"));
-		titlebox.setAttribute("flex", "1");
-
-		var titleEl = titlebox.appendChild(document.createElement("description"));
-		titleEl.className = "title";
-		titleEl.setAttribute("value", name);
-
-		var spacer = titlebox.appendChild(document.createElement("spacer"));
-		spacer.setAttribute("flex", "1");
-
-		verEl = titlebox.appendChild(document.createElement("description"));
-		verEl.className = "version";
-		verEl.setAttribute("value", ver);
-
-		//var descrEl = vbox.appendChild(document.createElement("description"));
-		//descrEl.className = "description";
-		//descrEl.setAttribute("crop", "end");
-		//descrEl.setAttribute("value", "Installed version: " + ver + ")");
-
-		var descrEl = vbox.appendChild(document.createElement("description"));
-		//descrEl.className = "description";
-		descrEl.setAttribute("crop", "end");
-		descrEl.setAttribute("value", "Version " + newVer + " is available");
-
-		var buttonBox = vbox.appendChild(document.createElement("hbox"));
-		buttonBox.appendChild(document.createElement("spacer"));
-		buttonBox.setAttribute("flex", "1");
-		buttonBox.setAttribute("align", "right");
-		buttonBox.className = "buttons";
-
-		var button = buttonBox.appendChild(document.createElement("checkbox"));
-		button.setAttribute("label", "Update this package");
-		button.setAttribute("checked", "true");
-		button.setAttribute("package", name);
-		//button.setAttribute("oncommand", "pkgUpdate(\""+ pkg[0] + "\", this);");
-		button.setAttribute("oncommand", "document.getElementById('update-"+name+"').setAttribute(\"update\", this.checked);");
-
-		return (item);
-}
-
-function pkgFindUpdates () {
-		var sep = ";;";
-		var cmd = 'write.table(svtmp.updatePkgs()[,-2], sep="' + sep + '", quote=FALSE, na="", eol="\n", row.names = FALSE, col.names = FALSE)';
-
-		var theList = document.getElementById("TheList");
-		var theUpdatesList = document.getElementById("TheUpdatesList");
-		while(theUpdatesList.firstChild) {
-				theUpdatesList.removeChild(theUpdatesList.firstChild);
-		}
-		sv.r.evalCallback(cmd, function (data) {
-				//sv.cmdout.clear();
-				sv.cmdout.append(data);
-
-				var lines = data.split(/\r?\n/);
-				var items, name, el, updateInfo, pkg;
-				for (var i in lines) {
-						pkg = lines[i].split(sep);
-						name = pkg[0];
-						//el = document.getElementById(name);
-						//updateInfo = el.appendChild(document.createElement("label"));
-						//updateInfo.setAttribute("value", "New version available: " + pkg[3]);
-						//theUpdatesList.appendChild(el.cloneNode(true));
-						//var uItem = el.appendChild(getUpdateItem(pkg));
-						theUpdatesList.appendChild(getUpdateItem(pkg));
-				}
-				//document.getElementById("pkgPanels").selectedIndex = 2;
-				document.getElementById("pkgPanelButtons").childNodes[2].click();
-
-				//ade4;;1.4-9;;2.8.0;;1.4-10;;http://r.meteo.uni.wroc.pl/bin/windows/contrib/2.8
-		});
-}
-
-self.onload = function () {
-		var args = window.arguments;
-		if (args) {
-			sv = args[0];
-		} else {
-			var p = parent;
-			while (p.opener && (p = p.opener) && !sv) if (p.sv) sv = p.sv;
-		}
-
-		var file = sv.tools.file.path("ProfD", "extensions", "sciviewsk at sciviews.org",
-							"defaults", "pkgMan.R").replace(/\\/g, "/");
-
-		sv.r.evalCallback("source(\"" + file + "\")", function(data) {
-			reloadList();
-		});
-}
-
-]]>
-	</script>
-
-	<script>
-	function richSelect(aControl) {
-			//document.getElementById("selection-name").value = aControl.selectedItem ? aControl.selectedItem.getAttribute("name") : "";
-			// document.getElementById("selection-index").value = aControl.selectedIndex;
-	}
-	</script>
-
-	<hbox>
-		<radiogroup id="pkgPanelButtons" orient="horizontal" disabled="true">
-			<radio label="Available"
-				oncommand="document.getElementById('pkgPanels').selectedIndex = 0;"/>
-			<radio label="Installed" selected="true"
-				oncommand="document.getElementById('pkgPanels').selectedIndex = 1;"/>
-			<radio label="Updates"
-				oncommand="document.getElementById('pkgPanels').selectedIndex = 2;"/>
-		</radiogroup>
-		<spacer flex = "2"/>
-		<button label="Close" onclick="self.close();"/>
-	</hbox>
-
-	<vbox style="font-weight:bold; background-color: #feac01; border: 1px black solid; margin: 2px; padding: 3px;">
-<description>
-    This package manager is an experimental feature of SciViews-K. It is not fully functional yet.
-</description>
-</vbox>
-
-	<deck id="pkgPanels" flex="1" style="padding: 0px; border: none;"
-		selectedIndex="1" persists="selectedIndex">
-
-		<box><!-- tabpanel First elements go here --></box>
-
-		<box>
-			<!--<notificationbox flex="1">-->
-			<vbox flex="1">
-				<hbox flex="5">
-					<richlistbox id = "TheList" onselect="richSelect(this)" flex="1"/>
-				</hbox>
-				<hbox align="left" flex="1" maxheight="20">
-					<button label="Find updates" accesskey="F"
-						oncommand="pkgFindUpdates();" align="left"
-						 disabled="true" />
-					<spacer flex="1"/>
-				</hbox>
-			</vbox>
-			<!--</notificationbox>-->
-		</box>
-
-		<box>
-			<vbox flex="1">
-				<hbox flex="5">
-					<richlistbox id = "TheUpdatesList" flex="1"
-						onselect="this.selectedItem.getElementsByTagName('checkbox')[0].focus();"/>
-				</hbox>
-				<hbox align="left" flex="1" maxheight="20">
-					<button label="Install updates" accesskey="I" oncommand=""
-						align="left" disabled="disabled"/>
-					<spacer flex="1"/>
-				</hbox>
-			</vbox>
-		</box>
-	</deck>
-</window>

Modified: komodo/SciViews-K/content/js/commands.js
===================================================================
--- komodo/SciViews-K/content/js/commands.js	2012-03-03 17:27:07 UTC (rev 455)
+++ komodo/SciViews-K/content/js/commands.js	2012-03-04 22:36:41 UTC (rev 456)
@@ -316,9 +316,9 @@
 	}
 
 	this.openPkgManager = function () {
-		var win = _getWindowRef("chrome://sciviewsk/content/RPkgManager.xul",
+		var win = _getWindowRef("chrome://sciviewsk/content/pkgman.xul",
 			"RPkgMgr", "chrome=yes,dependent" +
-			"scrollbars=yes,status=no,close,dialog=no", true, sv);
+			"scrollbars=yes,status=no,close,dialog=no, resizable", true, sv);
 		return(win);
 	}
 

Added: komodo/SciViews-K/content/pkgman.xbl
===================================================================
--- komodo/SciViews-K/content/pkgman.xbl	                        (rev 0)
+++ komodo/SciViews-K/content/pkgman.xbl	2012-03-04 22:36:41 UTC (rev 456)
@@ -0,0 +1,266 @@
+<?xml version="1.0"?>
+<!-- ***** BEGIN LICENSE BLOCK *****
+ Version: MPL 1.1/GPL 2.0/LGPL 2.1
+
+ The contents of this file are subject to the Mozilla Public License
+ Version 1.1 (the "License"); you may not use this file except in
+ compliance with the License. You may obtain a copy of the License at
+ http://www.mozilla.org/MPL/
+
+ Software distributed under the License is distributed on an "AS IS"
+ basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ License for the specific language governing rights and limitations
+ under the License.
+
+ The Original Code is SciViews-K by Kamil Barton
+
+ Contributor(s):
+   Kamil Barton
+
+ Alternatively, the contents of this file may be used under the terms of
+ either the GNU General Public License Version 2 or later (the "GPL"), or
+ the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ in which case the provisions of the GPL or the LGPL are applicable instead
+ of those above. If you wish to allow use of your version of this file only
+ under the terms of either the GPL or the LGPL, and not to allow others to
+ use your version of this file under the terms of the MPL, indicate your
+ decision by deleting the provisions above and replace them with the notice
+ and other provisions required by the GPL or the LGPL. If you do not delete
+ the provisions above, a recipient may use your version of this file under
+ the terms of any one of the MPL, the GPL or the LGPL.
+
+ ***** END LICENSE BLOCK ***** -->
+<!DOCTYPE bindings [
+  <!ENTITY % brandDTD SYSTEM "chrome://branding/locale/brand.dtd" >
+  %brandDTD;
+]>
+
+<bindings id="kbBlaStuff"
+  xmlns="http://www.mozilla.org/xbl"
+  xmlns:xbl="http://www.mozilla.org/xbl"
+  xmlns:html="http://www.w3.org/1999/xhtml"
+  xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+
+	<binding id="pkg-item"
+		extends="chrome://global/content/bindings/richlistbox.xml#richlistitem">
+    <resources>
+			<stylesheet src="chrome://global/skin/"/>
+    </resources>
+
+		<content minheight="30">
+			<xul:vbox style="border: 0 blue solid;" flex="1">
+				<xul:hbox class="addon-name-version">
+					<xul:label anonid="title" class="title addonName"
+						xbl:inherits="value=label"/>
+					<xul:label anonid="version" class="version addonVersion"
+						xbl:inherits="value=version" align="right"/>
+					<xul:label anonid="installedVersion"
+						xbl:inherits="value=installedVersion"/>
+				</xul:hbox>
+			
+				<xul:description class="description" crop="end" xbl:inherits="value=desc"/>
+	
+				<xul:vbox class="description-full"
+					style="margin-bottom: 3px; border: 0px red solid; overflow-y: auto;"
+					maxheight="120"
+					onoverflow="this.height=Math.min(this.maxHeight, this.firstChild.getBoundingClientRect().height + 3)">
+	
+					<xul:vbox>
+						<xul:hbox pack="start">
+							<xul:label class="addonLearnMore text-link"
+								value="Show full description"
+								anonid="getDescriptionPkgButton"
+								onclick="getDescriptionFor(document.getBindingParent(this))"/>
+						</xul:hbox>
+				
+						<xul:description anonid="fullDescription" class="description-full"
+							xbl:inherits="xbl:text=desc"/>
+					</xul:vbox>
+				</xul:vbox>
+			
+				<xul:hbox align="right" class="buttons" style="border: 0px blue solid;">
+					<xul:spacer/>
+					<xul:button anonid="installPkgButton" label="Install package"
+						mode=""
+						oncommand="pkgManInstall(this.getAttribute('pkg'), true)"
+						xbl:inherits="pkg=label"/>
+					<xul:button anonid="upgradePkgButton" label="Upgrade package"
+						mode="installed old required"
+						oncommand="pkgManUpgrade(this.getAttribute('pkg'))"
+						xbl:inherits="pkg=label"/>
+					<xul:button anonid="removePkgButton" label="Uninstall package"
+						mode="installed"
+						oncommand="pkgManRemove(this.getAttribute('pkg'))"
+						xbl:inherits="pkg=label" />
+					<xul:button anonid="loadPkgButton" label="Load package"
+						mode="installed/"
+						oncommand="pkgManLoad(this.getAttribute('pkg'))"
+						xbl:inherits="pkg=label" />
+					<xul:button anonid="detachPkgButton" label="Detach package"
+						mode="installed loaded"
+						oncommand="pkgManDetach(this.getAttribute('pkg'))"
+						xbl:inherits="pkg=label" />
+				</xul:hbox>
+			</xul:vbox>
+		</content>
+		
+		<implementation>
+	    <constructor>
+				<![CDATA[
+					var _this = this;
+					//var button = document.getAnonymousElementByAttribute(this,
+					//	"anonid", "loadPkgButton");
+					//button.addEventListener("command", function(event) {
+					//	alert(_this._title.value)}, false);
+					var version = document.getAnonymousElementByAttribute(this,
+						"anonid", "version");
+					version.value = version.value? "(" + version.value + ")" : "";
+				]]>
+			</constructor>
+		
+			<field name="_title">
+				document.getAnonymousElementByAttribute(this, "anonid", "title");
+			</field>
+		
+			<property name="label" onget="return this._title.value;">
+				<setter>
+				  <![CDATA[
+					  this._title.setAttribute("value", val);
+					  //this._title.value = val;
+					  return(val);
+				  ]]>
+				</setter>
+			</property>
+		
+			<property name="desc">
+				<setter>
+				  <![CDATA[
+						//sv.cmdout.append(val);
+						//this.setAttribute("desc", val);
+						var fullDescription = document
+							.getAnonymousElementByAttribute(this, "anonid",
+							"fullDescription");
+						if (!fullDescription) return("");
+	
+						var grid = this.buildDescription(val);
+						fullDescription.parentNode.replaceChild(grid, fullDescription);
+						var getDescriptionPkgButton = document
+							.getAnonymousElementByAttribute(this, "anonid",
+							"getDescriptionPkgButton");
+						getDescriptionPkgButton.hidden = true;
+						return val;
+				  ]]>
+				</setter>
+			</property>
+
+      <method name="buildDescription">
+        <parameter name="text"/>
+        <body>
+					<![CDATA[
+						const XUL_NS =
+							"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
+						const skipFields = ['Package', 'Version', 'Type', 'LazyLoad',
+								'LazyData', 'Encoding', 'Built', 'Packaged', 'Collate'];
+
+						//alert(text);
+						var lines = text.split(/[\r\n]+/);
+						var grid = document.createElementNS(XUL_NS, 'grid');
+						grid.className = "description-full";
+
+						var cols = grid.appendChild(document.createElementNS(XUL_NS,
+							'columns'));
+						for (var i = 0; i < 2; i++) {
+							var c = cols.appendChild(document.createElementNS(XUL_NS,
+								'column'));
+							c.setAttribute("flex", i);
+						}
+						var rows = grid.appendChild(document.createElementNS(XUL_NS,
+							'rows'));
+						for (var i in lines) {
+							var strs = lines[i].match(/^(\w+): (.*)$/);
+							if (strs == null || skipFields.indexOf(strs[1]) != -1) continue;
+							var fieldName = strs[1];
+							var fieldVal = strs[2];
+							if (fieldName == 'Depends')
+								fieldVal = fieldVal.replace(/\s*,?R\s*\([^\)]+\),?\s*/, '');
+							if (!fieldVal) continue;
+
+							var row = rows.appendChild(document.createElementNS(XUL_NS,
+								'row'));
+							var label = row.appendChild(document.createElementNS(XUL_NS,
+								'label'));
+							label.setAttribute("value", fieldName);
+							desc = row.appendChild(document.createElementNS(XUL_NS,
+								'description'));
+							desc.textContent = fieldVal;
+							label.className = "DescriptionField";
+							desc.className = "DescriptionText";
+						}
+						return(grid);
+					]]>
+				</body>
+			</method>
+		</implementation>
+	
+		<handlers>
+			<handler event="mouseup" action="this.checked=!this.checked"/>
+		</handlers>
+	</binding>
+
+	<binding id="pkg-nav-button"
+		extends="chrome://global/content/bindings/richlistbox.xml#richlistitem">
+    <resources>
+			<stylesheet src="chrome://global/skin/"/>
+    </resources>
+
+		<content minheight="30">
+			<xul:vbox flex="1">
+				<xul:hbox flex="1">
+					<xul:label anonid="next" class="navigButton text-link" value=""
+						xbl:inherits="onclick=oncommand"/>
+				</xul:hbox>
+			</xul:vbox>
+		</content>
+
+		<implementation>
+	    <constructor>
+				<![CDATA[
+					var button = document.getAnonymousElementByAttribute(this,
+						"anonid", "next");
+					var listItem = document.getBindingParent(button);
+					var listBox = listItem.parentNode;
+					var idx = listBox.getIndexOfItem(listItem);
+					var isLast = idx == listBox.itemCount - 1;
+					var isFirst = idx == 0;
+					button.value = isFirst ? "Previous page" : isLast? "Next page"
+						: "WTF?";
+					//button.addEventListener("click", function(event) {
+					//	alert(idx  )}, false);
+				]]>
+			</constructor>
+		</implementation>
+	</binding>
+
+	<!-- based on preferences.xml paneButton -->
+	<binding id="viewbutton"
+		extends="chrome://global/content/bindings/radio.xml#radio">
+    <resources>
+      <stylesheet src="chrome://sciviewsk/skin/pkgman.css"/>
+    </resources>
+  
+	  <content>
+      <xul:image class="viewButtonIcon" xbl:inherits="src"/>
+      <xul:label class="viewButtonLabel" xbl:inherits="value=label"/>
+    </content>
+  
+	  <implementation implements="nsIAccessibleProvider">
+      <property name="accessibleType" readonly="true">
+        <getter>
+          <![CDATA[
+            return(Components.interfaces.nsIAccessibleProvider.XULListitem);
+          ]]>
+        </getter>
+      </property>
+    </implementation>
+  </binding>
+</bindings>

Added: komodo/SciViews-K/content/pkgman.xul
===================================================================
--- komodo/SciViews-K/content/pkgman.xul	                        (rev 0)
+++ komodo/SciViews-K/content/pkgman.xul	2012-03-04 22:36:41 UTC (rev 456)
@@ -0,0 +1,477 @@
+<?xml version="1.0"?>
+
+<!-- ***** BEGIN LICENSE BLOCK *****
+ Version: MPL 1.1/GPL 2.0/LGPL 2.1
+
+ The contents of this file are subject to the Mozilla Public License
+ Version 1.1 (the "License"); you may not use this file except in
+ compliance with the License. You may obtain a copy of the License at
+ http://www.mozilla.org/MPL/
+
+ Software distributed under the License is distributed on an "AS IS"
+ basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ License for the specific language governing rights and limitations
+ under the License.
+
+ The Original Code is SciViews-K by Philippe Grosjean et al.
+
+ Contributor(s):
+   Kamil Barton
+   ActiveState Software Inc (code inspired from)
+
+ Alternatively, the contents of this file may be used under the terms of
+ either the GNU General Public License Version 2 or later (the "GPL"), or
+ the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ in which case the provisions of the GPL or the LGPL are applicable instead
+ of those above. If you wish to allow use of your version of this file only
+ under the terms of either the GPL or the LGPL, and not to allow others to
+ use your version of this file under the terms of the MPL, indicate your
+ decision by deleting the provisions above and replace them with the notice
+ and other provisions required by the GPL or the LGPL. If you do not delete
+ the provisions above, a recipient may use your version of this file under
+ the terms of any one of the MPL, the GPL or the LGPL.
+
+ ***** END LICENSE BLOCK ***** -->
+
+<!DOCTYPE overlay PUBLIC "-//MOZILLA//DTD XUL V1.0//EN"
+"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 
+
+<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
+<!--<?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?>-->
+<!--<?xml-stylesheet href="chrome://komodo/skin/bindings/buttons.css" type="text/css"?>-->
+<!--<?xml-stylesheet href="chrome://komodo/skin/bindings/sidebar.css" type="text/css"?>-->
+<!--<?xml-stylesheet href="chrome://komodo/skin/" type="text/css"?>-->
+<!--<?xml-stylesheet href="chrome://komodo/skin/global/global.css" type="text/css"?>-->
+<!--<?xml-stylesheet href="chrome://komodo/skin/bindings/scrolltabs.css" type="text/css"?>-->
+<!--<?xml-stylesheet href="chrome://mozapps/content/extensions/extensions.css" type="text/css"?>-->
+<?xml-stylesheet href="chrome://sciviewsk/skin/pkgman.css" type="text/css"?>
+
+<window id="RPackageManager"
+	xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+  width="400" height="300" screenX="20" screenY="20"
+  persist="screenX screenY width height"
+  title="R Package manager (beta)">
+
+	<script type="text/javascript">
+	<![CDATA[
+		var sv, ko;
+
+		function JSONDecode (str) {
+			var nativeJSON = Components.classes["@mozilla.org/dom/json;1"]
+				.createInstance(Components.interfaces.nsIJSON);
+			try {
+				return(nativeJSON.decode(str));
+			} catch(e) {
+				return(null);
+			}
+		}
+
+		function pkgManInstall (pkg, ask) {
+			ask = ', ask='  + (ask ? 'TRUE' : 'FALSE') +
+				', installDeps=' + (ask ? 'FALSE' : 'TRUE');
+		
+			var cmd = 'cat(listToJson(pkgManInstall("'
+				+ pkg + '"' + ask + ')))';
+		
+			sv.r.evalCallback(cmd, function (res) {
+				var response = JSONDecode(res);
+				if (response == null) {
+					ko.dialogs.alert("R said:", res, document.title);
+					return;
+				} else if (response.status == "question") {
+					if (ko.dialogs.okCancel(response.message, "OK", null,
+						"R package manager") == "OK") {
+						sv.r.evalCallback('cat(listToJson(pkgManInstall("' + pkg +
+							'", ask = FALSE, install.deps = TRUE)))',
+							updateInfo, "installed");
+						doInstall = true;
+					}
+				} else if (response.status == "done") {
+					ko.dialogs.alert("R said:", response.message, document.title);
+					//alert(pkgs);
+				}
+			});
+		}
+
+		function pkgManRemove (pkg) {
+			var cmd = 'cat(listToJson(pkgManRemove("' + pkg + '")))';
+			sv.r.evalCallback(cmd, updateInfo, "removed");
+		}
+
+		function pkgManDetach (pkg) {
+			var cmd = 'cat(listToJson(pkgManDetach("' + pkg + '")))';
+			sv.r.evalCallback(cmd, updateInfo, "detached");
+		}
+
+		function pkgManLoad (pkg) {
+			var cmd = 'cat(listToJson(pkgManLoad("' + pkg + '")))';
+			sv.r.evalCallback(cmd, updateInfo, "loaded");
+		}
+
+		function updateInfo (res, what) {
+			// Add to installed / reload installed
+			// Update items in Available
+			// Remove from Updates
+			//ko.dialogs.alert(what, res);
+			var avpList = document.getElementById("rAvailablePackageList");
+			var instList = document.getElementById("rPackageList");
+
+			switch(what) {
+			 case "installed":
+				response = JSONDecode(res);
+				if (response == null) {
+					ko.dialogs.alert("R said:", res, document.title + " updateInfo");
+					return;
+				}
+
+				var pkgs = response.packages;
+				if (typeof pkgs == "string") pkgs = [pkgs];
+		
+				if (response.message)
+					ko.dialogs.alert("R said:" + what, response.message.join("\n"),
+						document.title + " updateInfo");
+
+				var packageName, items;
+				for (var i in pkgs) {
+					packageName = pkgs[i];
+					items = avpList.getElementsByAttribute("label", packageName);
+					if (items.length == 0) continue;
+					for (var j = 0; j < items.length; j++) {
+						//alert("updating: " + packageName);
+						items[j].setAttribute("installedVersion",
+							items[j].getAttribute("version"));
+						items[j].setAttribute("installed", true);
+					}
+				}
+				getInstalledPkgs();
+				break;
+			
+			 case "removed":
+				response = JSONDecode(res);
+				if (response == null) {
+					ko.dialogs.alert("Something went wrong...", res, document.title
+						+ " updateInfo");
+					return;
+				}
+				var items, changedCount = 0;
+				for (var packageName in response) {
+					if (response[packageName] == "TRUE") {
+						changedCount++;
+						items = avpList.getElementsByAttribute("label", packageName);
+						if (items.length == 0) continue;
+						for (var j = 0; j < items.length; j++) {
+							items[j].removeAttribute("installed");
+							items[j].setAttribute("installedVersion", "");
+						}
+					}
+				}
+				if (changedCount > 0) getInstalledPkgs();
+				break;
+			
+			 case "loaded":
+				getInstalledPkgs();
+				break;
+			
+			 case "detached":
+				response = JSONDecode(res);
+				if (response == null) {
+					ko.dialogs.alert("Something went wrong...", res, document.title
+						+ " updateInfo");
+					return;
+				}
+				var items, changedCount = 0;
+				var errors = [];
+				for (var packageName in response) {
+					if (response[packageName] == "TRUE") {
+						changedCount++;
+						items = avpList.getElementsByAttribute("label", packageName);
+						if (items.length == 0) continue;
+						for (var j = 0; j < items.length; j++) {
+							items[j].removeAttribute("loaded");
+						}
+					} else {
+						errors.push(packageName + ": " + response[packageName])
+					}
+				}
+				if (changedCount > 0) getInstalledPkgs();
+				if (errors.length > 0)
+					ko.dialogs.alert("By detaching the packages, R said:",
+						errors.join("\n"),  document.title);
+				break;
+			
+			 default:
+			}
+		}
+
+		function getDescriptionFor (el) {
+			var pkg = el.label;
+			sv.r.evalCallback('pkgManDescribe("' + pkg + '")',
+				function (desc, el) {
+					el.desc = desc;
+				},
+			el);
+		};
+
+		function setCranMirror (url) {
+			if (!url) url = sv.pref.getPref("r.cran.mirror").trim();
+			try {
+				sv.r.eval("pkgManSetCRANMirror(\"" + url + "\")");
+			} catch(e) {
+				return;
+			}
+			var selectedCranMirror = document.getElementById('selectedCranMirror');
+			if (selectedCranMirror) selectedCranMirror.value = url;
+		}
+
+		function populateCranMirrorsList (rOutput) {
+			var lines = rOutput.split(/[\r\n]+/);
+			var mirror = sv.pref.getPref("r.cran.mirror").trim();
+			var rl = document.getElementById("rCRANMirrorsList");
+			var sel = -1;
+			for (var i = 0; i < lines.length; i++) {
+				l = lines[i].trim().split(';');
+				var row = document.createElement('listitem');
+				row.setAttribute('value', l[1]);
+				var cell = document.createElement('listcell');
+				cell.setAttribute('label', l[0]);
+				cell.setAttribute('image', "chrome://sciviewsk/skin/images/flags/"
+					+ l[2] + ".gif");
+				cell.className = "listcell-iconic";
+				row.appendChild(cell);
+				cell = document.createElement('listcell');
+				cell.setAttribute('label', l[1]);
+				row.appendChild(cell);
+				if (l[1].indexOf(mirror) > -1) sel = i;
+				rl.appendChild(row);
+			}
+			var it = rl.getItemAtIndex(sel);
+			rl.scrollToIndex(sel);
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/sciviews -r 456


More information about the Sciviews-commits mailing list