[gnome-builder] libide: add IdeSourceView::movement action
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide: add IdeSourceView::movement action
- Date: Mon, 23 Mar 2015 23:52:10 +0000 (UTC)
commit 03b519d79c92768300dfcedfdf6af6c06e006fa0
Author: Christian Hergert <christian hergert me>
Date: Tue Mar 3 20:21:53 2015 -0800
libide: add IdeSourceView::movement action
The movements still need to be implemented. Some of them can be lifted
from GbSourceView fairly easily.
When combined with Gtk+ CSS binding-sets, we should be able to emulate
Vim as well as we do today. In significantly less code too.
libide/Makefile.am | 2 +
libide/ide-source-view-movements.c | 127 ++++++++++++++++++++++++++++++++++++
libide/ide-source-view-movements.h | 33 +++++++++
libide/ide-source-view.c | 24 +++++++
libide/ide-source-view.h | 122 ++++++++++++++++++++++++++++++----
5 files changed, 293 insertions(+), 15 deletions(-)
---
diff --git a/libide/Makefile.am b/libide/Makefile.am
index 518687c..1d4e3ab 100644
--- a/libide/Makefile.am
+++ b/libide/Makefile.am
@@ -219,6 +219,8 @@ libide_1_0_la_SOURCES = \
libide/ide-source-snippet-parser.c \
libide/ide-source-snippet-parser.h \
libide/ide-source-snippet-private.h \
+ libide/ide-source-view-movements.c \
+ libide/ide-source-view-movements.h \
libide/tasks/ide-load-directory-task.c \
libide/tasks/ide-load-directory-task.h \
libide/theatrics/ide-animation.c \
diff --git a/libide/ide-source-view-movements.c b/libide/ide-source-view-movements.c
new file mode 100644
index 0000000..fa6c5d3
--- /dev/null
+++ b/libide/ide-source-view-movements.c
@@ -0,0 +1,127 @@
+/* ide-source-view-movement-helper.c
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This file is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This file is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "ide-source-view-movements.h"
+
+void
+_ide_source_view_apply_movement (IdeSourceView *self,
+ IdeSourceViewMovement movement,
+ gboolean extend_selection,
+ gint param)
+{
+ g_assert (IDE_IS_SOURCE_VIEW (self));
+
+ switch (movement)
+ {
+ case IDE_SOURCE_VIEW_MOVEMENT_NTH_CHAR:
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_CHAR:
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_NEXT_CHAR:
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_FIRST_CHAR:
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_FIRST_NONSPACE_CHAR:
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_MIDDLE_CHAR:
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_LAST_CHAR:
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_WORD_START:
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_NEXT_WORD_START:
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_WORD_END:
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_NEXT_WORD_END:
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_SENTANCE_START:
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_SENTANCE_END:
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_PARAGRAPH_START:
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_PARAGRAPH_END:
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_LINE:
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_NEXT_LINE:
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_FIRST_LINE:
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_NTH_LINE:
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_LAST_LINE:
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_LINE_PERCENTAGE:
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_HALF_PAGE_UP:
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_HALF_PAGE_DOWN:
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_PAGE_UP:
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_PAGE_DOWN:
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_SCREEN_UP:
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_SCREEN_DOWN:
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_SCREEN_TOP:
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_SCREEN_MIDDLE:
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_SCREEN_BOTTOM:
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_MATCH_SPECIAL:
+ break;
+
+ default:
+ g_return_if_reached ();
+ }
+}
diff --git a/libide/ide-source-view-movements.h b/libide/ide-source-view-movements.h
new file mode 100644
index 0000000..b7e698d
--- /dev/null
+++ b/libide/ide-source-view-movements.h
@@ -0,0 +1,33 @@
+/* ide-source-view-movement-helper.h
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This file is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This file is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef IDE_SOURCE_VIEW_HELPER_H
+#define IDE_SOURCE_VIEW_HELPER_H
+
+#include "ide-source-view.h"
+
+G_BEGIN_DECLS
+
+void _ide_source_view_apply_movement (IdeSourceView *source_view,
+ IdeSourceViewMovement movement,
+ gboolean extend_selection,
+ gint param);
+
+G_END_DECLS
+
+#endif /* IDE_SOURCE_VIEW_HELPER_H */
diff --git a/libide/ide-source-view.c b/libide/ide-source-view.c
index 53de672..affea21 100644
--- a/libide/ide-source-view.c
+++ b/libide/ide-source-view.c
@@ -47,6 +47,7 @@
#include "ide-source-location.h"
#include "ide-source-view.h"
#include "ide-source-view-mode.h"
+#include "ide-source-view-movements.h"
#define DEFAULT_FONT_DESC "Monospace 11"
#define ANIMATION_X_GROW 50
@@ -103,6 +104,7 @@ enum {
enum {
ACTION,
JUMP,
+ MOVEMENT,
PUSH_SNIPPET,
POP_SNIPPET,
SET_MODE,
@@ -1450,6 +1452,16 @@ ide_source_view_real_set_mode (IdeSourceView *self,
}
static void
+ide_source_view_real_movement (IdeSourceView *self,
+ IdeSourceViewMovement movement,
+ gboolean extend_selection)
+{
+ g_assert (IDE_IS_SOURCE_VIEW (self));
+
+ _ide_source_view_apply_movement (self, movement, extend_selection, 0 /* TODO */);
+}
+
+static void
ide_source_view_constructed (GObject *object)
{
IdeSourceView *self = (IdeSourceView *)object;
@@ -1624,6 +1636,7 @@ ide_source_view_class_init (IdeSourceViewClass *klass)
klass->action = ide_source_view_real_action;
klass->jump = ide_source_view_real_jump;
+ klass->movement = ide_source_view_real_movement;
klass->set_mode = ide_source_view_real_set_mode;
g_object_class_override_property (object_class, PROP_AUTO_INDENT, "auto-indent");
@@ -1713,6 +1726,17 @@ ide_source_view_class_init (IdeSourceViewClass *klass)
1,
GTK_TYPE_TEXT_ITER);
+ gSignals [MOVEMENT] = g_signal_new ("movement",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (IdeSourceViewClass, movement),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE,
+ 2,
+ IDE_TYPE_SOURCE_VIEW_MOVEMENT,
+ G_TYPE_BOOLEAN);
+
gSignals [SET_MODE] = g_signal_new ("set-mode",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
diff --git a/libide/ide-source-view.h b/libide/ide-source-view.h
index c3d811e..8068726 100644
--- a/libide/ide-source-view.h
+++ b/libide/ide-source-view.h
@@ -51,6 +51,95 @@ typedef enum
IDE_SOURCE_VIEW_MODE_TYPE_MODAL
} IdeSourceViewModeType;
+/**
+ * IdeSourceViewMovement:
+ * @IDE_SOURCE_VIEW_MOVEMENT_NTH_CHAR: move to nth character in line. Use a repeat to
+ * specify the target character within the line.
+ * @IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_CHAR: move to previous character in line.
+ * @IDE_SOURCE_VIEW_MOVEMENT_NEXT_CHAR: move to next character in line.
+ * @IDE_SOURCE_VIEW_MOVEMENT_FIRST_CHAR: move to line offset of zero.
+ * @IDE_SOURCE_VIEW_MOVEMENT_FIRST_NONSPACE_CHAR: move to first non-whitespace character in line.
+ * @IDE_SOURCE_VIEW_MOVEMENT_MIDDLE_CHAR: move to the middle character in the line.
+ * @IDE_SOURCE_VIEW_MOVEMENT_LAST_CHAR: move to the last character in the line.
+ * @IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_WORD_START: move to beginning of previous word.
+ * @IDE_SOURCE_VIEW_MOVEMENT_NEXT_WORD_START: move to beginning of next word.
+ * @IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_WORD_END: move to end of previous word.
+ * @IDE_SOURCE_VIEW_MOVEMENT_NEXT_WORD_END: move to end of next word.
+ * @IDE_SOURCE_VIEW_MOVEMENT_SENTANCE_START: move to beginning of sentance.
+ * @IDE_SOURCE_VIEW_MOVEMENT_SENTANCE_END: move to end of sentance.
+ * @IDE_SOURCE_VIEW_MOVEMENT_PARAGRAPH_START: move to start of paragraph.
+ * @IDE_SOURCE_VIEW_MOVEMENT_PARAGRAPH_END: move to end of paragraph.
+ * @IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_LINE: move to previous line, keeping line offset if possible.
+ * @IDE_SOURCE_VIEW_MOVEMENT_NEXT_LINE: move to next line, keeping line offset if possible.
+ * @IDE_SOURCE_VIEW_MOVEMENT_FIRST_LINE: move to first line in file, line offset of zero.
+ * @IDE_SOURCE_VIEW_MOVEMENT_NTH_LINE: move to nth line, line offset of zero. use repeat to
+ * select the given line number.
+ * @IDE_SOURCE_VIEW_MOVEMENT_LAST_LINE: move to last line in file, with line offset of zero.
+ * @IDE_SOURCE_VIEW_MOVEMENT_LINE_PERCENTAGE: move to line based on percentage. Use repeat to
+ * specify the percentage, 0 to 100.
+ * @IDE_SOURCE_VIEW_MOVEMENT_HALF_PAGE_UP: move half a page up.
+ * @IDE_SOURCE_VIEW_MOVEMENT_HALF_PAGE_DOWN: move half a page down.
+ * @IDE_SOURCE_VIEW_MOVEMENT_PAGE_UP: move a full page up.
+ * @IDE_SOURCE_VIEW_MOVEMENT_PAGE_DOWN: move a full page down.
+ * @IDE_SOURCE_VIEW_MOVEMENT_SCREEN_UP: move to viewport up by visible line, adjusting cursor
+ * to stay on screen if necessary.
+ * @IDE_SOURCE_VIEW_MOVEMENT_SCREEN_DOWN: move to viewport down by visible line, adjusting cursor
+ * to stay on screen if necessary.
+ * @IDE_SOURCE_VIEW_MOVEMENT_SCREEN_TOP: move to the top of the screen.
+ * @IDE_SOURCE_VIEW_MOVEMENT_SCREEN_MIDDLE: move to the middle of the screen.
+ * @IDE_SOURCE_VIEW_MOVEMENT_SCREEN_BOTTOM: move to the bottom of the screen.
+ * @IDE_SOURCE_VIEW_MOVEMENT_MATCH_SPECIAL: move to match of brace, bracket, comment.
+ *
+ * The type of movement.
+ *
+ * Some of these movements may be modified by using the modify-repeat action.
+ * First adjust the repeat and then perform the "movement" action.
+ */
+typedef enum
+{
+ IDE_SOURCE_VIEW_MOVEMENT_NTH_CHAR,
+ IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_CHAR,
+ IDE_SOURCE_VIEW_MOVEMENT_NEXT_CHAR,
+ IDE_SOURCE_VIEW_MOVEMENT_FIRST_CHAR,
+ IDE_SOURCE_VIEW_MOVEMENT_FIRST_NONSPACE_CHAR,
+ IDE_SOURCE_VIEW_MOVEMENT_MIDDLE_CHAR,
+ IDE_SOURCE_VIEW_MOVEMENT_LAST_CHAR,
+
+ IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_WORD_START,
+ IDE_SOURCE_VIEW_MOVEMENT_NEXT_WORD_START,
+
+ IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_WORD_END,
+ IDE_SOURCE_VIEW_MOVEMENT_NEXT_WORD_END,
+
+ IDE_SOURCE_VIEW_MOVEMENT_SENTANCE_START,
+ IDE_SOURCE_VIEW_MOVEMENT_SENTANCE_END,
+
+ IDE_SOURCE_VIEW_MOVEMENT_PARAGRAPH_START,
+ IDE_SOURCE_VIEW_MOVEMENT_PARAGRAPH_END,
+
+ IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_LINE,
+ IDE_SOURCE_VIEW_MOVEMENT_NEXT_LINE,
+
+ IDE_SOURCE_VIEW_MOVEMENT_FIRST_LINE,
+ IDE_SOURCE_VIEW_MOVEMENT_NTH_LINE,
+ IDE_SOURCE_VIEW_MOVEMENT_LAST_LINE,
+ IDE_SOURCE_VIEW_MOVEMENT_LINE_PERCENTAGE,
+
+ IDE_SOURCE_VIEW_MOVEMENT_HALF_PAGE_UP,
+ IDE_SOURCE_VIEW_MOVEMENT_HALF_PAGE_DOWN,
+
+ IDE_SOURCE_VIEW_MOVEMENT_PAGE_UP,
+ IDE_SOURCE_VIEW_MOVEMENT_PAGE_DOWN,
+
+ IDE_SOURCE_VIEW_MOVEMENT_SCREEN_UP,
+ IDE_SOURCE_VIEW_MOVEMENT_SCREEN_DOWN,
+ IDE_SOURCE_VIEW_MOVEMENT_SCREEN_TOP,
+ IDE_SOURCE_VIEW_MOVEMENT_SCREEN_MIDDLE,
+ IDE_SOURCE_VIEW_MOVEMENT_SCREEN_BOTTOM,
+
+ IDE_SOURCE_VIEW_MOVEMENT_MATCH_SPECIAL,
+} IdeSourceViewMovement;
+
G_DEFINE_AUTOPTR_CLEANUP_FUNC (IdeSourceView, g_object_unref)
struct _IdeSourceView
@@ -62,21 +151,24 @@ struct _IdeSourceViewClass
{
GtkSourceViewClass parent_class;
- void (*action) (IdeSourceView *self,
- const gchar *prefix,
- const gchar *action_name,
- const gchar *param);
- void (*jump) (IdeSourceView *self,
- const GtkTextIter *location);
- void (*pop_snippet) (IdeSourceView *self,
- IdeSourceSnippet *snippet);
- void (*push_snippet) (IdeSourceView *self,
- IdeSourceSnippet *snippet,
- IdeSourceSnippetContext *context,
- const GtkTextIter *location);
- void (*set_mode) (IdeSourceView *self,
- const gchar *mode,
- IdeSourceViewModeType type);
+ void (*action) (IdeSourceView *self,
+ const gchar *prefix,
+ const gchar *action_name,
+ const gchar *param);
+ void (*movement) (IdeSourceView *self,
+ IdeSourceViewMovement movement,
+ gboolean extend_selection);
+ void (*jump) (IdeSourceView *self,
+ const GtkTextIter *location);
+ void (*pop_snippet) (IdeSourceView *self,
+ IdeSourceSnippet *snippet);
+ void (*push_snippet) (IdeSourceView *self,
+ IdeSourceSnippet *snippet,
+ IdeSourceSnippetContext *context,
+ const GtkTextIter *location);
+ void (*set_mode) (IdeSourceView *self,
+ const gchar *mode,
+ IdeSourceViewModeType type);
};
void ide_source_view_clear_snippets (IdeSourceView *self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]