|
1 # This Source Code Form is subject to the terms of the Mozilla Public |
|
2 # License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
|
4 |
|
5 #ifdef XP_MACOSX |
|
6 var Cc = Components.classes; |
|
7 var Ci = Components.interfaces; |
|
8 #endif |
|
9 |
|
10 var gAppManagerDialog = { |
|
11 _removed: [], |
|
12 |
|
13 init: function appManager_init() { |
|
14 this.handlerInfo = window.arguments[0]; |
|
15 |
|
16 var bundle = document.getElementById("appManagerBundle"); |
|
17 var contentText; |
|
18 if (this.handlerInfo.type == TYPE_MAYBE_FEED) |
|
19 contentText = bundle.getString("handleWebFeeds"); |
|
20 else { |
|
21 var description = gApplicationsPane._describeType(this.handlerInfo); |
|
22 var key = |
|
23 (this.handlerInfo.wrappedHandlerInfo instanceof Ci.nsIMIMEInfo) ? "handleFile" |
|
24 : "handleProtocol"; |
|
25 contentText = bundle.getFormattedString(key, [description]); |
|
26 } |
|
27 contentText = bundle.getFormattedString("descriptionApplications", [contentText]); |
|
28 document.getElementById("appDescription").textContent = contentText; |
|
29 |
|
30 var list = document.getElementById("appList"); |
|
31 var apps = this.handlerInfo.possibleApplicationHandlers.enumerate(); |
|
32 while (apps.hasMoreElements()) { |
|
33 let app = apps.getNext(); |
|
34 if (!gApplicationsPane.isValidHandlerApp(app)) |
|
35 continue; |
|
36 |
|
37 app.QueryInterface(Ci.nsIHandlerApp); |
|
38 var item = list.appendItem(app.name); |
|
39 item.setAttribute("image", gApplicationsPane._getIconURLForHandlerApp(app)); |
|
40 item.className = "listitem-iconic"; |
|
41 item.app = app; |
|
42 } |
|
43 |
|
44 list.selectedIndex = 0; |
|
45 }, |
|
46 |
|
47 onOK: function appManager_onOK() { |
|
48 if (!this._removed.length) { |
|
49 // return early to avoid calling the |store| method. |
|
50 return; |
|
51 } |
|
52 |
|
53 for (var i = 0; i < this._removed.length; ++i) |
|
54 this.handlerInfo.removePossibleApplicationHandler(this._removed[i]); |
|
55 |
|
56 this.handlerInfo.store(); |
|
57 }, |
|
58 |
|
59 onCancel: function appManager_onCancel() { |
|
60 // do nothing |
|
61 }, |
|
62 |
|
63 remove: function appManager_remove() { |
|
64 var list = document.getElementById("appList"); |
|
65 this._removed.push(list.selectedItem.app); |
|
66 var index = list.selectedIndex; |
|
67 list.removeItemAt(index); |
|
68 if (list.getRowCount() == 0) { |
|
69 // The list is now empty, make the bottom part disappear |
|
70 document.getElementById("appDetails").hidden = true; |
|
71 } |
|
72 else { |
|
73 // Select the item at the same index, if we removed the last |
|
74 // item of the list, select the previous item |
|
75 if (index == list.getRowCount()) |
|
76 --index; |
|
77 list.selectedIndex = index; |
|
78 } |
|
79 }, |
|
80 |
|
81 onSelect: function appManager_onSelect() { |
|
82 var list = document.getElementById("appList"); |
|
83 if (!list.selectedItem) { |
|
84 document.getElementById("remove").disabled = true; |
|
85 return; |
|
86 } |
|
87 document.getElementById("remove").disabled = false; |
|
88 var app = list.selectedItem.app; |
|
89 var address = ""; |
|
90 if (app instanceof Ci.nsILocalHandlerApp) |
|
91 address = app.executable.path; |
|
92 else if (app instanceof Ci.nsIWebHandlerApp) |
|
93 address = app.uriTemplate; |
|
94 else if (app instanceof Ci.nsIWebContentHandlerInfo) |
|
95 address = app.uri; |
|
96 document.getElementById("appLocation").value = address; |
|
97 var bundle = document.getElementById("appManagerBundle"); |
|
98 var appType = app instanceof Ci.nsILocalHandlerApp ? "descriptionLocalApp" |
|
99 : "descriptionWebApp"; |
|
100 document.getElementById("appType").value = bundle.getString(appType); |
|
101 } |
|
102 }; |