From 42c99db36e2ac249fd75509094e5a9b33b117710 Mon Sep 17 00:00:00 2001 From: "brettw%gmail.com" Date: Fri, 10 Mar 2006 19:44:28 +0000 Subject: [PATCH] Bug 329854 r=joe.hughes Add a excludeReadOnlyFolders to query options for use when filing. --- .../places/public/nsINavHistoryService.idl | 10 +++++++ .../components/places/src/nsNavBookmarks.cpp | 9 +++++++ .../places/src/nsNavHistoryQuery.cpp | 26 +++++++++++++++++++ .../components/places/src/nsNavHistoryQuery.h | 3 +++ .../places/src/nsNavHistoryResult.cpp | 3 ++- 5 files changed, 50 insertions(+), 1 deletion(-) diff --git a/browser/components/places/public/nsINavHistoryService.idl b/browser/components/places/public/nsINavHistoryService.idl index fcce2bbe1820..c7870b4ba0d0 100644 --- a/browser/components/places/public/nsINavHistoryService.idl +++ b/browser/components/places/public/nsINavHistoryService.idl @@ -831,6 +831,16 @@ interface nsINavHistoryQueryOptions : nsISupports */ attribute boolean excludeQueries; + /** + * Set to true to exclude read-only folders from the query results. This is + * designed for cases where you want to give the user the option of filing + * something into a list of folders. It only affects cases where the actual + * folder result node would appear in its parent folder and filters it out. + * It doesn't affect the query at all, and doesn't affect more complex + * queries (such as "folders with annotation X"). + */ + attribute boolean excludeReadOnlyFolders; + /** * When set, allows items with "place:" URIs to appear as containers, * with the container's contents filled in from the stored query. diff --git a/browser/components/places/src/nsNavBookmarks.cpp b/browser/components/places/src/nsNavBookmarks.cpp index d087ef090d9d..f1ac3bc2c725 100644 --- a/browser/components/places/src/nsNavBookmarks.cpp +++ b/browser/components/places/src/nsNavBookmarks.cpp @@ -1644,6 +1644,15 @@ nsNavBookmarks::QueryFolderChildren(PRInt64 aFolderId, nsCOMPtr node; if (isFolder) { PRInt64 folder = mDBGetChildren->AsInt64(kGetChildrenIndex_FolderChild); + + if (options->ExcludeReadOnlyFolders()) { + // see if it's read only and skip it + PRBool readOnly = PR_FALSE; + GetFolderReadonly(folder, &readOnly); + if (readOnly) + continue; // skip + } + rv = ResultNodeForFolder(folder, aOptions, getter_AddRefs(node)); if (NS_FAILED(rv)) continue; diff --git a/browser/components/places/src/nsNavHistoryQuery.cpp b/browser/components/places/src/nsNavHistoryQuery.cpp index 270b26a54fdd..34aeba39c2ab 100644 --- a/browser/components/places/src/nsNavHistoryQuery.cpp +++ b/browser/components/places/src/nsNavHistoryQuery.cpp @@ -152,6 +152,7 @@ static void SetOptionsKeyUint32(const nsCString& aValue, #define QUERYKEY_RESULT_TYPE "type" #define QUERYKEY_EXCLUDE_ITEMS "excludeItems" #define QUERYKEY_EXCLUDE_QUERIES "excludeQueries" +#define QUERYKEY_EXCLUDE_READ_ONLY_FOLDERS "excludeReadOnlyFolders" #define QUERYKEY_EXPAND_QUERIES "expandQueries" #define QUERYKEY_FORCE_ORIGINAL_TITLE "originalTitle" #define QUERYKEY_INCLUDE_HIDDEN "includeHidden" @@ -416,6 +417,12 @@ nsNavHistory::QueriesToQueryString(nsINavHistoryQuery **aQueries, aQueryString += NS_LITERAL_CSTRING(QUERYKEY_EXCLUDE_QUERIES "=1"); } + // exclude read only folders + if (options->ExcludeReadOnlyFolders()) { + AppendAmpersandIfNonempty(aQueryString); + aQueryString += NS_LITERAL_CSTRING(QUERYKEY_EXCLUDE_READ_ONLY_FOLDERS "=1"); + } + // expand queries if (options->ExpandQueries()) { AppendAmpersandIfNonempty(aQueryString); @@ -627,6 +634,11 @@ nsNavHistory::TokensToQueries(const nsTArray& aTokens, SetOptionsKeyBool(kvp.value, aOptions, &nsINavHistoryQueryOptions::SetExcludeQueries); + // exclude read only folders + } else if (kvp.key.EqualsLiteral(QUERYKEY_EXCLUDE_READ_ONLY_FOLDERS)) { + SetOptionsKeyBool(kvp.value, aOptions, + &nsINavHistoryQueryOptions::SetExcludeReadOnlyFolders); + // expand queries } else if (kvp.key.EqualsLiteral(QUERYKEY_EXPAND_QUERIES)) { SetOptionsKeyBool(kvp.value, aOptions, @@ -1058,6 +1070,20 @@ nsNavHistoryQueryOptions::SetExcludeQueries(PRBool aExclude) return NS_OK; } +// excludeReadOnlyFolders +NS_IMETHODIMP +nsNavHistoryQueryOptions::GetExcludeReadOnlyFolders(PRBool* aExclude) +{ + *aExclude = mExcludeReadOnlyFolders; + return NS_OK; +} +NS_IMETHODIMP +nsNavHistoryQueryOptions::SetExcludeReadOnlyFolders(PRBool aExclude) +{ + mExcludeReadOnlyFolders = aExclude; + return NS_OK; +} + // expandQueries NS_IMETHODIMP nsNavHistoryQueryOptions::GetExpandQueries(PRBool* aExpand) diff --git a/browser/components/places/src/nsNavHistoryQuery.h b/browser/components/places/src/nsNavHistoryQuery.h index 495db81f3ddb..0b579beb47a5 100644 --- a/browser/components/places/src/nsNavHistoryQuery.h +++ b/browser/components/places/src/nsNavHistoryQuery.h @@ -117,6 +117,7 @@ public: mGroupCount(0), mGroupings(nsnull), mExcludeItems(PR_FALSE), mExcludeQueries(PR_FALSE), + mExcludeReadOnlyFolders(PR_FALSE), mExpandQueries(PR_FALSE), mForceOriginalTitle(PR_FALSE), mIncludeHidden(PR_FALSE), @@ -139,6 +140,7 @@ public: } PRBool ExcludeItems() const { return mExcludeItems; } PRBool ExcludeQueries() const { return mExcludeQueries; } + PRBool ExcludeReadOnlyFolders() const { return mExcludeReadOnlyFolders; } PRBool ExpandQueries() const { return mExpandQueries; } PRBool ForceOriginalTitle() const { return mForceOriginalTitle; } PRBool IncludeHidden() const { return mIncludeHidden; } @@ -163,6 +165,7 @@ private: PRUint32 *mGroupings; PRBool mExcludeItems; PRBool mExcludeQueries; + PRBool mExcludeReadOnlyFolders; PRBool mExpandQueries; PRBool mForceOriginalTitle; PRBool mIncludeHidden; diff --git a/browser/components/places/src/nsNavHistoryResult.cpp b/browser/components/places/src/nsNavHistoryResult.cpp index 631e9555fa1f..595d489e9cb9 100755 --- a/browser/components/places/src/nsNavHistoryResult.cpp +++ b/browser/components/places/src/nsNavHistoryResult.cpp @@ -2637,7 +2637,8 @@ nsNavHistoryFolderResultNode::StartIncrementalUpdate() { // if any items are excluded, we can not do incremental updates since the // indices from the bookmark service will not be valid - if (! mOptions->ExcludeItems() && ! mOptions->ExcludeQueries()) { + if (! mOptions->ExcludeItems() && ! mOptions->ExcludeQueries() && + ! mOptions->ExcludeReadOnlyFolders()) { // easy case: we are visible, always do incremental update if (mExpanded || AreChildrenVisible())