Bug 1332899 - Port Bug 1329926 and remove getURIForKeyword API from SeaMonkey. r=IanN a=IanN DONTBUILD
authorFrank-Rainer Grahl <frgrahl@gmx.net>
Tue, 21 Mar 2017 20:06:20 +0100
changeset 31394 a6e7681a0b0433fa027afd36606ddfad82756ef0
parent 31393 95cca2602d76e5be7c06a55c37521f3d8f07606e
child 31395 0b37f84fcc5d350ff5279c0dc10cd0adaeeec5fb
push id1
push userclokep@gmail.com
push dateMon, 07 May 2018 22:45:56 +0000
treeherdercomm-esr60@57eacde5ef40 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersIanN, IanN
bugs1332899, 1329926
Bug 1332899 - Port Bug 1329926 and remove getURIForKeyword API from SeaMonkey. r=IanN a=IanN DONTBUILD
suite/common/search/engineManager.js
suite/common/search/engineManager.xul
--- a/suite/common/search/engineManager.js
+++ b/suite/common/search/engineManager.js
@@ -1,14 +1,19 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
 
+XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
+                                  "resource://gre/modules/PlacesUtils.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "Task",
+                                  "resource://gre/modules/Task.jsm");
 const Ci = Components.interfaces;
 const Cc = Components.classes;
 
 const ENGINE_FLAVOR = "text/x-moz-search-engine";
 
 const BROWSER_SUGGEST_PREF = "browser.search.suggest.enabled";
 
 var gEngineView = null;
@@ -100,73 +105,63 @@ var gEngineManagerDialog = {
 
     gEngineView.invalidate();
     gEngineView.selection.select(newIndex);
     gEngineView.ensureRowIsVisible(newIndex);
     this.showRestoreDefaults(true);
     document.getElementById("engineList").focus();
   },
 
-  editKeyword: function engineManager_editKeyword() {
-    var selectedEngine = gEngineView.selectedEngine;
-    if (!selectedEngine)
+  selectEditKeyword: function engineManager_selectEditKeyword() {
+    let index = gEngineView.selectedIndex;
+    // No engine selected.
+    if (index == -1)
       return;
 
-    var alias = { value: selectedEngine.alias };
-    var strings = document.getElementById("engineManagerBundle");
-    var title = strings.getString("editTitle");
-    var msg = strings.getFormattedString("editMsg", [selectedEngine.name]);
-
-    while (Services.prompt.prompt(window, title, msg, alias, null, {})) {
-      if (this.updateKeyword(selectedEngine, alias.value))
-        break;
-    }
+    let tree = document.getElementById("engineList");
+    let column = tree.columns.getColumnFor(document.getElementById("engineKeyword"));
+    tree.startEditing(index, column);
   },
 
-  updateKeyword: function(aEngine, aKeyword) {
-    var bduplicate = false;
-    var eduplicate = false;
-    var dupName = "";
+  editKeyword: Task.async(function* (aEngine, aNewKeyword) {
+    let keyword = aNewKeyword.trim();
+    if (keyword) {
+      let eduplicate = false;
+      let dupName = "";
 
-    if (aKeyword) {
-      try {
-        let bmserv =
-          Components.classes["@mozilla.org/browser/nav-bookmarks-service;1"]
-                    .getService(Components.interfaces.nsINavBookmarksService);
-        if (bmserv.getURIForKeyword(aKeyword))
-          bduplicate = true;
-      } catch(ex) {}
+      // Check for duplicates in Places keywords.
+      let bduplicate = !!(yield PlacesUtils.keywords.fetch(keyword));
 
       // Check for duplicates in changes we haven't committed yet
       let engines = gEngineView._engineStore.engines;
       for (let engine of engines) {
-        if (engine.alias == aKeyword &&
+        if (engine.alias == keyword &&
             engine.name != aEngine.name) {
           eduplicate = true;
           dupName = engine.name;
           break;
         }
       }
+
+      // Notify the user if they have chosen an existing engine/bookmark keyword
+      if (eduplicate || bduplicate) {
+        let strings = document.getElementById("engineManagerBundle");
+        let dtitle = strings.getString("duplicateTitle");
+        let bmsg = strings.getString("duplicateBookmarkMsg");
+        let emsg = strings.getFormattedString("duplicateEngineMsg", [dupName]);
+
+        Services.prompt.alert(window, dtitle, eduplicate ? emsg : bmsg);
+        return false;
+      }
     }
 
-    // Notify the user if they have chosen an existing engine/bookmark keyword
-    if (eduplicate || bduplicate) {
-      var strings = document.getElementById("engineManagerBundle");
-      var dtitle = strings.getString("duplicateTitle");
-      var bmsg = strings.getString("duplicateBookmarkMsg");
-      var emsg = strings.getFormattedString("duplicateEngineMsg", [dupName]);
-
-      Services.prompt.alert(window, dtitle, eduplicate ? emsg : bmsg);
-      return false;
-    }
-
-    gEngineView._engineStore.changeEngine(aEngine, "alias", aKeyword);
+    gEngineView._engineStore.changeEngine(aEngine, "alias", keyword);
     gEngineView.invalidate();
     return true;
-  },
+  }),
 
   onSelect: function engineManager_onSelect() {
     // Buttons only work if an engine is selected and it's not the last engine,
     // the latter is true when the selected is first and last at the same time.
     var lastSelected = (gEngineView.selectedIndex == gEngineView.lastIndex);
     var firstSelected = (gEngineView.selectedIndex == 0);
     var noSelection = (gEngineView.selectedIndex == -1);
 
@@ -447,21 +442,23 @@ EngineView.prototype = {
     if (column.id == "engineName")
       return this._engineStore.engines[index].name;
     else if (column.id == "engineKeyword")
       return this._engineStore.engines[index].alias;
     return "";
   },
 
   setCellText: function(index, column, value) {
-    if (column.id != "engineKeyword")
-      return;
-    gEngineManagerDialog.updateKeyword(this._engineStore.engines[index], value);
-    document.getElementById("engineList").stopEditing(false);
-    return;
+    if (column.id == "engineKeyword") {
+      gEngineManagerDialog.editKeyword(this._engineStore.engines[index], value)
+                          .then(valid => {
+        if (!valid)
+          document.getElementById("engineList").startEditing(index, column);
+      });
+    }
   },
 
   setTree: function(tree) {
     this.tree = tree;
   },
 
   canDrop: function(targetIndex, orientation, dataTransfer) {
     var sourceIndex = this.getSourceIndexFromDrag(dataTransfer);
--- a/suite/common/search/engineManager.xul
+++ b/suite/common/search/engineManager.xul
@@ -31,17 +31,17 @@
              disabled="true"/>
     <command id="cmd_moveup"
              oncommand="gEngineManagerDialog.bump(1);"
              disabled="true"/>
     <command id="cmd_movedown"
              oncommand="gEngineManagerDialog.bump(-1);"
              disabled="true"/>
     <command id="cmd_editkeyword"
-             oncommand="gEngineManagerDialog.editKeyword();"
+             oncommand="gEngineManagerDialog.selectEditKeyword();"
              disabled="true"/>
   </commandset>
 
   <keyset id="engineManagerKeyset">
     <key id="delete" keycode="VK_DELETE" command="cmd_remove"/>
   </keyset>
 
   <stringbundleset id="engineManagerBundleset">