1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/preferences/selectBookmark.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,83 @@ 1.4 +//* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/** 1.10 + * SelectBookmarkDialog controls the user interface for the "Use Bookmark for 1.11 + * Home Page" dialog. 1.12 + * 1.13 + * The caller (gMainPane.setHomePageToBookmark in main.js) invokes this dialog 1.14 + * with a single argument - a reference to an object with a .urls property and 1.15 + * a .names property. This dialog is responsible for updating the contents of 1.16 + * the .urls property with an array of URLs to use as home pages and for 1.17 + * updating the .names property with an array of names for those URLs before it 1.18 + * closes. 1.19 + */ 1.20 +var SelectBookmarkDialog = { 1.21 + init: function SBD_init() { 1.22 + document.getElementById("bookmarks").place = 1.23 + "place:queryType=1&folder=" + PlacesUIUtils.allBookmarksFolderId; 1.24 + 1.25 + // Initial update of the OK button. 1.26 + this.selectionChanged(); 1.27 + }, 1.28 + 1.29 + /** 1.30 + * Update the disabled state of the OK button as the user changes the 1.31 + * selection within the view. 1.32 + */ 1.33 + selectionChanged: function SBD_selectionChanged() { 1.34 + var accept = document.documentElement.getButton("accept"); 1.35 + var bookmarks = document.getElementById("bookmarks"); 1.36 + var disableAcceptButton = true; 1.37 + if (bookmarks.hasSelection) { 1.38 + if (!PlacesUtils.nodeIsSeparator(bookmarks.selectedNode)) 1.39 + disableAcceptButton = false; 1.40 + } 1.41 + accept.disabled = disableAcceptButton; 1.42 + }, 1.43 + 1.44 + onItemDblClick: function SBD_onItemDblClick() { 1.45 + var bookmarks = document.getElementById("bookmarks"); 1.46 + var selectedNode = bookmarks.selectedNode; 1.47 + if (selectedNode && PlacesUtils.nodeIsURI(selectedNode)) { 1.48 + /** 1.49 + * The user has double clicked on a tree row that is a link. Take this to 1.50 + * mean that they want that link to be their homepage, and close the dialog. 1.51 + */ 1.52 + document.documentElement.getButton("accept").click(); 1.53 + } 1.54 + }, 1.55 + 1.56 + /** 1.57 + * User accepts their selection. Set all the selected URLs or the contents 1.58 + * of the selected folder as the list of homepages. 1.59 + */ 1.60 + accept: function SBD_accept() { 1.61 + var bookmarks = document.getElementById("bookmarks"); 1.62 + NS_ASSERT(bookmarks.hasSelection, 1.63 + "Should not be able to accept dialog if there is no selected URL!"); 1.64 + var urls = []; 1.65 + var names = []; 1.66 + var selectedNode = bookmarks.selectedNode; 1.67 + if (PlacesUtils.nodeIsFolder(selectedNode)) { 1.68 + var contents = PlacesUtils.getFolderContents(selectedNode.itemId).root; 1.69 + var cc = contents.childCount; 1.70 + for (var i = 0; i < cc; ++i) { 1.71 + var node = contents.getChild(i); 1.72 + if (PlacesUtils.nodeIsURI(node)) { 1.73 + urls.push(node.uri); 1.74 + names.push(node.title); 1.75 + } 1.76 + } 1.77 + contents.containerOpen = false; 1.78 + } 1.79 + else { 1.80 + urls.push(selectedNode.uri); 1.81 + names.push(selectedNode.title); 1.82 + } 1.83 + window.arguments[0].urls = urls; 1.84 + window.arguments[0].names = names; 1.85 + } 1.86 +};