text: Port to widget shortcuts

This commit is contained in:
Emmanuele Bassi 2020-02-05 17:13:44 +00:00 committed by Matthias Clasen
parent d75fd59ddf
commit 00bc9e6b85

View File

@ -679,7 +679,7 @@ G_DEFINE_TYPE_WITH_CODE (GtkText, gtk_text, GTK_TYPE_WIDGET,
G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE, gtk_text_editable_init)) G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE, gtk_text_editable_init))
static void static void
add_move_binding (GtkBindingSet *binding_set, add_move_binding (GtkWidgetClass *widget_class,
guint keyval, guint keyval,
guint modmask, guint modmask,
GtkMovementStep step, GtkMovementStep step,
@ -687,28 +687,22 @@ add_move_binding (GtkBindingSet *binding_set,
{ {
g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0); g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
gtk_binding_entry_add_signal (binding_set, keyval, modmask, gtk_widget_class_add_binding_signal (widget_class,
"move-cursor", 3, keyval, modmask,
G_TYPE_ENUM, step, "move-cursor",
G_TYPE_INT, count, "(iib)", step, count, FALSE);
G_TYPE_BOOLEAN, FALSE);
/* Selection-extending version */ /* Selection-extending version */
gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK, gtk_widget_class_add_binding_signal (widget_class,
"move-cursor", 3, keyval, modmask | GDK_SHIFT_MASK,
G_TYPE_ENUM, step, "move-cursor",
G_TYPE_INT, count, "(iib)", step, count, TRUE);
G_TYPE_BOOLEAN, TRUE);
} }
static void static void
gtk_text_class_init (GtkTextClass *class) gtk_text_class_init (GtkTextClass *class)
{ {
GObjectClass *gobject_class = G_OBJECT_CLASS (class); GObjectClass *gobject_class = G_OBJECT_CLASS (class);
GtkWidgetClass *widget_class; GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
GtkBindingSet *binding_set;
widget_class = (GtkWidgetClass*) class;
gobject_class->dispose = gtk_text_dispose; gobject_class->dispose = gtk_text_dispose;
gobject_class->finalize = gtk_text_finalize; gobject_class->finalize = gtk_text_finalize;
@ -1201,183 +1195,203 @@ gtk_text_class_init (GtkTextClass *class)
* Key bindings * Key bindings
*/ */
binding_set = gtk_binding_set_by_class (class);
/* Moving the insertion point */ /* Moving the insertion point */
add_move_binding (binding_set, GDK_KEY_Right, 0, add_move_binding (widget_class, GDK_KEY_Right, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, 1); GTK_MOVEMENT_VISUAL_POSITIONS, 1);
add_move_binding (binding_set, GDK_KEY_Left, 0, add_move_binding (widget_class, GDK_KEY_Left, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, -1); GTK_MOVEMENT_VISUAL_POSITIONS, -1);
add_move_binding (binding_set, GDK_KEY_KP_Right, 0, add_move_binding (widget_class, GDK_KEY_KP_Right, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, 1); GTK_MOVEMENT_VISUAL_POSITIONS, 1);
add_move_binding (binding_set, GDK_KEY_KP_Left, 0, add_move_binding (widget_class, GDK_KEY_KP_Left, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, -1); GTK_MOVEMENT_VISUAL_POSITIONS, -1);
add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK, add_move_binding (widget_class, GDK_KEY_Right, GDK_CONTROL_MASK,
GTK_MOVEMENT_WORDS, 1); GTK_MOVEMENT_WORDS, 1);
add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK, add_move_binding (widget_class, GDK_KEY_Left, GDK_CONTROL_MASK,
GTK_MOVEMENT_WORDS, -1); GTK_MOVEMENT_WORDS, -1);
add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK, add_move_binding (widget_class, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
GTK_MOVEMENT_WORDS, 1); GTK_MOVEMENT_WORDS, 1);
add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK, add_move_binding (widget_class, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
GTK_MOVEMENT_WORDS, -1); GTK_MOVEMENT_WORDS, -1);
add_move_binding (binding_set, GDK_KEY_Home, 0, add_move_binding (widget_class, GDK_KEY_Home, 0,
GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1); GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
add_move_binding (binding_set, GDK_KEY_End, 0, add_move_binding (widget_class, GDK_KEY_End, 0,
GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1); GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
add_move_binding (binding_set, GDK_KEY_KP_Home, 0, add_move_binding (widget_class, GDK_KEY_KP_Home, 0,
GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1); GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
add_move_binding (binding_set, GDK_KEY_KP_End, 0, add_move_binding (widget_class, GDK_KEY_KP_End, 0,
GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1); GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK, add_move_binding (widget_class, GDK_KEY_Home, GDK_CONTROL_MASK,
GTK_MOVEMENT_BUFFER_ENDS, -1); GTK_MOVEMENT_BUFFER_ENDS, -1);
add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK, add_move_binding (widget_class, GDK_KEY_End, GDK_CONTROL_MASK,
GTK_MOVEMENT_BUFFER_ENDS, 1); GTK_MOVEMENT_BUFFER_ENDS, 1);
add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK, add_move_binding (widget_class, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
GTK_MOVEMENT_BUFFER_ENDS, -1); GTK_MOVEMENT_BUFFER_ENDS, -1);
add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK, add_move_binding (widget_class, GDK_KEY_KP_End, GDK_CONTROL_MASK,
GTK_MOVEMENT_BUFFER_ENDS, 1); GTK_MOVEMENT_BUFFER_ENDS, 1);
/* Select all /* Select all
*/ */
gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK, gtk_widget_class_add_binding (widget_class,
"move-cursor", 3, GDK_KEY_a, GDK_CONTROL_MASK,
GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS, (GtkShortcutFunc) gtk_text_select_all,
G_TYPE_INT, -1, NULL);
G_TYPE_BOOLEAN, FALSE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
"move-cursor", 3,
GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
G_TYPE_INT, 1,
G_TYPE_BOOLEAN, TRUE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK, gtk_widget_class_add_binding (widget_class,
"move-cursor", 3, GDK_KEY_slash, GDK_CONTROL_MASK,
GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS, (GtkShortcutFunc) gtk_text_select_all,
G_TYPE_INT, -1, NULL);
G_TYPE_BOOLEAN, FALSE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
"move-cursor", 3,
GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
G_TYPE_INT, 1,
G_TYPE_BOOLEAN, TRUE);
/* Unselect all /* Unselect all
*/ */
gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK, gtk_widget_class_add_binding_signal (widget_class,
"move-cursor", 3, GDK_KEY_backslash, GDK_CONTROL_MASK,
GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS, "move-cursor",
G_TYPE_INT, 0, "(iib)", GTK_MOVEMENT_VISUAL_POSITIONS, 0, FALSE);
G_TYPE_BOOLEAN, FALSE); gtk_widget_class_add_binding_signal (widget_class,
gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
"move-cursor", 3, "move-cursor",
GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS, "(iib)", GTK_MOVEMENT_VISUAL_POSITIONS, 0, FALSE);
G_TYPE_INT, 0,
G_TYPE_BOOLEAN, FALSE);
/* Activate /* Activate
*/ */
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0, gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_Return, 0,
"activate", 0); "activate",
gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0, NULL);
"activate", 0); gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_ISO_Enter, 0,
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0, "activate",
"activate", 0); NULL);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_KP_Enter, 0,
"activate",
NULL);
/* Deleting text */ /* Deleting text */
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0, gtk_widget_class_add_binding_signal (widget_class,
"delete-from-cursor", 2, GDK_KEY_Delete, 0,
G_TYPE_ENUM, GTK_DELETE_CHARS, "delete-from-cursor",
G_TYPE_INT, 1); "(ii)", GTK_DELETE_CHARS, 1);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0, gtk_widget_class_add_binding_signal (widget_class,
"delete-from-cursor", 2, GDK_KEY_KP_Delete, 0,
G_TYPE_ENUM, GTK_DELETE_CHARS, "delete-from-cursor",
G_TYPE_INT, 1); "(ii)", GTK_DELETE_CHARS, 1);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0, gtk_widget_class_add_binding_signal (widget_class,
"backspace", 0); GDK_KEY_BackSpace, 0,
"backspace",
NULL);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_u, GDK_CONTROL_MASK, gtk_widget_class_add_binding_signal (widget_class,
"delete-from-cursor", 2, GDK_KEY_u, GDK_CONTROL_MASK,
G_TYPE_ENUM, GTK_DELETE_PARAGRAPH_ENDS, "delete-from-cursor",
G_TYPE_INT, -1); "(ii)", GTK_DELETE_PARAGRAPH_ENDS, -1);
/* Make this do the same as Backspace, to help with mis-typing */ /* Make this do the same as Backspace, to help with mis-typing */
gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK, gtk_widget_class_add_binding_signal (widget_class,
"backspace", 0); GDK_KEY_BackSpace, GDK_SHIFT_MASK,
"backspace",
NULL);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK, gtk_widget_class_add_binding_signal (widget_class,
"delete-from-cursor", 2, GDK_KEY_Delete, GDK_CONTROL_MASK,
G_TYPE_ENUM, GTK_DELETE_WORD_ENDS, "delete-from-cursor",
G_TYPE_INT, 1); "(ii)", GTK_DELETE_WORD_ENDS, 1);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK, gtk_widget_class_add_binding_signal (widget_class,
"delete-from-cursor", 2, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
G_TYPE_ENUM, GTK_DELETE_WORD_ENDS, "delete-from-cursor",
G_TYPE_INT, 1); "(ii)", GTK_DELETE_WORD_ENDS, 1);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK, gtk_widget_class_add_binding_signal (widget_class,
"delete-from-cursor", 2, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
G_TYPE_ENUM, GTK_DELETE_WORD_ENDS, "delete-from-cursor",
G_TYPE_INT, -1); "(ii)", GTK_DELETE_WORD_ENDS, -1);
/* Cut/copy/paste */ /* Cut/copy/paste */
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_x, GDK_CONTROL_MASK,
"cut-clipboard",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_c, GDK_CONTROL_MASK,
"copy-clipboard",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_v, GDK_CONTROL_MASK,
"paste-clipboard",
NULL);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK, gtk_widget_class_add_binding_signal (widget_class,
"cut-clipboard", 0); GDK_KEY_Delete, GDK_SHIFT_MASK,
gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK, "cut-clipboard",
"copy-clipboard", 0); NULL);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK, gtk_widget_class_add_binding_signal (widget_class,
"paste-clipboard", 0); GDK_KEY_Insert, GDK_CONTROL_MASK,
"copy-clipboard",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Insert, GDK_SHIFT_MASK,
"paste-clipboard",
NULL);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK, gtk_widget_class_add_binding_signal (widget_class,
"cut-clipboard", 0); GDK_KEY_KP_Delete, GDK_SHIFT_MASK,
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK, "cut-clipboard",
"copy-clipboard", 0); NULL);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK, gtk_widget_class_add_binding_signal (widget_class,
"paste-clipboard", 0); GDK_KEY_KP_Insert, GDK_CONTROL_MASK,
"copy-clipboard",
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_SHIFT_MASK, NULL);
"cut-clipboard", 0); gtk_widget_class_add_binding_signal (widget_class,
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, GDK_CONTROL_MASK, GDK_KEY_KP_Insert, GDK_SHIFT_MASK,
"copy-clipboard", 0); "paste-clipboard",
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, GDK_SHIFT_MASK, NULL);
"paste-clipboard", 0);
/* Overwrite */ /* Overwrite */
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0, gtk_widget_class_add_binding_signal (widget_class,
"toggle-overwrite", 0); GDK_KEY_Insert, 0,
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0, "toggle-overwrite",
"toggle-overwrite", 0); NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Insert, 0,
"toggle-overwrite",
NULL);
/* Emoji */ /* Emoji */
gtk_binding_entry_add_signal (binding_set, GDK_KEY_period, GDK_CONTROL_MASK, gtk_widget_class_add_binding_signal (widget_class,
"insert-emoji", 0); GDK_KEY_period, GDK_CONTROL_MASK,
gtk_binding_entry_add_signal (binding_set, GDK_KEY_semicolon, GDK_CONTROL_MASK, "insert-emoji",
"insert-emoji", 0); NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_semicolon, GDK_CONTROL_MASK,
"insert-emoji",
NULL);
/* Undo/Redo */ /* Undo/Redo */
gtk_binding_entry_add_action (binding_set, GDK_KEY_z, GDK_CONTROL_MASK, gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_z, GDK_CONTROL_MASK,
"text.undo", NULL); "text.undo", NULL);
gtk_binding_entry_add_action (binding_set, GDK_KEY_y, GDK_CONTROL_MASK, gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_y, GDK_CONTROL_MASK,
"text.redo", NULL); "text.redo", NULL);
gtk_binding_entry_add_action (binding_set, GDK_KEY_z, GDK_CONTROL_MASK | GDK_SHIFT_MASK, gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_z, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"text.redo", NULL); "text.redo", NULL);
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_TEXT_ACCESSIBLE); gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_TEXT_ACCESSIBLE);
gtk_widget_class_set_css_name (widget_class, I_("text")); gtk_widget_class_set_css_name (widget_class, I_("text"));