Bug 1219804 - Show last 5 recent bookmarks in the bookmarks menu. r=mak

This commit is contained in:
Dão Gottwald 2016-02-12 12:21:17 +01:00
Родитель 40c8a880c4
Коммит 52d9a689b0
5 изменённых файлов: 68 добавлений и 2 удалений

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

@ -451,6 +451,10 @@
class="show-only-for-keyboard"
command="Browser:BookmarkAllTabs"
key="bookmarkAllTabsKb"/>
<menuseparator/>
<menuitem label="&recentBookmarks.label;"
disabled="true"/>
<vbox id="menu_recentBookmarks"/>
<menuseparator id="bookmarksToolbarSeparator"/>
<menu id="bookmarksToolbarFolderMenu"
class="menu-iconic bookmark-item"

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

@ -1305,6 +1305,9 @@ var BookmarkingUI = {
return;
}
this._updateRecentBookmarks(document.getElementById("BMB_recentBookmarks"),
"subviewbutton");
if (!this._popupNeedsUpdate)
return;
this._popupNeedsUpdate = false;
@ -1338,6 +1341,60 @@ var BookmarkingUI = {
});
},
_updateRecentBookmarks: function(container, extraCSSClass = "") {
const kMaxResults = 5;
let options = PlacesUtils.history.getNewQueryOptions();
options.excludeQueries = true;
options.queryType = options.QUERY_TYPE_BOOKMARKS;
options.sortingMode = options.SORT_BY_DATE_DESCENDING;
options.maxResults = kMaxResults;
let query = PlacesUtils.history.getNewQuery();
while (container.firstChild) {
container.firstChild.remove();
}
PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase)
.asyncExecuteLegacyQueries([query], 1, options, {
handleResult: function (aResultSet) {
let onItemClick = function (aEvent) {
let item = aEvent.target;
openUILink(item.getAttribute("targetURI"), aEvent);
CustomizableUI.hidePanelForNode(item);
};
let fragment = document.createDocumentFragment();
let row;
while ((row = aResultSet.getNextRow())) {
let uri = row.getResultByIndex(1);
let title = row.getResultByIndex(2);
let icon = row.getResultByIndex(6);
let item =
document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
"menuitem");
item.setAttribute("label", title || uri);
item.setAttribute("targetURI", uri);
item.setAttribute("class", "menuitem-iconic menuitem-with-favicon bookmark-item " +
extraCSSClass);
item.addEventListener("click", onItemClick);
if (icon) {
let iconURL = "moz-anno:favicon:" + icon;
item.setAttribute("image", iconURL);
}
fragment.appendChild(item);
}
container.appendChild(fragment);
},
handleError: function (aError) {
Cu.reportError("Error while attempting to show recent bookmarks: " + aError);
},
handleCompletion: function (aReason) {
},
});
},
/**
* Handles star styling based on page proxy state changes.
*/
@ -1550,6 +1607,7 @@ var BookmarkingUI = {
onMainMenuPopupShowing: function BUI_onMainMenuPopupShowing(event) {
this._updateBookmarkPageMenuItem();
PlacesCommandHook.updateBookmarkAllTabsCommand();
this._updateRecentBookmarks(document.getElementById("menu_recentBookmarks"));
},
_showBookmarkedNotification: function BUI_showBookmarkedNotification() {

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

@ -812,6 +812,11 @@
command="Browser:ShowAllBookmarks"
key="manBookmarkKb"/>
<menuseparator/>
<menuitem label="&recentBookmarks.label;"
disabled="true"
class="subviewbutton"/>
<vbox id="BMB_recentBookmarks"/>
<menuseparator/>
<menu id="BMB_bookmarksToolbar"
class="menu-iconic bookmark-item subviewbutton"
label="&personalbarCmd.label;"

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

@ -184,8 +184,6 @@ const CustomizableWidgets = [
let options = PlacesUtils.history.getNewQueryOptions();
options.excludeQueries = true;
options.includeHidden = false;
options.resultType = options.RESULTS_AS_URI;
options.queryType = options.QUERY_TYPE_HISTORY;
options.sortingMode = options.SORT_BY_DATE_DESCENDING;
options.maxResults = kMaxResults;

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

@ -168,6 +168,7 @@ These should match what Safari and other Apple applications use on OS X Lion. --
<!ENTITY subscribeToPageMenuitem.label "Subscribe to This Page…">
<!ENTITY addCurPagesCmd.label "Bookmark All Tabs…">
<!ENTITY showAllBookmarks2.label "Show All Bookmarks">
<!ENTITY recentBookmarks.label "Recently Bookmarked">
<!ENTITY unsortedBookmarksCmd.label "Unsorted Bookmarks">
<!ENTITY bookmarksToolbarChevron.tooltip "Show more bookmarks">