1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/places/content/moveBookmarks.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,65 @@ 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 +var gMoveBookmarksDialog = { 1.10 + _nodes: null, 1.11 + 1.12 + _foldersTree: null, 1.13 + get foldersTree() { 1.14 + if (!this._foldersTree) 1.15 + this._foldersTree = document.getElementById("foldersTree"); 1.16 + 1.17 + return this._foldersTree; 1.18 + }, 1.19 + 1.20 + init: function() { 1.21 + this._nodes = window.arguments[0]; 1.22 + 1.23 + this.foldersTree.place = 1.24 + "place:excludeItems=1&excludeQueries=1&excludeReadOnlyFolders=1&folder=" + 1.25 + PlacesUIUtils.allBookmarksFolderId; 1.26 + }, 1.27 + 1.28 + onOK: function MBD_onOK(aEvent) { 1.29 + let selectedNode = this.foldersTree.selectedNode; 1.30 + let selectedFolderId = PlacesUtils.getConcreteItemId(selectedNode); 1.31 + 1.32 + if (!PlacesUIUtils.useAsyncTransactions) { 1.33 + let transactions = []; 1.34 + for (var i=0; i < this._nodes.length; i++) { 1.35 + // Nothing to do if the node is already under the selected folder 1.36 + if (this._nodes[i].parent.itemId == selectedFolderId) 1.37 + continue; 1.38 + 1.39 + let txn = new PlacesMoveItemTransaction(this._nodes[i].itemId, 1.40 + selectedFolderId, 1.41 + PlacesUtils.bookmarks.DEFAULT_INDEX); 1.42 + transactions.push(txn); 1.43 + } 1.44 + if (transactions.length != 0) { 1.45 + let txn = new PlacesAggregatedTransaction("Move Items", transactions); 1.46 + PlacesUtils.transactionManager.doTransaction(txn); 1.47 + } 1.48 + return; 1.49 + } 1.50 + 1.51 + PlacesTransactions.transact(function* () { 1.52 + let newParentGUID = yield PlacesUtils.promiseItemGUID(selectedFolderId); 1.53 + for (let node of this._nodes) { 1.54 + // Nothing to do if the node is already under the selected folder. 1.55 + if (node.parent.itemId == selectedFolderId) 1.56 + continue; 1.57 + yield PlacesTransactions.MoveItem({ GUID: node.bookmarkGuid 1.58 + , newParentGUID: newParentGUID }); 1.59 + } 1.60 + }.bind(this)).then(null, Components.utils.reportError); 1.61 + }, 1.62 + 1.63 + newFolder: function MBD_newFolder() { 1.64 + // The command is disabled when the tree is not focused 1.65 + this.foldersTree.focus(); 1.66 + goDoCommand("placesCmd_new:folder"); 1.67 + } 1.68 +};