[gtksourceview/wip/chergert/vim] setup command bar text



commit 9f9f8f256e3c44e7a783f6fd297bfbb125d4cb60
Author: Christian Hergert <chergert redhat com>
Date:   Wed Oct 27 12:41:26 2021 -0700

    setup command bar text
    
    show -- INSERT -- and -- REPLACE -- like vim. fixup command under replace.

 gtksourceview/vim/gtk-source-vim-insert.c  |  3 +++
 gtksourceview/vim/gtk-source-vim-replace.c | 12 ++++++++++++
 gtksourceview/vim/gtk-source-vim-state.h   |  2 ++
 gtksourceview/vim/gtk-source-vim.c         | 14 ++++++++++----
 4 files changed, 27 insertions(+), 4 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-insert.c b/gtksourceview/vim/gtk-source-vim-insert.c
index 67bbea7d..a9d4d360 100644
--- a/gtksourceview/vim/gtk-source-vim-insert.c
+++ b/gtksourceview/vim/gtk-source-vim-insert.c
@@ -21,6 +21,8 @@
 
 #include "config.h"
 
+#include <glib/gi18n.h>
+
 #include "gtksourceindenter.h"
 #include "gtksourceview.h"
 
@@ -303,6 +305,7 @@ gtk_source_vim_insert_class_init (GtkSourceVimInsertClass *klass)
        object_class->get_property = gtk_source_vim_insert_get_property;
        object_class->set_property = gtk_source_vim_insert_set_property;
 
+       state_class->command_bar_text = _("-- INSERT --");
        state_class->append_command = gtk_source_vim_insert_append_command;
        state_class->handle_event = gtk_source_vim_insert_handle_event;
        state_class->resume = gtk_source_vim_insert_resume;
diff --git a/gtksourceview/vim/gtk-source-vim-replace.c b/gtksourceview/vim/gtk-source-vim-replace.c
index be966d6c..f825e16a 100644
--- a/gtksourceview/vim/gtk-source-vim-replace.c
+++ b/gtksourceview/vim/gtk-source-vim-replace.c
@@ -21,6 +21,8 @@
 
 #include "config.h"
 
+#include <glib/gi18n.h>
+
 #include "gtk-source-vim-replace.h"
 #include "gtk-source-vim-insert-literal.h"
 
@@ -122,11 +124,21 @@ gtk_source_vim_replace_resume (GtkSourceVimState *state,
        gtk_source_vim_state_set_overwrite (state, TRUE);
 }
 
+static void
+gtk_source_vim_replace_append_command (GtkSourceVimState *state,
+                                       GString           *string)
+{
+       /* command should be empty during replace */
+       g_string_truncate (string, 0);
+}
+
 static void
 gtk_source_vim_replace_class_init (GtkSourceVimReplaceClass *klass)
 {
        GtkSourceVimStateClass *state_class = GTK_SOURCE_VIM_STATE_CLASS (klass);
 
+       state_class->command_bar_text = _("-- REPLACE --");
+       state_class->append_command = gtk_source_vim_replace_append_command;
        state_class->handle_keypress = gtk_source_vim_replace_handle_keypress;
        state_class->enter = gtk_source_vim_replace_enter;
        state_class->leave = gtk_source_vim_replace_leave;
diff --git a/gtksourceview/vim/gtk-source-vim-state.h b/gtksourceview/vim/gtk-source-vim-state.h
index 45e0fabc..5c1b5a0b 100644
--- a/gtksourceview/vim/gtk-source-vim-state.h
+++ b/gtksourceview/vim/gtk-source-vim-state.h
@@ -35,6 +35,8 @@ struct _GtkSourceVimStateClass
 {
        GObjectClass parent_class;
 
+       const char *command_bar_text;
+
        void     (*view_set)        (GtkSourceVimState *state);
        void     (*enter)           (GtkSourceVimState *state);
        void     (*suspend)         (GtkSourceVimState *state,
diff --git a/gtksourceview/vim/gtk-source-vim.c b/gtksourceview/vim/gtk-source-vim.c
index 7d55642e..9ba1d0d6 100644
--- a/gtksourceview/vim/gtk-source-vim.c
+++ b/gtksourceview/vim/gtk-source-vim.c
@@ -91,6 +91,7 @@ gtk_source_vim_handle_event (GtkSourceVimState *state,
        g_string_truncate (self->command_text, 0);
        gtk_source_vim_state_append_command (state, self->command_text);
        g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_COMMAND_TEXT]);
+       g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_COMMAND_BAR_TEXT]);
 
        return ret;
 }
@@ -233,15 +234,20 @@ gtk_source_vim_get_command_text (GtkSourceVim *self)
 const char *
 gtk_source_vim_get_command_bar_text (GtkSourceVim *self)
 {
-       GtkSourceVimState *child;
+       GtkSourceVimState *current;
 
        g_return_val_if_fail (GTK_SOURCE_IS_VIM (self), NULL);
 
-       child = gtk_source_vim_state_get_current (GTK_SOURCE_VIM_STATE (self));
+       current = gtk_source_vim_state_get_current (GTK_SOURCE_VIM_STATE (self));
+
+       if (GTK_SOURCE_IS_VIM_COMMAND_BAR (current))
+       {
+               return gtk_source_vim_command_bar_get_text (GTK_SOURCE_VIM_COMMAND_BAR (current));
+       }
 
-       if (GTK_SOURCE_IS_VIM_COMMAND_BAR (child))
+       if (GTK_SOURCE_VIM_STATE_GET_CLASS (current)->command_bar_text)
        {
-               return gtk_source_vim_command_bar_get_text (GTK_SOURCE_VIM_COMMAND_BAR (child));
+               return GTK_SOURCE_VIM_STATE_GET_CLASS (current)->command_bar_text;
        }
 
        return "";


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