[gtksourceview/wip/chergert/vim] add wrapper for marks



commit 20737b618fe253dabe7be6d937af6860bbbed4ee
Author: Christian Hergert <chergert redhat com>
Date:   Sun Nov 7 09:59:49 2021 -0800

    add wrapper for marks

 gtksourceview/vim/gtk-source-vim-state.c | 69 +++++++++++++++++++++++++++++++-
 gtksourceview/vim/gtk-source-vim-state.h |  8 ++++
 2 files changed, 76 insertions(+), 1 deletion(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-state.c b/gtksourceview/vim/gtk-source-vim-state.c
index 6da8a509..d73fcfa4 100644
--- a/gtksourceview/vim/gtk-source-vim-state.c
+++ b/gtksourceview/vim/gtk-source-vim-state.c
@@ -30,12 +30,14 @@
 #include "gtksourceview.h"
 
 #include "gtk-source-vim-registers.h"
+#include "gtk-source-vim-marks.h"
 #include "gtk-source-vim-state.h"
 
 typedef struct
 {
-       /* Owned reference to registers (usually set low in the stack) */
+       /* Owned reference to marks/registers (usually set low in the stack) */
        GtkSourceVimState *registers;
+       GtkSourceVimState *marks;
 
        /* Owned reference to the view (usually set low in the stack) */
        GtkSourceView *view;
@@ -286,6 +288,7 @@ gtk_source_vim_state_dispose (GObject *object)
 
        g_clear_weak_pointer (&priv->view);
        gtk_source_vim_state_release (&priv->registers);
+       gtk_source_vim_state_release (&priv->marks);
 
        /* First remove the children from our list */
        while (priv->children.length > 0)
@@ -1319,3 +1322,67 @@ gtk_source_vim_state_set_reverse_search (GtkSourceVimState *self,
 
        priv->reverse_search = !!reverse_search;
 }
+
+static GtkSourceVimMarks *
+gtk_source_vim_state_get_marks (GtkSourceVimState *self)
+{
+       GtkSourceVimStatePrivate *priv;
+       GtkSourceVimState *root;
+
+       g_assert (GTK_SOURCE_IS_VIM_STATE (self));
+
+       root = gtk_source_vim_state_get_root (self);
+       priv = gtk_source_vim_state_get_instance_private (root);
+
+       if (priv->marks == NULL)
+       {
+               priv->marks = gtk_source_vim_marks_new ();
+               gtk_source_vim_state_set_parent (GTK_SOURCE_VIM_STATE (priv->marks), root);
+       }
+
+       return GTK_SOURCE_VIM_MARKS (priv->marks);
+}
+
+GtkTextMark *
+gtk_source_vim_state_get_mark (GtkSourceVimState *self,
+                               const char        *name)
+{
+       GtkSourceVimMarks *marks;
+
+       g_return_val_if_fail (GTK_SOURCE_IS_VIM_STATE (self), NULL);
+       g_return_val_if_fail (name != NULL, NULL);
+
+       marks = gtk_source_vim_state_get_marks (self);
+
+       return gtk_source_vim_marks_get_mark (marks, name);
+}
+
+void
+gtk_source_vim_state_set_mark (GtkSourceVimState *self,
+                               const char        *name,
+                               const GtkTextIter *iter)
+{
+       GtkSourceVimMarks *marks;
+
+       g_return_if_fail (GTK_SOURCE_IS_VIM_STATE (self));
+       g_return_if_fail (name != NULL);
+
+       marks = gtk_source_vim_state_get_marks (self);
+
+       return gtk_source_vim_marks_set_mark (marks, name, iter);
+}
+
+gboolean
+gtk_source_vim_state_get_iter_at_mark (GtkSourceVimState *self,
+                                       const char        *name,
+                                       GtkTextIter       *iter)
+{
+       GtkSourceVimMarks *marks;
+
+       g_return_val_if_fail (GTK_SOURCE_IS_VIM_STATE (self), FALSE);
+       g_return_val_if_fail (name != NULL, FALSE);
+
+       marks = gtk_source_vim_state_get_marks (self);
+
+       return gtk_source_vim_marks_get_iter (marks, name, iter);
+}
diff --git a/gtksourceview/vim/gtk-source-vim-state.h b/gtksourceview/vim/gtk-source-vim-state.h
index 13efe80a..3ecce7d9 100644
--- a/gtksourceview/vim/gtk-source-vim-state.h
+++ b/gtksourceview/vim/gtk-source-vim-state.h
@@ -124,6 +124,14 @@ void               gtk_source_vim_state_get_search                 (GtkSourceVim
 gboolean           gtk_source_vim_state_get_reverse_search         (GtkSourceVimState        *self);
 void               gtk_source_vim_state_set_reverse_search         (GtkSourceVimState        *self,
                                                                     gboolean                  
reverse_search);
+GtkTextMark       *gtk_source_vim_state_get_mark                   (GtkSourceVimState        *self,
+                                                                    const char               *name);
+void               gtk_source_vim_state_set_mark                   (GtkSourceVimState        *self,
+                                                                   const char               *name,
+                                                                   const GtkTextIter        *iter);
+gboolean           gtk_source_vim_state_get_iter_at_mark           (GtkSourceVimState        *self,
+                                                                   const char               *name,
+                                                                   GtkTextIter              *iter);
 void               gtk_source_vim_state_keyval_to_string           (guint                     keyval,
                                                                     GdkModifierType           mods,
                                                                     char                      string[16]);


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