Bug 1250203 - Re-populate recent bookmarks when a bookmark has been deleted. r=mak
☠☠ backed out by 9c492faa4c39 ☠ ☠
authorDão Gottwald <dao@mozilla.com>
Fri, 08 Apr 2016 16:33:21 +0200
changeset 348997 81df156cb345cc8a11b46c4f11783c03047c4694
parent 348996 603e3444222259d97127198c5e3371fc087f7888
child 348998 8ec9a8049a25241fbe1cdce921baf41a9d2010eb
push id14989
push userdtownsend@mozilla.com
push dateFri, 08 Apr 2016 20:09:09 +0000
reviewersmak
bugs1250203
milestone48.0a1
Bug 1250203 - Re-populate recent bookmarks when a bookmark has been deleted. r=mak
browser/base/content/browser-places.js
--- a/browser/base/content/browser-places.js
+++ b/browser/base/content/browser-places.js
@@ -1402,16 +1402,43 @@ var BookmarkingUI = {
       item.addEventListener("command", onItemCommand);
       if (icon) {
         item.setAttribute("image", icon);
       }
       fragment.appendChild(item);
     }
     root.containerOpen = false;
     aHeaderItem.parentNode.insertBefore(fragment, aHeaderItem.nextSibling);
+
+    // Update the menu when a bookmark is being removed.
+    // The native menubar on Mac doesn't support live update, so this won't
+    // work there.
+    let observer = {
+      onItemAdded() {},
+      onBeginUpdateBatch() {},
+      onEndUpdateBatch() {},
+      onItemRemoved() {
+        removeObserver();
+        BookmarkingUI._updateRecentBookmarks(aHeaderItem, extraCSSClass);
+      },
+      onItemChanged() {},
+      onItemVisited() {},
+      onItemMoved() {}
+    };
+    PlacesUtils.bookmarks.addObserver(observer, false);
+
+    let popup = aHeaderItem.parentNode;
+    let removeObserver = function (event) {
+      if (event && event.target != popup) {
+        return;
+      }
+      PlacesUtils.bookmarks.removeObserver(observer);
+      popup.removeEventListener("popuphidden", removeObserver);
+    };
+    popup.addEventListener("popuphidden", removeObserver);
   },
 
   /**
    * Handles star styling based on page proxy state changes.
    */
   onPageProxyStateChanged: function BUI_onPageProxyStateChanged(aState) {
     if (!this._shouldUpdateStarState() || !this.star) {
       return;