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.

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

mercurial