232272
Produced: 22/04/2006 7:51:20 PM
   
Mode:  Differences with Context  
   
Left file: I:\manager2.diff     Right file: I:\manager.diff  
53 --- browser/components/search/jar.mn  17 Mar 2006 07:15:42 -0000  1.1 = 53 --- browser/components/search/jar.mn  17 Mar 2006 07:15:42 -0000  1.1
54 +++ browser/components/search/jar.mn  22 Apr 2006 23:39:45 -0000   54 +++ browser/components/search/jar.mn  20 Apr 2006 05:21:42 -0000
55 @@ -1,3 +1,5 @@   55 @@ -1,3 +1,5 @@
56 browser.jar:   56 browser.jar:
57 *       content/browser/search/search.xml                           (content/search.xml)   57 *       content/browser/search/search.xml                           (content/search.xml)
58          content/browser/search/searchbarBindings.css                (content/searchbarBindings.css)   58          content/browser/search/searchbarBindings.css                (content/searchbarBindings.css)
59 +*       content/browser/search/engineManager.xul                    (content/engineManager.xul) <> 59 +        content/browser/search/engineManager.xul                    (content/engineManager.xul)
60 +*       content/browser/search/engineManager.js                     (content/engineManager.js) = 60 +*       content/browser/search/engineManager.js                     (content/engineManager.js)
61 Index: browser/components/search/nsIBrowserSearchService.idl   61 Index: browser/components/search/nsIBrowserSearchService.idl
62 ===================================================================   62 ===================================================================
63 RCS file: /cvsroot/mozilla/browser/components/search/nsIBrowserSearchService.idl,v   63 RCS file: /cvsroot/mozilla/browser/components/search/nsIBrowserSearchService.idl,v
64 retrieving revision 1.2   64 retrieving revision 1.2
65 diff -u -p -8 -r1.2 nsIBrowserSearchService.idl   65 diff -u -p -8 -r1.2 nsIBrowserSearchService.idl
 
94 = 94
95    /**   95    /**
96 +   * Moves a search engine.   96 +   * Moves a search engine.
97 +   *   97 +   *
98 +   * @param  engine   98 +   * @param  engine
99 +   *         The engine to remove.   99 +   *         The engine to remove.
100 +   * @param  newIndex <> 100 +   * @param  dir
101 +   *         The engine's new index.   101 +   *         The direction to move the engine. +1 for "up", -1 for "down".
102 +   *      
103 +   * @throws NS_ERROR_FAILURE if newIndex is out of bounds.      
104 +   */ = 102 +   */
105 +  void moveEngine(in nsISearchEngine engine, in long newIndex); <> 103 +  void moveEngine(in nsISearchEngine engine, in long dir);
106 + = 104 +
107 +  /**   105 +  /**
108     * Removes the search engine. If the search engine is installed in a global   106     * Removes the search engine. If the search engine is installed in a global
109     * location, this will just hide the engine. If the engine is in the user's   107     * location, this will just hide the engine. If the engine is in the user's
110     * profile directory, it will be removed from disk.   108     * profile directory, it will be removed from disk.
111     *   109     *
 
200              "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; = 198              "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
201 -  var out = "", bits = 0, i, j;   199 -  var out = "", bits = 0, i, j;
202 +  var out = "", bits, i, j;   200 +  var out = "", bits, i, j;
203   201
204    while (aBytes.length >= 3) {   202    while (aBytes.length >= 3) {
205      bits = 0;   203      bits = 0;
206 -    for (i=0; i<3; i++) { <> 204     for (i=0; i<3; i++) {
207 +    for (i = 0; i < 3; i++) {      
208        bits <<= 8; = 205        bits <<= 8;
209        bits |= aBytes[i];   206        bits |= aBytes[i];
210      }   207      }
211 -    for (j=18; j>=0; j-=6) <> 208     for (j=18; j>=0; j-=6)
212 +    for (j = 18; j >= 0; j -= 6)      
213        out += B64_CHARS[(bits>>j) & 0x3F];      
214      
215      aBytes.splice(0, 3);      
216    }      
217      
218    switch (aBytes.length) {      
219      case 2:      
220        out += B64_CHARS[(aBytes[0]>>2) & 0x3F];      
221 @@ -270,17 +270,17 @@ function b64(aBytes) { = 209 @@ -270,17 +270,17 @@ function b64(aBytes) {
222    }   210    }
223    return out;   211    return out;
224 }   212 }
225   213
226 function iconLoadListener(aChannel, aEngine) {   214 function iconLoadListener(aChannel, aEngine) {
 
263        var endMark   = /\s*>\s*$/gi; = 251        var endMark   = /\s*>\s*$/gi;
264   252
265        var foundStart = false;   253        var foundStart = false;
266        var startLine, numberOfLines;   254        var startLine, numberOfLines;
267        // Find the beginning and end of the section   255        // Find the beginning and end of the section
268 -      for (var i=0; i<lines.length; i++) {   256 -      for (var i=0; i<lines.length; i++) {
269 +      for (var i = 0; i < lines.length; i++) { <> 257 +      for (var i = 0; i<lines.length; i++) {
270          if (foundStart) { = 258          if (foundStart) {
271            if (endMark.test(lines[i])) {   259            if (endMark.test(lines[i])) {
272              numberOfLines = i - startLine;   260              numberOfLines = i - startLine;
273              // Remove the end marker   261              // Remove the end marker
274              lines[i] = lines[i].replace(endMark, "");   262              lines[i] = lines[i].replace(endMark, "");
275              // If the endmarker was not the only thing on the line, include   263              // If the endmarker was not the only thing on the line, include
 
282        lines = lines.splice(startLine, numberOfLines); = 270        lines = lines.splice(startLine, numberOfLines);
283        LOG("_parseAsSherlock::getSection: Section lines:\n" +   271        LOG("_parseAsSherlock::getSection: Section lines:\n" +
284            lines.join("\n"));   272            lines.join("\n"));
285   273
286        var section = {};   274        var section = {};
287 -      for (var i=0; i<lines.length; i++) {   275 -      for (var i=0; i<lines.length; i++) {
288 +      for (var i = 0; i < lines.length; i++) { <> 276 +      for (var i = 0; i<lines.length; i++) {
289          var line = sTrim(lines[i]); = 277          var line = sTrim(lines[i]);
290   278
291          var els = line.split("=");   279          var els = line.split("=");
292          var name = sTrim(els.shift().toLowerCase());   280          var name = sTrim(els.shift().toLowerCase());
293          var value = sTrim(els.join("="));   281          var value = sTrim(els.join("="));
294   282
 
320        // <input> is first:  Name Attr:  Prefix      Data           Example: = 308        // <input> is first:  Name Attr:  Prefix      Data           Example:
321        // YES                EMPTY       None        <value>        TEMPLATE<value>   309        // YES                EMPTY       None        <value>        TEMPLATE<value>
322        // YES                NON-EMPTY   ?           <name>=<value> TEMPLATE?<name>=<value>   310        // YES                NON-EMPTY   ?           <name>=<value> TEMPLATE?<name>=<value>
323        // NO                 EMPTY       ------------- <ignored> --------------   311        // NO                 EMPTY       ------------- <ignored> --------------
324        // NO                 NON-EMPTY   &           <name>=<value> TEMPLATE?<n1>=<v1>&<n2>=<v2>   312        // NO                 NON-EMPTY   &           <name>=<value> TEMPLATE?<n1>=<v1>&<n2>=<v2>
325 -      for (var i=0; i<inputs.length; i++) {   313 -      for (var i=0; i<inputs.length; i++) {
326 +      for (var i = 0; i < inputs.length; i++) { <> 314 +      for (var i = 0; i<inputs.length; i++) {
327          var name  = inputs[i][0]; = 315          var name  = inputs[i][0];
328          var value = inputs[i][1];   316          var value = inputs[i][1];
329          if (i==0) {   317          if (i==0) {
330            if (name == "")   318            if (name == "")
331              template += kUserDefined;   319              template += kUserDefined;
332            else   320            else
 
337        url = new EngineURL("text/html", method, template); = 325        url = new EngineURL("text/html", method, template);
338   326
339      } else if (method == "POST") {   327      } else if (method == "POST") {
340        // Create the URL object and just add the parameters directly   328        // Create the URL object and just add the parameters directly
341        url = new EngineURL("text/html", method, template);   329        url = new EngineURL("text/html", method, template);
342 -      for (var i=0; i<inputs.length; i++) {   330 -      for (var i=0; i<inputs.length; i++) {
343 +      for (var i = 0; i < inputs.length; i++) { <> 331 +      for (var i = 0; i<inputs.length; i++) {
344          var name  = inputs[i][0]; = 332          var name  = inputs[i][0];
345          var value = inputs[i][1];   333          var value = inputs[i][1];
346          if (name)   334          if (name)
347            url.addParam(name, value);   335            url.addParam(name, value);
348        }   336        }
349      } else   337      } else
 
392        this._loadEngines(location); = 380        this._loadEngines(location);
393      }   381      }
394   382
395 +    // Now that all engines are loaded, build the sorted engine list   383 +    // Now that all engines are loaded, build the sorted engine list
396 +    this._buildSortedEngineList();   384 +    this._buildSortedEngineList();
397 +   385 +
    -+ 386 +    // Remove prefs for non-existent engines
      387 +    this._clearOldPrefs();
      388 +
398      selectedEngineName = getLocalizedPref(BROWSER_SEARCH_PREF + = 389      selectedEngineName = getLocalizedPref(BROWSER_SEARCH_PREF +
399                                            "selectedEngine");   390                                            "selectedEngine");
400      this._currentEngine = this.getEngineByName(selectedEngineName) ||   391      this._currentEngine = this.getEngineByName(selectedEngineName) ||
401                            this.defaultEngine;   392                            this.defaultEngine;
402    },   393    },
403   394
 
419    _loadEngines: function SRCH_SVC_loadEngines(aDir) { = 410    _loadEngines: function SRCH_SVC_loadEngines(aDir) {
420      LOG("_loadEngines: Searching in " + aDir.path + " for search engines.");   411      LOG("_loadEngines: Searching in " + aDir.path + " for search engines.");
421   412
422      // Check whether aDir is the user profile dir   413      // Check whether aDir is the user profile dir
423      var isInProfile = aDir.equals(getDir(NS_APP_USER_SEARCH_DIR));   414      var isInProfile = aDir.equals(getDir(NS_APP_USER_SEARCH_DIR));
424 @@ -1771,18 +1776,78 @@ SearchService.prototype = {   415 @@ -1772,17 +1780,102 @@ SearchService.prototype = {
425              addedEngine._iconURI = ios.newFileURI(icon); +-    
426          } = 416          }
427        }   417        }
428   418
429        this._addEngineToStore(addedEngine);   419        this._addEngineToStore(addedEngine);
430      }   420      }
431    },   421    },
432   422
    -+ 423    /**
      424 -   * Converts a Sherlock file and it's icon into the custom XML format used by
      425 +   * Clears prefs for search engines that no longer exist. This is done here
      426 +   * in addition to in removeEngine since some engines can be removed without
      427 +   * going through removeEngine (deleted manually, extension uninstalled, etc).
      428 +   */
      429 +  _clearOldPrefs: function SRCH_SVC_clearOldPrefs() {
      430 +    var app = Cc["@mozilla.org/xre/app-info;1"].
      431 +              getService(Components.interfaces.nsIXULAppInfo).
      432 +              QueryInterface(Components.interfaces.nsIXULRuntime);
      433 +
      434 +    var preferences = Cc["@mozilla.org/preferences-service;1"].
      435 +                      getService(Ci.nsIPrefService);
      436 +    var prefb = preferences.getBranch(BROWSER_SEARCH_PREF + "engine.");
      437 +    var prefList = prefb.getChildList("", {});
      438 +
      439 +    for (var i = 0; i<prefList.length; i++) {
      440 +      var engineName = decodeURIComponent(prefList[i].replace(/\.[^.]+$/, ""));
      441 +      if (!(engineName in this._engines) && !app.inSafeMode)
      442 +        prefb.clearUserPref(prefList[i]);
      443 +    }
      444 +  },
      445 +
433 +  _saveSortedEngineList: function SRCH_SVC_saveSortedEngineList() { = 446 +  _saveSortedEngineList: function SRCH_SVC_saveSortedEngineList() {
434 +    var preferences = Cc["@mozilla.org/preferences-service;1"].   447 +    var preferences = Cc["@mozilla.org/preferences-service;1"].
435 +                      getService(Ci.nsIPrefService);   448 +                      getService(Ci.nsIPrefService);
436 +    var orderBranch = preferences.getBranch(BROWSER_SEARCH_PREF + "order.");   449 +    var orderBranch = preferences.getBranch(BROWSER_SEARCH_PREF + "order.");
437 +   450 +
438 +    // First, reset the old branch   451 +    // First, reset the old branch
    <> 452 +    for (var i = 1; ; ++i) {
439 +    for (var i = 1; orderBranch.prefHasUserValue(i); ++i)   453 +      if (orderBranch.prefHasUserValue(i))
440 +      orderBranch.clearUserPref(i);   454 +        orderBranch.clearUserPref(i);
      455 +      else
      456 +        break;
441 +   457 +    }
442 +    // Now, create the new branch = 458 +    // Now, create the new branch
443 +    var pls = Cc["@mozilla.org/pref-localizedstring;1"].   459 +    var pls = Cc["@mozilla.org/pref-localizedstring;1"].
444 +              createInstance(Ci.nsIPrefLocalizedString);   460 +              createInstance(Ci.nsIPrefLocalizedString);
445 +    var engines = this._getSortedEngines(false);   461 +    var engines = this._getSortedEngines(false);
446 +    for (var i = 0; i < engines.length; ++i) {   462 +    for (var i = 0; i < engines.length; ++i) {
447 +      pls.data = engines[i].name;   463 +      pls.data = engines[i].name;
 
487 +                                         return 1; = 503 +                                         return 1;
488 +                                       return 0;   504 +                                       return 0;
489 +                                     });   505 +                                     });
490 +    this._sortedEngines = this._sortedEngines.concat(alphaEngines);   506 +    this._sortedEngines = this._sortedEngines.concat(alphaEngines);
491 +  },   507 +  },
492 +   508 +
493   /** <> 509 +  /**
494 -   * Converts a Sherlock file and it's icon into the custom XML format used by      
495 +   * Converts a Sherlock file and its icon into the custom XML format used by = 510 +   * Converts a Sherlock file and its icon into the custom XML format used by
496     * the Search Service. Saves the engine's icon (if present) into the XML as a   511     * the Search Service. Saves the engine's icon (if present) into the XML as a
497     * data: URI and changes the extension of the source file from ".src" to   512     * data: URI and changes the extension of the source file from ".src" to
498     * ".xml". The engine data is then written to the file as XML.   513     * ".xml". The engine data is then written to the file as XML.
499     * @param aEngine   514     * @param aEngine
500     *        The Engine object that needs to be converted.   515     *        The Engine object that needs to be converted.
 
508     *        The basename of the Sherlock file. = 523     *        The basename of the Sherlock file.
509     *          Example: "foo" for file "foo.src".   524     *          Example: "foo" for file "foo.src".
510     * @see nsIURL::fileBaseName   525     * @see nsIURL::fileBaseName
511     */   526     */
512    _findSherlockIcon: function SRCH_SVC_findSherlock(aEngineFile, aBaseName) {   527    _findSherlockIcon: function SRCH_SVC_findSherlock(aEngineFile, aBaseName) {
513 -    for (var i=0; i<SHERLOCK_ICON_EXTENSIONS.length; i++) {   528 -    for (var i=0; i<SHERLOCK_ICON_EXTENSIONS.length; i++) {
514 +    for (var i = 0; i < SHERLOCK_ICON_EXTENSIONS.length; i++) { <> 529 +    for (var i = 0; i<SHERLOCK_ICON_EXTENSIONS.length; i++) {
515        var icon = aEngineFile.parent.clone(); = 530        var icon = aEngineFile.parent.clone();
516        icon.append(aBaseName + SHERLOCK_ICON_EXTENSIONS[i]);   531        icon.append(aBaseName + SHERLOCK_ICON_EXTENSIONS[i]);
517        if (icon.exists() && icon.isFile())   532        if (icon.exists() && icon.isFile())
518          return icon;   533          return icon;
519      }   534      }
520      return null;   535      return null;
 
532 -    var i = 0; = 547 -    var i = 0;
533 -   548 -
534 -    while (true) {   549 -    while (true) {
535 -      engineName = getLocalizedPref(BROWSER_SEARCH_PREF + "order." + (++i));   550 -      engineName = getLocalizedPref(BROWSER_SEARCH_PREF + "order." + (++i));
536 -      if (!engineName)   551 -      if (!engineName)
537 -        break;   552 -        break;
538 +    if (aWithHidden) <>    
539 +      return this._sortedEngines;      
540   553 -
541 -      engine = this._engines[engineName]; = 554 -      engine = this._engines[engineName];
542 -      if (engine && !(engineName in addedEngines) &&   555 -      if (engine && !(engineName in addedEngines) &&
543 -          (aWithHidden || !engine.hidden)) {   556 -          (aWithHidden || !engine.hidden)) {
544 -        engines.push(engine);   557 -        engines.push(engine);
545 -        addedEngines[engineName] = engine;   558 -        addedEngines[engineName] = engine;
546 -      }   559 -      }
547 -    }   560 -    }
    <> 561 +    if (aWithHidden)
      562 +      return this._sortedEngines;
548 -   563
549 -    // No more sorted engines = 564 -    // No more sorted engines
550 -    for (engineName in this._engines) {   565 -    for (engineName in this._engines) {
551 -      engine = this._engines[engineName];   566 -      engine = this._engines[engineName];
552 -      if (!(engineName in addedEngines) && (aWithHidden || !engine.hidden))   567 -      if (!(engineName in addedEngines) && (aWithHidden || !engine.hidden))
553 -        engines.push(this._engines[engineName]);   568 -        engines.push(this._engines[engineName]);
554 -    }   569 -    }
 
609        delete this._engines[engineToRemove.name]; = 624        delete this._engines[engineToRemove.name];
610 +   625 +
611        notifyAction(engineToRemove, SEARCH_ENGINE_REMOVED);   626        notifyAction(engineToRemove, SEARCH_ENGINE_REMOVED);
612      }   627      }
613    },   628    },
614   629
615 +  moveEngine: function SRCH_SVC_moveEngine(aEngine, aNewIndex) { <> 630 +  moveEngine: function SRCH_SVC_moveEngine(aEngine, aDir) {
616 +    ENSURE_ARG((aNewIndex < this._sortedEngines.length) && (aNewIndex >= 0),   631 +    ENSURE_ARG(Math.abs(aDir) < this._sortedEngines.length,
617 +               "SRCH_SVC_moveEngine: Index out of bounds!");   632 +               "Invalid offset passed to moveEngine!");
618 +    ENSURE_ARG(aEngine instanceof Ci.nsISearchEngine, = 633 +    ENSURE_ARG(aEngine instanceof Ci.nsISearchEngine,
619 +               "SRCH_SVC_moveEngine: Invalid engine passed to moveEngine!"); <> 634 +               "Invalid engine passed to moveEngine!");
620 + = 635 +
621 +    var engine = aEngine.wrappedJSObject;   636 +    var engine = aEngine.wrappedJSObject;
622 +   637 +
623 +    var currentIndex = this._sortedEngines.indexOf(engine); <> 638 +    var index = this._sortedEngines.indexOf(engine);
624 +    ENSURE(currentIndex != -1, "moveEngine: Can't find engine to move!",   639 +    ENSURE(index != -1, "moveEngine: Can't find engine to move!",
625 +           Cr.NS_ERROR_UNEXPECTED); = 640 +           Cr.NS_ERROR_UNEXPECTED);
626 +   641 +
    -+ 642 +    var newIndex = index - aDir;
      643 +    ENSURE_ARG((newIndex < this._sortedEngines.length) && (newIndex >= 0),
      644 +               "Index out of bounds!");
      645 +
627 +    // Swap the two engines = 646 +    // Swap the two engines
628 +    this._sortedEngines[currentIndex] = this._sortedEngines[aNewIndex]; <> 647 +    this._sortedEngines[index] = this._sortedEngines[newIndex];
629 +    this._sortedEngines[aNewIndex] = engine;   648 +    this._sortedEngines[newIndex] = engine;
630 + = 649 +
631 +    notifyAction(engine, SEARCH_ENGINE_CHANGED);   650 +    notifyAction(engine, SEARCH_ENGINE_CHANGED);
632 +  },   651 +  },
633 +   652 +
634    get defaultEngine() {   653    get defaultEngine() {
635      const defPref = BROWSER_SEARCH_PREF + "defaultenginename";   654      const defPref = BROWSER_SEARCH_PREF + "defaultenginename";
 
643    }, = 662    },
644   663
645    get currentEngine() {   664    get currentEngine() {
646 -    if (this._currentEngine.hidden)   665 -    if (this._currentEngine.hidden)
647 +    if (!this._currentEngine || this._currentEngine.hidden)   666 +    if (!this._currentEngine || this._currentEngine.hidden)
648        this._currentEngine = this.defaultEngine;   667        this._currentEngine = this.defaultEngine;
649     return this._currentEngine; <> 668 -    return this._currentEngine;
      669 +    return this._currentEngine || this.defaultEngine;
650    }, = 670    },
651    set currentEngine(val) {   671    set currentEngine(val) {
652 -    ENSURE_ARG(val.QueryInterface(Ci.nsISearchEngine),   672 -    ENSURE_ARG(val.QueryInterface(Ci.nsISearchEngine),
653 +    ENSURE_ARG(val instanceof Ci.nsISearchEngine,   673 +    ENSURE_ARG(val instanceof Ci.nsISearchEngine,
654                 "Invalid argument passed to currentEngine setter");   674                 "Invalid argument passed to currentEngine setter");
655   675
 
745 +    tree.view = gEngineView; = 765 +    tree.view = gEngineView;
746 +   766 +
747 +    this._strings = document.getElementById("engineManagerBundle");   767 +    this._strings = document.getElementById("engineManagerBundle");
748 +   768 +
749 +    var os = Cc["@mozilla.org/observer-service;1"].   769 +    var os = Cc["@mozilla.org/observer-service;1"].
750 +             getService(Ci.nsIObserverService);   770 +             getService(Ci.nsIObserverService);
751 +    os.addObserver(this, "browser-search-engine-modified", false); <> 771 +    os.addObserver(this, "browser-search-engine-modified",
      772 +                   false);
752 + = 773 +
753 +    // Set the "Add Engines" link's href   774 +    // Set the "Add Engines" link's href
754 +    var regionBundle = document.getElementById("regionBundle");   775 +    var regionBundle = document.getElementById("regionBundle");
755 +    var searchEnginesURL = regionBundle.getString("searchEnginesURL");   776 +    var searchEnginesURL = regionBundle.getString("searchEnginesURL");
756 +    var addEngines = document.getElementById("addEngines");   777 +    var addEngines = document.getElementById("addEngines");
757 +    addEngines.setAttribute("href", searchEnginesURL);   778 +    addEngines.setAttribute("href", searchEnginesURL);
 
785 + = 806 +
786 +    // Commit the changes   807 +    // Commit the changes
787 +    gEngineView._engineStore.commit();   808 +    gEngineView._engineStore.commit();
788 +  },   809 +  },
789 +   810 +
790 +  remove: function engineManager_remove() {   811 +  remove: function engineManager_remove() {
    <> 812 +    var selectedEngine = gEngineView.selectedEngine;
      813 +    if (!selectedEngine)
      814 +      return;
      815 +
791 +    gEngineView._engineStore.removeEngine(gEngineView.selectedEngine);   816 +    gEngineView._engineStore.removeEngine(selectedEngine);
792 +    var index = gEngineView.selectedIndex; = 817 +    var index = gEngineView.selectedIndex;
793 +    gEngineView.rowCountChanged(index, -1);   818 +    gEngineView.rowCountChanged(index, -1);
794 +    gEngineView.invalidate();   819 +    gEngineView.invalidate();
795 +    gEngineView.selection.select(Math.min(index, gEngineView.lastIndex));   820 +    gEngineView.selection.select(Math.min(index, gEngineView.lastIndex));
796 +  },   821 +  },
797 +   822 +
798 +  editAlias: function engineManager_editAlias() {   823 +  editAlias: function engineManager_editAlias() {
799 +    var selectedEngine = gEngineView.selectedEngine;   824 +    var selectedEngine = gEngineView.selectedEngine;
    -+ 825 +    if (!selectedEngine)
      826 +      return;
      827 +
800 +    var prompt = Cc["@mozilla.org/embedcomp/prompt-service;1"]. = 828 +    var prompt = Cc["@mozilla.org/embedcomp/prompt-service;1"].
801 +                 getService(Ci.nsIPromptService);   829 +                 getService(Ci.nsIPromptService);
802 +   830 +
803 +    var alias = { value: selectedEngine.alias };   831 +    var alias = { value: selectedEngine.alias };
804 +   832 +
805 +    var title = this._strings.getString("edit_alias_title");   833 +    var title = this._strings.getString("edit_alias_title");
 
814 + = 842 +
815 +  /**   843 +  /**
816 +   * Moves the selected engine either up or down in the engine list   844 +   * Moves the selected engine either up or down in the engine list
817 +   * @param aDir   845 +   * @param aDir
818 +   *        -1 to move the selected engine down, +1 to move it up.   846 +   *        -1 to move the selected engine down, +1 to move it up.
819 +   */   847 +   */
820 bump: function engineManager_move(aDir) { <> 848 move: function engineManager_move(aDir) {
821 +    var selectedEngine = gEngineView.selectedEngine; = 849 +    var selectedEngine = gEngineView.selectedEngine;
822 +    var newIndex = gEngineView.selectedIndex - aDir; <> 850 +    if (!selectedEngine)
      851 +      return;
823 + = 852 +
824 +    gEngineView._engineStore.moveEngine(selectedEngine, newIndex); <> 853 +    if (Math.abs(aDir) != 1)
      854 +      throw new Error("Invalid direction!");
825 + = 855 +
826 +    gEngineView.invalidate(); <>    
827 +    gEngineView.selection.select(newIndex);   856 +    var newIndex = gEngineView.selectedIndex - aDir;
828 +  },      
829 + = 857 +
830 /** <> 858   if (newIndex < 0 || newIndex > gEngineView.lastIndex)
831 +   * Moves the selected engine to the specified index in the engine list.   859 +      throw new Error("Invalid aDir!");
832 +   * @param aNewIndex      
833 +   *        The desired index of the engine in the list.      
834 +   */   860 +
835 +  moveToIndex: function engineManager_moveToIndex(aNewIndex) {      
836 +    var selectedEngine = gEngineView.selectedEngine;      
837 +    gEngineView._engineStore.moveEngine(selectedEngine, aNewIndex);   861 +    gEngineView._engineStore.moveEngine(selectedEngine, aDir);
838 + = 862 +
839 +    gEngineView.invalidate();   863 +    gEngineView.invalidate();
840 +    gEngineView.selection.select(aNewIndex); <> 864 +    gEngineView.selection.select(newIndex);
841 +  }, = 865 +  },
842 +   866 +
843 +  onSelect: function engineManager_onSelect() {   867 +  onSelect: function engineManager_onSelect() {
844 +    var noEngineSelected = (gEngineView.selectedIndex == -1);   868 +    var noEngineSelected = (gEngineView.selectedIndex == -1);
845 +    var lastSelected = (gEngineView.selectedIndex == gEngineView.lastIndex); <> 869 +    document.getElementById("remove").disabled = noEngineSelected;
846 +    var firstSelected = (gEngineView.selectedIndex == 0);   870 +    // document.getElementById("rename").disabled = noEngineSelected;
847 +   871 +    document.getElementById("alias").disabled  = noEngineSelected;
848 +    document.getElementById("cmd_remove").setAttribute("disabled",      
849 +                                                       noEngineSelected);      
850 +    document.getElementById("cmd_editalias").setAttribute("disabled",      
851 +                                                          noEngineSelected);      
852 + = 872 +
853 +    document.getElementById("cmd_moveup").setAttribute("disabled", <> 873 +    document.getElementById("up").disabled = noEngineSelected ||
854 +                                            noEngineSelected || firstSelected);   874 +                                             (gEngineView.selectedIndex == 0);
855 + = 875 +
856 +    document.getElementById("cmd_movedown").setAttribute("disabled", <> 876 +    var lastSelected = (gEngineView.selectedIndex == gEngineView.lastIndex);
      877 +    document.getElementById("dn").disabled = noEngineSelected ||
857 +                                             noEngineSelected || lastSelected);   878 +                                             lastSelected;
858 +  } = 879 +  }
859 +};   880 +};
860 +   881 +
861 +// "Operation" objects   882 +// "Operation" objects
862 +function EngineMoveOp(aEngineClone, aNewIndex) { <> 883 +function EngineMoveOp(aEngineClone, aDir) {
863 +  if (!aEngineClone)   884 +  if (!aEngineClone || !aDir)
864 +    throw new Error("bad args to new EngineMoveOp!"); = 885 +    throw new Error("bad args to new EngineMoveOp!");
865 +  this._engine = aEngineClone.originalEngine;   886 +  this._engine = aEngineClone.originalEngine;
866 +  this._newIndex = aNewIndex; <> 887 +  this._dir = aDir;
867 +} = 888 +}
868 +EngineMoveOp.prototype = {   889 +EngineMoveOp.prototype = {
869 +  _engine: null,   890 +  _engine: null,
870 +  _newIndex: null, <> 891 +  _dir: null,
871 +  commit: function EMO_commit() { = 892 +  commit: function EMO_commit() {
872 +    var searchService = Cc["@mozilla.org/browser/search-service;1"].   893 +    var searchService = Cc["@mozilla.org/browser/search-service;1"].
873 +                        getService(Ci.nsIBrowserSearchService);   894 +                        getService(Ci.nsIBrowserSearchService);
874 +    searchService.moveEngine(this._engine, this._newIndex); <> 895 +    searchService.moveEngine(this._engine, this._dir);
875 +  } = 896 +  }
876 +}   897 +}
877 +   898 +
878 +function EngineRemoveOp(aEngineClone) {   899 +function EngineRemoveOp(aEngineClone) {
879 +  if (!aEngineClone)   900 +  if (!aEngineClone)
880 +    throw new Error("bad args to new EngineRemoveOp!");   901 +    throw new Error("bad args to new EngineRemoveOp!");
 
952 +      throw new Error("invalid engine?"); = 973 +      throw new Error("invalid engine?");
953 +   974 +
954 +    this._engines[index][aProp] = aNewValue;   975 +    this._engines[index][aProp] = aNewValue;
955 +    this._ops.push(new EngineChangeOp(aEngine, aProp, aNewValue));   976 +    this._ops.push(new EngineChangeOp(aEngine, aProp, aNewValue));
956 +  },   977 +  },
957 +   978 +
958 +  moveEngine: function ES_moveEngine(aEngine, aNewIndex) { <> 979 +  moveEngine: function ES_moveEngine(aEngine, aDir) {
959 +    if (aNewIndex < 0 || aNewIndex > this._engines.length - 1)      
960 +      throw new Error("ES_moveEngine: invalid aNewIndex!");      
961 +    var index = this._getIndexForEngine(aEngine); = 980 +    var index = this._getIndexForEngine(aEngine);
    -+ 981 +    var newIndex = index - aDir;
962 +    if (index == -1) = 982 +    if (index == -1)
963 +      throw new Error("ES_moveEngine: invalid engine?"); <> 983 +      throw new Error("invalid engine?");
      984 +    if (newIndex < 0 || newIndex > this._engines.length - 1)
      985 +      throw new Error("invalid aDir!");
964 + = 986 +
965 +    // Switch the two engines in our internal store   987 +    // Switch the two engines in our internal store
966 +    this._engines[index] = this._engines[aNewIndex]; <> 988 +    this._engines[index] = this._engines[newIndex];
967 +    this._engines[aNewIndex] = aEngine;   989 +    this._engines[newIndex] = aEngine;
968 + = 990 +
969 +    this._ops.push(new EngineMoveOp(aEngine, aNewIndex)); <> 991 +    this._ops.push(new EngineMoveOp(aEngine, aDir));
970 +  }, = 992 +  },
971 +   993 +
972 +  removeEngine: function ES_removeEngine(aEngine) {   994 +  removeEngine: function ES_removeEngine(aEngine) {
973 +    var index = this._getIndexForEngine(aEngine);   995 +    var index = this._getIndexForEngine(aEngine);
974 +    if (index == -1)   996 +    if (index == -1)
975 +      throw new Error("invalid engine?");   997 +      throw new Error("invalid engine?");
 
1075 RCS file: browser/components/search/content/engineManager.xul = 1097 RCS file: browser/components/search/content/engineManager.xul
1076 diff -N browser/components/search/content/engineManager.xul   1098 diff -N browser/components/search/content/engineManager.xul
1077 --- /dev/null 1 Jan 1970 00:00:00 -0000   1099 --- /dev/null 1 Jan 1970 00:00:00 -0000
1078 +++ browser/components/search/content/engineManager.xul 22 Apr 2006 23:39:46 -0000   1100 +++ browser/components/search/content/engineManager.xul 20 Apr 2006 05:21:43 -0000
1079 @@ -0,0 +1,121 @@   1101 @@ -0,0 +1,60 @@
1080 +<?xml version="1.0"?>   1102 +<?xml version="1.0"?>
1081 +# ***** BEGIN LICENSE BLOCK ***** +-    
1082 +# Version: MPL 1.1/GPL 2.0/LGPL 2.1      
1083 +#      
1084 +# The contents of this file are subject to the Mozilla Public License Version      
1085 +# 1.1 (the "License"); you may not use this file except in compliance with      
1086 +# the License. You may obtain a copy of the License at      
1087 +# http://www.mozilla.org/MPL/      
1088 +#      
1089 +# Software distributed under the License is distributed on an "AS IS" basis,      
1090 +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License      
1091 +# for the specific language governing rights and limitations under the      
1092 +# License.      
1093 +#      
1094 +# The Original Code is the Browser Search Service.      
1095 +#      
1096 +# The Initial Developer of the Original Code is      
1097 +# Google Inc.      
1098 +# Portions created by the Initial Developer are Copyright (C) 2005      
1099 +# the Initial Developer. All Rights Reserved.      
1100 +#      
1101 +# Contributor(s):      
1102 +#   Ben Goodger <beng@google.com> (Original author)      
1103 +#   Gavin Sharp <gavin@gavinsharp.com>      
1104 +#      
1105 +# Alternatively, the contents of this file may be used under the terms of      
1106 +# either the GNU General Public License Version 2 or later (the "GPL"), or      
1107 +# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),      
1108 +# in which case the provisions of the GPL or the LGPL are applicable instead      
1109 +# of those above. If you wish to allow use of your version of this file only      
1110 +# under the terms of either the GPL or the LGPL, and not to allow others to      
1111 +# use your version of this file under the terms of the MPL, indicate your      
1112 +# decision by deleting the provisions above and replace them with the notice      
1113 +# and other provisions required by the GPL or the LGPL. If you do not delete      
1114 +# the provisions above, a recipient may use your version of this file under      
1115 +# the terms of any one of the MPL, the GPL or the LGPL.      
1116 +#      
1117 +# ***** END LICENSE BLOCK *****      
1118 + = 1103 +
1119 +<?xml-stylesheet href="chrome://global/skin/"?>   1104 +<?xml-stylesheet href="chrome://global/skin/"?>
1120 +   1105 +
1121 +<!DOCTYPE dialog SYSTEM "chrome://browser/locale/engineManager.dtd">   1106 +<!DOCTYPE dialog SYSTEM "chrome://browser/locale/engineManager.dtd">
1122 +   1107 +
1123 +<dialog id="engineManager"   1108 +<dialog id="engineManager"
1124 +        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"   1109 +        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
1125 +        buttons="accept,cancel"   1110 +        buttons="accept,cancel"
1126 +        onload="gEngineManagerDialog.init();"   1111 +        onload="gEngineManagerDialog.init();"
1127 +        ondialogaccept="gEngineManagerDialog.onOK();"   1112 +        ondialogaccept="gEngineManagerDialog.onOK();"
1128 +        title="&engineManager.title;"   1113 +        title="&engineManager.title;"
1129 +        style="&engineManager.style;" <> 1114 +        style="min-width: 40em;"
1130 +        persist="screenX screenY"      
1131 +        windowtype="Browser:SearchManager"> = 1115 +        windowtype="Browser:SearchManager">
1132 +   1116 +
1133 +  <script type="application/x-javascript"   1117 +  <script type="application/x-javascript"
1134 +          src="chrome://browser/content/search/engineManager.js"/>   1118 +          src="chrome://browser/content/search/engineManager.js"/>
1135 +  <stringbundle id="engineManagerBundle"   1119 +  <stringbundle id="engineManagerBundle"
1136 +                src="chrome://browser/locale/search.properties"/>   1120 +                src="chrome://browser/locale/search.properties"/>
1137 +  <stringbundle id="regionBundle"   1121 +  <stringbundle id="regionBundle"
1138 +                src="chrome://browser-region/locale/region.properties"/>   1122 +                src="chrome://browser-region/locale/region.properties"/>
1139 +   1123 +
1140 +  <commandset id="engineManagerCommandSet"> +-    
1141 +    <command id="cmd_remove"      
1142 +             oncommand="gEngineManagerDialog.remove();"      
1143 +             disabled="true"/>      
1144 +    <command id="cmd_moveup"      
1145 +             oncommand="gEngineManagerDialog.bump(1);"      
1146 +             disabled="true"/>      
1147 +    <command id="cmd_movedown"      
1148 +             oncommand="gEngineManagerDialog.bump(-1);"      
1149 +             disabled="true"/>      
1150 +    <command id="cmd_editalias"      
1151 +             oncommand="gEngineManagerDialog.editAlias();"      
1152 +             disabled="true"/>      
1153 +  </commandset>      
1154 +      
1155 +  <keyset id="engineManagerKeyset"> = 1124 +  <keyset id="engineManagerKeyset">
1156 +    <key id="delete" keycode="VK_DELETE" command="cmd_remove"/> <> 1125 +    <key id="delete" keycode="VK_DELETE"
      1126 +         oncommand="gEngineManagerDialog.remove();"/>
1157 +  </keyset> = 1127 +  </keyset>
1158 +   1128 +
1159 +  <description>&engineManager.intro;</description> <> 1129 +  <label>&engineManager.intro;</label>
1160 + = 1130 +
1161 +  <separator class="thin"/>   1131 +  <separator class="thin"/>
1162 +   1132 +
1163 +  <hbox flex="1">   1133 +  <hbox flex="1">
1164 +    <tree id="engineList" flex="1" rows="10" hidecolumnpicker="true"   1134 +    <tree id="engineList" flex="1" rows="10" hidecolumnpicker="true"
1165 +          seltype="single" onselect="gEngineManagerDialog.onSelect();">   1135 +          seltype="single" onselect="gEngineManagerDialog.onSelect();">
 
1171 +        <treecol id="engineAlias" class="sortDirectionIndicator" flex="2" = 1141 +        <treecol id="engineAlias" class="sortDirectionIndicator" flex="2"
1172 +                 persist="width" label="&aliasColumn.label;"/>   1142 +                 persist="width" label="&aliasColumn.label;"/>
1173 +      </treecols>   1143 +      </treecols>
1174 +    </tree>   1144 +    </tree>
1175 +    <vbox>   1145 +    <vbox>
1176 +      <spacer flex="1"/>   1146 +      <spacer flex="1"/>
1177 +      <button id="up" <> 1147 +      <button id="up" label="&up.label;" accesskey="&up.accesskey;"
1178 +              label="&up.label;"   1148 +              oncommand="gEngineManagerDialog.move(1);"/>
1179 +              accesskey="&up.accesskey;"   1149 +      <button id="dn" label="&dn.label;" accesskey="&dn.accesskey;"
1180 +              command="cmd_moveup"/>   1150 +              oncommand="gEngineManagerDialog.move(-1);"/>
1181 +      <button id="dn"      
1182 +              label="&dn.label;"      
1183 +              accesskey="&dn.accesskey;"      
1184 +              command="cmd_movedown"/>      
1185 +      <spacer flex="1"/> = 1151 +      <spacer flex="1"/>
1186 +      <button id="alias" <>    
1187 +              label="&editAlias.label;"   1152 +      <button id="alias" label="&editAlias.label;"
1188 +              accesskey="&editAlias.accesskey;" = 1153 +              accesskey="&editAlias.accesskey;"
1189 +              command="cmd_editalias"/> <> 1154 +              oncommand="gEngineManagerDialog.editAlias();"/>
1190 +      <button id="remove"   1155 +      <button id="remove" label="&delete.label;"
1191 +              label="&delete.label;"      
1192 +              accesskey="&delete.accesskey;" = 1156 +              accesskey="&delete.accesskey;"
1193 +              command="cmd_remove"/> <> 1157 +              oncommand="gEngineManagerDialog.remove();"/>
1194 +    </vbox> = 1158 +    </vbox>
1195 +  </hbox>   1159 +  </hbox>
1196 +  <hbox> <>    
1197   <label id="addEngines" class="text-link" value="&addEngine.label;"/>   1160 +  <label id="addEngines" class="text-link" value="&addEngine.label;"/>
1198 +    <spacer flex="1"/>      
1199 +  </hbox>      
1200 +</dialog> = 1161 +</dialog>
1201 Index: browser/components/search/content/search.xml   1162 Index: browser/components/search/content/search.xml
1202 ===================================================================   1163 ===================================================================
1203 RCS file: /cvsroot/mozilla/browser/components/search/content/search.xml,v   1164 RCS file: /cvsroot/mozilla/browser/components/search/content/search.xml,v
1204 retrieving revision 1.43   1165 retrieving revision 1.41
1205 diff -u -p -8 -r1.43 search.xml   1166 diff -u -p -8 -r1.41 search.xml
 
1407 +                Components.classes["@mozilla.org/appshell/window-mediator;1"] = 1368 +                Components.classes["@mozilla.org/appshell/window-mediator;1"]
1408 +                          .getService(Components.interfaces.nsIWindowMediator);   1369 +                          .getService(Components.interfaces.nsIWindowMediator);
1409 +   1370 +
1410 +          var window = wm.getMostRecentWindow("Browser:SearchManager");   1371 +          var window = wm.getMostRecentWindow("Browser:SearchManager");
1411 +          if (window)   1372 +          if (window)
1412 +            window.focus()   1373 +            window.focus()
1413 +          else { <> 1374 +          else
1414 +            setTimeout(function () {      
1415 +              openDialog("chrome://browser/content/search/engineManager.xul",   1375 +            openDialog("chrome://browser/content/search/engineManager.xul",
1416 +                         "_blank", "chrome,dialog,modal");   1376 +                       "_blank", "resizable,chrome,dialog,modal");
1417 +            }, 0);      
1418 +          }      
1419          ]]></body> = 1377          ]]></body>
1420        </method>   1378        </method>
1421   1379
1422        <method name="onEnginePopupCommand">   1380        <method name="onEnginePopupCommand">
1423          <parameter name="aEvent"/>   1381          <parameter name="aEvent"/>
1424          <body><![CDATA[   1382          <body><![CDATA[
 
1514 RCS file: browser/locales/en-US/chrome/browser/engineManager.dtd = 1472 RCS file: browser/locales/en-US/chrome/browser/engineManager.dtd
1515 diff -N browser/locales/en-US/chrome/browser/engineManager.dtd   1473 diff -N browser/locales/en-US/chrome/browser/engineManager.dtd
1516 --- /dev/null 1 Jan 1970 00:00:00 -0000   1474 --- /dev/null 1 Jan 1970 00:00:00 -0000
1517 +++ browser/locales/en-US/chrome/browser/engineManager.dtd  22 Apr 2006 23:39:47 -0000   1475 +++ browser/locales/en-US/chrome/browser/engineManager.dtd  20 Apr 2006 05:21:45 -0000
1518 @@ -0,0 +1,18 @@   1476 @@ -0,0 +1,17 @@
1519 +<!ENTITY  engineManager.title       "Manage Search Engine List">   1477 +<!ENTITY  engineManager.title       "Manage Search Engine List">
1520 +<!ENTITY  engineManager.style       "min-width: 40em;"> +-    
1521 +<!ENTITY  engineManager.intro       "The following Search Engines are available:"> = 1478 +<!ENTITY  engineManager.intro       "The following Search Engines are available:">
1522 +   1479 +
1523 +<!ENTITY  up.label                  "Move Up">   1480 +<!ENTITY  up.label                  "Move Up">
1524 +<!ENTITY  up.accesskey              "U">   1481 +<!ENTITY  up.accesskey              "U">
1525 +<!ENTITY  dn.label                  "Move Down">   1482 +<!ENTITY  dn.label                  "Move Down">
1526 +<!ENTITY  dn.accesskey              "D">   1483 +<!ENTITY  dn.accesskey              "D">