[gtksourceview/wip/chergert/vim: 37/73] add view_set helper to avoid constructed




commit de99df53e7fb3bdede5de5925d2fb1c422ce9b41
Author: Christian Hergert <chergert redhat com>
Date:   Fri Oct 22 11:28:59 2021 -0700

    add view_set helper to avoid constructed

 gtksourceview/vim/gtk-source-vim-state.c |  6 ++++++
 gtksourceview/vim/gtk-source-vim-state.h |  1 +
 gtksourceview/vim/gtk-source-vim.c       | 11 +++++------
 3 files changed, 12 insertions(+), 6 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-state.c b/gtksourceview/vim/gtk-source-vim-state.c
index 23337d59..4b00644f 100644
--- a/gtksourceview/vim/gtk-source-vim-state.c
+++ b/gtksourceview/vim/gtk-source-vim-state.c
@@ -193,6 +193,12 @@ gtk_source_vim_state_set_property (GObject      *object,
 
                case PROP_VIEW:
                        g_set_weak_pointer (&priv->view, g_value_get_object (value));
+
+                       if (GTK_SOURCE_VIM_STATE_GET_CLASS (self)->view_set)
+                       {
+                               GTK_SOURCE_VIM_STATE_GET_CLASS (self)->view_set (self);
+                       }
+
                        break;
 
                default:
diff --git a/gtksourceview/vim/gtk-source-vim-state.h b/gtksourceview/vim/gtk-source-vim-state.h
index 9ecf80b2..206cf303 100644
--- a/gtksourceview/vim/gtk-source-vim-state.h
+++ b/gtksourceview/vim/gtk-source-vim-state.h
@@ -35,6 +35,7 @@ struct _GtkSourceVimStateClass
 {
        GObjectClass parent_class;
 
+       void     (*view_set)        (GtkSourceVimState *state);
        void     (*enter)           (GtkSourceVimState *state);
        void     (*suspend)         (GtkSourceVimState *state,
                                     GtkSourceVimState *to);
diff --git a/gtksourceview/vim/gtk-source-vim.c b/gtksourceview/vim/gtk-source-vim.c
index 1ec87368..306ac300 100644
--- a/gtksourceview/vim/gtk-source-vim.c
+++ b/gtksourceview/vim/gtk-source-vim.c
@@ -75,13 +75,12 @@ gtk_source_vim_handle_event (GtkSourceVimState *state,
 }
 
 static void
-gtk_source_vim_constructed (GObject *object)
+gtk_source_vim_view_set (GtkSourceVimState *state)
 {
-       GtkSourceVim *self = (GtkSourceVim *)object;
-
-       G_OBJECT_CLASS (gtk_source_vim_parent_class)->constructed (object);
+       g_assert (GTK_SOURCE_IS_VIM (state));
+       g_assert (gtk_source_vim_state_get_child (state) == NULL);
 
-       gtk_source_vim_state_push (GTK_SOURCE_VIM_STATE (self), gtk_source_vim_normal_new ());
+       gtk_source_vim_state_push (state, gtk_source_vim_normal_new ());
 }
 
 static void
@@ -113,10 +112,10 @@ gtk_source_vim_class_init (GtkSourceVimClass *klass)
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
        GtkSourceVimStateClass *state_class = GTK_SOURCE_VIM_STATE_CLASS (klass);
 
-       object_class->constructed = gtk_source_vim_constructed;
        object_class->get_property = gtk_source_vim_get_property;
 
        state_class->handle_event = gtk_source_vim_handle_event;
+       state_class->view_set = gtk_source_vim_view_set;
 
        properties [PROP_COMMAND_TEXT] =
                g_param_spec_string ("command-text",


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]