Bug 372508 - compact the bookmark APIs - part 1. r=sspitzer.

This commit is contained in:
mozilla.mano@sent.com 2007-05-10 11:18:34 -07:00
parent 095492e4a3
commit 769a716f84
11 changed files with 242 additions and 564 deletions

View File

@ -338,12 +338,8 @@ var gBookmarksObserver = {
},
onItemVisited: function() { },
onFolderAdded: function() { },
onFolderRemoved: function() { },
onFolderMoved: function() { },
onFolderChanged: function() { },
onSeparatorAdded: function() { },
onSeparatorRemoved: function() { }
};
/**

View File

@ -301,7 +301,7 @@ var BookmarkPropertiesPanel = {
}
else
this._itemType = BOOKMARK_FOLDER;
this._itemTitle = bookmarks.getFolderTitle(this._folderId);
this._itemTitle = bookmarks.getItemTitle(this._folderId);
break;
}
@ -370,7 +370,7 @@ var BookmarkPropertiesPanel = {
this._element("foldersSeparator").hidden = false;
var folderMenuItem = document.createElement("menuitem");
var folderTitle = PlacesUtils.bookmarks.getFolderTitle(aFolderId)
var folderTitle = PlacesUtils.bookmarks.getItemTitle(aFolderId)
folderMenuItem.folderId = aFolderId;
folderMenuItem.setAttribute("label", folderTitle);
folderMenuItem.className = "menuitem-iconic folder-icon";
@ -691,12 +691,7 @@ var BookmarkPropertiesPanel = {
*/
_getEditTitleTransaction:
function BPP__getEditTitleTransaction(aItemId, aNewTitle) {
// XXXmano: remove this once bug 372508 is fixed
if (this._itemType == BOOKMARK_ITEM)
return new PlacesEditItemTitleTransaction(aItemId, aNewTitle);
// folder or livemark container
return new PlacesEditFolderTitleTransaction(aItemId, aNewTitle);
},
/**

View File

@ -1923,7 +1923,7 @@ PlacesRemoveFolderTransaction.prototype = {
},
doTransaction: function PRFT_doTransaction() {
var title = this.bookmarks.getFolderTitle(this._id);
var title = this.bookmarks.getItemTitle(this._id);
this.LOG("Remove Folder: " + title);
this._saveFolderContents();
@ -1939,7 +1939,7 @@ PlacesRemoveFolderTransaction.prototype = {
undoTransaction: function PRFT_undoTransaction() {
this._removeTxn.undoTransaction();
var title = this.bookmarks.getFolderTitle(this._id);
var title = this.bookmarks.getItemTitle(this._id);
this.LOG("UNRemove Folder: " + title);
// Create children forwards to preserve parent-child relationships.
@ -2126,28 +2126,6 @@ PlacesEditItemDescriptionTransaction.prototype = {
}
};
/**
* Edit a folder's title.
*/
function PlacesEditFolderTitleTransaction(id, newTitle) {
this.id = id;
this._newTitle = newTitle;
this._oldTitle = "";
this.redoTransaction = this.doTransaction;
}
PlacesEditFolderTitleTransaction.prototype = {
__proto__: PlacesBaseTransaction.prototype,
doTransaction: function PEFTT_doTransaction() {
this._oldTitle = this.bookmarks.getFolderTitle(this.id);
this.bookmarks.setFolderTitle(this.id, this._newTitle);
},
undoTransaction: function PEFTT_undoTransaction() {
this.bookmarks.setFolderTitle(this.id, this._oldTitle);
}
};
/**
* Edit a bookmark's keyword.
*/

View File

@ -67,7 +67,7 @@
class="placesTree"
flex="1"
type="places"
place="place:folder=1&group=3&excludeItems=1&excludeQueries=1&excludeReadOnlyFolders=1"
place="place:folder=2&group=3&excludeItems=1&excludeReadOnlyFolders=1"
hidecolumnpicker="true">
<treecols>
<treecol id="title" flex="1" primary="true" hideheader="true"/>

View File

@ -502,7 +502,7 @@ var PlacesUtils = {
var itemURL = bookmarks.getBookmarkURI(aId);
var itemTitle = bookmarks.getItemTitle(aId);
var keyword = bookmarks.getKeywordForBookmark(aId);
var annos = this.getAnnotationsForURI(bookmarks.getItemURI(aId));
var annos = this.getAnnotationsForItem(aId);
if (aExcludeAnnotations) {
annos =
annos.filter(function(aValue, aIndex, aArray) {
@ -538,7 +538,7 @@ var PlacesUtils = {
var node = children.getChild(i);
if (self.nodeIsFolder(node)) {
var nodeFolderId = asFolder(node).folderId;
var title = self.bookmarks.getFolderTitle(nodeFolderId);
var title = self.bookmarks.getItemTitle(nodeFolderId);
// XXXmano: use item-annotations once bug 372508 is fixed
var annos = self.getAnnotationsForURI(self._uri(node.uri));
var folderItemsTransactions =
@ -565,7 +565,7 @@ var PlacesUtils = {
return childItemsTransactions;
}
var title = this.bookmarks.getFolderTitle(aData.id);
var title = this.bookmarks.getItemTitle(aData.id);
var annos = this.getAnnotationsForItem(aData.id);
var createTxn =
new PlacesCreateFolderTransaction(title, aContainer, aIndex, annos,

View File

@ -856,8 +856,8 @@ BookmarkContentSink::HandleLinkEnd()
NS_ASSERTION(NS_SUCCEEDED(rv), "SetSiteURI failed!");
rv = mLivemarkService->SetFeedURI(frame.mPreviousId, frame.mPreviousFeed);
NS_ASSERTION(NS_SUCCEEDED(rv), "SetFeedURI failed!");
rv = mBookmarksService->SetFolderTitle(frame.mPreviousId, frame.mPreviousText);
NS_ASSERTION(NS_SUCCEEDED(rv), "SetFolderTitle failed!");
rv = mBookmarksService->SetItemTitle(frame.mPreviousId, frame.mPreviousText);
NS_ASSERTION(NS_SUCCEEDED(rv), "SetItemTitle failed!");
} else {
if (mIsImportDefaults) {
rv = mLivemarkService->CreateLivemarkFolderOnly(mBookmarksService,
@ -913,8 +913,10 @@ BookmarkContentSink::HandleSeparator()
PrintNesting();
printf("--------\n");
#endif
PRInt64 itemId;
mBookmarksService->InsertSeparator(frame.mContainerID,
mBookmarksService->DEFAULT_INDEX);
mBookmarksService->DEFAULT_INDEX,
&itemId);
}
}
@ -1000,7 +1002,7 @@ BookmarkContentSink::NewFrame()
if (updateFolder) {
// move the menu folder to the current position
mBookmarksService->MoveFolder(ourID, CurFrame().mContainerID, -1);
mBookmarksService->SetFolderTitle(ourID, containerName);
mBookmarksService->SetItemTitle(ourID, containerName);
#ifdef DEBUG_IMPORT
printf(" [reparenting]");
#endif
@ -1456,7 +1458,7 @@ nsPlacesImportExportService::WriteContainerTitle(PRInt64 aFolder, nsIOutputStrea
nsAutoString title;
nsresult rv;
rv = mBookmarksService->GetFolderTitle(aFolder, title);
rv = mBookmarksService->GetItemTitle(aFolder, title);
NS_ENSURE_SUCCESS(rv, rv);
char* escapedTitle = nsEscapeHTML(NS_ConvertUTF16toUTF8(title).get());
@ -1764,7 +1766,7 @@ nsPlacesImportExportService::WriteContainerContents(PRInt64 aFolder, const nsACS
// bookmarks folder
nsCOMPtr<nsINavHistoryFolderResultNode> folderNode = do_QueryInterface(child);
PRInt64 folderId;
rv = folderNode->GetFolderId(&folderId);
rv = folderNode->GetItemId(&folderId);
NS_ENSURE_SUCCESS(rv, rv);
if (aFolder == mPlacesRoot && (folderId == mToolbarFolder ||
folderId == mBookmarksRoot)) {

View File

@ -54,7 +54,7 @@ interface nsITransaction;
* Observer for bookmark changes.
*/
[scriptable, uuid(582af67b-cde2-4dc2-9ef5-9eb79e224135)]
[scriptable, uuid(b3576cd9-d6f0-4faa-9b5d-cf7a9204dce9)]
interface nsINavBookmarkObserver : nsISupports
{
/**
@ -71,33 +71,33 @@ interface nsINavBookmarkObserver : nsISupports
void onEndUpdateBatch();
/**
* Notify this observer that the bookmark was added. Called after the actual
* add took place. The rest of the bookmarks will be shifted down, but no
* additional notifications will be sent.
* Notify this observer that an item was added. Called after the actual
* add took place. The items following the index will be shifted down, but
* no additional notifications will be sent.
*
* @param aBookmarkId
* @param aItemId
* The id of the bookmark that was added.
* @param aFolder
* The folder that the item was added to.
* @param aIndex
* The item's index in the folder.
*/
void onItemAdded(in long long aBookmarkId, in long long aFolder,
void onItemAdded(in long long aItemId, in long long aFolder,
in long aIndex);
/**
* Notify this observer that the bookmark was removed. Called after the
* actual remove took place. The bookmarks following the index will be
* shifted up, but no additional notifications will be sent.
* Notify this observer that an item was removed. Called after the actual
* remove took place. The items following the index will be shifted up, but
* no additional notifications will be sent.
*
* @param aBookmarkId
* @param aItemId
* The id of the bookmark that was removed.
* @param aFolder
* The folder that the item was removed from.
* @param aIndex
* The bookmark's index in the folder.
*/
void onItemRemoved(in long long aBookmarkId, in long long aFolder,
void onItemRemoved(in long long aItemId, in long long aFolder,
in long aIndex);
/**
@ -136,30 +136,6 @@ interface nsINavBookmarkObserver : nsISupports
void onItemVisited(in long long aBookmarkId, in long long aVisitID,
in PRTime time);
/**
* Notify this observer that a bookmark folder has been added.
* @param aFolder
* The id of the folder that was added.
* @param aParent
* The id of the folder's parent.
* @param aIndex
* The folder's index inside its parent.
*/
void onFolderAdded(in long long aFolder, in long long aParent,
in long aIndex);
/**
* Notify this observer that a bookmark folder has been removed.
* @param aFolder
* The id of the folder that was removed.
* @param aParent
* The id of the folder's old parent.
* @param aIndex
* The folder's old index in its parent.
*/
void onFolderRemoved(in long long aFolder, in long long aParent,
in long aIndex);
/**
* Notify this observer that a bookmark folder has been moved.
* @param aFolder
@ -186,24 +162,6 @@ interface nsINavBookmarkObserver : nsISupports
* The property that was changed.
*/
void onFolderChanged(in long long aFolder, in ACString aProperty);
/**
* Notify this observer that a separator has been added.
* @param aParent
* The id of the separator's parent.
* @param aIndex
* The separator's index inside its parent.
*/
void onSeparatorAdded(in long long aParent, in long aIndex);
/**
* Notify this observer that a separator has been removed.
* @param aParent
* The id of the separator's parent.
* @param aIndex
* The separator's old index in its parent.
*/
void onSeparatorRemoved(in long long aParent, in long aIndex);
};
/**
@ -212,18 +170,18 @@ interface nsINavBookmarkObserver : nsISupports
* folders. A URI in history can be contained in one or more such folders.
*/
[scriptable, uuid(7c2f2c2a-fccb-11db-8314-0800200c9a66)]
[scriptable, uuid(d0dcc4b9-3f41-4489-aec5-117f8ed26a68)]
interface nsINavBookmarksService : nsISupports
{
/**
* The folder ID of the Places root.
*/
readonly attribute PRInt64 placesRoot;
readonly attribute long long placesRoot;
/**
* The folder ID of the bookmarks root.
*/
readonly attribute PRInt64 bookmarksRoot;
readonly attribute long long bookmarksRoot;
/**
* The folder ID of the top-level folders that contain the tag "folders".
@ -231,12 +189,12 @@ interface nsINavBookmarksService : nsISupports
* NOTE: This isn't wired up yet, so don't try to use it for anything until
* bug 329961 is marked resolved.
*/
readonly attribute PRInt64 tagRoot;
readonly attribute long long tagRoot;
/**
* The folder ID of the personal toolbar.
*/
attribute PRInt64 toolbarFolder;
attribute long long toolbarFolder;
/**
* This value should be used for APIs that allow passing in an index
@ -245,59 +203,74 @@ interface nsINavBookmarksService : nsISupports
*/
const short DEFAULT_INDEX = -1;
const short TYPE_BOOKMARK = 1;
const short TYPE_FOLDER = 2;
const short TYPE_SEPARATOR = 3;
const unsigned short TYPE_BOOKMARK = 1;
const unsigned short TYPE_FOLDER = 2;
const unsigned short TYPE_SEPARATOR = 3;
/**
* Inserts a child item into the given folder. If this item already exists in
* the given folder, it will be moved to the new position.
* @param folder The id of the parent folder
* @param item The URI to insert
* @param index The index to insert at, or -1 to append
* @param aParentFolder
* The id of the parent folder
* @param aURI
* The URI to insert
* @param aIndex
* The index to insert at, or -1 to append
* @returns The ID of the newly-created bookmark
*/
PRInt64 insertItem(in PRInt64 folder, in nsIURI item, in PRInt32 index);
long long insertItem(in long long aParentFolder, in nsIURI aURI,
in long aIndex);
/**
* Removes a child item. Used to delete a bookmark or separator.
* @param bookmarkId The child item to remove
* @param aItemId
* The child item to remove
*/
void removeItem(in PRInt64 bookmarkId);
void removeItem(in long long aItemId);
/**
* Creates a new child folder and inserts it under the given parent.
* @param parent The id of the parent folder
* @param name The name of the new folder
* @param index The index to insert at, or -1 to append
* @param aParentFolder
* The id of the parent folder
* @param aName
* The name of the new folder
* @param aIndex
* The index to insert at, or -1 to append
* @returns the ID of the newly-inserted folder
*/
PRInt64 createFolder(in PRInt64 parent, in AString name, in PRInt32 index);
long long createFolder(in long long aParentFolder, in AString name,
in long index);
/**
* Wrapper for container services. Creates a folder under the given
* parent and sets the container type. Containers are wrappers around
* read-only folders, with a specific type.
*
* @param parent The id of the parent folder
* @param name The name of the new folder
* @param type The type of container to insert
* @param index The index to insert at, or -1 to append
* @param aParentFolder
* The id of the parent folder
* @param aName
* The name of the new folder
* @param aType
* The type of container to insert
* @param aIndex
* The index to insert at, or -1 to append
* @returns the ID of the newly-inserted folder
*/
PRInt64 createContainer(in PRInt64 parent, in AString name,
in AString type, in PRInt32 index);
long long createContainer(in long long aParentFolder, in AString aName,
in AString aType, in long aIndex);
/**
* Removes a folder from the bookmarks tree.
* @param folder The id of the folder to remove.
* @param aFolder
* The id of the folder to remove.
*/
void removeFolder(in PRInt64 folder);
void removeFolder(in long long aFolder);
/**
* Gets an undo-able transaction for removing a folder from the bookmarks
* tree.
* @param folder The id of the folder to remove.
* @param folder
* The id of the folder to remove.
* @returns An object implementing nsITransaction that can be used to undo
* or redo the action.
*
@ -309,114 +282,105 @@ interface nsINavBookmarksService : nsISupports
* specific IDs (potentially dangerous if abused by other code!) in the
* public API.
*/
nsITransaction getRemoveFolderTransaction(in PRInt64 folder);
nsITransaction getRemoveFolderTransaction(in long long aFolder);
/**
* Convenience function for container services. Removes
* all children of the given folder.
* @param folder The id of the folder to remove children from.
* @param aFolder
* The id of the folder to remove children from.
*/
void removeFolderChildren(in PRInt64 folder);
void removeFolderChildren(in long long aFolder);
/**
* Moves a folder to a different container, preserving its contents.
* @param folder The folder to move
* @param newParent The id of the folder's new parent
* @param index The folder's index under newParent, or -1 to append
* @param aFolder
* The folder to move
* @param aNewParent
* The id of the folder's new parent
* @param aIndex
* The folder's index under newParent, or -1 to append
*/
void moveFolder(in PRInt64 folder, in PRInt64 newParent, in PRInt32 index);
void moveFolder(in long long aFolder, in long long newParent, in long aIndex);
/**
* Returns the ID of a child folder with the given name. This does not
* recurse, you have to give it an immediate sibling of the given folder.
* If the given subfolder doesn't exist, it will return 0.
* @param folder Parent folder whose children we will search
* @param subFolder Name of the folder to search for in folder
* @param aFolder
* Parent folder whose children we will search
* @param aSubFolder
* Name of the folder to search for in folder
*/
PRInt64 getChildFolder(in PRInt64 folder, in AString subFolder);
long long getChildFolder(in long long aFolder, in AString aSubFolder);
/**
* Inserts a bookmark separator into the given folder at the given index.
* The separator can be removed using removeChildAt().
* @param folder Parent folder of the separator
* @param index The separator's index under folder, or -1 to append
* @param aFolder
* Parent folder of the separator
* @param aIndex
* The separator's index under folder, or -1 to append
* @returns the id of the new separator
*/
void insertSeparator(in PRInt64 folder, in PRInt32 index);
long long insertSeparator(in long long aFolder, in long aIndex);
/**
* Removes any type of child (item, folder, or separator) at the given index.
* @param folder The folder to remove a child from
* @param index The index of the child to remove
* @param aFolder
* The folder to remove a child from
* @param aIndex
* The index of the child to remove
*/
void removeChildAt(in PRInt64 folder, in PRInt32 index);
void removeChildAt(in long long aFolder, in long aIndex);
/**
* Set the title for a bookmark.
* @param id The id of the item whose title should be updated
* @param title The new title for the bookmark.
* Set the title for an item.
* @param aItemId
* The id of the item whose title should be updated
* @param aTitle
* The new title for the bookmark.
*/
void setItemTitle(in PRInt64 id, in AString title);
void setItemTitle(in long long aItemId, in AString aTitle);
/**
* Get the title for the bookmark.
* Get the title for an item.
*
* If no item title is available it will return a void string (null in JS).
*
* @param id The id of the item whose title should be retrieved
* @param aItemId
* The id of the item whose title should be retrieved
* @returns The title of the item.
*/
AString getItemTitle(in PRInt64 id);
AString getItemTitle(in long long aItemId);
/**
* Get the URI for a bookmark item.
*/
nsIURI getBookmarkURI(in PRInt64 id);
nsIURI getBookmarkURI(in long long aItemId);
/**
* Get the index for an item.
*/
PRInt32 getItemIndex(in PRInt64 id);
/**
* Set the title for a bookmark folder.
* @param folder The folder whose title should be set
* @param title The new title for the folder
*/
void setFolderTitle(in PRInt64 folder, in AString title);
/**
* Get the title for a bookmark folder. Throws an invalid argument
* exception if it can't find a folder with the given ID.
*
* @param folder The folder whose title should be retrieved
* @returns The title for the folder
*/
AString getFolderTitle(in PRInt64 folder);
long getItemIndex(in long long aItemId);
/**
* Get the place: url for a bookmark folder. You can use this value to
* get/set the icon for a folder or to associate other data with it using
* the annotation service. Its important that you use this function instead
* of just serializing the query/options for a given folder because you
* may have different options or query parameters. This function will give
* the canonical value.
* @param folder The folder whose URI should be retrieved
* get/set the icon for a folder. Its important that you use this function
* instead of just serializing the query/options for a given folder because
* you may have different options or query parameters. This function will
* give the canonical value.
* @param aFolder
* The folder whose URI should be retrieved
* @returns The URI for the folder
*/
nsIURI getFolderURI(in PRInt64 folder);
nsIURI getFolderURI(in long long aFolder);
/**
* Get an item's type (bookmark, separator, folder).
* The type is one of the TYPE_* constants defined above.
*/
long getItemType(in PRInt64 itemId);
/**
* Get the place: url for an item (bookmark, separator).
* This can be used for annotating bookmark items.
* NOTE: this is not currently supported in the query framework.
*/
nsIURI getItemURI(in PRInt64 itemId);
unsigned short getItemType(in long long aItemId);
/**
* Checks whether a folder has read-only children. This property is
@ -424,13 +388,13 @@ interface nsINavBookmarksService : nsISupports
* If this is set to true, UI should not allow the user to add, remove,
* or reorder children in this folder. The default for all folders is false.
*/
boolean getFolderReadonly(in PRInt64 folder);
boolean getFolderReadonly(in long long aFolder);
/**
* Returns true if the given URI is in any bookmark folder. If you want the
* results to be redirect-aware, use getBookmarkedURIFor()
*/
boolean isBookmarked(in nsIURI uri);
boolean isBookmarked(in nsIURI aURI);
/**
* Used to see if the given URI is bookmarked, or any page that redirected to
@ -442,25 +406,25 @@ interface nsINavBookmarksService : nsISupports
*
* If there is no bookmarked page found, it will return NULL.
*/
nsIURI getBookmarkedURIFor(in nsIURI uri);
nsIURI getBookmarkedURIFor(in nsIURI aURI);
/**
* Change the bookmarked URI for a bookmark.
* This changes which "place" the bookmark points at,
* which means all annotations, etc are carried along.
*/
void changeBookmarkURI(in PRInt64 id, in nsIURI newURI);
void changeBookmarkURI(in long long aItemId, in nsIURI aNewURI);
/**
* Get the parent folder's id for an item.
*/
PRInt64 getFolderIdForItem(in PRInt64 id);
long long getFolderIdForItem(in PRInt64 aItemId);
/**
* Returns the list of bookmark ids that contain the given URI.
*/
void getBookmarkIdsForURI(in nsIURI uri, out PRUint32 count,
[array, retval, size_is(count)] out PRInt64 bookmarks);
void getBookmarkIdsForURI(in nsIURI aURI, out unsigned long count,
[array, retval, size_is(count)] out long long bookmarks);
/**
* TArray version of getBookmarksIdForURI for ease of use in C++ code.
@ -476,19 +440,19 @@ interface nsINavBookmarksService : nsISupports
* Use an empty keyword to clear the keyword associated with the URI.
* In both of these cases, succeeds but does nothing if the URL/keyword is not found.
*/
void setKeywordForBookmark(in PRInt64 bookmarkId, in AString keyword);
void setKeywordForBookmark(in long long aItemId, in AString aKeyword);
/**
* Retrieves the keyword for the given URI. Will be void string
* (null in JS) if no such keyword is found.
*/
AString getKeywordForURI(in nsIURI uri);
AString getKeywordForURI(in nsIURI aURI);
/**
* Retrieves the keyword for the given bookmark. Will be void string
* (null in JS) if no such keyword is found.
*/
AString getKeywordForBookmark(in PRInt64 bookmarkId);
AString getKeywordForBookmark(in long long aItemId);
/**
* Returns the URI associated with the given keyword. Empty if no such

View File

@ -426,7 +426,7 @@ nsNavBookmarks::InitDefaults()
nsresult rv = mBundle->GetStringFromName(NS_LITERAL_STRING("PlacesBookmarksRootTitle").get(),
getter_Copies(bookmarksTitle));
NS_ENSURE_SUCCESS(rv, rv);
rv = SetFolderTitle(mBookmarksRoot, bookmarksTitle);
rv = SetItemTitle(mBookmarksRoot, bookmarksTitle);
NS_ENSURE_SUCCESS(rv, rv);
// create toolbar folder, parent bookmarks root, entitled "Bookmarks Toolbar Folder"
@ -1068,7 +1068,7 @@ nsNavBookmarks::CreateFolderWithID(PRInt64 aFolder, PRInt64 aParent,
// CreateContainerWithID rather than here.
if (aSendNotifications) {
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
OnFolderAdded(id, aParent, index))
OnItemAdded(id, aParent, index))
}
*aIndex = index;
@ -1106,15 +1106,17 @@ nsNavBookmarks::CreateContainerWithID(PRInt64 aFolder, PRInt64 aParent,
// Send notifications after folder type has been set.
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
OnFolderAdded(*aNewFolder, aParent, localIndex))
OnItemAdded(*aNewFolder, aParent, localIndex))
return NS_OK;
}
NS_IMETHODIMP
nsNavBookmarks::InsertSeparator(PRInt64 aParent, PRInt32 aIndex)
nsNavBookmarks::InsertSeparator(PRInt64 aParent, PRInt32 aIndex,
PRInt64* aNewItemId)
{
// You can pass -1 to indicate append, but no other negative number is allowed
// You can pass -1 to indicate append, but no other negative number is
// allowed
if (aIndex < -1)
return NS_ERROR_INVALID_ARG;
@ -1142,11 +1144,16 @@ nsNavBookmarks::InsertSeparator(PRInt64 aParent, PRInt32 aIndex)
rv = statement->Execute();
NS_ENSURE_SUCCESS(rv, rv);
PRInt64 rowId;
rv = dbConn->GetLastInsertRowID(&rowId);
NS_ENSURE_SUCCESS(rv, rv);
*aNewItemId = rowId;
rv = transaction.Commit();
NS_ENSURE_SUCCESS(rv, rv);
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
OnSeparatorAdded(aParent, index))
OnItemAdded(rowId, aParent, index))
return NS_OK;
}
@ -1179,7 +1186,7 @@ nsNavBookmarks::RemoveChildAt(PRInt64 aParent, PRInt32 aIndex)
type = mDBGetChildAt->AsInt32(2);
}
if (type == TYPE_BOOKMARK) {
if (type == TYPE_BOOKMARK || type == TYPE_SEPARATOR) {
// Commit this transaction so that we don't notify observers mid-tranaction
rv = transaction.Commit();
NS_ENSURE_SUCCESS(rv, rv);
@ -1193,28 +1200,6 @@ nsNavBookmarks::RemoveChildAt(PRInt64 aParent, PRInt32 aIndex)
return RemoveFolder(id);
}
else if (type == TYPE_SEPARATOR) {
nsCOMPtr<mozIStorageStatement> statement;
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING("DELETE FROM moz_bookmarks WHERE id = ?1"),
getter_AddRefs(statement));
NS_ENSURE_SUCCESS(rv, rv);
rv = statement->BindInt64Parameter(0, id);
NS_ENSURE_SUCCESS(rv, rv);
rv = statement->Execute();
NS_ENSURE_SUCCESS(rv, rv);
rv = AdjustIndices(aParent, aIndex + 1, PR_INT32_MAX, -1);
NS_ENSURE_SUCCESS(rv, rv);
rv = transaction.Commit();
NS_ENSURE_SUCCESS(rv, rv);
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
OnSeparatorRemoved(aParent, aIndex))
return NS_OK;
}
return NS_ERROR_INVALID_ARG;
}
@ -1304,7 +1289,7 @@ nsNavBookmarks::RemoveFolder(PRInt64 aFolder)
NS_ENSURE_SUCCESS(rv, rv);
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
OnFolderRemoved(aFolder, parent, index))
OnItemRemoved(aFolder, parent, index))
return NS_OK;
}
@ -1318,7 +1303,7 @@ nsNavBookmarks::GetRemoveFolderTransaction(PRInt64 aFolder, nsITransaction** aRe
// recreate the folder safely later.
nsAutoString title;
nsresult rv = GetFolderTitle(aFolder, title);
nsresult rv = GetItemTitle(aFolder, title);
NS_ENSURE_SUCCESS(rv, rv);
PRInt64 parent;
@ -1615,19 +1600,6 @@ nsNavBookmarks::GetItemTitle(PRInt64 aItemId, nsAString &aTitle)
return mDBGetItemProperties->GetString(kGetItemPropertiesIndex_Title, aTitle);
}
NS_IMETHODIMP
nsNavBookmarks::GetItemURI(PRInt64 aItemId, nsIURI **aURI)
{
NS_ENSURE_ARG_POINTER(aURI);
// Create a place URI for a bookmark or separator
//
// NOTE: this is not yet supported by the query system
nsCAutoString spec("place:moz_bookmarks.id=");
spec.AppendInt(aItemId);
spec.AppendLiteral("&group=3"); // GROUP_BY_FOLDER
return NS_NewURI(aURI, spec);
}
NS_IMETHODIMP
nsNavBookmarks::GetBookmarkURI(PRInt64 aItemId, nsIURI **aURI)
{
@ -1659,7 +1631,7 @@ nsNavBookmarks::GetBookmarkURI(PRInt64 aItemId, nsIURI **aURI)
}
NS_IMETHODIMP
nsNavBookmarks::GetItemType(PRInt64 aItemId, PRInt32 *aType)
nsNavBookmarks::GetItemType(PRInt64 aItemId, PRUint16 *aType)
{
mozStorageStatementScoper scope(mDBGetItemProperties);
@ -1674,49 +1646,10 @@ nsNavBookmarks::GetItemType(PRInt64 aItemId, PRInt32 *aType)
return NS_ERROR_INVALID_ARG; // invalid bookmark id
}
return mDBGetItemProperties->GetInt32(kGetItemPropertiesIndex_Type, aType);
}
NS_IMETHODIMP
nsNavBookmarks::SetFolderTitle(PRInt64 aFolder, const nsAString &aTitle)
{
nsCOMPtr<mozIStorageStatement> statement;
nsresult rv = DBConn()->CreateStatement(NS_LITERAL_CSTRING("UPDATE moz_bookmarks SET title = ?2 WHERE id = ?1"),
getter_AddRefs(statement));
NS_ENSURE_SUCCESS(rv, rv);
rv = statement->BindInt64Parameter(0, aFolder);
NS_ENSURE_SUCCESS(rv, rv);
rv = statement->BindStringParameter(1, aTitle);
NS_ENSURE_SUCCESS(rv, rv);
rv = statement->Execute();
NS_ENSURE_SUCCESS(rv, rv);
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
OnFolderChanged(aFolder, NS_LITERAL_CSTRING("title")))
*aType = (PRUint16)mDBGetItemProperties->AsInt32(kGetItemPropertiesIndex_Type);
return NS_OK;
}
NS_IMETHODIMP
nsNavBookmarks::GetFolderTitle(PRInt64 aFolder, nsAString &aTitle)
{
mozStorageStatementScoper scope(mDBGetItemProperties);
nsresult rv = mDBGetItemProperties->BindInt64Parameter(0, aFolder);
NS_ENSURE_SUCCESS(rv, rv);
PRBool results;
rv = mDBGetItemProperties->ExecuteStep(&results);
NS_ENSURE_SUCCESS(rv, rv);
if (!results) {
return NS_ERROR_INVALID_ARG;
}
return mDBGetItemProperties->GetString(kGetItemPropertiesIndex_Title, aTitle);
}
nsresult
nsNavBookmarks::GetFolderType(PRInt64 aFolder, nsACString &aType)
{

View File

@ -2482,22 +2482,6 @@ nsNavHistoryQueryResultNode::OnItemVisited(PRInt64 aItemId,
return NS_OK;
}
NS_IMETHODIMP
nsNavHistoryQueryResultNode::OnFolderAdded(PRInt64 aFolder, PRInt64 aParent,
PRInt32 aIndex)
{
if (mLiveUpdate == QUERYUPDATE_COMPLEX_WITH_BOOKMARKS)
return Refresh();
return NS_OK;
}
NS_IMETHODIMP
nsNavHistoryQueryResultNode::OnFolderRemoved(PRInt64 aFolder, PRInt64 aParent,
PRInt32 aIndex)
{
if (mLiveUpdate == QUERYUPDATE_COMPLEX_WITH_BOOKMARKS)
return Refresh();
return NS_OK;
}
NS_IMETHODIMP
nsNavHistoryQueryResultNode::OnFolderMoved(PRInt64 aFolder, PRInt64 aOldParent,
PRInt32 aOldIndex, PRInt64 aNewParent,
PRInt32 aNewIndex)
@ -2514,17 +2498,6 @@ nsNavHistoryQueryResultNode::OnFolderChanged(PRInt64 aFolder,
return Refresh();
return NS_OK;
}
NS_IMETHODIMP
nsNavHistoryQueryResultNode::OnSeparatorAdded(PRInt64 aParent, PRInt32 aIndex)
{
return NS_OK;
}
NS_IMETHODIMP
nsNavHistoryQueryResultNode::OnSeparatorRemoved(PRInt64 aParent,
PRInt32 aIndex)
{
return NS_OK;
}
// nsNavHistoryFolderResultNode ************************************************
//
@ -2925,13 +2898,13 @@ nsNavHistoryFolderResultNode::ReindexRange(PRInt32 aStartIndex,
}
// nsNavHistoryFolderResultNode::FindChildURIById
// nsNavHistoryFolderResultNode::FindChildById
//
// Searches this folder for a node with the given URI. Returns null if not
// found. Does not addref the node!
nsNavHistoryResultNode*
nsNavHistoryFolderResultNode::FindChildURIById(PRInt64 aItemId,
nsNavHistoryFolderResultNode::FindChildById(PRInt64 aItemId,
PRUint32* aNodeIndex)
{
for (PRInt32 i = 0; i < mChildren.Count(); i ++) {
@ -2966,15 +2939,10 @@ nsNavHistoryFolderResultNode::OnEndUpdateBatch()
NS_IMETHODIMP
nsNavHistoryFolderResultNode::OnItemAdded(PRInt64 aItemId,
PRInt64 aFolder, PRInt32 aIndex)
PRInt64 aParentFolder,
PRInt32 aIndex)
{
NS_ASSERTION(aFolder == mItemId, "Got wrong bookmark update");
if (mOptions->ExcludeItems()) {
// don't update items when we aren't displaying them, but we still need
// to adjust bookmark indices to account for the insertion
ReindexRange(aIndex, PR_INT32_MAX, 1);
return NS_OK;
}
NS_ASSERTION(aParentFolder == mItemId, "Got wrong bookmark update");
// here, try to do something reasonable if the bookmark service gives us
// a bogus index.
@ -2985,22 +2953,49 @@ nsNavHistoryFolderResultNode::OnItemAdded(PRInt64 aItemId,
NS_NOTREACHED("Invalid index for item adding: greater than count");
aIndex = mChildren.Count();
}
nsNavBookmarks* bookmarks = nsNavBookmarks::GetBookmarksService();
NS_ENSURE_TRUE(bookmarks, NS_ERROR_OUT_OF_MEMORY);
PRUint16 itemType;
nsresult rv = bookmarks->GetItemType(aItemId, &itemType);
NS_ENSURE_SUCCESS(rv, rv);
if (itemType != nsINavBookmarksService::TYPE_FOLDER &&
mOptions->ExcludeItems()) {
// don't update items when we aren't displaying them, but we still need
// to adjust bookmark indices to account for the insertion
ReindexRange(aIndex, PR_INT32_MAX, 1);
return NS_OK;
}
if (!StartIncrementalUpdate())
return NS_OK; // folder was completely refreshed for us
// adjust bookmark indices
// adjust indices to account for insertion
ReindexRange(aIndex, PR_INT32_MAX, 1);
nsNavHistoryResultNode* node;
if (itemType == nsINavBookmarksService::TYPE_BOOKMARK) {
nsNavHistory* history = nsNavHistory::GetHistoryService();
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
nsNavHistoryResultNode* node;
nsresult rv = history->BookmarkIdToResultNode(aItemId, mOptions, &node);
NS_ENSURE_SUCCESS(rv, rv);
node->mBookmarkIndex = aIndex;
rv = history->BookmarkIdToResultNode(aItemId, mOptions, &node);
node->mItemId = aItemId;
NS_ENSURE_SUCCESS(rv, rv);
}
else if (itemType == nsINavBookmarksService::TYPE_FOLDER) {
rv = bookmarks->ResultNodeForFolder(aItemId, mOptions, &node);
NS_ENSURE_SUCCESS(rv, rv);
}
else if (itemType == nsINavBookmarksService::TYPE_SEPARATOR) {
node = new nsNavHistorySeparatorResultNode();
NS_ENSURE_TRUE(node, NS_ERROR_OUT_OF_MEMORY);
node->mItemId = aItemId;
}
node->mBookmarkIndex = aIndex;
if (GetSortType() == nsINavHistoryQueryOptions::SORT_BY_NONE) {
if (itemType == nsINavBookmarksService::TYPE_SEPARATOR ||
GetSortType() == nsINavHistoryQueryOptions::SORT_BY_NONE) {
// insert at natural bookmarks position
return InsertChildAt(node, aIndex);
}
@ -3013,30 +3008,40 @@ nsNavHistoryFolderResultNode::OnItemAdded(PRInt64 aItemId,
NS_IMETHODIMP
nsNavHistoryFolderResultNode::OnItemRemoved(PRInt64 aItemId,
PRInt64 aFolder, PRInt32 aIndex)
PRInt64 aParentFolder, PRInt32 aIndex)
{
NS_ASSERTION(aFolder == mItemId, "Got wrong bookmark update");
if (mOptions->ExcludeItems()) {
// We only care about notifications when a child changes. When the deleted
// item is us, our parent should also be registered and will remove us from
// its list.
if (mItemId == aItemId)
return NS_OK;
// don't trust the index from the bookmark service, find it ourselves. The
// sorting could be different, or the bookmark services indices and ours might
// be out of sync somehow.
PRUint32 index;
nsNavHistoryResultNode* node = FindChildById(aItemId, &index);
if (!node) {
NS_NOTREACHED("Removing item we don't have");
return NS_ERROR_FAILURE;
}
NS_ASSERTION(aParentFolder == mItemId, "Got wrong bookmark update");
if (!node->IsFolder() && mOptions->ExcludeItems()) {
// don't update items when we aren't displaying them, but we do need to
// adjust everybody's bookmark indices to account for the removal
ReindexRange(aIndex, PR_INT32_MAX, -1);
return NS_OK;
}
if (!StartIncrementalUpdate())
return NS_OK; // folder was completely refreshed for us
return NS_OK; // we are completely refreshed
// shift all following indices down
ReindexRange(aIndex + 1, PR_INT32_MAX, -1);
// don't trust the index from the bookmark service, find it ourselves. The
// sorting could be different, or the bookmark services indices and ours might
// be out of sync somehow.
PRUint32 nodeIndex;
nsNavHistoryResultNode* node = FindChildURIById(aItemId, &nodeIndex);
if (! node)
return NS_ERROR_FAILURE; // can't find it
return RemoveChildAt(nodeIndex);
return RemoveChildAt(index);
}
@ -3054,7 +3059,7 @@ nsNavHistoryFolderResultNode::OnItemChanged(PRInt64 aItemId,
return NS_OK;
PRUint32 nodeIndex;
nsNavHistoryResultNode* node = FindChildURIById(aItemId, &nodeIndex);
nsNavHistoryResultNode* node = FindChildById(aItemId, &nodeIndex);
if (!node)
return NS_ERROR_FAILURE;
@ -3112,7 +3117,7 @@ nsNavHistoryFolderResultNode::OnItemVisited(PRInt64 aItemId,
return NS_OK;
PRUint32 nodeIndex;
nsNavHistoryResultNode* node = FindChildURIById(aItemId, &nodeIndex);
nsNavHistoryResultNode* node = FindChildById(aItemId, &nodeIndex);
if (! node)
return NS_ERROR_FAILURE;
@ -3155,68 +3160,6 @@ nsNavHistoryFolderResultNode::OnItemVisited(PRInt64 aItemId,
return NS_OK;
}
// nsNavHistoryFolderResultNode::OnFolderAdded (nsINavBookmarkObserver)
//
// Create the new folder and add it
NS_IMETHODIMP
nsNavHistoryFolderResultNode::OnFolderAdded(PRInt64 aFolder, PRInt64 aParent,
PRInt32 aIndex)
{
NS_ASSERTION(aParent == mItemId, "Got wrong bookmark update");
if (! StartIncrementalUpdate())
return NS_OK; // folder was completely refreshed for us
// adjust indices to account for insertion
ReindexRange(aIndex, PR_INT32_MAX, 1);
nsNavBookmarks* bookmarks = nsNavBookmarks::GetBookmarksService();
NS_ENSURE_TRUE(bookmarks, NS_ERROR_OUT_OF_MEMORY);
nsNavHistoryResultNode* node;
nsresult rv = bookmarks->ResultNodeForFolder(aFolder, mOptions, &node);
NS_ENSURE_SUCCESS(rv, rv);
node->mBookmarkIndex = aIndex;
if (GetSortType() == nsINavHistoryQueryOptions::SORT_BY_NONE) {
// insert at natural bookmarks position
return InsertChildAt(node, aIndex);
}
// insert at sorted position
return InsertSortedChild(node, PR_FALSE);
}
// nsNavHistoryFolderResultNode::OnFolderRemoved (nsINavBookmarkObserver)
NS_IMETHODIMP
nsNavHistoryFolderResultNode::OnFolderRemoved(PRInt64 aFolder, PRInt64 aParent,
PRInt32 aIndex)
{
// We only care about notifications when a child changes. When the deleted
// folder is us, our parent should also be registered and will remove us from
// its list.
if (mItemId == aFolder)
return NS_OK;
NS_ASSERTION(aParent == mItemId, "Got wrong bookmark update");
if (! StartIncrementalUpdate())
return NS_OK; // we are completely refreshed
// update indices
ReindexRange(aIndex + 1, PR_INT32_MAX, -1);
PRUint32 index;
nsNavHistoryFolderResultNode* node = FindChildFolder(aFolder, &index);
if (! node) {
NS_NOTREACHED("Removing folder we don't have");
return NS_ERROR_FAILURE;
}
return RemoveChildAt(index);
}
// nsNavHistoryFolderResultNode::OnFolderMoved (nsINavBookmarkObserver)
NS_IMETHODIMP
@ -3266,9 +3209,9 @@ nsNavHistoryFolderResultNode::OnFolderMoved(PRInt64 aFolder, PRInt64 aOldParent,
} else {
// moving between two different folders, just do a remove and an add
if (aOldParent == mItemId)
OnFolderRemoved(aFolder, aOldParent, aOldIndex);
OnItemRemoved(aFolder, aOldParent, aOldIndex);
if (aNewParent == mItemId)
OnFolderAdded(aFolder, aNewParent, aNewIndex);
OnItemAdded(aFolder, aNewParent, aNewIndex);
}
return NS_OK;
}
@ -3294,7 +3237,7 @@ nsNavHistoryFolderResultNode::OnFolderChanged(PRInt64 aFolder,
NS_ENSURE_TRUE(bookmarks, NS_ERROR_OUT_OF_MEMORY);
nsAutoString title;
bookmarks->GetFolderTitle(mItemId, title);
bookmarks->GetItemTitle(mItemId, title);
mTitle = NS_ConvertUTF16toUTF8(title);
PRInt32 sortType = GetSortType();
@ -3330,66 +3273,6 @@ nsNavHistoryFolderResultNode::OnFolderChanged(PRInt64 aFolder,
}
// nsNavHistoryFolderResultNode::OnSeparatorAdded (nsINavBookmarkObserver)
NS_IMETHODIMP
nsNavHistoryFolderResultNode::OnSeparatorAdded(PRInt64 aParent, PRInt32 aIndex)
{
NS_ASSERTION(aParent == mItemId, "Got wrong bookmark update");
if (mOptions->ExcludeItems()) {
// don't update items when we aren't displaying them, except we need to
// update the indices
ReindexRange(aIndex, PR_INT32_MAX, 1);
return NS_OK;
}
if (! StartIncrementalUpdate())
return NS_OK; // folder is completely refreshed for us
// adjust indices
ReindexRange(aIndex, PR_INT32_MAX, 1);
nsNavBookmarks* bookmarks = nsNavBookmarks::GetBookmarksService();
NS_ENSURE_TRUE(bookmarks, NS_ERROR_OUT_OF_MEMORY);
nsNavHistoryResultNode* node = new nsNavHistorySeparatorResultNode();
NS_ENSURE_TRUE(node, NS_ERROR_OUT_OF_MEMORY);
node->mBookmarkIndex = aIndex;
return InsertChildAt(node, aIndex);
}
// nsNavHistoryFolderResultNode::OnSeparatorRemoved (nsINavBookmarkObserver)
NS_IMETHODIMP
nsNavHistoryFolderResultNode::OnSeparatorRemoved(PRInt64 aParent,
PRInt32 aIndex)
{
NS_ASSERTION(aParent == mItemId, "Got wrong bookmark update");
if (mOptions->ExcludeItems()) {
// don't update items when we aren't displaying them, except we need to
// update everybody's indices
ReindexRange(aIndex, PR_INT32_MAX, -1);
return NS_OK;
}
if (! StartIncrementalUpdate())
return NS_OK; // folder is completely refreshed for us
ReindexRange(aIndex, PR_INT32_MAX, -1);
if (aIndex >= mChildren.Count()) {
NS_NOTREACHED("Removing separator at invalid index");
return NS_OK;
}
if (!mChildren[aIndex]->IsSeparator()) {
NS_NOTREACHED("OnSeparatorRemoved called for a non-separator node");
return NS_OK;
}
return RemoveChildAt(aIndex);
}
// nsNavHistorySeparatorResultNode
//
// Separator nodes do not hold any data
@ -3838,32 +3721,6 @@ nsNavHistoryResult::OnItemVisited(PRInt64 aItemId, PRInt64 aVisitId,
}
// nsNavHistoryResult::OnFolderAdded (nsINavBookmarkObserver)
NS_IMETHODIMP
nsNavHistoryResult::OnFolderAdded(PRInt64 aFolder,
PRInt64 aParent, PRInt32 aIndex)
{
ENUMERATE_BOOKMARK_OBSERVERS_FOR_FOLDER(aParent,
OnFolderAdded(aFolder, aParent, aIndex));
ENUMERATE_HISTORY_OBSERVERS(OnFolderAdded(aFolder, aParent, aIndex));
return NS_OK;
}
// nsNavHistoryResult::OnFolderRemoved (nsINavBookmarkObserver)
NS_IMETHODIMP
nsNavHistoryResult::OnFolderRemoved(PRInt64 aFolder,
PRInt64 aParent, PRInt32 aIndex)
{
ENUMERATE_BOOKMARK_OBSERVERS_FOR_FOLDER(aParent,
OnFolderRemoved(aFolder, aParent, aIndex));
ENUMERATE_HISTORY_OBSERVERS(OnFolderRemoved(aFolder, aParent, aIndex));
return NS_OK;
}
// nsNavHistoryResult::OnFolderMoved (nsINavBookmarkObserver)
//
// Need to notify both the source and the destination folders (if they
@ -3901,30 +3758,6 @@ nsNavHistoryResult::OnFolderChanged(PRInt64 aFolder,
}
// nsNavHistoryResult::OnSeparatorAdded (nsINavBookmarkObserver)
NS_IMETHODIMP
nsNavHistoryResult::OnSeparatorAdded(PRInt64 aParent, PRInt32 aIndex)
{
// Separators only appear in folder nodes, so history observers don't care.
ENUMERATE_BOOKMARK_OBSERVERS_FOR_FOLDER(aParent,
OnSeparatorAdded(aParent, aIndex));
return NS_OK;
}
// nsNavHistoryResult::OnSeparatorRemoved (nsINavBookmarkObserver)
NS_IMETHODIMP
nsNavHistoryResult::OnSeparatorRemoved(PRInt64 aParent, PRInt32 aIndex)
{
// Separators only appear in folder nodes, so history observers don't care.
ENUMERATE_BOOKMARK_OBSERVERS_FOR_FOLDER(aParent,
OnSeparatorRemoved(aParent, aIndex));
return NS_OK;
}
// nsNavHistoryResult::OnVisit (nsINavHistoryObserver)
NS_IMETHODIMP

View File

@ -733,7 +733,7 @@ public:
PRBool StartIncrementalUpdate();
void ReindexRange(PRInt32 aStartIndex, PRInt32 aEndIndex, PRInt32 aDelta);
nsNavHistoryResultNode* FindChildURIById(PRInt64 aItemId,
nsNavHistoryResultNode* FindChildById(PRInt64 aItemId,
PRUint32* aNodeIndex);
};

View File

@ -68,7 +68,7 @@ var observer = {
},
onItemAdded: function(id, folder, index) {
this._itemAddedId = id;
this._itemAddedFolder = folder;
this._itemAddedParent = folder;
this._itemAddedIndex = index;
},
onItemRemoved: function(id, folder, index) {
@ -87,16 +87,6 @@ var observer = {
this._itemVisitedVistId = visitID;
this._itemVisitedTime = time;
},
onFolderAdded: function(folder, parent, index) {
this._folderAdded = folder;
this._folderAddedParent = parent;
this._folderAddedIndex = index;
},
onFolderRemoved: function(folder, parent, index) {
this._folderRemoved = folder;
this._folderRemovedParent = parent;
this._folderRemovedIndex = index;
},
onFolderMoved: function(folder, oldParent, oldIndex, newParent, newIndex) {
this._folderMoved = folder;
this._folderMovedOldParent = oldParent;
@ -108,14 +98,6 @@ var observer = {
this._folderChanged = folder;
this._folderChangedProperty = property;
},
onSeparatorAdded: function(folder, index) {
this._separatorAdded = folder;
this._separatorAddedIndex = index;
},
onSeparatorRemoved: function(folder, index) {
this._separatorRemoved = folder;
this._separatorRemovedIndex = index;
},
QueryInterface: function(iid) {
if (iid.equals(Ci.nsINavBookmarkObserver) ||
iid.equals(Ci.nsISupports)) {
@ -142,9 +124,9 @@ function run_test() {
// create a folder to hold all the tests
// this makes the tests more tolerant of changes to default_places.html
var testRoot = bmsvc.createFolder(root, "places bookmarks xpcshell tests", bmsvc.DEFAULT_INDEX);
do_check_eq(observer._folderAdded, testRoot);
do_check_eq(observer._folderAddedParent, root);
do_check_eq(observer._folderAddedIndex, bmStartIndex);
do_check_eq(observer._itemAddedId, testRoot);
do_check_eq(observer._itemAddedParent, root);
do_check_eq(observer._itemAddedIndex, bmStartIndex);
var testStartIndex = 0;
// test getItemIndex for folders
@ -156,7 +138,7 @@ function run_test() {
// insert a bookmark
var newId = bmsvc.insertItem(testRoot, uri("http://google.com/"), bmsvc.DEFAULT_INDEX);
do_check_eq(observer._itemAddedId, newId);
do_check_eq(observer._itemAddedFolder, testRoot);
do_check_eq(observer._itemAddedParent, testRoot);
do_check_eq(observer._itemAddedIndex, testStartIndex);
do_check_eq(bmsvc.getBookmarkURI(newId).spec, "http://google.com/");
@ -188,19 +170,20 @@ function run_test() {
// create a folder at a specific index
var workFolder = bmsvc.createFolder(testRoot, "Work", 0);
do_check_eq(observer._folderAdded, workFolder);
do_check_eq(observer._folderAddedParent, testRoot);
do_check_eq(observer._folderAddedIndex, 0);
do_check_eq(observer._itemAddedId, workFolder);
do_check_eq(observer._itemAddedParent, testRoot);
do_check_eq(observer._itemAddedIndex, 0);
//XXX - test creating a folder at an invalid index
//XXX - test setFolderTitle
//XXX - test getFolderTitle
do_check_eq(bmsvc.getItemTitle(workFolder), "Work");
bmsvc.setItemTitle(workFolder, "Work #");
do_check_eq(bmsvc.getItemTitle(workFolder), "Work #");
// add item into subfolder, specifying index
var newId2 = bmsvc.insertItem(workFolder, uri("http://developer.mozilla.org/"), 0);
do_check_eq(observer._itemAddedId, newId2);
do_check_eq(observer._itemAddedFolder, workFolder);
do_check_eq(observer._itemAddedParent, workFolder);
do_check_eq(observer._itemAddedIndex, 0);
// change item
@ -210,7 +193,7 @@ function run_test() {
// insert item into subfolder
var newId3 = bmsvc.insertItem(workFolder, uri("http://msdn.microsoft.com/"), bmsvc.DEFAULT_INDEX);
do_check_eq(observer._itemAddedId, newId3);
do_check_eq(observer._itemAddedFolder, workFolder);
do_check_eq(observer._itemAddedParent, workFolder);
do_check_eq(observer._itemAddedIndex, 1);
// change item
@ -226,19 +209,19 @@ function run_test() {
// insert item into subfolder
var newId4 = bmsvc.insertItem(workFolder, uri("http://developer.mozilla.org/"), bmsvc.DEFAULT_INDEX);
do_check_eq(observer._itemAddedId, newId4);
do_check_eq(observer._itemAddedFolder, workFolder);
do_check_eq(observer._itemAddedParent, workFolder);
do_check_eq(observer._itemAddedIndex, 1);
// create folder
var homeFolder = bmsvc.createFolder(testRoot, "Home", bmsvc.DEFAULT_INDEX);
do_check_eq(observer._folderAdded, homeFolder);
do_check_eq(observer._folderAddedParent, testRoot);
do_check_eq(observer._folderAddedIndex, 2);
do_check_eq(observer._itemAddedId, homeFolder);
do_check_eq(observer._itemAddedParent, testRoot);
do_check_eq(observer._itemAddedIndex, 2);
// insert item
var newId5 = bmsvc.insertItem(homeFolder, uri("http://espn.com/"), bmsvc.DEFAULT_INDEX);
do_check_eq(observer._itemAddedId, newId5);
do_check_eq(observer._itemAddedFolder, homeFolder);
do_check_eq(observer._itemAddedParent, homeFolder);
do_check_eq(observer._itemAddedIndex, 0);
// change item
@ -248,7 +231,7 @@ function run_test() {
// insert query item
var newId6 = bmsvc.insertItem(testRoot, uri("place:domain=google.com&group=1"), bmsvc.DEFAULT_INDEX);
do_check_eq(observer._itemAddedFolder, testRoot);
do_check_eq(observer._itemAddedParent, testRoot);
do_check_eq(observer._itemAddedIndex, 3);
// change item
@ -266,8 +249,7 @@ function run_test() {
// test that the new index is properly stored
do_check_eq(bmsvc.getItemIndex(workFolder), 1);
// XXX use getFolderIdForItem to test for the new parent
do_check_eq(bmsvc.getFolderIdForItem(workFolder), homeFolder);
// try to get index of the folder from it's ex-parent
// XXX expose getItemAtIndex(folder, idx) to test that the item was *removed* from the old parent?
@ -369,11 +351,6 @@ function run_test() {
rootNode.containerOpen = false;
} catch(ex) { do_throw("removeFolderChildren(): " + ex); }
// test getItemURI
var newId9 = bmsvc.insertItem(testRoot, uri("http://foo9.com/"), bmsvc.DEFAULT_INDEX);
var placeURI = bmsvc.getItemURI(newId9);
do_check_eq(placeURI.spec, "place:moz_bookmarks.id=" + newId9 + "&group=3");
// XXX - test folderReadOnly
// test bookmark id in query output
@ -470,8 +447,8 @@ function run_test() {
// see bug #369887 for more details
var newId13 = bmsvc.insertItem(testRoot, uri("http://foobarcheese.com/"), bmsvc.DEFAULT_INDEX);
do_check_eq(observer._itemAddedId, newId13);
do_check_eq(observer._itemAddedFolder, testRoot);
do_check_eq(observer._itemAddedIndex, 13);
do_check_eq(observer._itemAddedParent, testRoot);
do_check_eq(observer._itemAddedIndex, 12);
// set bookmark title
bmsvc.setItemTitle(newId13, "ZZZXXXYYY");