home *** CD-ROM | disk | FTP | other *** search
Text File | 2010-07-12 | 55.4 KB | 1,609 lines |
- const APP_NAME = "yasearch";
-
- const { classes: Cc, interfaces: Ci, utils: Cu, Constructor: CC } = Components;
-
- var DOMUtils = {
- evaluateXPath: function DOMUtils_evaluateXPath(aNode, aExpr) {
- function nsResolver(aPrefix) {
- const ns = {
- "xul": "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
- "xhtml": "http://www.w3.org/1999/xhtml"
- };
-
- return ns[aPrefix] || null;
- }
-
- let xpEvaluator = Cc["@mozilla.org/dom/xpath-evaluator;1"].getService(Ci.nsIDOMXPathEvaluator);
- let xpathResult = xpEvaluator.evaluate(aExpr, aNode, nsResolver,
- Ci.nsIDOMXPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
- let nextElement,
- result = [];
-
- while ((nextElement = xpathResult.iterateNext()))
- result.push(nextElement);
-
- return result;
- }
- };
-
- var SettingsProxy = {
- _valuesHash: {},
-
- clear: function SettingsProxy_clear() {
- this._valuesHash = {};
- },
-
- remember: function SettingsProxy_remember(settingNode, value) {
- this._valuesHash[settingNode.effectiveID] = {node: settingNode, value: value};
- },
-
- recall: function SettingsProxy_recall(settingNode) {
- var info = this._valuesHash[settingNode.effectiveID];
- if (info)
- return info.value;
- },
-
- recallAll: function SettingsProxy_recallAll() {
- var ret = [];
- for each (let info in this._valuesHash)
- ret.push(info);
- return ret;
- },
-
- resetAll: function SettingsProxy_resetAll() {
- try {
- Preferences.barCore.Preferences.resetBranch(APP_NAME + ".xbwidgets.");
- } catch (ex) {}
- }
- };
-
- function WidgetProxy(aProtoId) {
- this._id = aProtoId;
- this.isXbWidget = true;
-
- this._init();
- }
-
- WidgetProxy.prototype = {
- _init: function WidgetProxy__init() {
- if (StaticWidgets.hasWidget(this._id)) {
- let widget = StaticWidgets.getWidget(this._id);
- this.isXbWidget = false;
- this.iconURL = widget.iconURL;
- this.isUnique = widget.isUnique;
- this.isRemovable = false;
- this._id = widget.protoId;
- this.protoId = widget.protoId;
- this.name = widget.name;
- } else {
- let proto = this.proto;
- this.iconURL = proto.unit.unitPackage.resolvePath(proto.iconPath);
- this.isUnique = proto.isUnique;
- this.isRemovable = !Preferences.barCore.application.isPreinstalledWidget(proto.id);
- this.protoId = proto.id;
- this.name = proto.name;
- }
- },
-
- get proto() {
- return Preferences.barCore.application.widgetLibrary.getWidgetProto(this._id);
- },
-
- get id() {
- return this._id;
- }
- };
-
- function WidgetInstProxy(aInstanceID) {
- this.isXbWidget = true;
-
- this._id = aInstanceID;
- this._preferenceIDs = [];
-
- this._init();
- }
-
- WidgetInstProxy.prototype = {
- _init: function WidgetInstProxy__init() {
- if (StaticWidgets.hasWidget(this._id)) {
- let widget = StaticWidgets.getWidget(this._id);
- this.isXbWidget = false;
- this.iconURL = widget.iconURL;
- this.isUnique = widget.isUnique;
- this.isRemovable = false;
- this.protoId = widget.protoId;
- this.instanceID = this._id;
- this.name = widget.name;
- this.xulDocument = widget.xulDocument;
- this._preferenceIDs = widget.preferenceIDs;
- } else {
- let xbWidget = this.xbWidget;
- let proto = xbWidget.prototype;
- this.iconURL = proto.unit.unitPackage.resolvePath(proto.iconPath);
- this.isUnique = proto.isUnique;
- this.isRemovable = false;
- this.protoId = proto.id;
- this.instanceID = this.widgetInfo.instanceID;
- this.name = proto.name;
- }
- },
-
- makeURL: function WidgetInstProxy_makeURL(aSpec) {
- let spec = /^https?:\/\//.test(aSpec) ? aSpec : this.unitPackage.resolvePath(aSpec);
- let uri = spec ? Preferences.barCore.Lib.sysutils.createFixupURIFromString(spec) : null;
-
- if (!(uri && /^(https?|xb)$/.test(uri.scheme) && uri.spec))
- return "";
-
- return uri.spec;
- },
-
- get id() {
- return this._id;
- },
-
- get widgetInfo() {
- return Preferences.overlayProvider.parseWidgetItemId(this._id);
- },
-
- get xbWidget() {
- return Preferences._wndEngine.getWidget(this.widgetInfo.instanceID);
- },
-
- get unitPackage() {
- return this.xbWidget.prototype.unit.unitPackage;
- },
-
- get protoSettings() {
- return this.xbWidget.prototype.settings;
- },
-
- get instSettings() {
- return this.xbWidget.settings;
- },
-
- updatePreferenceNodes: function WidgetInstProxy_updatePreferenceNodes() {
- this._preferenceIDs.forEach(function(aID) {
- let prefNode = document.getElementById(aID);
- if (prefNode)
- prefNode.updateElements();
- });
- }
- };
-
- var RegisteredWidgets = {
- _widgets: [],
-
- push: function RegisteredWidgets_push(aProtoID, aBeforeID) {
- let widget = new WidgetProxy(aProtoID);
- this._widgets.push(widget);
-
- return RegisteredWidgetsController.insertItem(widget, aBeforeID);
- },
-
- get: function RegisteredWidgets_get(aProtoID) {
- return this._widgets.filter(function(wp) wp.id == aProtoID)[0];
- },
-
- remove: function RegisteredWidgets_remove(aProtoID) {
- let widgets = this._widgets;
- for (let i = 0, len = widgets.length; i < len; i++) {
- if (widgets[i].id == aProtoID)
- return widgets.splice(i, 1)[0];
- }
- }
- };
-
- var ActiveWidgets = {
- _widgets: [],
-
- push: function ActiveWidgets_push(aInstanceID, aBeforeID) {
- let widget = new WidgetInstProxy(aInstanceID);
- this._widgets.push(widget);
-
- return ActiveWidgetsController.insertItem(widget, aBeforeID);
- },
-
- get: function ActiveWidgets_get(aInstanceID) {
- return this._widgets.filter(function(wp) (wp.id == aInstanceID || wp.instanceID == aInstanceID))[0];
- },
-
- remove: function ActiveWidgets_remove(aInstanceID) {
- let widgets = this._widgets;
- for (let i = 0, len = widgets.length; i < len; i++) {
- if (widgets[i].id == aInstanceID)
- return widgets.splice(i, 1)[0];
- }
- }
- };
-
- var StaticWidgets = {
- _specialIDs: {
- "proto": ["separator", "spacer", "spring"],
- "localNames": ["toolbarseparator", "toolbarspacer", "toolbarspring"],
- "names": {}
- },
-
- getSpecialID: function(aID) {
- let id = aID.replace(/(\d+)$/, "");
- if (this._specialIDs.proto.indexOf(id) > -1)
- return id;
-
- return null;
- },
-
- clear: function StaticWidgets_clear() {
- this._knowIDs = [];
- },
-
- _getItemFromDocumentOrPalette: function StaticWidgets__getItemFromDocumentOrPalette(aWidgetID) {
- return Preferences.getItemFromDocumentOrPalette(aWidgetID);
- },
-
- init: function StaticWidgets_init() {
- this.clear();
-
- this._specialIDs.proto.forEach(function(name) {
- this[name] = Preferences.getString(name);
- }, this._specialIDs.names);
-
- let infoFile = this._staticDir;
- infoFile.append("info.json");
-
- if (infoFile.exists()) {
- let widgetsInfo = Preferences.barCore.JSON.parse(Preferences.barCore.Lib.sysutils.readTextFile(infoFile));
-
- widgetsInfo.forEach(function(aWidgetID) {
- if (this._getItemFromDocumentOrPalette(aWidgetID))
- this._knowIDs.push(aWidgetID);
- }, this);
- }
-
- let toolbarNodes = Array.slice(Preferences._setupWndCtrl._appToolbar.childNodes);
- for (let i = toolbarNodes.length; i-- > 0;) {
- if (this._specialIDs.localNames.indexOf(toolbarNodes[i].localName) > -1) {
- this._knowIDs.push(toolbarNodes[i].id);
- }
- }
- },
-
- get _staticDir() {
- let staticDir = Preferences.prefDir;
- staticDir.append("static-widgets");
- return staticDir;
- },
-
- _parseXULFile: function StaticWidgets__parseXULFile(aWidgetID) {
- let widgetXULFile = this._staticDir;
- widgetXULFile.append(aWidgetID + ".xul");
-
- let uri = Preferences._ioService.newURI(document.documentURI, null, null);
- let domParser = new Preferences._domParserConstructor(null, uri, uri);
-
- let xulDocument = null;
- try {
- xulDocument = domParser.parseFromString(Preferences.barCore.Lib.sysutils.readTextFile(widgetXULFile), "text/xml");
- if (xulDocument.documentElement.localName != "widget")
- throw new Error("Wrong static widget structure.");
- } catch (ex) {}
-
- return xulDocument;
- },
-
- _knowIDs: [],
-
- get knownIDs() {
- return this._knowIDs;
- },
-
- get knownProtoIDs() {
- return this._knowIDs
- .filter(function(id) !this.getSpecialID(id), this)
- .concat(this._specialIDs.proto);
- },
-
- hasWidget: function StaticWidgets_hasWidget(aWidgetID) {
- return this.getSpecialID(aWidgetID) || (this.knownIDs.indexOf(aWidgetID) != -1);
- },
-
- getWidget: function StaticWidgets_getWidget(aWidgetID) {
- let xulDocument,
- name,
- iconURL = "",
- isUnique = true,
- preferenceIDs = [];
-
- if (this.getSpecialID(aWidgetID)) {
- aWidgetID = this.getSpecialID(aWidgetID);
- name = this._specialIDs.names[aWidgetID] || "widget";
- isUnique = false;
- } else {
- xulDocument = this._parseXULFile(aWidgetID);
-
- let widgetElement = xulDocument.documentElement;
- name = widgetElement.getAttribute("name") || aWidgetID;
- iconURL = widgetElement.getAttribute("icon") || "";
-
- if (iconURL && /^images\//.test(iconURL))
- iconURL = [Preferences.prefDirChrome, "static-widgets", iconURL].join("/");
-
- if (!iconURL) {
- let widgetElement = this._getItemFromDocumentOrPalette(aWidgetID);
- if (widgetElement)
- iconURL = widgetElement.getAttribute("image") || "";
- }
-
- preferenceIDs = this._createPreferencesNodes(xulDocument);
- }
-
- return {
- protoId: aWidgetID + "-proto",
- iconURL: iconURL,
- isUnique: isUnique,
- name: name,
- xulDocument: xulDocument,
- preferenceIDs: preferenceIDs
- };
- },
-
- _createPreferencesNodes: function StaticWidgets__createPreferencesNodes(aXULDocument) {
- let preferenceIDs = [];
- let docFrag = document.createDocumentFragment();
-
- let prefNodes = aXULDocument.getElementsByTagName("preference");
- for (let i = prefNodes.length; i--;) {
- let id = prefNodes[i].id;
- if (id) {
- preferenceIDs.push(id);
- if (!(document.getElementById(id)))
- docFrag.appendChild(prefNodes[i]);
- }
- }
-
- if (docFrag.childNodes.length)
- document.documentElement.currentPane.getElementsByTagName("preferences")[0].appendChild(docFrag);
-
- return preferenceIDs;
- }
- };
-
- var Preferences = {
- get JSON() {
- return this.barCore.JSON;
- },
-
- barCore: Cc["@yandex.ru/custombarcore;" + APP_NAME].getService().wrappedJSObject,
-
- _domParserConstructor: new CC("@mozilla.org/xmlextras/domparser;1", "nsIDOMParser", "init"),
- _ioService: Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService),
-
- _setupWndCtrl: null,
- _wndEngine: null,
-
- _restoreInfo: {
- currentset: {},
- collapsed: null
- },
-
- _initPane: function Preferences__initPane(aPaneID) {
- let paneElement = document.getElementById(aPaneID);
- if (!paneElement)
- return;
-
- if (document.documentElement.currentPane != paneElement)
- document.documentElement.showPane(paneElement);
-
- if (paneElement.getAttribute("xb-pane-ready") == "true")
- return;
-
- switch (aPaneID) {
- case "prefpane-customize":
- setTimeout(function() Preferences._initPrefPane(), 0);
-
- break;
-
- case "prefpane-misc":
- YaSearchPrefs.onPaneLoad();
- break;
- }
-
- paneElement.setAttribute("xb-pane-ready", "true");
- },
-
- _prefsInited: false,
-
- _initPrefPane: function Preferences__initPrefPane() {
- if (this._prefsInited)
- return;
-
- this._prefsInited = true;
-
- this._logger = this.barCore.Log4Moz.repository.getLogger(APP_NAME + ".Preferences");
- this._logger.trace("Init");
-
- this._setupWndCtrl = this.gBrowser[APP_NAME + "OverlayController"];
- this._wndEngine = this._setupWndCtrl.windowEngine;
- this.overlayProvider = this.barCore.application.overlayProvider;
-
- this._fillWidgetsLists();
-
- StaticHelper.onPaneLoad();
-
- this._rememberToolbarsCurrentSet();
-
- let toolbar = this._setupWndCtrl._appToolbar;
- this._restoreInfo.collapsed = toolbar.collapsed;
- toolbar.collapsed = false;
- toolbar.onToolbarCustomize(true);
-
- document.documentElement.setAttribute("buttondisabledextra2", "false");
- },
-
- selectWidget: function Preferences_selectWidget(aInstanceID) {
- if (this._prefsInited) {
- let widget = ActiveWidgets.get(aInstanceID);
- if (widget)
- ActiveWidgetsController.selectItem(widget);
-
- } else {
- this._initPane("prefpane-customize");
-
- window.setTimeout(function(me, instanceID) {
- if (me && me._prefsInited)
- me.selectWidget(instanceID);
- }, 0, this, aInstanceID);
- }
- },
-
- _fillWidgetsLists: function Preferences__fillWidgetsLists() {
- RegisteredWidgetsController.init();
- ActiveWidgetsController.init();
- StaticWidgets.init();
-
- StaticWidgets.knownProtoIDs.forEach(function(aStaticID)
- RegisteredWidgets.push(aStaticID));
-
- var knownIDs = this.barCore.application.widgetLibrary.getWidgetProtoIDs();
- for each (let protoID in knownIDs) {
- try {
- RegisteredWidgets.push(protoID);
- }
- catch (e) {
- this._logger.error("Failed in Preferences__fillWidgetsLists. " + this.barCore.Lib.misc.formatError(e));
- this._logger.debug(e.stack);
- }
- }
-
- this.getAllWidgetItems().forEach(function(aToolbarItem)
- ActiveWidgets.push(aToolbarItem.id));
- },
-
- _finalize: function Preferences__finalize() {
- this._setupWndCtrl._appToolbar.onToolbarCustomize(false);
-
- this._logger.trace("Finalize");
-
- RegisteredWidgetsController.finalize();
- ActiveWidgetsController.finalize();
-
- this.overlayProvider = null;
- this._wndEngine = null;
- this._setupWndCtrl = null;
- this._logger = null;
-
- this._prefDir = null;
- },
-
- get instantApply() {
- delete this.instantApply;
- return (this.instantApply = document.documentElement.instantApply);
- },
-
- _accepted: false,
-
- beforeAccept: function Preferences_beforeAccept() {
- try {
- if (!this._accepted) {
- this._apply();
- this._accepted = true;
- }
- }
- catch (e) {
- this._logger.error("Could not apply changes. " + this.barCore.Lib.misc.formatError(e));
- this._logger.debug(e.stack);
- }
-
- return true;
- },
-
- beforeUnload: function Preferences_beforeUnload() {
- StaticHelper.onWindowBeforeUnload();
-
- try {
- if (this._gBrowser)
- this._gBrowser.removeEventListener("unload", this, false);
- } catch (ex) {}
-
- if (!this._prefsInited)
- return;
-
- try {
- if (this.instantApply)
- this.beforeAccept();
-
- if (!this._accepted)
- this._cancel();
-
- this._finalize();
- }
- catch (e) {
- this._logger.error("Failed in Preferences_beforeUnload. " + this.barCore.Lib.misc.formatError(e));
- }
- },
-
- _apply: function Preferences__apply() {
- YaSearchPrefs.onDialogAccept();
-
- if (!this._prefsInited)
- return;
-
- this._logger.debug("Applying");
-
- this.getAllWidgetItems().forEach(function(aToolbarItem) {
- try {
- let customizeState = aToolbarItem.getAttribute("xb-customize");
- if (customizeState) {
- aToolbarItem.removeAttribute("xb-customize");
-
- if (customizeState == "removed") {
- this.barCore.application.forEachWindow(
- function(controller) {
- try {
- controller.removeItemById(aToolbarItem.id, true);
- } catch (e) {
- this._logger.error(this.barCore.Lib.misc.formatError(e));
- this._logger.debug(e.stack);
- }
- }, this);
- }
- }
-
- } catch (ex) {
- this._logger.error(ex);
- }
-
- }, this);
-
- for each (let info in SettingsProxy.recallAll())
- info.node.setValue(info.value);
-
- SettingsProxy.clear();
-
- if (this._restoreInfo.collapsed) {
- let toolbar = this._setupWndCtrl._appToolbar;
-
- if (this._restoreInfo.currentset[toolbar.id] != toolbar.currentSet) {
- toolbar.collapsed = false;
- toolbar.ownerDocument.persist(toolbar.id, "collapsed");
- this._restoreInfo.collapsed = false;
- } else {
- toolbar.collapsed = this._restoreInfo.collapsed;
- }
- }
-
- this._persistToolbarsSet();
- },
-
- _cancel: function Preferences__cancel() {
- this._logger.debug("Reverting");
-
- this._restoreToolbarsCurrentSet();
- },
-
- restoreDefault: function Preferences_restoreDefault() {
- if (!this._getUserConfirm(this.getString("PreferencesTitle"), this.getString("RestoreDefaultSet")))
- return;
-
- const UNDEF = undefined;
- let prefNodes = document.getElementsByTagName("preference");
- for (let i = prefNodes.length; i--;) {
- try {
- prefNodes[i].valueFromPreferences = UNDEF;
- } catch (ex) {}
- }
-
- let items = this.getAllWidgetItems();
- for (let i = items.length; i-- > 0;) {
- let item = items[i];
-
- if (item.hasAttribute("xb-customize"))
- item.removeAttribute("xb-customize");
-
- this._setupWndCtrl.removeItem(item, true);
- }
-
- SettingsProxy.resetAll();
-
- let toolbar = this._setupWndCtrl._appToolbar;
- let defaultset = toolbar.getAttribute("defaultset");
- toolbar.currentSet = defaultset;
-
- if (toolbar.collapsed) {
- toolbar.collapsed = false;
- toolbar.ownerDocument.persist(toolbar.id, "collapsed");
- this._restoreInfo.collapsed = false;
- }
-
- this._persistToolbarsSet();
-
- SettingsProxy.clear();
-
- StaticHelper.onRestoreDefault();
-
- this._fillWidgetsLists();
-
- this._rememberToolbarsCurrentSet();
- },
-
- _getToolbarsCurrentSet: function Preferences__getToolbarsCurrentSet() {
- let toolbarsCurrentset = {};
-
- let toolbars = this._setupWndCtrl._toolbox.getElementsByTagName("toolbar");
-
- for (let i = toolbars.length; i-- > 0;) {
- let toolbar = toolbars[i];
- let id = toolbar.id;
- if (!id)
- continue;
-
- toolbarsCurrentset[id] = toolbar.currentSet;
- }
-
- return toolbarsCurrentset;
- },
-
- _rememberToolbarsCurrentSet: function Preferences__rememberToolbarsCurrentSet() {
- this._restoreInfo.currentset = this._getToolbarsCurrentSet();
- },
-
- _restoreToolbarsCurrentSet: function Preferences__restoreToolbarsCurrentSet() {
- this._checkModifiedToolbaritemsOnRestore();
-
- let toolbox = this._setupWndCtrl._toolbox;
- let toolbarsRememberedInfo = this._restoreInfo.currentset;
-
- for (let [toolbarId, toolbarInfo] in Iterator(this._getToolbarsCurrentSet())) {
- let prevCurrenset = toolbarsRememberedInfo[toolbarId];
- if (!prevCurrenset)
- continue;
-
- let toolbar = toolbox.getElementsByAttribute("id", toolbarId).item(0);
- if (!toolbar)
- continue;
-
- if (prevCurrenset !== toolbar.currentSet) {
- let restoredSet = prevCurrenset || toolbar.getAttribute("defaultset") || "";
- Preferences._logger.trace(["Restored currentset for #" + toolbarId, restoredSet].join("\n"));
-
- toolbar.currentSet = restoredSet;
- toolbar.ownerDocument.persist(toolbarId, "currentset");
- }
- }
-
- this._rememberToolbarsCurrentSet();
- },
-
- _checkModifiedToolbaritemsOnRestore: function Preferences__checkModifiedToolbaritemsOnRestore() {
- let xpathString = ["//xul:*[@xb-customize='removed']",
- "//xul:*[@xb-customize='added']"]
- .join("|");
-
- let setupWndCtrl = this._setupWndCtrl;
-
- let items = DOMUtils.evaluateXPath(setupWndCtrl._toolbox, xpathString);
- for (let i = items.length; i-- > 0;) {
- let item = items[i];
- try {
- if (item.getAttribute("xb-customize") == "added")
- setupWndCtrl.removeItem(item, true);
-
- item.removeAttribute("xb-customize");
- } catch(e) {}
- }
- },
-
- _getSiblingNode: function(aNode, aDirection) {
- let directionProp = aDirection + "Sibling";
- let node = aNode[directionProp];
-
- while (node && node.getAttribute("xb-customize") == "removed")//invisible items
- node = node[directionProp];
-
- return node;
- },
-
- _getChildNode: function(aParent, aType) {
- let node = aType == "first" ? aParent.firstChild : aParent.lastChild;
-
- if (node && node.getAttribute("xb-customize") == "removed")
- node = this._getSiblingNode(node, aType == "first" ? "next" : "previous");
-
- return node;
- },
-
- _getFirstChild: function(aParent) {
- return this._getChildNode(aParent, "first");
- },
-
- _getLastChild: function(aParent) {
- return this._getChildNode(aParent, "last");
- },
-
- _checkControlsTimeout: null,
-
- checkControls: function Preferences_checkControls() {
- if (this._checkControlsTimeout)
- window.clearTimeout(this._checkControlsTimeout);
-
- this._checkControlsTimeout = setTimeout(function(me) {
- if (me && "_checkControls" in me)
- me._checkControls();
- }, 0, this);
- },
-
- _checkControls: function Preferences__checkControls() {
- let canAddWidgets = !!RegisteredWidgetsController.list.selectedCount;
- document.getElementById("canAddWidgetsBroadcaster").setAttribute("disabled", !canAddWidgets);
-
- let canDeleteWidgets = false;
-
- let focusedElement = document.commandDispatcher.focusedElement;
-
- if (!focusedElement || focusedElement != ActiveWidgetsController.list) {
- let selectedItems = Array.slice(RegisteredWidgetsController.list.selectedItems);
- canDeleteWidgets = !!selectedItems.some(function(aItem) aItem.isRemovable);
- }
-
- document.getElementById("canDeleteWidgetsBroadcaster").setAttribute("disabled", !canDeleteWidgets);
-
- let activeList = ActiveWidgetsController.list;
-
- let canRemoveWidgets = !!activeList.selectedCount;
- document.getElementById("canRemoveWidgetsBroadcaster").setAttribute("disabled", !canRemoveWidgets);
-
- let canMoveUp = canRemoveWidgets,
- canMoveDown = canRemoveWidgets;
-
- if (canRemoveWidgets) {
- let itemCount = activeList.itemCount;
- let selectedCount = activeList.selectedCount;
- let selectedItems = activeList.selectedItemsSorted;
-
- let firstSelectedItem = selectedItems[0];
- let lastSelectedItem = selectedItems[selectedCount-1];
-
- let appToolbar = this._setupWndCtrl._appToolbar;
-
- let firstToolbaritem = this.gDocument.getElementById(firstSelectedItem.id);
- let firstToolbar = firstToolbaritem.parentNode;
-
- if (firstToolbar == appToolbar && firstToolbaritem == this._getFirstChild(firstToolbar)) {
- canMoveUp = false;
-
- let i = 0;
- let nextToolbaritem = firstToolbaritem;
-
- while (++i < selectedCount && (nextToolbaritem = this._getSiblingNode(nextToolbaritem, "next"))) {
- if (nextToolbaritem.id != selectedItems[i].id) {
- canMoveUp = true;
- break;
- }
- }
- }
-
- let lastToolbaritem = this.gDocument.getElementById(lastSelectedItem.id);
- let lastToolbar = lastToolbaritem.parentNode;
-
- if (lastToolbar == appToolbar && lastToolbaritem == this._getLastChild(lastToolbar)) {
- canMoveDown = false;
-
- let i = selectedCount - 1;
- let previousToolbaritem = lastToolbaritem;
-
- while (--i >= 0 && (previousToolbaritem = this._getSiblingNode(previousToolbaritem, "previous"))) {
- if (previousToolbaritem.id != selectedItems[i].id) {
- canMoveDown = true;
- break;
- }
- }
- }
- }
-
- document.getElementById("canMoveWidgetsUpBroadcaster").setAttribute("disabled", !canMoveUp);
- document.getElementById("canMoveWidgetsDownBroadcaster").setAttribute("disabled", !canMoveDown);
- },
-
- selectAll: function Preferences_selectAll() {
- let focusedElement = document.commandDispatcher.focusedElement;
- if (focusedElement && focusedElement.localName == "richlistbox") {
- if ("expandItem" in focusedElement && focusedElement.currentItem)
- focusedElement.expandItem(null);
-
- focusedElement.selectAll();
- }
- },
-
- addWidgets: function Preferences_addWidgets(aNodeBefore) {
- let selectedItems = Array.slice(RegisteredWidgetsController.list.selectedItems);
- let beforeId = aNodeBefore ? aNodeBefore.id : null;
-
- let addedItems = [];
- for (let i = 0, len = selectedItems.length; i < len; i++) {
- let addedItem = this._addWidget(selectedItems[i], beforeId);
-
- if (addedItem)
- addedItems.push(addedItem);
- }
-
- let addedLength = addedItems.length;
- if (addedLength) {
- let firstSelectedItem = addedItems[0];
- let lastSelectedItem = addedItems[addedLength-1];
-
- let activeList = ActiveWidgetsController.list;
- activeList.selectItemRange(firstSelectedItem, lastSelectedItem);
-
- if (addedLength == 1) {
- firstSelectedItem.click();
- } else {
- activeList.ensureElementIsVisible(lastSelectedItem);
- activeList.ensureElementIsVisible(firstSelectedItem);
- }
- }
- },
-
- _addWidget: function Preferences__addWidget(aListItem, aBeforeId) {
- let widget = RegisteredWidgets.get(aListItem.id);
-
- let beforeElement = aBeforeId ? this.gDocument.getElementById(aBeforeId) : null;
-
- let toolbaritem;
- let widgetProtoId = widget.protoId;
-
- if (widget.isXbWidget) {
- if (widget.isUnique) {
- let allWidgetItems = this.getAllWidgetItems();
- for (let i = allWidgetItems.length; i-- > 0;) {
- let existToolbaritem = allWidgetItems[i];
- try {
- if (existToolbaritem.getAttribute("xb-customize") == "removed" &&
- existToolbaritem.prototypeID === widgetProtoId)
- {
- toolbaritem = existToolbaritem;
- break;
- }
- } catch (ex) {}
- }
-
- if (toolbaritem) {
- let toolbar = this._setupWndCtrl._appToolbar;
- toolbaritem = beforeElement ? toolbar.insertBefore(toolbaritem, beforeElement)
- : toolbar.appendChild(toolbaritem);
- }
- }
-
- toolbaritem = toolbaritem || this._setupWndCtrl.addWidgetItem(widget.protoId, null, beforeElement, null, true);
-
- } else {
- let destToolbar = beforeElement ? beforeElement.parentNode : this._setupWndCtrl._appToolbar;
- toolbaritem = destToolbar.insertItem(widget.protoId.replace(/\-proto/, ""), beforeElement);
- }
-
- if (!toolbaritem)
- return;
-
- toolbaritem.setAttribute("xb-customize", "added");
-
- return ActiveWidgets.push(toolbaritem.id, aBeforeId);
- },
-
- removeWidgets: function Preferences_removeWidgets(aListItems, aRemovePermanently) {
- let itemsToRemove = typeof aListItems == "undefined"
- ? Array.slice(ActiveWidgetsController.list.selectedItems)
- : aListItems;
- if (!itemsToRemove)
- return;
-
- for (let i = itemsToRemove.length; i-- > 0;)
- this._removeWidget(itemsToRemove[i], aRemovePermanently);
- },
-
- _removeWidget: function Preferences__removeWidget(aListItem, aRemovePermanently) {
- let toolbaritemId = aListItem.id;
- let toolbaritem = this.gDocument.getElementById(toolbaritemId);
-
- if (toolbaritem) {
- if (aRemovePermanently)
- this._setupWndCtrl.removeItem(toolbaritem, true);
- else
- toolbaritem.setAttribute("xb-customize", "removed");
- }
-
- ActiveWidgetsController.removeItem(aListItem);
-
- let widget = ActiveWidgets.remove(toolbaritemId);
- RegisteredWidgetsController.checkWidgetUniqueState(widget.protoId, false);
- },
-
- moveWidgets: function Preferences_moveWidgets(aDirection, aRelativeElement) {
- let selectedItems = ActiveWidgetsController.list.selectedItemsSorted;
- if (!selectedItems)
- return;
-
- let placeAfter = !!(aDirection == "down"),
- len = selectedItems.length,
- selectedItem = placeAfter ? selectedItems[len-1] : selectedItems[0];
-
- let toolbaritem = this.gDocument.getElementById(selectedItem.id);
- if (!toolbaritem)
- return;
-
- let relativeElement;
-
- if (aDirection) {
- relativeElement = this._getSiblingNode(toolbaritem, aDirection == "up" ? "previous" : "next") || toolbaritem;
-
- let itemToolbar = toolbaritem.parentNode;
-
- if (toolbaritem == relativeElement || relativeElement == itemToolbar.lastChild) {
- let appToolbar = this._setupWndCtrl._appToolbar;
-
- if (itemToolbar != appToolbar && appToolbar.firstChild) {
- if ((aDirection == "down" && itemToolbar.lastChild == relativeElement) ||
- (aDirection == "up" && itemToolbar.firstChild == relativeElement))
- {
- relativeElement = aDirection == "down" ? appToolbar.firstChild : appToolbar.lastChild;
-
- aDirection = aDirection == "down" ? "up" : "down";
- placeAfter = !placeAfter;
- }
- }
- }
-
- } else if (aRelativeElement) {
- relativeElement = this.gDocument.getElementById(aRelativeElement.id);
- }
-
- ActiveWidgetsController.moveSelectedItems(aDirection, relativeElement ? relativeElement.id : null);
-
- relativeElement = placeAfter ? relativeElement.nextSibling : relativeElement;
-
- let toolbar = relativeElement ? relativeElement.parentNode : this._setupWndCtrl._appToolbar;
-
- let doc = toolbar.ownerDocument;
- let docFrag = doc.createDocumentFragment();
- let next = toolbaritem.nextSibling;
-
- selectedItems.forEach(function(aListItem) {
- let toolbaritem = doc.getElementById(aListItem.id);
- if (toolbaritem) {
- if (placeAfter && toolbaritem.nextSibling)
- next = toolbaritem.nextSibling;
-
- docFrag.appendChild(toolbaritem);
- }
- });
-
- if (relativeElement == toolbaritem && next)
- relativeElement = next;
-
- relativeElement ? toolbar.insertBefore(docFrag, relativeElement)
- : toolbar.appendChild(docFrag);
-
- this.checkControls();
-
- let selectedLen = selectedItems.length;
- let activeList = ActiveWidgetsController.list;
-
- if (selectedLen > 1)
- activeList.ensureElementIsVisible(selectedItems[selectedItems.length-1]);
-
- activeList.ensureElementIsVisible(selectedItems[0]);
- },
-
- deleteWidgets: function Preferences_deleteWidgets() {
- let selectedItems = Array.slice(RegisteredWidgetsController.list.selectedItems);
- if (!selectedItems.length)
- return;
-
- let removableItems = selectedItems.filter(function(aItem) aItem.isRemovable);
- if (!removableItems.length)
- return;
-
- const maxWidgetsInTitle = 6;
- const maxWidgetLabelLength = parseInt(180 / Math.min(removableItems.length, maxWidgetsInTitle), 10);
-
- function getShortItemLabel(aItem) {
- let label = aItem.getAttribute("label");
-
- if (label.length > maxWidgetLabelLength) {
- label = label.substr(0, maxWidgetLabelLength)
- .replace(/(\s+\S{0,5})$/, "") + "...";
- }
-
- return label;
- }
-
- let widgetsLabel = (removableItems.length > maxWidgetsInTitle
- ? removableItems.slice(0, maxWidgetsInTitle - 1)
- : removableItems)
- .map(function(aItem) getShortItemLabel(aItem));
-
- let moreText = widgetsLabel.length == removableItems.length ? "" : " " + this.getString("DeleteWidgetsAndOthers");
- widgetsLabel = "«" + widgetsLabel.join("», «") + "»" + moreText;
-
- let confirmTitle = this.getStringPlural("DeleteWidgetsTitle", [removableItems.length]);
- let confirmText = this.getStringPlural("DeleteWidgetsText", [removableItems.length], [widgetsLabel]);
-
- if (!this._getUserConfirm(confirmTitle, confirmText))
- return;
-
- let barApp = this.barCore.application;
-
- let widgetsProtoToRemove = [];
- let checkPackages = { __proto__: null };
-
- removableItems.forEach(function(aItem) {
- let protoId = aItem.getAttribute("id");
-
- let activeItems = ActiveWidgetsController.getItemsForProto(protoId);
- this.removeWidgets(activeItems, true);
-
- RegisteredWidgetsController.removeItem(protoId);
- RegisteredWidgets.remove(protoId);
-
- barApp.forEachWindow(function(controller) controller.removeWidgetsOfProto(protoId));
-
- let [packageID, ] = barApp.widgetLibrary.parseWidgetProtoID(protoId);
- checkPackages[packageID] = true;
- widgetsProtoToRemove.push(protoId);
- }, this);
-
- barApp.widgetLibrary.forgetWidgets(widgetsProtoToRemove);
-
- barApp.forEachWindow(function(controller) controller.updatePalette([]));
-
- for (let packageID in checkPackages) {
- this._logger.debug("Checking package " + packageID);
- if (!barApp.widgetLibrary.getWidgetProtos(packageID).length) {
- barApp.packageManager.uninstallPackage(packageID);
- }
- }
- },
-
- _persistToolbarsSet: function Preferences__persistToolbarsSet(aToolbox) {
- if (!window.persistCurrentSets)
- return;
-
- let toolbox = aToolbox || this.gDocument.getElementById("navigator-toolbox");
-
- let n = {
- gToolboxChanged: true,
- gToolbox: toolbox,
- gToolboxDocument: toolbox.ownerDocument
- };
-
- let o = {};
-
- for (let p in n) {
- o[p] = window[p];
- window[p] = n[p];
- }
-
- persistCurrentSets();
-
- for (let p in o)
- window[p] = o[p];
- },
-
- getAllWidgetItems: function() {
- let toolbarID = this._setupWndCtrl._appToolbar.id;
-
- let xpathString = ["//xul:toolbaritem[@xb-app='" + APP_NAME + "']",
- "//xul:toolbar[@id='" + toolbarID + "']/xul:toolbarseparator",
- "//xul:toolbar[@id='" + toolbarID + "']/xul:toolbarspring",
- "//xul:toolbar[@id='" + toolbarID + "']/xul:toolbarspacer"]
- .concat(StaticWidgets.knownIDs.map(function(id) "//xul:toolbaritem[@id='" + id + "']"))
- .join("|");
-
- return DOMUtils.evaluateXPath(this._setupWndCtrl._toolbox, xpathString);
- },
-
- getItemFromDocumentOrPalette: function Preferences_getItemFromDocumentOrPalette(aWidgetID) {
- return this.gDocument.getElementById(aWidgetID) ||
- this._setupWndCtrl._toolbox.palette.getElementsByAttribute("id", aWidgetID).item(0);
- },
-
- _gBrowser: null,
-
- get gBrowser() {
- if (!this._gBrowser) {
- let misc = this.barCore.Lib.misc;
-
- let browser = misc.getTopNavigatorWindow();
-
- if (!browser) {
- window.open("about:blank", "_blank");
- browser = misc.getTopNavigatorWindow();
- window.focus();
- }
-
- if (!browser)
- throw new Error("Can't create browser for preferences window.");
-
- browser.addEventListener("unload", this, false);
-
- this._gBrowser = browser;
- }
-
- return this._gBrowser;
- },
-
- get gDocument() {
- return this.gBrowser.document;
- },
-
- _prefDirChrome: null,
-
- get prefDirChrome() {
- if (!this._prefDirChrome)
- this._prefDirChrome = document.documentURI.split("/preferences.xul")[0];
-
- return this._prefDirChrome;
- },
-
- _prefDir: null,
-
- get prefDir() {
- if (!this._prefDir) {
- const reg = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci.nsIChromeRegistry);
- let chromeURL = this._ioService.newURI(document.documentURI, null, null);
- let spec = reg.convertChromeURL(chromeURL).spec;
-
- let protocolHandler = Cc["@mozilla.org/network/protocol;1?name=file"].createInstance(Ci.nsIFileProtocolHandler);
- this._prefDir = protocolHandler.getFileFromURLSpec(spec).parent;
- }
-
- return this._prefDir.clone();
- },
-
- getPrefDirFile: function Preferences_getPrefDirFile(aPath) {
- let prefFile = this.prefDir;
- aPath.split("/").forEach(function(path) prefFile.append(path));
- return prefFile;
- },
-
- _transformXML: function Preferences_transformXML(aXML, aStylesheet) {
- if (!(aXML && aStylesheet))
- return null;
-
- let xsltProcessor = Cc["@mozilla.org/document-transformer;1?type=xslt"].createInstance(Ci.nsIXSLTProcessor);
-
- let result = null;
-
- try {
- xsltProcessor.importStylesheet(aStylesheet);
- let ownerDocument = document.implementation.createDocument("", "xb-prefs", null);
- result = xsltProcessor.transformToFragment(aXML, ownerDocument);
- } catch (ex) {
- this._logger.error("Can't transform XML. " + ex);
- }
-
- if (!result || (result.documentElement && result.documentElement.localName == "parsererror")) {
- this._logger.trace("Can't transform XML.");
- result = null;
- }
-
- return result;
- },
-
- get _controlsStylesheet() {
- let controlsXSLTFile = this.getPrefDirFile("templates/controls.xsl");
-
- delete this._controlsStylesheet;
- return (this._controlsStylesheet = this.barCore.Lib.sysutils.xmlDocFromFile(controlsXSLTFile));
- },
-
- transformControlXML: function Preferences_transformControlXML(aControlXML) {
- let result = this._transformXML(aControlXML, this._controlsStylesheet);
- return result ? result.firstChild : null;
- },
-
- transformSourceXMLData: function Preferences_transformSourceXMLData(aInstanceID, aType, aXMLString, aStylesheetString) {
- if (!aXMLString)
- return null;
-
- let widget = ActiveWidgets.get(aInstanceID);
- if (!widget)
- return;
-
- var pkgURI = this._ioService.newURI(widget.unitPackage.resolvePath("null"), null, null);
- let domParser = new this._domParserConstructor(null, pkgURI, pkgURI);
-
- let xmlData = null;
- try {
- xmlData = domParser.parseFromString(aXMLString, "text/xml");
- } catch (ex) {}
-
- if (!xmlData)
- return null;
-
- let result;
-
- if (aStylesheetString) {
- try {
- domParser = new this._domParserConstructor(null, pkgURI, pkgURI);
-
- let stylesheet = domParser.parseFromString(aStylesheetString, "text/xml");
- xmlData = this._transformXML(xmlData, stylesheet);
- } catch (ex) {
- this._logger.error(ex);
- xmlData = null;
- }
-
- if (!xmlData)
- return null;
- }
-
- try {
- let type = aType.indexOf("shortcuts") == -1 ? "source" : "shortcuts";
- let controlsXSLTFile = this.getPrefDirFile("templates/controls-" + type + ".xsl");
-
- let stylesheet = this.barCore.Lib.sysutils.xmlDocFromFile(controlsXSLTFile);
- result = this._transformXML(xmlData, stylesheet);
-
- } catch (ex) {
- this._logger.error(ex);
- }
-
- if (!result) {
- this._logger.trace("Can't transform XML data for control.");
- return null;
- }
-
- this._logger.trace("Preferences.transformControlXMLData");
-
- return result;
- },
-
- onPrefChange: function Preferences_onPrefChange(aItem, aPrefName, aPrefValue) {
- let widget = ActiveWidgets.get(aItem.id);
-
- if (widget && widget.isXbWidget) {
- let settingNode = widget.xbWidget.findSetting(aPrefName);
-
- if (settingNode) {
- if (this.instantApply)
- settingNode.setValue(aPrefValue);
- else
- SettingsProxy.remember(settingNode, aPrefValue);
- }
- }
- },
-
- doCommand: function Preferences_doCommand(aCommand, aArguments) {
- switch (aCommand) {
- case "cmd_addWidgets":
- this.addWidgets(aArguments);
- break;
-
- case "cmd_removeWidgets":
- this.removeWidgets();
- break;
-
- case "cmd_moveWidgetsUp":
- this.moveWidgets("up");
- break;
-
- case "cmd_moveWidgetsDown":
- this.moveWidgets("down");
- break;
-
- case "cmd_moveWidgets":
- this.moveWidgets(null, aArguments);
- break;
-
- case "cmd_restoreDefault":
- this.restoreDefault();
- break;
-
- case "cmd_selectAll":
- this.selectAll();
- break;
-
- case "cmd_deleteWidgets":
- this.deleteWidgets();
- break;
-
- default:
- break;
- }
- },
-
- handleEvent: function Preferences_handleEvent(aEvent) {
- switch (aEvent.type) {
- case "load":
- aEvent.currentTarget.removeEventListener("load", arguments.callee, false);
-
- ["width", "height"].forEach(function(aAttrName) {
- if (this.hasAttribute("min" + aAttrName) && this.hasAttribute(aAttrName)) {
- let minval = parseInt(this.getAttribute("min" + aAttrName), 10);
- let realval = parseInt(this.getAttribute(aAttrName), 10);
-
- if (realval && minval) {
- let val = Math.max(minval, realval);
-
- if (minval > realval)
- this.setAttribute(aAttrName, val);
-
- if (aAttrName == "height")
- window.outerHeight = val;
- else if (aAttrName == "width")
- window.outerWidth = val;
- }
- }
- }, document.documentElement);
-
- if ("arguments" in window && window.arguments.length > 1)
- this.selectWidget(window.arguments[1]);
-
- break;
-
- case "paneload":
- document.documentElement.__defineGetter__("_shouldAnimate", function() false);
-
- this._initPane(aEvent.target.id);
-
- break;
-
- case "unload":
- document.documentElement.cancelDialog();
- break;
-
- default:
- break;
- }
- },
-
- _getUserConfirm: function Preferences__getUserConfirm(aTitle, aText) {
- return Cc["@mozilla.org/embedcomp/prompt-service;1"]
- .getService(Ci.nsIPromptService)
- .confirm(window, aTitle, aText);
- },
-
- get _stringBundle() {
- delete this._stringBundle;
- return this._stringBundle = new Preferences.barCore.Lib.misc.StringBundle("preferences/preferences.properties");
- },
-
- getString: function Preferences_getString(aName, aArgs) {
- return this._stringBundle.get(aName, aArgs);
- },
-
- getStringPlural: function Preferences_getStringPlural(aName, aArgs, aPluralData) {
- return this._stringBundle.getPlural(aName, aArgs, aPluralData);
- }
- };
-
- var RegisteredWidgetsController = {
- _inited: false,
-
- init: function RWL_init() {
- this.finalize();
- this._inited = true;
- },
-
- finalize: function RWL_finalize() {
- if (this._list) {
- this.list.clear();
- this._list = null;
- }
-
- this._inited = false;
- },
-
- _list: null,
-
- get list() {
- return this._list || (this._list = document.getElementById("registered-widgets-list"));
- },
-
- insertItem: function RWL_insertItem(aWidgetProxy, aBeforeID) {
- return this.list.insertItem(aWidgetProxy.isUnique,
- aWidgetProxy.isRemovable,
- aWidgetProxy.protoId,
- aWidgetProxy.name,
- aWidgetProxy.iconURL,
- aBeforeID);
- },
-
- checkWidgetUniqueState: function RWL_checkWidgetUniqueState(aProtoID, aHide) {
- let listitem = document.getElementById(aProtoID);
-
- if (listitem) {
- listitem.hidden = aHide;
-
- if (aHide)
- this.list.removeItemFromSelection(listitem);
- }
- },
-
- removeItem: function RWL_removeItem(aProtoIdOrListItem) {
- let listItem = aProtoIdOrListItem;
- if (typeof listItem == "string")
- listItem = document.getElementById(aProtoIdOrListItem);
-
- if (listItem && listItem.parentNode == this.list) {
- this.list.removeItemFromSelection(listItem);
-
- let indx = this.list.getIndexOfItem(listItem);
- this.list.removeItemAt(indx);
- }
- }
- };
-
- var ActiveWidgetsController = {
- init: function AWL_init() {
- this.finalize();
- this.list.PreferencesController = Preferences;
- },
-
- finalize: function AWL_finalize() {
- if (this._list) {
- this.list.clear();
- this.list.PreferencesController = null;
- this._list = null;
- }
- },
-
- _list: null,
-
- get list() {
- return this._list || (this._list = document.getElementById("active-widgets-list"));
- },
-
- selectItem: function AWL_selectItem(aWidgetProxy) {
- this.list.selectedItem = document.getElementById(aWidgetProxy.id);
- },
-
- insertItem: function AWL_insertItem(aWidgetProxy, aBeforeID) {
- if (aWidgetProxy.isUnique)
- RegisteredWidgetsController.checkWidgetUniqueState(aWidgetProxy.protoId, true);
-
- return this.list.insertItem(aWidgetProxy.isUnique,
- aWidgetProxy.isRemovable,
- aWidgetProxy.id,
- aWidgetProxy.name,
- aWidgetProxy.iconURL,
- aBeforeID);
- },
-
- removeItem: function AWL_removeItem(aItem) {
- if (aItem && aItem.parentNode == this.list) {
- this.list.removeItemFromSelection(aItem);
-
- let indx = this.list.getIndexOfItem(aItem);
- this.list.removeItemAt(indx);
- }
- },
-
- moveSelectedItems: function AWL_moveSelectedItems(aDirection, aBeforeElementId) {
- return this.list.moveSelectedItems(aDirection, aBeforeElementId);
- },
-
- getItemsForProto: function AWL_getItemsForProto(aWidgetProtoID) {
- return Array.slice(this.list.childNodes)
- .filter(function(aItem) {
- let widget = ActiveWidgets.get(aItem.id);
- return !!(widget && widget.protoId == aWidgetProtoID);
- });
- },
-
- _getProxiedSettingValue: function AWL__getProxiedSettingValue(aSettingNode) {
- let value = SettingsProxy.recall(aSettingNode);
-
- if (typeof(value) == "undefined")
- value = aSettingNode.getValue();
-
- return value;
- },
-
- initItemSettings: function AWL_initItemSettings(aItem) {
- let widget = ActiveWidgets.get(aItem.id);
- if (!widget)
- return;
-
- if (!widget.isXbWidget) {
- if (aItem.getAttribute("xb-static-inited") == "true")
- return;
-
- aItem.setAttribute("xb-static-inited", "true");
-
- if (widget.xulDocument) {
- let staticGUI = widget.xulDocument.getElementsByTagName("gui");
- for (let i = staticGUI.length; i--;) {
- let guiNode = staticGUI[i];
-
- let guiNodes = guiNode.childNodes;
- for (let j = 0, len = guiNodes.length; ++j < len;)
- aItem.appendChild(document.importNode(guiNodes[j], true));
-
- if (guiNode.hasAttribute("onload"))
- (new Function(guiNode.getAttribute("onload")))();
- }
-
- widget.updatePreferenceNodes();
- }
-
- return;
- }
-
- let settingsContainer = aItem.settingsContainer;
-
- let protoSettings = widget.protoSettings;
- let instSettings = widget.instSettings;
-
- for (let [name, setting] in Iterator(instSettings)) {
- let element = this._createSettingUI(widget, name, setting.controlInfo);
-
- if (element) {
- let settingNode = setting.node;
- element.setAttribute("value", this._getProxiedSettingValue(settingNode));
- settingsContainer.appendChild(element);
- }
- }
-
- for (let [name, setting] in Iterator(protoSettings)) {
- let element = this._createSettingUI(widget, name, setting.controlInfo);
-
- if (element) {
- let settingNode = setting.node;
- element.setAttribute("value", this._getProxiedSettingValue(settingNode));
- element.setAttribute("xb-global-setting-warning", "auto");
- element.setAttribute("xb-global-setting-names", widget.name);
- settingsContainer.appendChild(element);
- }
- }
- },
-
- _createSettingUI: function AWL__createSettingUI(aWidget, aSettingName, aControlInfo) {
- let control = Preferences.transformControlXML(aControlInfo);
-
- if (!control)
- return null;
-
- control.setAttribute("prefName", aSettingName);
-
- ["source", "alt-source",
- "template", "alt-template",
- "shortcuts-source", "shortcuts-alt-source",
- "shortcuts-template", "shortcuts-alt-template"
- ].forEach(function(aAttrName) {
- if (control.hasAttribute(aAttrName)) {
- let url = aWidget.makeURL(control.getAttribute(aAttrName));
-
- if (url) {
- control.setAttribute(aAttrName, url);
- } else {
- control.removeAttribute(aAttrName);
- }
- }
- }, this);
-
- return control;
- }
- };
-
- window.addEventListener("load", Preferences, false);
- window.addEventListener("paneload", Preferences, false);
-