[Sciviews-commits] r390 - in komodo/SciViews-K-dev: . R content content/js content/pkgman skin skin/images
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Aug 16 17:06:02 CEST 2011
Author: prezez
Date: 2011-08-16 17:06:02 +0200 (Tue, 16 Aug 2011)
New Revision: 390
Added:
komodo/SciViews-K-dev/R/pkgman.R
komodo/SciViews-K-dev/content/pkgman/
komodo/SciViews-K-dev/content/pkgman/pkgman.xbl
komodo/SciViews-K-dev/content/pkgman/pkgman.xul
komodo/SciViews-K-dev/skin/images/viewButtons.png
komodo/SciViews-K-dev/skin/pkgman.css
Modified:
komodo/SciViews-K-dev/R/captureAll.R
komodo/SciViews-K-dev/chrome.manifest
komodo/SciViews-K-dev/content/js/commands.js
Log:
SciViews-K-dev:
new R package manager
captureAll: fixed use of 'show' vs. 'print'
Modified: komodo/SciViews-K-dev/R/captureAll.R
===================================================================
--- komodo/SciViews-K-dev/R/captureAll.R 2011-08-12 22:09:12 UTC (rev 389)
+++ komodo/SciViews-K-dev/R/captureAll.R 2011-08-16 15:06:02 UTC (rev 390)
@@ -1,7 +1,3 @@
-#: src/main/errors.c:551
-#msgid "Error in "
-#msgid "Error: "
-
# replacement for 'base::as.character.error', which does not translate "Error"
`as.character.error` <- function (x, ...) {
msg <- conditionMessage(x)
@@ -113,7 +109,10 @@
#cat('---\n')
# this will catch also 'print' errors
off <<- -3L
- if(res1$visible) show(res1$value)
+ if(res1$visible) if(mode(res1$value) == "S4")
+ show(res1$value) else
+ print(res1$value)
+
}
},
Added: komodo/SciViews-K-dev/R/pkgman.R
===================================================================
--- komodo/SciViews-K-dev/R/pkgman.R (rev 0)
+++ komodo/SciViews-K-dev/R/pkgman.R 2011-08-16 15:06:02 UTC (rev 390)
@@ -0,0 +1,189 @@
+# 'imports'
+compareVersion <- utils::compareVersion
+available.packages <- utils::available.packages
+installed.packages <- utils::installed.packages
+install.packages <- utils::install.packages
+remove.packages <- utils::remove.packages
+packageDescription <- utils::packageDescription
+getCRANmirrors <- utils::getCRANmirrors
+write.table <- utils::write.table
+
+pkgManGetDescription <- function(pkg, print=TRUE) {
+ if (pkg %in% rownames(installed.packages())) {
+ desc <- packageDescription(pkg)
+ } else {
+ con <- url(file.path(getOption("repos")['CRAN'], "web", "packages", pkg,
+ 'DESCRIPTION', fsep = '/'))
+ m <- try(open(con, "r"), silent = TRUE)
+ if (!inherits(m, "try-error")) {
+ dcf <- try(read.dcf(con))
+ close(con)
+ desc <- as.list(dcf[1, ])
+ class(desc) <- "packageDescription"
+ } else {
+ return(invisible(NULL))
+ }
+ }
+ if (print) {
+ write.dcf(as.data.frame.list(desc[!sapply(desc, is.na)],
+ optional = TRUE), width = Inf)
+ invisible(desc)
+ } else {
+ desc
+ }
+}
+
+pkgManGetMirrors <- function() {
+ tmpVar <- "pkgMan.CRANmirrors"
+ if(existsTemp(tmpVar)) {
+ mirrors <- getTemp(tmpVar)
+ } else {
+ mirrors <- getCRANmirrors()
+ assignTemp(tmpVar, mirrors)
+ }
+ write.table(mirrors[, c(1,4)], row.names = FALSE, col.names = F, sep=';', quote = F, na="")
+}
+
+pkgManGetAvailable <- function(page = "next", pattern = "", ilen=50,
+ col=c("Package", "Version", "InstalledVersion", "Status"),
+ reload=FALSE, sep=';', eol="\t\n") {
+ if (!existsTemp('avpkg.list') || reload) {
+ avpkg.list <- availablePkgs(utils::available.packages(filters=c("R_version",
+ "OS_type", "duplicates")), installed = FALSE)
+ assignTemp('avpkg.list', avpkg.list)
+ } else {
+ avpkg.list <- getTemp('avpkg.list')
+ }
+ if (page == "first") {
+ newSearch <- TRUE
+ i0 <- 1
+ } else {
+ newSearch <- getTemp('avpkg.pattern', "") != pattern
+ i0 <- getTemp('avpkg.idx', default = 1)
+ }
+
+ if(is.character(pattern) && pattern != "") {
+ if(newSearch) {
+ page <- "current"
+ i0 <- 1
+ idx <- grep(pattern, avpkg.list[,'Package'], ignore.case = TRUE)
+ assignTemp('avpkg.pattern.idx', idx)
+ } else {
+ idx <- getTemp('avpkg.pattern.idx')
+ }
+ imax <- length(idx)
+ } else {
+ imax <- nrow(avpkg.list)
+ idx <- seq(imax)
+ }
+ #browser()
+ assignTemp('avpkg.pattern', pattern)
+
+ if (page == "next") i0 <- i0 + ilen else
+ if (page == "prev") i0 <- i0 - ilen
+ outside <- i0 > imax || i0 < 1
+ if (outside) return(NULL)
+ assignTemp('avpkg.idx', i0)
+ i1 <- min(i0 + ilen - 1, imax)
+ i <- seq(i0, i1)
+ cat(i0, i1, imax, "\t\n")
+ write.table(availablePkgs(avpkg.list[idx[i], , drop = FALSE])[, col, drop = FALSE],
+ row.names = FALSE, col.names = F, sep=sep, quote = FALSE, eol=eol, na='')
+}
+
+availablePkgs <- function(avpkg=available.packages(), installed=TRUE) {
+ #browser()
+ avpkg <- avpkg[order(toupper(avpkg[, "Package"])), , drop = FALSE]
+ if(installed) {
+ inspkg <- installed.packages()
+ ipkgnames <- unique(inspkg[, 'Package'])
+
+ ipkgnames <- ipkgnames[ipkgnames %in% avpkg[, 'Package']]
+ avpkg <- cbind(avpkg, 'InstalledVersion'=NA, 'Status'=NA)
+ if(length(ipkgnames)) {
+ pkgstatus <- sapply(ipkgnames, function(pkg) {
+ compareVersion(avpkg[pkg, 'Version'], inspkg[pkg, 'Version'])
+ })
+ avpkg[ipkgnames, 'Status'] <- pkgstatus
+ avpkg[ipkgnames, 'InstalledVersion'] <- inspkg[ipkgnames, 'Version']
+ }
+ }
+ avpkg
+}
+
+pkgManGetInstalled <- function(sep=';', eol="\t\n") {
+ inspkg <- installed.packages(fields="Description")
+ inspkg <- inspkg[order(toupper(inspkg[, "Package"])),
+ c("Package","Version","Description")]
+
+ inspkg[,3] <- gsub("\n", " ", inspkg[,3])
+ inspkg <- cbind(inspkg, Installed=inspkg[, 'Package'] %in% .packages())
+ write.table(inspkg, row.names = FALSE, col.names = F, sep=sep, quote = F, eol=eol, na='')
+}
+
+pkgManSetCRANMirror <- function(url) {
+ repos <- getOption("repos")
+ repos['CRAN'] <- url
+ options(repos = repos)
+}
+
+
+pkgManInstallPackages <- function(upkgs, installDeps=FALSE, ask=TRUE) {
+ dep <- suppressMessages(utils:::getDependencies(upkgs, available = getTemp('avpkg.list')))
+ msg <- status <- ""
+ if (!ask && (installDeps || all(dep %in% upkgs))) {
+ msg <- captureAll(install.packages(dep))
+ status <- "done"
+ } else {
+ l <- length(dep)
+ msg <- sprintf(ngettext(l,
+ "This will install package %2$s.",
+ "This will install packages: %s and %s.",
+ ), paste(sQuote(dep[-l]), collapse = ", "), sQuote(dep[l]))
+ status <- "question"
+
+ }
+ list(packages=dep, message=msg, status=status)
+ #invisible(dep)
+}
+
+pkgManRemovePackage <- function(pkgName) {
+ sapply(pkgName, function(pkgName) {
+ if(pkgName %in% loadedNamespaces()) unloadNamespace(pkgName)
+ pack <- paste("package", pkgName, sep=":")
+ if(pack %in% search()) detach(pack, character.only = TRUE)
+
+ dlli <- getLoadedDLLs()[[pkgName]]
+ if(!is.null(dlli)) dyn.unload(dlli[['path']])
+
+ pkgpath <- find.package(pkgName, quiet = TRUE)
+ if(length(pkgpath) == 0L) return(FALSE)
+
+ pkglib <- normalizePath(file.path(pkgpath, ".."))
+ if(file.access(pkglib, 2) == 0) {
+ remove.packages(pkgName, lib=pkglib)
+ return(TRUE)
+ } else {
+ #warning("No sufficient access rights to library", sQuote(pkglib))
+ return(FALSE)
+ }
+ }, simplify=FALSE)
+}
+
+pkgManLoadPackage <- function(pkgName) {
+ sapply(pkgName, library, character.only = TRUE, logical.return = TRUE, simplify = FALSE)
+}
+
+pkgManDetachPackage <- function(pkgName) {
+ sapply(pkgName, function(pkgName) {
+ tryCatch({
+ if(pkgName %in% loadedNamespaces()) unloadNamespace(pkgName)
+ pack <- paste("package", pkgName, sep=":")
+ if(pack %in% search()) detach(pack, character.only = TRUE)
+ TRUE
+ }, error = function(e) {
+ conditionMessage(e)
+ })
+ }, simplify = FALSE)
+}
+
Modified: komodo/SciViews-K-dev/chrome.manifest
===================================================================
--- komodo/SciViews-K-dev/chrome.manifest 2011-08-12 22:09:12 UTC (rev 389)
+++ komodo/SciViews-K-dev/chrome.manifest 2011-08-16 15:06:02 UTC (rev 390)
@@ -3,6 +3,8 @@
overlay chrome://komodo/content/komodo.xul chrome://sciviewsk/content/RObjectsOverlay.xul
overlay chrome://komodo/content/pref/pref.xul chrome://sciviewsk/content/prefOverlay.xul
+overlay chrome://komodo/content/pref/pref.xul chrome://sciviewsk/content/pkgman/pkgman.xul
+
# The following items is not finished yet, and is thus commented out
#overlay chrome://komodo/content/komodo.xul chrome://sciviewsk/content/RConsoleOverlay.xul
Modified: komodo/SciViews-K-dev/content/js/commands.js
===================================================================
--- komodo/SciViews-K-dev/content/js/commands.js 2011-08-12 22:09:12 UTC (rev 389)
+++ komodo/SciViews-K-dev/content/js/commands.js 2011-08-16 15:06:02 UTC (rev 390)
@@ -205,7 +205,7 @@
}
this.openPkgManager = function () {
- var win = _getWindowRef("chrome://sciviewsk/content/RPkgManager.xul",
+ var win = _getWindowRef("chrome://sciviewsk/content/pkgman/pkgman.xul",
"RPkgMgr", "chrome=yes,dependent" +
"scrollbars=yes,status=no,close,dialog=no", true, sv);
return(win);
Added: komodo/SciViews-K-dev/content/pkgman/pkgman.xbl
===================================================================
--- komodo/SciViews-K-dev/content/pkgman/pkgman.xbl (rev 0)
+++ komodo/SciViews-K-dev/content/pkgman/pkgman.xbl 2011-08-16 15:06:02 UTC (rev 390)
@@ -0,0 +1,186 @@
+<?xml version="1.0"?>
+<!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>
+
+
+
+</bindings>
Added: komodo/SciViews-K-dev/content/pkgman/pkgman.xul
===================================================================
--- komodo/SciViews-K-dev/content/pkgman/pkgman.xul (rev 0)
+++ komodo/SciViews-K-dev/content/pkgman/pkgman.xul 2011-08-16 15:06:02 UTC (rev 390)
@@ -0,0 +1,388 @@
+<?xml version="1.0"?>
+<?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"
+ maxheight="350" maxwidth="300" title="R Package manager (pre-alpha)" >
+
+<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(simpsON(pkgManInstallPackages("' + 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(simpsON(pkgManInstallPackages("' + pkg +
+ '", ask=FALSE, installDeps=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(simpsON(pkgManRemovePackage("' + pkg + '")))';
+ sv.r.evalCallback(cmd, updateInfo, "removed");
+}
+
+function pkgManDetach(pkg) {
+ var cmd = 'cat(simpsON(pkgManDetachPackage("' + pkg + '")))';
+ sv.r.evalCallback(cmd, updateInfo, "detached");
+}
+
+function pkgManLoad(pkg) {
+ var cmd = 'cat(simpsON(pkgManLoadPackage("' + 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);
+ default:
+ }
+}
+
+function getDescriptionFor(el) {
+ var pkg = el.label;
+ sv.r.evalCallback('pkgManGetDescription("' + pkg + '")', function(desc, el) {
+ el.desc = desc;
+ }, el);
+};
+
+function setCranMirror(url) {
+ if(!url) url = sv.pref.getPref("CRANMirror").trim();
+ sv.rconn.evalAtOnce("pkgManSetCRANMirror(\"" + url + "\")");
+ document.getElementById('selectedCranMirror').value = url;
+}
+
+function getCranMirrors() {
+ var mirror = sv.pref.getPref("CRANMirror").trim();
+ var cmd = "pkgManGetMirrors()";
+ var lines = sv.rconn.evalAtOnce(cmd, 3).split(/[\r\n]+/);
+ 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]);
+ 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);
+ rl.ensureIndexIsVisible( sel);
+ //rl.timedSelect(it , 10);
+ rl.selectItem( it);
+}
+
+function makePkgItem(name, version, installedVersion, status, installed, old, loaded) {
+ var item = document.createElement("richlistitem");
+ item.setAttribute("label", name);
+ item.setAttribute("version", version);
+ if(installedVersion) item.setAttribute("installedVersion", installedVersion);
+ if(status) item.setAttribute("status", status);
+ if(installed) item.setAttribute("installed", installed);
+ if(old) item.setAttribute("old", old);
+ if(loaded) item.setAttribute("loaded", loaded);
+ return item;
+}
+
+
+
+function getInstalledPkgs() {
+ var lines = sv.rconn.evalAtOnce('pkgManGetInstalled()').trim();
+ if (lines == 'NULL') return;
+ lines = lines.split(/\t[\r\n]+/);
+ rl = document.getElementById("rPackageList");
+
+ var selectedIndex, selectedItem, selectedLabel;
+
+ selectedIndex = rl.selectedIndex;
+ selectedItem = rl.getSelectedItem(0);
+ if(selectedItem != null) selectedLabel = selectedItem.label;
+
+ while(rl.itemCount) rl.removeItemAt(0);
+ for(var i = 0; i < lines.length; i++){
+ l = lines[i].trim().split(';');
+ rl.appendChild(
+ makePkgItem(l[0], l[1], null, null, true, null, l[3] == 'TRUE')
+ );
+ }
+
+ if(selectedIndex != -1) {
+ for (var i = 0; i < rl.itemCount; i++)
+ if(rl.getItemAtIndex(i).label == selectedLabel) {
+ rl.selectedIndex = i;
+ break;
+ }
+ }
+}
+
+function getAvailablePkgs(page, reload) {
+ if (!page) page = '';
+ var searchPattern = document.getElementById('searchfield').value.trim();
+ searchPattern = sv.tools.string.toRegex(searchPattern);
+
+ var lines = sv.rconn.evalAtOnce('pkgManGetAvailable("' + page + '", pattern="' +
+ searchPattern + '", reload=' +
+ (reload ? 'TRUE': 'FALSE') + ')', 2).trim();
+
+ if (lines == 'NULL') return;
+
+ lines = lines.split(/\t[\r\n]+/);
+
+ rl = document.getElementById("rAvailablePackageList");
+ while(rl.itemCount) rl.removeItemAt(0);
+
+ idx = lines[0].trim().split(" ").map(function(x) parseInt(x));
+ var item;
+ var prevButton = document.getElementById('availablePackagesPrevButton');
+ if (idx[0] > 1) {
+ item = document.createElement("richlistitem");
+ item.setAttribute("class", "navButton");
+ item.setAttribute("oncommand", "getAvailablePkgs('prev')");
+ rl.appendChild(item);
+ prevButton.disabled = false;
+ } else {
+ prevButton.disabled = true;
+ }
+ for(var i = 1; i < lines.length; i++){
+ l = lines[i].trim().split(';');
+ rl.appendChild(makePkgItem(l[0], l[1], l[2], l[3], l[3] != '', l[3] == '1'));
+ }
+
+ var nextButton = document.getElementById('availablePackagesNextButton');
+ if (idx[1] < idx[2]) {
+ item = document.createElement("richlistitem");
+ item.setAttribute("class", "navButton");
+ item.setAttribute("oncommand", "getAvailablePkgs('next')");
+ rl.appendChild(item);
+ nextButton.disabled = false;
+ } else {
+ nextButton.disabled = true;
+ }
+ var info = document.getElementById('availablePackagesInfo');
+ info.value = ' Showing packages ' + idx[0] + "-" + idx[1] + ' of ' + idx[2]
+ + ' total (from "' + lines[1].split(';', 1) + '" to "'
+ + lines[lines.length-1].split(';', 1) + '")'
+}
+
+
+function init() {
+ var rDir = sv.tools.file.path("ProfD", "extensions", "sciviewsk at sciviews.org", "R", "pkgman.R");
+ sv.r.evalHidden('if(!exists("pkgManGetInstalled", as.environment("komodoConnection"))) ' +
+ 'sys.source("' + sv.tools.string.addslashes(rDir) +
+ '", as.environment("komodoConnection"));');
+
+ //sv.r.eval('sys.source("' + sv.tools.string.addslashes(rDir) + '", as.environment("komodoConnection"));');
+
+ setCranMirror();
+ getCranMirrors();
+ getAvailablePkgs("first", true);
+ getInstalledPkgs();
+
+}
+
+
+
+function pkgMgrOnLoad(event) {
+
+ var p = parent;
+ while (p = p.opener) {
+ if (p.ko) {
+ sv = p.sv;
+ ko = p.ko;
+ break;
+ }}
+
+ window.setTimeout(init, 256);
+}
+
+addEventListener("load", pkgMgrOnLoad, false);
+
+]]>
+</script>
+ <hbox id="topStackBar">
+ <radiogroup id="viewGroup" orient="horizontal" flex="2">
+ <radio id="search-view" label="Available"
+ oncommand="document.getElementById('pkgPanels').selectedIndex = 0;"/>
+ <radio id="extensions-view" label="Installed"
+ oncommand="document.getElementById('pkgPanels').selectedIndex = 1;"/>
+ <radio id="updates-view" label="Updates"
+ oncommand="document.getElementById('pkgPanels').selectedIndex = 2;" disabled="true" />
+ <radio id="mirrors-view" label="CRAN mirrors" selected="true"
+ oncommand="document.getElementById('pkgPanels').selectedIndex = 3;"/>
+ </radiogroup>
+<spacer/>
+<button label="Close" onclick="self.close();"/>
+ </hbox>
+<deck id="pkgPanels" flex="1" style="padding: 0px; border: 0px black solid;"
+ persists="selectedIndex" selectedIndex="3">
+<box >
+<vbox flex="1">
+<hbox id="searchPanel" align="center">
+ <textbox id="searchfield" emptytext="Search packages" type="search"
+ searchbutton="true" class="compact"
+ oncommand="getAvailablePkgs('current')" />
+<spacer flex="1"/>
+<button label="Prev" id="availablePackagesPrevButton" oncommand="getAvailablePkgs('prev')" />
+<button label="Next" id="availablePackagesNextButton" oncommand="getAvailablePkgs('next')" />
+</hbox>
+<hbox>
+<label id="availablePackagesInfo" value="Bla bla bla" />
+</hbox>
+<hbox flex="1">
+ <richlistbox id="rAvailablePackageList" class="rPackageList" flex="1" />
+</hbox></vbox>
+</box>
+
+<box>
+<hbox flex="1">
+<richlistbox id="rPackageList" class="rPackageList" flex="1" />
+</hbox>
+</box>
+<box><label id="wtf1" value=""/></box>
+<vbox>
+<hbox><label value="Selected mirror: "/><label id="selectedCranMirror" value=""/></hbox>
+<hbox flex="1">
+ <listbox id="rCRANMirrorsList" suppressonselect="false" flex="1"
+ onclick="setCranMirror(this.selectedItem.value)">
+ <listhead>
+ <listheader label="Name" width="100"/>
+ <listheader label="URL" width="150"/>
+ </listhead>
+ <listcols>
+ <listcol flex="1"/>
+ <listcol flex="1"/>
+ </listcols>
+</listbox>
+
+</hbox>
+
+</vbox>
+</deck>
+
+</window>
Added: komodo/SciViews-K-dev/skin/images/viewButtons.png
===================================================================
(Binary files differ)
Property changes on: komodo/SciViews-K-dev/skin/images/viewButtons.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: komodo/SciViews-K-dev/skin/pkgman.css
===================================================================
--- komodo/SciViews-K-dev/skin/pkgman.css (rev 0)
+++ komodo/SciViews-K-dev/skin/pkgman.css 2011-08-16 15:06:02 UTC (rev 390)
@@ -0,0 +1,168 @@
+#viewGroup radio {
+ -moz-appearance: none;
+ margin: 0px 1px 0px 1px;
+ padding: 5px 3px 1px;
+ min-width: 4.5em;
+ list-style-image: url("chrome://sciviewsk/skin/images/viewButtons.png");
+}
+
+radio#mirrors-view {
+ -moz-image-region: rect(0px, 96px, 32px, 64px)
+}
+radio#mirrors-view:hover, radio#mirrors-view[selected="true"] {
+ -moz-image-region: rect(32px, 96px, 64px, 64px)
+}
+
+radio#updates-view[disabled="true"] image {
+ opacity: 0.2;
+}
+
+#pkgPanels richlistbox[empty] {
+ visibility: hidden;
+}
+
+.rPackageList richlistitem {
+ -moz-binding: url("chrome://sciviewsk/content/pkgman/pkgman.xbl#pkg-item");
+ padding-top: 6px;
+ padding-bottom: 6px;
+ -moz-padding-start: 7px;
+ -moz-padding-end: 7px;
+ border-bottom: 1px dotted #C0C0C0;
+}
+
+.rPackageList richlistitem.navButton {
+-moz-binding: url("chrome://sciviewsk/content/pkgman/pkgman.xbl#pkg-nav-button");
+}
+
+richlistitem[installed] button[anonid="installPkgButton"],
+richlistitem:not([old]) button[anonid="upgradePkgButton"],
+richlistitem:not([installed]) button[anonid="removePkgButton"],
+richlistitem:not([loaded]) button[anonid="detachPkgButton"],
+richlistitem:not([installed]) button[anonid="loadPkgButton"],
+richlistitem[loaded] button[anonid="loadPkgButton"] {
+ visibility: collapse;
+}
+
+richlistitem description.title {
+ font-weight: bold;
+}
+
+richlistitem[update=true] {
+ background-color: #e1ffc4;
+}
+
+richlistitem[selected="true"] {
+ color: HighlightText;
+ background-attachment: scroll;
+ background-color: Highlight;
+ background-image: url("chrome://sciviewsk/skin/images/itemEnabledFader.png");
+ background-position: 0% 0%;
+ background-repeat: repeat;
+}
+
+richlistitem.navButton {
+ color: ButtonText;
+ background-color: ThreeDFace;
+}
+
+
+richlistitem.navButton[selected="true"] {
+ color: HighlightText;
+ background-attachment: scroll;
+ background-color: Highlight;
+ background-image: none;
+}
+
+richlistitem description.description {
+}
+
+
+richlistitem label.title {
+ font-weight: bold;
+}
+
+
+richlistitem description.description-full {
+ white-space: pre-wrap;
+ overflow: auto;
+}
+
+richlistitem .DescriptionText {
+}
+
+richlistitem .DescriptionField {
+ font-weight: bold;
+}
+
+richlistitem .text-link {
+ color: white;
+}
+
+richlistitem:not([selected="true"]) .description-full {
+ visibility: collapse;
+}
+
+richlistitem[selected="true"] description.description {
+ visibility: collapse;
+}
+
+richlistitem:not([selected="true"]) hbox.buttons {
+ visibility: collapse;
+}
+
+/*richlistitem:not([selected="true"])[status="0"] {
+ background-color: #fbed9f;
+}
+
+richlistitem:not([selected="true"])[status="1"] {
+ background-color: #fecfcf;
+}*/
+
+#rPackageList >
+richlistitem:not([selected]):not([loaded]) {
+ opacity: 0.3;
+ /*
+ background-color: red;
+ background-color: #8981f5;
+
+ */
+}
+
+#rAvailablePackageList >
+richlistitem[installed]:not([selected]) {
+ background-color: rgba(64,0,128,0.2);
+ /*opacity: 0.3;*/
+}
+
+#rAvailablePackageList >
+richlistitem[installed][selected] {
+ background-color: rgba(32,0,128,0.4);
+ /*opacity: 0.3;*/
+}
+
+
+
+richlistitem:not([selected])[old] {
+ background-color: #d3ffa8;
+}
+
+
+
+
+tab:first-child {
+ -moz-border-radius: 6px 6px 0px 0px;
+}
+
+tab:last-child {
+ -moz-border-radius: 0px 6px 0px 0px;
+}
+tab {
+ -moz-image-region: rect(10px, 15px, 5px, 0px);
+ color: GrayText;
+ min-height: 45px;
+}
+
+tab[selected="true"] {
+ color: ButtonText;
+ font-weight: bold;
+}
More information about the Sciviews-commits
mailing list