From 82b7c4fdeeafc87e21a902e7ff8554cde55f507b Mon Sep 17 00:00:00 2001 From: Ilia Maslakov Date: Fri, 23 Oct 2009 17:58:01 +0000 Subject: [PATCH] Add support for multi-hotkeys in editor (like a ctrl-x,t). Signed-off-by: Ilia Maslakov --- edit/edit-widget.h | 1 + edit/edit.c | 3 +++ edit/editkeys.c | 23 ++++++++++++++++------- src/keybind.c | 4 ++++ src/main.c | 1 + src/main.h | 1 + src/setup.c | 18 ++++++++++-------- 7 files changed, 36 insertions(+), 15 deletions(-) diff --git a/edit/edit-widget.h b/edit/edit-widget.h index 31c1c0d40..99b9795b1 100644 --- a/edit/edit-widget.h +++ b/edit/edit-widget.h @@ -127,6 +127,7 @@ struct WEdit { /* user map stuff */ GIConv converter; const global_keymap_t *user_map; + const global_keymap_t *user_x_map; /* line break */ LineBreaks lb; diff --git a/edit/edit.c b/edit/edit.c index 7b0572d9c..e619a8d2f 100644 --- a/edit/edit.c +++ b/edit/edit.c @@ -726,6 +726,9 @@ edit_set_keymap (WEdit *edit) edit->user_map = default_editor_keymap; if (editor_keymap && editor_keymap->len > 0) edit->user_map = (global_keymap_t *) editor_keymap->data; + edit->user_x_map = default_editor_x_keymap; + if (editor_x_keymap && editor_x_keymap->len > 0) + edit->user_x_map = (global_keymap_t *) editor_x_keymap->data; } diff --git a/edit/editkeys.c b/edit/editkeys.c index 406d93b92..6dfa149eb 100644 --- a/edit/editkeys.c +++ b/edit/editkeys.c @@ -63,11 +63,10 @@ edit_translate_key (WEdit *edit, long x_key, int *cmd, int *ch) int command = CK_Insert_Char; int char_for_insertion = -1; int i = 0; - int extmod = 0; int c; /* an ordinary insertable character */ - if (x_key < 256 && !extmod) { + if (x_key < 256) { #ifdef HAVE_CHARSET if ( edit->charpoint >= 4 ) { edit->charpoint = 0; @@ -145,12 +144,22 @@ edit_translate_key (WEdit *edit, long x_key, int *cmd, int *ch) } /* Commands specific to the key emulation */ - for (i = 0; edit->user_map[i].key != 0; i++) - if (x_key == edit->user_map[i].key) { - command = edit->user_map[i].command; - break; + if (edit->extmod) { + edit->extmod = 0; + for (i = 0; edit->user_x_map[i].key; i++) { + if (x_key == edit->user_x_map[i].key) { + command = edit->user_x_map[i].command; + break; + } } - + } else { + for (i = 0; edit->user_map[i].key != 0; i++) { + if (x_key == edit->user_map[i].key) { + command = edit->user_map[i].command; + break; + } + } + } fin: *cmd = command; *ch = char_for_insertion; diff --git a/src/keybind.c b/src/keybind.c index d25154b62..15aa38fee 100644 --- a/src/keybind.c +++ b/src/keybind.c @@ -594,6 +594,10 @@ const global_keymap_t default_editor_keymap[] = { { 0, 0, "" } }; + +const global_keymap_t default_editor_x_keymap[] = { + { 0, 0, "" } +}; #endif /* screen.c */ diff --git a/src/main.c b/src/main.c index 2f927b0c5..636ccf2e8 100644 --- a/src/main.c +++ b/src/main.c @@ -308,6 +308,7 @@ mc_main_error_quark (void) #ifdef USE_INTERNAL_EDIT GArray *editor_keymap = NULL; +GArray *editor_x_keymap = NULL; #endif GArray *viewer_keymap = NULL; GArray *viewer_hex_keymap = NULL; diff --git a/src/main.h b/src/main.h index 475cce74b..1c195ff0d 100644 --- a/src/main.h +++ b/src/main.h @@ -77,6 +77,7 @@ extern int is_right; /* If the selected menu was the right */ #ifdef USE_INTERNAL_EDIT extern GArray *editor_keymap; +extern GArray *editor_x_keymap; #endif extern GArray *viewer_keymap; extern GArray *viewer_hex_keymap; diff --git a/src/setup.c b/src/setup.c index 9f221ac40..3598fab10 100644 --- a/src/setup.c +++ b/src/setup.c @@ -966,29 +966,31 @@ load_keymap_defs (void) if (mc_global_keymap != NULL) { #ifdef USE_INTERNAL_EDIT - editor_keymap = g_array_new(TRUE, FALSE, sizeof (global_keymap_t)); + editor_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t)); load_keymap_from_section ("editor", editor_keymap, mc_global_keymap); + editor_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t)); + load_keymap_from_section ("editor:xmap", editor_x_keymap, mc_global_keymap); #endif - viewer_keymap = g_array_new(TRUE, FALSE, sizeof (global_keymap_t)); + viewer_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t)); load_keymap_from_section ("viewer", viewer_keymap, mc_global_keymap); - viewer_hex_keymap = g_array_new(TRUE, FALSE, sizeof (global_keymap_t)); + viewer_hex_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t)); load_keymap_from_section ("viewer:hex", viewer_hex_keymap, mc_global_keymap); - main_keymap = g_array_new(TRUE, FALSE, sizeof (global_keymap_t)); + main_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t)); load_keymap_from_section ("main", main_keymap, mc_global_keymap); - main_x_keymap = g_array_new(TRUE, FALSE, sizeof (global_keymap_t)); + main_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t)); load_keymap_from_section ("main:xmap", main_x_keymap, mc_global_keymap); - panel_keymap = g_array_new(TRUE, FALSE, sizeof (global_keymap_t)); + panel_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t)); load_keymap_from_section ("panel", panel_keymap, mc_global_keymap); - input_keymap = g_array_new(TRUE, FALSE, sizeof (global_keymap_t)); + input_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t)); load_keymap_from_section ("input", input_keymap, mc_global_keymap); - mc_config_deinit(mc_global_keymap); + mc_config_deinit (mc_global_keymap); } }