Skip to content
This repository has been archived by the owner on Feb 29, 2020. It is now read-only.

Commit

Permalink
feat(addon): #764 SearchProvider manages your engines
Browse files Browse the repository at this point in the history
  • Loading branch information
sarracini committed May 31, 2016
1 parent 0ef6ea7 commit fcc55d0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions common/action-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const am = new ActionManager([
"RECEIVE_CURRENT_ENGINE",
"SEARCH_STATE_REQUEST",
"SEARCH_STATE_RESPONSE",
"NOTIFY_MANAGE_ENGINES",
"NOTIFY_CYCLE_CURRENT_ENGINE",
"NOTIFY_ROUTE_CHANGE",
"NOTIFY_PERFORMANCE",
"NOTIFY_USER_EVENT"
Expand Down
13 changes: 13 additions & 0 deletions lib/ActivityStreams.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ ActivityStreams.prototype = {
SearchProvider.search.performSearch(browser, searchData);
});
break;
case am.type("NOTIFY_MANAGE_ENGINES"): // eslint-disable-line
let win = windowMediator.getMostRecentWindow("navigator:browser");
let gBrowser = win.getBrowser();
let browser = gBrowser.selectedBrowser;
SearchProvider.search.manageEngines(browser);
break;
case am.type("NOTIFY_CYCLE_CURRENT_ENGINE"):
SearchProvider.search.asyncCycleEngine(msg.data);
break;
}
},

Expand Down Expand Up @@ -249,6 +258,8 @@ ActivityStreams.prototype = {
this.on(am.type("NOTIFY_UNBLOCK_ALL"), this._respondToPlacesRequests);
this.on(am.type("NOTIFY_BOOKMARK_DELETE"), this._respondToPlacesRequests);
this.on(am.type("SEARCH_STATE_REQUEST"), this._respondToSearchRequests);
this.on(am.type("NOTIFY_MANAGE_ENGINES"), this._respondToSearchRequests);
this.on(am.type("NOTIFY_CYCLE_CURRENT_ENGINE"), this._respondToSearchRequests);
this.on(am.type("NOTIFY_PERFORM_SEARCH"), this._respondToSearchRequests);
this.on(am.type("NOTIFY_ROUTE_CHANGE"), this._onRouteChange);
this.on(am.type("NOTIFY_USER_EVENT"), this._handleUserEvent);
Expand Down Expand Up @@ -276,6 +287,8 @@ ActivityStreams.prototype = {
this.off(am.type("NOTIFY_UNBLOCK_ALL"), this._respondToPlacesRequests);
this.off(am.type("NOTIFY_BOOKMARK_DELETE"), this._respondToPlacesRequests);
this.off(am.type("SEARCH_STATE_REQUEST"), this._respondToSearchRequests);
this.off(am.type("NOTIFY_MANAGE_ENGINES"), this._respondToSearchRequests);
this.off(am.type("NOTIFY_CYCLE_CURRENT_ENGINE"), this._respondToSearchRequests);
this.off(am.type("NOTIFY_PERFORM_SEARCH"), this._respondToSearchRequests);
this.off(am.type("NOTIFY_ROUTE_CHANGE"), this._onRouteChange);
this.off(am.type("NOTIFY_USER_EVENT"), this._handleUserEvent);
Expand Down
12 changes: 12 additions & 0 deletions lib/SearchProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ NewTabSearchProvider.prototype = {
}.bind(this));
},

manageEngines(browser) {
const browserWindow = browser.ownerDocument.defaultView;
browserWindow.openPreferences("paneSearch");
},

asyncCycleEngine: Task.async(function*(engineName) {
Services.search.currentEngine = Services.search.getEngineByName(engineName);
let state = yield this.state;
let newEngine = state.currentEngine;
this.emit("CURRENT_ENGINE", newEngine);
}),

performSearch(browser, searchData) {
ContentSearch._onMessageSearch({target: browser}, searchData);
},
Expand Down

0 comments on commit fcc55d0

Please sign in to comment.