Skip to content

Commit

Permalink
Bug 1122618 - Added change to rebuild the defaultEngineDropDown whene…
Browse files Browse the repository at this point in the history
…ver the default engine is changed. Separated the code performing the changes and displaying the changes when removing/adding engines. r=florian.
  • Loading branch information
Jeremy Francispillai committed Jan 6, 2016
1 parent b336cf3 commit 84ac618
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
19 changes: 12 additions & 7 deletions browser/components/preferences/in-content/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ var gSearchPane = {
gSearchPane.onRestoreDefaults();
break;
case "removeEngineButton":
gSearchPane.remove();
Services.search.removeEngine(gEngineView.selectedEngine.originalEngine);
break;
}
break;
Expand Down Expand Up @@ -180,7 +180,11 @@ var gSearchPane = {
gEngineView.invalidate();
break;
case "engine-removed":
gSearchPane.remove(aEngine);
break;
case "engine-current":
gSearchPane.buildDefaultEngineDropDown();
break;
case "engine-default":
// Not relevant
break;
Expand Down Expand Up @@ -228,9 +232,8 @@ var gSearchPane = {
document.getElementById("restoreDefaultSearchEngines").disabled = !aEnable;
},

remove: function() {
gEngineView._engineStore.removeEngine(gEngineView.selectedEngine);
let index = gEngineView.selectedIndex;
remove: function(aEngine) {
let index = gEngineView._engineStore.removeEngine(aEngine);
gEngineView.rowCountChanged(index, -1);
gEngineView.invalidate();
gEngineView.selection.select(Math.min(index, gEngineView.lastIndex));
Expand Down Expand Up @@ -369,16 +372,18 @@ EngineStore.prototype = {
},

removeEngine: function ES_removeEngine(aEngine) {
var index = this._getIndexForEngine(aEngine);
let engineName = aEngine.name;
let index = this._engines.findIndex(element => element.name == engineName);

if (index == -1)
throw new Error("invalid engine?");

this._engines.splice(index, 1);
Services.search.removeEngine(aEngine.originalEngine);

if (this._defaultEngines.some(this._isSameEngine, aEngine))
if (this._defaultEngines.some(this._isSameEngine, this._engines[index]))
gSearchPane.showRestoreDefaults(true);
gSearchPane.buildDefaultEngineDropDown();
return index;
},

restoreDefaultEngines: function ES_restoreDefaultEngines() {
Expand Down
3 changes: 1 addition & 2 deletions toolkit/components/search/nsSearchService.js
Original file line number Diff line number Diff line change
Expand Up @@ -4016,11 +4016,10 @@ SearchService.prototype = {
// Remove the engine from the internal store
delete this._engines[engineToRemove.name];

notifyAction(engineToRemove, SEARCH_ENGINE_REMOVED);

// Since we removed an engine, we need to update the preferences.
this._saveSortedEngineList();
}
notifyAction(engineToRemove, SEARCH_ENGINE_REMOVED);
},

moveEngine: function SRCH_SVC_moveEngine(aEngine, aNewIndex) {
Expand Down

0 comments on commit 84ac618

Please sign in to comment.