fix for bug #382221: Dragging bookmark on toolbar doesn't give permanent resultwe need to adjust the indices before we make the change to the item we aremoving, otherwise, our we'll impact the index of the item we are moving.r=dietrich

This commit is contained in:
sspitzer@mozilla.org 2007-05-30 16:25:19 -07:00
Родитель 485ecbb620
Коммит 3096678093
1 изменённых файлов: 20 добавлений и 18 удалений

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

@ -1455,25 +1455,9 @@ nsNavBookmarks::MoveItem(PRInt64 aItemId, PRInt64 aNewParent, PRInt32 aIndex)
return NS_OK;
}
// update parent/index fields
nsCAutoString buffer;
buffer.AssignLiteral("UPDATE moz_bookmarks SET ");
if (aNewParent != oldParent) {
buffer.AppendLiteral(" parent = ");
buffer.AppendInt(aNewParent);
}
if (newIndex != oldIndex) {
if (aNewParent != oldParent)
buffer.AppendLiteral(", ");
buffer.AppendLiteral(" position = ");
buffer.AppendInt(newIndex);
}
buffer.AppendLiteral(" WHERE id = ");
buffer.AppendInt(aItemId);
rv = dbConn->ExecuteSimpleSQL(buffer);
NS_ENSURE_SUCCESS(rv, rv);
// adjust indices to account for the move
// do this before we update the parent/index fields
// or we'll re-adjust the index for the item we are moving
if (oldParent == aNewParent) {
// We can optimize the updates if moving within the same container.
// We only shift the items between the old and new positions, since the
@ -1493,6 +1477,24 @@ nsNavBookmarks::MoveItem(PRInt64 aItemId, PRInt64 aNewParent, PRInt32 aIndex)
}
NS_ENSURE_SUCCESS(rv, rv);
// update parent/index fields
nsCAutoString buffer;
buffer.AssignLiteral("UPDATE moz_bookmarks SET ");
if (aNewParent != oldParent) {
buffer.AppendLiteral(" parent = ");
buffer.AppendInt(aNewParent);
}
if (newIndex != oldIndex) {
if (aNewParent != oldParent)
buffer.AppendLiteral(", ");
buffer.AppendLiteral(" position = ");
buffer.AppendInt(newIndex);
}
buffer.AppendLiteral(" WHERE id = ");
buffer.AppendInt(aItemId);
rv = dbConn->ExecuteSimpleSQL(buffer);
NS_ENSURE_SUCCESS(rv, rv);
rv = transaction.Commit();
NS_ENSURE_SUCCESS(rv, rv);