[gtk+/composite-templates-new: 13/15] GtkAppChooserWidget: Define GtkTreeStore and cell renderers with the GtkBuilder template
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/composite-templates-new: 13/15] GtkAppChooserWidget: Define GtkTreeStore and cell renderers with the GtkBuilder template
- Date: Sat, 23 Mar 2013 15:43:04 +0000 (UTC)
commit 81a9f4e6439cbbed8eea10b97e1757f4399c15dd
Author: Tristan Van Berkom <tristanvb openismus com>
Date: Sat Mar 23 22:20:54 2013 +0900
GtkAppChooserWidget: Define GtkTreeStore and cell renderers with the GtkBuilder template
This is in a separate commit as the implementation may be delicate.
gtk/gtkappchooserwidget.c | 122 +++++++++++++-------------------------------
1 files changed, 36 insertions(+), 86 deletions(-)
---
diff --git a/gtk/gtkappchooserwidget.c b/gtk/gtkappchooserwidget.c
index c32bf04..0ec0747 100644
--- a/gtk/gtkappchooserwidget.c
+++ b/gtk/gtkappchooserwidget.c
@@ -82,7 +82,9 @@ struct _GtkAppChooserWidgetPrivate {
GtkWidget *program_list;
GtkListStore *program_list_store;
+ GtkTreeViewColumn *column;
GtkCellRenderer *padding_renderer;
+ GtkCellRenderer *secondary_padding;
};
enum {
@@ -799,95 +801,12 @@ gtk_app_chooser_widget_real_add_items (GtkAppChooserWidget *self)
}
static void
-gtk_app_chooser_widget_add_items (GtkAppChooserWidget *self)
+gtk_app_chooser_widget_initialize_items (GtkAppChooserWidget *self)
{
- GtkCellRenderer *renderer;
- GtkTreeViewColumn *column;
- GtkTreeModel *sort;
-
- /* create list store */
- self->priv->program_list_store = gtk_list_store_new (NUM_COLUMNS,
- G_TYPE_APP_INFO,
- G_TYPE_ICON,
- G_TYPE_STRING,
- G_TYPE_STRING,
- G_TYPE_STRING,
- G_TYPE_BOOLEAN,
- G_TYPE_BOOLEAN,
- G_TYPE_STRING,
- G_TYPE_BOOLEAN,
- G_TYPE_BOOLEAN);
- sort = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (self->priv->program_list_store));
-
- gtk_tree_view_set_model (GTK_TREE_VIEW (self->priv->program_list),
- GTK_TREE_MODEL (sort));
- gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort),
- COLUMN_NAME,
- GTK_SORT_ASCENDING);
- gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (sort),
- COLUMN_NAME,
- gtk_app_chooser_sort_func,
- self, NULL);
- gtk_tree_view_set_search_column (GTK_TREE_VIEW (self->priv->program_list),
- COLUMN_NAME);
- gtk_tree_view_set_search_equal_func (GTK_TREE_VIEW (self->priv->program_list),
- gtk_app_chooser_search_equal_func,
- NULL, NULL);
-
- column = gtk_tree_view_column_new ();
-
/* initial padding */
- renderer = gtk_cell_renderer_text_new ();
- gtk_tree_view_column_pack_start (column, renderer, FALSE);
- g_object_set (renderer,
+ g_object_set (self->priv->padding_renderer,
"xpad", self->priv->show_all ? 0 : 6,
NULL);
- self->priv->padding_renderer = renderer;
-
- /* heading text renderer */
- renderer = gtk_cell_renderer_text_new ();
- gtk_tree_view_column_pack_start (column, renderer, FALSE);
- gtk_tree_view_column_set_attributes (column, renderer,
- "markup", COLUMN_HEADING_TEXT,
- "visible", COLUMN_HEADING,
- NULL);
- g_object_set (renderer,
- "ypad", 6,
- "xpad", 0,
- "wrap-width", 350,
- "wrap-mode", PANGO_WRAP_WORD,
- NULL);
-
- /* padding renderer for non-heading cells */
- renderer = gtk_cell_renderer_text_new ();
- gtk_tree_view_column_pack_start (column, renderer, FALSE);
- gtk_tree_view_column_set_cell_data_func (column, renderer,
- padding_cell_renderer_func,
- NULL, NULL);
-
- /* app icon renderer */
- renderer = gtk_cell_renderer_pixbuf_new ();
- gtk_tree_view_column_pack_start (column, renderer, FALSE);
- gtk_tree_view_column_set_attributes (column, renderer,
- "gicon", COLUMN_GICON,
- NULL);
- g_object_set (renderer,
- "stock-size", GTK_ICON_SIZE_MENU,
- NULL);
-
- /* app name renderer */
- renderer = gtk_cell_renderer_text_new ();
- gtk_tree_view_column_pack_start (column, renderer, TRUE);
- gtk_tree_view_column_set_attributes (column, renderer,
- "markup", COLUMN_DESC,
- NULL);
- g_object_set (renderer,
- "ellipsize", PANGO_ELLIPSIZE_END,
- "ellipsize-set", TRUE,
- NULL);
-
- gtk_tree_view_column_set_sort_column_id (column, COLUMN_NAME);
- gtk_tree_view_append_column (GTK_TREE_VIEW (self->priv->program_list), column);
/* populate the widget */
gtk_app_chooser_widget_real_add_items (self);
@@ -975,7 +894,7 @@ gtk_app_chooser_widget_constructed (GObject *object)
if (G_OBJECT_CLASS (gtk_app_chooser_widget_parent_class)->constructed != NULL)
G_OBJECT_CLASS (gtk_app_chooser_widget_parent_class)->constructed (object);
- gtk_app_chooser_widget_add_items (self);
+ gtk_app_chooser_widget_initialize_items (self);
}
static void
@@ -1168,6 +1087,14 @@ gtk_app_chooser_widget_class_init (GtkAppChooserWidgetClass *klass)
"/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_automate_child (container_class, "program_list_store", FALSE,
GTK_AUTOMATE_CHILD_PRIVATE,
+ G_STRUCT_OFFSET (GtkAppChooserWidgetPrivate, program_list_store));
+ gtk_container_class_automate_child (container_class, "column", FALSE, GTK_AUTOMATE_CHILD_PRIVATE,
+ G_STRUCT_OFFSET (GtkAppChooserWidgetPrivate, column));
+ gtk_container_class_automate_child (container_class, "padding_renderer", FALSE, GTK_AUTOMATE_CHILD_PRIVATE,
+ G_STRUCT_OFFSET (GtkAppChooserWidgetPrivate, padding_renderer));
+ gtk_container_class_automate_child (container_class, "secondary_padding", FALSE,
GTK_AUTOMATE_CHILD_PRIVATE,
+ G_STRUCT_OFFSET (GtkAppChooserWidgetPrivate, secondary_padding));
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,
@@ -1181,15 +1108,38 @@ static void
gtk_app_chooser_widget_init (GtkAppChooserWidget *self)
{
GtkTreeSelection *selection;
+ GtkTreeModel *sort;
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTK_TYPE_APP_CHOOSER_WIDGET,
GtkAppChooserWidgetPrivate);
gtk_container_init_template (GTK_CONTAINER (self));
+ /* Various parts of the GtkTreeView code need custom code to setup, mostly
+ * because we lack signals to connect to, or properties to set.
+ */
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (self->priv->program_list));
gtk_tree_selection_set_select_function (selection, gtk_app_chooser_selection_func,
self, NULL);
+
+ sort = gtk_tree_view_get_model (GTK_TREE_VIEW (self->priv->program_list));
+ gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort),
+ COLUMN_NAME,
+ GTK_SORT_ASCENDING);
+ gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (sort),
+ COLUMN_NAME,
+ gtk_app_chooser_sort_func,
+ self, NULL);
+
+ gtk_tree_view_set_search_column (GTK_TREE_VIEW (self->priv->program_list), COLUMN_NAME);
+ gtk_tree_view_set_search_equal_func (GTK_TREE_VIEW (self->priv->program_list),
+ gtk_app_chooser_search_equal_func,
+ NULL, NULL);
+
+ gtk_tree_view_column_set_cell_data_func (self->priv->column,
+ self->priv->secondary_padding,
+ padding_cell_renderer_func,
+ NULL, NULL);
}
static GAppInfo *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]