[gnome-builder] ide-source-view: add save-command css binding



commit dfdead66d0366257ffce70bb03726d46acfc642d
Author: Sebastien Lafargue <slafargue gnome org>
Date:   Mon Oct 12 19:51:03 2015 +0200

    ide-source-view: add save-command css binding
    
    We can now use "save-command" in css binding to remember the current
    command so we can get it later in priv->command.
    It's required by Vim mode when some commands rely on contextual
    informations from a previous command.
    
    It works by recording the current GdkEvent pressed key so you need
    to put it at the start of your binding to work.
    
    The command is also passed to _ide_source_view_apply_movement ()
    movements dispatcher.

 libide/ide-source-view-movements.c |    3 +++
 libide/ide-source-view-movements.h |    1 +
 libide/ide-source-view.c           |   33 +++++++++++++++++++++++++++++++--
 libide/ide-source-view.h           |    1 +
 4 files changed, 36 insertions(+), 2 deletions(-)
---
diff --git a/libide/ide-source-view-movements.c b/libide/ide-source-view-movements.c
index 297f14e..ebcffa3 100644
--- a/libide/ide-source-view-movements.c
+++ b/libide/ide-source-view-movements.c
@@ -45,6 +45,7 @@ typedef struct
   GtkTextIter            insert;                      /* Current insert cursor location */
   GtkTextIter            selection;                   /* Current selection cursor location */
   gint                   count;                       /* Repeat count for movement */
+  gunichar               command;                     /* Command that trigger some movements type. See , and 
; in vim */
   gunichar               modifier;                    /* For forward/backward char search */
   guint                  extend_selection : 1;        /* If selection should be extended */
   guint                  exclusive : 1;               /* See ":help exclusive" in vim */
@@ -1246,6 +1247,7 @@ _ide_source_view_apply_movement (IdeSourceView         *self,
                                  gboolean               extend_selection,
                                  gboolean               exclusive,
                                  guint                  count,
+                                 gunichar               command,
                                  gunichar               modifier,
                                  gint                  *target_offset)
 {
@@ -1283,6 +1285,7 @@ _ide_source_view_apply_movement (IdeSourceView         *self,
   mv.count = count;
   mv.ignore_select = FALSE;
   mv.ignore_target_offset = FALSE;
+  mv.command = command;
   mv.modifier = modifier;
 
   ide_source_view_movements_get_selection (&mv);
diff --git a/libide/ide-source-view-movements.h b/libide/ide-source-view-movements.h
index f11ef78..cb1106d 100644
--- a/libide/ide-source-view-movements.h
+++ b/libide/ide-source-view-movements.h
@@ -28,6 +28,7 @@ void _ide_source_view_apply_movement (IdeSourceView         *source_view,
                                       gboolean               extend_selection,
                                       gboolean               exclusive,
                                       guint                  count,
+                                      gunichar               command,
                                       gunichar               modifier,
                                       gint                  *target_offset);
 
diff --git a/libide/ide-source-view.c b/libide/ide-source-view.c
index 5710779..f0673c4 100644
--- a/libide/ide-source-view.c
+++ b/libide/ide-source-view.c
@@ -116,6 +116,7 @@ typedef struct
   guint                        change_sequence;
 
   gint                         target_line_offset;
+  gunichar                     command;
   gunichar                     modifier;
   guint                        count;
 
@@ -242,6 +243,7 @@ enum {
   REQUEST_DOCUMENTATION,
   RESET_FONT_SIZE,
   RESTORE_INSERT_MARK,
+  SAVE_COMMAND,
   SAVE_INSERT_MARK,
   SELECTION_THEATRIC,
   SET_MODE,
@@ -3155,8 +3157,10 @@ ide_source_view_real_movement (IdeSourceView         *self,
   if (priv->scrolling_to_scroll_mark)
     priv->scrolling_to_scroll_mark = FALSE;
 
-  _ide_source_view_apply_movement (self, movement, extend_selection, exclusive,
-                                   count, priv->modifier, &priv->target_line_offset);
+  _ide_source_view_apply_movement (self,
+                                   movement, extend_selection, exclusive,
+                                   count, priv->command, priv->modifier,
+                                   &priv->target_line_offset);
 }
 
 static void
@@ -3556,6 +3560,20 @@ ide_source_view_real_save_insert_mark (IdeSourceView *self)
 }
 
 static void
+ide_source_view_real_save_command (IdeSourceView *self)
+{
+  GdkEvent *event;
+  guint keyval;
+  IdeSourceViewPrivate *priv = ide_source_view_get_instance_private (self);
+
+  g_assert (IDE_IS_SOURCE_VIEW (self));
+
+  event = gtk_get_current_event ();
+  if (event && gdk_event_get_keyval (event, &keyval))
+    priv->command = (gunichar)keyval;
+}
+
+static void
 ide_source_view__completion_hide_cb (IdeSourceView       *self,
                                      GtkSourceCompletion *completion)
 {
@@ -5470,6 +5488,7 @@ ide_source_view_class_init (IdeSourceViewClass *klass)
   klass->replay_macro = ide_source_view_real_replay_macro;
   klass->reset_font_size = ide_source_view_real_reset_font_size;
   klass->restore_insert_mark = ide_source_view_real_restore_insert_mark;
+  klass->save_command = ide_source_view_real_save_command;
   klass->save_insert_mark = ide_source_view_real_save_insert_mark;
   klass->selection_theatric = ide_source_view_real_selection_theatric;
   klass->set_mode = ide_source_view_real_set_mode;
@@ -5716,6 +5735,16 @@ ide_source_view_class_init (IdeSourceViewClass *klass)
                                 G_TYPE_NONE,
                                 0);
 
+  gSignals [SAVE_COMMAND] =
+    g_signal_new ("save-command",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+                  G_STRUCT_OFFSET (IdeSourceViewClass, save_command),
+                  NULL, NULL,
+                  g_cclosure_marshal_VOID__VOID,
+                  G_TYPE_NONE,
+                  0);
+
   /**
    * IdeSourceView::capture-modifier:
    *
diff --git a/libide/ide-source-view.h b/libide/ide-source-view.h
index e2e4329..265e163 100644
--- a/libide/ide-source-view.h
+++ b/libide/ide-source-view.h
@@ -251,6 +251,7 @@ struct _IdeSourceViewClass
                                        gboolean                 use_count);
   void (*request_documentation)       (IdeSourceView           *self);
   void (*restore_insert_mark)         (IdeSourceView           *self);
+  void (*save_command)                (IdeSourceView           *self);
   void (*save_insert_mark)            (IdeSourceView           *self);
   void (*selection_theatric)          (IdeSourceView           *self,
                                        IdeSourceViewTheatric    theatric);


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