Bug 657131 - Create a new Execute menu for Scratchpad; r=mihai.sucan,sdwilsh
authorRob Campbell <rcampbell@mozilla.com>
Sat, 21 May 2011 08:59:23 -0300
changeset 69847 2a10e886f3d7a4f43511ba88179bd440cf65b078
parent 69846 ac4c8689e717739894b00f188fe72fdf56c524f0
child 69848 ca4df27501e4c37cd28bd31b4c378763e5d17d35
push idunknown
push userunknown
push dateunknown
reviewersmihai.sucan, sdwilsh
bugs657131
milestone6.0a1
Bug 657131 - Create a new Execute menu for Scratchpad; r=mihai.sucan,sdwilsh
browser/base/content/scratchpad.js
browser/base/content/scratchpad.xul
browser/base/content/test/browser_scratchpad_contexts.js
browser/base/content/test/browser_scratchpad_execute_print.js
browser/base/content/test/browser_scratchpad_initialization.js
browser/base/content/test/browser_scratchpad_ui.js
browser/locales/en-US/chrome/browser/scratchpad.dtd
--- a/browser/base/content/scratchpad.js
+++ b/browser/base/content/scratchpad.js
@@ -278,53 +278,53 @@ var Scratchpad = {
            this.evalInContentSandbox(aString) :
            this.evalInChromeSandbox(aString);
   },
 
   /**
    * Execute the selected text (if any) or the entire textbox content in the
    * current context.
    */
-  execute: function SP_execute()
+  run: function SP_run()
   {
     let selection = this.selectedText || this.textbox.value;
     let result = this.evalForContext(selection);
     this.deselect();
     return [selection, result];
   },
 
   /**
    * Execute the selected text (if any) or the entire textbox content in the
    * current context. The resulting object is opened up in the Property Panel
    * for inspection.
    */
   inspect: function SP_inspect()
   {
-    let [selection, result] = this.execute();
+    let [selection, result] = this.run();
 
     if (result) {
       this.openPropertyPanel(selection, result);
     }
   },
 
   /**
    * Execute the selected text (if any) or the entire textbox content in the
-   * current context. The evaluation result is "printed" in the textbox after
+   * current context. The evaluation result is inserted into the textbox after
    * the selected text, or at the end of the textbox value if there is no
    * selected text.
    */
-  print: function SP_print()
+  display: function SP_display()
   {
     let selectionStart = this.textbox.selectionStart;
     let selectionEnd = this.textbox.selectionEnd;
     if (selectionStart == selectionEnd) {
       selectionEnd = this.textbox.value.length;
     }
 
-    let [selection, result] = this.execute();
+    let [selection, result] = this.run();
     if (!result) {
       return;
     }
 
     let firstPiece = this.textbox.value.slice(0, selectionEnd);
     let lastPiece = this.textbox.value.
                     slice(selectionEnd, this.textbox.value.length);
 
--- a/browser/base/content/scratchpad.xul
+++ b/browser/base/content/scratchpad.xul
@@ -65,19 +65,19 @@
   <command id="sp-cmd-save" oncommand="Scratchpad.saveFile();"/>
   <command id="sp-cmd-saveas" oncommand="Scratchpad.saveFileAs();"/>
 
   <!-- TODO: bug 650340 - implement printFile()
   <command id="sp-cmd-printFile" oncommand="Scratchpad.printFile();" disabled="true"/>
  -->
 
   <command id="sp-cmd-close" oncommand="window.close();"/>
-  <command id="sp-cmd-execute" oncommand="Scratchpad.execute();"/>
+  <command id="sp-cmd-run" oncommand="Scratchpad.run();"/>
   <command id="sp-cmd-inspect" oncommand="Scratchpad.inspect();"/>
-  <command id="sp-cmd-print" oncommand="Scratchpad.print();"/>
+  <command id="sp-cmd-display" oncommand="Scratchpad.display();"/>
   <command id="sp-cmd-contentContext" oncommand="Scratchpad.setContentContext();"/>
   <command id="sp-cmd-browserContext" oncommand="Scratchpad.setBrowserContext();" disabled="true"/>
   <command id="sp-cmd-resetContext" oncommand="Scratchpad.resetContext();"/>
   <command id="sp-cmd-errorConsole" oncommand="Scratchpad.openErrorConsole();" disabled="true"/>
   <command id="sp-cmd-webConsole" oncommand="Scratchpad.openWebConsole();"/>
 </commandset>
 
 <keyset id="sp-keyset">
@@ -113,27 +113,27 @@
        key="&copyCmd.key;"
        modifiers="accel"/>
   <key id="key_paste"
        key="&pasteCmd.key;"
        modifiers="accel"/>
   <key id="key_selectAll" key="&selectAllCmd.key;" modifiers="accel"/>
   <key id="key_undo" key="&undoCmd.key;" modifiers="accel"/>
   <key id="key_redo" key="&undoCmd.key;" modifiers="accel,shift"/>
-  <key id="sp-key-execute"
-       key="&execute.key;"
-       command="sp-cmd-execute"
+  <key id="sp-key-run"
+       key="&run.key;"
+       command="sp-cmd-run"
        modifiers="accel"/>
   <key id="sp-key-inspect"
        key="&inspect.key;"
        command="sp-cmd-inspect"
        modifiers="accel"/>
-  <key id="sp-key-print"
-       key="&print.key;"
-       command="sp-cmd-print"
+  <key id="sp-key-display"
+       key="&display.key;"
+       command="sp-cmd-display"
        modifiers="accel"/>
   <key id="sp-key-errorConsole"
        key="&errorConsoleCmd.commandkey;"
        command="sp-cmd-errorConsole"
        modifiers="accel,shift"/>
   <key id="sp-key-webConsole"
        key="&webConsoleCmd.commandkey;"
        command="sp-cmd-webConsole"
@@ -215,17 +215,16 @@
                 accesskey="&pasteCmd.accesskey;"
                 command="cmd_paste"/>
       <menuseparator/>
       <menuitem id="sp-menu-selectAll"
                 label="&selectAllCmd.label;"
                 key="key_selectAll"
                 accesskey="&selectAllCmd.accesskey;"
                 command="cmd_selectAll"/>
-      <menuseparator/>
 
       <!-- TODO: bug 650345 - implement search and replace
       <menuitem id="sp-menu-find"
                 label="&findOnCmd.label;"
                 accesskey="&findOnCmd.accesskey;"
                 key="key_find"
                 disabled="true"
                 command="cmd_find"/>
@@ -233,31 +232,37 @@
                 label="&findAgainCmd.label;"
                 accesskey="&findAgainCmd.accesskey;"
                 key="key_findAgain"
                 disabled="true"
                 command="cmd_findAgain"/>
       <menuseparator id="sp-execute-separator"/>
       -->
 
-      <menuitem id="sp-text-execute"
-                label="&execute.label;"
-                accesskey="&execute.accesskey;"
-                key="sp-key-execute"
-                command="sp-cmd-execute"/>
+    </menupopup>
+  </menu>
+
+  <menu id="sp-execute-menu" label="&executeMenu.label;"
+        accesskey="&executeMenu.accesskey;">
+    <menupopup id="sp-menu_executepopup">
+      <menuitem id="sp-text-run"
+                label="&run.label;"
+                accesskey="&run.accesskey;"
+                key="sp-key-run"
+                command="sp-cmd-run"/>
       <menuitem id="sp-text-inspect"
                 label="&inspect.label;"
                 accesskey="&inspect.accesskey;"
                 key="sp-key-inspect"
                 command="sp-cmd-inspect"/>
-      <menuitem id="sp-text-print"
-                label="&print.label;"
-                accesskey="&print.accesskey;"
-                key="sp-key-print"
-                command="sp-cmd-print"/>
+      <menuitem id="sp-text-display"
+                label="&display.label;"
+                accesskey="&display.accesskey;"
+                key="sp-key-display"
+                command="sp-cmd-display"/>
     </menupopup>
   </menu>
 
   <menu id="sp-environment-menu"
         label="&environmentMenu.label;"
         accesskey="&environmentMenu.accesskey;">
     <menupopup id="sp-menu-environment">
       <menuitem id="sp-menu-content"
@@ -301,31 +306,31 @@
   <menupopup id="scratchpad-text-popup">
     <menuitem id="menu_cut"/>
     <menuitem id="menu_copy"/>
     <menuitem id="menu_paste"/>
     <menuitem id="menu_delete"/>
     <menuseparator/>
     <menuitem id="menu_selectAll"/>
     <menuseparator/>
-    <menuitem id="sp-text-execute"
-              label="&execute.label;"
-              accesskey="&execute.accesskey;"
-              key="sp-key-execute"
-              command="sp-cmd-execute"/>
+    <menuitem id="sp-text-run"
+              label="&run.label;"
+              accesskey="&run.accesskey;"
+              key="sp-key-run"
+              command="sp-cmd-run"/>
     <menuitem id="sp-text-inspect"
               label="&inspect.label;"
               accesskey="&inspect.accesskey;"
               key="sp-key-inspect"
               command="sp-cmd-inspect"/>
-    <menuitem id="sp-text-print"
-              label="&print.label;"
-              accesskey="&print.accesskey;"
-              key="sp-key-print"
-              command="sp-cmd-print"/>
+    <menuitem id="sp-text-display"
+              label="&display.label;"
+              accesskey="&display.accesskey;"
+              key="sp-key-display"
+              command="sp-cmd-display"/>
   </menupopup>
 </popupset>
 
 <textbox id="scratchpad-textbox"
          multiline="true"
          flex="1"
          context="scratchpad-text-popup"
          placeholder="&textbox.placeholder;" />
--- a/browser/base/content/test/browser_scratchpad_contexts.js
+++ b/browser/base/content/test/browser_scratchpad_contexts.js
@@ -49,17 +49,17 @@ function runTests()
      "statusbar label is correct");
 
   ok(sp.textbox, "textbox exists");
   sp.textbox.value = "window.foobarBug636725 = 'aloha';";
 
   ok(!content.wrappedJSObject.foobarBug636725,
      "no content.foobarBug636725");
 
-  sp.execute();
+  sp.run();
 
   is(content.wrappedJSObject.foobarBug636725, "aloha",
      "content.foobarBug636725 has been set");
 
   sp.setBrowserContext();
 
   is(sp.executionContext, gScratchpadWindow.SCRATCHPAD_CONTEXT_BROWSER,
      "executionContext is chrome");
@@ -72,54 +72,54 @@ function runTests()
 
   is(statusbar.getAttribute("label"), chromeMenu.getAttribute("label"),
      "statusbar label is correct");
 
   sp.textbox.value = "window.foobarBug636725 = 'aloha2';";
 
   ok(!window.foobarBug636725, "no window.foobarBug636725");
 
-  sp.execute();
+  sp.run();
 
   is(window.foobarBug636725, "aloha2", "window.foobarBug636725 has been set");
 
   sp.textbox.value = "window.gBrowser";
 
-  is(typeof sp.execute()[1].addTab, "function",
+  is(typeof sp.run()[1].addTab, "function",
      "chrome context has access to chrome objects");
 
   // Check that the sandbox is cached.
 
   sp.textbox.value = "typeof foobarBug636725cache;";
-  is(sp.execute()[1], "undefined", "global variable does not exist");
+  is(sp.run()[1], "undefined", "global variable does not exist");
 
   sp.textbox.value = "var foobarBug636725cache = 'foo';";
-  sp.execute();
+  sp.run();
 
   sp.textbox.value = "typeof foobarBug636725cache;";
-  is(sp.execute()[1], "string",
+  is(sp.run()[1], "string",
      "global variable exists across two different executions");
 
   sp.resetContext();
 
-  is(sp.execute()[1], "undefined",
+  is(sp.run()[1], "undefined",
      "global variable no longer exists after calling resetContext()");
 
   sp.textbox.value = "var foobarBug636725cache2 = 'foo';";
-  sp.execute();
+  sp.run();
 
   sp.textbox.value = "typeof foobarBug636725cache2;";
-  is(sp.execute()[1], "string",
+  is(sp.run()[1], "string",
      "global variable exists across two different executions");
 
   sp.setContentContext();
 
   is(sp.executionContext, gScratchpadWindow.SCRATCHPAD_CONTEXT_CONTENT,
      "executionContext is content");
 
-  is(sp.execute()[1], "undefined",
+  is(sp.run()[1], "undefined",
      "global variable no longer exists after changing the context");
 
   gScratchpadWindow.close();
   gScratchpadWindow = null;
   gBrowser.removeCurrentTab();
   finish();
 }
--- a/browser/base/content/test/browser_scratchpad_execute_print.js
+++ b/browser/base/content/test/browser_scratchpad_execute_print.js
@@ -12,42 +12,42 @@ function test()
   gBrowser.selectedTab = gBrowser.addTab();
   gBrowser.selectedBrowser.addEventListener("load", function() {
     gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
 
     gScratchpadWindow = Scratchpad.openScratchpad();
     gScratchpadWindow.addEventListener("load", runTests, false);
   }, true);
 
-  content.location = "data:text/html,<p>test execute() and print() in Scratchpad";
+  content.location = "data:text/html,<p>test run() and display() in Scratchpad";
 }
 
 function runTests()
 {
   gScratchpadWindow.removeEventListener("load", arguments.callee, false);
 
   let sp = gScratchpadWindow.Scratchpad;
 
   content.wrappedJSObject.foobarBug636725 = 1;
 
   ok(sp.textbox, "textbox exists");
   sp.textbox.value = "++window.foobarBug636725";
 
-  let exec = sp.execute();
+  let exec = sp.run();
   is(exec[0], sp.textbox.value, "execute()[0] is correct");
   is(exec[1], content.wrappedJSObject.foobarBug636725,
      "execute()[1] is correct");
 
   is(sp.textbox.value, "++window.foobarBug636725",
      "execute() does not change the textbox value");
 
   is(content.wrappedJSObject.foobarBug636725, 2,
      "execute() updated window.foobarBug636725");
 
-  sp.print();
+  sp.display();
 
   is(content.wrappedJSObject.foobarBug636725, 3,
      "print() updated window.foobarBug636725");
 
   is(sp.textbox.value, "++window.foobarBug636725/*\n3\n*/",
      "print() shows evaluation result in the textbox");
 
   is(sp.selectedText, "/*\n3\n*/", "selectedText is correct");
@@ -64,17 +64,17 @@ function runTests()
   is(sp.textbox.selectionStart, 1, "selectionStart is 1");
   is(sp.textbox.selectionEnd, 2, "selectionEnd is 2");
 
   sp.selectRange(0, 29);
 
   is(sp.textbox.selectionStart, 0, "selectionStart is 0");
   is(sp.textbox.selectionEnd, 29, "selectionEnd is 29");
 
-  exec = sp.execute();
+  exec = sp.run();
 
   is(exec[0], "window.foobarBug636725 = 'a';",
      "execute()[0] is correct");
   is(exec[1], "a",
      "execute()[1] is correct");
 
   is(sp.textbox.value, "window.foobarBug636725 = 'a';\n" +
                        "window.foobarBug636725 = 'b';",
@@ -83,17 +83,17 @@ function runTests()
   is(content.wrappedJSObject.foobarBug636725, "a",
      "execute() worked for the selected range");
 
   sp.textbox.value = "window.foobarBug636725 = 'c';\n" +
                      "window.foobarBug636725 = 'b';";
 
   sp.selectRange(0, 22);
 
-  sp.print();
+  sp.display();
 
   is(content.wrappedJSObject.foobarBug636725, "a",
      "print() worked for the selected range");
 
   is(sp.textbox.value, "window.foobarBug636725" +
                        "/*\na\n*/" +
                        " = 'c';\n" +
                        "window.foobarBug636725 = 'b';",
--- a/browser/base/content/test/browser_scratchpad_initialization.js
+++ b/browser/base/content/test/browser_scratchpad_initialization.js
@@ -23,19 +23,19 @@ function test()
 }
 
 function runTests()
 {
   gScratchpadWindow.removeEventListener("load", arguments.callee, false);
 
   let sp = gScratchpadWindow.Scratchpad;
   ok(sp, "Scratchpad object exists in new window");
-  is(typeof sp.execute, "function", "Scratchpad.execute() exists");
+  is(typeof sp.run, "function", "Scratchpad.run() exists");
   is(typeof sp.inspect, "function", "Scratchpad.inspect() exists");
-  is(typeof sp.print, "function", "Scratchpad.print() exists");
+  is(typeof sp.display, "function", "Scratchpad.display() exists");
 
   let chromeContextMenu = gScratchpadWindow.document.
                           getElementById("sp-menu-browser");
   ok(chromeContextMenu, "Chrome context menuitem element exists");
   is(chromeContextMenu.getAttribute("hidden"), "true",
      "Chrome context menuitem is hidden");
 
   let errorConsoleCommand = gScratchpadWindow.document.
--- a/browser/base/content/test/browser_scratchpad_ui.js
+++ b/browser/base/content/test/browser_scratchpad_ui.js
@@ -28,18 +28,19 @@ function runTests()
   let sp = gScratchpadWindow.Scratchpad;
   let doc = gScratchpadWindow.document;
 
   let methodsAndItems = {
     "sp-menu-newscratchpad": "openScratchpad",
     "sp-menu-open": "openFile",
     "sp-menu-save": "saveFile",
     "sp-menu-saveas": "saveFileAs",
-    "sp-text-execute": "execute",
+    "sp-text-run": "run",
     "sp-text-inspect": "inspect",
+    "sp-text-display": "display",
     "sp-menu-content": "setContentContext",
     "sp-menu-browser": "setBrowserContext",
     "sp-menu-resetContext": "resetContext",
     "sp-menu-errorConsole": "openErrorConsole",
     "sp-menu-webConsole": "openWebConsole",
   };
 
   let lastMethodCalled = null;
--- a/browser/locales/en-US/chrome/browser/scratchpad.dtd
+++ b/browser/locales/en-US/chrome/browser/scratchpad.dtd
@@ -56,27 +56,27 @@
 <!ENTITY pasteCmd.label               "Paste">
 <!ENTITY pasteCmd.key                 "V">
 <!ENTITY pasteCmd.accesskey           "P">
 
 <!ENTITY selectAllCmd.label           "Select All">
 <!ENTITY selectAllCmd.key             "A">
 <!ENTITY selectAllCmd.accesskey       "A">
 
-<!ENTITY execute.label                "Execute">
-<!ENTITY execute.accesskey            "E">
-<!ENTITY execute.key                  "t">
+<!ENTITY run.label                    "Run">
+<!ENTITY run.accesskey                "R">
+<!ENTITY run.key                      "r">
 
 <!ENTITY inspect.label                "Inspect">
 <!ENTITY inspect.accesskey            "I">
 <!ENTITY inspect.key                  "i">
 
-<!ENTITY print.label                  "Print">
-<!ENTITY print.accesskey              "p">
-<!ENTITY print.key                    "r">
+<!ENTITY display.label                "Display">
+<!ENTITY display.accesskey            "D">
+<!ENTITY display.key                  "l">
 
 <!-- LOCALIZATION NOTE (environmentMenu.label, accesskey): This menu item was
   -  renamed from "Context" to avoid confusion with the right-click context
   -  menu in the text area. It refers to the JavaScript Environment (or context)
   -  the user is evaluating against. I.e., Content (current tab) or Chrome
   -  (browser).
   -->
 <!ENTITY environmentMenu.label        "Environment">
@@ -105,16 +105,19 @@
   -->
 
 <!-- LOCALIZATION NOTE (resetContext.label): This command allows the developer
   -  to reset/clear the global object of the environment where the code executes.
   -->
 <!ENTITY resetContext.label           "Reset">
 <!ENTITY resetContext.accesskey       "R">
 
+<!ENTITY executeMenu.label            "Execute">
+<!ENTITY executeMenu.accesskey        "X">
+
 <!ENTITY toolsMenu.label              "Tools">
 <!ENTITY toolsMenu.accesskey          "T">
 
 <!ENTITY errorConsoleCmd.label        "Error Console">
 <!ENTITY errorConsoleCmd.accesskey    "C">
 <!ENTITY errorConsoleCmd.commandkey   "j">
 
 <!ENTITY webConsoleCmd.label          "Web Console">