Bug 348737: restoring default search engines doesn't restore the original order, r=mconnor

This commit is contained in:
gavin%gavinsharp.com 2006-08-27 17:18:41 +00:00
parent e39fdc0329
commit 0470959842
2 changed files with 32 additions and 17 deletions

View File

@ -261,6 +261,12 @@ EngineStore.prototype = {
return this._engines.indexOf(aEngine);
},
_getEngineByName: function ES_getEngineByName(aName) {
for each (var engine in this._engines)
if (engine.name == aName)
return engine;
},
_cloneEngine: function ES_cloneObj(aEngine) {
var newO=[];
for (var i in aEngine)
@ -299,7 +305,10 @@ EngineStore.prototype = {
if (index == -1)
throw new Error("ES_moveEngine: invalid engine?");
// Switch the two engines in our internal store
if (index == aNewIndex)
return; // nothing to do
// Move the engine in our internal store
var removedEngine = this._engines.splice(index, 1)[0];
this._engines.splice(aNewIndex, 0, removedEngine);
@ -318,18 +327,23 @@ EngineStore.prototype = {
},
restoreDefaultEngines: function ES_restoreDefaultEngines() {
var i = 0;
for each (var e in this._defaultEngines) {
// skip adding engine if the engine is already in the list
if (this._engines.some(this._isSameEngine, e))
continue;
var added = 0;
this._engines.splice(i, 0, e);
this._ops.push(new EngineUnhideOp(e, i));
i++;
for (var i = 0; i < this._defaultEngines.length; ++i) {
var e = this._defaultEngines[i];
// If the engine is already in the list, just move it.
if (this._engines.some(this._isSameEngine, e)) {
this.moveEngine(this._getEngineByName(e.name), i);
} else {
// Otherwise, add it back to our internal store
this._engines.splice(i, 0, e);
this._ops.push(new EngineUnhideOp(e, i));
added++;
}
}
gEngineManagerDialog.showRestoreDefaults(false);
return i;
return added;
},
reloadIcons: function ES_reloadIcons() {

View File

@ -2544,17 +2544,15 @@ SearchService.prototype = {
return engine._isInAppDir;
};
var engines = this._sortedEngines.filter(isDefault);
var prefB = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefService).
getBranch(BROWSER_SEARCH_PREF + "order.");
var engineOrder = {};
var i = 1;
while (true) {
try {
engineOrder[prefB.getCharPref(i)] = i++;
} catch (ex) {
var name = getLocalizedPref(BROWSER_SEARCH_PREF + "order." + i);
if (!name)
break;
}
engineOrder[name] = i++;
}
function compareEngines (a, b) {
@ -2670,6 +2668,9 @@ SearchService.prototype = {
ENSURE(currentIndex != -1, "moveEngine: Can't find engine to move!",
Cr.NS_ERROR_UNEXPECTED);
if (currentIndex == aNewIndex)
return; // nothing to do!
// Move the engine
var movedEngine = this._sortedEngines.splice(currentIndex, 1)[0];
this._sortedEngines.splice(aNewIndex, 0, movedEngine);