[gnome-builder] libide: allow faking block cursor



commit 0b7977fb7a74aa7bd83ece5cd436676a30866d3a
Author: Christian Hergert <christian hergert me>
Date:   Sat Mar 7 02:24:10 2015 -0800

    libide: allow faking block cursor
    
    This is the same hack we do in GbSourceVim. We use the overwrite caret
    and then hijack all the unknown input so we don't overwrite data. May
    not be the most idea thing, but it's what we do today and it works
    pretty well.

 data/keybindings/vim.css      |   20 ++++++++++++++++++++
 libide/ide-source-view-mode.c |   15 +++++++++++++++
 libide/ide-source-view-mode.h |    1 +
 libide/ide-source-view.c      |    5 +++++
 4 files changed, 41 insertions(+), 0 deletions(-)
---
diff --git a/data/keybindings/vim.css b/data/keybindings/vim.css
index e595980..78ba98d 100644
--- a/data/keybindings/vim.css
+++ b/data/keybindings/vim.css
@@ -776,6 +776,7 @@ IdeSourceViewMode.default,
 IdeSourceViewMode.vim-normal {
   -IdeSourceViewMode-suppress-unbound: true;
   -IdeSourceViewMode-coalesce-undo: true;
+  -IdeSourceViewMode-block-cursor: true;
 
   gtk-key-bindings: builder-vim-source-view,
                     builder-vim-source-view-normal;
@@ -784,6 +785,7 @@ IdeSourceViewMode.vim-normal {
 IdeSourceViewMode.vim-normal-with-count {
   -IdeSourceViewMode-suppress-unbound: true;
   -IdeSourceViewMode-coalesce-undo: true;
+  -IdeSourceViewMode-block-cursor: true;
 
   gtk-key-bindings: builder-vim-source-view,
                     builder-vim-source-view-normal-with-count,
@@ -793,6 +795,7 @@ IdeSourceViewMode.vim-normal-with-count {
 IdeSourceViewMode.vim-normal-c {
   -IdeSourceViewMode-suppress-unbound: true;
   -IdeSourceViewMode-coalesce-undo: true;
+  -IdeSourceViewMode-block-cursor: true;
 
   gtk-key-bindings: builder-vim-source-view,
                     builder-vim-source-view-normal-c;
@@ -801,6 +804,7 @@ IdeSourceViewMode.vim-normal-c {
 IdeSourceViewMode.vim-normal-c-i {
   -IdeSourceViewMode-suppress-unbound: true;
   -IdeSourceViewMode-coalesce-undo: true;
+  -IdeSourceViewMode-block-cursor: true;
 
   gtk-key-bindings: builder-vim-source-view,
                     builder-vim-source-view-normal-c-i;
@@ -809,6 +813,7 @@ IdeSourceViewMode.vim-normal-c-i {
 IdeSourceViewMode.vim-normal-d {
   -IdeSourceViewMode-suppress-unbound: true;
   -IdeSourceViewMode-coalesce-undo: true;
+  -IdeSourceViewMode-block-cursor: true;
 
   gtk-key-bindings: builder-vim-source-view,
                     builder-vim-source-view-normal-d;
@@ -817,6 +822,7 @@ IdeSourceViewMode.vim-normal-d {
 IdeSourceViewMode.vim-normal-d-g {
   -IdeSourceViewMode-suppress-unbound: true;
   -IdeSourceViewMode-coalesce-undo: true;
+  -IdeSourceViewMode-block-cursor: true;
 
   gtk-key-bindings: builder-vim-source-view,
                     builder-vim-source-view-normal-d-g;
@@ -825,6 +831,7 @@ IdeSourceViewMode.vim-normal-d-g {
 IdeSourceViewMode.vim-normal-d-i {
   -IdeSourceViewMode-suppress-unbound: true;
   -IdeSourceViewMode-coalesce-undo: true;
+  -IdeSourceViewMode-block-cursor: true;
 
   gtk-key-bindings: builder-vim-source-view,
                     builder-vim-source-view-normal-d-i;
@@ -833,6 +840,7 @@ IdeSourceViewMode.vim-normal-d-i {
 IdeSourceViewMode.vim-normal-g {
   -IdeSourceViewMode-suppress-unbound: true;
   -IdeSourceViewMode-coalesce-undo: true;
+  -IdeSourceViewMode-block-cursor: true;
 
   gtk-key-bindings: builder-vim-source-view,
                     builder-vim-source-view-normal-g;
@@ -841,6 +849,7 @@ IdeSourceViewMode.vim-normal-g {
 IdeSourceViewMode.vim-normal-g-u {
   -IdeSourceViewMode-suppress-unbound: true;
   -IdeSourceViewMode-coalesce-undo: true;
+  -IdeSourceViewMode-block-cursor: true;
 
   gtk-key-bindings: builder-vim-source-view,
                     builder-vim-source-view-normal-g-u;
@@ -849,6 +858,7 @@ IdeSourceViewMode.vim-normal-g-u {
 IdeSourceViewMode.vim-normal-indent {
   -IdeSourceViewMode-suppress-unbound: true;
   -IdeSourceViewMode-coalesce-undo: true;
+  -IdeSourceViewMode-block-cursor: true;
 
   gtk-key-bindings: builder-vim-source-view,
                     builder-vim-source-view-normal-indent;
@@ -857,6 +867,7 @@ IdeSourceViewMode.vim-normal-indent {
 IdeSourceViewMode.vim-normal-y {
   -IdeSourceViewMode-suppress-unbound: true;
   -IdeSourceViewMode-coalesce-undo: true;
+  -IdeSourceViewMode-block-cursor: true;
 
   gtk-key-bindings: builder-vim-source-view,
                     builder-vim-source-view-normal-y;
@@ -865,6 +876,7 @@ IdeSourceViewMode.vim-normal-y {
 IdeSourceViewMode.vim-normal-z {
   -IdeSourceViewMode-suppress-unbound: true;
   -IdeSourceViewMode-coalesce-undo: true;
+  -IdeSourceViewMode-block-cursor: true;
 
   gtk-key-bindings: builder-vim-source-view,
                     builder-vim-source-view-normal-z;
@@ -873,6 +885,7 @@ IdeSourceViewMode.vim-normal-z {
 IdeSourceViewMode.vim-insert {
   -IdeSourceViewMode-suppress-unbound: false;
   -IdeSourceViewMode-coalesce-undo: true;
+  -IdeSourceViewMode-block-cursor: false;
 
   gtk-key-bindings: builder-vim-source-view,
                     builder-vim-source-view-insert;
@@ -881,6 +894,7 @@ IdeSourceViewMode.vim-insert {
 IdeSourceViewMode.vim-visual {
   -IdeSourceViewMode-suppress-unbound: true;
   -IdeSourceViewMode-coalesce-undo: true;
+  -IdeSourceViewMode-block-cursor: true;
 
   gtk-key-bindings: builder-vim-source-view,
                     builder-vim-source-view-visual;
@@ -889,6 +903,7 @@ IdeSourceViewMode.vim-visual {
 IdeSourceViewMode.vim-visual-g {
   -IdeSourceViewMode-suppress-unbound: true;
   -IdeSourceViewMode-coalesce-undo: true;
+  -IdeSourceViewMode-block-cursor: true;
 
   gtk-key-bindings: builder-vim-source-view,
                     builder-vim-source-view-visual-g;
@@ -897,6 +912,7 @@ IdeSourceViewMode.vim-visual-g {
 IdeSourceViewMode.vim-visual-z {
   -IdeSourceViewMode-suppress-unbound: true;
   -IdeSourceViewMode-coalesce-undo: true;
+  -IdeSourceViewMode-block-cursor: true;
 
   gtk-key-bindings: builder-vim-source-view,
                     builder-vim-source-view-visual-z;
@@ -905,6 +921,7 @@ IdeSourceViewMode.vim-visual-z {
 IdeSourceViewMode.vim-visual-line {
   -IdeSourceViewMode-suppress-unbound: true;
   -IdeSourceViewMode-coalesce-undo: true;
+  -IdeSourceViewMode-block-cursor: true;
 
   gtk-key-bindings: builder-vim-source-view,
                     builder-vim-source-view-visual-line;
@@ -913,6 +930,7 @@ IdeSourceViewMode.vim-visual-line {
 IdeSourceViewMode.vim-visual-line-g {
   -IdeSourceViewMode-suppress-unbound: true;
   -IdeSourceViewMode-coalesce-undo: true;
+  -IdeSourceViewMode-block-cursor: true;
 
   gtk-key-bindings: builder-vim-source-view,
                     builder-vim-source-view-visual-line-g;
@@ -921,6 +939,7 @@ IdeSourceViewMode.vim-visual-line-g {
 IdeSourceViewMode.vim-visual-line-z {
   -IdeSourceViewMode-suppress-unbound: true;
   -IdeSourceViewMode-coalesce-undo: true;
+  -IdeSourceViewMode-block-cursor: true;
 
   gtk-key-bindings: builder-vim-source-view,
                     builder-vim-source-view-visual-line-z;
@@ -929,6 +948,7 @@ IdeSourceViewMode.vim-visual-line-z {
 IdeSourceViewMode.vim-visual-block {
   -IdeSourceViewMode-suppress-unbound: true;
   -IdeSourceViewMode-coalesce-undo: true;
+  -IdeSourceViewMode-block-cursor: true;
 
   gtk-key-bindings: builder-vim-source-view, builder-vim-source-view-visual-block;
 }
diff --git a/libide/ide-source-view-mode.c b/libide/ide-source-view-mode.c
index f1d0099..2de0881 100644
--- a/libide/ide-source-view-mode.c
+++ b/libide/ide-source-view-mode.c
@@ -84,6 +84,12 @@ ide_source_view_mode_get_suppress_unbound (IdeSourceViewMode *self)
   return get_boolean_param (self, "suppress-unbound");
 }
 
+gboolean
+ide_source_view_mode_get_block_cursor (IdeSourceViewMode *self)
+{
+  return get_boolean_param (self, "block-cursor");
+}
+
 static void
 ide_source_view_mode_finalize (GObject *object)
 {
@@ -214,6 +220,14 @@ 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 ("block-cursor",
+                                                                 _("Block Cursor"),
+                                                                 _("Use fake block cursor by "
+                                                                   "using overwrite mode."),
+                                                                 FALSE,
+                                                                 (G_PARAM_READABLE |
+                                                                  G_PARAM_STATIC_STRINGS)));
 
   /* Proxy all action signals from source view */
   type = IDE_TYPE_SOURCE_VIEW;
@@ -359,6 +373,7 @@ _ide_source_view_mode_new (GtkWidget             *view,
 
   IDE_TRACE_MSG ("coalesce_undo = %d", ide_source_view_mode_get_coalesce_undo (mode));
   IDE_TRACE_MSG ("supress_unbound = %d", ide_source_view_mode_get_suppress_unbound (mode));
+  IDE_TRACE_MSG ("block_cursor = %d", ide_source_view_mode_get_block_cursor (mode));
 
   return g_object_ref_sink (mode);
 }
diff --git a/libide/ide-source-view-mode.h b/libide/ide-source-view-mode.h
index 6a59746..90797f1 100644
--- a/libide/ide-source-view-mode.h
+++ b/libide/ide-source-view-mode.h
@@ -46,6 +46,7 @@ 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);
diff --git a/libide/ide-source-view.c b/libide/ide-source-view.c
index 7dc0097..8e79589 100644
--- a/libide/ide-source-view.c
+++ b/libide/ide-source-view.c
@@ -2118,6 +2118,7 @@ ide_source_view_real_set_mode (IdeSourceView         *self,
                                IdeSourceViewModeType  type)
 {
   IdeSourceViewPrivate *priv = ide_source_view_get_instance_private (self);
+  gboolean overwrite;
 
   IDE_ENTRY;
 
@@ -2158,6 +2159,10 @@ ide_source_view_real_set_mode (IdeSourceView         *self,
   if (ide_source_view_mode_get_coalesce_undo (priv->mode))
     BEGIN_USER_ACTION (self);
 
+  overwrite = ide_source_view_mode_get_block_cursor (priv->mode);
+  if (overwrite != gtk_text_view_get_overwrite (GTK_TEXT_VIEW (self)))
+    gtk_text_view_set_overwrite (GTK_TEXT_VIEW (self), overwrite);
+
   IDE_EXIT;
 }
 


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