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: #ifdef XP_MACOSX michael@0: var Cc = Components.classes; michael@0: var Ci = Components.interfaces; michael@0: #endif michael@0: michael@0: var gAppManagerDialog = { michael@0: _removed: [], michael@0: michael@0: init: function appManager_init() { michael@0: this.handlerInfo = window.arguments[0]; michael@0: michael@0: var bundle = document.getElementById("appManagerBundle"); michael@0: var contentText; michael@0: if (this.handlerInfo.type == TYPE_MAYBE_FEED) michael@0: contentText = bundle.getString("handleWebFeeds"); michael@0: else { michael@0: var description = gApplicationsPane._describeType(this.handlerInfo); michael@0: var key = michael@0: (this.handlerInfo.wrappedHandlerInfo instanceof Ci.nsIMIMEInfo) ? "handleFile" michael@0: : "handleProtocol"; michael@0: contentText = bundle.getFormattedString(key, [description]); michael@0: } michael@0: contentText = bundle.getFormattedString("descriptionApplications", [contentText]); michael@0: document.getElementById("appDescription").textContent = contentText; michael@0: michael@0: var list = document.getElementById("appList"); michael@0: var apps = this.handlerInfo.possibleApplicationHandlers.enumerate(); michael@0: while (apps.hasMoreElements()) { michael@0: let app = apps.getNext(); michael@0: if (!gApplicationsPane.isValidHandlerApp(app)) michael@0: continue; michael@0: michael@0: app.QueryInterface(Ci.nsIHandlerApp); michael@0: var item = list.appendItem(app.name); michael@0: item.setAttribute("image", gApplicationsPane._getIconURLForHandlerApp(app)); michael@0: item.className = "listitem-iconic"; michael@0: item.app = app; michael@0: } michael@0: michael@0: list.selectedIndex = 0; michael@0: }, michael@0: michael@0: onOK: function appManager_onOK() { michael@0: if (!this._removed.length) { michael@0: // return early to avoid calling the |store| method. michael@0: return; michael@0: } michael@0: michael@0: for (var i = 0; i < this._removed.length; ++i) michael@0: this.handlerInfo.removePossibleApplicationHandler(this._removed[i]); michael@0: michael@0: this.handlerInfo.store(); michael@0: }, michael@0: michael@0: onCancel: function appManager_onCancel() { michael@0: // do nothing michael@0: }, michael@0: michael@0: remove: function appManager_remove() { michael@0: var list = document.getElementById("appList"); michael@0: this._removed.push(list.selectedItem.app); michael@0: var index = list.selectedIndex; michael@0: list.removeItemAt(index); michael@0: if (list.getRowCount() == 0) { michael@0: // The list is now empty, make the bottom part disappear michael@0: document.getElementById("appDetails").hidden = true; michael@0: } michael@0: else { michael@0: // Select the item at the same index, if we removed the last michael@0: // item of the list, select the previous item michael@0: if (index == list.getRowCount()) michael@0: --index; michael@0: list.selectedIndex = index; michael@0: } michael@0: }, michael@0: michael@0: onSelect: function appManager_onSelect() { michael@0: var list = document.getElementById("appList"); michael@0: if (!list.selectedItem) { michael@0: document.getElementById("remove").disabled = true; michael@0: return; michael@0: } michael@0: document.getElementById("remove").disabled = false; michael@0: var app = list.selectedItem.app; michael@0: var address = ""; michael@0: if (app instanceof Ci.nsILocalHandlerApp) michael@0: address = app.executable.path; michael@0: else if (app instanceof Ci.nsIWebHandlerApp) michael@0: address = app.uriTemplate; michael@0: else if (app instanceof Ci.nsIWebContentHandlerInfo) michael@0: address = app.uri; michael@0: document.getElementById("appLocation").value = address; michael@0: var bundle = document.getElementById("appManagerBundle"); michael@0: var appType = app instanceof Ci.nsILocalHandlerApp ? "descriptionLocalApp" michael@0: : "descriptionWebApp"; michael@0: document.getElementById("appType").value = bundle.getString(appType); michael@0: } michael@0: };