[gtksourceview/wip/chergert/gsv-gtk4: 172/197] gutter: ensure we always have access to the view
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/gsv-gtk4: 172/197] gutter: ensure we always have access to the view
- Date: Tue, 2 Jun 2020 18:51:30 +0000 (UTC)
commit 410301a0a2393c4548171a0aeeb25ba62416f075
Author: Christian Hergert <chergert redhat com>
Date: Fri Mar 27 14:51:34 2020 -0700
gutter: ensure we always have access to the view
This fixes an issue when creating a sourceview with :show-line-numbers
set initially. This happened because we did not root the widget until
much later.
gtksourceview/gtksourcegutter-private.h | 3 ++-
gtksourceview/gtksourcegutter.c | 32 +++++++++-----------------------
gtksourceview/gtksourceview.c | 4 ++--
3 files changed, 13 insertions(+), 26 deletions(-)
---
diff --git a/gtksourceview/gtksourcegutter-private.h b/gtksourceview/gtksourcegutter-private.h
index de5b9686..0d0c0006 100644
--- a/gtksourceview/gtksourcegutter-private.h
+++ b/gtksourceview/gtksourcegutter-private.h
@@ -26,7 +26,8 @@
G_BEGIN_DECLS
G_GNUC_INTERNAL
-GtkSourceGutter *_gtk_source_gutter_new (GtkTextWindowType type);
+GtkSourceGutter *_gtk_source_gutter_new (GtkTextWindowType type,
+ GtkSourceView *view);
G_GNUC_INTERNAL
GtkSourceGutterLines *_gtk_source_gutter_get_lines (GtkSourceGutter *gutter);
G_GNUC_INTERNAL
diff --git a/gtksourceview/gtksourcegutter.c b/gtksourceview/gtksourcegutter.c
index 124015e2..2b311a5e 100644
--- a/gtksourceview/gtksourcegutter.c
+++ b/gtksourceview/gtksourcegutter.c
@@ -360,24 +360,6 @@ apply_style (GtkSourceGutter *gutter,
gtk_style_context_add_class (style_context, class);
}
-static void
-gtk_source_gutter_root (GtkWidget *widget)
-{
- GtkWidget *view;
-
- GTK_WIDGET_CLASS (gtk_source_gutter_parent_class)->root (widget);
-
- view = gtk_widget_get_ancestor (widget, GTK_SOURCE_TYPE_VIEW);
- set_view (GTK_SOURCE_GUTTER (widget), GTK_SOURCE_VIEW (view));
-}
-
-static void
-gtk_source_gutter_unroot (GtkWidget *widget)
-{
- GTK_WIDGET_CLASS (gtk_source_gutter_parent_class)->unroot (widget);
- set_view (GTK_SOURCE_GUTTER (widget), NULL);
-}
-
static void
gtk_source_gutter_forall (GtkContainer *container,
GtkCallback callback,
@@ -410,6 +392,10 @@ gtk_source_gutter_set_property (GObject *object,
gutter->window_type = g_value_get_enum (value);
break;
+ case PROP_VIEW:
+ set_view (gutter, g_value_get_object (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -453,10 +439,8 @@ gtk_source_gutter_class_init (GtkSourceGutterClass *klass)
widget_class->map = gtk_source_gutter_map;
widget_class->measure = gtk_source_gutter_measure;
- widget_class->root = gtk_source_gutter_root;
widget_class->size_allocate = gtk_source_gutter_size_allocate;
widget_class->snapshot = gtk_source_gutter_snapshot;
- widget_class->unroot = gtk_source_gutter_unroot;
container_class->forall = gtk_source_gutter_forall;
container_class->add = gtk_source_gutter_add;
@@ -473,7 +457,7 @@ gtk_source_gutter_class_init (GtkSourceGutterClass *klass)
"View",
"",
GTK_SOURCE_TYPE_VIEW,
- G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
/**
* GtkSourceGutter:window-type:
@@ -555,10 +539,12 @@ append_renderer (GtkSourceGutter *gutter,
}
GtkSourceGutter *
-_gtk_source_gutter_new (GtkTextWindowType type)
+_gtk_source_gutter_new (GtkTextWindowType type,
+ GtkSourceView *view)
{
return g_object_new (GTK_SOURCE_TYPE_GUTTER,
- "window_type", type,
+ "window-type", type,
+ "view", view,
NULL);
}
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index 7ea65139..e04f305b 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -4711,7 +4711,7 @@ gtk_source_view_get_gutter (GtkSourceView *view,
{
if (priv->left_gutter == NULL)
{
- priv->left_gutter = _gtk_source_gutter_new (window_type);
+ priv->left_gutter = _gtk_source_gutter_new (window_type, view);
gtk_text_view_set_gutter (GTK_TEXT_VIEW (view),
GTK_TEXT_WINDOW_LEFT,
GTK_WIDGET (priv->left_gutter));
@@ -4725,7 +4725,7 @@ gtk_source_view_get_gutter (GtkSourceView *view,
{
if (priv->right_gutter == NULL)
{
- priv->right_gutter = _gtk_source_gutter_new (window_type);
+ priv->right_gutter = _gtk_source_gutter_new (window_type, view);
gtk_text_view_set_gutter (GTK_TEXT_VIEW (view),
GTK_TEXT_WINDOW_RIGHT,
GTK_WIDGET (priv->right_gutter));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]