From e0c103144910370e24f912e2ce58dc3a0b112f69 Mon Sep 17 00:00:00 2001 From: "mak77@bonardo.net" Date: Wed, 5 Nov 2008 14:03:48 -0800 Subject: [PATCH] Bug 445737 - undo delete bookmark doesn't restore keyword (r=dietrich) --- .../places/src/nsPlacesTransactionsService.js | 21 ++++++++++++------- .../places/tests/unit/test_placesTxn.js | 6 +++++- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/browser/components/places/src/nsPlacesTransactionsService.js b/browser/components/places/src/nsPlacesTransactionsService.js index 947ff5715be7..908573245a69 100644 --- a/browser/components/places/src/nsPlacesTransactionsService.js +++ b/browser/components/places/src/nsPlacesTransactionsService.js @@ -488,18 +488,25 @@ function placesRemoveItemTransaction(aItemId) { this._removeTxn = PlacesUtils.bookmarks .getRemoveFolderTransaction(this._id); } + else if (this._itemType == Ci.nsINavBookmarksService.TYPE_BOOKMARK) { + this._uri = PlacesUtils.bookmarks.getBookmarkURI(this._id); + this._keyword = PlacesUtils.bookmarks.getKeywordForBookmark(this._id); + } + + if (this._itemType != Ci.nsINavBookmarksService.TYPE_SEPARATOR) + this._title = PlacesUtils.bookmarks.getItemTitle(this._id); + + this._oldContainer = PlacesUtils.bookmarks.getFolderIdForItem(this._id); + this._annotations = PlacesUtils.getAnnotationsForItem(this._id); + this._dateAdded = PlacesUtils.bookmarks.getItemDateAdded(this._id); + this._lastModified = PlacesUtils.bookmarks.getItemLastModified(this._id); } placesRemoveItemTransaction.prototype = { __proto__: placesBaseTransaction.prototype, doTransaction: function PRIT_doTransaction() { - this._oldContainer = PlacesUtils.bookmarks.getFolderIdForItem(this._id); this._oldIndex = PlacesUtils.bookmarks.getItemIndex(this._id); - this._title = PlacesUtils.bookmarks.getItemTitle(this._id); - this._annotations = PlacesUtils.getAnnotationsForItem(this._id); - this._dateAdded = PlacesUtils.bookmarks.getItemDateAdded(this._id); - this._lastModified = PlacesUtils.bookmarks.getItemLastModified(this._id); if (this._itemType == Ci.nsINavBookmarksService.TYPE_FOLDER) { this._saveFolderContents(); @@ -512,8 +519,6 @@ placesRemoveItemTransaction.prototype = { this._removeTxn.doTransaction(); } else { - if (this._itemType == Ci.nsINavBookmarksService.TYPE_BOOKMARK) - this._uri = PlacesUtils.bookmarks.getBookmarkURI(this._id); PlacesUtils.bookmarks.removeItem(this._id); if (this._uri) { // if this was the last bookmark (excluding tag-items and livemark @@ -535,6 +540,8 @@ placesRemoveItemTransaction.prototype = { this._title); if (this._tags && this._tags.length > 0) PlacesUtils.tagging.tagURI(this._uri, this._tags); + if (this._keyword) + PlacesUtils.bookmarks.setKeywordForBookmark(this._id, this._keyword); } else if (this._itemType == Ci.nsINavBookmarksService.TYPE_FOLDER) { this._removeTxn.undoTransaction(); diff --git a/browser/components/places/tests/unit/test_placesTxn.js b/browser/components/places/tests/unit/test_placesTxn.js index 4e0abd94b62a..2a4f38410163 100644 --- a/browser/components/places/tests/unit/test_placesTxn.js +++ b/browser/components/places/tests/unit/test_placesTxn.js @@ -291,20 +291,24 @@ function run_test() { do_check_eq(observer._itemAddedParent, root); do_check_eq(observer._itemAddedIndex, 3); - // Test removing an item + // Test removing an item with a keyword + bmsvc.setKeywordForBookmark(bkmk2Id, "test_keyword"); var txn5 = ptSvc.removeItem(bkmk2Id); txn5.doTransaction(); do_check_eq(observer._itemRemovedId, bkmk2Id); do_check_eq(observer._itemRemovedFolder, root); do_check_eq(observer._itemRemovedIndex, 2); + do_check_eq(bmsvc.getKeywordForBookmark(bkmk2Id), null); txn5.undoTransaction(); var newbkmk2Id = observer._itemAddedId; do_check_eq(observer._itemAddedParent, root); do_check_eq(observer._itemAddedIndex, 2); + do_check_eq(bmsvc.getKeywordForBookmark(newbkmk2Id), "test_keyword"); txn5.redoTransaction(); do_check_eq(observer._itemRemovedId, newbkmk2Id); do_check_eq(observer._itemRemovedFolder, root); do_check_eq(observer._itemRemovedIndex, 2); + do_check_eq(bmsvc.getKeywordForBookmark(newbkmk2Id), null); txn5.undoTransaction(); do_check_eq(observer._itemAddedParent, root); do_check_eq(observer._itemAddedIndex, 2);