Bug 595246 - Add possibility to manage available search engines from preferences and sidebar, r=Neil
authorRobert Kaiser <kairo@kairo.at>
Tue, 03 May 2011 14:24:16 +0200
changeset 7677 5a3480d2f3a1d82200322a88337a586a4d5daf71
parent 7676 bdd02cca51f547456eaafb000bfbd70859936f81
child 7678 34703bb121c7c035c2f2c61c042947402ada210a
push id5892
push userkairo@kairo.at
push dateTue, 03 May 2011 12:24:30 +0000
treeherdercomm-central@5a3480d2f3a1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersNeil
bugs595246
Bug 595246 - Add possibility to manage available search engines from preferences and sidebar, r=Neil
suite/common/pref/pref-search.js
suite/common/pref/pref-search.xul
suite/common/search/engineManager.js
suite/common/search/search-panel.js
suite/common/search/search-panel.xul
suite/locales/en-US/chrome/common/pref/pref-search.dtd
suite/locales/en-US/chrome/common/search/search-panel.dtd
--- a/suite/common/pref/pref-search.js
+++ b/suite/common/pref/pref-search.js
@@ -49,8 +49,17 @@ function Startup() {
     menuitem.setAttribute("class", "menuitem-iconic");
     if (engines[i].iconURI)
       menuitem.setAttribute("image", engines[i].iconURI.spec);
     menulist.menupopup.appendChild(menuitem);
     menuitem.engine = engines[i];
   }
   menulist.value = Services.search.defaultEngine.name;
 }
+
+function OpenManager() {
+  var window = Services.wm.getMostRecentWindow("Browser:SearchManager");
+  if (window)
+    window.focus();
+  else
+    openDialog("chrome://communicator/content/search/engineManager.xul",
+               "_blank", "chrome,dialog,modal,centerscreen,resizable");
+}
--- a/suite/common/pref/pref-search.xul
+++ b/suite/common/pref/pref-search.xul
@@ -66,16 +66,21 @@
 
       <hbox align="center">
         <label value="&defaultSearchEngine.label;"
                accesskey="&defaultSearchEngine.accesskey;"
                control="engineList"/>
         <menulist id="engineList"
                   preference="browser.search.defaultenginename"/>
       </hbox>
+      <hbox pack="end">
+        <button id="managerButton"
+                label="&engineManager.label;"
+                oncommand="OpenManager();"/>
+      </hbox>
     </groupbox>
 
     <groupbox>
       <caption label="&searchResults.label;"/>
       <checkbox id="openSearchTab"
                 label="&openInTab.label;"
                 accesskey="&openInTab.accesskey;"
                 preference="browser.search.openintab"/>
--- a/suite/common/search/engineManager.js
+++ b/suite/common/search/engineManager.js
@@ -103,18 +103,25 @@ var gEngineManagerDialog = {
   },
 
   showRestoreDefaults: function engineManager_showRestoreDefaults(val) {
     document.documentElement.getButton("extra2").disabled = !val;
   },
 
   loadAddEngines: function engineManager_loadAddEngines() {
     this.onOK();
-    window.opener.BrowserSearch.loadAddEngines();
-    window.close();
+    var win = window.opener;
+    // No browser window found as opener, look for one.
+    if (!win || !win.BrowserSearch)
+      win = Services.wm.getMostRecentWindow("navigator:browser");
+    // If a browser is open, use it, else don't do anything.
+    if (win && win.BrowserSearch) {
+      win.BrowserSearch.loadAddEngines();
+      window.close();
+    }
   },
 
   remove: function engineManager_remove() {
     gEngineView._engineStore.removeEngine(gEngineView.selectedEngine);
     var index = gEngineView.selectedIndex;
     gEngineView.rowCountChanged(index, -1);
     gEngineView.invalidate();
     gEngineView.selection.select(Math.min(index, gEngineView.lastIndex));
--- a/suite/common/search/search-panel.js
+++ b/suite/common/search/search-panel.js
@@ -76,16 +76,25 @@ function doSearch() {
   var textValue = textbox.value;
 
   var where = Services.prefs.getBoolPref("browser.search.openintab") ? "tab" : "current";
 
   var submission = Services.search.currentEngine.getSubmission(textValue);
   openUILinkIn(submission.uri.spec, where, null, submission.postData);
 }
 
+function OpenManager() {
+  var window = Services.wm.getMostRecentWindow("Browser:SearchManager");
+  if (window)
+    window.focus();
+  else
+    openDialog("chrome://communicator/content/search/engineManager.xul",
+               "_blank", "chrome,dialog,modal,centerscreen,resizable");
+}
+
 var engineObserver = {
   observe: function(aEngine, aTopic, aVerb) {
     if (aTopic == SEARCH_ENGINE_TOPIC) {
       if (aVerb == "engine-current")
         return;
       // Right now, always just rebuild the list after any modification.
       LoadEngineList();
     }
--- a/suite/common/search/search-panel.xul
+++ b/suite/common/search/search-panel.xul
@@ -54,9 +54,12 @@
 
     <hbox align="center">
       <textbox id="sidebar-search-text" flex="1"
                onkeypress="if (event.keyCode == event.DOM_VK_RETURN) doSearch();"
                placeholder="&search.placeholder;"/>
       <button id="searchButton" label="&search.button.label;"
               oncommand="doSearch();"/>
     </hbox>
+    <button id="managerButton"
+            label="&search.engineManager.label;"
+            oncommand="OpenManager();"/>
 </page>
--- a/suite/locales/en-US/chrome/common/pref/pref-search.dtd
+++ b/suite/locales/en-US/chrome/common/pref/pref-search.dtd
@@ -2,17 +2,16 @@
 
 <!-- LOCALIZATION NOTE : FILE The Search prefs dialog -->
 
 <!ENTITY pref.search.title                "Internet Search">
 <!ENTITY legendHeader                     "Default Search Engine">
 <!ENTITY defaultSearchEngine.label        "Search using:">
 <!ENTITY defaultSearchEngine.accesskey    "S">
 
-<!-- Will be used by bug 595246 -->
 <!ENTITY engineManager.label              "Manage Search Engines…">
 
 <!ENTITY searchResults.label              "Search Results">
 
 <!ENTITY openInTab.label                  "Open new tabs for sidebar search results">
 <!ENTITY openInTab.accesskey              "n">
 <!ENTITY openContextSearchTab.label       "Open a tab instead of a window for a context menu web search">
 <!ENTITY openContextSearchTab.accesskey   "t">
--- a/suite/locales/en-US/chrome/common/search/search-panel.dtd
+++ b/suite/locales/en-US/chrome/common/search/search-panel.dtd
@@ -33,10 +33,9 @@
    - 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 ***** -->
 
 <!ENTITY search.button.label      "Search">
 <!ENTITY search.placeholder       "Enter search text">
 
-<!-- Will be used by bug 595246 -->
 <!ENTITY search.engineManager.label "Manage Search Engines…">