diff --git a/ChangeLog b/ChangeLog index ec59a0c650..3de82bb3da 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-12-18 Sven Neumann + + * libgimpwidgets/gimppropwidgets.[ch] + * libgimpwidgets/gimpwidgets.def: added new function + gimp_prop_file_chooser_button_new_with_dialog(). + 2006-12-16 Mukund Sivaraman * app/core/gimp-transform-resize.c: Fixed code in diff --git a/libgimpwidgets/gimppropwidgets.c b/libgimpwidgets/gimppropwidgets.c index f4665160a3..5a6c2701d0 100644 --- a/libgimpwidgets/gimppropwidgets.c +++ b/libgimpwidgets/gimppropwidgets.c @@ -1925,11 +1925,15 @@ gimp_prop_text_buffer_notify (GObject *config, /*************************/ -static void gimp_prop_file_chooser_button_callback (GtkFileChooser *button, - GObject *config); -static void gimp_prop_file_chooser_button_notify (GObject *config, - GParamSpec *param_spec, - GtkFileChooser *button); +static GtkWidget * gimp_prop_file_chooser_button_setup (GtkWidget *button, + GObject *config, + GParamSpec *param_spec); +static void gimp_prop_file_chooser_button_callback (GtkFileChooser *button, + GObject *config); +static void gimp_prop_file_chooser_button_notify (GObject *config, + GParamSpec *param_spec, + GtkFileChooser *button); + /** * gimp_prop_file_chooser_button_new: @@ -1955,9 +1959,6 @@ gimp_prop_file_chooser_button_new (GObject *config, { GParamSpec *param_spec; GtkWidget *button; - GtkWidget *widget; - gchar *filename; - gchar *value; g_return_val_if_fail (G_IS_OBJECT (config), NULL); g_return_val_if_fail (property_name != NULL, NULL); @@ -1967,15 +1968,79 @@ gimp_prop_file_chooser_button_new (GObject *config, if (! param_spec) return NULL; + button = gtk_file_chooser_button_new (title, action); + + return gimp_prop_file_chooser_button_setup (button, config, param_spec); +} + +/** + * gimp_prop_file_chooser_button_new_with_dialog: + * @config: object to which property is attached. + * @property_name: name of path property. + * @dialog: the #GtkFileChooserDialog widget to use. + * + * Creates a #GtkFileChooserButton to edit the specified path property. + * + * The button uses @dialog as it's file-picking window. Note that @dialog + * must be a #GtkFileChooserDialog (or subclass) and must not have + * %GTK_DIALOG_DESTROY_WITH_PARENT set. + * + * Note that #GtkFileChooserButton implements the #GtkFileChooser + * interface; you can use the #GtkFileChooser API with it. + * + * Return value: A new #GtkFileChooserButton. + * + * Since GIMP 2.4 + */ +GtkWidget * +gimp_prop_file_chooser_button_new_with_dialog (GObject *config, + const gchar *property_name, + GtkWidget *dialog) +{ + GParamSpec *param_spec; + GtkWidget *button; + gchar *title; + + g_return_val_if_fail (G_IS_OBJECT (config), NULL); + g_return_val_if_fail (property_name != NULL, NULL); + g_return_val_if_fail (GTK_IS_FILE_CHOOSER_DIALOG (dialog), NULL); + + param_spec = check_param_spec (config, property_name, + GIMP_TYPE_PARAM_CONFIG_PATH, G_STRFUNC); + if (! param_spec) + return NULL; + + /* work around bug in GtkFileChooserButton */ + title = g_strdup (gtk_window_get_title (GTK_WINDOW (dialog))); + + button = gtk_file_chooser_button_new_with_dialog (dialog); + + if (title) + { + gtk_file_chooser_button_set_title (GTK_FILE_CHOOSER_BUTTON (button), + title); + g_free (title); + } + + return gimp_prop_file_chooser_button_setup (button, config, param_spec); +} + +static GtkWidget * +gimp_prop_file_chooser_button_setup (GtkWidget *button, + GObject *config, + GParamSpec *param_spec) +{ + GtkWidget *widget; + gchar *value; + gchar *filename; + g_object_get (config, - property_name, &value, + param_spec->name, &value, NULL); filename = value ? gimp_config_path_expand (value, TRUE, NULL) : NULL; g_free (value); - button = gtk_file_chooser_button_new (title, action); - if (filename) { gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (button), filename); @@ -2000,7 +2065,7 @@ gimp_prop_file_chooser_button_new (GObject *config, G_CALLBACK (gimp_prop_file_chooser_button_callback), config); - connect_notify (config, property_name, + connect_notify (config, param_spec->name, G_CALLBACK (gimp_prop_file_chooser_button_notify), button); diff --git a/libgimpwidgets/gimppropwidgets.h b/libgimpwidgets/gimppropwidgets.h index a4228eb7f6..e12ff59962 100644 --- a/libgimpwidgets/gimppropwidgets.h +++ b/libgimpwidgets/gimppropwidgets.h @@ -144,6 +144,10 @@ GtkWidget * gimp_prop_file_chooser_button_new (GObject *config, const gchar *property_name, const gchar *title, GtkFileChooserAction action); +GtkWidget * gimp_prop_file_chooser_button_new_with_dialog (GObject *config, + const gchar *property_name, + + GtkWidget *dialog); GtkWidget * gimp_prop_path_editor_new (GObject *config, const gchar *path_property_name, const gchar *writable_property_name, diff --git a/libgimpwidgets/gimpwidgets.def b/libgimpwidgets/gimpwidgets.def index d8991498bc..91fa4ff748 100644 --- a/libgimpwidgets/gimpwidgets.def +++ b/libgimpwidgets/gimpwidgets.def @@ -243,6 +243,7 @@ EXPORTS gimp_prop_enum_stock_box_new gimp_prop_expander_new gimp_prop_file_chooser_button_new + gimp_prop_file_chooser_button_new_with_dialog gimp_prop_hscale_new gimp_prop_int_combo_box_new gimp_prop_label_new