[gtk+/composite-templates-new: 19/19] GtkFileChooserDialog: Define children with a GtkBuilder template
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/composite-templates-new: 19/19] GtkFileChooserDialog: Define children with a GtkBuilder template
- Date: Mon, 25 Mar 2013 12:54:07 +0000 (UTC)
commit a4c6702ca7bf71b5005a5eee8b782bc6fc5efc73
Author: Tristan Van Berkom <tristanvb openismus com>
Date: Mon Mar 25 21:49:49 2013 +0900
GtkFileChooserDialog: Define children with a GtkBuilder template
gtk/Makefile.am | 1 +
gtk/gtk.gresource.xml | 1 +
gtk/gtkfilechooserdialog.c | 106 +++++++++++--------------------------------
gtk/gtkfilechooserdialog.ui | 52 +++++++++++++++++++++
gtk/gtkfilechooserprivate.h | 2 -
gtk/tests/templates.c | 20 ++++++++
po/POTFILES.in | 1 +
7 files changed, 101 insertions(+), 82 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 65e1db3..c7eded4 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -1101,6 +1101,7 @@ COMPOSITE_TEMPLATES = \
gtkcolorchooserdialog.ui \
gtkdialog.ui \
gtkfilechooserdefault.ui \
+ gtkfilechooserdialog.ui \
gtkinfobar.ui \
gtklockbutton.ui \
gtkmessagedialog.ui \
diff --git a/gtk/gtk.gresource.xml b/gtk/gtk.gresource.xml
index d6631cb..ace43a7 100644
--- a/gtk/gtk.gresource.xml
+++ b/gtk/gtk.gresource.xml
@@ -18,6 +18,7 @@
<file>gtkcolorchooserdialog.ui</file>
<file>gtkdialog.ui</file>
<file>gtkfilechooserdefault.ui</file>
+ <file>gtkfilechooserdialog.ui</file>
<file>gtkinfobar.ui</file>
<file>gtklockbutton.ui</file>
<file>gtkmessagedialog.ui</file>
diff --git a/gtk/gtkfilechooserdialog.c b/gtk/gtkfilechooserdialog.c
index 6ed41b6..29a91a9 100644
--- a/gtk/gtkfilechooserdialog.c
+++ b/gtk/gtkfilechooserdialog.c
@@ -195,11 +195,6 @@
#define GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE(o) (GTK_FILE_CHOOSER_DIALOG (o)->priv)
-static void gtk_file_chooser_dialog_finalize (GObject *object);
-
-static GObject* gtk_file_chooser_dialog_constructor (GType type,
- guint n_construct_properties,
- GObjectConstructParam *construct_params);
static void gtk_file_chooser_dialog_set_property (GObject *object,
guint prop_id,
const GValue *value,
@@ -211,6 +206,12 @@ static void gtk_file_chooser_dialog_get_property (GObject *obj
static void gtk_file_chooser_dialog_map (GtkWidget *widget);
static void gtk_file_chooser_dialog_unmap (GtkWidget *widget);
+static void file_chooser_widget_file_activated (GtkFileChooser *chooser,
+ GtkFileChooserDialog *dialog);
+static void file_chooser_widget_default_size_changed (GtkWidget *widget,
+ GtkFileChooserDialog *dialog);
+static void file_chooser_widget_response_requested (GtkWidget *widget,
+ GtkFileChooserDialog *dialog);
static void response_cb (GtkDialog *dialog,
gint response_id);
@@ -224,11 +225,10 @@ gtk_file_chooser_dialog_class_init (GtkFileChooserDialogClass *class)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
+ GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
- gobject_class->constructor = gtk_file_chooser_dialog_constructor;
gobject_class->set_property = gtk_file_chooser_dialog_set_property;
gobject_class->get_property = gtk_file_chooser_dialog_get_property;
- gobject_class->finalize = gtk_file_chooser_dialog_finalize;
widget_class->map = gtk_file_chooser_dialog_map;
widget_class->unmap = gtk_file_chooser_dialog_unmap;
@@ -237,47 +237,33 @@ gtk_file_chooser_dialog_class_init (GtkFileChooserDialogClass *class)
_gtk_file_chooser_install_properties (gobject_class);
+ /* Bind class to template
+ */
+ gtk_container_class_set_template_from_resource (container_class,
+ "/org/gtk/libgtk/gtkfilechooserdialog.ui");
+
+ gtk_container_class_bind_child (container_class, GtkFileChooserDialogPrivate, widget);
+ gtk_container_class_bind_callback (container_class, response_cb);
+ gtk_container_class_bind_callback (container_class, file_chooser_widget_file_activated);
+ gtk_container_class_bind_callback (container_class, file_chooser_widget_default_size_changed);
+ gtk_container_class_bind_callback (container_class, file_chooser_widget_response_requested);
+
g_type_class_add_private (class, sizeof (GtkFileChooserDialogPrivate));
}
static void
gtk_file_chooser_dialog_init (GtkFileChooserDialog *dialog)
{
- GtkWidget *action_area, *content_area;
GtkFileChooserDialogPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (dialog,
GTK_TYPE_FILE_CHOOSER_DIALOG,
GtkFileChooserDialogPrivate);
- GtkDialog *fc_dialog = GTK_DIALOG (dialog);
-
dialog->priv = priv;
dialog->priv->response_requested = FALSE;
- content_area = gtk_dialog_get_content_area (fc_dialog);
- action_area = gtk_dialog_get_action_area (fc_dialog);
-
- gtk_container_set_border_width (GTK_CONTAINER (fc_dialog), 5);
- gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
- gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
-
- gtk_window_set_role (GTK_WINDOW (dialog), "GtkFileChooserDialog");
+ gtk_container_init_template (GTK_CONTAINER (dialog));
- /* We do a signal connection here rather than overriding the method in
- * class_init because GtkDialog::response is a RUN_LAST signal. We want *our*
- * handler to be run *first*, regardless of whether the user installs response
- * handlers of his own.
- */
- g_signal_connect (dialog, "response",
- G_CALLBACK (response_cb), NULL);
-}
-
-static void
-gtk_file_chooser_dialog_finalize (GObject *object)
-{
- GtkFileChooserDialog *dialog = GTK_FILE_CHOOSER_DIALOG (object);
-
- g_free (dialog->priv->file_system);
-
- G_OBJECT_CLASS (gtk_file_chooser_dialog_parent_class)->finalize (object);
+ _gtk_file_chooser_set_delegate (GTK_FILE_CHOOSER (dialog),
+ GTK_FILE_CHOOSER (priv->widget));
}
static gboolean
@@ -429,50 +415,6 @@ file_chooser_widget_response_requested (GtkWidget *widget,
g_list_free (children);
}
-
-static GObject*
-gtk_file_chooser_dialog_constructor (GType type,
- guint n_construct_properties,
- GObjectConstructParam *construct_params)
-{
- GtkFileChooserDialogPrivate *priv;
- GtkWidget *content_area;
- GObject *object;
-
- object = G_OBJECT_CLASS (gtk_file_chooser_dialog_parent_class)->constructor (type,
- n_construct_properties,
- construct_params);
- priv = GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE (object);
-
- gtk_widget_push_composite_child ();
-
- if (priv->file_system)
- priv->widget = g_object_new (GTK_TYPE_FILE_CHOOSER_WIDGET,
- NULL);
- else
- priv->widget = g_object_new (GTK_TYPE_FILE_CHOOSER_WIDGET, NULL);
-
- g_signal_connect (priv->widget, "file-activated",
- G_CALLBACK (file_chooser_widget_file_activated), object);
- g_signal_connect (priv->widget, "default-size-changed",
- G_CALLBACK (file_chooser_widget_default_size_changed), object);
- g_signal_connect (priv->widget, "response-requested",
- G_CALLBACK (file_chooser_widget_response_requested), object);
-
- content_area = gtk_dialog_get_content_area (GTK_DIALOG (object));
-
- gtk_container_set_border_width (GTK_CONTAINER (priv->widget), 5);
- gtk_box_pack_start (GTK_BOX (content_area), priv->widget, TRUE, TRUE, 0);
-
- gtk_widget_show (priv->widget);
-
- _gtk_file_chooser_set_delegate (GTK_FILE_CHOOSER (object),
- GTK_FILE_CHOOSER (priv->widget));
-
- gtk_widget_pop_composite_child ();
-
- return object;
-}
static void
gtk_file_chooser_dialog_set_property (GObject *object,
@@ -568,7 +510,11 @@ gtk_file_chooser_dialog_unmap (GtkWidget *widget)
GTK_WIDGET_CLASS (gtk_file_chooser_dialog_parent_class)->unmap (widget);
}
-/* GtkDialog::response handler */
+/* We do a signal connection here rather than overriding the method in
+ * class_init because GtkDialog::response is a RUN_LAST signal. We want *our*
+ * handler to be run *first*, regardless of whether the user installs response
+ * handlers of his own.
+ */
static void
response_cb (GtkDialog *dialog,
gint response_id)
diff --git a/gtk/gtkfilechooserdialog.ui b/gtk/gtkfilechooserdialog.ui
new file mode 100644
index 0000000..b98113f
--- /dev/null
+++ b/gtk/gtkfilechooserdialog.ui
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.10 -->
+ <template class="GtkFileChooserDialog" parent="GtkDialog">
+ <property name="can_focus">False</property>
+ <property name="border_width">5</property>
+ <property name="role">GtkFileChooserDialog</property>
+ <property name="type_hint">dialog</property>
+ <signal name="response" handler="response_cb" swapped="no"/>
+ <child internal-child="vbox">
+ <object class="GtkBox" id="dialog-vbox1">
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">2</property>
+ <child internal-child="action_area">
+ <object class="GtkButtonBox" id="dialog-action_area1">
+ <property name="can_focus">False</property>
+ <property name="layout_style">end</property>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="pack_type">end</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkFileChooserWidget" id="widget">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="border_width">5</property>
+ <property name="orientation">vertical</property>
+ <signal name="file-activated" handler="file_chooser_widget_file_activated" swapped="no"/>
+ <signal name="response-requested" handler="file_chooser_widget_response_requested" swapped="no"/>
+ <signal name="default-size-changed" handler="file_chooser_widget_default_size_changed"
swapped="no"/>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/gtk/gtkfilechooserprivate.h b/gtk/gtkfilechooserprivate.h
index 3f7d08c..34ff0f0 100644
--- a/gtk/gtkfilechooserprivate.h
+++ b/gtk/gtkfilechooserprivate.h
@@ -106,8 +106,6 @@ GSList * _gtk_file_chooser_list_shortcut_folder_files (GtkFileChooser *cho
struct _GtkFileChooserDialogPrivate
{
GtkWidget *widget;
-
- char *file_system;
/* for use with GtkFileChooserEmbed */
gboolean response_requested;
diff --git a/gtk/tests/templates.c b/gtk/tests/templates.c
index e6bbd84..72a1c96 100644
--- a/gtk/tests/templates.c
+++ b/gtk/tests/templates.c
@@ -211,6 +211,25 @@ test_file_chooser_widget_basic (void)
gtk_widget_destroy (widget);
}
+static void
+test_file_chooser_dialog_basic (void)
+{
+ GtkWidget *widget;
+
+ g_test_log_set_fatal_handler (ignore_gvfs_warning, NULL);
+
+ widget = gtk_file_chooser_dialog_new ("The Dialog", NULL,
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ GTK_STOCK_OK, GTK_RESPONSE_OK,
+ NULL);
+
+ g_assert (GTK_IS_FILE_CHOOSER_DIALOG (widget));
+ g_timeout_add (100, main_loop_quit_cb, NULL);
+ gtk_main();
+
+ gtk_widget_destroy (widget);
+}
+
int
main (int argc, char **argv)
{
@@ -230,6 +249,7 @@ main (int argc, char **argv)
g_test_add_func ("/Template/GtkAppChooserDialog/Basic", test_app_chooser_dialog_basic);
g_test_add_func ("/Template/GtkColorChooserDialog/Basic", test_color_chooser_dialog_basic);
g_test_add_func ("/Template/GtkFileChooserWidget/Basic", test_file_chooser_widget_basic);
+ g_test_add_func ("/Template/GtkFileChooserDialog/Basic", test_file_chooser_dialog_basic);
return g_test_run();
}
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 659332e..5c0fb8e 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -281,6 +281,7 @@ modules/printbackends/test/gtkprintbackendtest.c
[type: gettext/glade]gtk/gtkcolorchooserdialog.ui
[type: gettext/glade]gtk/gtkdialog.ui
[type: gettext/glade]gtk/gtkfilechooserdedault.ui
+[type: gettext/glade]gtk/gtkfilechooserdialog.ui
[type: gettext/glade]gtk/gtkinfobar.ui
[type: gettext/glade]gtk/gtklockbutton.ui
[type: gettext/glade]gtk/gtkmessagedialog.ui
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]