browser/components/preferences/selectBookmark.js

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

     1 //* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 /**
     7  * SelectBookmarkDialog controls the user interface for the "Use Bookmark for
     8  * Home Page" dialog. 
     9  * 
    10  * The caller (gMainPane.setHomePageToBookmark in main.js) invokes this dialog
    11  * with a single argument - a reference to an object with a .urls property and
    12  * a .names property.  This dialog is responsible for updating the contents of
    13  * the .urls property with an array of URLs to use as home pages and for
    14  * updating the .names property with an array of names for those URLs before it
    15  * closes.
    16  */ 
    17 var SelectBookmarkDialog = {
    18   init: function SBD_init() {
    19     document.getElementById("bookmarks").place =
    20       "place:queryType=1&folder=" + PlacesUIUtils.allBookmarksFolderId;
    22     // Initial update of the OK button.
    23     this.selectionChanged();
    24   },
    26   /** 
    27    * Update the disabled state of the OK button as the user changes the 
    28    * selection within the view. 
    29    */
    30   selectionChanged: function SBD_selectionChanged() {
    31     var accept = document.documentElement.getButton("accept");
    32     var bookmarks = document.getElementById("bookmarks");
    33     var disableAcceptButton = true;
    34     if (bookmarks.hasSelection) {
    35       if (!PlacesUtils.nodeIsSeparator(bookmarks.selectedNode))
    36         disableAcceptButton = false;
    37     }
    38     accept.disabled = disableAcceptButton;
    39   },
    41   onItemDblClick: function SBD_onItemDblClick() {
    42     var bookmarks = document.getElementById("bookmarks");
    43     var selectedNode = bookmarks.selectedNode;
    44     if (selectedNode && PlacesUtils.nodeIsURI(selectedNode)) {
    45       /**
    46        * The user has double clicked on a tree row that is a link. Take this to
    47        * mean that they want that link to be their homepage, and close the dialog.
    48        */
    49       document.documentElement.getButton("accept").click();
    50     }
    51   },
    53   /**
    54    * User accepts their selection. Set all the selected URLs or the contents
    55    * of the selected folder as the list of homepages.
    56    */
    57   accept: function SBD_accept() {
    58     var bookmarks = document.getElementById("bookmarks");
    59     NS_ASSERT(bookmarks.hasSelection,
    60               "Should not be able to accept dialog if there is no selected URL!");
    61     var urls = [];
    62     var names = [];
    63     var selectedNode = bookmarks.selectedNode;
    64     if (PlacesUtils.nodeIsFolder(selectedNode)) {
    65       var contents = PlacesUtils.getFolderContents(selectedNode.itemId).root;
    66       var cc = contents.childCount;
    67       for (var i = 0; i < cc; ++i) {
    68         var node = contents.getChild(i);
    69         if (PlacesUtils.nodeIsURI(node)) {
    70           urls.push(node.uri);
    71           names.push(node.title);
    72         }
    73       }
    74       contents.containerOpen = false;
    75     }
    76     else {
    77       urls.push(selectedNode.uri);
    78       names.push(selectedNode.title);
    79     }
    80     window.arguments[0].urls = urls;
    81     window.arguments[0].names = names;
    82   }
    83 };

mercurial