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 691040 - selection is reported incorrectly in file chooser button
selection is reported incorrectly in file chooser button
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkFileChooser
2.24.x
Other All
: Normal blocker
: ---
Assigned To: Federico Mena Quintero
Federico Mena Quintero
: 327243 355623 499653 531002 555351 574514 683395 684128 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2013-01-02 23:17 UTC by Paul Davis
Modified: 2017-08-28 04:50 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
test case to document incorrect behaviour (2.09 KB, text/x-csrc)
2013-01-02 23:17 UTC, Paul Davis
  Details
new example code to show new regression with this bug (2.09 KB, text/x-csrc)
2013-01-28 21:23 UTC, Paul Davis
  Details
updated test case (2.17 KB, text/plain)
2013-02-01 14:47 UTC, Paul Davis
  Details
proposed fix (1.83 KB, patch)
2013-03-06 15:01 UTC, Paul Davis
none Details | Review

Description Paul Davis 2013-01-02 23:17:10 UTC
Created attachment 232596 [details]
test case to document incorrect behaviour

From #674556

---------------
 Federico Mena Quintero [gtk+ developer] 2012-04-23 20:42:27 UTC

 Fixed in commit 85c9b5c76.
---------------

Fairly sure that this commit broke/changed the behaviour of the file chooser
button.

Small test program attached. Run program. Press "Click Me" to bring up a dialog
with an FCB. Click the FCB, select "Other". Click on a folder in the left hand
list, then click Open. The program will print to stdout indicating that the
current folder has been changed. Then click "OK" in the dialog with the FCB.

GTK+ 2.24.10: after the dialog has run, the current folder is the same as the
one selected.

Git 2-24: after the dialog has run, the current folder is the last one set by
the program.
Comment 1 Peter Hjalmarsson 2013-01-05 12:33:25 UTC
Got bitten by this, took a quick look at it and it is the
impl->reload_state = RELOAD_EMPTY;
that breaks stuff.
Commenting that out and fc returns the right path.
Comment 2 Peter Hjalmarsson 2013-01-05 12:46:05 UTC
(In reply to comment #1)
Realized that maybe I should be a bit more verbose.
So I post a diff.
Doing this, seems to work very fine (if we even need the reload, since if the parent is getting unmapped, then what is it that needs to reload?).


diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index cf8f1d9..fee96cf 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -5718,7 +5718,7 @@ toplevel_unmap_cb (GtkWidget *widget,
   settings_save (impl);
 
   cancel_all_operations (impl);
-  impl->reload_state = RELOAD_EMPTY;
+  impl->reload_state = RELOAD_HAS_FOLDER;
 }
 
 /* We monitor the focus widget on our toplevel to be able to know which widget
Comment 3 Peter Hjalmarsson 2013-01-05 12:54:48 UTC
Hehe, ok. Bad of me, changing code without knowing what I am doing. It seems currently that the same codepath is used wether you press OK or Cancel (i.e. if the change I just proposed is used, then "Cancel" still chooses the directory you browsed to).
Comment 4 Federico Mena Quintero 2013-01-25 00:06:23 UTC
My bad!  The root cause was that _gtk_file_chooser_settings_get_last_folder_uri() was not ensuring that the settings were actually read with ensure_settings_read().

However, it turns out that we don't use the last_folder_uri for anything meaningful anymore.  That it was being used to "get the current directory when the file chooser is unmapped" is an artifact of how that code used to work.

I removed all that code, and made the file chooser fall back to ->current_folder again.  This fixes the selection in SELECT_FOLDER mode for GtkFileChooserButton.

This is fixed in gtk-2-24 in commit cfb09e5.  Apologies for the regression.
Comment 5 Paul Davis 2013-01-25 13:30:19 UTC
confirmed fixed.
Comment 6 Paul Davis 2013-01-28 21:21:47 UTC
Unfortunately this has introduced a new regression. I've attached a new example, which simply has one extra line added to set the current folder for the FC button. the effect of this call is precisely ... zero, whereas it used to work.
Comment 7 Paul Davis 2013-01-28 21:23:46 UTC
Created attachment 234660 [details]
new example code to show new regression with this bug

differs from previous example by addition of:

   gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(button), "/home/paul");
Comment 8 Federico Mena Quintero 2013-01-30 23:25:41 UTC
*** Bug 684128 has been marked as a duplicate of this bug. ***
Comment 9 Federico Mena Quintero 2013-02-01 12:10:09 UTC
Umm, the new example code doesn't set the current folder.  Where should it set it?
Comment 10 Paul Davis 2013-02-01 14:47:40 UTC
Created attachment 234987 [details]
updated test case

damn, sorry i uploaded a version with the line edit. here is the correct version.
Comment 11 Federico Mena Quintero 2013-02-05 21:46:23 UTC
!#@$%.  I see what you mean.  And now selection is broken when Cancel is used in the GtkFileChooserButton's internal dialog.

Let me double-check GtkFileChooserButton's code.  This breaks frequently, so clearly it is thinking in different terms than the underlying dialog :(
Comment 12 Matthias Clasen 2013-02-09 20:40:36 UTC
Federico, I need to do a 2.24.15 release for 3.7.5 - do you have a fix for this ?
Comment 13 Paul Davis 2013-02-11 14:50:52 UTC
federico: why not just back out a0280d7f and 85c9b5c76 ? the first one doesn't address any actual bug in gtk2 and the second is just a band aid to try to deal with the problems the first one created ...
Comment 14 Federico Mena Quintero 2013-02-13 21:36:46 UTC
I've just pushed a slew of changes to GtkFileChooserButton in gtk-2-24.  This bug should be fixed as of commit 81df0059.  Paul, can you please confirm this?

I've resurrected the automated tests in gtk+/gtk/tests/filechooser.c - this is what let me add a test for your bug.
Comment 15 Paul Davis 2013-02-14 16:10:29 UTC
The test case now passes, and the functionality appears to be back in my application. The original issue (the browser window size being lost) is still fixed. I think we can consider this fixed.
Comment 16 Federico Mena Quintero 2013-02-14 17:20:36 UTC
Perfect, thanks for confirming.  Hopefully with the tests in place the button should not break so often :)
Comment 17 Paul Davis 2013-03-05 04:16:18 UTC
contrary to my earlier testing, more extensive tests reveal that the file chooser and/or filechooser button is still severely broken to the point of unusability.

the earlier tests failed to notice this because the test program was linked against "new" GTK, but run time execution used an existing (older) GTK install.

testing against current git head reveals that the filechooser button fails to display its initial "set_current_folder()" value AND fails to respond to user interaction that changes it.

more to follow.
Comment 18 Paul Davis 2013-03-05 04:49:40 UTC
to demo the issue(s):

build GTK from gtk-2-24

build the (updated) test case below AND ensure that at run time it will use the build of GTK just created

click the button marked "Click me"

note that in the window that appears, the file chooser button displays no path at all. 

click the file chooser button to get the "menu"

from the menu, select a folder

watch the callbacks report that the current folder is now the one originally set (regardless of the fact that it was not displayed), and watch the selection be displayed (finally! but wait ... its not displaying what will be returned by get_current_folder())

repeat. 

tear hair from scalp.
Comment 19 Paul Davis 2013-03-05 20:13:30 UTC
<rgareus> las: set a breakpoint at   gtk_file_chooser_set_current_folder_file
<rgareus> las: this function is called from the combo_box_changed_cb() in gtkfilechooserbutton.c
<rgareus> las: it should eventually end up in     iface->set_current_folder = gtk_file_chooser_button_set_current_folder;
<rgareus> las: but it does not. gtk_file_chooser_set_current_folder_file() calls itself with a couple of times with different GTK_FILE_CHOOSER_GET_IFACE()
<rgareus> las: and eventually ends up in gtk_file_chooser_default_update_current_folder()
<rgareus> las: querying the button's current folder however, uses the correct interface:  gtk_file_chooser_button_get_current_folder()
<rgareus> las: but that remains unchanged beause gtk_file_chooser_button_set_current_folder() is never called :(
Comment 20 Paul Davis 2013-03-06 15:01:07 UTC
Created attachment 238204 [details] [review]
proposed fix 

this is a proposed fix for the issues seen so far.

it incorporates federico's suggestion on IRC regarding what happens in combo_box_changed_cb(), and then additionally ensures that we (1) update the combo box when set_current_folder() is called AND the dialog is inactive (2) get the current file from the right place if the dialog is inactive.
Comment 21 Federico Mena Quintero 2013-03-08 00:40:52 UTC
(In reply to comment #20)
> this is a proposed fix for the issues seen so far.
> 
> it incorporates federico's suggestion on IRC regarding what happens in
> combo_box_changed_cb(), and then additionally ensures that we (1) update the
> combo box when set_current_folder() is called AND the dialog is inactive (2)
> get the current file from the right place if the dialog is inactive.

Than you!  Your fix is necessary but not sufficient.  I'm taking care of all the related stuff I can find, and have a unit test for this.

Right now I'm doing a git-bisect for something that broke the tests, but it is with respect to widget sizing (!).  Expect news tomorrow.
Comment 22 Federico Mena Quintero 2013-03-13 15:14:11 UTC
I've pushed all this to gtk-2-24 and master.  Again, thanks for all the testing you've done.
Comment 23 Sudhir Khanger 2013-05-06 02:25:46 UTC
I am using gtk-2-24-17 on Arch Linux and I still have blank file chooser button in Banshee.

https://www.archlinux.org/packages/extra/x86_64/gtk2/
Comment 24 Federico Mena Quintero 2013-05-07 19:54:32 UTC
I'm afraid you'll have to wait until 2.24.18; these fixes appeared after 2.24.17 :)
Comment 25 piruthiviraj natarajan 2013-05-17 09:46:22 UTC
It seems to be fixed in Fedora rawhide now with 2.24.18.
Comment 26 Federico Mena Quintero 2013-09-23 19:35:34 UTC
*** Bug 683395 has been marked as a duplicate of this bug. ***
Comment 27 Federico Mena Quintero 2013-09-23 20:48:04 UTC
*** Bug 531002 has been marked as a duplicate of this bug. ***
Comment 28 Federico Mena Quintero 2013-09-23 20:48:32 UTC
*** Bug 574514 has been marked as a duplicate of this bug. ***
Comment 29 Federico Mena Quintero 2013-09-23 20:53:31 UTC
*** Bug 555351 has been marked as a duplicate of this bug. ***
Comment 30 Federico Mena Quintero 2013-09-23 20:54:16 UTC
*** Bug 499653 has been marked as a duplicate of this bug. ***
Comment 31 Federico Mena Quintero 2013-09-23 20:55:04 UTC
*** Bug 355623 has been marked as a duplicate of this bug. ***
Comment 32 Federico Mena Quintero 2013-09-23 20:56:37 UTC
*** Bug 327243 has been marked as a duplicate of this bug. ***