[gtk+/composite-templates-new: 12/13] GtkAppChooserWidget: 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: 12/13] GtkAppChooserWidget: Define children with a GtkBuilder template
- Date: Sat, 23 Mar 2013 13:23:38 +0000 (UTC)
commit c79918baad8cfc4955b852dbc8480286287ff4f9
Author: Tristan Van Berkom <tristanvb openismus com>
Date: Sat Mar 23 21:59:30 2013 +0900
GtkAppChooserWidget: Define children with a GtkBuilder template
gtk/Makefile.am | 1 +
gtk/gtk.gresource.xml | 1 +
gtk/gtkappchooserwidget.c | 44 ++++++++++++++++----------------------------
gtk/tests/templates.c | 11 +++++++++++
po/POTFILES.in | 1 +
5 files changed, 30 insertions(+), 28 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 95e378c..9cf77ac 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -1095,6 +1095,7 @@ DND_CURSORS = \
COMPOSITE_TEMPLATES = \
gtkaboutdialog.ui \
+ gtkappchooserwidget.ui \
gtkassistant.ui \
gtkdialog.ui \
gtkinfobar.ui \
diff --git a/gtk/gtk.gresource.xml b/gtk/gtk.gresource.xml
index cf7b9ed..e7bd656 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>gtkappchooserwidget.ui</file>
<file>gtkassistant.ui</file>
<file>gtkdialog.ui</file>
<file>gtkinfobar.ui</file>
diff --git a/gtk/gtkappchooserwidget.c b/gtk/gtkappchooserwidget.c
index 36875df..c32bf04 100644
--- a/gtk/gtkappchooserwidget.c
+++ b/gtk/gtkappchooserwidget.c
@@ -1003,6 +1003,7 @@ static void
gtk_app_chooser_widget_class_init (GtkAppChooserWidgetClass *klass)
{
GObjectClass *gobject_class;
+ GtkContainerClass *container_class;
GParamSpec *pspec;
gobject_class = G_OBJECT_CLASS (klass);
@@ -1160,48 +1161,35 @@ gtk_app_chooser_widget_class_init (GtkAppChooserWidgetClass *klass)
G_TYPE_NONE,
2, GTK_TYPE_MENU, G_TYPE_APP_INFO);
+ /* Define templates */
+ container_class = GTK_CONTAINER_CLASS (klass);
+ gtk_container_class_set_template (container_class,
+ GTK_TEMPLATE_SOURCE_RESOURCE,
+ "/org/gtk/libgtk/gtkappchooserwidget.ui");
+ gtk_container_class_automate_child (container_class, "program_list", FALSE, GTK_AUTOMATE_CHILD_PRIVATE,
+ G_STRUCT_OFFSET (GtkAppChooserWidgetPrivate, program_list));
+ gtk_container_class_declare_callbacks (container_class,
+ "refresh_and_emit_app_selected",
(GCallback)refresh_and_emit_app_selected,
+ "program_list_selection_activated",
(GCallback)program_list_selection_activated,
+ "widget_button_press_event_cb",
(GCallback)widget_button_press_event_cb,
+ NULL);
+
g_type_class_add_private (klass, sizeof (GtkAppChooserWidgetPrivate));
}
static void
gtk_app_chooser_widget_init (GtkAppChooserWidget *self)
{
- GtkWidget *scrolled_window;
GtkTreeSelection *selection;
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTK_TYPE_APP_CHOOSER_WIDGET,
GtkAppChooserWidgetPrivate);
- gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_VERTICAL);
-
- scrolled_window = gtk_scrolled_window_new (NULL, NULL);
- gtk_widget_set_size_request (scrolled_window, 400, 300);
- gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
- GTK_SHADOW_IN);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
- GTK_POLICY_NEVER,
- GTK_POLICY_AUTOMATIC);
- gtk_widget_show (scrolled_window);
-
- self->priv->program_list = gtk_tree_view_new ();
- gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (self->priv->program_list),
- FALSE);
- gtk_container_add (GTK_CONTAINER (scrolled_window), self->priv->program_list);
- gtk_box_pack_start (GTK_BOX (self), scrolled_window, TRUE, TRUE, 0);
- gtk_widget_show (self->priv->program_list);
+
+ gtk_container_init_template (GTK_CONTAINER (self));
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (self->priv->program_list));
- gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
gtk_tree_selection_set_select_function (selection, gtk_app_chooser_selection_func,
self, NULL);
- g_signal_connect_swapped (selection, "changed",
- G_CALLBACK (refresh_and_emit_app_selected),
- self);
- g_signal_connect (self->priv->program_list, "row-activated",
- G_CALLBACK (program_list_selection_activated),
- self);
- g_signal_connect (self->priv->program_list, "button-press-event",
- G_CALLBACK (widget_button_press_event_cb),
- self);
}
static GAppInfo *
diff --git a/gtk/tests/templates.c b/gtk/tests/templates.c
index 24fd951..5bb96a4 100644
--- a/gtk/tests/templates.c
+++ b/gtk/tests/templates.c
@@ -119,6 +119,16 @@ test_statusbar_basic (void)
gtk_widget_destroy (widget);
}
+static void
+test_app_chooser_widget_basic (void)
+{
+ GtkWidget *widget;
+
+ widget = gtk_app_chooser_widget_new (NULL);
+ g_assert (GTK_IS_APP_CHOOSER_WIDGET (widget));
+ gtk_widget_destroy (widget);
+}
+
int
main (int argc, char **argv)
{
@@ -134,6 +144,7 @@ main (int argc, char **argv)
g_test_add_func ("/Template/GtkAssistant/Basic", test_assistant_basic);
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);
return g_test_run();
}
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 1cd015a..8f7d476 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/gtkappchooserwidget.ui
[type: gettext/glade]gtk/gtkassistant.ui
[type: gettext/glade]gtk/gtkdialog.ui
[type: gettext/glade]gtk/gtkinfobar.ui
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]