Bug 771481 - 'No scripts.' should be displayed in the dropdown when there are no scripts matching the search string; r=past
authorVictor Porof <vporof@mozilla.com>
Wed, 18 Jul 2012 16:13:15 +0300
changeset 102874 c55c28ca8d048a008147025977133d1997530fd6
parent 102631 d56993c345f4ac09355ed7e60e15951258f877f7
child 102875 48a7ba394c0ac315503acc5500cda96492ad7619
push idunknown
push userunknown
push dateunknown
reviewerspast
bugs771481
milestone17.0a1
Bug 771481 - 'No scripts.' should be displayed in the dropdown when there are no scripts matching the search string; r=past
browser/devtools/debugger/debugger-view.js
browser/devtools/debugger/debugger.xul
browser/devtools/debugger/test/browser_dbg_location-changes-blank.js
browser/devtools/debugger/test/browser_dbg_scripts-searching-02.js
browser/locales/en-US/chrome/browser/devtools/debugger.dtd
browser/locales/en-US/chrome/browser/devtools/debugger.properties
browser/themes/gnomestripe/devtools/debugger.css
browser/themes/pinstripe/devtools/debugger.css
browser/themes/winstripe/devtools/debugger.css
--- a/browser/devtools/debugger/debugger-view.js
+++ b/browser/devtools/debugger/debugger-view.js
@@ -144,16 +144,18 @@ function ScriptsView() {
 
 ScriptsView.prototype = {
 
   /**
    * Removes all elements from the scripts container, leaving it empty.
    */
   empty: function DVS_empty() {
     this._scripts.selectedIndex = -1;
+    this._scripts.setAttribute("label", L10N.getStr("noScriptsText"));
+    this._scripts.removeAttribute("tooltiptext");
 
     while (this._scripts.firstChild) {
       this._scripts.removeChild(this._scripts.firstChild);
     }
   },
 
   /**
    * Removes the input in the searchbox and unhides all the scripts.
@@ -420,56 +422,70 @@ ScriptsView.prototype = {
    * The click listener for the scripts container.
    */
   _onScriptsChange: function DVS__onScriptsChange() {
     let selectedItem = this._scripts.selectedItem;
     if (!selectedItem) {
       return;
     }
 
-    let script = selectedItem.getUserData("sourceScript");
-    this._preferredScript = script;
-    DebuggerController.SourceScripts.showScript(script);
+    this._preferredScript = selectedItem;
+    DebuggerController.SourceScripts.showScript(selectedItem.getUserData("sourceScript"));
   },
 
   /**
    * The search listener for the scripts search box.
    */
   _onScriptsSearch: function DVS__onScriptsSearch(e) {
     let editor = DebuggerView.editor;
     let scripts = this._scripts;
     let [file, line, token] = this._getSearchboxInfo();
 
+    // If the webpage has no scripts, searching is redundant.
+    if (!scripts.itemCount) {
+      return;
+    }
+
     // Presume we won't find anything.
     scripts.selectedItem = this._preferredScript;
+    scripts.setAttribute("label", this._preferredScript.label);
+    scripts.setAttribute("tooltiptext", this._preferredScript.value);
 
     // If we're not searching for a file anymore, unhide all the scripts.
     if (!file) {
       for (let i = 0, l = scripts.itemCount; i < l; i++) {
         scripts.getItemAtIndex(i).hidden = false;
       }
     } else {
-      for (let i = 0, l = scripts.itemCount, found = false; i < l; i++) {
+      let found = false;
+
+      for (let i = 0, l = scripts.itemCount; i < l; i++) {
         let item = scripts.getItemAtIndex(i);
         let target = item.label.toLowerCase();
 
         // Search is not case sensitive, and is tied to the label not the url.
         if (target.match(file)) {
           item.hidden = false;
 
           if (!found) {
             found = true;
             scripts.selectedItem = item;
+            scripts.setAttribute("label", item.label);
+            scripts.setAttribute("tooltiptext", item.value);
           }
         }
         // Hide what doesn't match our search.
         else {
           item.hidden = true;
         }
       }
+      if (!found) {
+        scripts.setAttribute("label", L10N.getStr("noMatchingScriptsText"));
+        scripts.removeAttribute("tooltiptext");
+      }
     }
     if (line > -1) {
       editor.setCaretPosition(line - 1);
     }
     if (token.length) {
       let offset = editor.find(token, { ignoreCase: true });
       if (offset > -1) {
         editor.setSelection(offset, offset + token.length)
--- a/browser/devtools/debugger/debugger.xul
+++ b/browser/devtools/debugger/debugger.xul
@@ -59,16 +59,17 @@
                        tooltiptext="&debuggerUI.stepInButton.tooltip;"
                        tabindex="0"/>
         <toolbarbutton id="step-out"
                        class="devtools-toolbarbutton"
                        tooltiptext="&debuggerUI.stepOutButton.tooltip;"
                        tabindex="0"/>
       </hbox>
       <menulist id="scripts" class="devtools-menulist"
+                sizetopopup="always"
                 label="&debuggerUI.emptyScriptText;"/>
       <textbox id="scripts-search" type="search"
                class="devtools-searchinput"
                emptytext="&debuggerUI.emptyFilterText;"/>
       <checkbox id="pause-exceptions"
                 type="checkbox"
                 tabindex="0"
                 label="&debuggerUI.pauseExceptions;"/>
--- a/browser/devtools/debugger/test/browser_dbg_location-changes-blank.js
+++ b/browser/devtools/debugger/test/browser_dbg_location-changes-blank.js
@@ -62,16 +62,23 @@ function testLocationChange()
 
         // Wait for the initial resume...
         gDebugger.gClient.addOneTimeListener("resumed", function() {
           is(gDebugger.DebuggerView.Scripts.selected, null,
             "There should be no selected script.");
           is(gDebugger.editor.getText().length, 0,
             "The source editor not have any text displayed.");
 
+          let menulist = gDebugger.DebuggerView.Scripts._scripts;
+          let noScripts = gDebugger.L10N.getStr("noScriptsText");
+          is(menulist.getAttribute("label"), noScripts,
+            "The menulist should display a notice that there are no scripts availalble.");
+          is(menulist.getAttribute("tooltiptext"), "",
+            "The menulist shouldn't have any tooltip text attributed when there are no scripts available.");
+
           closeDebuggerAndFinish();
         });
       });
     });
     content.location = "about:blank";
   });
 }
 
--- a/browser/devtools/debugger/test/browser_dbg_scripts-searching-02.js
+++ b/browser/devtools/debugger/test/browser_dbg_scripts-searching-02.js
@@ -119,20 +119,51 @@ function finalCheck(i, string, token) {
 
   if (string[i]) {
     EventUtils.sendChar(string[i]);
     finalCheck(i + 1, string, token);
     return;
   }
 
   clear();
+  ok(gEditor.getCaretPosition().line == 5 &&
+     gEditor.getCaretPosition().col == 8 + token.length + i,
+    "The editor didn't remain at the correct token. (4)");
 
   executeSoon(function() {
+    let noMatchingScripts = gDebugger.L10N.getStr("noMatchingScriptsText");
+
     is(gScripts.visibleItemsCount, 2,
       "Not all the scripts are shown after the searchbox was emptied.");
+    is(gMenulist.selectedIndex, 1,
+      "The menulist should have retained its selected index after the searchbox was emptied.");
+
+    write("BOGUS");
+    ok(gEditor.getCaretPosition().line == 5 &&
+       gEditor.getCaretPosition().col == 8 + token.length + i,
+      "The editor didn't remain at the correct token. (5)");
+
+    is(gMenulist.getAttribute("label"), noMatchingScripts,
+      "The menulist should display a notice that no scripts match the searched token.");
+    is(gScripts.visibleItemsCount, 0,
+      "No scripts should be displayed in the menulist after a bogus search.");
+    is(gMenulist.selectedIndex, 1,
+      "The menulist should retain its selected index after a bogus search.");
+
+    clear();
+    ok(gEditor.getCaretPosition().line == 5 &&
+       gEditor.getCaretPosition().col == 8 + token.length + i,
+      "The editor didn't remain at the correct token. (6)");
+
+    isnot(gMenulist.getAttribute("label"), noMatchingScripts,
+      "The menulist should not display a notice after the searchbox was emptied.");
+    is(gScripts.visibleItemsCount, 2,
+      "Not all the scripts are shown after the searchbox was emptied.");
+    is(gMenulist.selectedIndex, 1,
+      "The menulist should have retained its selected index after the searchbox was emptied of a bogus search.");
 
     closeDebuggerAndFinish();
   });
 }
 
 function clear() {
   gSearchBox.focus();
   gSearchBox.value = "";
--- a/browser/locales/en-US/chrome/browser/devtools/debugger.dtd
+++ b/browser/locales/en-US/chrome/browser/devtools/debugger.dtd
@@ -62,9 +62,9 @@
 <!ENTITY debuggerUI.propertiesTitle  "Scope variables">
 
 <!-- LOCALIZATION NOTE (debuggerUI.emptyFilterText): This is the text that
   -  appears in the filter text box when it is empty. -->
 <!ENTITY debuggerUI.emptyFilterText  "Filter scripts">
 
 <!-- LOCALIZATION NOTE (emptyScriptText): The text to display in the menulist when
   - there are no scripts. -->
-<!ENTITY debuggerUI.emptyScriptText  "No scripts.">
+<!ENTITY debuggerUI.emptyScriptText  "No scripts">
--- a/browser/locales/en-US/chrome/browser/devtools/debugger.properties
+++ b/browser/locales/en-US/chrome/browser/devtools/debugger.properties
@@ -54,16 +54,24 @@ resumeTooltip=Click to resume
 # LOCALIZATION NOTE (emptyStackText): The text that is displayed in the stack
 # frames list when there are no frames to display.
 emptyStackText=No stacks to display.
 
 # LOCALIZATION NOTE (emptyBreakpointsText): The text that is displayed in the
 # breakpoints list when there are no breakpoints to display.
 emptyBreakpointsText=No breakpoints to display.
 
+# LOCALIZATION NOTE (noScriptsText): The text to display in the menulist when
+# there are no scripts.
+noScriptsText=No scripts
+
+# LOCALIZATION NOTE (noMatchingScriptsText): The text to display in the
+# menulist when there are no matching scripts after filtering.
+noMatchingScriptsText=No matching scripts
+
 # LOCALIZATION NOTE (breakpointMenuItem): The text for all the elements that
 # are displayed in the breakpoints menu item popup.
 breakpointMenuItem.enableSelf=Enable breakpoint
 breakpointMenuItem.disableSelf=Disable breakpoint
 breakpointMenuItem.deleteSelf=Remove breakpoint
 breakpointMenuItem.enableOthers=Enable others
 breakpointMenuItem.disableOthers=Disable others
 breakpointMenuItem.deleteOthers=Remove others
--- a/browser/themes/gnomestripe/devtools/debugger.css
+++ b/browser/themes/gnomestripe/devtools/debugger.css
@@ -13,16 +13,17 @@
  */
 
 #dbg-content {
   padding: 0;
 }
 
 #scripts {
   max-width: 350px;
+  min-width: 150px;
 }
 
 /**
  * Lists and headers
  */
 
 .list-item {
   padding: 2px;
--- a/browser/themes/pinstripe/devtools/debugger.css
+++ b/browser/themes/pinstripe/devtools/debugger.css
@@ -15,16 +15,17 @@
  */
 
 #dbg-content {
   padding: 0;
 }
 
 #scripts {
   max-width: 350px;
+  min-width: 150px;
 }
 
 /**
  * Lists and headers
  */
 
 .list-item {
   padding: 2px;
--- a/browser/themes/winstripe/devtools/debugger.css
+++ b/browser/themes/winstripe/devtools/debugger.css
@@ -13,16 +13,17 @@
  */
 
 #dbg-content {
   padding: 0;
 }
 
 #scripts {
   max-width: 350px;
+  min-width: 150px;
 }
 
 /**
  * This hardcoded width likely due to a toolkit Windows specific bug.
  * See http://hg.mozilla.org/mozilla-central/annotate/f38d6df93cad/toolkit/themes/winstripe/global/textbox-aero.css#l7
  */
 #scripts-search {
   width: 200px;