toolkit/components/prompts/content/selectDialog.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/prompts/content/selectDialog.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,68 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +const Ci = Components.interfaces;
     1.9 +const Cr = Components.results;
    1.10 +const Cc = Components.classes;
    1.11 +const Cu = Components.utils;
    1.12 +
    1.13 +let gArgs, listBox;
    1.14 +
    1.15 +function dialogOnLoad() {
    1.16 +    gArgs = window.arguments[0].QueryInterface(Ci.nsIWritablePropertyBag2)
    1.17 +                               .QueryInterface(Ci.nsIWritablePropertyBag);
    1.18 +
    1.19 +    let promptType = gArgs.getProperty("promptType");
    1.20 +    if (promptType != "select") {
    1.21 +        Cu.reportError("selectDialog opened for unknown type: " + promptType);
    1.22 +        window.close();
    1.23 +    }
    1.24 +
    1.25 +    // Default to canceled.
    1.26 +    gArgs.setProperty("ok", false);
    1.27 +
    1.28 +    document.title = gArgs.getProperty("title");
    1.29 +
    1.30 +    let text = gArgs.getProperty("text");
    1.31 +    document.getElementById("info.txt").setAttribute("value", text);
    1.32 +
    1.33 +    let items = gArgs.getProperty("list");
    1.34 +    listBox = document.getElementById("list");
    1.35 +
    1.36 +    for (let i = 0; i < items.length; i++) {
    1.37 +        let str = items[i];
    1.38 +        if (str == "")
    1.39 +            str = "<>";
    1.40 +        listBox.appendItem(str);
    1.41 +        listBox.getItemAtIndex(i).addEventListener("dblclick", dialogDoubleClick, false);
    1.42 +    }
    1.43 +    listBox.selectedIndex = 0;
    1.44 +    listBox.focus();
    1.45 +
    1.46 +    // resize the window to the content
    1.47 +    window.sizeToContent();
    1.48 +
    1.49 +    // Move to the right location
    1.50 +    moveToAlertPosition();
    1.51 +    centerWindowOnScreen();
    1.52 +
    1.53 +    // play sound
    1.54 +    try {
    1.55 +        Cc["@mozilla.org/sound;1"].
    1.56 +        createInstance(Ci.nsISound).
    1.57 +        playEventSound(Ci.nsISound.EVENT_SELECT_DIALOG_OPEN);
    1.58 +    } catch (e) { }
    1.59 +}
    1.60 +
    1.61 +function dialogOK() {
    1.62 +    let selected = listBox.selectedIndex;
    1.63 +    gArgs.setProperty("selected", listBox.selectedIndex);
    1.64 +    gArgs.setProperty("ok", true);
    1.65 +    return true;
    1.66 +}
    1.67 +
    1.68 +function dialogDoubleClick() {
    1.69 +    dialogOK();
    1.70 +    window.close();
    1.71 +}

mercurial