After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 484922 - Should remember the sort state of columns
Should remember the sort state of columns
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkFileChooser
2.12.x
Other All
: Normal enhancement
: ---
Assigned To: Federico Mena Quintero
Federico Mena Quintero
Depends on:
Blocks:
 
 
Reported: 2007-10-09 03:15 UTC by Federico Mena Quintero
Modified: 2009-06-12 22:58 UTC
See Also:
GNOME target: ---
GNOME version: 2.19/2.20


Attachments
this patch doesn't work, could you take a look at it and help me determine why column_changed_cb doesn't change the settings->sort_order/sort_column or impl->sort_order/sort_column (8.62 KB, patch)
2007-12-29 01:44 UTC, Benjamin Gramlich
none Details | Review
patch to remember sort order (8.76 KB, patch)
2008-01-02 20:32 UTC, Benjamin Gramlich
none Details | Review

Description Federico Mena Quintero 2007-10-09 03:15:52 UTC
The file chooser should remember the sort column, and the sort direction.

I would add these fields to gtkfilechooser.ini:

  SortColumn=[name|modified]
  SortOrder=[ascending|descending]

This bug is also filed at https://bugzilla.novell.com/show_bug.cgi?id=331690
Comment 1 Federico Mena Quintero 2007-11-30 18:08:38 UTC
Added the "gnome-love" keyword.  I'll be happy to mentor someone who wants to implement this simple feature.
Comment 2 Benjamin Gramlich 2007-12-11 18:04:13 UTC
If I'm not mistaken the code that handles this is in the "create_file_list" function in gtkfilechooserdefault.c. What would be the best way to implement this feature? Environment variables? I would appreciate any mentoring you can provide.
Comment 3 Federico Mena Quintero 2007-12-11 19:33:05 UTC
Hi, Benjamin, I'm glad you are interested in this! :)

The code to read the settings and apply the values to the file list should go in gtkfilechooserdefault.c:settings_load().

Right below that function is settings_save(); that's where you should read the values from the widgets and save them to the settings.

You'll need to modify gtkfilechoosersettings.[ch] for the new configuration values.  Just add two string keys like in the first comment in this bug; one to save the sort column and the other for ascending/descending order.
Comment 4 Benjamin Gramlich 2007-12-12 17:27:41 UTC
I worked on this for a bit last night, but I've become confused. I can save and load the settings, but I can't figure out how to apply them. I should be using the two enums, GtkSortType & the column numbers for the file list in gtkfilechooserdefault.c, right? Then I could apply them with gtk_tree_view_column_set_sort_column_id() or gtk_tree_view_column_set_sort_order(). How to I cast the enumerations so that they can be passed to these two functions.
Comment 5 Benjamin Gramlich 2007-12-22 03:41:26 UTC
Where is GtkFileChooserDefault defined? I can't seem to find it, and I need to modify it so that i can set impl->sort_column and impl->sort_order.
Comment 6 Federico Mena Quintero 2007-12-22 15:21:26 UTC
(In reply to comment #5)
> Where is GtkFileChooserDefault defined? I can't seem to find it, and I need to
> modify it so that i can set impl->sort_column and impl->sort_order.

It's in gtkfilechooserprivate.h.

(In reply to comment #4)
> I worked on this for a bit last night, but I've become confused. I can save and
> load the settings, but I can't figure out how to apply them. I should be using
> the two enums, GtkSortType & the column numbers for the file list in
> gtkfilechooserdefault.c, right? Then I could apply them with
> gtk_tree_view_column_set_sort_column_id() or
> gtk_tree_view_column_set_sort_order(). How to I cast the enumerations so that
> they can be passed to these two functions.

For set_sort_column_id(), just use the enum we have in gtkfilechooserdefault.c:
/* Column numbers for the file list */
enum {
  FILE_LIST_COL_NAME,
  FILE_LIST_COL_SIZE,
  FILE_LIST_COL_MTIME,
  FILE_LIST_COL_NUM_COLUMNS
};

For set_sort_order(), what do you mean?  I thought you already parsed a GtkSortType from your configuration string?
Comment 7 Benjamin Gramlich 2007-12-22 15:59:40 UTC
I figured out the bits for the column and sort order. I was asking the wrong question. When calling set_sort_column_id do I pass GTK_TREE_MODEL (impl->sort_model) to access the tree view widget inside the dialog?

Thank you for your help.
Comment 8 Benjamin Gramlich 2007-12-29 01:44:39 UTC
Created attachment 101770 [details] [review]
this patch doesn't work, could you take a look at it and help me determine why column_changed_cb doesn't change the settings->sort_order/sort_column or impl->sort_order/sort_column
Comment 9 Benjamin Gramlich 2008-01-02 20:32:35 UTC
Created attachment 102011 [details] [review]
patch to remember sort order

This patch correct saves and loads previous sort settings, but it does not apply them to the file chooser because of this error:

 Gtk-CRITICAL **: gtk_tree_sortable_set_sort_column_id: assertion `GTK_IS_TREE_SORTABLE (sortable)' failed

I try to apply the settings with gtk_tree_sortable_set_sort_column_id (impl->sort_model, sort_column, sort_order), which is the reverse of gtk_tree_sortable_get_sort_column_id which is called in gtkfilechooserdefault::list_sort_column_changed_cb.

Please advise me as to what to do to fix this issue so the patch can be correctly implemented.

Thank you!
Comment 10 Baptiste Mille-Mathias 2008-08-16 21:12:54 UTC
Federico,

could you provide feedback?

thanks
Comment 11 Federico Mena Quintero 2009-03-27 18:34:27 UTC
Note to self: review this patch!
Comment 12 Matthias Clasen 2009-03-28 01:56:23 UTC
Benjamin, the problem is that impl->browse_files_model is not a TreeSortable, 
impl->sort_model is. That is also what list_sort_column_changed_cb is getting called with.
Comment 13 Federico Mena Quintero 2009-06-12 22:58:31 UTC
I fixed this up and committed it in two separate commits:

69a06113915709da57b2676e9e0d23bb34a31bc8 - load/save functions for GtkSettings
1d4cba68762e3ae080f3463a74df42b39a9b0c2e - load/save the columns in GtkFileChooserDefault

Thanks for working on this, Benjamin :)