GtkFileChooserButton: return correct selection for SELECT_FOLDER mode

The old code to load the last_folder_uri state from the settings was not actually
ensuring that the settings were read from disk.  The result was this:

1. user chooses a folder in SELECT_FOLDER mode
2. user dismisses the file chooser dialog inside a GtkFileChooserButton
3. The dialog unmaps itself and saves the last_folder_uri with the user's selection
4. The file chooser button gets queried for the selection
5. GtkFileChooserDefault sees that it is unmapped, and falls back to the last_folder_uri
6. But since that key is not ensured as read by the temporary instance of GtkFileChooserSettings,
   it returns nothing.
7. The file chooser falls back to returning the user's home directory.

However, *we don't use the last_folder_uri* anymore, for anything!  So, removed
that code and now everything falls back to ->current_folder correctly.  This
is the correct selection value for SELECT_FOLDER mode anyway.

https://bugzilla.gnome.org/show_bug.cgi?id=674556
Signed-off-by: Federico Mena Quintero <federico@gnome.org>
This commit is contained in:
Federico Mena Quintero 2013-01-24 17:57:03 -06:00
parent 0c5877215b
commit cfb09e5654
3 changed files with 0 additions and 73 deletions

View File

@ -5971,22 +5971,9 @@ static void
settings_save (GtkFileChooserDefault *impl)
{
GtkFileChooserSettings *settings;
char *current_folder_uri;
settings = _gtk_file_chooser_settings_new ();
/* Current folder */
if (impl->current_folder)
current_folder_uri = g_file_get_uri (impl->current_folder);
else
current_folder_uri = "";
_gtk_file_chooser_settings_set_last_folder_uri (settings, current_folder_uri);
if (impl->current_folder)
g_free (current_folder_uri);
/* All the other state */
_gtk_file_chooser_settings_set_location_mode (settings, impl->location_mode);
@ -6017,30 +6004,6 @@ gtk_file_chooser_default_realize (GtkWidget *widget)
emit_default_size_changed (impl);
}
static GFile *
get_file_for_last_folder_opened (GtkFileChooserDefault *impl)
{
char *last_folder_uri;
GFile *file;
GtkFileChooserSettings *settings;
settings = _gtk_file_chooser_settings_new ();
last_folder_uri = _gtk_file_chooser_settings_get_last_folder_uri (settings);
g_object_unref (settings);
/* If no last folder is set, we use the user's home directory, since
* this is the starting point for most documents.
*/
if (last_folder_uri == NULL || last_folder_uri[0] == '\0')
file = g_file_new_for_path (g_get_home_dir ());
else
file = g_file_new_for_uri (last_folder_uri);
g_free (last_folder_uri);
return file;
}
/* Changes the current folder to $CWD */
static void
switch_to_cwd (GtkFileChooserDefault *impl)
@ -7334,16 +7297,6 @@ gtk_file_chooser_default_get_current_folder (GtkFileChooser *chooser)
impl->operation_mode == OPERATION_MODE_RECENT)
return NULL;
if (impl->reload_state == RELOAD_EMPTY)
{
/* We are unmapped, or we had an error while loading the last folder.
* We'll return the folder used by the last invocation of the file chooser
* since once we get (re)mapped, we'll load *that* folder anyway unless
* the caller explicitly calls set_current_folder() on us.
*/
return get_file_for_last_folder_opened (impl);
}
if (impl->current_folder)
return g_object_ref (impl->current_folder);

View File

@ -38,7 +38,6 @@
#include "gtkalias.h"
#define SETTINGS_GROUP "Filechooser Settings"
#define LAST_FOLDER_URI_KEY "LastFolderUri"
#define LOCATION_MODE_KEY "LocationMode"
#define SHOW_HIDDEN_KEY "ShowHidden"
#define SHOW_SIZE_COLUMN_KEY "ShowSizeColumn"
@ -143,10 +142,6 @@ ensure_settings_read (GtkFileChooserSettings *settings)
if (!g_key_file_has_group (key_file, SETTINGS_GROUP))
goto out;
/* Last folder URI */
settings->last_folder_uri = g_key_file_get_string (key_file, SETTINGS_GROUP, LAST_FOLDER_URI_KEY, NULL);
/* Location mode */
location_mode_str = g_key_file_get_string (key_file, SETTINGS_GROUP,
@ -260,7 +255,6 @@ _gtk_file_chooser_settings_class_init (GtkFileChooserSettingsClass *class)
static void
_gtk_file_chooser_settings_init (GtkFileChooserSettings *settings)
{
settings->last_folder_uri = NULL;
settings->location_mode = LOCATION_MODE_PATH_BAR;
settings->sort_order = GTK_SORT_ASCENDING;
settings->sort_column = FILE_LIST_COL_NAME;
@ -279,19 +273,6 @@ _gtk_file_chooser_settings_new (void)
return g_object_new (GTK_FILE_CHOOSER_SETTINGS_TYPE, NULL);
}
char *
_gtk_file_chooser_settings_get_last_folder_uri (GtkFileChooserSettings *settings)
{
return g_strdup (settings->last_folder_uri);
}
void
_gtk_file_chooser_settings_set_last_folder_uri (GtkFileChooserSettings *settings, const char *uri)
{
g_free (settings->last_folder_uri);
settings->last_folder_uri = g_strdup (uri);
}
LocationMode
_gtk_file_chooser_settings_get_location_mode (GtkFileChooserSettings *settings)
{
@ -490,8 +471,6 @@ _gtk_file_chooser_settings_save (GtkFileChooserSettings *settings,
/* Initialise with the on-disk keyfile, so we keep unknown options */
g_key_file_load_from_file (key_file, filename, 0, NULL);
g_key_file_set_string (key_file, SETTINGS_GROUP,
LAST_FOLDER_URI_KEY, settings->last_folder_uri);
g_key_file_set_string (key_file, SETTINGS_GROUP,
LOCATION_MODE_KEY, location_mode_str);
g_key_file_set_boolean (key_file, SETTINGS_GROUP,

View File

@ -44,8 +44,6 @@ struct _GtkFileChooserSettings
{
GObject object;
char *last_folder_uri;
LocationMode location_mode;
GtkSortType sort_order;
@ -71,9 +69,6 @@ GType _gtk_file_chooser_settings_get_type (void) G_GNUC_CONST;
GtkFileChooserSettings *_gtk_file_chooser_settings_new (void);
char *_gtk_file_chooser_settings_get_last_folder_uri (GtkFileChooserSettings *settings);
void _gtk_file_chooser_settings_set_last_folder_uri (GtkFileChooserSettings *settings, const char *uri);
LocationMode _gtk_file_chooser_settings_get_location_mode (GtkFileChooserSettings *settings);
void _gtk_file_chooser_settings_set_location_mode (GtkFileChooserSettings *settings,
LocationMode location_mode);