Bug 401509 (and bug 393947) - Bogus folders listed in save-bookmark/star hanger. r=dietrich.

This commit is contained in:
mozilla.mano%sent.com 2007-12-13 14:20:24 +00:00
Родитель d64adc4ba3
Коммит 1d1b9aedb0
4 изменённых файлов: 63 добавлений и 106 удалений

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

@ -89,7 +89,7 @@
* been performed by the dialog.
*/
const LAST_USED_ANNO = "bookmarkPropertiesDialog/lastUsed";
const LAST_USED_ANNO = "bookmarkPropertiesDialog/folderLastUsed";
const STATIC_TITLE_ANNO = "bookmarks/staticTitle";
// This doesn't include "static" special folders (first two menu items)
@ -113,17 +113,6 @@ var BookmarkPropertiesPanel = {
return this.__strings;
},
/**
* The Microsummary Service for displaying microsummaries.
*/
__mss: null,
get _mss() {
if (!this.__mss)
this.__mss = Cc["@mozilla.org/microsummary/service;1"].
getService(Ci.nsIMicrosummaryService);
return this.__mss;
},
_action: null,
_itemType: null,
_folderId: null,
@ -391,6 +380,15 @@ var BookmarkPropertiesPanel = {
},
_initFolderMenuList: function BPP__initFolderMenuList() {
// Build the static list
var bms = PlacesUtils.bookmarks;
var bmMenuItem = this._element("bookmarksRootItem");
bmMenuItem.label = bms.getItemTitle(PlacesUtils.bookmarksMenuFolderId);
bmMenuItem.folderId = PlacesUtils.bookmarksMenuFolderId;
var toolbarItem = this._element("toolbarFolderItem");
toolbarItem.label = bms.getItemTitle(PlacesUtils.toolbarFolderId);
toolbarItem.folderId = PlacesUtils.toolbarFolderId;
// List of recently used folders:
var annos = PlacesUtils.annotations;
var folderIds = annos.getItemsWithAnnotation(LAST_USED_ANNO, { });
@ -429,7 +427,7 @@ var BookmarkPropertiesPanel = {
}
var defaultItem =
this._getFolderMenuItem(this._defaultInsertionPoint.itemId, true);
this._getFolderMenuItem(this._defaultInsertionPoint.itemId);
// if we fail to get a menuitem for the default insertion point
// use the Bookmarks root
@ -568,8 +566,9 @@ var BookmarkPropertiesPanel = {
var itemToSelect = userEnteredNameField;
try {
this._microsummaries = this._mss.getMicrosummaries(this._bookmarkURI,
this._bookmarkId);
this._microsummaries =
PlacesUtils.microsummaries.getMicrosummaries(this._bookmarkURI,
this._bookmarkId);
}
catch(ex) {
// getMicrosummaries will throw an exception if the page to which the URI
@ -591,7 +590,8 @@ var BookmarkPropertiesPanel = {
var menuItem = this._createMicrosummaryMenuItem(microsummary);
if (this._action == ACTION_EDIT &&
this._mss.isMicrosummary(this._bookmarkId, microsummary))
PlacesUtils.microsummaries
.isMicrosummary(this._bookmarkId, microsummary))
itemToSelect = menuItem;
menupopup.appendChild(menuItem);
@ -840,9 +840,11 @@ var BookmarkPropertiesPanel = {
// microsummary, but the bookmark previously had one, or the user
// selected a microsummary which is not the one the bookmark previously
// had.
if ((newMicrosummary == null && this._mss.hasMicrosummary(itemId)) ||
if ((newMicrosummary == null &&
PlacesUtils.microsummaries.hasMicrosummary(itemId)) ||
(newMicrosummary != null &&
!this._mss.isMicrosummary(itemId, newMicrosummary))) {
!PlacesUtils.microsummaries
.isMicrosummary(itemId, newMicrosummary))) {
transactions.push(
PlacesUtils.ptm.editBookmarkMicrosummary(itemId, newMicrosummary));
}
@ -1007,8 +1009,11 @@ var BookmarkPropertiesPanel = {
else // BOOKMARK_ITEM
createTxn = this._getCreateNewBookmarkTransaction(container, index);
// Mark the containing folder as recently-used
this._markFolderAsRecentlyUsed(container);
// Mark the containing folder as recently-used if it isn't in the static
// list
if (container != PlacesUtils.toolbarFolderId &&
container != PlacesUtils.bookmarksMenuFolderId)
this._markFolderAsRecentlyUsed(container);
// perfrom our transaction do via the transaction manager passed by the
// opener so it can be undone.
@ -1058,14 +1063,7 @@ var BookmarkPropertiesPanel = {
_getFolderIdFromMenuList:
function BPP__getFolderIdFromMenuList() {
var selectedItem = this._folderMenuList.selectedItem
switch (selectedItem.id) {
case "bookmarksRootItem":
return PlacesUtils.bookmarksMenuFolderId;
case "toolbarFolderItem":
return PlacesUtils.toolbarFolderId;
}
var selectedItem = this._folderMenuList.selectedItem;
NS_ASSERT("folderId" in selectedItem,
"Invalid menuitem in the folders-menulist");
return selectedItem.folderId;
@ -1077,29 +1075,17 @@ var BookmarkPropertiesPanel = {
* folder. If the items-count limit (see MAX_FOLDERS_IN_MENU_LIST) is reached,
* the new item replaces the last menu-item.
* @param aFolderId
* The identifier of the bookmarks folder
* @param aCheckStaticFolderItems
* whether or not to also treat the static items at the top of
* menu-list. Note dynamic items get precedence even if this is set to
* true.
* The identifier of the bookmarks folder.
*/
_getFolderMenuItem:
function BPP__getFolderMenuItem(aFolderId, aCheckStaticFolderItems) {
function BPP__getFolderMenuItem(aFolderId) {
var menupopup = this._folderMenuList.menupopup;
// 0: Bookmarks root, 1: toolbar folder, 2: separator
for (var i=3; i < menupopup.childNodes.length; i++) {
for (var i=0; i < menupopup.childNodes.length; i++) {
if (menupopup.childNodes[i].folderId == aFolderId)
return menupopup.childNodes[i];
}
if (aCheckStaticFolderItems) {
if (aFolderId == PlacesUtils.bookmarksMenuFolderId)
return this._element("bookmarksRootItem")
if (aFolderId == PlacesUtils.toolbarFolderId)
return this._element("toolbarFolderItem")
}
// 2 special folders + separator + folder-items-count limit
if (menupopup.childNodes.length == 3 + MAX_FOLDER_ITEM_IN_MENU_LIST)
menupopup.removeChild(menupopup.lastChild);
@ -1129,7 +1115,7 @@ var BookmarkPropertiesPanel = {
folderId == PlacesUtils.bookmarksMenuFolderId))
return;
var folderItem = this._getFolderMenuItem(folderId, false);
var folderItem = this._getFolderMenuItem(folderId);
this._folderMenuList.selectedItem = folderItem;
},

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

@ -133,10 +133,8 @@
<menupopup>
<!-- Static item for special folders -->
<menuitem id="bookmarksRootItem"
label="&bookmarks.bookmarksFolderItem.label;"
class="menuitem-iconic folder-icon"/>
<menuitem id="toolbarFolderItem"
label="&bookmarks.toolbarFolderItem.label;"
class="menuitem-iconic folder-icon"/>
<menuseparator id="foldersSeparator" hidden="true"/>
</menupopup>

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

@ -35,22 +35,11 @@
*
* ***** END LICENSE BLOCK ***** */
const LAST_USED_ANNO = "bookmarkPropertiesDialog/lastUsed";
const LAST_USED_ANNO = "bookmarkPropertiesDialog/folderLastUsed";
const STATIC_TITLE_ANNO = "bookmarks/staticTitle";
const MAX_FOLDER_ITEM_IN_MENU_LIST = 5;
var gEditItemOverlay = {
/**
* The Microsummary Service for displaying microsummaries.
*/
__mss: null,
get _mss() {
if (!this.__mss)
this.__mss = Cc["@mozilla.org/microsummary/service;1"].
getService(Ci.nsIMicrosummaryService);
return this.__mss;
},
_uri: null,
_itemId: -1,
_itemType: -1,
@ -58,6 +47,7 @@ var gEditItemOverlay = {
_microsummaries: null,
_hiddenRows: [],
_observersAdded: false,
_staticFoldersListBuilt: false,
get itemId() {
return this._itemId;
@ -210,14 +200,17 @@ var gEditItemOverlay = {
// Build the static list
var unfiledItem = this._element("unfiledRootItem");
unfiledItem.label = bms.getItemTitle(PlacesUtils.unfiledBookmarksFolderId);
// only show "Unfiled Bookmarks" if the url isn't bookmarked somewhere else
unfiledItem.hidden = aSelectedFolder != PlacesUtils.unfiledBookmarksFolderId;
this._element("bmRootItem").label =
bms.getItemTitle(PlacesUtils.bookmarksMenuFolderId);
this._element("toolbarFolderItem").label =
bms.getItemTitle(PlacesUtils.toolbarFolderId);
if (!this._staticFoldersListBuilt) {
unfiledItem.label = bms.getItemTitle(PlacesUtils.unfiledBookmarksFolderId);
unfiledItem.folderId = PlacesUtils.unfiledBookmarksFolderId;
var bmMenuItem = this._element("bmRootItem");
bmMenuItem.label = bms.getItemTitle(PlacesUtils.bookmarksMenuFolderId);
bmMenuItem.folderId = PlacesUtils.bookmarksMenuFolderId;
var toolbarItem = this._element("toolbarFolderItem");
toolbarItem.label = bms.getItemTitle(PlacesUtils.toolbarFolderId);
toolbarItem.folderId = PlacesUtils.toolbarFolderId;
this._staticFoldersListBuilt = true;
}
// List of recently used folders:
var folderIds = annos.getItemsWithAnnotation(LAST_USED_ANNO, { });
@ -248,7 +241,7 @@ var gEditItemOverlay = {
this._appendFolderItemToMenupopup(menupopup, folders[i].folderId);
}
var defaultItem = this._getFolderMenuItem(aSelectedFolder, true);
var defaultItem = this._getFolderMenuItem(aSelectedFolder);
this._folderMenuList.selectedItem = defaultItem;
// Hide the folders-separator if no folder is annotated as recently-used
@ -327,7 +320,8 @@ var gEditItemOverlay = {
try {
if (this._itemType == Ci.nsINavBookmarksService.TYPE_BOOKMARK &&
!this._readOnly)
this._microsummaries = this._mss.getMicrosummaries(this._uri, -1);
this._microsummaries = PlacesUtils.microsummaries
.getMicrosummaries(this._uri, -1);
}
catch(ex) {
// getMicrosummaries will throw an exception in at least two cases:
@ -348,8 +342,8 @@ var gEditItemOverlay = {
var microsummary = enumerator.getNext()
.QueryInterface(Ci.nsIMicrosummary);
var menuItem = this._createMicrosummaryMenuItem(microsummary);
if (this._mss.isMicrosummary(this._itemId, microsummary))
itemToSelect = menuItem;
if (PlacesUtils.microsummaries
.isMicrosummary(this._itemId, microsummary))
menupopup.appendChild(menuItem);
}
@ -489,9 +483,11 @@ var gEditItemOverlay = {
// has actually changed, i.e. the user selected no microsummary, but the
// bookmark previously had one, or the user selected a microsummary which
// is not the one the bookmark previously had
if ((newMicrosummary == null && this._mss.hasMicrosummary(this._itemId)) ||
if ((newMicrosummary == null &&
PlacesUtils.microsummaries.hasMicrosummary(this._itemId)) ||
(newMicrosummary != null &&
!this._mss.isMicrosummary(this._itemId, newMicrosummary))) {
!PlacesUtils.microsummaries
.isMicrosummary(this._itemId, newMicrosummary))) {
txns.push(ptm.editBookmarkMicrosummary(this._itemId, newMicrosummary));
}
@ -593,16 +589,7 @@ var gEditItemOverlay = {
_getFolderIdFromMenuList:
function EIO__getFolderIdFromMenuList() {
var selectedItem = this._folderMenuList.selectedItem
switch (selectedItem.id) {
case "editBMPanel_unfiledRootItem":
return PlacesUtils.unfiledBookmarksFolderId;
case "editBMPanel_bmRootItem":
return PlacesUtils.bookmarksMenuFolderId;
case "editBMPanel_toolbarFolderItem":
return PlacesUtils.toolbarFolderId;
}
var selectedItem = this._folderMenuList.selectedItem;
NS_ASSERT("folderId" in selectedItem,
"Invalid menuitem in the folders-menulist");
return selectedItem.folderId;
@ -614,31 +601,17 @@ var gEditItemOverlay = {
* folder. If the items-count limit (see MAX_FOLDERS_IN_MENU_LIST) is reached,
* the new item replaces the last menu-item.
* @param aFolderId
* The identifier of the bookmarks folder
* @param aCheckStaticFolderItems
* whether or not to also treat the static items at the top of
* menu-list. Note dynamic items get precedence even if this is set to
* true.
* The identifier of the bookmarks folder.
*/
_getFolderMenuItem:
function EIO__getFolderMenuItem(aFolderId, aCheckStaticFolderItems) {
function EIO__getFolderMenuItem(aFolderId) {
var menupopup = this._folderMenuList.menupopup;
// 0: All Bookmarks, 1: Bookmarks root, 2: toolbar folder, 3: separator
for (var i=4; i < menupopup.childNodes.length; i++) {
for (var i=0; i < menupopup.childNodes.length; i++) {
if (menupopup.childNodes[i].folderId == aFolderId)
return menupopup.childNodes[i];
}
if (aCheckStaticFolderItems) {
if (aFolderId == PlacesUtils.unfiledBookmarksFolderId)
return this._element("unfiledRootItem");
if (aFolderId == PlacesUtils.bookmarksMenuFolderId)
return this._element("bmRootItem");
if (aFolderId == PlacesUtils.toolbarFolderId)
return this._element("toolbarFolderItem");
}
// 3 special folders + separator + folder-items-count limit
if (menupopup.childNodes.length == 4 + MAX_FOLDER_ITEM_IN_MENU_LIST)
menupopup.removeChild(menupopup.lastChild);
@ -654,9 +627,11 @@ var gEditItemOverlay = {
var txn = PlacesUtils.ptm.moveItem(this._itemId, container, -1);
PlacesUtils.ptm.doTransaction(txn);
// Mark the containing folder as recently-used if it isn't the
// "All Bookmarks" root
if (container != PlacesUtils.unfiledBookmarksFolderId)
// Mark the containing folder as recently-used if it isn't in the
// static list
if (container != PlacesUtils.unfiledBookmarksFolderId &&
container != PlacesUtils.toolbarFolderId &&
container != PlacesUtils.bookmarksMenuFolderId)
this._markFolderAsRecentlyUsed(container);
}
@ -677,7 +652,7 @@ var gEditItemOverlay = {
if (this._getFolderIdFromMenuList() == folderId)
return;
var folderItem = this._getFolderMenuItem(folderId, false);
var folderItem = this._getFolderMenuItem(folderId);
this._folderMenuList.selectedItem = folderItem;
folderItem.doCommand();
},
@ -843,7 +818,7 @@ var gEditItemOverlay = {
aNewParent == this._getFolderIdFromMenuList())
return;
var folderItem = this._getFolderMenuItem(aNewParent, false);
var folderItem = this._getFolderMenuItem(aNewParent);
// just setting selectItem _does not_ trigger oncommand, so we don't
// recurse

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

@ -15,8 +15,6 @@
<!ENTITY bookmarks.site_location.accesskey "S">
<!ENTITY bookmarks.loadInSidebar.label "Load this bookmark in the sidebar">
<!ENTITY bookmarks.loadInSidebar.accesskey "o">
<!ENTITY bookmarks.bookmarksFolderItem.label "Bookmarks">
<!ENTITY bookmarks.toolbarFolderItem.label "Bookmarks Toolbar">
<!ENTITY bookmarks.expanderDown.tooltip "Show all the bookmarks folders">
<!ENTITY bookmarks.expanderUp.tooltip "Hide">
<!ENTITY bookmarks.newFolderButton.label "New Folder">