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