moveBookmarks.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. var gMoveBookmarksDialog = {
  6. _nodes: null,
  7. _foldersTree: null,
  8. get foldersTree() {
  9. if (!this._foldersTree)
  10. this._foldersTree = document.getElementById("foldersTree");
  11. return this._foldersTree;
  12. },
  13. init: function() {
  14. this._nodes = window.arguments[0];
  15. this.foldersTree.place =
  16. "place:excludeItems=1&excludeQueries=1&excludeReadOnlyFolders=1&folder=" +
  17. PlacesUIUtils.allBookmarksFolderId;
  18. },
  19. onOK: function(aEvent) {
  20. var selectedNode = this.foldersTree.selectedNode;
  21. NS_ASSERT(selectedNode,
  22. "selectedNode must be set in a single-selection tree with initial selection set");
  23. var selectedFolderID = PlacesUtils.getConcreteItemId(selectedNode);
  24. var transactions = [];
  25. for (var i=0; i < this._nodes.length; i++) {
  26. // Nothing to do if the node is already under the selected folder
  27. if (this._nodes[i].parent.itemId == selectedFolderID)
  28. continue;
  29. let txn = new PlacesMoveItemTransaction(this._nodes[i].itemId,
  30. selectedFolderID,
  31. PlacesUtils.bookmarks.DEFAULT_INDEX);
  32. transactions.push(txn);
  33. }
  34. if (transactions.length != 0) {
  35. let txn = new PlacesAggregatedTransaction("Move Items", transactions);
  36. PlacesUtils.transactionManager.doTransaction(txn);
  37. }
  38. },
  39. newFolder: function() {
  40. // The command is disabled when the tree is not focused
  41. this.foldersTree.focus();
  42. goDoCommand("placesCmd_new:folder");
  43. }
  44. };