toolkit/components/prompts/content/selectDialog.js

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

     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/. */
     5 const Ci = Components.interfaces;
     6 const Cr = Components.results;
     7 const Cc = Components.classes;
     8 const Cu = Components.utils;
    10 let gArgs, listBox;
    12 function dialogOnLoad() {
    13     gArgs = window.arguments[0].QueryInterface(Ci.nsIWritablePropertyBag2)
    14                                .QueryInterface(Ci.nsIWritablePropertyBag);
    16     let promptType = gArgs.getProperty("promptType");
    17     if (promptType != "select") {
    18         Cu.reportError("selectDialog opened for unknown type: " + promptType);
    19         window.close();
    20     }
    22     // Default to canceled.
    23     gArgs.setProperty("ok", false);
    25     document.title = gArgs.getProperty("title");
    27     let text = gArgs.getProperty("text");
    28     document.getElementById("info.txt").setAttribute("value", text);
    30     let items = gArgs.getProperty("list");
    31     listBox = document.getElementById("list");
    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();
    43     // resize the window to the content
    44     window.sizeToContent();
    46     // Move to the right location
    47     moveToAlertPosition();
    48     centerWindowOnScreen();
    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 }
    58 function dialogOK() {
    59     let selected = listBox.selectedIndex;
    60     gArgs.setProperty("selected", listBox.selectedIndex);
    61     gArgs.setProperty("ok", true);
    62     return true;
    63 }
    65 function dialogDoubleClick() {
    66     dialogOK();
    67     window.close();
    68 }

mercurial