From 638e666e32f3d4fcc4b79ef009c5c9ccce0b8d8c Mon Sep 17 00:00:00 2001 From: Paolo Amadini Date: Wed, 16 May 2018 11:45:19 +0100 Subject: [PATCH] Bug 1459556 - Part 1 - Remove the implementation from the "handler" binding. r=jaws MozReview-Commit-ID: IN1C5NC9Rzb --HG-- extra : rebase_source : 776e8d830ba2f5f37a039889705906e4d9a27096 extra : source : f7b1991ca700088428baf65f38ca8eff3135f8c5 --- browser/components/preferences/handlers.xml | 23 -------- .../components/preferences/in-content/main.js | 56 +++++++++++++++---- 2 files changed, 44 insertions(+), 35 deletions(-) diff --git a/browser/components/preferences/handlers.xml b/browser/components/preferences/handlers.xml index 3cf7f17f823e..ef967924ca8d 100644 --- a/browser/components/preferences/handlers.xml +++ b/browser/components/preferences/handlers.xml @@ -11,29 +11,6 @@ xmlns:xbl="http://www.mozilla.org/xbl"> - - - - return this.getAttribute("type"); - - - - - - - diff --git a/browser/components/preferences/in-content/main.js b/browser/components/preferences/in-content/main.js index 14060a5759d7..7aec0a2e4cac 100644 --- a/browser/components/preferences/in-content/main.js +++ b/browser/components/preferences/in-content/main.js @@ -583,6 +583,7 @@ var gMainPane = { // of the preferences page. window.addEventListener("pageshow", async () => { try { + this._initListEventHandlers(); this._loadData(); await this._rebuildVisibleTypes(); this._sortVisibleTypes(); @@ -1448,6 +1449,31 @@ var gMainPane = { // View Construction + selectedHandlerListItem: null, + + _initListEventHandlers() { + this._list.addEventListener("select", event => { + if (event.target != this._list) { + return; + } + + let handlerListItem = this._list.selectedItem && + HandlerListItem.forNode(this._list.selectedItem); + if (this.selectedHandlerListItem == handlerListItem) { + return; + } + + if (this.selectedHandlerListItem) { + this.selectedHandlerListItem.showActionsMenu = false; + } + this.selectedHandlerListItem = handlerListItem; + if (handlerListItem) { + this.rebuildActionsMenu(); + handlerListItem.showActionsMenu = true; + } + }); + }, + async _rebuildVisibleTypes() { this._visibleTypes = []; @@ -1506,8 +1532,9 @@ var gMainPane = { }, _rebuildView() { - let lastSelectedType = this._list.selectedItem && - HandlerListItem.forNode(this._list.selectedItem).handlerInfoWrapper.type; + let lastSelectedType = this.selectedHandlerListItem && + this.selectedHandlerListItem.handlerInfoWrapper.type; + this.selectedHandlerListItem = null; // Clear the list of entries. while (this._list.childNodes.length > 1) @@ -1585,7 +1612,7 @@ var gMainPane = { */ rebuildActionsMenu() { var typeItem = this._list.selectedItem; - var handlerInfo = this._handledTypes[typeItem.type]; + var handlerInfo = this.selectedHandlerListItem.handlerInfoWrapper; var menu = document.getAnonymousElementByAttribute(typeItem, "class", "actionsMenu"); var menuPopup = menu.menupopup; @@ -1699,7 +1726,7 @@ var gMainPane = { if (Cc["@mozilla.org/gio-service;1"]) { let gIOSvc = Cc["@mozilla.org/gio-service;1"]. getService(Ci.nsIGIOService); - var gioApps = gIOSvc.getAppsForURIScheme(typeItem.type); + var gioApps = gIOSvc.getAppsForURIScheme(handlerInfo.type); let enumerator = gioApps.enumerate(); let possibleHandlers = handlerInfo.possibleApplicationHandlers; while (enumerator.hasMoreElements()) { @@ -1906,8 +1933,7 @@ var gMainPane = { }, _storeAction(aActionItem) { - var typeItem = this._list.selectedItem; - var handlerInfo = this._handledTypes[typeItem.type]; + var handlerInfo = this.selectedHandlerListItem.handlerInfoWrapper; let action = parseInt(aActionItem.getAttribute("action")); @@ -1942,7 +1968,7 @@ var gMainPane = { handlerInfo.handledOnlyByPlugin = false; // Update the action label and image to reflect the new preferred action. - HandlerListItem.forNode(typeItem).refreshAction(); + this.selectedHandlerListItem.refreshAction(); }, manageApp(aEvent) { @@ -1950,8 +1976,7 @@ var gMainPane = { // as we handle it specially ourselves. aEvent.stopPropagation(); - var typeItem = this._list.selectedItem; - var handlerInfo = this._handledTypes[typeItem.type]; + var handlerInfo = this.selectedHandlerListItem.handlerInfoWrapper; let onComplete = () => { // Rebuild the actions menu so that we revert to the previous selection, @@ -1959,7 +1984,7 @@ var gMainPane = { this.rebuildActionsMenu(); // update the richlistitem too. Will be visible when selecting another row - HandlerListItem.forNode(typeItem).refreshAction(); + this.selectedHandlerListItem.refreshAction(); }; gSubDialog.open("chrome://browser/content/preferences/applicationManager.xul", @@ -1998,7 +2023,7 @@ var gMainPane = { if (AppConstants.platform == "win") { var params = {}; - var handlerInfo = this._handledTypes[this._list.selectedItem.type]; + var handlerInfo = this.selectedHandlerListItem.handlerInfoWrapper; if (isFeedType(handlerInfo.type)) { // MIME info will be null, create a temp object. @@ -2038,7 +2063,7 @@ var gMainPane = { handlerApp.executable = fp.file; // Add the app to the type's list of possible handlers. - let handler = this._handledTypes[this._list.selectedItem.type]; + let handler = this.selectedHandlerListItem.handlerInfoWrapper; handler.addPossibleApplicationHandler(handlerApp); chooseAppCallback(handlerApp); @@ -2464,6 +2489,13 @@ class HandlerListItem { this.node.setAttribute("actionIcon", this.handlerInfoWrapper.actionIcon); } } + + set showActionsMenu(value) { + document.getAnonymousElementByAttribute(this.node, "anonid", "selected") + .setAttribute("hidden", !value); + document.getAnonymousElementByAttribute(this.node, "anonid", "not-selected") + .setAttribute("hidden", !!value); + } } /**