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: const Ci = Components.interfaces; michael@0: const Cr = Components.results; michael@0: const Cc = Components.classes; michael@0: const Cu = Components.utils; michael@0: michael@0: let gArgs, listBox; michael@0: michael@0: function dialogOnLoad() { michael@0: gArgs = window.arguments[0].QueryInterface(Ci.nsIWritablePropertyBag2) michael@0: .QueryInterface(Ci.nsIWritablePropertyBag); michael@0: michael@0: let promptType = gArgs.getProperty("promptType"); michael@0: if (promptType != "select") { michael@0: Cu.reportError("selectDialog opened for unknown type: " + promptType); michael@0: window.close(); michael@0: } michael@0: michael@0: // Default to canceled. michael@0: gArgs.setProperty("ok", false); michael@0: michael@0: document.title = gArgs.getProperty("title"); michael@0: michael@0: let text = gArgs.getProperty("text"); michael@0: document.getElementById("info.txt").setAttribute("value", text); michael@0: michael@0: let items = gArgs.getProperty("list"); michael@0: listBox = document.getElementById("list"); michael@0: michael@0: for (let i = 0; i < items.length; i++) { michael@0: let str = items[i]; michael@0: if (str == "") michael@0: str = "<>"; michael@0: listBox.appendItem(str); michael@0: listBox.getItemAtIndex(i).addEventListener("dblclick", dialogDoubleClick, false); michael@0: } michael@0: listBox.selectedIndex = 0; michael@0: listBox.focus(); michael@0: michael@0: // resize the window to the content michael@0: window.sizeToContent(); michael@0: michael@0: // Move to the right location michael@0: moveToAlertPosition(); michael@0: centerWindowOnScreen(); michael@0: michael@0: // play sound michael@0: try { michael@0: Cc["@mozilla.org/sound;1"]. michael@0: createInstance(Ci.nsISound). michael@0: playEventSound(Ci.nsISound.EVENT_SELECT_DIALOG_OPEN); michael@0: } catch (e) { } michael@0: } michael@0: michael@0: function dialogOK() { michael@0: let selected = listBox.selectedIndex; michael@0: gArgs.setProperty("selected", listBox.selectedIndex); michael@0: gArgs.setProperty("ok", true); michael@0: return true; michael@0: } michael@0: michael@0: function dialogDoubleClick() { michael@0: dialogOK(); michael@0: window.close(); michael@0: }