[Sciviews-commits] r199 - in komodo/SciViews-K: content content/js content/js/tools skin skin/images templates

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Sep 27 15:47:00 CEST 2009


Author: prezez
Date: 2009-09-27 15:47:00 +0200 (Sun, 27 Sep 2009)
New Revision: 199

Added:
   komodo/SciViews-K/skin/images/find.png
Removed:
   komodo/SciViews-K/content/js/tools/e4x2dom.js
Modified:
   komodo/SciViews-K/content/RHelpOverlay.xul
   komodo/SciViews-K/content/js/commands.js
   komodo/SciViews-K/content/js/tools/file.js
   komodo/SciViews-K/skin/sciviewsk.css
   komodo/SciViews-K/templates/
   komodo/SciViews-K/templates/.Rprofile
Log:
Exception logging in sv.tools.file.getfile 
More thorough path to URI conversion in sv.command.openHelp.
Find Toolbar for R Help window.
Deleted "e4x2dom.js" - not used anymore.
sv.socket.updateCharset() called from R at startup (in templates/.Rprofile).


Modified: komodo/SciViews-K/content/RHelpOverlay.xul
===================================================================
--- komodo/SciViews-K/content/RHelpOverlay.xul	2009-09-27 10:02:42 UTC (rev 198)
+++ komodo/SciViews-K/content/RHelpOverlay.xul	2009-09-27 13:47:00 UTC (rev 199)
@@ -43,7 +43,9 @@
 <?xml-stylesheet href="chrome://komodo/skin/bindings/buttons.css" type="text/css"?>
 <?xml-stylesheet href="chrome://komodo/skin/bindings/views.css" type="text/css"?>
 <?xml-stylesheet href="chrome://komodo/skin/bindings/widgets.css" type="text/css"?>
+<?xml-stylesheet href="chrome://sciviewsk/skin/sciviewsk.css" type="text/css"?>
 
+
 <window
     id="RHelpWindow" title="R Help" onload="rHelpOnLoad();"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
@@ -66,7 +68,9 @@
 			var page = rHelpTopic.value;
 			rHelpTopic.select();
 			// Try to differenciate an URL from a help topic
-			if (page.match(/^[a-zA-Z]+:\/\//) != null) {
+			var isUri = page.search(/^((f|ht)tps?|chrome|about|file):\/{0,3}/) === 0;
+
+			if (isUri) {
 				// This looks like a URL
 				rHelpBrowser.webNavigation.loadURI(page, null, null, null, null);
 			} else {
@@ -85,12 +89,35 @@
 			rHelpTopic.select();
 			sv.r.search(rHelpTopic.value);
         }
-		
-		function searchpage() {
-			rHelpTopic.select();
-			findInDoc(rHelpTopic.value);
+
+		function onFindCommand (event) {
+			var button = event.target;
+			if (!button.checked) {
+				find();
+			} else {
+				// hide findToolbar:
+				var findToolbar = document.getElementById("FindToolbar");
+				findToolbar.setAttribute("hidden", "true");
+			}
 		}
 
+
+		function find(next) {
+			//rHelpTopic.select();
+			//findInDoc(rHelpTopic.value);
+			var findToolbar = document.getElementById("FindToolbar");
+
+			if (!next) {
+				var isShown = findToolbar.getAttribute("hidden") != "true";
+				findToolbar.removeAttribute("hidden");
+
+				findToolbar._findField.value = rHelpBrowser.docShell.document.getSelection();
+				findToolbar._find(findToolbar._findField.value);
+			} else {
+				findToolbar._findAgain(event.shiftKey);
+			}
+		}
+
 		function printpage() {
 			alert("Print not implemented yet!");
 			// This does not work!
@@ -125,7 +152,7 @@
 
 
 		// Browser progress listener:
-		// so far used only to change title
+		// so far used only to change title and location text
 
 		// From: https://developer.mozilla.org/en/Code_snippets/Progress_Listeners
 		const STATE_START = Components.interfaces.
@@ -174,13 +201,26 @@
 		}
 
 		function keyPressListener (event) {
-			//alert(event.ctrlKey + " * " + event.which);
-			if ((event.ctrlKey && event.which == 102)
-				|| event.keyCode == 114) {
-				findInDoc(rHelpTopic.value, false);
+			if (event.ctrlKey && event.which == 102) { // Ctrl+F
+				find(false);
+			} else if (event.keyCode == 114) { // F3
+				find(true);
+			} else if (event.keyCode == 8) { // backspace
+				goBack();
 			}
 		}
 
+		function onFindToolbarAttrModified(event) {
+			if (event.attrName == "hidden"
+				&& (!event.newValue || event.newValue == "true")) {
+				//var bc = document.getElementById("cmd_rhelp_findToolbar");
+				//bc.setAttribute("hidden", event.target.hidden);
+				//rhelp-find!!!
+				document.getElementById("rhelp-find").checked = !event.target.hidden;
+			}
+		}
+
+
 		self.onload = function () {
             var args = window.arguments;
 			sv = args[0];
@@ -199,37 +239,27 @@
 
 			document.addEventListener("keypress", keyPressListener, true);
 
+			// Listen to find toolbar attribute modifications:
+
+			document.getElementById("FindToolbar").
+				addEventListener("DOMAttrModified",
+										 onFindToolbarAttrModified, true);
+
 			/*rHelpBrowser.removeProgressListener(myListener,
 			  Components.interfaces.nsIWebProgress.NOTIFY_STATE_DOCUMENT);
 			*/
         }
 
-		function findInDoc(searchString, findBackwards) {
-			findBackwards = findBackwards? true : false;
 
-			var rhb = rHelpBrowser;
-
-			if (!rhb.fastFind.searchString) {
-				//rHelpBrowser.fastFind.setDocShell(rhb.docShell)
-				rhb.fastFind.init(rhb.docShell);
-			}
-
-			if (searchString) {
-				if (searchString == rhb.fastFind.searchString) {
-					rhb.fastFind.findAgain(findBackwards, false);
-				} else {
-					rhb.fastFind.find(searchString, false);
-				}
-			}
-		}
         ]]>
     </script>
+
     <hbox>
 		<vbox align="stretch" flex="1">
             <textbox id="rhelp-topic" flex="0"
-				emptytext="topic or web page (Ctrl-F/F3 search in doc)"
+				emptytext="topic or web page"
 				onkeypress="txtInput(event);"
-				tooltiptext="Search topic or Web page (or Ctrl-F/F3 to search in document)"/>
+				tooltiptext="Search topic or Web page"/>
         </vbox>
 		<toolbarbutton id="rhelp-go" class="macro-play-icon"
 		    oncommand="go();" disabled="false" label="Go"
@@ -239,11 +269,11 @@
 		    oncommand="search();" disabled="false" label="Search"
 			tooltiptext="Search expression in R help" persist="buttonstyle"
 			buttonstyle="pictures"/>
-		<toolbarbutton id="rhelp-searchpage" class="list-item-down-icon"
-		    oncommand="searchpage();" disabled="false" label="Search in page"
-			tooltiptext="Search expression in this page (Ctrl-F/F3)"
+		<spacer flex="1"/>
+		<toolbarbutton id="rhelp-find" class="find-icon"
+		    oncommand="onFindCommand(event);" disabled="false" label="Search in page"
+			tooltiptext="Search this page (Ctrl-F/F3)"
 			persist="buttonstyle" buttonstyle="pictures"/>
-		<spacer flex="1"/>
 		<toolbarbutton id="rhelp-back-button" class="history-back-icon"
 		    oncommand="goBack();" disabled="false" label="Back"
 			tooltiptext="Back" persist="buttonstyle" buttonstyle="pictures"/>
@@ -292,4 +322,7 @@
                 src="about:blank" flex="1"/>
         </hbox>
     </vbox>
+		<vbox id="browser-bottombox">
+		<findbar browserid="rhelp-browser" id="FindToolbar" hidden="true"/>
+	</vbox>
 </window>

Modified: komodo/SciViews-K/content/js/commands.js
===================================================================
--- komodo/SciViews-K/content/js/commands.js	2009-09-27 10:02:42 UTC (rev 198)
+++ komodo/SciViews-K/content/js/commands.js	2009-09-27 13:47:00 UTC (rev 199)
@@ -60,7 +60,7 @@
 		// env strings: "ENV1=fooJ\nENV2=bar"
 		// gPrefSvc.prefs.getStringPref("runEnv");
 		var defRApp = "r-terminal";
-		var isWin = navigator.platform == "Win32";
+		var isWin = navigator.platform.search(/Win\d+$/) === 0;
 		// Default preferredRApp on Windows is r-gui
 		if (isWin) defRApp = "r-gui";
 		var preferredRApp = sv.prefs.getString("sciviews.preferredRApp",
@@ -189,10 +189,12 @@
 			observerSvc.addObserver(this, 'status_message', false);
 			sv.log.debug("R has been started with command: " + command);
 			sv.r.running = true;
-			sv.socket.updateCharset(true);
+			// Sending commands to R does not seem to work, I think it is too early, R is still
+			// starting. This should be in .Rprofile
+			//sv.socket.updateCharset(true);
 			// Possibly refresh the GUI by running SciViews-specific
 			// R task callbacks and make sure R Objects pane is updated
-			sv.r.evalHidden("try(guiRefresh(force = TRUE), silent = TRUE)");
+			//sv.r.evalHidden("try(guiRefresh(force = TRUE), silent = TRUE)");
 
 			//xtk.domutils.fireEvent(window, 'r_app_started_closed');
 			window.updateCommands('r_app_started_closed');
@@ -335,9 +337,28 @@
 			// because:
 			// 1) sv.tools.file.getfile() returns null on Mac OS X
 			// 2) sv.tools.file.getURI() raises an error on Mac OS X
-			//webpage = sv.tools.file.getURI(sv.tools.file.getfile(webpage.replace(/\//g, "\\")));
-			webpage = "file://" + webpage;
-			
+
+			// This should hopefully work on all platforms (it does on Win and Linux)
+			// First, check if "webpage" is an URI already:
+			var isUri = webpage.search(/^((f|ht)tps?|chrome|about|file):\/{0,3}/) === 0;
+			// We will need special treatment of backslashes in windows
+			var isWin = navigator.platform.search(/Win\d+$/) === 0;
+
+			try {
+			    if (!isUri) {
+					if (isWin)
+						webpage = webpage.replace(/\//g, "\\");
+					webpage = sv.tools.file.getURI(sv.tools.file.getfile(webpage));
+			    }
+			} catch (e) {
+			    // fallback:
+			    if (!isUri)
+				webpage = "file://" + webpage;
+
+			    sv.log.exception(e, "sv.command.openHelp");
+			}
+
+
 			// We want to display a specific page
 			if (typeof(RHelpWin) == "undefined" || RHelpWin.closed) {
 				sv.log.debug("Starting R help with page " + webpage);

Deleted: komodo/SciViews-K/content/js/tools/e4x2dom.js
===================================================================
--- komodo/SciViews-K/content/js/tools/e4x2dom.js	2009-09-27 10:02:42 UTC (rev 198)
+++ komodo/SciViews-K/content/js/tools/e4x2dom.js	2009-09-27 13:47:00 UTC (rev 199)
@@ -1,75 +0,0 @@
-// SciViews-K E4X functions, 'sv.tools.e4xdom' namespace
-// From this post and modified by R. Francois so that it works with XUL:
-// http://ecmanaut.blogspot.com/2006/03/e4x-and-dom.html
-// License: MPL 1.1/GPL 2.0/LGPL 2.1
-////////////////////////////////////////////////////////////////////////////////
-// sv.tools.e4x2dom.importNode(e4x, doc);     // Translate e4x node to DOM node
-// sv.tools.e4x2dom.appendTo(e4x, node, doc); // Append e4x node to a DOM node
-// sv.tools.e4x2dom.setContent(e4x, node);    // Idem, but clear DOM node first
-// sv.tools.e4x2dom.append(e4x, node, i);     // Append at 'i'th position
-// sv.tools.e4x2dom.clear(node);              // Clear a DOM node
-// sv.tools.e4x2dom.d4e(domNode);             // Translate DOM node to e4x node
-////////////////////////////////////////////////////////////////////////////////
-
-// Define the 'sv.tools.e4x2dom' namespace
-if (typeof(sv.tools.e4x2dom) == 'undefined') sv.tools.e4x2dom = new Object();
-
-// Translate e4x (JavaScript) node into a DOM node
-sv.tools.e4x2dom.importNode = function (e4x, doc) {
-	var me = this.importNode, xhtml, domTree, importMe;
-	me.Const = me.Const || { mimeType: 'text/xml' };
-	me.Static = me.Static || {};
-	me.Static.parser = me.Static.parser || new DOMParser;
-	xhtml = <testing
-		xmlns:html="http://www.w3.org/1999/xhtml"
-		xmlns:svg="http://www.w3.org/2000/svg"
-		xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
-		xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"/>;
-	xhtml.test = e4x;
-	domTree = me.Static.parser.parseFromString( xhtml.toXMLString().
-		replace( />\n *</g, "><" ), me.Const.mimeType);
-	importMe = domTree.documentElement.firstChild;
-	while(importMe && importMe.nodeType != 1)
-		importMe = importMe.nextSibling;
-	if(!doc) doc = document;
-	return importMe ? doc.importNode(importMe, true) : null;
-}
-
-// Append an e4x node to a DOM node
-sv.tools.e4x2dom.appendTo = function (e4x, node, doc) {
-	return(node.appendChild(this.importNode(e4x, doc || node.ownerDocument)));
-}
-
-// Append an e4x node to a DOM node, clearing it first
-sv.tools.e4x2dom.setContent = function (e4x, node) {
-	this.clear(node);
-	this.appendTo(e4x, node);
-}
-
-// Append an e4x node to a DOM node, clear first or not depending on 'i'
-sv.tools.e4x2dom.append = function (e4x, node, i) {
-	if (i == 0) {
-		this.setContent(e4x, node);
-	} else {
-		this.appendTo(e4x, node);
-	}
-}
-
-// Clear a DOM node
-sv.tools.e4x2dom.clear = function (node) {
-	while(node.firstChild)
-		node.removeChild(node.firstChild);
-}
-
-// Translate a DOM node into an e4x (JavaScript) node
-sv.tools.e4x2dom.d4e = function (domNode) {
-	var xmls = new XMLSerializer();
-	return(new XML(xmls.serializeToString(domNode)));
-}
-
-var HTML = "http://www.w3.org/1999/xhtml";
-var XUL  = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
-var SVG  = "http://www.w3.org/2000/svg";
-var RDF  = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
-
-default xml namespace = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";

Modified: komodo/SciViews-K/content/js/tools/file.js
===================================================================
--- komodo/SciViews-K/content/js/tools/file.js	2009-09-27 10:02:42 UTC (rev 198)
+++ komodo/SciViews-K/content/js/tools/file.js	2009-09-27 13:47:00 UTC (rev 199)
@@ -25,7 +25,8 @@
 if (typeof(sv.tools) == 'undefined')
 	sv.tools = {};
 // Define the 'sv.tools.file' namespace
-if (typeof(sv.tools.file) == 'undefined') sv.tools.file = new Object();
+if (typeof(sv.tools.file) == 'undefined')
+	sv.tools.file = {};
 
 (function () {
 	// Default file encoding to use
@@ -152,11 +153,14 @@
 					getService(Components.interfaces.nsIProperties).
 					get(baseDir, Components.interfaces.nsILocalFile);
 			} catch(e) {
+				sv.log.exception(e, "sv.tools.file.getfile: get " + baseDir);
 				file = Components.classes["@mozilla.org/file/local;1"].
 					createInstance(Components.interfaces.nsILocalFile);
 				try {
 					file.initWithPath(baseDir);
 				} catch (e) {
+					sv.log.exception(e,
+						"sv.tools.file.getfile: file.initWithPath(" + baseDir + ")");
 					return null;
 				}
 			}

Added: komodo/SciViews-K/skin/images/find.png
===================================================================
(Binary files differ)


Property changes on: komodo/SciViews-K/skin/images/find.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: komodo/SciViews-K/skin/sciviewsk.css
===================================================================
--- komodo/SciViews-K/skin/sciviewsk.css	2009-09-27 10:02:42 UTC (rev 198)
+++ komodo/SciViews-K/skin/sciviewsk.css	2009-09-27 13:47:00 UTC (rev 199)
@@ -110,6 +110,10 @@
 	list-style-image: url("chrome://sciviewsk/skin/images/toggle_open.png");
 }
 
+.find-icon {
+	list-style-image: url("chrome://sciviewsk/skin/images/find.png");
+}
+
 .r-objects-filter:hover,
 .r-objects-filter:hover:active {
 	list-style-image: url("chrome://sciviewsk/skin/images/filter-a.png");
@@ -163,6 +167,12 @@
 	color: #800000;
 }
 
+#sciviews_robjects_objects_tree treechildren::-moz-tree-cell-text(default-value) {
+	font-style: italic;
+	color: #800040;
+}
+
+
 #sciviews_robjects_objects_tree treechildren::-moz-tree-cell-text(class-package) {
 	font-weight: bold;
 }


Property changes on: komodo/SciViews-K/templates
___________________________________________________________________
Name: svn:ignore
   + !*
*-dev.*


Modified: komodo/SciViews-K/templates/.Rprofile
===================================================================
--- komodo/SciViews-K/templates/.Rprofile	2009-09-27 10:02:42 UTC (rev 198)
+++ komodo/SciViews-K/templates/.Rprofile	2009-09-27 13:47:00 UTC (rev 199)
@@ -2,6 +2,7 @@
 # SciViews-R installation and startup for running R with Komodo/SciViews-K
 # Version 0.9.0, 2009-09-20 Ph. Grosjean (phgrosjean at sciviews.org)
 
+# TODO: Include all this as a function in svMisc??
 # Make sure we don't process this twice in case of duplicate items in .Rprofile
 if (!exists(".SciViewsReady", envir = .GlobalEnv)) {
 	.SciViewsReady <- FALSE
@@ -376,6 +377,8 @@
 				path.expand(getOption("R.initdir")), sep = ""))
 		}
 		rm(koact, Komodo, args, msg)
+		# update
+		invisible(koCmd("sv.socket.updateCharset();"));
 	}
 }
 ### SciViews install end ###



More information about the Sciviews-commits mailing list