Bug 1248268 - Add option for disabling the "Recently Bookmarked" UI. r=mak

This commit is contained in:
Dão Gottwald 2016-04-29 13:43:59 +02:00
Родитель 8f53f7d6cc
Коммит ac879e2e39
5 изменённых файлов: 116 добавлений и 11 удалений

Просмотреть файл

@ -496,6 +496,8 @@ pref("browser.bookmarks.autoExportHTML", false);
// 0: no backups created (and deletes all existing backups)
pref("browser.bookmarks.max_backups", 15);
pref("browser.bookmarks.showRecentlyBookmarked", true);
// Scripts & Windows prefs
pref("dom.disable_open_during_load", true);
pref("javascript.options.showInConsole", true);

Просмотреть файл

@ -1326,8 +1326,8 @@ var BookmarkingUI = {
return;
}
this._updateRecentBookmarks(document.getElementById("BMB_recentBookmarks"),
"subviewbutton");
this._initRecentBookmarks(document.getElementById("BMB_recentBookmarks"),
"subviewbutton");
if (!this._popupNeedsUpdate)
return;
@ -1362,7 +1362,68 @@ var BookmarkingUI = {
});
},
_updateRecentBookmarks: function(aHeaderItem, extraCSSClass = "") {
RECENTLY_BOOKMARKED_PREF: "browser.bookmarks.showRecentlyBookmarked",
_initRecentBookmarks(aHeaderItem, aExtraCSSClass) {
this._populateRecentBookmarks(aHeaderItem, aExtraCSSClass);
// Add observers and listeners and remove them again when the menupopup closes.
let bookmarksMenu = aHeaderItem.parentNode;
let placesContextMenu = document.getElementById("placesContext");
let prefObserver = () => {
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;
document.getElementById("placesContext_hideRecentlyBookmarked").hidden = shouldHidePrefUI || !prefEnabled;
document.getElementById("placesContext_recentlyBookmarkedSeparator").hidden = shouldHidePrefUI;
};
let onPlacesContextMenuShowing = event => {
if (event.target == event.currentTarget) {
let triggerPopup = event.target.triggerNode;
while (triggerPopup && triggerPopup.localName != "menupopup") {
triggerPopup = triggerPopup.parentNode;
}
let shouldHidePrefUI = triggerPopup != bookmarksMenu;
updatePlacesContextMenu(shouldHidePrefUI);
}
};
let onBookmarksMenuHidden = event => {
if (event.target == event.currentTarget) {
updatePlacesContextMenu(true);
Services.prefs.removeObserver(this.RECENTLY_BOOKMARKED_PREF, prefObserver, false);
placesContextMenu.removeEventListener("popupshowing", onPlacesContextMenuShowing);
bookmarksMenu.removeEventListener("popuphidden", onBookmarksMenuHidden);
}
};
Services.prefs.addObserver(this.RECENTLY_BOOKMARKED_PREF, prefObserver, false);
placesContextMenu.addEventListener("popupshowing", onPlacesContextMenuShowing);
bookmarksMenu.addEventListener("popuphidden", onBookmarksMenuHidden);
},
_populateRecentBookmarks(aHeaderItem, aExtraCSSClass = "") {
while (aHeaderItem.nextSibling &&
aHeaderItem.nextSibling.localName == "menuitem") {
aHeaderItem.nextSibling.remove();
}
let shouldShow = Services.prefs.getBoolPref(this.RECENTLY_BOOKMARKED_PREF);
let separator = aHeaderItem.previousSibling;
aHeaderItem.hidden = !shouldShow;
separator.hidden = !shouldShow;
if (!shouldShow) {
return;
}
const kMaxResults = 5;
let options = PlacesUtils.history.getNewQueryOptions();
@ -1372,11 +1433,6 @@ var BookmarkingUI = {
options.maxResults = kMaxResults;
let query = PlacesUtils.history.getNewQuery();
while (aHeaderItem.nextSibling &&
aHeaderItem.nextSibling.localName == "menuitem") {
aHeaderItem.nextSibling.remove();
}
let onItemCommand = function (aEvent) {
let item = aEvent.target;
openUILink(item.getAttribute("targetURI"), aEvent);
@ -1397,8 +1453,9 @@ var BookmarkingUI = {
"menuitem");
item.setAttribute("label", title || uri);
item.setAttribute("targetURI", uri);
item.setAttribute("context", "hideRecentlyBookmarked");
item.setAttribute("class", "menuitem-iconic menuitem-with-favicon bookmark-item " +
extraCSSClass);
aExtraCSSClass);
item.addEventListener("command", onItemCommand);
if (icon) {
item.setAttribute("image", icon);
@ -1407,6 +1464,15 @@ var BookmarkingUI = {
}
root.containerOpen = false;
aHeaderItem.parentNode.insertBefore(fragment, aHeaderItem.nextSibling);
aHeaderItem.setAttribute("context", "hideRecentlyBookmarked");
},
showRecentlyBookmarked() {
Services.prefs.setBoolPref(this.RECENTLY_BOOKMARKED_PREF, true);
},
hideRecentlyBookmarked() {
Services.prefs.setBoolPref(this.RECENTLY_BOOKMARKED_PREF, false);
},
/**
@ -1625,7 +1691,7 @@ var BookmarkingUI = {
this._updateBookmarkPageMenuItem();
PlacesCommandHook.updateBookmarkAllTabsCommand();
this._updateRecentBookmarks(document.getElementById("menu_recentBookmarks"));
this._initRecentBookmarks(document.getElementById("menu_recentBookmarks"));
},
_showBookmarkedNotification: function BUI_showBookmarkedNotification() {

Просмотреть файл

@ -383,7 +383,35 @@
#include browser-context.inc
</menupopup>
<menupopup id="placesContext"/>
<menupopup id="placesContext">
<menuseparator id="placesContext_recentlyBookmarkedSeparator"
ignoreitem="true"
ordinal="2"
hidden="true"/>
<menuitem id="placesContext_hideRecentlyBookmarked"
label="&hideRecentlyBookmarked.label;"
accesskey="&hideRecentlyBookmarked.accesskey;"
oncommand="BookmarkingUI.hideRecentlyBookmarked();"
closemenu="single"
ignoreitem="true"
ordinal="2"
hidden="true"/>
<menuitem id="placesContext_showRecentlyBookmarked"
label="&showRecentlyBookmarked.label;"
accesskey="&showRecentlyBookmarked.accesskey;"
oncommand="BookmarkingUI.showRecentlyBookmarked();"
closemenu="single"
ignoreitem="true"
ordinal="2"
hidden="true"/>
</menupopup>
<menupopup id="hideRecentlyBookmarked">
<menuitem label="&hideRecentlyBookmarked.label;"
accesskey="&hideRecentlyBookmarked.accesskey;"
oncommand="BookmarkingUI.hideRecentlyBookmarked();"
closemenu="single"/>
</menupopup>
<panel id="ctrlTab-panel" class="KUI-panel" hidden="true" norestorefocus="true" level="top">
<hbox>

Просмотреть файл

@ -560,6 +560,8 @@ PlacesController.prototype = {
* Detects information (meta-data rules) about the current selection in the
* view (see _buildSelectionMetadata) and sets the visibility state for each
* of the menu-items in the given popup with the following rules applied:
* 0) The "ignoreitem" attribute may be set to "true" for this code not to
* handle that menuitem.
* 1) The "selectiontype" attribute may be set on a menu-item to "single"
* if the menu-item should be visible only if there is a single node
* selected, or to "multiple" if the menu-item should be visible only if
@ -601,6 +603,9 @@ PlacesController.prototype = {
var usableItemCount = 0;
for (var i = 0; i < aPopup.childNodes.length; ++i) {
var item = aPopup.childNodes[i];
if (item.getAttribute("ignoreitem") == "true") {
continue;
}
if (item.localName != "menuseparator") {
// We allow pasting into tag containers, so special case that.
var hideIfNoIP = item.getAttribute("hideifnoinsertionpoint") == "true" &&

Просмотреть файл

@ -171,6 +171,10 @@ These should match what Safari and other Apple applications use on OS X Lion. --
<!ENTITY recentBookmarks.label "Recently Bookmarked">
<!ENTITY otherBookmarksCmd.label "Other Bookmarks">
<!ENTITY bookmarksToolbarChevron.tooltip "Show more bookmarks">
<!ENTITY showRecentlyBookmarked.label "Show Recently Bookmarked">
<!ENTITY showRecentlyBookmarked.accesskey "h">
<!ENTITY hideRecentlyBookmarked.label "Hide Recently Bookmarked">
<!ENTITY hideRecentlyBookmarked.accesskey "H">
<!ENTITY backCmd.label "Back">
<!ENTITY backButton.tooltip "Go back one page">