[Sciviews-commits] r237 - in komodo/SciViews-K: . content content/js
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Dec 22 11:11:32 CET 2009
Author: phgrosjean
Date: 2009-12-22 11:11:32 +0100 (Tue, 22 Dec 2009)
New Revision: 237
Added:
komodo/SciViews-K/content/Rinterpolationhelp.xul
komodo/SciViews-K/content/Rinterpolationquery.xul
komodo/SciViews-K/content/js/interpolate.js
komodo/SciViews-K/content/js/rinterpolationquery.js
Modified:
komodo/SciViews-K/SciViews-K.kpf
komodo/SciViews-K/content/RHelpWindow.xul
komodo/SciViews-K/content/js/r.js
komodo/SciViews-K/content/js/sciviews.js
komodo/SciViews-K/content/overlayMain.xul
komodo/SciViews-K/sciviewsk-0.9.9-ko.xpi
Log:
Custom interpolationquery dialog box
Modified: komodo/SciViews-K/SciViews-K.kpf
===================================================================
--- komodo/SciViews-K/SciViews-K.kpf 2009-12-17 13:21:48 UTC (rev 236)
+++ komodo/SciViews-K/SciViews-K.kpf 2009-12-22 10:11:32 UTC (rev 237)
@@ -818,4 +818,7 @@
<boolean id="import_recursive">1</boolean>
<string id="import_type">useFolders</string>
</preference-set>
+<preference-set idref="6200c0ed-45ec-4f46-a159-284803d65c04/content/js/rinterpolationquery.js">
+ <string id="spellcheckLangID">en-US</string>
+</preference-set>
</project>
Modified: komodo/SciViews-K/content/RHelpWindow.xul
===================================================================
--- komodo/SciViews-K/content/RHelpWindow.xul 2009-12-17 13:21:48 UTC (rev 236)
+++ komodo/SciViews-K/content/RHelpWindow.xul 2009-12-22 10:11:32 UTC (rev 237)
@@ -60,7 +60,6 @@
var rHelpBrowser;
var rHelpTopic;
-
function go(uri, loadFlags) {
// these are still undefined when calling .go on load event,
// so define them here:
Added: komodo/SciViews-K/content/Rinterpolationhelp.xul
===================================================================
--- komodo/SciViews-K/content/Rinterpolationhelp.xul (rev 0)
+++ komodo/SciViews-K/content/Rinterpolationhelp.xul 2009-12-22 10:11:32 UTC (rev 237)
@@ -0,0 +1,230 @@
+<?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):
+ Philippe Grosjean
+ 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/global.css" type="text/css"?>
+<?xml-stylesheet href="chrome://komodo/skin/global/global.css" type="text/css"?>
+<?xml-stylesheet href="chrome://global/skin/toolbarbutton.css" type="text/css"?>
+<?xml-stylesheet href="chrome://komodo/skin/bindings/buttons.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"?>
+<?xml-stylesheet href="chrome://sciviewsk/skin/rhelpwin.css" type="text/css"?>
+
+<dialog id="dialog-interpolationhelp"
+ xmlns:html="http://www.w3.org/1999/xhtml"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+ onload="OnLoad()"
+ orient="vertical"
+ width="700" height="500" screenX="20" screenY="20"
+ persist="screenX screenY width height"
+ style="min-height: 400px; min-width: 300px;"
+ flex="1"
+ buttons="cancel,accept"
+ ondialogcancel="return true;"
+ ondialogaccept="Go(); return false;">
+
+<script type="text/javascript">
+<![CDATA[
+
+var rHelpBrowser;
+var rHelpTopic;
+var rHomepage;
+const nsIWebNavigation = Components.interfaces.nsIWebNavigation;
+
+function OnLoad() {
+ rHelpBrowser = document.getElementById("rsnippethelp-browser");
+ rHelpBrowser.addProgressListener(progressListener,
+ Components.interfaces.nsIWebProgress.NOTIFY_STATE_DOCUMENT);
+ rHelpTopic = document.getElementById("rsnippethelp-topic");
+
+ var dialog = document.getElementById("dialog-interpolationhelp")
+ var cancelButton = dialog.getButton("cancel");
+ cancelButton.setAttribute("value", "Close");
+ cancelButton.setAttribute("accesskey", "c");
+ var okButton = dialog.getButton("accept");
+ okButton.setAttribute("hidden", "true");
+
+ // Process input arguments.
+ if (typeof window.arguments[0].title != "undefined" &&
+ window.arguments[0].title != null) {
+ document.title = window.arguments[0].title;
+ } else {
+ document.title = "Interpolation Help";
+ }
+
+ // Set home page to the page provided on startup
+ if (typeof window.arguments[0].uri != "undefined" &&
+ window.arguments[0].uri != null) {
+ rHomepage = window.arguments[0].uri;
+ } else {
+ rHomepage = "bout:blank";
+ }
+ rHelpTopic.value = rHomepage;
+ rHelpBrowser.webNavigation.loadURI(rHomepage,
+ nsIWebNavigation.LOAD_FLAGS_NONE, null, null, null);
+}
+
+function Go() {
+ rHelpBrowser.webNavigation.loadURI(rHelpTopic.value,
+ nsIWebNavigation.LOAD_FLAGS_NONE, null, null, null);
+}
+
+function Home() {
+ rHelpBrowser.webNavigation.loadURI(rHomepage,
+ nsIWebNavigation.LOAD_FLAGS_NONE, null, null, null);
+}
+
+// Browser progress listener:
+// so far used only to change location text
+
+// From: https://developer.mozilla.org/en/Code_snippets/Progress_Listeners
+
+var progressListener = {
+ QueryInterface: function(aIID) {
+ if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
+ aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
+ aIID.equals(Components.interfaces.nsISupports))
+ return this;
+ throw Components.results.NS_NOINTERFACE;
+ },
+
+ onStateChange: function(aWebProgress, aRequest, aFlag, aStatus) {
+ // If you use myListener for more than one tab/window, use
+ // aWebProgress.DOMWindow to obtain the tab/window which
+ // triggers the state change
+
+ if (aFlag & Components.interfaces.nsIWebProgressListener.STATE_START) {
+ // This fires when the load event is initiated
+ document.getElementById("cmd_stop")
+ .setAttribute("disabled", false);
+
+ document.getElementById("cmd_stop").hidden = false;
+ document.getElementById("cmd_reload").hidden = true;
+ }
+
+ if (aFlag & Components.interfaces.nsIWebProgressListener.STATE_STOP) {
+ // This fires when the load finishes
+ rHelpTopic.value = aWebProgress.DOMWindow.document.location;
+
+ document.getElementById("cmd_stop")
+ .setAttribute("disabled", true);
+
+ document.getElementById("cmd_stop").hidden = true;
+ document.getElementById("cmd_reload").hidden = false;
+
+ document.getElementById("cmd_go_back")
+ .setAttribute("disabled", !rHelpBrowser.webNavigation
+ .canGoBack)
+ document.getElementById("cmd_go_forward")
+ .setAttribute("disabled", !rHelpBrowser.webNavigation
+ .canGoForward);
+ }
+ },
+
+ onLocationChange: function(aProgress, aRequest, aURI){
+ // This fires when the location bar changes; i.e load event is
+ // confirmed or when the user switches tabs. If you use
+ // myListener for more than one tab/window, use
+ // aProgress.DOMWindow to obtain the tab/window which triggered
+ //the change.
+ },
+
+ // For definitions of the remaining functions see XULPlanet.com
+ onProgressChange: function(aWebProgress, aRequest, curSelf,
+ maxSelf, curTot, maxTot) { },
+ onStatusChange: function(aWebProgress, aRequest, aStatus,
+ aMessage) { },
+ onSecurityChange: function(aWebProgress, aRequest, aState) { }
+}
+
+]]>
+</script>
+
+<keyset id="keyset_main">
+ <key id="key_go_back" keycode="VK_BACK" command="cmd_go_back" modifiers="" />
+ <key id="key_go_home" keycode="VK_HOME" command="cmd_go_home" modifiers="alt" />
+</keyset>
+
+<commandset id="commandset_main">
+ <command id="cmd_go" oncommand="Go();" disabled="false"
+ label="Go" tooltiptext="Go" />
+ <command id="cmd_go_back" oncommand="rHelpBrowser.goBack();" disabled="false"
+ label="Back" tooltiptext="Back" />
+ <command id="cmd_go_forward" oncommand="rHelpBrowser.goForward();" disabled="false"
+ label="Forward" tooltiptext="Forward" />
+ <command id="cmd_go_home" oncommand="Home();"
+ label="Home" tooltiptext="Home" />
+ <command id="cmd_stop" oncommand="rHelpBrowser.stop(rHelpBrowser.webNavigation.STOP_ALL);"
+ label="Stop" tooltiptext="Stop" />
+ <command id="cmd_reload" oncommand="rHelpBrowser.reload();"
+ label="Reload page" tooltiptext="Reload page" />
+</commandset>
+
+<toolbox id="rsnippethelp-toolbox" class="toolbox-top" mode="icons"
+ defaultmode="icons" iconsize="small">
+ <toolbar type="toolbar" id="nav-toolbar" class="toolbar"
+ mode="icons" iconsize="small"
+ defaulticonsize="small">
+ <toolbarbutton id="rsnippethelp-back-button" class="history-back-icon"
+ command="cmd_go_back" buttonstyle="pictures"/>
+ <toolbarbutton id="rsnippethelp-forward-button" class="history-forward-icon"
+ command="cmd_go_forward" buttonstyle="pictures"/>
+ <toolbarbutton id="rsnippethelp-home" class="home-icon"
+ command="cmd_go_home" buttonstyle="pictures"/>
+ <toolbarbutton id="rsnippethelp-stop-button" class="stop-icon"
+ command="cmd_stop" buttonstyle="pictures"/>
+ <toolbarbutton id="rsnippethelp-reload-button" class="reload-icon"
+ command="cmd_reload" buttonstyle="pictures"/>
+ <vbox align="stretch" flex="1">
+ <textbox id="rsnippethelp-topic" flex="0"
+ emptytext="web page"
+ tooltiptext="Web page"
+ />
+ </vbox>
+ <toolbarbutton id="rhelp-go" class="go-icon"
+ command="cmd_go" buttonstyle="pictures"/>
+ <spacer flex="1"/>
+ </toolbar>
+</toolbox>
+
+<vbox flex="1">
+ <hbox flex="1">
+ <browser id="rsnippethelp-browser" type="content-primary"
+ src="about:blank" flex="1"
+ />
+ </hbox>
+</vbox>
+</dialog>
Added: komodo/SciViews-K/content/Rinterpolationquery.xul
===================================================================
--- komodo/SciViews-K/content/Rinterpolationquery.xul (rev 0)
+++ komodo/SciViews-K/content/Rinterpolationquery.xul 2009-12-22 10:11:32 UTC (rev 237)
@@ -0,0 +1,101 @@
+<?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 Komodo code.
+ Modified and adapted for SciViews-K by Ph. Grosjean.
+
+ The Initial Developer of the Original Code is ActiveState Software Inc.
+ Portions created by ActiveState Software Inc are Copyright (C) 2000-2007
+ ActiveState Software Inc. All Rights Reserved.
+
+ Contributor(s):
+ ActiveState Software Inc
+ Ph. Grosjean
+
+ 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 ***** -->
+
+<!-- String interpolation query dialog.
+
+ This dialog expects an object as the first window argument with the
+ following properties:
+ "queries" is an array of KoIInterpolationQuery's objects.
+ "title" is an appropriate title for the query dialog (a value of
+ null will trigger the default title).
+
+ On exit:
+ "queries" elements will be modified in-place with the user's answers.
+ "retval" will be set to "ok" or "cancel".
+ -->
+
+<?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?>
+<?xml-stylesheet href="chrome://komodo/skin/global/global.css" type="text/css"?>
+<?xml-stylesheet href="chrome://komodo/skin/autocomplete.css" type="text/css"?>
+
+<dialog id="dialog-interpolationquery"
+ xmlns:html="http://www.w3.org/1999/xhtml"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+ onload="OnLoad()"
+ orient="vertical"
+ style="min-width: 40em; max-width: 55em;"
+ flex="1"
+ buttons="help,accept,cancel"
+ ondialogaccept="return OK();"
+ ondialogcancel="return Cancel();"
+ ondialoghelp="alert('Sorry, not help currently available!');">
+
+ <script src="chrome://xtk/content/xtk.js" type="application/x-javascript;version=1.7"/>
+ <script type="application/x-javascript;version=1.7" src="chrome://komodo/content/library/logging.js"/>
+ <script type="application/x-javascript;version=1.7" src="chrome://komodo/content/library/trace.js"/>
+ <script type="application/x-javascript;version=1.7" src="chrome://komodo/content/library/mru.js"/>
+ <script type="application/x-javascript;version=1.7" src="chrome://sciviewsk/content/js/rinterpolationquery.js"/>
+
+ <popupset>
+ <panel type="autocomplete" id="popupTextboxAutoComplete" noautofocus="true"/>
+ </popupset>
+
+ <vbox>
+ <!--PhG: how can I get a description area with multiple lines that nicely
+ fit in width in the dialog box? I can only do a single line, or use a
+ disabled textbox, but that does not fill well too!!!-->
+ <!--<textbox id="query-desc"
+ disabled="true" multiline="true" hidden="true" style="background-color:gray">
+ </textbox>-->
+ <description id="query-desc" crop="end">
+ </description>
+ <separator class="thin"/>
+ <grid>
+ <columns>
+ <!--<column style="min-width: 100px;" flex="1"/>-->
+ <!--<column style="min-width: 200px;" flex="1"/>-->
+ <column />
+ <column flex="1"/>
+ </columns>
+ <rows id="query-rows">
+ </rows>
+ </grid>
+ </vbox>
+ <separator class="thin"/>
+</dialog>
Added: komodo/SciViews-K/content/js/interpolate.js
===================================================================
--- komodo/SciViews-K/content/js/interpolate.js (rev 0)
+++ komodo/SciViews-K/content/js/interpolate.js 2009-12-22 10:11:32 UTC (rev 237)
@@ -0,0 +1,136 @@
+// SciViews-K interpolation function
+// Copyright (c) 2009, Ph. Grosjean (phgrosjean at sciviews.org)
+// License: MPL 1.1/GPL 2.0/LGPL 2.1
+////////////////////////////////////////////////////////////////////////////////
+// ko.interpolate.interpolate(); // A reworked version of the Komodo function
+// with more features needed by R code snippets (contextual help, description,
+// tooltips, ...)
+////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * * Interpolate '%'-escape codes in the given list(s) of strings.
+ *
+ * "editor" is a reference the komodo.xul window.
+ * "strings" is a list of raw strings to interpolate.
+ * "bracketedStrings" is a list of raw strings to interpolate, using the bracketed form
+ * "queryTitle" (optional) is a title for the possible query dialog raised
+ * during interpolation.
+ * "viewData" (optional) allows one to override specific view data used for
+ * interpolation. By default view data is retrieved from the current view.
+ * This may not always be appropriate. It may be an object with one or
+ * more of the following attributes:
+ * "fileName" is the filename of the current file (null, if N/A);
+ * "lineNum" is the current line number (0, if N/A);
+ * "word" is the current word under cursor (null if none);
+ * "selection" is the current selection (null if none).
+ *
+ * On success, this function returns a *double* list of interpolated strings:
+ * For each string in "strings" and "bracketedStrings" two strings are
+ * returned. The first is the interpolated string for use and the second for
+ * *display*. In most cases these are the same but they may differ, for
+ * example, if a password query response was interpolated into the string which
+ * should not be displayed in the Komodo UI.
+ *
+ * Otherwise an exception is raised and an error set on the last error service:
+ * koILastError errno reason
+ * ----------------------- -----------------------------------------
+ * NS_ERROR_ABORT User cancelled the query dialog.
+ * NS_ERROR_INVALID_ARG A normal interpolation failure because of
+ * invalid interp code usage.
+ */
+ko.interpolate.interpolate = function Interpolate_interpolate(editor, strings,
+ bracketedStrings,
+ queryTitle /* =null */,
+ viewData /* =<determined from current view> */)
+{
+ try {
+ if (typeof queryTitle == 'undefined') queryTitle = null;
+ log.info("interpolate.interpolate(editor, strings=["+strings+
+ "], bracketedStrings=["+bracketedStrings+"], queryTitle='"+
+ queryTitle+"', viewData)");
+ viewData = ko.interpolate.getViewData(editor, viewData);
+
+ var lastErrorSvc = Components.classes["@activestate.com/koLastErrorService;1"]
+ .getService(Components.interfaces.koILastErrorService);
+
+ // Interpolation step 1: get queries.
+ var queriesCountObj = new Object();
+ var queriesObj = new Array();
+ var i1countObj = new Object();
+ var i1stringsObj = new Array();
+
+ //XXX The prefset used may need to be the project prefs at some point in
+ // the future, for now we'll stick with the current view's prefset.
+ var iSvc = Components.classes["@activestate.com/koInterpolationService;1"]
+ .getService(Components.interfaces.koIInterpolationService);
+ iSvc.Interpolate1(strings.length, strings,
+ bracketedStrings.length, bracketedStrings,
+ viewData.fileName, viewData.lineNum,
+ viewData.word, viewData.selection,
+ viewData.projectFile,
+ viewData.prefSet,
+ queriesCountObj, queriesObj,
+ i1countObj, i1stringsObj);
+ var queries = queriesObj.value;
+ var istrings = i1stringsObj.value;
+
+ // Ask the user for required data. (If there are no queries then we are
+ // done interpolating.)
+ if (queries.length != 0) {
+ var obj = new Object();
+ obj.queries = queries;
+ obj.title = queryTitle;
+ // PhG: this is added to allow access to sv... functions
+ obj.sv = sv;
+
+ // PhG: replaced this by my own dialog box with extra features
+ //window.openDialog("chrome://komodo/content/run/interpolationquery.xul",
+ window.openDialog("chrome://sciviewsk/content/Rinterpolationquery.xul",
+ "Komodo:InterpolationQuery",
+ "chrome,modal,titlebar",
+ obj);
+ if (obj.retval == "Cancel") {
+ var errmsg = "Interpolation query cancelled.";
+ lastErrorSvc.setLastError(Components.results.NS_ERROR_ABORT, errmsg);
+ throw errmsg;
+ }
+
+ // Interpolation step 2: interpolated with answered queries.
+ var i2countObj = new Object();
+ var i2stringsObj = new Array();
+ iSvc.Interpolate2(istrings.length, istrings,
+ queries.length, queries,
+ i2countObj, i2stringsObj);
+ istrings = i2stringsObj.value;
+ }
+
+ // PhG: If there is a end indicator in the snippet (______ at the start
+ // of a line), then cut the string there
+ for (var i = 0; i < istrings.length; i++) {
+ //istrings[i] = istrings[i].replace(/[\n\r]{1,2}.*$/, "");
+ // Do we need to eliminate a part of the snippet?
+ var isplit = istrings[i].split(/[\n\r]{1,2}______/);
+ if (isplit.length > 1) {
+ // Keep only first part
+ istrings[i] = isplit[0];
+ // The string must contain both !@#_currentPos and !@#_anchor
+ if (istrings[i].indexOf("!@#_currentPos") == -1) {
+ // If !@#_anchor is there, add !@#_currentPos at the end
+ if (istrings[i].indexOf("!@#_anchor") > -1) {
+ istrings[i] = istrings[i] + "!@#_currentPos";
+ }
+ } else { // !@#_currentPos is there, make sure !@#_anchor is also there
+ if (istrings[i].indexOf("!@#_anchor") == -1) {
+ istrings[i] = istrings[i] + "!@#_anchor";
+ }
+ }
+ }
+ }
+
+ log.info("interpolate.interpolate: istrings=["+istrings+"]");
+ return istrings;
+ } catch(e) {
+ log.exception(e);
+ throw e;
+ }
+}
Modified: komodo/SciViews-K/content/js/r.js
===================================================================
--- komodo/SciViews-K/content/js/r.js 2009-12-17 13:21:48 UTC (rev 236)
+++ komodo/SciViews-K/content/js/r.js 2009-12-22 10:11:32 UTC (rev 237)
@@ -623,7 +623,7 @@
var cmd = '';
cmd += pkg? ' package = "' + pkg + '", ' : "";
cmd += topic? ' topic = "' + topic + '", ' : "";
- cmd = 'cat(getHelpURL(help(' + cmd + ' htmlhelp = TRUE)))';
+ cmd = 'cat(getHelpURL(help(' + cmd + ' help_type = "html")))';
// Old version for R < 2.10: cmd = 'cat(unclass(help(' + cmd + ' htmlhelp = TRUE)))';
// TODO: error handling when package does not exists
res = sv.r.evalCallback(cmd, sv.command.openHelp);
Added: komodo/SciViews-K/content/js/rinterpolationquery.js
===================================================================
--- komodo/SciViews-K/content/js/rinterpolationquery.js (rev 0)
+++ komodo/SciViews-K/content/js/rinterpolationquery.js 2009-12-22 10:11:32 UTC (rev 237)
@@ -0,0 +1,283 @@
+// SciViews-K interpolationquery functions
+// Define functions to drive the custom interpolationquery dialog box
+////////////////////////////////////////////////////////////////////////////////
+
+/* ***** 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 Komodo code.
+ * Modified and adapted for SciViews-K by Ph. Grosjean.
+ *
+ * The Initial Developer of the Original Code is ActiveState Software Inc.
+ * Portions created by ActiveState Software Inc are Copyright (C) 2000-2007
+ * ActiveState Software Inc. All Rights Reserved.
+ *
+ * Contributor(s):
+ * ActiveState Software Inc
+ * Ph. Grosjean
+ *
+ * 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 ***** */
+
+/* String interpolation query dialog (see interpolate.js)
+ *
+ * Used when a strings being interpolated include codes requiring that the user
+ * be asked for information to place in the string.
+ *
+ * With this version, we got more help on the code being constructed
+ * and also the possibility to fill mru lists using a R command
+ */
+
+var gQueries = null;
+var gSv = null;
+var gHelpWin = null;
+
+function OnLoad() {
+ var dialog = document.getElementById("dialog-interpolationquery")
+ var okButton = dialog.getButton("accept");
+ var cancelButton = dialog.getButton("cancel");
+ okButton.setAttribute("accesskey", "o");
+ cancelButton.setAttribute("accesskey", "c");
+
+ // PhG added to provide further help on R snippets
+ var helpButton = dialog.getButton("help");
+ helpButton.setAttribute("accesskey", "?");
+ helpButton.setAttribute("hidden", "true"); // Hidden by default
+
+ // Process input arguments.
+ if (typeof window.arguments[0].title != "undefined" &&
+ window.arguments[0].title != null) {
+ document.title = window.arguments[0].title;
+ } else {
+ document.title = "Interpolation Query";
+ }
+ gQueries = window.arguments[0].queries;
+ gSv = window.arguments[0].sv;
+
+ // Generate UI for the queries.
+ var queryRows = document.getElementById("query-rows");
+ var q, label, textbox, row, hbox, i;
+ var j = 0;
+ try {
+ for (i = 0; i < gQueries.length; i++) {
+ // Want the following XUL for each query:
+ // <row align="center">
+ // <label id="query0-label"
+ // value="QUESTION"
+ // control="query0-textbox"
+ // crop="end"
+ // flex="1"/>
+ // <textbox id="query<i>-textbox"
+ // style="min-height: 1.8em;"
+ // flex="1"
+ // value="<answer>"
+ // type="autocomplete"
+ // autocompletepopup="popupTextboxAutoComplete"
+ // autocompletesearch="mru"
+ // autocompletesearchparam="dialog-interpolationquery-<mruName>Mru"
+ // maxrows="10"
+ // enablehistory="true"
+ // completeselectedindex="true"
+ // tabscrolling="true"
+ // ontextentered="this.focus();"
+ // onfocus="this.select();"/>
+ // </row>
+ //
+ // unless this is a password query (q.isPassword), then we want the
+ // <textbox/> to be:
+ // ...
+ // <textbox id="query<i>-textbox"
+ // style="min-height: 1.8em;"
+ // flex="1"
+ // value="<answer>"
+ // type="password"
+ // onfocus="this.select();"/>
+ // ...
+ q = gQueries[i];
+
+ // Special case: if query is "R-desc" or "R-tip", use it
+ // for extra features of our R interpolation query dialog box
+ // and make sure we return nothing from it
+ switch (q.question) {
+ case "R-desc":
+ var queryDesc = document.getElementById("query-desc");
+ if (queryDesc.value == "") {
+ queryDesc.value = q.answer;
+ queryDesc.setAttribute("tooltiptext", q.answer);
+ } else {
+ queryDesc.value = queryDesc.value + " " + q.answer;
+ queryDesc.setAttribute("tooltiptext", queryDesc.value);
+ }
+ //queryDesc.setAttribute("hidden", "false");
+ // Make sure we return nothing from here!
+ q.answer = "";
+ break;
+
+ case "R-tip":
+ // Set the tooltip text of a query box to this string
+ // They must appear in the same order as the querybox themselves
+ var id = "query"+j+"-textbox";
+ var queryTextbox = document.getElementById(id);
+ queryTextbox.setAttribute("tooltiptext", q.answer);
+ // Make sure we return nothing from here!
+ q.answer = "";
+ j = j+1;
+ break;
+
+ case "R-help":
+ case "URL-help":
+ helpButton.setAttribute("hidden", "false");
+ dialog.setAttribute("ondialoghelp",
+ "Help('" + q.answer + "');");
+ // Make sure we return nothing from here!
+ q.answer = "";
+ break;
+
+ case "RWiki-help":
+ helpButton.setAttribute("hidden", "false");
+ // Get the RWiki base URL
+ var baseURL = "http:/wiki.r-project.org/rwiki/doku.php?id="
+ baseURL = gSv.prefs.getString("sciviews.rwiki.help.base",
+ baseURL);
+ dialog.setAttribute("ondialoghelp",
+ "Help('" + baseURL + q.answer + "');");
+ // Make sure we return nothing from here!
+ q.answer = "";
+ break;
+
+ default:
+ row = document.createElement("row");
+ row.setAttribute("align", "center");
+
+ label = document.createElement("label");
+ label.setAttribute("id", "query"+i+"-label");
+ label.setAttribute("value", q.question+" =");
+ label.setAttribute("control", "query"+i+"-textbox");
+ label.setAttribute("crop", "end");
+ label.setAttribute("flex", "1");
+ row.appendChild(label);
+
+ textbox = document.createElement("textbox");
+ textbox.setAttribute("id", "query"+i+"-textbox");
+ textbox.setAttribute("style", "min-height: 1.8em;");
+ textbox.setAttribute("flex", "1");
+ if (q.answer) {
+ textbox.setAttribute("value", q.answer);
+ } else {
+ textbox.setAttribute("value", "");
+ }
+ textbox.setAttribute("onfocus", "this.select();");
+
+ if (q.isPassword) {
+ textbox.setAttribute("type", "password");
+ } else {
+ textbox.setAttribute("type", "autocomplete");
+ textbox.setAttribute("autocompletepopup", "popupTextboxAutoComplete");
+ textbox.setAttribute("autocompletesearch", "mru");
+ if (q.mruName) {
+ textbox.setAttribute("autocompletesearchparam",
+ "dialog-interpolationquery-"+q.mruName+"Mru");
+ textbox.setAttribute("enablehistory", "true");
+ } else {
+ // Disable autocomplete: no mruName given.
+ textbox.setAttribute("disableautocomplete", "true");
+ textbox.removeAttribute("enablehistory");
+ }
+ textbox.setAttribute("maxrows", "10");
+ textbox.setAttribute("completeselectedindex", "true");
+ // PhG: was set to true, but changed to false for easier navig
+ textbox.setAttribute("tabscrolling", "false");
+ textbox.setAttribute("ontextentered", "this.focus();");
+ }
+
+ row.appendChild(textbox);
+ queryRows.appendChild(row);
+ }
+ }
+ } catch(ex) {
+ dump("error adding interpolation query rows: "+ex+"\n");
+ }
+
+ window.sizeToContent();
+ dialog.moveToAlertPosition();
+}
+
+function OK() {
+ try { gHelpWin.closeHelp(); } catch(e) {}
+ // Store users answers to query objects.
+ for (var i = 0; i < gQueries.length; i++) {
+ var q = gQueries[i];
+ // Skip special %ask fields like "R-desc" or "R-tip"
+ if (!q.question.match(/^(R-desc|R-tip|R-help|RWiki-help|URL-help)$/i)) {
+ var id = "query"+i+"-textbox";
+ var queryTextbox = document.getElementById(id);
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/sciviews -r 237
More information about the Sciviews-commits
mailing list