[gnome-builder/wip/libide: 68/153] sourceview: add jump-notify signal



commit 23921398e017078f0766da6ba999032d9a6dce20
Author: Christian Hergert <christian hergert me>
Date:   Wed Feb 11 11:10:28 2015 -0800

    sourceview: add jump-notify signal
    
    This signal should be emitted by features that move the cursor around in
    a way that should be interprited as a "jump". Jumps will be pushed into
    the navigation stack so that we can navigate through the jump history.

 src/editor/gb-source-view.c |   28 +++++++++++++++++++++++
 src/editor/gb-source-view.h |   35 +++++++++++++++-------------
 src/vim/gb-source-vim.c     |   52 +++++++++++++++++++++++++++++++++++++++---
 3 files changed, 95 insertions(+), 20 deletions(-)
---
diff --git a/src/editor/gb-source-view.c b/src/editor/gb-source-view.c
index 4268105..c05b301 100644
--- a/src/editor/gb-source-view.c
+++ b/src/editor/gb-source-view.c
@@ -107,6 +107,7 @@ enum {
   BEGIN_SEARCH,
   DISPLAY_DOCUMENTATION,
   DRAW_LAYER,
+  JUMP_NOTIFY,
   POP_SNIPPET,
   PUSH_SNIPPET,
   REQUEST_DOCUMENTATION,
@@ -117,6 +118,22 @@ enum {
 static GParamSpec *gParamSpecs [LAST_PROP];
 static guint       gSignals [LAST_SIGNAL];
 
+void
+gb_source_view_jump_notify (GbSourceView *self)
+{
+  GtkTextBuffer *buffer;
+  GtkTextMark *mark;
+  GtkTextIter iter;
+
+  g_return_if_fail (GB_IS_SOURCE_VIEW (self));
+
+  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self));
+  mark = gtk_text_buffer_get_insert (buffer);
+  gtk_text_buffer_get_iter_at_mark (buffer, &iter, mark);
+
+  g_signal_emit (self, gSignals [JUMP_NOTIFY], 0, &iter);
+}
+
 GbSourceVim *
 gb_source_view_get_vim (GbSourceView *view)
 {
@@ -2372,6 +2389,17 @@ gb_source_view_class_init (GbSourceViewClass *klass)
                   1,
                   G_TYPE_STRV);
 
+  gSignals [JUMP_NOTIFY] =
+    g_signal_new ("jump-notify",
+                  GB_TYPE_SOURCE_VIEW,
+                  G_SIGNAL_RUN_LAST,
+                  G_STRUCT_OFFSET (GbSourceViewClass, jump_notify),
+                  NULL, NULL,
+                  g_cclosure_marshal_generic,
+                  G_TYPE_NONE,
+                  1,
+                  GTK_TYPE_TEXT_ITER);
+
   binding_set = gtk_binding_set_by_class (klass);
   gtk_binding_entry_add_signal (binding_set,
                                 GDK_KEY_k,
diff --git a/src/editor/gb-source-view.h b/src/editor/gb-source-view.h
index c4a2869..6c139c3 100644
--- a/src/editor/gb-source-view.h
+++ b/src/editor/gb-source-view.h
@@ -51,23 +51,25 @@ struct _GbSourceViewClass
 {
   GtkSourceViewClass parent_class;
 
-  void (*push_snippet)          (GbSourceView           *view,
-                                GbSourceSnippet        *snippet,
-                                GbSourceSnippetContext *context,
-                                GtkTextIter            *location);
-  void (*pop_snippet)           (GbSourceView           *view,
-                                GbSourceSnippet        *snippet);
-  void (*begin_search)          (GbSourceView           *view,
-                                GtkDirectionType        direction,
-                                const gchar            *search_text);
-  void (*draw_layer)            (GbSourceView           *view,
-                                 GtkTextViewLayer        layer,
-                                 cairo_t                *cr);
-  void (*request_documentation) (GbSourceView           *view);
-  void (*display_documentation) (GbSourceView           *view,
-                                 const gchar            *search_text);
-  void (*drop_uris)             (GbSourceViewClass      *view,
+  void (*push_snippet)          (GbSourceView            *view,
+                                 GbSourceSnippet         *snippet,
+                                 GbSourceSnippetContext  *context,
+                                 GtkTextIter             *location);
+  void (*pop_snippet)           (GbSourceView            *view,
+                                 GbSourceSnippet         *snippet);
+  void (*begin_search)          (GbSourceView            *view,
+                                 GtkDirectionType         direction,
+                                 const gchar             *search_text);
+  void (*draw_layer)            (GbSourceView            *view,
+                                 GtkTextViewLayer         layer,
+                                 cairo_t                 *cr);
+  void (*request_documentation) (GbSourceView            *view);
+  void (*display_documentation) (GbSourceView            *view,
+                                 const gchar             *search_text);
+  void (*drop_uris)             (GbSourceView            *view,
                                  const gchar            **uri_list);
+  void (*jump_notify)           (GbSourceView            *view,
+                                 GtkTextIter             *location);
 };
 
 void                  gb_source_view_begin_search         (GbSourceView         *view,
@@ -88,6 +90,7 @@ void                  gb_source_view_set_overwrite_braces (GbSourceView
 void                  gb_source_view_set_show_shadow      (GbSourceView         *view,
                                                            gboolean              show_shadow);
 GbSourceVim          *gb_source_view_get_vim              (GbSourceView         *view);
+void                  gb_source_view_jump_notify          (GbSourceView         *view);
 
 G_END_DECLS
 
diff --git a/src/vim/gb-source-vim.c b/src/vim/gb-source-vim.c
index ff28e2d..28ee792 100644
--- a/src/vim/gb-source-vim.c
+++ b/src/vim/gb-source-vim.c
@@ -617,6 +617,15 @@ gb_source_vim_set_mode (GbSourceVim     *vim,
   else if (vim->priv->mode == GB_SOURCE_VIM_INSERT)
     gtk_text_buffer_end_user_action (buffer);
 
+#ifndef GB_SOURCE_VIM_EXTERNAL
+  /*
+   * If we are entering insert mode, let's mark this spot as a jump so we can
+   * come back to it later.
+   */
+  if (GB_IS_SOURCE_VIEW (vim->priv->text_view))
+    gb_source_view_jump_notify (GB_SOURCE_VIEW (vim->priv->text_view));
+#endif
+
   vim->priv->mode = mode;
 
   /*
@@ -1327,7 +1336,7 @@ bracket_predicate (gunichar ch,
   return (state->depth == 0);
 }
 
-static void
+static gboolean
 gb_source_vim_move_matching_bracket (GbSourceVim *vim)
 {
   MatchingBracketState state;
@@ -1338,7 +1347,7 @@ gb_source_vim_move_matching_bracket (GbSourceVim *vim)
   gboolean is_forward;
   gboolean ret;
 
-  g_return_if_fail (GB_IS_SOURCE_VIM (vim));
+  g_return_val_if_fail (GB_IS_SOURCE_VIM (vim), FALSE);
 
   buffer = gtk_text_view_get_buffer (vim->priv->text_view);
   has_selection = gb_source_vim_get_selection_bounds (vim, &iter, &selection);
@@ -1379,7 +1388,7 @@ gb_source_vim_move_matching_bracket (GbSourceVim *vim)
       break;
 
     default:
-      return;
+      return FALSE;
     }
 
   if (is_forward)
@@ -1402,7 +1411,11 @@ gb_source_vim_move_matching_bracket (GbSourceVim *vim)
         gtk_text_buffer_select_range (buffer, &iter, &iter);
 
       gb_source_vim_ensure_scroll (vim);
+
+      return TRUE;
     }
+
+  return FALSE;
 }
 
 static gboolean
@@ -4211,6 +4224,11 @@ gb_source_vim_op_goto_line (GbSourceVim *vim,
       line = line > 0 ? line - 1 : 0;
 
       gb_source_vim_move_to_line_n (vim, line);
+
+#ifndef GB_SOURCE_VIM_EXTERNAL
+      if (GB_IS_SOURCE_VIEW (vim->priv->text_view))
+        gb_source_view_jump_notify (GB_SOURCE_VIEW (vim->priv->text_view));
+#endif
     }
 }
 
@@ -4711,6 +4729,11 @@ gb_source_vim_cmd_match_backward (GbSourceVim *vim,
 
   for (i = 0; i < count; i++)
     gb_source_vim_reverse_search (vim);
+
+#ifndef GB_SOURCE_VIM_EXTERNAL
+  if (GB_IS_SOURCE_VIEW (vim->priv->text_view))
+    gb_source_view_jump_notify (GB_SOURCE_VIEW (vim->priv->text_view));
+#endif
 }
 
 static void
@@ -4726,6 +4749,11 @@ gb_source_vim_cmd_match_forward (GbSourceVim *vim,
 
   for (i = 0; i < count; i++)
     gb_source_vim_search (vim);
+
+#ifndef GB_SOURCE_VIM_EXTERNAL
+  if (GB_IS_SOURCE_VIEW (vim->priv->text_view))
+    gb_source_view_jump_notify (GB_SOURCE_VIEW (vim->priv->text_view));
+#endif
 }
 
 static void
@@ -5161,6 +5189,11 @@ gb_source_vim_cmd_repeat_search_reverse (GbSourceVim *vim,
 
   for (i = 0; i < count; i++)
     gb_source_vim_repeat_search (vim, search_direction);
+
+#ifndef GB_SOURCE_VIM_EXTERNAL
+  if (GB_IS_SOURCE_VIM (vim->priv->text_view))
+    gb_source_view_jump_notify (GB_SOURCE_VIEW (vim->priv->text_view));
+#endif
 }
 
 static void
@@ -5176,6 +5209,11 @@ gb_source_vim_cmd_repeat_search (GbSourceVim *vim,
 
   for (i = 0; i < count; i++)
     gb_source_vim_repeat_search (vim, vim->priv->search_direction);
+
+#ifndef GB_SOURCE_VIM_EXTERNAL
+  if (GB_IS_SOURCE_VIM (vim->priv->text_view))
+    gb_source_view_jump_notify (GB_SOURCE_VIEW (vim->priv->text_view));
+#endif
 }
 
 static void
@@ -5562,7 +5600,13 @@ gb_source_vim_cmd_matching_bracket (GbSourceVim *vim,
     case ']':
     case '(':
     case ')':
-      gb_source_vim_move_matching_bracket (vim);
+      if (gb_source_vim_move_matching_bracket (vim))
+        {
+#ifndef GB_SOURCE_VIM_EXTERNAL
+          if (GB_IS_SOURCE_VIEW (vim->priv->text_view))
+            gb_source_view_jump_notify (GB_SOURCE_VIEW (vim->priv->text_view));
+#endif
+        }
       break;
 
     default:


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