[Sciviews-commits] r122 - in komodo/SciViews-K: content content/js content/js/tools templates

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Mar 17 21:27:12 CET 2009


Author: prezez
Date: 2009-03-17 21:27:12 +0100 (Tue, 17 Mar 2009)
New Revision: 122

Modified:
   komodo/SciViews-K/content/js/commands.js
   komodo/SciViews-K/content/js/tools/io.js
   komodo/SciViews-K/content/overlayMain.xul
   komodo/SciViews-K/templates/.Rprofile
Log:
added: sv.io.makePath - creates (os-independent) path (also to special dirs)
changed sv.command.setControllers: no longer needs "ko.interpolate.interpolateStrings" to get special directories
modified .Rprofile, to use "koAppFile" environment variable to find Komodo, if available.



Modified: komodo/SciViews-K/content/js/commands.js
===================================================================
--- komodo/SciViews-K/content/js/commands.js	2009-03-12 08:12:30 UTC (rev 121)
+++ komodo/SciViews-K/content/js/commands.js	2009-03-17 20:27:12 UTC (rev 122)
@@ -100,6 +100,7 @@
 	  sv);
 }
 
+
 this.setControllers = function() {
 	// make these commands active only when current document language is R
 	var cmdNames = ["RunAll", "SourceAll", "RunBlock", "RunFunction", "RunLine", "RunPara",
@@ -137,22 +138,25 @@
 	viewManager.prototype.do_cmd_sv_RSourceFunction = function()	{ sv.r.source("function"); };
 
 
-	// TODO: submenu with checkboxes to select preferred way to start R
 	viewManager.prototype.do_cmd_svStartR = function()	{
 		// runIn = "command-output-window", "new-console",
 		//env strings: "ENV1=fooJ\nENV2=bar"
 		//gPrefSvc.prefs.getStringPref("runEnv");
 
+		var isWin = navigator.platform == "Win32";
 		var preferredRApp = sv.prefs.getString("sciviews.preferredRApp", "r-terminal");
 
+		var env = ["koId=" + sv.prefs.getString("sciviews.client.id", "SciViewsK"),
+				   "koHost=localhost",
+				   "koActivate=FALSE",
+				   "Rinitdir=" + sv.io.makePath(isWin? "Pers" : "Home"),
+				   "koServe=" + sv.prefs.getString("sciviews.client.socket", "8888"),
+				   "koPort=" + sv.prefs.getString("sciviews.server.socket", "7052"),
+				   "koAppFile=" + sv.io.makePath("resource:app", ["komodo" + (isWin? ".exe" : "")])
+		   ];
 
-		var env = ["koPort=%(pref:sciviews.server.socket)", "koId=%(pref:sciviews.client.id)", "koHost=localhost",
-			 "koActivate=FALSE", "Rinitdir=~", "koServe=%(pref:sciviews.client.socket)"];
+		var cwd = sv.io.makePath("ProfD", ["extensions", "sciviewsk at sciviews.org", "templates"]);
 
-		var cwd = "%(path:hostUserDataDir)/XRE/extensions/sciviewsk at sciviews.org/templates";
-		cwd = ko.interpolate.interpolateStrings(cwd);
-
-
 		var command, mode = "no-console";
 
 		switch (preferredRApp) {
@@ -188,14 +192,14 @@
 				  mode = "new-console";
 
 		}
-		for (i in env) {
-			try {
-				env[i] = ko.interpolate.interpolateStrings(env[i]);
-			} catch (e) {
-				alert(e + "\n" + env[i]);
-				return;
-			}
-		}
+		//for (i in env) {
+		//	try {
+		//		env[i] = ko.interpolate.interpolateStrings(env[i]);
+		//	} catch (e) {
+		//		alert(e + "\n" + env[i]);
+		//		return;
+		//	}
+		//}
 		ko.run.runCommand(window, command, cwd, env.join("\n"), false,
 						  false, false, mode, false, false, false);
 	};
@@ -204,7 +208,7 @@
 }).apply(sv.command);
 
 
-//sv.cmdsSetControllers();
+//sv.command.setControllers();
 addEventListener("load", sv.command.setControllers, false);
 
 /*

Modified: komodo/SciViews-K/content/js/tools/io.js
===================================================================
--- komodo/SciViews-K/content/js/tools/io.js	2009-03-12 08:12:30 UTC (rev 121)
+++ komodo/SciViews-K/content/js/tools/io.js	2009-03-17 20:27:12 UTC (rev 122)
@@ -12,6 +12,8 @@
 
 //sv.io.tempFile(prefix)			// creates unique temporary file, accessible
 						// by all users, and returns its name
+//sv.io.makePath([specialDir], [pathComponents]) create path from array, and/or special directory name
+
 ////////////////////////////////////////////////////////////////////////////////
 
 // Define the 'sv.io' namespace
@@ -130,6 +132,37 @@
 	return tmpfile.path;
 }
 
+
+//specialDir - [optional] name for special directory, see special directory reference at
+//https://developer.mozilla.org/En/Code_snippets:File_I/O
+// eg. ProfD, TmpD, Home, Desk, Progs
+// pathComponents - [optional] array of directiory/file names to append
+function sv.io.makePath(specialDir, pathComponents) {
+	  var file;
+	  if (specialDir) {
+			file = Components.classes["@mozilla.org/file/directory_service;1"].
+				getService(Components.interfaces.nsIProperties).
+					get(specialDir, Components.interfaces.nsIFile);
+	  } else {
+			file = Components.classes["@mozilla.org/file/local;1"].
+			   createInstance(Components.interfaces.nsILocalFile);
+			try {
+				  if (pathComponents) {
+						file.initWithPath(pathComponents[0]);
+						pathComponents.shift();
+				  }
+			} catch (e) {}
+	  }
+	  if (pathComponents && pathComponents.length) {
+		   for (i in pathComponents)
+				file.append(pathComponents[i]);
+	  }
+	  return file.path;
+}
+
+
+
+
 /*
 Stuff:
 

Modified: komodo/SciViews-K/content/overlayMain.xul
===================================================================
--- komodo/SciViews-K/content/overlayMain.xul	2009-03-12 08:12:30 UTC (rev 121)
+++ komodo/SciViews-K/content/overlayMain.xul	2009-03-17 20:27:12 UTC (rev 122)
@@ -64,7 +64,7 @@
   <script type="application/x-javascript" src="chrome://sciviewsk/content/js/commands.js"/>
   <script type="application/x-javascript" src="chrome://sciviewsk/content/js/r-help.js"/>
 
-<stringbundleset id="svStringBundles">
+<stringbundleset>
 <stringbundle id="svBundle" src="chrome://sciviewsk/locale/main.properties" />
 </stringbundleset>
 
@@ -144,7 +144,7 @@
 		<menuitem id="r-tk" type="checkbox" checked="false" label="R tk" platform="Linux,Mac" />
 	  </menupopup>
 	</menu>
-	<!--<menuitem id="r_start_pkg_manager" observes="cmd_svOpenPkgManager" class="menuitem" />-->
+	<menuitem id="r_start_pkg_manager" observes="cmd_svOpenPkgManager" class="menuitem" />
 	<menuitem id="r_browse_wd" observes="cmd_svBrowseWD" class="menuitem-iconic r-working-dir-icon" />
 
 	<menuseparator/>

Modified: komodo/SciViews-K/templates/.Rprofile
===================================================================
--- komodo/SciViews-K/templates/.Rprofile	2009-03-12 08:12:30 UTC (rev 121)
+++ komodo/SciViews-K/templates/.Rprofile	2009-03-17 20:27:12 UTC (rev 122)
@@ -266,31 +266,43 @@
 
 		# Look if and where komodo is installed
 		if (.Platform$OS.type == "unix") {
-			Komodo <- "/usr/local/bin/komodo"	# Link should be created!
+			if (Sys.getenv("koAppFile") != "") {
+				Komodo <- Sys.getenv("koAppFile")
+			} else {
+				Komodo <- "/usr/local/bin/komodo"	# Link should be created!
+			}
 			# Check that this file exists
 			if (!file.exists(Komodo)) {
 				# File not found, display a message with missing link
 				Komodo <- NULL
-				cat("Komodo is not found by R. Please, follow instructions at\n",
-					"http://www.sciviews.org/SciViews-K to install it correctly.\n",
-					"In particular, you must create a symbolic link in /user/local/bin:\n",
-					"sudo ln -s <KomodoBinLocation>/komodo /usr/local/bin/komodo\n",
-					"otherwise, R cannot find it!\n")
+				cat("Komodo is not found by R. Please, follow instructions at",
+					"http://www.sciviews.org/SciViews-K to install it correctly.",
+					"In particular, you must create a symbolic link in /user/local/bin:",
+					"sudo ln -s <KomodoBinLocation>/komodo /usr/local/bin/komodo",
+					"otherwise, R cannot find it!", sep="\n")
 			} else {
 				# Change the editor and the pager to Komodo
 				options(editor = Komodo)
 				options(pager = svPager)
 			}
 		} else {
-			Komodo <- "komodo"	# On Windows, 'komodo' should be enough
-			# But for reasons that escape me, komodo seems to stip off its own
-			# directory from the path variable. So, I have to restore it from
-			# the Windows registry :-(
-			Ret <- tclRequire("registry", warn = TRUE)
-			Path <- tclvalue(.Tcl("registry get {HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment} {Path}"))
-			if (!is.null(Path) && !is.na(Path) && Path != "")
-				Sys.setenv(path = Path)
-			rm(Ret, Path)
+
+		    # if komodo path was passed in environment
+			if (file.exists(Sys.getenv("koAppFile"))) {
+				Komodo <-  paste("\"", Sys.getenv("koAppFile"), "\"", sep="")
+			} else {
+				Komodo <- "komodo"	# On Windows, 'komodo' should be enough
+				# But for reasons that escape me, komodo seems to stip off its own
+				# directory from the path variable. So, I have to restore it from
+				# the Windows registry :-(
+				Ret <- tclRequire("registry", warn = TRUE)
+				Path <- tclvalue(.Tcl("registry get {HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment} {Path}"))
+				if (!is.null(Path) && !is.na(Path) && Path != "")
+					Sys.setenv(path = Path)
+				rm(Ret, Path)
+			}
+
+
 			owarn <- getOption("warn")
 			options(warn = -1)
 			# Try to run Komodo now
@@ -361,4 +373,4 @@
 		rm(koact, Komodo, args)
 	}
 }
-### SciViews install end ###
\ No newline at end of file
+### SciViews install end ###



More information about the Sciviews-commits mailing list