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 563010 - GtkFileChooserButton cannot have none file selected again
GtkFileChooserButton cannot have none file selected again
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkFileChooser
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Federico Mena Quintero
Federico Mena Quintero
Depends on:
Blocks: 332496
 
 
Reported: 2008-12-02 18:22 UTC by Milan Crha
Modified: 2009-10-21 17:48 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
proposed gtk patch (2.15 KB, patch)
2008-12-03 14:25 UTC, Milan Crha
none Details | Review
chooser-button-unselect-all.py (422 bytes, text/plain)
2009-02-26 18:16 UTC, Federico Mena Quintero
  Details
sel.c - test program (1.36 KB, text/plain)
2009-06-18 01:12 UTC, Federico Mena Quintero
  Details
gtk+-bgo563010-filechooser-button-unselect-all.diff (1.81 KB, patch)
2009-10-19 17:50 UTC, Federico Mena Quintero
none Details | Review
proposed gtk patch ][ (1.52 KB, patch)
2009-10-20 14:20 UTC, Milan Crha
accepted-commit_now Details | Review

Description Milan Crha 2008-12-02 18:22:04 UTC
While looking on the bug #332496 I realized I cannot any way to persuade GtkFileChooserButton to unselect everything and show "(None)" after had been file selected. I tried so many things, but no luck, it always picks the last selected file. Please have some possibility to unset file/dir from the file chooser button.
Comment 1 Milan Crha 2008-12-03 14:25:55 UTC
Created attachment 123872 [details] [review]
proposed gtk patch

for gtk+;

New API to be able to do this.
Comment 2 André Klapper 2009-02-23 14:25:40 UTC
ping - can this get a review?
Comment 3 Federico Mena Quintero 2009-02-26 18:16:46 UTC
Created attachment 129589 [details]
chooser-button-unselect-all.py

I don't think we need a new API; gtk_file_chooser_unselect_all (button) is all you need.  It seems to work fine for me in the attached program.
Comment 4 Federico Mena Quintero 2009-02-26 18:17:27 UTC
Or is ::unselect_all() not working for you?  We may need to make the docs more clear on this; a patch would be lovely :)
Comment 5 Federico Mena Quintero 2009-02-26 18:30:06 UTC
If you find that this doesn't work for you, we could totally use a test in gtk+/gtk/tests/filechooser.c --- that's the automatic tests for the file chooser.
Comment 6 Milan Crha 2009-02-27 10:05:42 UTC
Maybe I do something wrong, but it doesn't work for me when I use patch from bug #332496 and change new function to gtk_file_chooser_unselect_all. The file name is still there, even when I hit "no image" in the dialog. Any idea?
Comment 7 Federico Mena Quintero 2009-02-27 19:20:10 UTC
Ah, okay, with that it makes more sense.  From a quick reading of the code, I think you should just use gtk_file_chooser_unselect_all() from your "response" callback in Evolution, but make the callback stop the emission of the signal.

Otherwise, GtkFileChooserButton's own handler for "response" will also run after your own handler (see gtkfilechooserbutton.c:dialog_response_cb()), and this will reset the button to showing its old_file --- it has something like

   if (response == ACCEPT || response == OK)
       /* emit selection_changed */
   else if (priv->old_file)
       /* reset the button to showing old_file */
   else
       ...

Can you try your Evo patch with something like

static void
file_chooser_response (GtkDialog *dialog, gint response_id, struct chooser_button_struct *data)
{
	g_return_if_fail (data != NULL);
	g_return_if_fail (data->button != NULL);

	if (response_id == GTK_RESPONSE_NO) {
		gtk_file_chooser_button_select_none (data->button);
+               g_signal_stop_emission_by_name (dialog, "response");
	}
}
Comment 8 Milan Crha 2009-03-02 12:51:47 UTC
that will not close the dialog.
Comment 9 Federico Mena Quintero 2009-03-02 18:47:47 UTC
Hmm --- gtkfilechooserbutton.c:dialog_response_cb() hides the dialog and makes the combo box sensitive again.  Your "response" handler would need to do the same, but it has no way to access the combo box.

What if you use connect_after for your original "response" callback instead?  It will then run after the GtkFileChooserButton's.  You will need to call gtk_file_chooser_unselect_all() from your callback to make the button clear itself.  Something like

  g_signal_connect_after (dialog, "response", response_cb, blahblah);

  static void
  response_cb (GtkDialog *dialog, int response_id, gpointer data)
  {
     if (response_id == GTK_RESPONSE_NO)
        gtk_file_chooser_unselect_all (chooser_button);
  }
Comment 10 Milan Crha 2009-03-03 09:22:02 UTC
I'm sorry, I should mention, but then forgot: I tried and it didn't work too.
Comment 11 Milan Crha 2009-06-17 13:11:09 UTC
Federico, so, what's the final word on this, please? It takes too long for such a little, but useful, thing, from my point of view.
Comment 12 Federico Mena Quintero 2009-06-17 16:57:44 UTC
You never said why that didn't work.  Did you trace this in gdb?

I don't have time to actually try Evolution with your patch.  Or can you build a small, self-contained test case which I can try easily?

I'm pretty convinced that we don't need an extra API in GtkFileChooserButton.  If just calling gtk_file_chooser_unselect_all() doesn't work, it's just a bug somewhere.
Comment 13 Milan Crha 2009-06-17 17:23:00 UTC
(In reply to comment #12)
> You never said why that didn't work.  Did you trace this in gdb?
> 
> I don't have time to actually try Evolution with your patch.  Or can you build
> a small, self-contained test case which I can try easily?
> 
> I'm pretty convinced that we don't need an extra API in GtkFileChooserButton. 
> If just calling gtk_file_chooser_unselect_all() doesn't work, it's just a bug
> somewhere.
> 

heh, knowing why that didn't work I might fix the existing function(s), but as this is pretty long time ago I really do not remember what was the reason to add new API instead of fixing the old. I can try to reinvestigate. I just hoped that someone knowing the gtk+ better than me might have it fixed much much quicker.
Comment 14 Federico Mena Quintero 2009-06-18 01:12:50 UTC
Created attachment 136884 [details]
sel.c - test program

OK, this is a bit more complicated than I thought.  There *is* a bug in GtkFileChooserButton.

This test program replicates what your patch for Evolution wants to do.

First I tried a normal signal_connect to "response".  In the callback I would call gtk_file_chooser_select_none (button), hide the dialog, and stop the emission of the signal.  However, the button would still show the same filename.  This doesn't work because the button's "response" handler also does other stuff, *AND* it has the selection_changed signal blocked while the dialog is active.  So, the button never notices that the selection changed to nothing.

Then I tried to do

  1. create the dialog
  2. create the button
  3. connect to "response" on the dialog

so that our "response" handler would run *after* the button had run its own handler.  This is the version in the attached program.

It does not work because gtkfilechooserbutton.c:update_label_and_image() is not synchronous.  It queues a _gtk_file_system_get_info(), which will update the label *after* our response handler has run (i.e. after the idle loop).  Also, it's not cancelling the cancellable all the time; only if the list of selected files is not empty.

I'll start fixing this.
Comment 15 Milan Crha 2009-06-18 09:43:19 UTC
OK, thanks a lot.
Comment 16 Milan Crha 2009-10-19 15:57:17 UTC
(In reply to comment #14)
> It does not work because gtkfilechooserbutton.c:update_label_and_image() is not
> synchronous.  It queues a _gtk_file_system_get_info(), which will update the
> label *after* our response handler has run (i.e. after the idle loop).  Also,
> it's not cancelling the cancellable all the time; only if the list of selected
> files is not empty.
> 
> I'll start fixing this.

Federico, any update on this, please?
Comment 17 Federico Mena Quintero 2009-10-19 17:50:28 UTC
Created attachment 145798 [details] [review]
gtk+-bgo563010-filechooser-button-unselect-all.diff

Sorry, I never finished fixing this.  This patch is as far as I got.  I don't remember if I actually tested it... maybe you can pick things up from there?
Comment 18 Milan Crha 2009-10-20 14:20:42 UTC
Created attachment 145863 [details] [review]
proposed gtk patch ][

for gtk+;

I extended your patch slightly, to let it work as I expect. It works fine with the above attached sel.c test program. What do you think, Federico?
Comment 19 Federico Mena Quintero 2009-10-20 22:21:48 UTC
Review of attachment 145863 [details] [review]:

Excellent, thanks for debugging this!  I'm surprised that we didn't cancel that pending operation for show_and_select_files!

You'll be happy to know that that code path no longer exists in the "filesystemmodel" branch, which will get merged soon with master.

Can you please push your patch to master?  We'll deal with the merge later.  I hope that the branch will only need the changes to gtkfilechooserbutton.c.
Comment 20 Milan Crha 2009-10-21 08:52:29 UTC
I have commit rights to gnome's git, and as I was told that it's not restricted to some projects only, then I probably can commit to gtk+ too. I was hoping to include this change to a next stable release as well, so we can gain from it a bit. I mean to have it available at least for 2.30, as that's a place where my patch from bug #332496 will be included. What do you think?
Comment 21 Milan Crha 2009-10-21 16:43:17 UTC
Err, I'm wrong. I realized that I used too old gtk+, on the actual master is your patch the right change to do (mine added chunk is irrelevant in the actual master, as the code changed there).

I'm really confused now and I'm not going to commit anything at the moment. When I remove the chunk from gtk_file_chooser_default_unselect_all in the above latest patch then it works as expected.
Comment 22 Federico Mena Quintero 2009-10-21 17:48:23 UTC
OK, I've just pushed the patches to master and gtk-2-18.  I guess you'll be able to use them soon from gtk+-2.18.4.

Thanks for your help in debugging this, Milan :)