[gtksourceview/wip/chergert/gsv-gtk4] completion: use extra treeview for styling
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/gsv-gtk4] completion: use extra treeview for styling
- Date: Tue, 17 Mar 2020 17:04:05 +0000 (UTC)
commit b291f74568183b9153acf989d126510fcc427175
Author: Christian Hergert <chergert redhat com>
Date: Tue Mar 17 10:03:46 2020 -0700
completion: use extra treeview for styling
We don't want this long term, but for now we can use it to get the theme
information out without too much trouble.
Long term, this will all be replaced with a new completion API that is
based on GListModel, so this is mostly just temporary.
gtksourceview/gtksourcecompletion.c | 49 ++++++++++++++++++++----------------
gtksourceview/gtksourcecompletion.ui | 3 +++
2 files changed, 30 insertions(+), 22 deletions(-)
---
diff --git a/gtksourceview/gtksourcecompletion.c b/gtksourceview/gtksourcecompletion.c
index 6bce5012..d342e8a3 100644
--- a/gtksourceview/gtksourcecompletion.c
+++ b/gtksourceview/gtksourcecompletion.c
@@ -156,6 +156,9 @@ struct _GtkSourceCompletion
GtkImage *selection_image;
GtkLabel *selection_label;
+ /* Used for insensitive styling */
+ GtkTreeView *insensitive;
+
/* The default widget for the info window */
GtkLabel *default_info;
@@ -1568,16 +1571,16 @@ static void
style_context_changed (GtkStyleContext *style_context,
GtkSourceCompletion *completion)
{
- PangoFontDescription *font_desc = NULL;
-
- gtk_style_context_save (style_context);
- gtk_style_context_set_state (style_context, GTK_STATE_FLAG_NORMAL);
+ PangoFontDescription *font_desc;
+ PangoContext *context;
- gtk_style_context_get (style_context,
- GTK_STYLE_PROPERTY_FONT, &font_desc,
- NULL);
+ if (completion->view == NULL)
+ {
+ return;
+ }
- gtk_style_context_restore (style_context);
+ context = gtk_widget_get_pango_context (GTK_WIDGET (completion->view));
+ font_desc = pango_context_get_font_description (context);
/*
* Work around issue where when a proposal provides "<b>markup</b>" and
@@ -1591,14 +1594,19 @@ style_context_changed (GtkStyleContext *style_context,
*/
if (PANGO_WEIGHT_NORMAL == pango_font_description_get_weight (font_desc))
{
+ font_desc = pango_font_description_copy (font_desc);
pango_font_description_unset_fields (font_desc, PANGO_FONT_MASK_WEIGHT);
+ g_object_set (completion->cell_renderer_proposal,
+ "font-desc", font_desc,
+ NULL);
+ pango_font_description_free (font_desc);
+ }
+ else
+ {
+ g_object_set (completion->cell_renderer_proposal,
+ "font-desc", font_desc,
+ NULL);
}
-
- g_object_set (completion->cell_renderer_proposal,
- "font-desc", font_desc,
- NULL);
-
- pango_font_description_free (font_desc);
}
static void
@@ -2032,6 +2040,7 @@ init_tree_view (GtkSourceCompletion *completion,
GdkRGBA* background_color = NULL;
GdkRGBA foreground_color;
+ completion->insensitive = GTK_TREE_VIEW (gtk_builder_get_object (builder, "insensitive"));
completion->tree_view_proposals = GTK_TREE_VIEW (gtk_builder_get_object (builder,
"tree_view_proposals"));
g_signal_connect_swapped (completion->tree_view_proposals,
@@ -2078,19 +2087,15 @@ init_tree_view (GtkSourceCompletion *completion,
"cell-background-set",
GTK_SOURCE_COMPLETION_MODEL_COLUMN_IS_HEADER,
NULL);
- style_context = gtk_widget_get_style_context (GTK_WIDGET (completion->tree_view_proposals));
-
- gtk_style_context_save (style_context);
- gtk_style_context_set_state (style_context, GTK_STATE_FLAG_INSENSITIVE);
-
+ /* Get styling for insensitive cell background. Ideally this will all
+ * go away with a widget'ized form of completion before GTK 4.
+ */
+ style_context = gtk_widget_get_style_context (GTK_WIDGET (completion->insensitive));
gtk_style_context_get (style_context,
"background-color", &background_color,
NULL);
-
gtk_style_context_get_color (style_context, &foreground_color);
- gtk_style_context_restore (style_context);
-
g_object_set (cell_renderer,
"cell-background-rgba", background_color,
NULL);
diff --git a/gtksourceview/gtksourcecompletion.ui b/gtksourceview/gtksourcecompletion.ui
index 7de346ce..2a2fce81 100644
--- a/gtksourceview/gtksourcecompletion.ui
+++ b/gtksourceview/gtksourcecompletion.ui
@@ -118,4 +118,7 @@ along with this library; if not, see <http://www.gnu.org/licenses/>.
</object>
</child>
</object>
+ <object class="GtkTreeView" id="insensitive">
+ <property name="sensitive">False</property>
+ </object>
</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]