Bug 650760 - Create Help menu for Scratchpad; r=rcampbell
authorJohan Charlez <johan.charlez@gmail.com>
Tue, 21 Feb 2012 07:09:29 -0400
changeset 90292 3d77924fb9701af70a6f84894b311532e52b6cd8
parent 90291 94ab58a742a9093117c6739715ea6cbfd64d1d53
child 90293 f6a20bf8511879ad6b68232bd3a76de668e79208
push idunknown
push userunknown
push dateunknown
reviewersrcampbell
bugs650760
milestone13.0a1
Bug 650760 - Create Help menu for Scratchpad; r=rcampbell
browser/devtools/scratchpad/scratchpad.js
browser/devtools/scratchpad/scratchpad.xul
browser/devtools/scratchpad/test/Makefile.in
browser/devtools/scratchpad/test/browser_scratchpad_bug_650760_help_key.js
browser/locales/en-US/chrome/browser/devtools/scratchpad.dtd
browser/locales/en-US/chrome/browser/devtools/scratchpad.properties
--- a/browser/devtools/scratchpad/scratchpad.js
+++ b/browser/devtools/scratchpad/scratchpad.js
@@ -1063,17 +1063,25 @@ var Scratchpad = {
     // trigger all observers that implement this named handler
     for (let i = 0; i < this._observers.length; ++i) {
       let observer = this._observers[i];
       let handler = observer["on" + aName];
       if (handler) {
         handler.apply(observer, aArgs);
       }
     }
-  }
+  },
+
+  openDocumentationPage: function SP_openDocumentationPage()
+  {
+    let url = this.strings.GetStringFromName("help.openDocumentationPage");
+    let newTab = this.gBrowser.addTab(url);
+    this.browserWindow.focus();
+    this.gBrowser.selectedTab = newTab;
+  },
 };
 
 XPCOMUtils.defineLazyGetter(Scratchpad, "strings", function () {
   return Services.strings.createBundle(SCRATCHPAD_L10N);
 });
 
 addEventListener("load", Scratchpad.onLoad.bind(Scratchpad), false);
 addEventListener("unload", Scratchpad.onUnload.bind(Scratchpad), false);
--- a/browser/devtools/scratchpad/scratchpad.xul
+++ b/browser/devtools/scratchpad/scratchpad.xul
@@ -78,16 +78,17 @@
   <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();"/>
   <command id="sp-cmd-undo" oncommand="Scratchpad.undo();" disabled="true"/>
   <command id="sp-cmd-redo" oncommand="Scratchpad.redo();" disabled="true"/>
+  <command id="sp-cmd-documentationLink" oncommand="Scratchpad.openDocumentationPage();"/>
 </commandset>
 
 <keyset id="sp-keyset">
   <key id="sp-key-window"
        key="&newWindowCmd.commandkey;"
        command="sp-cmd-newWindow"
        modifiers="accel"/>
   <key id="sp-key-open"
@@ -166,16 +167,19 @@
        keycode="VK_F3"
        command="cmd_findPrevious"
        modifiers="shift"/>
 #endif
   <key id="key_gotoLine"
        key="&gotoLineCmd.key;"
        command="cmd_gotoLine"
        modifiers="accel"/>
+  <key id="key_openHelp"
+       keycode="VK_F1"
+       command="sp-cmd-documentationLink"/>
 </keyset>
 
 
 <menubar id="sp-menubar">
   <menu id="sp-file-menu" label="&fileMenu.label;"
         accesskey="&fileMenu.accesskey;">
     <menupopup id="sp-menu-filepopup">
       <menuitem id="sp-menu-newscratchpad"
@@ -311,16 +315,34 @@
                 type="radio"/>
       <menuitem id="sp-menu-browser"
                 command="sp-cmd-browserContext"
                 label="&browserContext.label;"
                 accesskey="&browserContext.accesskey;"
                 type="radio"/>
     </menupopup>
   </menu>
+
+#ifdef XP_WIN
+  <menu id="sp-help-menu"
+        label="&helpMenu.label;"
+        accesskey="&helpMenuWin.accesskey;">
+#else
+  <menu id="sp-help-menu"
+        label="&helpMenu.label;"
+        accesskey="&helpMenu.accesskey;">
+#endif
+    <menupopup id="sp-menu-help">
+      <menuitem id="sp-menu-documentation"
+                label="&documentationLink.label;"
+                accesskey="&documentationLink.accesskey;"
+                command="sp-cmd-documentationLink"
+                key="key_openHelp"/>
+    </menupopup>
+  </menu>
 </menubar>
 
 <popupset id="scratchpad-popups">
   <menupopup id="scratchpad-text-popup"
              onpopupshowing="goUpdateGlobalEditMenuItems()">
     <menuitem id="menu_cut"/>
     <menuitem id="menu_copy"/>
     <menuitem id="menu_paste"/>
--- a/browser/devtools/scratchpad/test/Makefile.in
+++ b/browser/devtools/scratchpad/test/Makefile.in
@@ -58,12 +58,13 @@ include $(topsrcdir)/config/rules.mk
 		browser_scratchpad_bug_679467_falsy.js \
 		browser_scratchpad_bug_699130_edit_ui_updates.js \
 		browser_scratchpad_bug_669612_unsaved.js \
 		browser_scratchpad_bug_653427_confirm_close.js \
 		browser_scratchpad_bug684546_reset_undo.js \
 		browser_scratchpad_bug690552_display_outputs_errors.js \
 		browser_scratchpad_bug650345_find_ui.js \
 		browser_scratchpad_bug714942_goto_line_ui.js \
+		browser_scratchpad_bug_650760_help_key.js \
 		head.js \
 
 libs:: $(_BROWSER_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/browser/devtools/scratchpad/test/browser_scratchpad_bug_650760_help_key.js
@@ -0,0 +1,60 @@
+/* vim: set ts=2 et sw=2 tw=80: */
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function test()
+{
+  waitForExplicitFinish();
+
+  gBrowser.selectedTab = gBrowser.addTab();
+  content.location = "data:text/html,Test keybindings for opening Scratchpad MDN Documentation, bug 650760";
+  gBrowser.selectedBrowser.addEventListener("load", function onTabLoad() {
+    gBrowser.selectedBrowser.removeEventListener("load", onTabLoad, true);
+
+    ok(window.Scratchpad, "Scratchpad variable exists");
+
+    openScratchpad(runTest);
+  }, true);
+}
+
+function runTest()
+{
+  let sp = gScratchpadWindow.Scratchpad;
+  ok(sp, "Scratchpad object exists in new window");
+  ok(sp.editor.hasFocus(), "the editor has focus");
+
+  let keyid = gScratchpadWindow.document.getElementById("key_openHelp");
+  let modifiers = keyid.getAttribute("modifiers");
+
+  let key = null;
+  if (keyid.getAttribute("keycode"))
+    key = keyid.getAttribute("keycode");
+
+  else if (keyid.getAttribute("key"))
+    key = keyid.getAttribute("key");
+
+  isnot(key, null, "Successfully retrieved keycode/key");
+
+  var aEvent = {
+    shiftKey: modifiers.match("shift"),
+    ctrlKey: modifiers.match("ctrl"),
+    altKey: modifiers.match("alt"),
+    metaKey: modifiers.match("meta"),
+    accelKey: modifiers.match("accel")
+  }
+
+  info("check that the MDN page is opened on \"F1\"");
+  let linkClicked = false;
+  sp.openDocumentationPage = function(event) { linkClicked = true; };
+
+  EventUtils.synthesizeKey(key, aEvent, gScratchpadWindow);
+
+  is(linkClicked, true, "MDN page will open");
+  finishTest();
+}
+
+function finishTest()
+{
+  gScratchpadWindow.close();
+  finish();
+}
--- a/browser/locales/en-US/chrome/browser/devtools/scratchpad.dtd
+++ b/browser/locales/en-US/chrome/browser/devtools/scratchpad.dtd
@@ -116,16 +116,28 @@
   -  to select an execution environment for the browser window itself as opposed
   -  to content. This is a feature for browser and addon developers and only
   -  enabled via the devtools.chrome.enabled preference. Formerly, this label
   -  was called "Chrome".
   -->
 <!ENTITY browserContext.label         "Browser">
 <!ENTITY browserContext.accesskey     "B">
 
+<!-- LOCALIZATION NOTE some localizations of Windows (ex:french, german) use "?"
+  -  for the help button in the menubar but Gnome does not.
+  -->
+<!ENTITY helpMenu.label               "Help">
+<!ENTITY helpMenu.accesskey           "H">
+<!ENTITY helpMenuWin.label            "Help">
+<!ENTITY helpMenuWin.accesskey        "H">
+
+<!ENTITY documentationLink.label      "Scratchpad Help on MDN">
+<!ENTITY documentationLink.accesskey  "D">
+
+
 <!-- LOCALIZATION NOTE (resetContext2.label): This command allows the developer
   -  to reset/clear the global object of the environment where the code executes.
   -->
 <!ENTITY resetContext2.label          "Reset Variables">
 <!ENTITY resetContext2.accesskey      "T">
 
 <!ENTITY executeMenu.label            "Execute">
 <!ENTITY executeMenu.accesskey        "X">
--- a/browser/locales/en-US/chrome/browser/devtools/scratchpad.properties
+++ b/browser/locales/en-US/chrome/browser/devtools/scratchpad.properties
@@ -49,8 +49,12 @@ confirmClose.title=Unsaved Changes
 # LOCALIZATION NOTE  (scratchpadIntro): This is a multi-line comment explaining
 # how to use the Scratchpad. Note that this should be a valid JavaScript
 # comment inside /* and */.
 scratchpadIntro=/*\n * This is a JavaScript Scratchpad.\n *\n * Enter some JavaScript, then Right Click or choose from the Execute Menu:\n * 1. Run to evaluate the selected text,\n * 2. Inspect to bring up an Object Inspector on the result, or,\n * 3. Display to insert the result in a comment after the selection.\n */\n\n
 
 # LOCALIZATION NOTE  (notification.browserContext): This is the message displayed
 # over the top of the editor when the user has switched to browser context.
 browserContext.notification=This scratchpad executes in the Browser context.
+
+# LOCALIZATION NOTE (help.openDocumentationPage): This returns a localized link with
+# documentation for Scratchpad on MDN.
+help.openDocumentationPage=https://developer.mozilla.org/en/Tools/Scratchpad