Red Hat Bugzilla – Bug 473143
zenity --file-selection doesn't handle --filename= option correctly when not using --save
Last modified: 2009-01-16 14:57:27 EST
Created attachment 324780 [details]
patch to fix default file selection in zenity when not using --save
Description of problem:
There is a long-standing problem (at least since Fedora Core 3) in zenity's file selection dialog, when used for opening rather than saving files. If given a file name via the --filename= option, zenity will not select that file name, but instead triggers a failed assertion. There is nothing in zenity's documentation to suggest --filename should only be used with the --save option, and it's reasonable to expect that you should be able to provide a default or current filename for an open dialog, so I'd call this a bug.
Version-Release number of selected component (if applicable):
2.24.0-2.fc10 (all the way back to gnome-utils-2.8.0-5)
Steps to Reproduce:
1. zenity --file-selection --filename=.bashrc
(zenity:18562): Gtk-CRITICAL **: gtk_file_chooser_default_set_current_name: assertion `impl->action == GTK_FILE_CHOOSER_ACTION_SAVE || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER' failed
Dialog box should select the named file without complaining.
The fix is actually quite trivial (at least for the case of a single default file name), as the attached patch shows. The GTK documentation for gtk_file_chooser_set_current_name() says: This function is meant for such uses as a suggested name in a "Save As..." dialog. If you want to preselect a particular existing file, you should use gtk_file_chooser_set_filename() instead. So, that's what I did. Note that if you wanted to allow multiple default filenames to be specified, when using the --multiple option, the single call to gtk_file_chooser_set_filename() would need to be replaced with a loop that separates out all the given file names and calls gtk_file_chooser_select_filename() on each one (note "select" rather than "set", as the set call first unselects everything).
Thanks for the patch.
Filed upstream here:
Committed upstream, will show up in rawhide shortly.