browser/components/places/content/moveBookmarks.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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 var gMoveBookmarksDialog = {
michael@0 7 _nodes: null,
michael@0 8
michael@0 9 _foldersTree: null,
michael@0 10 get foldersTree() {
michael@0 11 if (!this._foldersTree)
michael@0 12 this._foldersTree = document.getElementById("foldersTree");
michael@0 13
michael@0 14 return this._foldersTree;
michael@0 15 },
michael@0 16
michael@0 17 init: function() {
michael@0 18 this._nodes = window.arguments[0];
michael@0 19
michael@0 20 this.foldersTree.place =
michael@0 21 "place:excludeItems=1&excludeQueries=1&excludeReadOnlyFolders=1&folder=" +
michael@0 22 PlacesUIUtils.allBookmarksFolderId;
michael@0 23 },
michael@0 24
michael@0 25 onOK: function MBD_onOK(aEvent) {
michael@0 26 let selectedNode = this.foldersTree.selectedNode;
michael@0 27 let selectedFolderId = PlacesUtils.getConcreteItemId(selectedNode);
michael@0 28
michael@0 29 if (!PlacesUIUtils.useAsyncTransactions) {
michael@0 30 let transactions = [];
michael@0 31 for (var i=0; i < this._nodes.length; i++) {
michael@0 32 // Nothing to do if the node is already under the selected folder
michael@0 33 if (this._nodes[i].parent.itemId == selectedFolderId)
michael@0 34 continue;
michael@0 35
michael@0 36 let txn = new PlacesMoveItemTransaction(this._nodes[i].itemId,
michael@0 37 selectedFolderId,
michael@0 38 PlacesUtils.bookmarks.DEFAULT_INDEX);
michael@0 39 transactions.push(txn);
michael@0 40 }
michael@0 41 if (transactions.length != 0) {
michael@0 42 let txn = new PlacesAggregatedTransaction("Move Items", transactions);
michael@0 43 PlacesUtils.transactionManager.doTransaction(txn);
michael@0 44 }
michael@0 45 return;
michael@0 46 }
michael@0 47
michael@0 48 PlacesTransactions.transact(function* () {
michael@0 49 let newParentGUID = yield PlacesUtils.promiseItemGUID(selectedFolderId);
michael@0 50 for (let node of this._nodes) {
michael@0 51 // Nothing to do if the node is already under the selected folder.
michael@0 52 if (node.parent.itemId == selectedFolderId)
michael@0 53 continue;
michael@0 54 yield PlacesTransactions.MoveItem({ GUID: node.bookmarkGuid
michael@0 55 , newParentGUID: newParentGUID });
michael@0 56 }
michael@0 57 }.bind(this)).then(null, Components.utils.reportError);
michael@0 58 },
michael@0 59
michael@0 60 newFolder: function MBD_newFolder() {
michael@0 61 // The command is disabled when the tree is not focused
michael@0 62 this.foldersTree.focus();
michael@0 63 goDoCommand("placesCmd_new:folder");
michael@0 64 }
michael@0 65 };

mercurial