GNOME Bugzilla – Bug 766122
Re-used filechooser displays $pwd half of the time when shown
Last modified: 2016-05-26 11:45:34 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
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?
Created attachment 327516 [details] [review] GtkFileChooser: don't override already opened folder This seems to be working for me.
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
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
Created attachment 328554 [details] [review] GtkFileChooser: don't override already opened folder v3: * Rebased on top of current master
Attachment 328554 [details] pushed as fcd3321 - GtkFileChooser: don't override already opened folder