From ab3bd282d9649db1968f5ae36b4702b6b97f7978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A3o=20Gottwald?= Date: Wed, 4 May 2016 16:52:40 +0200 Subject: [PATCH] Bug 1250203 - Re-populate recent bookmarks when a bookmark gets deleted while the menu is open. r=mak --- browser/base/content/browser-places.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/browser/base/content/browser-places.js b/browser/base/content/browser-places.js index 46b86e5c3e7a..65df7ad4df5e 100644 --- a/browser/base/content/browser-places.js +++ b/browser/base/content/browser-places.js @@ -1379,6 +1379,19 @@ var BookmarkingUI = { this._populateRecentBookmarks(aHeaderItem, aExtraCSSClass); }; + this._recentlyBookmarkedObserver = { + QueryInterface: XPCOMUtils.generateQI([ + Ci.nsINavBookmarkObserver, + Ci.nsISupportsWeakReference + ]) + }; + this._recentlyBookmarkedObserver.onItemRemoved = () => { + // Update the menu when a bookmark has been removed. + // The native menubar on Mac doesn't support live update, so this won't + // work there. + this._populateRecentBookmarks(aHeaderItem, aExtraCSSClass); + }; + let updatePlacesContextMenu = (shouldHidePrefUI = false) => { let prefEnabled = !shouldHidePrefUI && Services.prefs.getBoolPref(this.RECENTLY_BOOKMARKED_PREF); document.getElementById("placesContext_showRecentlyBookmarked").hidden = shouldHidePrefUI || prefEnabled; @@ -1402,12 +1415,15 @@ var BookmarkingUI = { updatePlacesContextMenu(true); Services.prefs.removeObserver(this.RECENTLY_BOOKMARKED_PREF, prefObserver, false); + PlacesUtils.bookmarks.removeObserver(this._recentlyBookmarkedObserver); + this._recentlyBookmarkedObserver = null; placesContextMenu.removeEventListener("popupshowing", onPlacesContextMenuShowing); bookmarksMenu.removeEventListener("popuphidden", onBookmarksMenuHidden); } }; Services.prefs.addObserver(this.RECENTLY_BOOKMARKED_PREF, prefObserver, false); + PlacesUtils.bookmarks.addObserver(this._recentlyBookmarkedObserver, true); placesContextMenu.addEventListener("popupshowing", onPlacesContextMenuShowing); bookmarksMenu.addEventListener("popuphidden", onBookmarksMenuHidden); },