Save the expanded state of the folder browser with the file chooser

* gtk/gtkfilechooserdefault.c:
* gtk/gtkfilechooserprivate.h:
* gtk/gtkfilechoosersettings.c:
* gtk/gtkfilechoosersettings.h:
Save the expanded state of the folder browser with the file
chooser settings.  Resolves the expander portions of (#153828,
Lemmit Kaplinski)

svn path=/trunk/; revision=17121
This commit is contained in:
Peter Teichman 2007-01-08 18:34:06 +00:00
parent 5169423a9b
commit 0177b21959
5 changed files with 83 additions and 2 deletions

View File

@ -1,3 +1,13 @@
2006-01-08 Peter Teichman <peter@novell.com>
* gtk/gtkfilechooserdefault.c:
* gtk/gtkfilechooserprivate.h:
* gtk/gtkfilechoosersettings.c:
* gtk/gtkfilechoosersettings.h:
Save the expanded state of the folder browser with the file
chooser settings. Resolves the expander portions of (#153828,
Lemmit Kaplinski)
2007-01-08 Emmanuele Bassi <ebassi@gnome.org>
* gtk/gtkrecentchoosermenu.c (gtk_recent_chooser_menu_create_item):

View File

@ -4232,6 +4232,7 @@ expander_changed_cb (GtkExpander *expander,
GParamSpec *pspec,
GtkFileChooserDefault *impl)
{
impl->expand_folders = gtk_expander_get_expanded(GTK_EXPANDER (impl->save_expander));
update_appearance (impl);
}
@ -5428,16 +5429,21 @@ settings_load (GtkFileChooserDefault *impl)
GtkFileChooserSettings *settings;
LocationMode location_mode;
gboolean show_hidden;
gboolean expand_folders;
settings = _gtk_file_chooser_settings_new ();
location_mode = _gtk_file_chooser_settings_get_location_mode (settings);
show_hidden = _gtk_file_chooser_settings_get_show_hidden (settings);
expand_folders = _gtk_file_chooser_settings_get_expand_folders (settings);
g_object_unref (settings);
location_mode_set (impl, location_mode, TRUE);
gtk_file_chooser_set_show_hidden (GTK_FILE_CHOOSER (impl), show_hidden);
impl->expand_folders = expand_folders;
if (impl->save_expander)
gtk_expander_set_expanded (GTK_EXPANDER (impl->save_expander), expand_folders);
}
static void
@ -5449,6 +5455,7 @@ settings_save (GtkFileChooserDefault *impl)
_gtk_file_chooser_settings_set_location_mode (settings, impl->location_mode);
_gtk_file_chooser_settings_set_show_hidden (settings, gtk_file_chooser_get_show_hidden (GTK_FILE_CHOOSER (impl)));
_gtk_file_chooser_settings_set_expand_folders (settings, impl->expand_folders);
/* NULL GError */
_gtk_file_chooser_settings_save (settings, NULL);

View File

@ -265,6 +265,7 @@ struct _GtkFileChooserDefault
guint list_sort_ascending : 1;
guint changing_folder : 1;
guint shortcuts_current_folder_active : 1;
guint expand_folders : 1;
#if 0
guint shortcuts_drag_outside : 1;

View File

@ -42,6 +42,7 @@
#define ELEMENT_TOPLEVEL "gtkfilechooser"
#define ELEMENT_LOCATION "location"
#define ELEMENT_SHOW_HIDDEN "show_hidden"
#define ELEMENT_EXPAND_FOLDERS "expand_folders"
#define ATTRIBUTE_VERSION "version"
#define ATTRIBUTE_MODE "mode"
#define ATTRIBUTE_VALUE "value"
@ -69,6 +70,7 @@ set_defaults (GtkFileChooserSettings *settings)
{
settings->location_mode = LOCATION_MODE_PATH_BAR;
settings->show_hidden = FALSE;
settings->expand_folders = FALSE;
}
typedef enum {
@ -77,7 +79,8 @@ typedef enum {
STATE_ERROR,
STATE_IN_TOPLEVEL,
STATE_IN_LOCATION,
STATE_IN_SHOW_HIDDEN
STATE_IN_SHOW_HIDDEN,
STATE_IN_EXPAND_FOLDERS
} State;
struct parse_state {
@ -271,6 +274,34 @@ parse_start_element_cb (GMarkupParseContext *context,
value_str);
}
}
else if (EQ (element_name, ELEMENT_EXPAND_FOLDERS))
{
const char *value_str;
state->state = STATE_IN_EXPAND_FOLDERS;
value_str = get_attribute_value (attribute_names, attribute_values, ATTRIBUTE_VALUE);
if (!value_str)
set_missing_attribute_error (state, line, col, ATTRIBUTE_VALUE, error);
else if (EQ (value_str, VALUE_TRUE))
state->settings->expand_folders = TRUE;
else if (EQ (value_str, VALUE_FALSE))
state->settings->expand_folders = FALSE;
else
{
state->state = STATE_ERROR;
g_set_error (error,
G_MARKUP_ERROR,
G_MARKUP_ERROR_INVALID_CONTENT,
_("Line %d, column %d: expected \"%s\" or \"%s\", but found \"%s\" instead"),
line,
col,
VALUE_FALSE,
VALUE_TRUE,
value_str);
}
}
else
set_unexpected_element_error (state, line, col, element_name, error);
@ -336,6 +367,14 @@ parse_end_element_cb (GMarkupParseContext *context,
break;
case STATE_IN_EXPAND_FOLDERS:
if (EQ (element_name, ELEMENT_EXPAND_FOLDERS))
state->state = STATE_IN_TOPLEVEL;
else
set_unexpected_element_end_error (state, line, col, ELEMENT_EXPAND_FOLDERS, element_name, error);
break;
default:
g_assert_not_reached ();
}
@ -454,11 +493,26 @@ _gtk_file_chooser_settings_set_show_hidden (GtkFileChooserSettings *settings,
settings->show_hidden = show_hidden ? TRUE : FALSE;
}
gboolean
_gtk_file_chooser_settings_get_expand_folders (GtkFileChooserSettings *settings)
{
ensure_settings_read (settings);
return settings->expand_folders;
}
void
_gtk_file_chooser_settings_set_expand_folders (GtkFileChooserSettings *settings,
gboolean expand_folders)
{
settings->expand_folders = expand_folders ? TRUE : FALSE;
}
static char *
settings_to_markup (GtkFileChooserSettings *settings)
{
const char *location_mode_str;
const char *show_hidden_str;
const char *expand_folders_str;
if (settings->location_mode == LOCATION_MODE_PATH_BAR)
location_mode_str = MODE_PATH_BAR;
@ -471,14 +525,17 @@ settings_to_markup (GtkFileChooserSettings *settings)
}
show_hidden_str = settings->show_hidden ? VALUE_TRUE : VALUE_FALSE;
expand_folders_str = settings->expand_folders ? VALUE_TRUE : VALUE_FALSE;
return g_strdup_printf
("<" ELEMENT_TOPLEVEL ">\n" /* <gtkfilechooser> */
" <" ELEMENT_LOCATION " " ATTRIBUTE_MODE "=\"%s\"/>\n" /* <location mode="path-bar"/> */
" <" ELEMENT_SHOW_HIDDEN " " ATTRIBUTE_VALUE "=\"%s\"/>\n" /* <show_hidden value="false"/> */
" <" ELEMENT_EXPAND_FOLDERS " " ATTRIBUTE_VALUE "=\"%s\"/>\n" /* <expand_folders value="false"/> */
"</" ELEMENT_TOPLEVEL ">\n", /* </gtkfilechooser> */
location_mode_str,
show_hidden_str);
show_hidden_str,
expand_folders_str);
}
gboolean

View File

@ -42,6 +42,8 @@ struct _GtkFileChooserSettings
guint settings_read : 1;
guint show_hidden : 1;
guint expand_folders : 1;
};
struct _GtkFileChooserSettingsClass
@ -61,6 +63,10 @@ gboolean _gtk_file_chooser_settings_get_show_hidden (GtkFileChooserSettings *set
void _gtk_file_chooser_settings_set_show_hidden (GtkFileChooserSettings *settings,
gboolean show_hidden);
gboolean _gtk_file_chooser_settings_get_expand_folders (GtkFileChooserSettings *settings);
void _gtk_file_chooser_settings_set_expand_folders (GtkFileChooserSettings *settings,
gboolean expand_folders);
gboolean _gtk_file_chooser_settings_save (GtkFileChooserSettings *settings,
GError **error);