Commit dfdead66 authored by Sébastien Lafargue's avatar Sébastien Lafargue Committed by Christian Hergert

ide-source-view: add save-command css binding

We can now use "save-command" in css binding to remember the current
command so we can get it later in priv->command.
It's required by Vim mode when some commands rely on contextual
informations from a previous command.

It works by recording the current GdkEvent pressed key so you need
to put it at the start of your binding to work.

The command is also passed to _ide_source_view_apply_movement ()
movements dispatcher.
parent 43afdd06
......@@ -45,6 +45,7 @@ typedef struct
GtkTextIter insert; /* Current insert cursor location */
GtkTextIter selection; /* Current selection cursor location */
gint count; /* Repeat count for movement */
gunichar command; /* Command that trigger some movements type. See , and ; in vim */
gunichar modifier; /* For forward/backward char search */
guint extend_selection : 1; /* If selection should be extended */
guint exclusive : 1; /* See ":help exclusive" in vim */
......@@ -1246,6 +1247,7 @@ _ide_source_view_apply_movement (IdeSourceView *self,
gboolean extend_selection,
gboolean exclusive,
guint count,
gunichar command,
gunichar modifier,
gint *target_offset)
{
......@@ -1283,6 +1285,7 @@ _ide_source_view_apply_movement (IdeSourceView *self,
mv.count = count;
mv.ignore_select = FALSE;
mv.ignore_target_offset = FALSE;
mv.command = command;
mv.modifier = modifier;
ide_source_view_movements_get_selection (&mv);
......
......@@ -28,6 +28,7 @@ void _ide_source_view_apply_movement (IdeSourceView *source_view,
gboolean extend_selection,
gboolean exclusive,
guint count,
gunichar command,
gunichar modifier,
gint *target_offset);
......
......@@ -116,6 +116,7 @@ typedef struct
guint change_sequence;
gint target_line_offset;
gunichar command;
gunichar modifier;
guint count;
......@@ -242,6 +243,7 @@ enum {
REQUEST_DOCUMENTATION,
RESET_FONT_SIZE,
RESTORE_INSERT_MARK,
SAVE_COMMAND,
SAVE_INSERT_MARK,
SELECTION_THEATRIC,
SET_MODE,
......@@ -3155,8 +3157,10 @@ ide_source_view_real_movement (IdeSourceView *self,
if (priv->scrolling_to_scroll_mark)
priv->scrolling_to_scroll_mark = FALSE;
_ide_source_view_apply_movement (self, movement, extend_selection, exclusive,
count, priv->modifier, &priv->target_line_offset);
_ide_source_view_apply_movement (self,
movement, extend_selection, exclusive,
count, priv->command, priv->modifier,
&priv->target_line_offset);
}
static void
......@@ -3555,6 +3559,20 @@ ide_source_view_real_save_insert_mark (IdeSourceView *self)
priv->target_line_offset = priv->saved_line_offset;
}
static void
ide_source_view_real_save_command (IdeSourceView *self)
{
GdkEvent *event;
guint keyval;
IdeSourceViewPrivate *priv = ide_source_view_get_instance_private (self);
g_assert (IDE_IS_SOURCE_VIEW (self));
event = gtk_get_current_event ();
if (event && gdk_event_get_keyval (event, &keyval))
priv->command = (gunichar)keyval;
}
static void
ide_source_view__completion_hide_cb (IdeSourceView *self,
GtkSourceCompletion *completion)
......@@ -5470,6 +5488,7 @@ ide_source_view_class_init (IdeSourceViewClass *klass)
klass->replay_macro = ide_source_view_real_replay_macro;
klass->reset_font_size = ide_source_view_real_reset_font_size;
klass->restore_insert_mark = ide_source_view_real_restore_insert_mark;
klass->save_command = ide_source_view_real_save_command;
klass->save_insert_mark = ide_source_view_real_save_insert_mark;
klass->selection_theatric = ide_source_view_real_selection_theatric;
klass->set_mode = ide_source_view_real_set_mode;
......@@ -5716,6 +5735,16 @@ ide_source_view_class_init (IdeSourceViewClass *klass)
G_TYPE_NONE,
0);
gSignals [SAVE_COMMAND] =
g_signal_new ("save-command",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (IdeSourceViewClass, save_command),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
0);
/**
* IdeSourceView::capture-modifier:
*
......
......@@ -251,6 +251,7 @@ struct _IdeSourceViewClass
gboolean use_count);
void (*request_documentation) (IdeSourceView *self);
void (*restore_insert_mark) (IdeSourceView *self);
void (*save_command) (IdeSourceView *self);
void (*save_insert_mark) (IdeSourceView *self);
void (*selection_theatric) (IdeSourceView *self,
IdeSourceViewTheatric theatric);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment