From 93e1bb29dcc60527d004998c409257cebb9d487c Mon Sep 17 00:00:00 2001 From: "beng%bengoodger.com" Date: Fri, 31 Mar 2006 22:42:21 +0000 Subject: [PATCH] 331905 - pasted folders/items are inserted at the wrong level in the bookmarks hierarchy. r=annie.sullivan@gmail.com --- browser/components/places/content/context.inc | 2 +- .../components/places/content/controller.js | 161 +++++++++--------- 2 files changed, 80 insertions(+), 83 deletions(-) diff --git a/browser/components/places/content/context.inc b/browser/components/places/content/context.inc index 27b22e373c70..b378a6b39a44 100755 --- a/browser/components/places/content/context.inc +++ b/browser/components/places/content/context.inc @@ -29,7 +29,7 @@ + selection="host|separator|link|links|folder|mixed"/> -1) + txn.container = this.container; + txn.doTransaction(); + } this.bookmarks.endUpdateBatch(); this.LOG("== " + this._name + " (Aggregate Ends) ========="); }, @@ -2167,8 +2174,12 @@ PlacesAggregateTransaction.prototype = { undoTransaction: function() { this.LOG("== UN" + this._name + " (UNAggregate) ============"); this.bookmarks.beginUpdateBatch(); - for (var i = this._transactions.length - 1; i >= 0; --i) - this._transactions[i].undoTransaction(); + for (var i = this._transactions.length; i >= 0; --i) { + var txn = this._transactions[i]; + if (this.container > -1) + txn.container = this.container; + txn.undoTransaction(); + } this.bookmarks.endUpdateBatch(); this.LOG("== UN" + this._name + " (UNAggregate Ends) ======="); } @@ -2180,22 +2191,33 @@ PlacesAggregateTransaction.prototype = { */ function PlacesCreateFolderTransaction(name, container, index) { this._name = name; - this._container = container; + this.container = container; this._index = index; this._id = null; + this.childTransactions = []; this.redoTransaction = this.doTransaction; } PlacesCreateFolderTransaction.prototype = { __proto__: PlacesBaseTransaction.prototype, doTransaction: function PCFT_doTransaction() { - this.LOG("Create Folder: " + this._name + " in: " + this._container + "," + this._index); - this._id = this.bookmarks.createFolder(this._container, this._name, this._index); + this.LOG("Create Folder: " + this._name + " in: " + this.container + "," + this._index); + this._id = this.bookmarks.createFolder(this.container, this._name, this._index); + for (var i = 0; i < this.childTransactions.length; ++i) { + var txn = this.childTransactions[i]; + txn.container = this._id; + txn.doTransaction(); + } }, undoTransaction: function PCFT_undoTransaction() { - this.LOG("UNCreate Folder: " + this._name + " from: " + this._container + "," + this._index); + this.LOG("UNCreate Folder: " + this._name + " from: " + this.container + "," + this._index); this.bookmarks.removeFolder(this._id); + for (var i = 0; i < this.childTransactions.length; ++i) { + var txn = this.childTransactions[i]; + txn.container = this._id; + txn.undoTransaction(); + } } }; @@ -2204,7 +2226,7 @@ PlacesCreateFolderTransaction.prototype = { */ function PlacesCreateItemTransaction(uri, container, index) { this._uri = uri; - this._container = container; + this.container = container; this._index = index; this.redoTransaction = this.doTransaction; } @@ -2212,35 +2234,35 @@ PlacesCreateItemTransaction.prototype = { __proto__: PlacesBaseTransaction.prototype, doTransaction: function PCIT_doTransaction() { - this.LOG("Create Item: " + this._uri.spec + " in: " + this._container + "," + this._index); - this.bookmarks.insertItem(this._container, this._uri, this._index); + this.LOG("Create Item: " + this._uri.spec + " in: " + this.container + "," + this._index); + this.bookmarks.insertItem(this.container, this._uri, this._index); }, undoTransaction: function PCIT_undoTransaction() { - this.LOG("UNCreate Item: " + this._uri.spec + " from: " + this._container + "," + this._index); - this.bookmarks.removeItem(this._container, this._uri); + this.LOG("UNCreate Item: " + this._uri.spec + " from: " + this.container + "," + this._index); + this.bookmarks.removeItem(this.container, this._uri); } }; /** * Create a new Separator */ -function PlacesInsertSeparatorTransaction(container, index) { - this._container = container; +function PlacesCreateSeparatorTransaction(container, index) { + this.container = container; this._index = index; this._id = null; } -PlacesInsertSeparatorTransaction.prototype = { +PlacesCreateSeparatorTransaction.prototype = { __proto__: PlacesBaseTransaction.prototype, doTransaction: function PIST_doTransaction() { - this.LOG("Create separator in: " + this._container + "," + this._index); - this._id = this.bookmarks.insertSeparator(this._container, this._index); + this.LOG("Create separator in: " + this.container + "," + this._index); + this._id = this.bookmarks.insertSeparator(this.container, this._index); }, undoTransaction: function PIST_undoTransaction() { - this.LOG("UNCreate separator from: " + this._container + "," + this._index); - this.bookmarks.removeChildAt(this._container, this._index); + this.LOG("UNCreate separator from: " + this.container + "," + this._index); + this.bookmarks.removeChildAt(this.container, this._index); } }; @@ -2297,29 +2319,6 @@ PlacesMoveItemTransaction.prototype = { } }; -/** - * A named leaf item. - * @param name - * The name of the item - * @param uri - * The URI fo the item - */ -function PlacesRemoveFolderSaveChildItem(name, uri) { - this.name = name; - var ios = - Cc["@mozilla.org/network/io-service;1"]. - getService(Ci.nsIIOService); - this.uri = ios.newURI(uri, null, null); -} -/** - * A named folder, with children. - * @param name - * The name of the folder. - */ -function PlacesRemoveFolderSaveChildFolder(name) { - this.name = name; - this.children = []; -} /** * Remove a Folder * This is a little complicated. When we remove a container we need to remove @@ -2329,8 +2328,8 @@ function PlacesRemoveFolderSaveChildFolder(name) { * likely have a different id. */ -function PlacesRemoveFolderTransaction(removeTxn, id) { - this._removeTxn = removeTxn; +function PlacesRemoveFolderTransaction(id) { + this._removeTxn = this.bookmarks.getRemoveFolderTransaction(id); this._id = id; this._transactions = []; // A set of transactions to remove content. this.redoTransaction = this.doTransaction; @@ -2355,9 +2354,7 @@ PlacesRemoveFolderTransaction.prototype = { var txn; if (child.type == Ci.nsINavHistoryResultNode.RESULT_TYPE_FOLDER) { var folder = asFolder(child); - var removeTxn = - this.bookmarks.getRemoveFolderTransaction(folder.folderId); - txn = new PlacesRemoveFolderTransaction(removeTxn, folder.folderId); + txn = new PlacesRemoveFolderTransaction(folder.folderId); } else if (child.type == Ci.nsINavHistoryResultNode.RESULT_TYPE_SEPARATOR) { txn = new PlacesRemoveSeparatorTransaction(this._id, i);