michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: var gMoveBookmarksDialog = { michael@0: _nodes: null, michael@0: michael@0: _foldersTree: null, michael@0: get foldersTree() { michael@0: if (!this._foldersTree) michael@0: this._foldersTree = document.getElementById("foldersTree"); michael@0: michael@0: return this._foldersTree; michael@0: }, michael@0: michael@0: init: function() { michael@0: this._nodes = window.arguments[0]; michael@0: michael@0: this.foldersTree.place = michael@0: "place:excludeItems=1&excludeQueries=1&excludeReadOnlyFolders=1&folder=" + michael@0: PlacesUIUtils.allBookmarksFolderId; michael@0: }, michael@0: michael@0: onOK: function MBD_onOK(aEvent) { michael@0: let selectedNode = this.foldersTree.selectedNode; michael@0: let selectedFolderId = PlacesUtils.getConcreteItemId(selectedNode); michael@0: michael@0: if (!PlacesUIUtils.useAsyncTransactions) { michael@0: let transactions = []; michael@0: for (var i=0; i < this._nodes.length; i++) { michael@0: // Nothing to do if the node is already under the selected folder michael@0: if (this._nodes[i].parent.itemId == selectedFolderId) michael@0: continue; michael@0: michael@0: let txn = new PlacesMoveItemTransaction(this._nodes[i].itemId, michael@0: selectedFolderId, michael@0: PlacesUtils.bookmarks.DEFAULT_INDEX); michael@0: transactions.push(txn); michael@0: } michael@0: if (transactions.length != 0) { michael@0: let txn = new PlacesAggregatedTransaction("Move Items", transactions); michael@0: PlacesUtils.transactionManager.doTransaction(txn); michael@0: } michael@0: return; michael@0: } michael@0: michael@0: PlacesTransactions.transact(function* () { michael@0: let newParentGUID = yield PlacesUtils.promiseItemGUID(selectedFolderId); michael@0: for (let node of this._nodes) { michael@0: // Nothing to do if the node is already under the selected folder. michael@0: if (node.parent.itemId == selectedFolderId) michael@0: continue; michael@0: yield PlacesTransactions.MoveItem({ GUID: node.bookmarkGuid michael@0: , newParentGUID: newParentGUID }); michael@0: } michael@0: }.bind(this)).then(null, Components.utils.reportError); michael@0: }, michael@0: michael@0: newFolder: function MBD_newFolder() { michael@0: // The command is disabled when the tree is not focused michael@0: this.foldersTree.focus(); michael@0: goDoCommand("placesCmd_new:folder"); michael@0: } michael@0: };