|
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 const Ci = Components.interfaces; |
|
6 const Cr = Components.results; |
|
7 const Cc = Components.classes; |
|
8 const Cu = Components.utils; |
|
9 |
|
10 let gArgs, listBox; |
|
11 |
|
12 function dialogOnLoad() { |
|
13 gArgs = window.arguments[0].QueryInterface(Ci.nsIWritablePropertyBag2) |
|
14 .QueryInterface(Ci.nsIWritablePropertyBag); |
|
15 |
|
16 let promptType = gArgs.getProperty("promptType"); |
|
17 if (promptType != "select") { |
|
18 Cu.reportError("selectDialog opened for unknown type: " + promptType); |
|
19 window.close(); |
|
20 } |
|
21 |
|
22 // Default to canceled. |
|
23 gArgs.setProperty("ok", false); |
|
24 |
|
25 document.title = gArgs.getProperty("title"); |
|
26 |
|
27 let text = gArgs.getProperty("text"); |
|
28 document.getElementById("info.txt").setAttribute("value", text); |
|
29 |
|
30 let items = gArgs.getProperty("list"); |
|
31 listBox = document.getElementById("list"); |
|
32 |
|
33 for (let i = 0; i < items.length; i++) { |
|
34 let str = items[i]; |
|
35 if (str == "") |
|
36 str = "<>"; |
|
37 listBox.appendItem(str); |
|
38 listBox.getItemAtIndex(i).addEventListener("dblclick", dialogDoubleClick, false); |
|
39 } |
|
40 listBox.selectedIndex = 0; |
|
41 listBox.focus(); |
|
42 |
|
43 // resize the window to the content |
|
44 window.sizeToContent(); |
|
45 |
|
46 // Move to the right location |
|
47 moveToAlertPosition(); |
|
48 centerWindowOnScreen(); |
|
49 |
|
50 // play sound |
|
51 try { |
|
52 Cc["@mozilla.org/sound;1"]. |
|
53 createInstance(Ci.nsISound). |
|
54 playEventSound(Ci.nsISound.EVENT_SELECT_DIALOG_OPEN); |
|
55 } catch (e) { } |
|
56 } |
|
57 |
|
58 function dialogOK() { |
|
59 let selected = listBox.selectedIndex; |
|
60 gArgs.setProperty("selected", listBox.selectedIndex); |
|
61 gArgs.setProperty("ok", true); |
|
62 return true; |
|
63 } |
|
64 |
|
65 function dialogDoubleClick() { |
|
66 dialogOK(); |
|
67 window.close(); |
|
68 } |