GNOME Bugzilla – Bug 484922
Should remember the sort state of columns
Last modified: 2009-06-12 22:58:31 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
Added the "gnome-love" keyword. I'll be happy to mentor someone who wants to implement this simple feature.
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.
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.
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.
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.
(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?
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.
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
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!
Federico, could you provide feedback? thanks
Note to self: review this patch!
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.
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 :)