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 766122 - Re-used filechooser displays $pwd half of the time when shown
Re-used filechooser displays $pwd half of the time when shown
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkFileChooser
3.21.x
Other Windows
: Normal normal
: ---
Assigned To: gtk-bugs
Federico Mena Quintero
Depends on:
Blocks:
 
 
Reported: 2016-05-07 23:41 UTC by LRN
Modified: 2016-05-26 11:45 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Testcase (1.93 KB, text/plain)
2016-05-07 23:41 UTC, LRN
  Details
GtkFileChooser: don't override already opened folder (1.33 KB, patch)
2016-05-09 12:52 UTC, LRN
none Details | Review
GtkFileChooser: don't override already opened folder (1.35 KB, patch)
2016-05-26 11:43 UTC, LRN
none Details | Review
GtkFileChooser: don't override already opened folder (1.35 KB, patch)
2016-05-26 11:45 UTC, LRN
committed Details | Review

Description LRN 2016-05-07 23:41:12 UTC
Created attachment 327460 [details]
Testcase

How to reproduce:
* Compile and run the attached testcase, which does the following:
  * create a window with a "save" button
  * create a dialog
  * every time the "save" button is clicked:
    * set filename to Documents/Untitled.file
    * run dialog
    * hide dialog

Expected result:
* Every time the "save" button is clicked, the filechooser dialog being shown should have the Documents directory opened

Actual result:
* Half of the time filechooser dialog opens $pwd instead
Comment 1 LRN 2016-05-09 12:21:24 UTC
When gtk_file_chooser_widget_select_file() is first called, same_path is evaluated to FALSE, so it skips the
> if (same_path && priv->load_state == LOAD_FINISHED)
branch and goes down into pending_select_files_add() and gtk_file_chooser_set_current_folder_file()

When gtk_file_chooser_widget_select_file() called the second time, save_path evaluates to TRUE (because testcase, as well as the real-life app it was distilled from, sets the same path practically every time), and it goes down into show_and_select_files() immediately, then bails out.

However, show_and_select_file() does nothing when the file it is told to show does not exist. Because of that
> priv->reload_state = RELOAD_HAS_FOLDER
does not happen, and later on filechooser is allowed to pick a folder of its own choosing.

And if the file exists, show_and_select_file() still only selects it in the currently-displayed directory, but does not do
> priv->reload_state = RELOAD_HAS_FOLDER
, thus also allowing filchooser to pick a different folder later on, which it does.

A tentative fix is to ensure that 
> priv->reload_state = RELOAD_HAS_FOLDER
happens when the directory is already selected, i guess?
Comment 2 LRN 2016-05-09 12:52:20 UTC
Created attachment 327516 [details] [review]
GtkFileChooser: don't override already opened folder

This seems to be working for me.
Comment 3 Matthias Clasen 2016-05-26 11:28:48 UTC
Review of attachment 327516 [details] [review]:

As with all things file chooser; I'm somewhat wary that this might break something else, but on the surface, it looks right to me.

::: gtk/gtkfilechooserwidget.c
@@ +5669,3 @@
 
+      /* Prevent filechooser from showing a different folder */
+      priv->reload_state = RELOAD_HAS_FOLDER;

The comment is slightly misleading; the file chooser can still show different folders.

It should probably say something like:

Prevent the file chooser from loading a different folder when it is mapped
Comment 4 LRN 2016-05-26 11:43:34 UTC
Created attachment 328551 [details] [review]
GtkFileChooser: don't override already opened folder

v2:
* Changed the comment as requested
* Fixed a typo in the commit message
Comment 5 LRN 2016-05-26 11:45:01 UTC
Created attachment 328554 [details] [review]
GtkFileChooser: don't override already opened folder

v3:
* Rebased on top of current master
Comment 6 LRN 2016-05-26 11:45:30 UTC
Attachment 328554 [details] pushed as fcd3321 - GtkFileChooser: don't override already opened folder