[gtksourceview] Completion: fix and simplify tree view sizing
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] Completion: fix and simplify tree view sizing
- Date: Thu, 21 Feb 2013 18:03:41 +0000 (UTC)
commit 545c7c462dd5a5d074ed090b5413a16b7cfcb5eb
Author: Sébastien Wilmet <swilmet gnome org>
Date: Thu Feb 21 00:37:32 2013 +0100
Completion: fix and simplify tree view sizing
This fixes the following bug:
https://bugzilla.gnome.org/show_bug.cgi?id=643179
gtksourceview/gtksourcecompletion.c | 116 +++++-----------------------------
gtksourceview/gtksourcecompletion.ui | 10 +--
2 files changed, 18 insertions(+), 108 deletions(-)
---
diff --git a/gtksourceview/gtksourcecompletion.c b/gtksourceview/gtksourcecompletion.c
index 55b6173..b49bb20 100644
--- a/gtksourceview/gtksourcecompletion.c
+++ b/gtksourceview/gtksourcecompletion.c
@@ -163,7 +163,6 @@ struct _GtkSourceCompletionPrivate
/* List of proposals */
GtkTreeView *tree_view_proposals;
GtkTreeViewColumn *tree_view_column_accelerator;
- GtkCellRenderer *cell_renderer_accelerator;
GtkCellRenderer *cell_renderer_icon;
/************************
@@ -1073,21 +1072,6 @@ show_info_after_cb (GtkWidget *widget,
gtk_label_select_region (completion->priv->default_info, 0, 0);
}
-static gint
-measure_accelerator_width (GtkWidget *widget)
-{
- PangoLayout *layout;
- PangoRectangle rect;
-
- layout = gtk_widget_create_pango_layout (widget, NULL);
- pango_layout_set_markup (layout, "<small><b>0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n</b></small>", -1);
-
- pango_layout_get_pixel_extents (layout, &rect, NULL);
- g_object_unref (layout);
-
- return rect.width;
-}
-
static gboolean
gtk_source_completion_configure_event (GtkWidget *widget,
GdkEventConfigure *event,
@@ -1102,72 +1086,14 @@ gtk_source_completion_configure_event (GtkWidget *widget,
}
static void
-set_column_width (GtkTreeView *tv,
- gint column,
- gint width)
-{
- GtkTreeViewColumn *col = gtk_tree_view_get_column (tv, column);
-
- if (width <= 0)
- {
- return;
- }
-
- if (gtk_tree_view_column_get_fixed_width (col) != width)
- {
- gtk_tree_view_column_set_fixed_width (col, width);
- }
-}
-
-static void
-update_column_sizes (GtkSourceCompletion *completion)
+update_tree_view_visibility (GtkSourceCompletion *completion)
{
- gint cwidth;
- GtkAllocation allocation;
- gint icon_width;
- gint icon_height;
-
- /* Resize tree view columns accordingly */
- if (completion->priv->num_accelerators > 0)
- {
- GtkStyleContext *context;
- gint xpad;
- gint separator;
-
- g_object_get (completion->priv->cell_renderer_accelerator,
- "xpad", &xpad,
- NULL);
-
- context = gtk_widget_get_style_context (GTK_WIDGET (completion->priv->tree_view_proposals));
- gtk_style_context_get_style (context,
- "horizontal-separator", &separator,
- NULL);
-
- cwidth = measure_accelerator_width (GTK_WIDGET (completion->priv->tree_view_proposals));
- cwidth += (xpad + separator) * 2;
- }
- else
- {
- cwidth = 0;
- }
-
- gtk_widget_get_allocation (GTK_WIDGET (completion->priv->tree_view_proposals),
- &allocation);
-
- set_column_width (completion->priv->tree_view_proposals, 0, allocation.width - cwidth);
- set_column_width (completion->priv->tree_view_proposals, 1, cwidth);
-
gtk_tree_view_column_set_visible (completion->priv->tree_view_column_accelerator,
completion->priv->num_accelerators > 0);
g_object_set (completion->priv->cell_renderer_icon,
"visible", completion->priv->show_icons,
NULL);
-
- gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &icon_width, &icon_height);
- gtk_cell_renderer_set_fixed_size (completion->priv->cell_renderer_icon,
- icon_width,
- icon_height);
}
static gboolean
@@ -1929,12 +1855,12 @@ gtk_source_completion_set_property (GObject *object,
case PROP_SHOW_ICONS:
completion->priv->show_icons = g_value_get_boolean (value);
- update_column_sizes (completion);
+ update_tree_view_visibility (completion);
break;
case PROP_ACCELERATORS:
completion->priv->num_accelerators = g_value_get_uint (value);
- update_column_sizes (completion);
+ update_tree_view_visibility (completion);
break;
case PROP_AUTO_COMPLETE_DELAY:
completion->priv->auto_complete_delay = g_value_get_uint (value);
@@ -2512,7 +2438,8 @@ initialize_tree_view (GtkSourceCompletion *completion,
{
GtkTreeSelection *selection;
GtkTreeViewColumn *column;
- GtkCellRenderer *text_cell_renderer;
+ GtkCellRenderer *cell_renderer_proposal;
+ GtkCellRenderer *cell_renderer_accelerator;
GtkStyleContext *style_context;
GdkRGBA background_color;
GdkRGBA foreground_color;
@@ -2524,20 +2451,6 @@ initialize_tree_view (GtkSourceCompletion *completion,
G_CALLBACK (gtk_source_completion_activate_proposal),
completion);
- g_signal_connect_data (completion->priv->tree_view_proposals,
- "size-allocate",
- G_CALLBACK (update_column_sizes),
- completion,
- NULL,
- G_CONNECT_AFTER | G_CONNECT_SWAPPED);
-
- g_signal_connect_data (completion->priv->tree_view_proposals,
- "style-updated",
- G_CALLBACK (update_column_sizes),
- completion,
- NULL,
- G_CONNECT_AFTER | G_CONNECT_SWAPPED);
-
/* Selection */
selection = gtk_tree_view_get_selection (completion->priv->tree_view_proposals);
@@ -2572,11 +2485,11 @@ initialize_tree_view (GtkSourceCompletion *completion,
"cell-background-rgba", &background_color,
NULL);
- /* Text cell renderer */
+ /* Proposal text cell renderer */
- text_cell_renderer = GTK_CELL_RENDERER (gtk_builder_get_object (builder, "cell_renderer_proposal"));
+ cell_renderer_proposal = GTK_CELL_RENDERER (gtk_builder_get_object (builder,
"cell_renderer_proposal"));
- gtk_tree_view_column_set_attributes (column, text_cell_renderer,
+ gtk_tree_view_column_set_attributes (column, cell_renderer_proposal,
"markup", GTK_SOURCE_COMPLETION_MODEL_COLUMN_MARKUP,
"cell-background-set",
GTK_SOURCE_COMPLETION_MODEL_COLUMN_IS_HEADER,
"foreground-set", GTK_SOURCE_COMPLETION_MODEL_COLUMN_IS_HEADER,
@@ -2586,7 +2499,7 @@ initialize_tree_view (GtkSourceCompletion *completion,
GTK_STATE_FLAG_INSENSITIVE,
&foreground_color);
- g_object_set (text_cell_renderer,
+ g_object_set (cell_renderer_proposal,
"foreground-rgba", &foreground_color,
"cell-background-rgba", &background_color,
NULL);
@@ -2596,24 +2509,25 @@ initialize_tree_view (GtkSourceCompletion *completion,
completion->priv->tree_view_column_accelerator =
GTK_TREE_VIEW_COLUMN (gtk_builder_get_object (builder, "tree_view_column_accelerator"));
- completion->priv->cell_renderer_accelerator =
- GTK_CELL_RENDERER (gtk_builder_get_object (builder, "cell_renderer_accelerator"));
+ cell_renderer_accelerator = GTK_CELL_RENDERER (gtk_builder_get_object (builder,
"cell_renderer_accelerator"));
gtk_tree_view_column_set_attributes (completion->priv->tree_view_column_accelerator,
- completion->priv->cell_renderer_accelerator,
+ cell_renderer_accelerator,
"cell-background-set",
GTK_SOURCE_COMPLETION_MODEL_COLUMN_IS_HEADER,
NULL);
- g_object_set (completion->priv->cell_renderer_accelerator,
+ g_object_set (cell_renderer_accelerator,
"foreground-rgba", &foreground_color,
"cell-background-rgba", &background_color,
NULL);
gtk_tree_view_column_set_cell_data_func (completion->priv->tree_view_column_accelerator,
- completion->priv->cell_renderer_accelerator,
+ cell_renderer_accelerator,
(GtkTreeCellDataFunc)render_proposal_accelerator_func,
completion,
NULL);
+
+ update_tree_view_visibility (completion);
}
static void
diff --git a/gtksourceview/gtksourcecompletion.ui b/gtksourceview/gtksourcecompletion.ui
index 18b627d..cbdfbb1 100644
--- a/gtksourceview/gtksourcecompletion.ui
+++ b/gtksourceview/gtksourcecompletion.ui
@@ -51,15 +51,13 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
<object class="GtkTreeView" id="tree_view_proposals">
<property name="visible">True</property>
<property name="headers_visible">False</property>
- <property name="headers_clickable">False</property>
<property name="enable_search">False</property>
- <property name="fixed_height_mode">True</property>
<property name="show_expanders">False</property>
- <property name="vexpand">True</property>
+ <property name="expand">True</property>
<child>
<object class="GtkTreeViewColumn" id="tree_view_column_proposal">
- <property name="sizing">fixed</property>
- <property name="expand">False</property>
+ <property name="expand">True</property>
+ <property name="sizing">autosize</property>
<child>
<object class="GtkCellRendererPixbuf" id="cell_renderer_icon"/>
</child>
@@ -70,8 +68,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
</child>
<child>
<object class="GtkTreeViewColumn" id="tree_view_column_accelerator">
- <property name="sizing">fixed</property>
- <property name="expand">False</property>
<child>
<object class="GtkCellRendererText" id="cell_renderer_accelerator"/>
</child>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]