[gtk+/composite-templates-new: 16/19] GtkAppChooserDialog: 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: 16/19] GtkAppChooserDialog: Define children with a GtkBuilder template
- Date: Mon, 25 Mar 2013 13:26:08 +0000 (UTC)
commit 591d7f121044e183d31b76481ba32723d3be0ef3
Author: Tristan Van Berkom <tristanvb openismus com>
Date: Sat Mar 23 23:02:33 2013 +0900
GtkAppChooserDialog: Define children with a GtkBuilder template
gtk/Makefile.am | 1 +
gtk/gtk.gresource.xml | 1 +
gtk/gtkappchooserdialog.c | 70 +++++++++----------------
gtk/gtkappchooserdialog.ui | 123 ++++++++++++++++++++++++++++++++++++++++++++
gtk/tests/templates.c | 11 ++++
po/POTFILES.in | 1 +
6 files changed, 161 insertions(+), 46 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 9cf77ac..abd15da 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -1095,6 +1095,7 @@ DND_CURSORS = \
COMPOSITE_TEMPLATES = \
gtkaboutdialog.ui \
+ gtkappchooserdialog.ui \
gtkappchooserwidget.ui \
gtkassistant.ui \
gtkdialog.ui \
diff --git a/gtk/gtk.gresource.xml b/gtk/gtk.gresource.xml
index e7bd656..db5ce92 100644
--- a/gtk/gtk.gresource.xml
+++ b/gtk/gtk.gresource.xml
@@ -12,6 +12,7 @@
<file alias="cursor/dnd-move.png">cursor_dnd_move.png</file>
<file alias="cursor/dnd-copy.png">cursor_dnd_copy.png</file>
<file>gtkaboutdialog.ui</file>
+ <file>gtkappchooserdialog.ui</file>
<file>gtkappchooserwidget.ui</file>
<file>gtkassistant.ui</file>
<file>gtkdialog.ui</file>
diff --git a/gtk/gtkappchooserdialog.c b/gtk/gtkappchooserdialog.c
index 00882d5..74fc493 100644
--- a/gtk/gtkappchooserdialog.c
+++ b/gtk/gtkappchooserdialog.c
@@ -68,6 +68,7 @@ struct _GtkAppChooserDialogPrivate {
GtkWidget *label;
GtkWidget *button;
GtkWidget *online_button;
+ GtkWidget *inner_box;
GtkWidget *open_label;
@@ -450,35 +451,14 @@ widget_populate_popup_cb (GtkAppChooserWidget *widget,
}
static void
-build_dialog_ui (GtkAppChooserDialog *self)
+construct_appchooser_widget (GtkAppChooserDialog *self)
{
- GtkWidget *vbox;
- GtkWidget *vbox2;
- GtkWidget *button, *w;
GAppInfo *info;
- gtk_container_set_border_width (GTK_CONTAINER (self), 5);
-
- vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
- gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
- gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (self))), vbox, TRUE, TRUE, 0);
- gtk_widget_show (vbox);
-
- vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
- gtk_box_pack_start (GTK_BOX (vbox), vbox2, TRUE, TRUE, 0);
- gtk_widget_show (vbox2);
-
- self->priv->label = gtk_label_new ("");
- gtk_widget_set_halign (self->priv->label, GTK_ALIGN_START);
- gtk_widget_set_valign (self->priv->label, GTK_ALIGN_CENTER);
- gtk_label_set_line_wrap (GTK_LABEL (self->priv->label), TRUE);
- gtk_box_pack_start (GTK_BOX (vbox2), self->priv->label,
- FALSE, FALSE, 0);
- gtk_widget_show (self->priv->label);
-
+ /* Need to build the appchooser widget after, because of the content-type construct-only property */
self->priv->app_chooser_widget =
gtk_app_chooser_widget_new (self->priv->content_type);
- gtk_box_pack_start (GTK_BOX (vbox2), self->priv->app_chooser_widget, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (self->priv->inner_box), self->priv->app_chooser_widget, TRUE, TRUE, 0);
gtk_widget_show (self->priv->app_chooser_widget);
g_signal_connect (self->priv->app_chooser_widget, "application-selected",
@@ -490,32 +470,14 @@ build_dialog_ui (GtkAppChooserDialog *self)
g_signal_connect (self->priv->app_chooser_widget, "populate-popup",
G_CALLBACK (widget_populate_popup_cb), self);
- button = gtk_button_new_with_label (_("Show other applications"));
- self->priv->show_more_button = button;
- w = gtk_image_new_from_stock (GTK_STOCK_ADD,
- GTK_ICON_SIZE_BUTTON);
- gtk_button_set_image (GTK_BUTTON (button), w);
- gtk_box_pack_start (GTK_BOX (self->priv->app_chooser_widget), button, FALSE, FALSE, 6);
- gtk_widget_show_all (button);
-
- g_signal_connect (button, "clicked",
- G_CALLBACK (show_more_button_clicked_cb), self);
-
- gtk_dialog_add_button (GTK_DIALOG (self),
- GTK_STOCK_CANCEL,
- GTK_RESPONSE_CANCEL);
-
- self->priv->button = gtk_dialog_add_button (GTK_DIALOG (self),
- _("_Select"),
- GTK_RESPONSE_OK);
+ /* Add the custom button to the new appchooser */
+ gtk_box_pack_start (GTK_BOX (self->priv->app_chooser_widget),
+ self->priv->show_more_button, FALSE, FALSE, 6);
info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (self->priv->app_chooser_widget));
gtk_widget_set_sensitive (self->priv->button, info != NULL);
if (info)
g_object_unref (info);
-
- gtk_dialog_set_default_response (GTK_DIALOG (self),
- GTK_RESPONSE_OK);
}
static void
@@ -560,7 +522,7 @@ gtk_app_chooser_dialog_constructed (GObject *object)
if (G_OBJECT_CLASS (gtk_app_chooser_dialog_parent_class)->constructed != NULL)
G_OBJECT_CLASS (gtk_app_chooser_dialog_parent_class)->constructed (object);
- build_dialog_ui (self);
+ construct_appchooser_widget (self);
set_dialog_properties (self);
ensure_online_button (self);
}
@@ -651,6 +613,7 @@ static void
gtk_app_chooser_dialog_class_init (GtkAppChooserDialogClass *klass)
{
GObjectClass *gobject_class;
+ GtkContainerClass *container_class;
GParamSpec *pspec;
gobject_class = G_OBJECT_CLASS (klass);
@@ -690,6 +653,16 @@ gtk_app_chooser_dialog_class_init (GtkAppChooserDialogClass *klass)
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
g_object_class_install_property (gobject_class, PROP_HEADING, pspec);
+ /* Bind class to template
+ */
+ container_class = GTK_CONTAINER_CLASS (klass);
+ gtk_container_class_set_template_from_resource (container_class,
+ "/org/gtk/libgtk/gtkappchooserdialog.ui");
+ gtk_container_class_bind_child (container_class, GtkAppChooserDialogPrivate, label);
+ gtk_container_class_bind_child (container_class, GtkAppChooserDialogPrivate, button);
+ gtk_container_class_bind_child (container_class, GtkAppChooserDialogPrivate, show_more_button);
+ gtk_container_class_bind_child (container_class, GtkAppChooserDialogPrivate, inner_box);
+ gtk_container_class_bind_callback (container_class, show_more_button_clicked_cb);
g_type_class_add_private (klass, sizeof (GtkAppChooserDialogPrivate));
}
@@ -700,11 +673,16 @@ gtk_app_chooser_dialog_init (GtkAppChooserDialog *self)
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTK_TYPE_APP_CHOOSER_DIALOG,
GtkAppChooserDialogPrivate);
+ gtk_container_init_template (GTK_CONTAINER (self));
+
/* we can't override the class signal handler here, as it's a RUN_LAST;
* we want our signal handler instead to be executed before any user code.
*/
g_signal_connect (self, "response",
G_CALLBACK (gtk_app_chooser_dialog_response), NULL);
+
+ gtk_dialog_set_default_response (GTK_DIALOG (self),
+ GTK_RESPONSE_OK);
}
static void
diff --git a/gtk/gtkappchooserdialog.ui b/gtk/gtkappchooserdialog.ui
new file mode 100644
index 0000000..720cde1
--- /dev/null
+++ b/gtk/gtkappchooserdialog.ui
@@ -0,0 +1,123 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface domain="gtk30">
+ <!-- interface-requires gtk+ 3.10 -->
+ <template class="GtkAppChooserDialog" parent="GtkDialog">
+ <property name="can_focus">False</property>
+ <property name="border_width">5</property>
+ <property name="type_hint">dialog</property>
+ <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>
+ <object class="GtkButton" id="cancel">
+ <property name="label">gtk-cancel</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="can_default">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="button">
+ <property name="label" translatable="yes">_Select</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="can_default">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_underline">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </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="GtkBox" id="main_box">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="border_width">5</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">12</property>
+ <child>
+ <object class="GtkBox" id="inner_box">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkLabel" id="label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">start</property>
+ <property name="valign">center</property>
+ <property name="label" translatable="yes">label</property>
+ <property name="wrap">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="-6">cancel</action-widget>
+ <action-widget response="-5">button</action-widget>
+ </action-widgets>
+ </template>
+ <object class="GtkImage" id="show_more_image">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="stock">gtk-add</property>
+ </object>
+ <object class="GtkButton" id="show_more_button">
+ <property name="label" translatable="yes">Show Other Applications</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="image">show_more_image</property>
+ <signal name="clicked" handler="show_more_button_clicked_cb" swapped="no"/>
+ </object>
+</interface>
diff --git a/gtk/tests/templates.c b/gtk/tests/templates.c
index 5bb96a4..4276011 100644
--- a/gtk/tests/templates.c
+++ b/gtk/tests/templates.c
@@ -129,6 +129,16 @@ test_app_chooser_widget_basic (void)
gtk_widget_destroy (widget);
}
+static void
+test_app_chooser_dialog_basic (void)
+{
+ GtkWidget *widget;
+
+ widget = gtk_app_chooser_dialog_new_for_content_type (NULL, 0, "text/plain");
+ g_assert (GTK_IS_APP_CHOOSER_DIALOG (widget));
+ gtk_widget_destroy (widget);
+}
+
int
main (int argc, char **argv)
{
@@ -145,6 +155,7 @@ main (int argc, char **argv)
g_test_add_func ("/Template/GtkScaleButton/Basic", test_scale_button_basic);
g_test_add_func ("/Template/GtkStatusBar/Basic", test_statusbar_basic);
g_test_add_func ("/Template/GtkAppChooserWidget/Basic", test_app_chooser_widget_basic);
+ g_test_add_func ("/Template/GtkAppChooserDialog/Basic", test_app_chooser_dialog_basic);
return g_test_run();
}
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 8f7d476..5755ba5 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -275,6 +275,7 @@ modules/printbackends/lpr/gtkprintbackendlpr.c
modules/printbackends/papi/gtkprintbackendpapi.c
modules/printbackends/test/gtkprintbackendtest.c
[type: gettext/glade]gtk/gtkaboutdialog.ui
+[type: gettext/glade]gtk/gtkappchooserdialog.ui
[type: gettext/glade]gtk/gtkappchooserwidget.ui
[type: gettext/glade]gtk/gtkassistant.ui
[type: gettext/glade]gtk/gtkdialog.ui
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]