Bug 396300 - Put unfiled-bookmarks under their own root. r=dietirch, a=mconnor.

This commit is contained in:
mozilla.mano@sent.com 2007-09-16 18:42:15 -07:00
Родитель e0dbe1f429
Коммит dc139dbe05
8 изменённых файлов: 54 добавлений и 86 удалений

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

@ -154,7 +154,7 @@ var PlacesCommandHook = {
* a <browser> element.
* @param [optional] aParent
* The folder in which to create a new bookmark if the page loaded in
* aBrowser isn't bookmarked yet, defaults to the places root.
* aBrowser isn't bookmarked yet, defaults to the unfiled root.
* @param [optional] aShowEditUI
* whether or not to show the edit-bookmark UI for the bookmark item
* @param [optional] aAnchorElement
@ -183,7 +183,7 @@ var PlacesCommandHook = {
}
catch (e) { }
var parent = aParent != undefined ? aParent : PlacesUtils.placesRootId;
var parent = aParent != undefined ? aParent : PlacesUtils.unfiledRootId;
var descAnno = { name: DESCRIPTION_ANNO, value: description };
var txn = PlacesUtils.ptm.createItem(uri, parent, -1,
title, null, [descAnno]);

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

@ -157,7 +157,7 @@ var gEditItemOverlay = {
var container = PlacesUtils.bookmarks.getFolderIdForItem(this._itemId);
// only show "All Bookmarks" if the url isn't bookmarked somewhere else
this._element("placesRootItem").hidden = container != PlacesUtils.placesRootId;
this._element("unfiledRootItem").hidden = container != PlacesUtils.unfiledRootId;
// List of recently used folders:
var annos = PlacesUtils.annotations;
@ -479,8 +479,8 @@ var gEditItemOverlay = {
function EIO__getFolderIdFromMenuList() {
var selectedItem = this._folderMenuList.selectedItem
switch (selectedItem.id) {
case "editBMPanel_placesRootItem":
return PlacesUtils.placesRootId;
case "editBMPanel_unfiledRootItem":
return PlacesUtils.unfiledRootId;
case "editBMPanel_bmRootItem":
return PlacesUtils.bookmarksRootId;
case "editBMPanel_toolbarFolderItem":
@ -515,8 +515,8 @@ var gEditItemOverlay = {
}
if (aCheckStaticFolderItems) {
if (aFolderId == PlacesUtils.placesRootId)
return this._element("placesRootItem");
if (aFolderId == PlacesUtils.unfiledRootId)
return this._element("unfiledRootItem");
if (aFolderId == PlacesUtils.bookmarksRootId)
return this._element("bmRootItem");
if (aFolderId == PlacesUtils.toolbarFolderId)
@ -540,7 +540,7 @@ var gEditItemOverlay = {
// Mark the containing folder as recently-used if it isn't the
// "All Bookmarks" root
if (container != PlacesUtils.placesRootId)
if (container != PlacesUtils.unfiledRootId)
this._markFolderAsRecentlyUsed(container);
}

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

@ -90,7 +90,7 @@
oncommand="gEditItemOverlay.onFolderMenuListCommand();">
<menupopup>
<!-- Static item for special folders -->
<menuitem id="editBMPanel_placesRootItem"
<menuitem id="editBMPanel_unfiledRootItem"
label="&editBookmarkOverlay.allBookmarksFolderItem.label;"
class="menuitem-iconic folder-icon"/>
<menuitem id="editBMPanel_bmRootItem"

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

@ -1454,6 +1454,13 @@ var PlacesUtils = {
return this._tagRootId;
},
get unfiledRootId() {
if (!("_unfiledRootId" in this))
this._unfiledRootId = this.bookmarks.unfiledRoot;
return this._unfiledRootId;
},
/**
* Set the POST data associated with a URI, if any.
* Used by POST keywords.
@ -1504,8 +1511,9 @@ var PlacesUtils = {
for each (var bk in bmkIds) {
// Find the first folder which isn't a tag container
var parent = this.bookmarks.getFolderIdForItem(bk);
if (parent == this.placesRootId)
if (parent == this.unfiledRootId)
return bk;
var grandparent = this.bookmarks.getFolderIdForItem(parent);
if (grandparent != this.tagRootId &&
!this.annotations.itemHasAnnotation(parent, LMANNO_FEEDURI))

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

@ -163,7 +163,7 @@ interface nsINavBookmarkObserver : nsISupports
* folders. A URI in history can be contained in one or more such folders.
*/
[scriptable, uuid(117e4d4c-8c10-4c50-b588-848942b55b6e)]
[scriptable, uuid(3ba9f6ca-0003-43b9-bdfb-7014dfec5b76)]
interface nsINavBookmarksService : nsISupports
{
/**
@ -178,12 +178,14 @@ interface nsINavBookmarksService : nsISupports
/**
* The folder ID of the top-level folders that contain the tag "folders".
*
* NOTE: This isn't wired up yet, so don't try to use it for anything until
* bug 329961 is marked resolved.
*/
readonly attribute long long tagRoot;
/**
* The folder ID of the unfiled-bookmarks root
*/
readonly attribute long long unfiledRoot;
/**
* The folder ID of the personal toolbar.
*/

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

@ -263,6 +263,19 @@ nsNavBookmarks::Init()
mLock = PR_NewLock();
NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
// Temporary migration code for bug 396300
nsCOMPtr<mozIStorageStatement> moveUnfiledBookmarks;
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING("UPDATE moz_bookmarks SET parent = ?1 WHERE type = ?2 AND parent=?3"),
getter_AddRefs(moveUnfiledBookmarks));
rv = moveUnfiledBookmarks->BindInt64Parameter(0, mUnfiledRoot);
NS_ENSURE_SUCCESS(rv, rv);
rv = moveUnfiledBookmarks->BindInt32Parameter(1, TYPE_BOOKMARK);
NS_ENSURE_SUCCESS(rv, rv);
rv = moveUnfiledBookmarks->BindInt32Parameter(2, mRoot);
NS_ENSURE_SUCCESS(rv, rv);
rv = moveUnfiledBookmarks->Execute();
NS_ENSURE_SUCCESS(rv, rv);
nsAnnotationService* annosvc = nsAnnotationService::GetAnnotationService();
NS_ENSURE_TRUE(annosvc, NS_ERROR_OUT_OF_MEMORY);
@ -401,6 +414,10 @@ nsNavBookmarks::InitRoots()
rv = CreateRoot(getRootStatement, NS_LITERAL_CSTRING("tags"), &mTagRoot, mRoot, nsnull);
NS_ENSURE_SUCCESS(rv, rv);
getRootStatement->Reset();
rv = CreateRoot(getRootStatement, NS_LITERAL_CSTRING("unfiled"), &mUnfiledRoot, mRoot, nsnull);
NS_ENSURE_SUCCESS(rv, rv);
if (importDefaults) {
// when there is no places root, we should define the hierarchy by
// importing the default one.
@ -408,25 +425,6 @@ nsNavBookmarks::InitRoots()
NS_ENSURE_SUCCESS(rv, rv);
}
// migration for bug 382094 - remove for A6
PRInt64 parent;
rv = GetFolderIdForItem(mBookmarksRoot, &parent);
if (NS_FAILED(rv) || parent == 0) {
nsCOMPtr<mozIStorageStatement> statement;
rv = DBConn()->CreateStatement(NS_LITERAL_CSTRING("UPDATE moz_bookmarks SET parent = ?1 WHERE id = ?2 or id = ?3"),
getter_AddRefs(statement));
NS_ENSURE_SUCCESS(rv, rv);
rv = statement->BindInt64Parameter(0, mRoot);
NS_ENSURE_SUCCESS(rv, rv);
rv = statement->BindInt64Parameter(1, mBookmarksRoot);
NS_ENSURE_SUCCESS(rv, rv);
rv = statement->BindInt64Parameter(2, mTagRoot);
NS_ENSURE_SUCCESS(rv, rv);
rv = statement->Execute();
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK;
}
@ -473,60 +471,11 @@ nsNavBookmarks::InitToolbarFolder()
nsTArray<PRInt64> folders;
nsresult rv = annosvc->GetItemsWithAnnotationTArray(BOOKMARKS_TOOLBAR_FOLDER_ANNO,
&folders);
if (NS_FAILED(rv) || folders.Length() == 0) {
/**
* XXXmano: temporary migaration code, should be removed some time
* after alpha 5.
*/
mozIStorageConnection *dbConn = DBConn();
if (NS_FAILED(rv) || folders.Length() == 0)
mToolbarFolder = -1;
else
mToolbarFolder = folders[0];
nsCOMPtr<mozIStorageStatement> statement;
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING("SELECT id from moz_bookmarks WHERE folder_type = 'toolbar'"),
getter_AddRefs(statement));
NS_ENSURE_SUCCESS(rv, rv);
PRBool hasResult;
rv = statement->ExecuteStep(&hasResult);
NS_ENSURE_SUCCESS(rv, rv);
if (hasResult) {
PRInt64 toolbarFolder;
rv = statement->GetInt64(0, &toolbarFolder);
NS_ENSURE_SUCCESS(rv, rv);
rv = SetToolbarFolder(toolbarFolder);
NS_ENSURE_SUCCESS(rv, rv);
} else {
/**
* XXXdietrich: temporary migration code to fix bug 389808.
* should be removed some time after alpha 7.
*/
nsCOMPtr<mozIStorageStatement> getToolbarFolderStatement;
rv = dbConn->CreateStatement(NS_LITERAL_CSTRING("SELECT id from moz_bookmarks WHERE title = ?1 AND type = ?2"),
getter_AddRefs(getToolbarFolderStatement));
NS_ENSURE_SUCCESS(rv, rv);
nsXPIDLString toolbarTitle;
rv = mBundle->GetStringFromName(NS_LITERAL_STRING("PlacesBookmarksToolbarTitle").get(),
getter_Copies(toolbarTitle));
NS_ENSURE_SUCCESS(rv, rv);
rv = getToolbarFolderStatement->BindStringParameter(0, toolbarTitle);
NS_ENSURE_SUCCESS(rv, rv);
rv = getToolbarFolderStatement->BindInt32Parameter(1, TYPE_FOLDER);
NS_ENSURE_SUCCESS(rv, rv);
rv = getToolbarFolderStatement->ExecuteStep(&hasResult);
NS_ENSURE_SUCCESS(rv, rv);
if (hasResult) {
PRInt64 toolbarFolder;
rv = getToolbarFolderStatement->GetInt64(0, &toolbarFolder);
NS_ENSURE_SUCCESS(rv, rv);
rv = SetToolbarFolder(toolbarFolder);
NS_ENSURE_SUCCESS(rv, rv);
}
}
return NS_OK;
}
mToolbarFolder = folders[0];
return NS_OK;
}
@ -938,6 +887,13 @@ nsNavBookmarks::GetTagRoot(PRInt64 *aRoot)
return NS_OK;
}
NS_IMETHODIMP
nsNavBookmarks::GetUnfiledRoot(PRInt64 *aRoot)
{
*aRoot = mUnfiledRoot;
return NS_OK;
}
NS_IMETHODIMP
nsNavBookmarks::InsertBookmark(PRInt64 aFolder, nsIURI *aItem, PRInt32 aIndex,
const nsAString& aTitle,

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

@ -138,6 +138,7 @@ private:
PRInt64 mRoot;
PRInt64 mBookmarksRoot;
PRInt64 mTagRoot;
PRInt64 mUnfiledRoot;
// personal toolbar folder
PRInt64 mToolbarFolder;

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

@ -117,6 +117,7 @@ function run_test() {
do_check_true(bmsvc.bookmarksRoot > 0);
do_check_true(bmsvc.tagRoot > 0);
do_check_true(bmsvc.toolbarFolder > 0);
do_check_true(bmsvc.unfiledRoot > 0);
// test root parentage
do_check_eq(bmsvc.getFolderIdForItem(bmsvc.bookmarksRoot), bmsvc.placesRoot);