Add GtkFileChooserSettings for the dialog's geometry

2009-01-14  Federico Mena Quintero  <federico@novell.com>

	    Remember the file chooser's geometry across invocations.

	    * gtk/gtkfilechoosersettings.h (struct _GtkFileChooserSettings):
	    New fields geometry_x, geometry_y, geometry_width, geometry_height.
	    (_gtk_file_chooser_settings_get_geometry): New prototype.
	    (_gtk_file_chooser_settings_set_geometry): New prototype.

	    * gtk/gtkfilechoosersettings.c (GEOMETRY_X_KEY, GEOMETRY_Y_KEY,
	    GEOMETRY_WIDTH_KEY, GEOMETRY_HEIGTH_KEY): New key names.
	    (ensure_settings_read): Read the geometry keys.
	    (_gtk_file_chooser_settings_save): Save the geometry keys.
	    (_gtk_file_chooser_settings_init): Initialize the geometry keys to
	    "don't have this value".
	    (_gtk_file_chooser_settings_get_geometry): New public function.
	    (_gtk_file_chooser_settings_set_geometry): New public function.

Signed-off-by: Federico Mena Quintero <federico@novell.com>

svn path=/trunk/; revision=22116
This commit is contained in:
Federico Mena Quintero 2009-01-14 20:18:23 +00:00 committed by Federico Mena Quintero
parent 245fbd73a4
commit b05fcd7e6b
3 changed files with 101 additions and 0 deletions

View File

@ -1,3 +1,21 @@
2009-01-14 Federico Mena Quintero <federico@novell.com>
Remember the file chooser's geometry across invocations.
* gtk/gtkfilechoosersettings.h (struct _GtkFileChooserSettings):
New fields geometry_x, geometry_y, geometry_width, geometry_height.
(_gtk_file_chooser_settings_get_geometry): New prototype.
(_gtk_file_chooser_settings_set_geometry): New prototype.
* gtk/gtkfilechoosersettings.c (GEOMETRY_X_KEY, GEOMETRY_Y_KEY,
GEOMETRY_WIDTH_KEY, GEOMETRY_HEIGTH_KEY): New key names.
(ensure_settings_read): Read the geometry keys.
(_gtk_file_chooser_settings_save): Save the geometry keys.
(_gtk_file_chooser_settings_init): Initialize the geometry keys to
"don't have this value".
(_gtk_file_chooser_settings_get_geometry): New public function.
(_gtk_file_chooser_settings_set_geometry): New public function.
2009-01-13 Matthias Clasen <mclasen@redhat.com>
Bug 450716 New API to change global IM

View File

@ -42,6 +42,10 @@
#define SHOW_HIDDEN_KEY "ShowHidden"
#define EXPAND_FOLDERS_KEY "ExpandFolders"
#define SHOW_SIZE_COLUMN_KEY "ShowSizeColumn"
#define GEOMETRY_X_KEY "GeometryX"
#define GEOMETRY_Y_KEY "GeometryY"
#define GEOMETRY_WIDTH_KEY "GeometryWidth"
#define GEOMETRY_HEIGHT_KEY "GeometryHeight"
#define MODE_PATH_BAR "path-bar"
#define MODE_FILENAME_ENTRY "filename-entry"
@ -76,6 +80,24 @@ warn_if_invalid_key_and_clear_error (const gchar *key,
}
}
static void
get_int_key (GKeyFile *key_file, const char *group, const char *key, int *out_value)
{
GError *error;
int val;
error = NULL;
val = g_key_file_get_integer (key_file, group, key, &error);
if (val == 0 && error != NULL)
{
*out_value = -1;
g_error_free (error);
}
else
*out_value = val;
}
static void
ensure_settings_read (GtkFileChooserSettings *settings)
{
@ -143,6 +165,11 @@ ensure_settings_read (GtkFileChooserSettings *settings)
else
settings->show_size_column = value != FALSE;
get_int_key (key_file, SETTINGS_GROUP, GEOMETRY_X_KEY, &settings->geometry_x);
get_int_key (key_file, SETTINGS_GROUP, GEOMETRY_Y_KEY, &settings->geometry_y);
get_int_key (key_file, SETTINGS_GROUP, GEOMETRY_WIDTH_KEY, &settings->geometry_width);
get_int_key (key_file, SETTINGS_GROUP, GEOMETRY_HEIGHT_KEY, &settings->geometry_height);
out:
g_key_file_free (key_file);
@ -165,6 +192,10 @@ _gtk_file_chooser_settings_init (GtkFileChooserSettings *settings)
settings->show_hidden = FALSE;
settings->expand_folders = FALSE;
settings->show_size_column = FALSE;
settings->geometry_x = -1;
settings->geometry_y = -1;
settings->geometry_width = -1;
settings->geometry_height = -1;
}
GtkFileChooserSettings *
@ -229,6 +260,34 @@ _gtk_file_chooser_settings_set_expand_folders (GtkFileChooserSettings *settings,
settings->expand_folders = expand_folders != FALSE;
}
void
_gtk_file_chooser_settings_get_geometry (GtkFileChooserSettings *settings,
int *out_x,
int *out_y,
int *out_width,
int *out_height)
{
ensure_settings_read (settings);
*out_x = settings->geometry_x;
*out_y = settings->geometry_y;
*out_width = settings->geometry_width;
*out_height = settings->geometry_height;
}
void
_gtk_file_chooser_settings_set_geometry (GtkFileChooserSettings *settings,
int x,
int y,
int width,
int height)
{
settings->geometry_x = x;
settings->geometry_y = y;
settings->geometry_width = width;
settings->geometry_height = height;
}
gboolean
_gtk_file_chooser_settings_save (GtkFileChooserSettings *settings,
GError **error)
@ -271,6 +330,14 @@ _gtk_file_chooser_settings_save (GtkFileChooserSettings *settings,
EXPAND_FOLDERS_KEY, settings->expand_folders);
g_key_file_set_boolean (key_file, SETTINGS_GROUP,
SHOW_SIZE_COLUMN_KEY, settings->show_size_column);
g_key_file_set_integer (key_file, SETTINGS_GROUP,
GEOMETRY_X_KEY, settings->geometry_x);
g_key_file_set_integer (key_file, SETTINGS_GROUP,
GEOMETRY_Y_KEY, settings->geometry_y);
g_key_file_set_integer (key_file, SETTINGS_GROUP,
GEOMETRY_WIDTH_KEY, settings->geometry_width);
g_key_file_set_integer (key_file, SETTINGS_GROUP,
GEOMETRY_HEIGHT_KEY, settings->geometry_height);
contents = g_key_file_to_data (key_file, &len, error);
g_key_file_free (key_file);

View File

@ -38,6 +38,11 @@ struct _GtkFileChooserSettings
LocationMode location_mode;
int geometry_x;
int geometry_y;
int geometry_width;
int geometry_height;
guint settings_read : 1;
guint show_hidden : 1;
guint show_size_column : 1;
@ -69,6 +74,17 @@ gboolean _gtk_file_chooser_settings_get_show_size_column (GtkFileChooserSettings
void _gtk_file_chooser_settings_set_show_size_column (GtkFileChooserSettings *settings,
gboolean show_column);
void _gtk_file_chooser_settings_get_geometry (GtkFileChooserSettings *settings,
int *out_x,
int *out_y,
int *out_width,
int *out_heigth);
void _gtk_file_chooser_settings_set_geometry (GtkFileChooserSettings *settings,
int x,
int y,
int width,
int heigth);
gboolean _gtk_file_chooser_settings_save (GtkFileChooserSettings *settings,
GError **error);