applicationManager.js
Go to the documentation of this file.
1 # ***** BEGIN LICENSE BLOCK *****
2 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 #
4 # The contents of this file are subject to the Mozilla Public License Version
5 # 1.1 (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
7 # http://www.mozilla.org/MPL/
8 #
9 # Software distributed under the License is distributed on an "AS IS" basis,
10 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 # for the specific language governing rights and limitations under the
12 # License.
13 #
14 # The Original Code is mozilla.org Code.
15 #
16 # The Initial Developer of the Original Code is
17 # Mozilla Corporation.
18 # Portions created by the Initial Developer are Copyright (C) 2008
19 # the Initial Developer. All Rights Reserved.
20 #
21 # Contributor(s):
22 # Florian Queze <florian@queze.net> (Original author)
23 #
24 # Alternatively, the contents of this file may be used under the terms of
25 # either the GNU General Public License Version 2 or later (the "GPL"), or
26 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 # in which case the provisions of the GPL or the LGPL are applicable instead
28 # of those above. If you wish to allow use of your version of this file only
29 # under the terms of either the GPL or the LGPL, and not to allow others to
30 # use your version of this file under the terms of the MPL, indicate your
31 # decision by deleting the provisions above and replace them with the notice
32 # and other provisions required by the GPL or the LGPL. If you do not delete
33 # the provisions above, a recipient may use your version of this file under
34 # the terms of any one of the MPL, the GPL or the LGPL.
35 #
36 # ***** END LICENSE BLOCK *****
37 
38 #ifdef XP_MACOSX
39 var Cc = Components.classes;
40 var Ci = Components.interfaces;
41 #endif
42 
44  _removed: [],
45 
46  init: function appManager_init() {
47  this.handlerInfo = window.arguments[0];
48 
49  var bundle = document.getElementById("appManagerBundle");
50  var contentText;
51  if (this.handlerInfo.type == TYPE_MAYBE_FEED)
52  contentText = bundle.getString("handleWebFeeds");
53  else {
54  var description = gApplicationsPane._describeType(this.handlerInfo);
55  var key =
56  (this.handlerInfo.wrappedHandlerInfo instanceof Ci.nsIMIMEInfo) ? "handleFile"
57  : "handleProtocol";
58  contentText = bundle.getFormattedString(key, [description]);
59  }
60  contentText = bundle.getFormattedString("descriptionApplications", [contentText]);
61  document.getElementById("appDescription").textContent = contentText;
62 
63  var list = document.getElementById("appList");
64  var apps = this.handlerInfo.possibleApplicationHandlers.enumerate();
65  while (apps.hasMoreElements()) {
66  let app = apps.getNext();
67  if (!gApplicationsPane.isValidHandlerApp(app))
68  continue;
69 
70  app.QueryInterface(Ci.nsIHandlerApp);
71  var item = list.appendItem(app.name);
72  item.setAttribute("image", gApplicationsPane._getIconURLForHandlerApp(app));
73  item.className = "listitem-iconic";
74  item.app = app;
75  }
76 
77  list.selectedIndex = 0;
78  },
79 
80  onOK: function appManager_onOK() {
81  if (!this._removed.length) {
82  // return early to avoid calling the |store| method.
83  return;
84  }
85 
86  for (var i = 0; i < this._removed.length; ++i)
87  this.handlerInfo.removePossibleApplicationHandler(this._removed[i]);
88 
89  this.handlerInfo.store();
90  },
91 
92  onCancel: function appManager_onCancel() {
93  // do nothing
94  },
95 
96  remove: function appManager_remove() {
97  var list = document.getElementById("appList");
98  this._removed.push(list.selectedItem.app);
99  var index = list.selectedIndex;
100  list.removeItemAt(index);
101  if (list.getRowCount() == 0) {
102  // The list is now empty, make the bottom part disappear
103  document.getElementById("appDetails").hidden = true;
104  }
105  else {
106  // Select the item at the same index, if we removed the last
107  // item of the list, select the previous item
108  if (index == list.getRowCount())
109  --index;
110  list.selectedIndex = index;
111  }
112  },
113 
114  onSelect: function appManager_onSelect() {
115  var list = document.getElementById("appList");
116  if (!list.selectedItem) {
117  document.getElementById("remove").disabled = true;
118  return;
119  }
120  document.getElementById("remove").disabled = false;
121  var app = list.selectedItem.app;
122  var address = "";
123  if (app instanceof Ci.nsILocalHandlerApp)
124  address = app.executable.path;
125  else if (app instanceof Ci.nsIWebHandlerApp)
126  address = app.uriTemplate;
127  else if (app instanceof Ci.nsIWebContentHandlerInfo)
128  address = app.uri;
129  document.getElementById("appLocation").value = address;
130  var bundle = document.getElementById("appManagerBundle");
131  var appType = app instanceof Ci.nsILocalHandlerApp ? "descriptionLocalApp"
132  : "descriptionWebApp";
133  document.getElementById("appType").value = bundle.getString(appType);
134  }
135 };
const Cc
#define TYPE_MAYBE_FEED
var gAppManagerDialog
let window
_window init
Definition: FeedWriter.js:1144
var bundle
function onCancel()
Definition: safeMode.js:129
function onOK()
Definition: safeMode.js:111
const Ci
_dialogDatepicker onSelect
_getSelectedPageStyle s i