Index: browser/components/search/nsSearchService.js
===================================================================
RCS file: /cvsroot/mozilla/browser/components/search/nsSearchService.js,v
retrieving revision 1.45
diff -u -8 -p -r1.45 nsSearchService.js
--- browser/components/search/nsSearchService.js 28 Jun 2006 16:16:12 -0000 1.45
+++ browser/components/search/nsSearchService.js 9 Jul 2006 05:18:48 -0000
@@ -1943,16 +1943,19 @@ SearchService.prototype = {
// If this is set to the URI of the description of a search engine being added
// to the list (typically by calling addEngine()), that engine will be
// selected as the current engine when it finishes loading. If another
// engine is added with "start using this one now" before the first selected
// engine finishes loading, the second choice will override the first one.
// If the selected engine fails to load, this marker will be cleared.
_selectNewEngineURI: null,
+ // Whether or not we need to write the order of engines on shutdown.
+ _needToSetOrderPrefs: false;
+
_init: function() {
engineMetadataService.init();
this._addObservers();
var fileLocator = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties);
var locations = fileLocator.get(NS_APP_SEARCH_DIR_LIST,
Ci.nsISimpleEnumerator);
@@ -2057,19 +2060,22 @@ SearchService.prototype = {
}
}
this._addEngineToStore(addedEngine);
}
},
_saveSortedEngineList: function SRCH_SVC_saveSortedEngineList() {
- var engines = this._getSortedEngines(false);
- for (var i = 0; i < engines.length; ++i)
- engineMetadataService.setAttr(engines[i], "order", i+1);
+ // We only need to write the prefs. if something has changed.
+ if (this._needToSetOrderPrefs) {
+ var engines = this._getSortedEngines(false);
+ for (var i = 0; i < engines.length; ++i)
+ engineMetadataService.setAttr(engines[i], "order", i+1);
+ }
},
_buildSortedEngineList: function SRCH_SVC_buildSortedEngineList() {
var addedEngines = { };
this._sortedEngines = [];
var engine;
for each (engine in this._engines) {
@@ -2348,16 +2354,19 @@ SearchService.prototype = {
ENSURE(index != -1, "Can't find engine to remove in _sortedEngines!",
Cr.NS_ERROR_FAILURE);
this._sortedEngines.splice(index, 1);
// Remove the engine from the internal store
delete this._engines[engineToRemove.name];
notifyAction(engineToRemove, SEARCH_ENGINE_REMOVED);
+
+ // Since we removed a search engine, we need to update the preferences.
+ this._needToSetOrderPrefs = true;
}
},
moveEngine: function SRCH_SVC_moveEngine(aEngine, aNewIndex) {
ENSURE_ARG((aNewIndex < this._sortedEngines.length) && (aNewIndex >= 0),
"SRCH_SVC_moveEngine: Index out of bounds!");
ENSURE_ARG(aEngine instanceof Ci.nsISearchEngine,
"SRCH_SVC_moveEngine: Invalid engine passed to moveEngine!");
@@ -2368,16 +2377,19 @@ SearchService.prototype = {
ENSURE(currentIndex != -1, "moveEngine: Can't find engine to move!",
Cr.NS_ERROR_UNEXPECTED);
// Move the engine
var movedEngine = this._sortedEngines.splice(currentIndex, 1)[0];
this._sortedEngines.splice(aNewIndex, 0, movedEngine);
notifyAction(engine, SEARCH_ENGINE_CHANGED);
+
+ // Since we removed a search engine, we need to update the preferences.
+ this._needToSetOrderPrefs = true;
},
get defaultEngine() {
const defPref = BROWSER_SEARCH_PREF + "defaultenginename";
// Get the default engine - this pref should always exist, but the engine
// might be hidden
this._defaultEngine = this.getEngineByName(getLocalizedPref(defPref, ""));
if (!this._defaultEngine || this._defaultEngine.hidden)