[gnome-builder/wip/libide] libide: allow specifying replayed insert with count



commit cff03e8b192df83bd01594df36439b157f6f9dd1
Author: Christian Hergert <christian hergert me>
Date:   Thu Mar 12 03:04:33 2015 -0700

    libide: allow specifying replayed insert with count

 libide/ide-source-view-mode.c |   18 ++++++++++++++++++
 libide/ide-source-view-mode.h |   15 ++++++++-------
 libide/ide-source-view.c      |   24 +++++++++++++++++++++++-
 3 files changed, 49 insertions(+), 8 deletions(-)
---
diff --git a/libide/ide-source-view-mode.c b/libide/ide-source-view-mode.c
index 13a9810..1ede67f 100644
--- a/libide/ide-source-view-mode.c
+++ b/libide/ide-source-view-mode.c
@@ -102,6 +102,15 @@ ide_source_view_mode_get_default_mode (IdeSourceViewMode *self)
 }
 
 gboolean
+ide_source_view_mode_get_repeat_insert_with_count (IdeSourceViewMode *self)
+{
+  /*
+   * If count is 10, and you type -, you will get ----------
+   */
+  return get_boolean_param (self, "repeat-insert-with-count");
+}
+
+gboolean
 ide_source_view_mode_get_coalesce_undo (IdeSourceViewMode *self)
 {
   /*
@@ -296,6 +305,15 @@ ide_source_view_mode_class_init (IdeSourceViewModeClass *klass)
                                                                 (G_PARAM_READABLE |
                                                                  G_PARAM_STATIC_STRINGS)));
 
+  gtk_widget_class_install_style_property (GTK_WIDGET_CLASS (klass),
+                                           g_param_spec_boolean ("repeat-insert-with-count",
+                                                                 "Repeat Insert with Count",
+                                                                 "Use the current count to "
+                                                                  "repeat the insertion.",
+                                                                 FALSE,
+                                                                 (G_PARAM_READABLE |
+                                                                  G_PARAM_STATIC_STRINGS)));
+
   /* Proxy all action signals from source view */
   type = IDE_TYPE_SOURCE_VIEW;
   while (type != G_TYPE_INVALID && type != GTK_TYPE_WIDGET)
diff --git a/libide/ide-source-view-mode.h b/libide/ide-source-view-mode.h
index 64b2b34..396d308 100644
--- a/libide/ide-source-view-mode.h
+++ b/libide/ide-source-view-mode.h
@@ -47,13 +47,14 @@ struct _IdeSourceViewModeClass
   GtkWidgetClass parent_class;
 };
 
-gboolean               ide_source_view_mode_get_block_cursor      (IdeSourceViewMode *self);
-gboolean               ide_source_view_mode_get_suppress_unbound  (IdeSourceViewMode *self);
-gboolean               ide_source_view_mode_get_coalesce_undo     (IdeSourceViewMode *self);
-const gchar           *ide_source_view_mode_get_name              (IdeSourceViewMode *self);
-const gchar           *ide_source_view_mode_get_default_mode      (IdeSourceViewMode *self);
-gboolean               ide_source_view_mode_get_keep_mark_on_char (IdeSourceViewMode *self);
-IdeSourceViewModeType  ide_source_view_mode_get_mode_type         (IdeSourceViewMode *self);
+gboolean               ide_source_view_mode_get_repeat_insert_with_count (IdeSourceViewMode *self);
+gboolean               ide_source_view_mode_get_block_cursor             (IdeSourceViewMode *self);
+gboolean               ide_source_view_mode_get_suppress_unbound         (IdeSourceViewMode *self);
+gboolean               ide_source_view_mode_get_coalesce_undo            (IdeSourceViewMode *self);
+const gchar           *ide_source_view_mode_get_name                     (IdeSourceViewMode *self);
+const gchar           *ide_source_view_mode_get_default_mode             (IdeSourceViewMode *self);
+gboolean               ide_source_view_mode_get_keep_mark_on_char        (IdeSourceViewMode *self);
+IdeSourceViewModeType  ide_source_view_mode_get_mode_type                (IdeSourceViewMode *self);
 
 G_END_DECLS
 
diff --git a/libide/ide-source-view.c b/libide/ide-source-view.c
index 47edbb9..0b6ac0b 100644
--- a/libide/ide-source-view.c
+++ b/libide/ide-source-view.c
@@ -1804,11 +1804,33 @@ ide_source_view_key_press_event (GtkWidget   *widget,
       return TRUE;
     }
 
-  ret = GTK_WIDGET_CLASS (ide_source_view_parent_class)->key_press_event (widget, event);
+  /*
+   * If repeat-with-count is set, we need to repeat the insertion multiple times.
+   */
+  if (priv->count &&
+      priv->mode &&
+      ide_source_view_mode_get_repeat_insert_with_count (priv->mode))
+    {
+      gsize i;
+
+      for (i = MAX (1, priv->count); i > 0; i--)
+        ret = GTK_WIDGET_CLASS (ide_source_view_parent_class)->key_press_event (widget, event);
+      priv->count = 0;
+    }
+  else
+    {
+      ret = GTK_WIDGET_CLASS (ide_source_view_parent_class)->key_press_event (widget, event);
+    }
 
+  /*
+   * If we just inserted ({["', we might want to insert a matching close.
+   */
   if (ret)
     ide_source_view_maybe_insert_match (self, event);
 
+  /*
+   * Only scroll to the insert mark if we made a change.
+   */
   if (priv->change_sequence != change_sequence)
     ide_source_view_scroll_mark_onscreen (self, insert);
 


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