Commit 36dfea8e authored by Federico Mena Quintero's avatar Federico Mena Quintero Committed by Federico Mena Quintero

Removed the "extra widget" bit, implemented with the following:

2003-09-03  Federico Mena Quintero  <federico@ximian.com>

	* TODO: Removed the "extra widget" bit, implemented with the
	following:

	* gtkfilechooser.h: Added gtk_file_chooser_{set,get}_extra_widget().

	* gtkfilechooser.c (gtk_file_chooser_base_init): Install an
	"extra-widget" interface property.
	(gtk_file_chooser_set_extra_widget): Implemented.
	(gtk_file_chooser_get_extra_widget): Implemented.

	* gtkfilechooserutils.h (GtkFileChooserProp): Added
	GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET.

	* gtkfilechooserutils.c (_gtk_file_chooser_install_properties):
	Added the "extra-widget" property.

	* gtkfilechooserimpldefault.c (struct _GtkFileChooserImplDefault):
	Added an extra_widget field.
	(gtk_file_chooser_impl_default_set_property): Handle the
	"extra-widget" property.
	(gtk_file_chooser_impl_default_get_property): Likewise.
	(set_preview_widget): Fix the call gtk_container_remove().  Also,
	we don't need to ref/sink/unref the preview widget, as that gets
	already done by container_add/remove.
	(set_extra_widget): New utility function.

	* testfilechooser.c (main): Add an extra widget.
parent fafe735f
......@@ -127,6 +127,12 @@ gtk_file_chooser_base_init (gpointer g_iface)
_("Whether the application supplied widget for custom previews should be shown."),
TRUE,
G_PARAM_READWRITE));
g_object_interface_install_property (g_iface,
g_param_spec_object ("extra-widget",
_("Extra widget"),
_("Application supplied widget for extra options."),
GTK_TYPE_WIDGET,
G_PARAM_READWRITE));
g_object_interface_install_property (g_iface,
g_param_spec_boolean ("select-multiple",
_("Select Multiple"),
......@@ -1078,6 +1084,50 @@ gtk_file_chooser_get_preview_uri (GtkFileChooser *chooser)
return result;
}
/**
* gtk_file_chooser_set_extra_widget:
* @chooser: a #GtkFileChooser
* @extra_widget: widget for extra options
*
* Sets an application-supplied widget to provide extra options to the user.
**/
void
gtk_file_chooser_set_extra_widget (GtkFileChooser *chooser,
GtkWidget *extra_widget)
{
g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
g_object_set (chooser, "extra-widget", extra_widget, NULL);
}
/**
* gtk_file_chooser_get_extra_widget:
* @chooser: a #GtkFileChooser
*
* Gets the current preview widget; see
* gtk_file_chooser_set_extra_widget().
*
* Return value: the current extra widget, or %NULL
**/
GtkWidget *
gtk_file_chooser_get_extra_widget (GtkFileChooser *chooser)
{
GtkWidget *extra_widget;
g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
g_object_get (chooser, "extra-widget", &extra_widget, NULL);
/* Horrid hack; g_object_get() refs returned objects but
* that contradicts the memory management conventions
* for accessors.
*/
if (extra_widget)
g_object_unref (extra_widget);
return extra_widget;
}
/**
* gtk_file_chooser_add_filter:
* @chooser: a #GtkFileChooser
......
......@@ -101,6 +101,12 @@ gboolean gtk_file_chooser_get_preview_widget_active (GtkFileChooser *chooser);
char *gtk_file_chooser_get_preview_filename (GtkFileChooser *file_chooser);
char *gtk_file_chooser_get_preview_uri (GtkFileChooser *file_chooser);
/* Extra widget
*/
void gtk_file_chooser_set_extra_widget (GtkFileChooser *chooser,
GtkWidget *extra_widget);
GtkWidget *gtk_file_chooser_get_extra_widget (GtkFileChooser *chooser);
/* List of user selectable filters
*/
void gtk_file_chooser_add_filter (GtkFileChooser *chooser,
......
......@@ -89,6 +89,7 @@ struct _GtkFileChooserImplDefault
GtkWidget *list;
GtkWidget *entry;
GtkWidget *preview_widget;
GtkWidget *extra_widget;
};
static void gtk_file_chooser_impl_default_class_init (GtkFileChooserImplDefaultClass *class);
......@@ -277,20 +278,12 @@ set_preview_widget (GtkFileChooserImplDefault *impl,
return;
if (impl->preview_widget)
{
g_object_unref (impl->preview_widget);
impl->preview_widget = NULL;
gtk_container_remove (GTK_CONTAINER (impl->preview_frame),
impl->preview_widget);
}
gtk_container_remove (GTK_CONTAINER (impl->preview_frame),
impl->preview_widget);
impl->preview_widget = preview_widget;
if (impl->preview_widget)
{
g_object_ref (impl->preview_widget);
gtk_object_sink (GTK_OBJECT (impl->preview_widget));
gtk_widget_show (impl->preview_widget);
gtk_container_add (GTK_CONTAINER (impl->preview_frame),
impl->preview_widget);
......@@ -485,6 +478,25 @@ gtk_file_chooser_impl_default_constructor (GType type,
return object;
}
/* Sets the extra_widget by packing it in the appropriate place */
static void
set_extra_widget (GtkFileChooserImplDefault *impl,
GtkWidget *extra_widget)
{
if (extra_widget == impl->extra_widget)
return;
if (impl->extra_widget)
gtk_container_remove (GTK_CONTAINER (impl), impl->extra_widget);
impl->extra_widget = extra_widget;
if (impl->extra_widget)
{
gtk_widget_show (impl->extra_widget);
gtk_box_pack_end (GTK_BOX (impl), impl->extra_widget, FALSE, FALSE, 0);
}
}
static void
gtk_file_chooser_impl_default_set_property (GObject *object,
guint prop_id,
......@@ -538,6 +550,9 @@ gtk_file_chooser_impl_default_set_property (GObject *object,
impl->preview_widget_active = g_value_get_boolean (value);
update_preview_widget_visibility (impl);
break;
case GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET:
set_extra_widget (impl, g_value_get_object (value));
break;
case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE:
{
gboolean select_multiple = g_value_get_boolean (value);
......@@ -599,6 +614,9 @@ gtk_file_chooser_impl_default_get_property (GObject *object,
case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE:
g_value_set_boolean (value, impl->preview_widget_active);
break;
case GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET:
g_value_set_object (value, impl->extra_widget);
break;
case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE:
g_value_set_boolean (value, impl->select_multiple);
break;
......
......@@ -102,6 +102,11 @@ _gtk_file_chooser_install_properties (GObjectClass *klass)
g_param_spec_override ("preview-widget-active",
G_TYPE_BOOLEAN,
G_PARAM_READWRITE));
g_object_class_install_property (klass,
GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET,
g_param_spec_override ("extra-widget",
GTK_TYPE_WIDGET,
G_PARAM_READWRITE));
g_object_class_install_property (klass,
GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE,
g_param_spec_override ("select-multiple",
......
......@@ -35,6 +35,7 @@ typedef enum {
GTK_FILE_CHOOSER_PROP_LOCAL_ONLY,
GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET,
GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE,
GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET,
GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE,
GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN,
GTK_FILE_CHOOSER_PROP_LAST = GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN,
......
......@@ -264,6 +264,7 @@ main (int argc, char **argv)
GtkFileSystem *file_system;
GtkFileFilter *filter;
GtkWidget *preview_vbox;
GtkWidget *extra;
gtk_init (&argc, &argv);
......@@ -329,6 +330,10 @@ main (int argc, char **argv)
update_preview_cb (GTK_FILE_CHOOSER (dialog));
g_signal_connect (dialog, "update-preview",
G_CALLBACK (update_preview_cb), NULL);
/* Extra widget */
extra = gtk_check_button_new_with_mnemonic ("_Frobnicate the file");
gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (dialog), extra);
gtk_window_set_default_size (GTK_WINDOW (dialog), 600, 400);
/* show_all() to reveal bugs in composite widget handling */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment