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 581873 - gtk_file_chooser_set_filter does nothing / file chooser has no filter selected
gtk_file_chooser_set_filter does nothing / file chooser has no filter selected
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkFileChooser
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Stefan Sauer (gstreamer, gtkdoc dev)
Federico Mena Quintero
Depends on:
Blocks:
 
 
Reported: 2009-05-08 14:15 UTC by Stefan Sauer (gstreamer, gtkdoc dev)
Modified: 2009-10-20 21:12 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
flip the if condition to not wrongly reset the filter (463 bytes, patch)
2009-10-15 20:44 UTC, Stefan Sauer (gstreamer, gtkdoc dev)
none Details | Review
same patch with the printfs to easy verification (1.23 KB, patch)
2009-10-15 20:45 UTC, Stefan Sauer (gstreamer, gtkdoc dev)
none Details | Review

Description Stefan Sauer (gstreamer, gtkdoc dev) 2009-05-08 14:15:36 UTC
$ pkg-config --modversion glib-2.0
2.18.2
$ pkg-config --modversion gtk+-2.0
2.14.4

its Ubuntu 8.10, same issue on opensuse 11.1.

I add a couple of filters to my filechooser using
gtk_file_chooser_add_filter()

if(!file_name) {
  GST_DEBUG("use defaults %s/%s",folder_name,name);
  /* the user just created a new document */
  gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(dialog), folder_name);
  gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER(dialog), name);
}
else {
  /* the user edited an existing document */
  gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog),file_name);
}

in the first case (!file_name) the filechooser shows the first filter in the filter list.

in the second case the filter list shows no entry. but if I click on it I see all filters. I then added some code that uses gtk_file_chooser_set_filter() to preselect the filter that matches the current format. But the gtk_file_chooser_set_filter() has no visual effect.

For the record I tried two ways to select the current filter: gtk_file_filter_filter() and just matching the extensions myself. gtk_file_filter_filter() unfortunately never matches. The extension comparission works though.
Comment 1 Stefan Sauer (gstreamer, gtkdoc dev) 2009-05-08 14:25:37 UTC
With gtk from git HEAD. The file_filter seems to work, but still gtk_file_chooser_set_filter() has no visual effect.

One more detail, the application is installed under an own prefix. I have set XDG_DATA_DIRS to contain $prefix/share - i wonder if that is enough to ensure glib finds the mime-info I have installed there.
Comment 2 Stefan Sauer (gstreamer, gtkdoc dev) 2009-05-09 21:27:08 UTC
gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog),filter);
is doing a g_object_set(chooser, "filter", filter, NULL);
and in gtkfilechooserdefault.c this is calling set_current_filter();

I set a break point on set_current_filter() but its never stopping there. Will add printfs next :/ Breakpoint on gtk_file_chooser_set_filter() works.
Comment 3 Stefan Sauer (gstreamer, gtkdoc dev) 2009-10-15 20:38:57 UTC
I looked into it again. I added two printfs in gtk+/gtk/gtkfilechooserdefault.c:
* at the begin of set_current_filter()
* at show_and_select_files_finished_loading() before is calls set_current_filter (data->impl, NULL);

And this is what happens. I create my file chooser, as we have an existing file (save-as) I do gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog),file_name);. Then I match the file-type and set the filter to show only those files
gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog),filter);
Finally bring the dialog up:
  puts("ui ready");
  gtk_widget_show_all(dialog);
  puts("ui shown");
  result=gtk_dialog_run(GTK_DIALOG(dialog));

Below is the log and it confirms that gtk+ for some reason resets my filter. As usual for gtk+ that code there is almost uncommented and that keep me wondering what the intention here. Another printf shows that it checks the file I have set as a filename. So if that is a hidden file if will show hidden files. And if my selected filter matches it resets the fiter. I'd say that logic is flawed. Imho the filter should be reset if all the filter is not matching one or many of the selected filenames. And indeed that makes it work. I'll attach a patch.

-- log --

use last path /home/ensonic/buzztard/share/buzztard/songs/kick.xml, format is 'buzztard song without externals', filter 0x8719dc0

changing file filter to: 0x8719dc0, buzztard song without externals
changing file filter to: 0x8719dc0, buzztard song without externals

ui ready
ui shown

resetting the filter
changing file filter to: (nil), (NULL)
changing file filter to: (nil), (NULL)
Comment 4 Stefan Sauer (gstreamer, gtkdoc dev) 2009-10-15 20:44:33 UTC
Created attachment 145546 [details] [review]
flip the if condition to not wrongly reset the filter

Please review. If the fix is okay, please let me know if I should apply to to some branch as well.
Comment 5 Stefan Sauer (gstreamer, gtkdoc dev) 2009-10-15 20:45:14 UTC
Created attachment 145547 [details] [review]
same patch with the printfs to easy verification
Comment 6 Federico Mena Quintero 2009-10-19 18:56:36 UTC
Thanks for tracking this down, Stefan.

Could you please check the show_and_select_files() function in the "filesystemmodel" branch?  The code is a bit different there, but it should follow the same logic that you describe.  We are going to merge that branch soon; feel free to commit your fix to it and it will go into the merged version later.
Comment 7 Stefan Sauer (gstreamer, gtkdoc dev) 2009-10-20 10:04:28 UTC
Hmm, with the code in git HEAD its already fixed. 

In the code here, my patch would still help.
http://git.gnome.org/cgit/gtk+/tree/gtk/gtkfilechooserdefault.c?h=gtk-2-18#n6670

I now just tested under ubunto jaunty and they might have a local patch. Its gtk+-2.16.1 and I did not get the full problem there. Will retest at home under opensuse 11.1 later today.
Comment 8 Stefan Sauer (gstreamer, gtkdoc dev) 2009-10-20 19:51:51 UTC
2.16.4 still has it. Something in the 2.17.X series fixed it.
Comment 9 Stefan Sauer (gstreamer, gtkdoc dev) 2009-10-20 21:12:43 UTC
I guess there is no point in applying anything to 2.16.X as 2.18.X is stable anyway.