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/. */
7 * SelectBookmarkDialog controls the user interface for the "Use Bookmark for
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
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();
27 * Update the disabled state of the OK button as the user changes the
28 * selection within the view.
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;
38 accept.disabled = disableAcceptButton;
41 onItemDblClick: function SBD_onItemDblClick() {
42 var bookmarks = document.getElementById("bookmarks");
43 var selectedNode = bookmarks.selectedNode;
44 if (selectedNode && PlacesUtils.nodeIsURI(selectedNode)) {
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.
49 document.documentElement.getButton("accept").click();
54 * User accepts their selection. Set all the selected URLs or the contents
55 * of the selected folder as the list of homepages.
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!");
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)) {
71 names.push(node.title);
74 contents.containerOpen = false;
77 urls.push(selectedNode.uri);
78 names.push(selectedNode.title);
80 window.arguments[0].urls = urls;
81 window.arguments[0].names = names;