Closed Bug 325342 Opened 19 years ago Closed 17 years ago

Allow bookmark folders to be sorted

Categories

(Firefox :: Bookmarks & History, defect)

defect
Not set
normal

Tracking

()

VERIFIED FIXED
Firefox 3 alpha5

People

(Reporter: brettw, Assigned: enndeakin)

References

Details

(Whiteboard: [Fx2-parity])

Attachments

(1 file, 6 obsolete files)

Implement the "Sort by name" item in the context menu of the places view.
It might be nice to add the sorting function to the bookmark service so anybody could easily call it.
Priority: -- → P4
Target Milestone: --- → Firefox 2 alpha2
Assignee: bugs → nobody
Priority: P4 → --
Whiteboard: [Fx2-parity]
Target Milestone: Firefox 2 alpha2 → Firefox 3
Blocks: 370099
Is this command supposed to just change the sort such that the tree is sorted by title, or is it supposed to take the contents of the folder that was context-clicked and sorts the underlying data permanently? 
The later.
Attached patch work in progress (obsolete) — Splinter Review
This is a work in progress. It sorts by name, but doesn't update the UI properly. The code in nsNavBookmarks::SetItemIndex needs to be updated to ensure this.
Attached patch add sort by name function (obsolete) — Splinter Review
Assignee: nobody → enndeakin
Attachment #260666 - Attachment is obsolete: true
Status: NEW → ASSIGNED
Attachment #261901 - Flags: review?
Attachment #261901 - Flags: review? → review?(dietrich)
Comment on attachment 261901 [details] [diff] [review]
add sort by name function

>Index: browser/components/places/content/controller.js
>===================================================================
>RCS file: /cvsroot/mozilla/browser/components/places/content/controller.js,v
>retrieving revision 1.141
>diff -u -p -8 -r1.141 controller.js
>--- browser/components/places/content/controller.js	30 Mar 2007 23:16:24 -0000	1.141
>+++ browser/components/places/content/controller.js	18 Apr 2007 00:31:43 -0000
>@@ -200,16 +200,20 @@ PlacesController.prototype = {  
>         // children of a live bookmark (legacy bookmarks UI doesn't support
>         // this)
>         if (PlacesUtils.nodeIsURI() &&
>             PlacesUtils.nodeIsLivemarkItem(selectedNode))
>           return true;
> #endif
>       }
>       return false;
>+    case "placesCmd_sortby:name":

"sortBy" would be more in line with the style here.

>   /**
>+   * Changes the index for a bookmark item.
>+   */
>+  void setItemIndex(in PRInt64 id, in PRInt32 index);
>+

can you add @param documentation for this?

> NS_IMETHODIMP
>+nsNavBookmarks::SetItemIndex(PRInt64 aItemId, PRInt32 aNewIndex)
>+{
>+  nsresult rv;
>+  PRInt32 type = 0;
>+  PRInt32 oldIndex = 0;
>+  PRInt64 parent = 0;
>+  PRInt64 folderKey = -1;
>+
>+  mozIStorageConnection *dbConn = DBConn();
>+  nsCOMPtr<nsIURI> uri;
>+  {
>+    nsCOMPtr<mozIStorageStatement> getStatement;
>+    rv = dbConn->CreateStatement(NS_LITERAL_CSTRING(
>+      "SELECT b.type, p.url, b.position, b.parent, b.fk "
>+      "FROM moz_bookmarks b "
>+      "JOIN moz_places p ON b.fk = p.id "
>+      "WHERE b.id = ?1"),
>+    getter_AddRefs(getStatement));
>+    NS_ENSURE_SUCCESS(rv, rv);
>+

can you add the type column to the mDBGetBookmarkProperties statement and use that, instead of creating a new one?

>+
>+  if (type == TYPE_FOLDER) {
>+    ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
>+                        OnFolderRemoved(folderKey, parent, oldIndex))
>+    ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
>+                        OnFolderAdded(folderKey, parent, aNewIndex))
>+  }
>+  else if (type == TYPE_SEPARATOR) {
>+    ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
>+                        OnSeparatorRemoved(parent, oldIndex))
>+    ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
>+                        OnSeparatorAdded(parent, aNewIndex))
>+  }
>+  else {
>+    ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
>+                        OnItemRemoved(aItemId, uri, parent, oldIndex))
>+    ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
>+                        OnItemAdded(aItemId, uri, parent, aNewIndex))
>+  }

yikes, there's got to be a better way. can you file a followup bug for using onItemChanged for this?
Attachment #261901 - Flags: review?(dietrich) → review-
Attached patch address review comments (obsolete) — Splinter Review
Attachment #261901 - Attachment is obsolete: true
Attachment #262033 - Flags: review?(dietrich)
Comment on attachment 262033 [details] [diff] [review]
address review comments

r=me, please have mano do a pass on this as well. thanks neil!

>   /**
>+   * Changes the index for a bookmark item. This method does not change
>+   * the indicies of any other bookmarks in the same folder.

nit: s/indicies/indices/
Attachment #262033 - Flags: review?(dietrich) → review+
(In reply to comment #9)
> (From update of attachment 262033 [details] [diff] [review])
> r=me, please have mano do a pass on this as well. thanks neil!
> 
> >   /**
> >+   * Changes the index for a bookmark item. This method does not change
> >+   * the indicies of any other bookmarks in the same folder.
> 
> nit: s/indicies/indices/
> 

another request: please add a warning that calling setItemIndex *will* cause the indexes to be corrupted if not called for each child of a container.

hrm, the whole deal should probably be moved into the bookmarks service at some point, would be safer.
Attached patch adjust comments (obsolete) — Splinter Review
Attachment #262037 - Flags: review?(mano)
Comment on attachment 262037 [details] [diff] [review]
adjust comments

>Index: browser/components/places/content/controller.js
>===================================================================

>@@ -200,16 +200,20 @@ PlacesController.prototype = {  
>         // children of a live bookmark (legacy bookmarks UI doesn't support
>         // this)
>         if (PlacesUtils.nodeIsURI() &&
>             PlacesUtils.nodeIsLivemarkItem(selectedNode))
>           return true;
> #endif
>       }
>       return false;
>+    case "placesCmd_sortBy:name":
>+      if (this._view.selectedNode)
>+        return PlacesUtils.nodeIsFolder(this._view.selectedNode);

This allows sorting a read-only folder (e.g. livemark-containers).

>   onEvent: function PC_onEvent(eventName) { },
>@@ -442,21 +449,21 @@ PlacesController.prototype = {  
>     // be filtered (e.g. left list). 
>     var enoughChildrenToSort = false;
>     if (PlacesUtils.nodeIsFolder(sortFolder)) {
>       var folder = asFolder(sortFolder);
>       var contents = this.getFolderContents(folder.folderId, false, false);
>       enoughChildrenToSort = contents.childCount > 1;
>     }
>     var metadata = this._buildSelectionMetadata();
>-    this._setEnabled("placesCmd_sortby:name", 
>+    this._setEnabled("placesCmd_sortBy:name", 
>       (sortingChildren || !inSysArea) && canInsert && viewIsFolder && 
>       !("mixed" in metadata) && enoughChildrenToSort);
> 
>-    var command = document.getElementById("placesCmd_sortby:name");
>+    var command = document.getElementById("placesCmd_sortBy:name");
>     

just remove this code, it's no longer used.
>   /**
>+   * Sort a folder by name
>+   */

s/ a / the selected/ ?

> /**
>+ * Sort a folder by name
>+ */
>+function PlacesSortFolderByNameTransaction(aFolderId, aFolderIndex) {
>+  this._folderId = aFolderId;
>+  this._folderIndex = aFolderIndex;
>+  this._oldOrder = null,
>+  this.redoTransaction = this.doTransaction;
>+}
>+PlacesSortFolderByNameTransaction.prototype = {
>+  __proto__: PlacesBaseTransaction.prototype,
>+
>+  doTransaction: function PSSFBN_doTransaction() {
>+    this._oldOrder = [];
>+
>+    var items = [];
>+    var contents = PlacesUtils.getFolderContents(this._folderId, false, false);

s/PlacesUtils/this.utils/


>Index: toolkit/components/places/src/nsNavBookmarks.cpp
>===================================================================

>+  if (type == TYPE_FOLDER) {
>+    ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
>+                        OnFolderRemoved(folderKey, parent, oldIndex))
>+    ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
>+                        OnFolderAdded(folderKey, parent, aNewIndex))
>+  }
>+  else if (type == TYPE_SEPARATOR) {
>+    ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
>+                        OnSeparatorRemoved(parent, oldIndex))
>+    ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
>+                        OnSeparatorAdded(parent, aNewIndex))
>+  }
>+  else {
>+    ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
>+                        OnItemRemoved(aItemId, uri, parent, oldIndex))
>+    ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
>+                        OnItemAdded(aItemId, uri, parent, aNewIndex))
>+  }
>+
>+  return NS_OK;
>+}

So it would be nice if we could somehow batch the setItemIndex calls and then call invalidateContainer... file a bug please.
Attachment #262037 - Flags: review?(mano) → review-
Attached patch address review comments (obsolete) — Splinter Review
Attachment #262037 - Attachment is obsolete: true
Attachment #262117 - Flags: review?(mano)
Comment on attachment 262117 [details] [diff] [review]
address review comments

You were looking for PlacesUtils.folderIsReadonly as a general solution.

Either way, nodeIsLivemarkItem checks if whether a node is a _child_ of a live bookmark
Attachment #262117 - Flags: review?(mano) → review-
mano, so something like the following:

    case "placesCmd_sortBy:name":
      var selectedNode = this._view.selectedNode;
      return selectedNode &&
             PlacesUtils.nodeIsFolder(selectedNode) &&
             !PlacesUtils.nodeIsReadOnly(selectedNode);
Seems right.
Attached patch check folders properly (obsolete) — Splinter Review
Attachment #262117 - Attachment is obsolete: true
Attachment #262490 - Flags: review?(mano)
Comment on attachment 262490 [details] [diff] [review]
check folders properly

r=mano
Attachment #262490 - Flags: review?(mano) → review+
Target Milestone: Firefox 3 → Firefox 3 alpha4
The patch in bug 376863 caused this to stop working, because the folders don't set the bookmarkId anymore. So what should I be using instead?
folderId for folder (asFolder(node).folderId that is).

Dietrich has a bug on unifying the two, I think.
Depends on: 372508
(In reply to comment #20)
> folderId for folder (asFolder(node).folderId that is).
> 
> Dietrich has a bug on unifying the two, I think.
> 

neil, you should still use mano's recommendation for getting the folder id. my patch changed the source of the folder ids, but not the accessor.
yeah well, i'm planning to merge the two soon enough.
No longer depends on: 372508
...and this is done now, the generic node interface has an itemId attribute.
Target Milestone: Firefox 3 alpha4 → Firefox 3 alpha5
Attachment #262033 - Attachment is obsolete: true
Attachment #262490 - Attachment is obsolete: true
Attachment #264466 - Flags: review?
Attachment #264466 - Flags: review? → review?(mano)
Comment on attachment 264466 [details] [diff] [review]
update for itemid

>Index: toolkit/components/places/public/nsINavBookmarksService.idl
>===================================================================


>   /**
>+   * Changes the index for a bookmark item. This method does not change
>+   * the indices of any other bookmarks in the same folder, so ensure that
>+   * the new index does not already exist, or change the index of other
>+   * bookmarks accordingly, otherwise the bookmark indices will become
>+   * corrupted.
>+   *
>+   *  @param id         The bookmark id to modify
>+   *  @param index      The new index
>+   */
>+  void setItemIndex(in PRInt64 id, in PRInt32 index);
>+

nit: use long long and long here.

r=mano otherwise.
Attachment #264466 - Flags: review?(mano) → review+
nit #2: aItemId and aIndex to match other methods.

you should also remove "bookmark" from the method documentation - this method applies to all item types (bookmarks, folders and separators).
Status: ASSIGNED → RESOLVED
Closed: 17 years ago
Resolution: --- → FIXED
verified with Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.9a7pre) Gecko/2007070504 Minefield/3.0a7pre
Status: RESOLVED → VERIFIED
Added test case http://litmus.mozilla.org/show_test.cgi?searchType=by_id&id=4454 to Litmus FFT
Flags: in-testsuite+
Flags: in-testsuite+ → in-litmus+
Bug 451915 - move Firefox/Places bugs to Firefox/Bookmarks and History. Remove all bugspam from this move by filtering for the string "places-to-b-and-h".

In Thunderbird 3.0b, you do that as follows:
Tools | Message Filters
Make sure the correct account is selected. Click "New"
Conditions: Body   contains   places-to-b-and-h
Change the action to "Delete Message".
Select "Manually Run" from the dropdown at the top.
Click OK.

Select the filter in the list, make sure "Inbox" is selected at the bottom, and click "Run Now". This should delete all the bugspam. You can then delete the filter.

Gerv
Component: Places → Bookmarks & History
QA Contact: places → bookmarks
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: