Bug 1064282 - Scratchpad should have statusbar like Page Source viewer. r=fitzgen
authorAdrian Aichner <adrian.aichner@gmail.com>
Mon, 15 Sep 2014 17:18:16 -0700
changeset 228652 797f355e77fb516a9df34fb7d0ac71b9fac22a03
parent 228651 ab5a6bea66bfb52ac5692c2e502c74a2fe2bf66b
child 228653 dda7d018294e2381c246862f4f032156ee3539dd
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfitzgen
bugs1064282
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1064282 - Scratchpad should have statusbar like Page Source viewer. r=fitzgen --- browser/devtools/scratchpad/scratchpad.js | 12 ++++++++++++ browser/devtools/scratchpad/scratchpad.xul | 1 + .../test/browser_scratchpad_run_error_goto_line.js | 11 +++++++++++ .../chrome/browser/devtools/scratchpad.properties | 5 +++++ 4 files changed, 29 insertions(+), 0 deletions(-)
browser/devtools/scratchpad/scratchpad.js
browser/devtools/scratchpad/scratchpad.xul
browser/devtools/scratchpad/test/browser_scratchpad_run_error_goto_line.js
browser/locales/en-US/chrome/browser/devtools/scratchpad.properties
--- a/browser/devtools/scratchpad/scratchpad.js
+++ b/browser/devtools/scratchpad/scratchpad.js
@@ -1547,16 +1547,24 @@ var Scratchpad = {
    *         the inner window ID
    */
   getInnerWindowId: function SP_getInnerWindowId(aWindow)
   {
     return aWindow.QueryInterface(Ci.nsIInterfaceRequestor).
            getInterface(Ci.nsIDOMWindowUtils).currentInnerWindowID;
   },
 
+  updateStatusBar: function SP_updateStatusBar(aEventType)
+  {
+    var statusBarField = document.getElementById("statusbar-line-col");
+    let { line, ch } = this.editor.getCursor();
+    statusBarField.textContent = this.strings.formatStringFromName(
+      "scratchpad.statusBarLineCol", [ line + 1, ch + 1], 2);
+  },
+
   /**
    * The Scratchpad window load event handler. This method
    * initializes the Scratchpad window and source editor.
    *
    * @param nsIDOMEvent aEvent
    */
   onLoad: function SP_onLoad(aEvent)
   {
@@ -1608,16 +1616,19 @@ var Scratchpad = {
     };
 
     this.editor = new Editor(config);
     let editorElement = document.querySelector("#scratchpad-editor");
     this.editor.appendTo(editorElement).then(() => {
       var lines = initialText.split("\n");
 
       this.editor.on("change", this._onChanged);
+      // Keep a reference to the bound version for use in onUnload.
+      this.updateStatusBar = Scratchpad.updateStatusBar.bind(this);
+      this.editor.on("cursorActivity", this.updateStatusBar);
       let okstring = this.strings.GetStringFromName("selfxss.okstring");
       let msg = this.strings.formatStringFromName("selfxss.msg", [okstring], 1);
       this._onPaste = WebConsoleUtils.pasteHandlerGen(this.editor.container.contentDocument.body,
                                                       document.querySelector('#scratchpad-notificationbox'),
                                                       msg, okstring);
       editorElement.addEventListener("paste", this._onPaste);
       editorElement.addEventListener("drop", this._onPaste);
       this.editor.on("save", () => this.saveFile());
@@ -1693,16 +1704,17 @@ var Scratchpad = {
     CloseObserver.uninit();
     if (this._onPaste) {
       let editorElement = document.querySelector("#scratchpad-editor");
       editorElement.removeEventListener("paste", this._onPaste);
       editorElement.removeEventListener("drop", this._onPaste);
       this._onPaste = null;
     }
     this.editor.off("change", this._onChanged);
+    this.editor.off("cursorActivity", this.updateStatusBar);
     this.editor.destroy();
     this.editor = null;
 
     if (this._sidebar) {
       this._sidebar.destroy();
       this._sidebar = null;
     }
 
--- a/browser/devtools/scratchpad/scratchpad.xul
+++ b/browser/devtools/scratchpad/scratchpad.xul
@@ -398,11 +398,12 @@
     <splitter class="devtools-side-splitter"/>
     <tabbox id="scratchpad-sidebar" class="devtools-sidebar-tabs"
                                     width="300"
                                     hidden="true">
       <tabs/>
       <tabpanels flex="1"/>
     </tabbox>
   </hbox>
+  <toolbar id="statusbar-line-col" class="chromeclass-toolbar"/>
 </notificationbox>
 
 </window>
--- a/browser/devtools/scratchpad/test/browser_scratchpad_run_error_goto_line.js
+++ b/browser/devtools/scratchpad/test/browser_scratchpad_run_error_goto_line.js
@@ -39,11 +39,22 @@ function runTests(sw)
     let inputLine = lineInput.value;
     is(inputLine, errorLine, "jumpToLine input field is set from editor selection");
     EventUtils.synthesizeKey("VK_RETURN", { }, editorDoc.defaultView);
     // CodeMirror lines and columns are 0-based, Scratchpad UI and error
     // stack are 1-based.
     let cursor = sp.editor.getCursor();
     is(cursor.line + 1, inputLine, "jumpToLine goto error location (line)");
     is(cursor.ch + 1, 1, "jumpToLine goto error location (column)");
+  }, error => {
+    ok(false, error);
+    finish();
+  }).then(() => {
+    var statusBarField = sp.editor.container.ownerDocument.querySelector("#statusbar-line-col");
+    let { line, ch } = sp.editor.getCursor();
+    is(statusBarField.textContent, sp.strings.formatStringFromName(
+      "scratchpad.statusBarLineCol", [ line + 1, ch + 1], 2), "statusbar text is correct (" + statusBarField.textContent + ")");
+    finish();
+  }, error => {
+    ok(false, error);
     finish();
   });
 }
--- a/browser/locales/en-US/chrome/browser/devtools/scratchpad.properties
+++ b/browser/locales/en-US/chrome/browser/devtools/scratchpad.properties
@@ -73,16 +73,21 @@ scratchpad.noargs=Scratchpad was created
 # 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
 
+# LOCALIZATION NOTE (scratchpad.statusBarLineCol): Line, Column
+# information displayed in statusbar when selection is made in
+# Scratchpad.
+scratchpad.statusBarLineCol  = Line %1$S, Col %2$S
+
 # LOCALIZATION NOTE (fileExists.notification): This is the message displayed
 # over the top of the the editor when a file does not exist.
 fileNoLongerExists.notification=This file no longer exists.
 
 # LOCALIZATION NOTE (propertiesFilterPlaceholder): this is the text that
 # appears in the filter text box for the properties view container.
 propertiesFilterPlaceholder=Filter properties