Bug 371823 - Optimize item moves. r=sspitzer.

This commit is contained in:
mozilla.mano%sent.com 2007-05-22 22:03:55 +00:00
Родитель e72aa521c3
Коммит 8e01c47957
11 изменённых файлов: 119 добавлений и 180 удалений

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

@ -339,7 +339,7 @@ var gBookmarksObserver = {
}, },
onItemVisited: function() { }, onItemVisited: function() { },
onFolderMoved: function() { }, onItemMoved: function() { },
onFolderChanged: function() { } onFolderChanged: function() { }
}; };

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

@ -1761,66 +1761,29 @@ PlacesCreateLivemarkTransaction.prototype = {
} }
}; };
/**
* Move a Folder
*/
function PlacesMoveFolderTransaction(id, oldContainer, oldIndex, newContainer, newIndex) {
NS_ASSERT(!isNaN(id + oldContainer + oldIndex + newContainer + newIndex), "Parameter is NaN!");
NS_ASSERT(newIndex >= -1, "invalid insertion index");
this._id = id;
this._oldContainer = oldContainer;
this._oldIndex = oldIndex;
this._newContainer = newContainer;
this._newIndex = newIndex;
this.redoTransaction = this.doTransaction;
}
PlacesMoveFolderTransaction.prototype = {
__proto__: PlacesBaseTransaction.prototype,
doTransaction: function PMFT_doTransaction() {
this.LOG("Move Folder: " + this._id + " from: " + this._oldContainer + "," + this._oldIndex + " to: " + this._newContainer + "," + this._newIndex);
this.bookmarks.moveFolder(this._id, this._newContainer, this._newIndex);
},
undoTransaction: function PMFT_undoTransaction() {
this.LOG("UNMove Folder: " + this._id + " from: " + this._oldContainer + "," + this._oldIndex + " to: " + this._newContainer + "," + this._newIndex);
this.bookmarks.moveFolder(this._id, this._oldContainer, this._oldIndex);
}
};
/** /**
* Move an Item * Move an Item
*/ */
function PlacesMoveItemTransaction(id, uri, oldContainer, oldIndex, newContainer, newIndex) { function PlacesMoveItemTransaction(aItemId, aNewContainer, aNewIndex) {
this._id = id; NS_ASSERT(!isNaN(aItemId + aNewContainer + aNewIndex), "Parameter is NaN!");
this._uri = uri; NS_ASSERT(aNewIndex >= -1, "invalid insertion index");
this._oldContainer = oldContainer; this._id = aItemId;
this._oldIndex = oldIndex; this._oldContainer = this.utils.bookmarks.getFolderIdForItem(this._id);
this._newContainer = newContainer; this._oldIndex = this.utils.bookmarks.getItemIndex(this._id);
this._newIndex = newIndex; NS_ASSERT(this._oldContainer > 0 && this._oldIndex >= 0, "invalid item");
this._newContainer = aNewContainer;
this._newIndex = aNewIndex;
this.redoTransaction = this.doTransaction; this.redoTransaction = this.doTransaction;
} }
PlacesMoveItemTransaction.prototype = { PlacesMoveItemTransaction.prototype = {
__proto__: PlacesBaseTransaction.prototype, __proto__: PlacesBaseTransaction.prototype,
doTransaction: function PMIT_doTransaction() { doTransaction: function PMIT_doTransaction() {
this.LOG("Move Item: " + this._uri.spec + " from: " + this._oldContainer + "," + this._oldIndex + " to: " + this._newContainer + "," + this._newIndex); this.bookmarks.moveItem(this._id, this._newContainer, this._newIndex);
var title = this.bookmarks.getItemTitle(this._id);
var annotations = this.utils.getAnnotationsForItem(this._id);
this.bookmarks.removeItem(this._id);
this._id = this.bookmarks.insertItem(this._newContainer, this._uri, this._newIndex);
this.bookmarks.setItemTitle(this._id, title);
this.utils.setAnnotationsForItem(this._id, annotations);
}, },
undoTransaction: function PMIT_undoTransaction() { undoTransaction: function PMIT_undoTransaction() {
this.LOG("UNMove Item: " + this._uri.spec + " from: " + this._oldContainer + "," + this._oldIndex + " to: " + this._newContainer + "," + this._newIndex); this.bookmarks.moveItem(this._id, this._oldContainer, this._oldIndex);
var title = this.bookmarks.getItemTitle(this._id);
var annotations = this.utils.getAnnotationsForItem(this._id);
this.bookmarks.removeItem(this._id);
this._id = this.bookmarks.insertItem(this._oldContainer, this._uri, this._oldIndex);
this.bookmarks.setItemTitle(this._id, title);
this.utils.setAnnotationsForItem(this._id, annotations);
} }
}; };

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

@ -65,37 +65,12 @@ var gMoveBookmarksDialog = {
var transactions = []; var transactions = [];
for (var i=0; i < this._nodes.length; i++) { for (var i=0; i < this._nodes.length; i++) {
var parentId = this._nodes[i].parent.itemId;
// Nothing to do if the node is already under the selected folder // Nothing to do if the node is already under the selected folder
if (parentId == selectedFolderID) if (this._nodes[i].parent.itemId == selectedFolderID)
continue; continue;
var nodeIndex = PlacesUtils.getIndexOfNode(this._nodes[i]);
if (PlacesUtils.nodeIsFolder(this._nodes[i])) {
// Disallow moving a folder into itself
if (this._nodes[i].itemId != selectedFolderID) {
transactions.push(new transactions.push(new
PlacesMoveFolderTransaction(this._nodes[i].itemId, PlacesMoveItemTransaction(this._nodes[i].itemId, selectedFolderID, -1));
parentId, nodeIndex,
selectedFolderID, -1));
}
}
else if (PlacesUtils.nodeIsBookmark(this._nodes[i])) {
transactions.push(new
PlacesMoveItemTransaction(this._nodes[i].itemId,
PlacesUtils._uri(this._nodes[i].uri),
parentId, nodeIndex, selectedFolderID, -1));
}
else if (PlacesUtils.nodeIsSeparator(this._nodes[i])) {
// See makeTransaction in utils.js
var removeTxn =
new PlacesRemoveSeparatorTransaction(parentId, nodeIndex);
var createTxn =
new PlacesCreateSeparatorTransaction(selectedFolderID, -1);
transactions.push(new
PlacesAggregateTransaction("SeparatorMove", [removeTxn, createTxn]));
}
} }
if (transactions.length != 0) { if (transactions.length != 0) {

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

@ -450,7 +450,7 @@ var PlacesUtils = {
// bookmarks folder: <itemId>\n<>\n<parentId>\n<indexInParent> // bookmarks folder: <itemId>\n<>\n<parentId>\n<indexInParent>
// uri: 0\n<uri>\n<parentId>\n<indexInParent> // uri: 0\n<uri>\n<parentId>\n<indexInParent>
// bookmark: <itemId>\n<uri>\n<parentId>\n<indexInParent> // bookmark: <itemId>\n<uri>\n<parentId>\n<indexInParent>
// separator: 0\n<>\n<parentId>\n<indexInParent> // separator: <itemId>\n<>\n<parentId>\n<indexInParent>
var wrapped = ""; var wrapped = "";
if (aNode.itemId != -1) // if (aNode.itemId != -1) //
wrapped += aNode.itemId + NEWLINE; wrapped += aNode.itemId + NEWLINE;
@ -655,16 +655,16 @@ var PlacesUtils = {
index, copy) { index, copy) {
switch (type) { switch (type) {
case this.TYPE_X_MOZ_PLACE_CONTAINER: case this.TYPE_X_MOZ_PLACE_CONTAINER:
if (data.id > 0 && data.uri == null) { if (data.id > 0) {
// Place is a folder. // Place is a folder.
if (copy) if (copy)
return this._getFolderCopyTransaction(data, container, index); return this._getFolderCopyTransaction(data, container, index);
return new PlacesMoveFolderTransaction(data.id, data.parent,
data.index, container,
index);
} }
break;
case this.TYPE_X_MOZ_PLACE: case this.TYPE_X_MOZ_PLACE:
if (data.id > 0) { if (data.id <= 0)
return this._getURIItemCopyTransaction(data.uri, container, index);
if (copy) { if (copy) {
// Copying a child of a live-bookmark by itself should result // Copying a child of a live-bookmark by itself should result
// as a new normal bookmark item (bug 376731) // as a new normal bookmark item (bug 376731)
@ -673,32 +673,28 @@ var PlacesUtils = {
["livemark/bookmarkFeedURI"]); ["livemark/bookmarkFeedURI"]);
return copyBookmarkAnno; return copyBookmarkAnno;
} }
return new PlacesMoveItemTransaction(data.id, data.uri, data.parent, break;
data.index, container,
index);
}
return this._getURIItemCopyTransaction(data.uri, container, index);
case this.TYPE_X_MOZ_PLACE_SEPARATOR: case this.TYPE_X_MOZ_PLACE_SEPARATOR:
if (copy) { if (copy) {
// There is no data in a separator, so copying it just amounts to // There is no data in a separator, so copying it just amounts to
// inserting a new separator. // inserting a new separator.
return new PlacesCreateSeparatorTransaction(container, index); return new PlacesCreateSeparatorTransaction(container, index);
} }
// Similarly, moving a separator is just removing the old one and break;
// then creating a new one.
var removeTxn =
new PlacesRemoveSeparatorTransaction(data.parent, data.index);
var createTxn =
new PlacesCreateSeparatorTransaction(container, index);
return new PlacesAggregateTransaction("SeparatorMove", [removeTxn, createTxn]);
case this.TYPE_X_MOZ_URL: case this.TYPE_X_MOZ_URL:
case this.TYPE_UNICODE: case this.TYPE_UNICODE:
var title = type == this.TYPE_X_MOZ_URL ? data.title : data.uri; var title = type == this.TYPE_X_MOZ_URL ? data.title : data.uri;
var createTxn = var createTxn =
new PlacesCreateItemTransaction(data.uri, container, index, title); new PlacesCreateItemTransaction(data.uri, container, index, title);
return createTxn; return createTxn;
} default:
return null; return null;
}
if (data.id <= 0)
return null;
// Move the item otherwise
return new PlacesMoveItemTransaction(data.id, container, index);
}, },
/** /**

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

@ -1219,7 +1219,7 @@ BookmarkContentSink::NewFrame()
if (updateFolder) { if (updateFolder) {
// move the menu folder to the current position // move the menu folder to the current position
mBookmarksService->MoveFolder(ourID, CurFrame().mContainerID, -1); mBookmarksService->MoveItem(ourID, CurFrame().mContainerID, -1);
mBookmarksService->SetItemTitle(ourID, containerName); mBookmarksService->SetItemTitle(ourID, containerName);
#ifdef DEBUG_IMPORT #ifdef DEBUG_IMPORT
printf(" [reparenting]"); printf(" [reparenting]");

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

@ -54,7 +54,7 @@ interface nsITransaction;
* Observer for bookmark changes. * Observer for bookmark changes.
*/ */
[scriptable, uuid(7A553BA3-5381-4A66-95D9-C7BA3895603C)] [scriptable, uuid(73d28ab9-0360-4077-845e-543d1aedba1d)]
interface nsINavBookmarkObserver : nsISupports interface nsINavBookmarkObserver : nsISupports
{ {
/** /**
@ -137,19 +137,19 @@ interface nsINavBookmarkObserver : nsISupports
in PRTime time); in PRTime time);
/** /**
* Notify this observer that a bookmark folder has been moved. * Notify this observer that an item has been moved.
* @param aFolder * @param aItemId
* The id of the folder that was moved. * The id of the item that was moved.
* @param aOldParent * @param aOldParent
* The id of the folder's old parent. * The id of the old parent.
* @param aOldIndex * @param aOldIndex
* The folder's old index inside oldParent. * The old index inside aOldParent.
* @param aNewParent * @param aNewParent
* The id of the folder's new parent. * The id of the new parent.
* @param aNewIndex * @param aNewIndex
* The folder's index inside newParent. * The foindex inside aNewParent.
*/ */
void onFolderMoved(in long long aFolder, void onItemMoved(in long long aItemId,
in long long aOldParent, in long aOldIndex, in long long aOldParent, in long aOldIndex,
in long long aNewParent, in long aNewIndex); in long long aNewParent, in long aNewIndex);
@ -293,15 +293,15 @@ interface nsINavBookmarksService : nsISupports
void removeFolderChildren(in long long aFolder); void removeFolderChildren(in long long aFolder);
/** /**
* Moves a folder to a different container, preserving its contents. * Moves an item to a different container, preserving its contents.
* @param aFolder * @param aItemId
* The folder to move * The id of the item to move
* @param aNewParent * @param aNewParent
* The id of the folder's new parent * The id of the new parent
* @param aIndex * @param aIndex
* The folder's index under newParent, or -1 to append * The index under aNewParent, or -1 to append
*/ */
void moveFolder(in long long aFolder, in long long newParent, in long aIndex); void moveItem(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 * Returns the ID of a child folder with the given name. This does not

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

@ -1353,14 +1353,14 @@ nsNavBookmarks::RemoveFolderChildren(PRInt64 aFolder)
} }
NS_IMETHODIMP NS_IMETHODIMP
nsNavBookmarks::MoveFolder(PRInt64 aFolder, PRInt64 aNewParent, PRInt32 aIndex) nsNavBookmarks::MoveItem(PRInt64 aItemId, PRInt64 aNewParent, PRInt32 aIndex)
{ {
// 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) if (aIndex < -1)
return NS_ERROR_INVALID_ARG; return NS_ERROR_INVALID_ARG;
// Disallow making a folder it's own parent. // Disallow making a folder it's own parent.
if (aFolder == aNewParent) if (aItemId == aNewParent)
return NS_ERROR_INVALID_ARG; return NS_ERROR_INVALID_ARG;
mozIStorageConnection *dbConn = DBConn(); mozIStorageConnection *dbConn = DBConn();
@ -1370,10 +1370,11 @@ nsNavBookmarks::MoveFolder(PRInt64 aFolder, PRInt64 aNewParent, PRInt32 aIndex)
nsresult rv; nsresult rv;
PRInt64 oldParent; PRInt64 oldParent;
PRInt32 oldIndex; PRInt32 oldIndex;
nsCAutoString type; PRInt32 itemType;
nsCAutoString folderType;
{ {
mozStorageStatementScoper scope(mDBGetItemProperties); mozStorageStatementScoper scope(mDBGetItemProperties);
rv = mDBGetItemProperties->BindInt64Parameter(0, aFolder); rv = mDBGetItemProperties->BindInt64Parameter(0, aItemId);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
PRBool results; PRBool results;
@ -1385,21 +1386,25 @@ nsNavBookmarks::MoveFolder(PRInt64 aFolder, PRInt64 aNewParent, PRInt32 aIndex)
oldParent = mDBGetItemProperties->AsInt64(kGetItemPropertiesIndex_Parent); oldParent = mDBGetItemProperties->AsInt64(kGetItemPropertiesIndex_Parent);
oldIndex = mDBGetItemProperties->AsInt32(kGetItemPropertiesIndex_Position); oldIndex = mDBGetItemProperties->AsInt32(kGetItemPropertiesIndex_Position);
rv = mDBGetItemProperties->GetUTF8String(kGetItemPropertiesIndex_FolderType, type); itemType = mDBGetItemProperties->AsInt32(kGetItemPropertiesIndex_Type);
if (itemType == TYPE_FOLDER) {
rv = mDBGetItemProperties->GetUTF8String(kGetItemPropertiesIndex_FolderType,
folderType);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
} }
}
// if parent and index are the same, nothing to do // if parent and index are the same, nothing to do
if (oldParent == aNewParent && oldIndex == aIndex) if (oldParent == aNewParent && oldIndex == aIndex)
return NS_OK; return NS_OK;
// Make sure aNewParent is not aFolder or a subfolder of aFolder // Make sure aNewParent is not aFolder or a subfolder of aFolder
{ if (itemType == TYPE_FOLDER) {
mozStorageStatementScoper scope(mDBGetItemProperties); mozStorageStatementScoper scope(mDBGetItemProperties);
PRInt64 p = aNewParent; PRInt64 p = aNewParent;
while (p) { while (p) {
if (p == aFolder) { if (p == aItemId) {
return NS_ERROR_INVALID_ARG; return NS_ERROR_INVALID_ARG;
} }
@ -1455,7 +1460,7 @@ nsNavBookmarks::MoveFolder(PRInt64 aFolder, PRInt64 aNewParent, PRInt32 aIndex)
buffer.AppendInt(newIndex); buffer.AppendInt(newIndex);
} }
buffer.AppendLiteral(" WHERE id = "); buffer.AppendLiteral(" WHERE id = ");
buffer.AppendInt(aFolder); buffer.AppendInt(aItemId);
rv = dbConn->ExecuteSimpleSQL(buffer); rv = dbConn->ExecuteSimpleSQL(buffer);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
@ -1484,14 +1489,15 @@ nsNavBookmarks::MoveFolder(PRInt64 aFolder, PRInt64 aNewParent, PRInt32 aIndex)
// notify bookmark observers // notify bookmark observers
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver, ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
OnFolderMoved(aFolder, oldParent, oldIndex, OnItemMoved(aItemId, oldParent, oldIndex, aNewParent,
aNewParent, newIndex)) newIndex))
// notify remote container provider if there is one // notify remote container provider if there is one
if (!type.IsEmpty()) { if (!folderType.IsEmpty()) {
nsCOMPtr<nsIRemoteContainer> container = do_GetService(type.get(), &rv); nsCOMPtr<nsIRemoteContainer> container =
do_GetService(folderType.get(), &rv);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
rv = container->OnContainerMoved(aFolder, aNewParent, newIndex); rv = container->OnContainerMoved(aItemId, aNewParent, newIndex);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
} }
} }

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

@ -2595,7 +2595,7 @@ nsNavHistoryQueryResultNode::OnItemVisited(PRInt64 aItemId,
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsNavHistoryQueryResultNode::OnFolderMoved(PRInt64 aFolder, PRInt64 aOldParent, nsNavHistoryQueryResultNode::OnItemMoved(PRInt64 aFolder, PRInt64 aOldParent,
PRInt32 aOldIndex, PRInt64 aNewParent, PRInt32 aOldIndex, PRInt64 aNewParent,
PRInt32 aNewIndex) PRInt32 aNewIndex)
{ {
@ -3294,10 +3294,10 @@ nsNavHistoryFolderResultNode::OnItemVisited(PRInt64 aItemId,
return NS_OK; return NS_OK;
} }
// nsNavHistoryFolderResultNode::OnFolderMoved (nsINavBookmarkObserver) // nsNavHistoryFolderResultNode::OnItemMoved (nsINavBookmarkObserver)
NS_IMETHODIMP NS_IMETHODIMP
nsNavHistoryFolderResultNode::OnFolderMoved(PRInt64 aFolder, PRInt64 aOldParent, nsNavHistoryFolderResultNode::OnItemMoved(PRInt64 aItemId, PRInt64 aOldParent,
PRInt32 aOldIndex, PRInt64 aNewParent, PRInt32 aOldIndex, PRInt64 aNewParent,
PRInt32 aNewIndex) PRInt32 aNewIndex)
{ {
@ -3315,8 +3315,8 @@ nsNavHistoryFolderResultNode::OnFolderMoved(PRInt64 aFolder, PRInt64 aOldParent,
ReindexRange(aNewIndex, PR_INT32_MAX, 1); ReindexRange(aNewIndex, PR_INT32_MAX, 1);
PRUint32 index; PRUint32 index;
nsNavHistoryFolderResultNode* node = FindChildFolder(aFolder, &index); nsNavHistoryResultNode* node = FindChildById(aItemId, &index);
if (! node) { if (!node) {
NS_NOTREACHED("Can't find folder that is moving!"); NS_NOTREACHED("Can't find folder that is moving!");
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
@ -3332,7 +3332,7 @@ nsNavHistoryFolderResultNode::OnFolderMoved(PRInt64 aFolder, PRInt64 aOldParent,
if (DoesChildNeedResorting(index, comparator, sortingAnnotation.get())) { if (DoesChildNeedResorting(index, comparator, sortingAnnotation.get())) {
// needs resorting, this will cause everything to be redrawn, so we // needs resorting, this will cause everything to be redrawn, so we
// don't need to do that explicitly later. // don't need to do that explicitly later.
nsRefPtr<nsNavHistoryContainerResultNode> lock(node); nsRefPtr<nsNavHistoryResultNode> lock(node);
RemoveChildAt(index, PR_TRUE); RemoveChildAt(index, PR_TRUE);
InsertChildAt(node, InsertChildAt(node,
FindInsertionPoint(node, comparator, sortingAnnotation.get()), FindInsertionPoint(node, comparator, sortingAnnotation.get()),
@ -3343,9 +3343,9 @@ nsNavHistoryFolderResultNode::OnFolderMoved(PRInt64 aFolder, PRInt64 aOldParent,
} else { } else {
// moving between two different folders, just do a remove and an add // moving between two different folders, just do a remove and an add
if (aOldParent == mItemId) if (aOldParent == mItemId)
OnItemRemoved(aFolder, aOldParent, aOldIndex); OnItemRemoved(aItemId, aOldParent, aOldIndex);
if (aNewParent == mItemId) if (aNewParent == mItemId)
OnItemAdded(aFolder, aNewParent, aNewIndex); OnItemAdded(aItemId, aNewParent, aNewIndex);
} }
return NS_OK; return NS_OK;
} }
@ -3854,25 +3854,25 @@ nsNavHistoryResult::OnItemVisited(PRInt64 aItemId, PRInt64 aVisitId,
} }
// nsNavHistoryResult::OnFolderMoved (nsINavBookmarkObserver) // nsNavHistoryResult::OnItemMoved (nsINavBookmarkObserver)
// //
// Need to notify both the source and the destination folders (if they // Need to notify both the source and the destination folders (if they
// are different). // are different).
NS_IMETHODIMP NS_IMETHODIMP
nsNavHistoryResult::OnFolderMoved(PRInt64 aFolder, nsNavHistoryResult::OnItemMoved(PRInt64 aItemId,
PRInt64 aOldParent, PRInt32 aOldIndex, PRInt64 aOldParent, PRInt32 aOldIndex,
PRInt64 aNewParent, PRInt32 aNewIndex) PRInt64 aNewParent, PRInt32 aNewIndex)
{ {
{ // scope for loop index for VC6's broken for loop scoping { // scope for loop index for VC6's broken for loop scoping
ENUMERATE_BOOKMARK_OBSERVERS_FOR_FOLDER(aOldParent, ENUMERATE_BOOKMARK_OBSERVERS_FOR_FOLDER(aOldParent,
OnFolderMoved(aFolder, aOldParent, aOldIndex, aNewParent, aNewIndex)); OnItemMoved(aItemId, aOldParent, aOldIndex, aNewParent, aNewIndex));
} }
if (aNewParent != aOldParent) { if (aNewParent != aOldParent) {
ENUMERATE_BOOKMARK_OBSERVERS_FOR_FOLDER(aNewParent, ENUMERATE_BOOKMARK_OBSERVERS_FOR_FOLDER(aNewParent,
OnFolderMoved(aFolder, aOldParent, aOldIndex, aNewParent, aNewIndex)); OnItemMoved(aItemId, aOldParent, aOldIndex, aNewParent, aNewIndex));
} }
ENUMERATE_HISTORY_OBSERVERS(OnFolderMoved(aFolder, aOldParent, aOldIndex, ENUMERATE_HISTORY_OBSERVERS(OnItemMoved(aItemId, aOldParent, aOldIndex,
aNewParent, aNewIndex)); aNewParent, aNewIndex));
return NS_OK; return NS_OK;
} }

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

@ -87,12 +87,12 @@ var observer = {
this._itemVisitedVistId = visitID; this._itemVisitedVistId = visitID;
this._itemVisitedTime = time; this._itemVisitedTime = time;
}, },
onFolderMoved: function(folder, oldParent, oldIndex, newParent, newIndex) { onItemMoved: function(id, oldParent, oldIndex, newParent, newIndex) {
this._folderMoved = folder; this._itemMovedId = id
this._folderMovedOldParent = oldParent; this._itemMovedOldParent = oldParent;
this._folderMovedOldIndex = oldIndex; this._itemMovedOldIndex = oldIndex;
this._folderMovedNewParent = newParent; this._itemMovedNewParent = newParent;
this._folderMovedNewIndex = newIndex; this._itemMovedNewIndex = newIndex;
}, },
onFolderChanged: function(folder, property) { onFolderChanged: function(folder, property) {
this._folderChanged = folder; this._folderChanged = folder;
@ -271,12 +271,12 @@ function run_test() {
// move folder, appending, to different folder // move folder, appending, to different folder
var oldParentCC = getChildCount(testRoot); var oldParentCC = getChildCount(testRoot);
bmsvc.moveFolder(workFolder, homeFolder, bmsvc.DEFAULT_INDEX); bmsvc.moveItem(workFolder, homeFolder, bmsvc.DEFAULT_INDEX);
do_check_eq(observer._folderMoved, workFolder); do_check_eq(observer._itemMovedId, workFolder);
do_check_eq(observer._folderMovedOldParent, testRoot); do_check_eq(observer._itemMovedOldParent, testRoot);
do_check_eq(observer._folderMovedOldIndex, 0); do_check_eq(observer._itemMovedOldIndex, 0);
do_check_eq(observer._folderMovedNewParent, homeFolder); do_check_eq(observer._itemMovedNewParent, homeFolder);
do_check_eq(observer._folderMovedNewIndex, 1); do_check_eq(observer._itemMovedNewIndex, 1);
// test that the new index is properly stored // test that the new index is properly stored
do_check_eq(bmsvc.getItemIndex(workFolder), 1); do_check_eq(bmsvc.getItemIndex(workFolder), 1);
@ -292,7 +292,14 @@ function run_test() {
// XXX move folder, specify same index, within the same folder // XXX move folder, specify same index, within the same folder
// XXX move folder, appending, within the same folder // XXX move folder, appending, within the same folder
// XXX move item, appending, to different folder // move item, appending, to different folder
bmsvc.moveItem(newId5, testRoot, bmsvc.DEFAULT_INDEX);
do_check_eq(observer._itemMovedId, newId5);
do_check_eq(observer._itemMovedOldParent, homeFolder);
do_check_eq(observer._itemMovedOldIndex, 0);
do_check_eq(observer._itemMovedNewParent, testRoot);
do_check_eq(observer._itemMovedNewIndex, 3);
// XXX move item, specified index, to different folder // XXX move item, specified index, to different folder
// XXX move item, specified index, within the same folder // XXX move item, specified index, within the same folder
// XXX move item, specify same index, within the same folder // XXX move item, specify same index, within the same folder
@ -300,8 +307,8 @@ function run_test() {
// Test expected failure of moving a folder to be its own parent // Test expected failure of moving a folder to be its own parent
try { try {
bmsvc.moveFolder(workFolder, workFolder, bmsvc.DEFAULT_INDEX); bmsvc.moveItem(workFolder, workFolder, bmsvc.DEFAULT_INDEX);
do_throw("moveFolder() allowed moving a folder to be it's own parent."); do_throw("moveItem() allowed moving a folder to be it's own parent.");
} catch (e) {} } catch (e) {}
// test insertSeparator and removeChildAt // test insertSeparator and removeChildAt
@ -508,7 +515,7 @@ function run_test() {
var newId13 = bmsvc.insertItem(testRoot, uri("http://foobarcheese.com/"), bmsvc.DEFAULT_INDEX); var newId13 = bmsvc.insertItem(testRoot, uri("http://foobarcheese.com/"), bmsvc.DEFAULT_INDEX);
do_check_eq(observer._itemAddedId, newId13); do_check_eq(observer._itemAddedId, newId13);
do_check_eq(observer._itemAddedParent, testRoot); do_check_eq(observer._itemAddedParent, testRoot);
do_check_eq(observer._itemAddedIndex, 12); do_check_eq(observer._itemAddedIndex, 13);
// set bookmark title // set bookmark title
bmsvc.setItemTitle(newId13, "ZZZXXXYYY"); bmsvc.setItemTitle(newId13, "ZZZXXXYYY");

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

@ -67,12 +67,8 @@ var observer =
bmsvc.removeObserver(this); bmsvc.removeObserver(this);
}, },
onItemVisited: function(bookmarkId, bookmark, aVisitID, time){}, onItemVisited: function(bookmarkId, bookmark, aVisitID, time){},
onFolderAdded: function(folder, parent, index){}, onItemMoved: function(itemId, oldParent, oldIndex, newParent, newIndex){},
onFolderRemoved: function(folder, parent, index){}, onFolderChanged: function(folder, property){}
onFolderMoved: function(folder, oldParent, oldIndex, newParent, newIndex){},
onFolderChanged: function(folder, property){},
onSeparatorAdded: function(parent, index){},
onSeparatorRemoved: function(parent, index){}
}; };
bmsvc.addObserver(observer, false); bmsvc.addObserver(observer, false);

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

@ -59,12 +59,8 @@ var observer =
onItemRemoved: function(itemId, folder, index){}, onItemRemoved: function(itemId, folder, index){},
onItemChanged: function(itemId, property, isAnnotationProperty, value){}, onItemChanged: function(itemId, property, isAnnotationProperty, value){},
onItemVisited: function(itemId, aVisitID, time){}, onItemVisited: function(itemId, aVisitID, time){},
onFolderAdded: function(folder, parent, index){}, onItemMoved: function(itemId, oldParent, oldIndex, newParent, newIndex){},
onFolderRemoved: function(folder, parent, index){},
onFolderMoved: function(folder, oldParent, oldIndex, newParent, newIndex){},
onFolderChanged: function(folder, property){}, onFolderChanged: function(folder, property){},
onSeparatorAdded: function(parent, index){},
onSeparatorRemoved: function(parent, index){},
// nsIAnnotationObserver // nsIAnnotationObserver
onItemAnnotationSet: function(aItemId, aAnnotationName) { onItemAnnotationSet: function(aItemId, aAnnotationName) {