michael@0: // -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*- michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: Components.utils.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; michael@0: michael@0: let SearchFlyoutPanel = { michael@0: _isInitialized: false, michael@0: _hasShown: false, michael@0: init: function pv_init() { michael@0: if (this._isInitialized) { michael@0: Cu.reportError("Attempting to re-initialize PreferencesPanelView"); michael@0: return; michael@0: } michael@0: this._topmostElement = document.getElementById("search-flyoutpanel"); michael@0: this._isInitialized = true; michael@0: }, michael@0: michael@0: checked: function checked(aId) { michael@0: aId = aId.replace("search-", ""); michael@0: Services.search.defaultEngine = this._engines[parseInt(aId)]; michael@0: this.updateSearchEngines(); michael@0: }, michael@0: michael@0: updateSearchEngines: function () { michael@0: // Clear the list michael@0: let setting = document.getElementById("search-options"); michael@0: while(setting.hasChildNodes()) { michael@0: setting.removeChild(setting.firstChild); michael@0: } michael@0: michael@0: // Build up the list and check the default michael@0: this._engines = Services.search.getVisibleEngines(); michael@0: let defaultEngine = Services.search.defaultEngine; michael@0: michael@0: this._engines.forEach(function (aEngine, aIndex) { michael@0: let radio = document.createElementNS(XUL_NS, "radio"); michael@0: radio.setAttribute("id", "search-" + aIndex); michael@0: radio.setAttribute("label", aEngine.name); michael@0: radio.setAttribute("oncommand", "FlyoutPanelsUI.SearchFlyoutPanel.checked(this.id)"); michael@0: if (defaultEngine == aEngine) { michael@0: radio.setAttribute("selected", true); michael@0: } michael@0: setting.appendChild(radio); michael@0: }.bind(this)); michael@0: }, michael@0: michael@0: _show: function() { michael@0: if (!this._hasShown) { michael@0: this._hasShown = true; michael@0: this.updateSearchEngines(); michael@0: } michael@0: this._topmostElement.show(); michael@0: } michael@0: };