mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-05 16:20:10 +00:00
filechooser: Attach GSettings object to GtkSettings
... instead of keeping one per GtkFileChooserDefault. This allows using it in other places, too.
This commit is contained in:
parent
b112a85395
commit
78d91aaf9b
@ -6014,16 +6014,6 @@ set_sort_column (GtkFileChooserDefault *impl)
|
||||
impl->sort_order);
|
||||
}
|
||||
|
||||
static void
|
||||
settings_ensure (GtkFileChooserDefault *impl)
|
||||
{
|
||||
if (impl->settings != NULL)
|
||||
return;
|
||||
|
||||
impl->settings = g_settings_new ("org.gtk.Settings.FileChooser");
|
||||
g_settings_delay (impl->settings);
|
||||
}
|
||||
|
||||
static void
|
||||
settings_load (GtkFileChooserDefault *impl)
|
||||
{
|
||||
@ -6033,15 +6023,16 @@ settings_load (GtkFileChooserDefault *impl)
|
||||
gint sort_column;
|
||||
GtkSortType sort_order;
|
||||
gint sidebar_width;
|
||||
GSettings *settings;
|
||||
|
||||
settings_ensure (impl);
|
||||
settings = _gtk_file_chooser_get_settings_for_widget (GTK_WIDGET (impl));
|
||||
|
||||
location_mode = g_settings_get_enum (impl->settings, SETTINGS_KEY_LOCATION_MODE);
|
||||
show_hidden = g_settings_get_boolean (impl->settings, SETTINGS_KEY_SHOW_HIDDEN);
|
||||
show_size_column = g_settings_get_boolean (impl->settings, SETTINGS_KEY_SHOW_SIZE_COLUMN);
|
||||
sort_column = g_settings_get_enum (impl->settings, SETTINGS_KEY_SORT_COLUMN);
|
||||
sort_order = g_settings_get_enum (impl->settings, SETTINGS_KEY_SORT_ORDER);
|
||||
sidebar_width = g_settings_get_int (impl->settings, SETTINGS_KEY_SIDEBAR_WIDTH);
|
||||
location_mode = g_settings_get_enum (settings, SETTINGS_KEY_LOCATION_MODE);
|
||||
show_hidden = g_settings_get_boolean (settings, SETTINGS_KEY_SHOW_HIDDEN);
|
||||
show_size_column = g_settings_get_boolean (settings, SETTINGS_KEY_SHOW_SIZE_COLUMN);
|
||||
sort_column = g_settings_get_enum (settings, SETTINGS_KEY_SORT_COLUMN);
|
||||
sort_order = g_settings_get_enum (settings, SETTINGS_KEY_SORT_ORDER);
|
||||
sidebar_width = g_settings_get_int (settings, SETTINGS_KEY_SIDEBAR_WIDTH);
|
||||
|
||||
location_mode_set (impl, location_mode, TRUE);
|
||||
|
||||
@ -6065,25 +6056,29 @@ save_dialog_geometry (GtkFileChooserDefault *impl)
|
||||
{
|
||||
GtkWindow *toplevel;
|
||||
int x, y, width, height;
|
||||
GSettings *settings;
|
||||
|
||||
toplevel = get_toplevel (GTK_WIDGET (impl));
|
||||
|
||||
if (!(toplevel && GTK_IS_FILE_CHOOSER_DIALOG (toplevel)))
|
||||
return;
|
||||
|
||||
settings = _gtk_file_chooser_get_settings_for_widget (GTK_WIDGET (toplevel));
|
||||
|
||||
gtk_window_get_position (toplevel, &x, &y);
|
||||
gtk_window_get_size (toplevel, &width, &height);
|
||||
|
||||
g_settings_set (impl->settings, SETTINGS_KEY_WINDOW_POSITION, "(ii)", x, y);
|
||||
g_settings_set (impl->settings, SETTINGS_KEY_WINDOW_SIZE, "(ii)", width, height);
|
||||
g_settings_set (settings, SETTINGS_KEY_WINDOW_POSITION, "(ii)", x, y);
|
||||
g_settings_set (settings, SETTINGS_KEY_WINDOW_SIZE, "(ii)", width, height);
|
||||
}
|
||||
|
||||
static void
|
||||
settings_save (GtkFileChooserDefault *impl)
|
||||
{
|
||||
char *current_folder_uri;
|
||||
GSettings *settings;
|
||||
|
||||
settings_ensure (impl);
|
||||
settings = _gtk_file_chooser_get_settings_for_widget (GTK_WIDGET (impl));
|
||||
|
||||
/* Current folder */
|
||||
|
||||
@ -6092,29 +6087,26 @@ settings_save (GtkFileChooserDefault *impl)
|
||||
else
|
||||
current_folder_uri = "";
|
||||
|
||||
g_settings_set_string (impl->settings, SETTINGS_KEY_LAST_FOLDER_URI, current_folder_uri);
|
||||
g_settings_set_string (settings, SETTINGS_KEY_LAST_FOLDER_URI, current_folder_uri);
|
||||
|
||||
if (impl->current_folder)
|
||||
g_free (current_folder_uri);
|
||||
|
||||
/* All the other state */
|
||||
|
||||
g_settings_set_enum (impl->settings, SETTINGS_KEY_LOCATION_MODE, impl->location_mode);
|
||||
g_settings_set_boolean (impl->settings, SETTINGS_KEY_SHOW_HIDDEN,
|
||||
g_settings_set_enum (settings, SETTINGS_KEY_LOCATION_MODE, impl->location_mode);
|
||||
g_settings_set_boolean (settings, SETTINGS_KEY_SHOW_HIDDEN,
|
||||
gtk_file_chooser_get_show_hidden (GTK_FILE_CHOOSER (impl)));
|
||||
g_settings_set_boolean (impl->settings, SETTINGS_KEY_SHOW_SIZE_COLUMN, impl->show_size_column);
|
||||
g_settings_set_enum (impl->settings, SETTINGS_KEY_SORT_COLUMN, impl->sort_column);
|
||||
g_settings_set_enum (impl->settings, SETTINGS_KEY_SORT_ORDER, impl->sort_order);
|
||||
g_settings_set_int (impl->settings, SETTINGS_KEY_SIDEBAR_WIDTH,
|
||||
g_settings_set_boolean (settings, SETTINGS_KEY_SHOW_SIZE_COLUMN, impl->show_size_column);
|
||||
g_settings_set_enum (settings, SETTINGS_KEY_SORT_COLUMN, impl->sort_column);
|
||||
g_settings_set_enum (settings, SETTINGS_KEY_SORT_ORDER, impl->sort_order);
|
||||
g_settings_set_int (settings, SETTINGS_KEY_SIDEBAR_WIDTH,
|
||||
gtk_paned_get_position (GTK_PANED (impl->browse_widgets_hpaned)));
|
||||
|
||||
save_dialog_geometry (impl);
|
||||
|
||||
/* Now apply the settings */
|
||||
g_settings_apply (impl->settings);
|
||||
|
||||
g_object_unref (impl->settings);
|
||||
impl->settings = NULL;
|
||||
g_settings_apply (settings);
|
||||
}
|
||||
|
||||
/* GtkWidget::realize method */
|
||||
@ -6134,11 +6126,12 @@ static GFile *
|
||||
get_file_for_last_folder_opened (GtkFileChooserDefault *impl)
|
||||
{
|
||||
char *last_folder_uri;
|
||||
GSettings *settings;
|
||||
GFile *file;
|
||||
|
||||
settings_ensure (impl);
|
||||
settings = _gtk_file_chooser_get_settings_for_widget (GTK_WIDGET (impl));
|
||||
|
||||
last_folder_uri = g_settings_get_string (impl->settings, SETTINGS_KEY_LAST_FOLDER_URI);
|
||||
last_folder_uri = g_settings_get_string (settings, SETTINGS_KEY_LAST_FOLDER_URI);
|
||||
|
||||
/* If no last folder is set, we use the user's home directory, since
|
||||
* this is the starting point for most documents.
|
||||
@ -8214,13 +8207,14 @@ gtk_file_chooser_default_get_default_size (GtkFileChooserEmbed *chooser_embed,
|
||||
GtkFileChooserDefault *impl;
|
||||
GtkRequisition req;
|
||||
int x, y, width, height;
|
||||
GSettings *settings;
|
||||
|
||||
impl = GTK_FILE_CHOOSER_DEFAULT (chooser_embed);
|
||||
|
||||
settings_ensure (impl);
|
||||
settings = _gtk_file_chooser_get_settings_for_widget (GTK_WIDGET (impl));
|
||||
|
||||
g_settings_get (impl->settings, SETTINGS_KEY_WINDOW_POSITION, "(ii)", &x, &y);
|
||||
g_settings_get (impl->settings, SETTINGS_KEY_WINDOW_SIZE, "(ii)", &width, &height);
|
||||
g_settings_get (settings, SETTINGS_KEY_WINDOW_POSITION, "(ii)", &x, &y);
|
||||
g_settings_get (settings, SETTINGS_KEY_WINDOW_SIZE, "(ii)", &width, &height);
|
||||
|
||||
if (x >= 0 && y >= 0 && width > 0 && height > 0)
|
||||
{
|
||||
|
@ -280,8 +280,6 @@ struct _GtkFileChooserDefault
|
||||
gint sort_column;
|
||||
GtkSortType sort_order;
|
||||
|
||||
GSettings *settings;
|
||||
|
||||
#if 0
|
||||
GdkDragContext *shortcuts_drag_context;
|
||||
GSource *shortcuts_drag_outside_idle;
|
||||
|
@ -414,3 +414,30 @@ _gtk_file_chooser_extract_recent_folders (GList *infos)
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
GSettings *
|
||||
_gtk_file_chooser_get_settings_for_widget (GtkWidget *widget)
|
||||
{
|
||||
static GQuark file_chooser_settings_quark = 0;
|
||||
GtkSettings *gtksettings;
|
||||
GSettings *settings;
|
||||
|
||||
if (G_UNLIKELY (file_chooser_settings_quark == 0))
|
||||
file_chooser_settings_quark = g_quark_from_static_string ("-gtk-file-chooser-settings");
|
||||
|
||||
gtksettings = gtk_widget_get_settings (widget);
|
||||
settings = g_object_get_qdata (G_OBJECT (gtksettings), file_chooser_settings_quark);
|
||||
|
||||
if (G_UNLIKELY (settings == NULL))
|
||||
{
|
||||
settings = g_settings_new ("org.gtk.Settings.FileChooser");
|
||||
g_settings_delay (settings);
|
||||
|
||||
g_object_set_qdata_full (G_OBJECT (gtksettings),
|
||||
file_chooser_settings_quark,
|
||||
settings,
|
||||
g_object_unref);
|
||||
}
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
@ -52,6 +52,8 @@ GQuark _gtk_file_chooser_delegate_get_quark (void) G_GNUC_CONST;
|
||||
|
||||
GList *_gtk_file_chooser_extract_recent_folders (GList *infos);
|
||||
|
||||
GSettings *_gtk_file_chooser_get_settings_for_widget (GtkWidget *widget);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_FILE_CHOOSER_UTILS_H__ */
|
||||
|
Loading…
Reference in New Issue
Block a user