From 210775829d017952a4f3262509044309e8ea6223 Mon Sep 17 00:00:00 2001 From: Jim Mathies Date: Wed, 4 Dec 2013 05:46:10 -0600 Subject: [PATCH] Bug 941292 - Add search provider options flyout. r=sfoster --- browser/metro/base/content/browser.xul | 6 ++ .../content/flyoutpanels/FlyoutPanelsUI.js | 1 + .../content/flyoutpanels/SearchFlyoutPanel.js | 60 +++++++++++++++++++ .../content/flyoutpanels/SettingsCharm.js | 9 +++ browser/metro/base/jar.mn | 1 + .../locales/en-US/chrome/browser.properties | 1 + .../locales/en-US/chrome/searchPanel.dtd | 7 +++ browser/metro/locales/jar.mn | 1 + 8 files changed, 86 insertions(+) create mode 100644 browser/metro/base/content/flyoutpanels/SearchFlyoutPanel.js create mode 100644 browser/metro/locales/en-US/chrome/searchPanel.dtd diff --git a/browser/metro/base/content/browser.xul b/browser/metro/base/content/browser.xul index 9fa81ee6267..6e419b02ff1 100644 --- a/browser/metro/base/content/browser.xul +++ b/browser/metro/base/content/browser.xul @@ -21,6 +21,8 @@ %prefsDTD; %aboutPanelDTD; + +%searchPanelDTD; #ifdef MOZ_SERVICES_SYNC %syncBrandDTD; @@ -686,6 +688,10 @@ Desktop browser's sync prefs. + + + + diff --git a/browser/metro/base/content/flyoutpanels/FlyoutPanelsUI.js b/browser/metro/base/content/flyoutpanels/FlyoutPanelsUI.js index 0beb5657e10..7eccd1ae915 100644 --- a/browser/metro/base/content/flyoutpanels/FlyoutPanelsUI.js +++ b/browser/metro/base/content/flyoutpanels/FlyoutPanelsUI.js @@ -22,6 +22,7 @@ let FlyoutPanelsUI = { [ ['AboutFlyoutPanel', 'chrome://browser/content/flyoutpanels/AboutFlyoutPanel.js'], ['PrefsFlyoutPanel', 'chrome://browser/content/flyoutpanels/PrefsFlyoutPanel.js'], + ['SearchFlyoutPanel', 'chrome://browser/content/flyoutpanels/SearchFlyoutPanel.js'], #ifdef MOZ_SERVICES_SYNC ['SyncFlyoutPanel', 'chrome://browser/content/flyoutpanels/SyncFlyoutPanel.js'], #endif diff --git a/browser/metro/base/content/flyoutpanels/SearchFlyoutPanel.js b/browser/metro/base/content/flyoutpanels/SearchFlyoutPanel.js new file mode 100644 index 00000000000..c46b4c8430e --- /dev/null +++ b/browser/metro/base/content/flyoutpanels/SearchFlyoutPanel.js @@ -0,0 +1,60 @@ +// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*- +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +Components.utils.import("resource://gre/modules/Services.jsm"); + +const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; + +let SearchFlyoutPanel = { + _isInitialized: false, + _hasShown: false, + init: function pv_init() { + if (this._isInitialized) { + Cu.reportError("Attempting to re-initialize PreferencesPanelView"); + return; + } + this._topmostElement = document.getElementById("search-flyoutpanel"); + this._isInitialized = true; + }, + + checked: function checked(aId) { + aId = aId.replace("search-", ""); + Services.search.defaultEngine = this._engines[parseInt(aId)]; + this.updateSearchEngines(); + }, + + updateSearchEngines: function () { + // Clear the list + let setting = document.getElementById("search-options"); + while(setting.hasChildNodes()) { + setting.removeChild(setting.firstChild); + } + + // Build up the list and check the default + this._engines = Services.search.getVisibleEngines(); + let defaultEngine = Services.search.defaultEngine; + + this._engines.forEach(function (aEngine, aIndex) { + let radio = document.createElementNS(XUL_NS, "radio"); + radio.setAttribute("id", "search-" + aIndex); + radio.setAttribute("label", aEngine.name); + radio.setAttribute("oncommand", "FlyoutPanelsUI.SearchFlyoutPanel.checked(this.id)"); + if (defaultEngine == aEngine) { + radio.setAttribute("selected", true); + } + setting.appendChild(radio); + }.bind(this)); + }, + + _show: function() { + if (!this._hasShown) { + this._hasShown = true; + this.updateSearchEngines(); + } + this._topmostElement.show(); + } +}; diff --git a/browser/metro/base/content/flyoutpanels/SettingsCharm.js b/browser/metro/base/content/flyoutpanels/SettingsCharm.js index f42451d7a22..7a6a9ad7984 100644 --- a/browser/metro/base/content/flyoutpanels/SettingsCharm.js +++ b/browser/metro/base/content/flyoutpanels/SettingsCharm.js @@ -29,6 +29,13 @@ var SettingsCharm = { label: Strings.browser.GetStringFromName("optionsCharm"), onselected: function() FlyoutPanelsUI.show('PrefsFlyoutPanel') }); + + // Search providers + this.addEntry({ + label: Strings.browser.GetStringFromName("searchCharm"), + onselected: function() FlyoutPanelsUI.show('SearchFlyoutPanel') + }); + /* * Temporarily disabled until we can have sync prefs together with the * Desktop browser's sync prefs. @@ -38,11 +45,13 @@ var SettingsCharm = { onselected: function() FlyoutPanelsUI.show('SyncFlyoutPanel') }); */ + // About this.addEntry({ label: Strings.browser.GetStringFromName("aboutCharm1"), onselected: function() FlyoutPanelsUI.show('AboutFlyoutPanel') }); + // Help this.addEntry({ label: Strings.browser.GetStringFromName("helpOnlineCharm"), diff --git a/browser/metro/base/jar.mn b/browser/metro/base/jar.mn index 915046df5da..72b7c1f0638 100644 --- a/browser/metro/base/jar.mn +++ b/browser/metro/base/jar.mn @@ -34,6 +34,7 @@ chrome.jar: * content/flyoutpanels/FlyoutPanelsUI.js (content/flyoutpanels/FlyoutPanelsUI.js) * content/flyoutpanels/AboutFlyoutPanel.js (content/flyoutpanels/AboutFlyoutPanel.js) content/flyoutpanels/PrefsFlyoutPanel.js (content/flyoutpanels/PrefsFlyoutPanel.js) + content/flyoutpanels/SearchFlyoutPanel.js (content/flyoutpanels/SearchFlyoutPanel.js) #ifdef MOZ_SERVICES_SYNC content/flyoutpanels/SyncFlyoutPanel.js (content/flyoutpanels/SyncFlyoutPanel.js) #endif diff --git a/browser/metro/locales/en-US/chrome/browser.properties b/browser/metro/locales/en-US/chrome/browser.properties index 20be5bc2d65..176fff7a4d3 100644 --- a/browser/metro/locales/en-US/chrome/browser.properties +++ b/browser/metro/locales/en-US/chrome/browser.properties @@ -44,6 +44,7 @@ clearPrivateData.message=Clear your private data? # Settings Charms aboutCharm1=About optionsCharm=Options +searchCharm=Search helpOnlineCharm=Help (online) # General diff --git a/browser/metro/locales/en-US/chrome/searchPanel.dtd b/browser/metro/locales/en-US/chrome/searchPanel.dtd new file mode 100644 index 00000000000..b0d80ccbe9e --- /dev/null +++ b/browser/metro/locales/en-US/chrome/searchPanel.dtd @@ -0,0 +1,7 @@ + + + + + diff --git a/browser/metro/locales/jar.mn b/browser/metro/locales/jar.mn index 626fe1789a2..0aed0c2a189 100644 --- a/browser/metro/locales/jar.mn +++ b/browser/metro/locales/jar.mn @@ -16,6 +16,7 @@ locale/browser/config.dtd (%chrome/config.dtd) locale/browser/preferences.dtd (%chrome/preferences.dtd) locale/browser/aboutPanel.dtd (%chrome/aboutPanel.dtd) + locale/browser/searchPanel.dtd (%chrome/searchPanel.dtd) locale/browser/checkbox.dtd (%chrome/checkbox.dtd) locale/browser/sync.dtd (%chrome/sync.dtd) locale/browser/sync.properties (%chrome/sync.properties)