[gtksourceview/wip/chergert/vim] check editable before some commands
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/vim] check editable before some commands
- Date: Fri, 5 Nov 2021 18:40:00 +0000 (UTC)
commit 4118906b75bad4882a326e961560abf5ea5cd637
Author: Christian Hergert <chergert redhat com>
Date: Fri Nov 5 11:39:36 2021 -0700
check editable before some commands
gtksourceview/vim/gtk-source-vim-command.c | 36 ++++++++++++++++++++++++++++++
gtksourceview/vim/gtk-source-vim-state.c | 12 ++++++++++
gtksourceview/vim/gtk-source-vim-state.h | 1 +
3 files changed, 49 insertions(+)
---
diff --git a/gtksourceview/vim/gtk-source-vim-command.c b/gtksourceview/vim/gtk-source-vim-command.c
index 967d69e0..33cb5c76 100644
--- a/gtksourceview/vim/gtk-source-vim-command.c
+++ b/gtksourceview/vim/gtk-source-vim-command.c
@@ -68,6 +68,9 @@ gtk_source_vim_command_format (GtkSourceVimCommand *self)
GtkTextIter iter;
GtkTextIter selection;
+ if (!gtk_source_vim_state_get_editable (GTK_SOURCE_VIM_STATE (self)))
+ return;
+
buffer = gtk_source_vim_state_get_buffer (GTK_SOURCE_VIM_STATE (self), &iter, &selection);
root = gtk_source_vim_state_get_root (GTK_SOURCE_VIM_STATE (self));
@@ -94,6 +97,9 @@ gtk_source_vim_command_shift (GtkSourceVimCommand *self,
GtkTextIter iter, selection;
int count;
+ if (!gtk_source_vim_state_get_editable (GTK_SOURCE_VIM_STATE (self)))
+ return;
+
gtk_source_vim_state_set_can_repeat (GTK_SOURCE_VIM_STATE (self), TRUE);
count = gtk_source_vim_state_get_count (GTK_SOURCE_VIM_STATE (self));
@@ -150,6 +156,9 @@ gtk_source_vim_command_delete (GtkSourceVimCommand *self)
GtkTextIter iter, selection;
char *text;
+ if (!gtk_source_vim_state_get_editable (GTK_SOURCE_VIM_STATE (self)))
+ return;
+
gtk_source_vim_state_set_can_repeat (GTK_SOURCE_VIM_STATE (self), TRUE);
buffer = gtk_source_vim_state_get_buffer (GTK_SOURCE_VIM_STATE (self), &iter, &selection);
@@ -180,6 +189,9 @@ gtk_source_vim_command_join (GtkSourceVimCommand *self)
GtkTextIter end;
guint offset;
+ if (!gtk_source_vim_state_get_editable (GTK_SOURCE_VIM_STATE (self)))
+ return;
+
buffer = gtk_source_vim_state_get_buffer (GTK_SOURCE_VIM_STATE (self), &iter, &selection);
gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER (buffer));
@@ -234,6 +246,9 @@ gtk_source_vim_command_paste_after (GtkSourceVimCommand *self)
const char *text;
int count;
+ if (!gtk_source_vim_state_get_editable (GTK_SOURCE_VIM_STATE (self)))
+ return;
+
buffer = gtk_source_vim_state_get_buffer (GTK_SOURCE_VIM_STATE (self), &iter, &selection);
text = gtk_source_vim_state_get_current_register_value (GTK_SOURCE_VIM_STATE (self));
count = gtk_source_vim_state_get_count (GTK_SOURCE_VIM_STATE (self));
@@ -296,6 +311,9 @@ gtk_source_vim_command_paste_before (GtkSourceVimCommand *self)
const char *text;
int count;
+ if (!gtk_source_vim_state_get_editable (GTK_SOURCE_VIM_STATE (self)))
+ return;
+
buffer = gtk_source_vim_state_get_buffer (GTK_SOURCE_VIM_STATE (self), &iter, &selection);
text = gtk_source_vim_state_get_current_register_value (GTK_SOURCE_VIM_STATE (self));
count = gtk_source_vim_state_get_count (GTK_SOURCE_VIM_STATE (self));
@@ -345,6 +363,9 @@ gtk_source_vim_command_toggle_case (GtkSourceVimCommand *self)
GtkTextIter iter;
GtkTextIter selection;
+ if (!gtk_source_vim_state_get_editable (GTK_SOURCE_VIM_STATE (self)))
+ return;
+
buffer = gtk_source_vim_state_get_buffer (GTK_SOURCE_VIM_STATE (self), &iter, &selection);
gtk_source_vim_state_begin_user_action (GTK_SOURCE_VIM_STATE (self));
@@ -371,6 +392,9 @@ gtk_source_vim_command_change_case (GtkSourceVimCommand *self,
GtkTextIter iter;
GtkTextIter selection;
+ if (!gtk_source_vim_state_get_editable (GTK_SOURCE_VIM_STATE (self)))
+ return;
+
buffer = gtk_source_vim_state_get_buffer (GTK_SOURCE_VIM_STATE (self), &iter, &selection);
gtk_text_iter_order (&iter, &selection);
@@ -432,6 +456,9 @@ gtk_source_vim_command_rot13 (GtkSourceVimCommand *self)
char *text;
char *new_text;
+ if (!gtk_source_vim_state_get_editable (GTK_SOURCE_VIM_STATE (self)))
+ return;
+
buffer = gtk_source_vim_state_get_buffer (GTK_SOURCE_VIM_STATE (self), &iter, &selection);
text = gtk_text_iter_get_slice (&iter, &selection);
new_text = rot13 (text);
@@ -481,6 +508,9 @@ gtk_source_vim_command_replace_one (GtkSourceVimCommand *self)
g_assert (GTK_SOURCE_IS_VIM_COMMAND (self));
+ if (!gtk_source_vim_state_get_editable (GTK_SOURCE_VIM_STATE (self)))
+ return;
+
if (self->char_pending[0] == 0)
{
return;
@@ -513,6 +543,9 @@ gtk_source_vim_command_undo (GtkSourceVimCommand *self)
GtkSourceBuffer *buffer;
int count;
+ if (!gtk_source_vim_state_get_editable (GTK_SOURCE_VIM_STATE (self)))
+ return;
+
buffer = gtk_source_vim_state_get_buffer (GTK_SOURCE_VIM_STATE (self), NULL, NULL);
count = gtk_source_vim_state_get_count (GTK_SOURCE_VIM_STATE (self));
@@ -531,6 +564,9 @@ gtk_source_vim_command_redo (GtkSourceVimCommand *self)
GtkSourceBuffer *buffer;
int count;
+ if (!gtk_source_vim_state_get_editable (GTK_SOURCE_VIM_STATE (self)))
+ return;
+
buffer = gtk_source_vim_state_get_buffer (GTK_SOURCE_VIM_STATE (self), NULL, NULL);
count = gtk_source_vim_state_get_count (GTK_SOURCE_VIM_STATE (self));
diff --git a/gtksourceview/vim/gtk-source-vim-state.c b/gtksourceview/vim/gtk-source-vim-state.c
index 78efed96..bfa2222b 100644
--- a/gtksourceview/vim/gtk-source-vim-state.c
+++ b/gtksourceview/vim/gtk-source-vim-state.c
@@ -1167,3 +1167,15 @@ gtk_source_vim_state_select_linewise (GtkSourceVimState *self,
gtk_text_buffer_select_range (GTK_TEXT_BUFFER (buffer), insert, selection);
}
+
+gboolean
+gtk_source_vim_state_get_editable (GtkSourceVimState *self)
+{
+ GtkSourceView *view;
+
+ g_return_val_if_fail (GTK_SOURCE_IS_VIM_STATE (self), FALSE);
+
+ view = gtk_source_vim_state_get_view (self);
+
+ return gtk_text_view_get_editable (GTK_TEXT_VIEW (view));
+}
diff --git a/gtksourceview/vim/gtk-source-vim-state.h b/gtksourceview/vim/gtk-source-vim-state.h
index 5ab5889c..7e55a008 100644
--- a/gtksourceview/vim/gtk-source-vim-state.h
+++ b/gtksourceview/vim/gtk-source-vim-state.h
@@ -59,6 +59,7 @@ struct _GtkSourceVimStateClass
GString *string);
};
+gboolean gtk_source_vim_state_get_editable (GtkSourceVimState *self);
void gtk_source_vim_state_set_parent (GtkSourceVimState *self,
GtkSourceVimState *parent);
void gtk_source_vim_state_push (GtkSourceVimState *self,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]