Optimization of command handling.
Этот коммит содержится в:
родитель
e85f6b23e3
Коммит
5592a472f6
@ -47,8 +47,9 @@
|
||||
|
||||
#include "../src/tty/tty.h" /* keys */
|
||||
#include "../src/tty/key.h" /* KEY_M_SHIFT */
|
||||
#include "../src/cmddef.h" /* list of commands */
|
||||
|
||||
#include "../src/cmddef.h" /* list of commands */
|
||||
#include "../src/keybind.h" /* lookup_keymap_command() */
|
||||
#include "../src/charsets.h" /* convert_from_input_c() */
|
||||
#include "../src/main.h" /* display_codepage */
|
||||
#include "../src/strutil.h" /* str_isutf8 () */
|
||||
@ -62,7 +63,6 @@ edit_translate_key (WEdit *edit, long x_key, int *cmd, int *ch)
|
||||
{
|
||||
unsigned long command = (unsigned long) CK_Insert_Char;
|
||||
int char_for_insertion = -1;
|
||||
size_t i = 0;
|
||||
int c;
|
||||
|
||||
/* an ordinary insertable character */
|
||||
@ -146,20 +146,13 @@ edit_translate_key (WEdit *edit, long x_key, int *cmd, int *ch)
|
||||
/* Commands specific to the key emulation */
|
||||
if (edit->extmod) {
|
||||
edit->extmod = 0;
|
||||
for (i = 0; editor_x_map[i].key; i++) {
|
||||
if (x_key == editor_x_map[i].key) {
|
||||
command = editor_x_map[i].command;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (i = 0; editor_map[i].key != 0; i++) {
|
||||
if (x_key == editor_map[i].key) {
|
||||
command = editor_map[i].command;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
command = lookup_keymap_command (editor_x_map, x_key);
|
||||
} else
|
||||
command = lookup_keymap_command (editor_map, x_key);
|
||||
|
||||
if (command == CK_Ignore_Key)
|
||||
command = CK_Insert_Char;
|
||||
|
||||
fin:
|
||||
*cmd = (int) command; /* FIXME */
|
||||
*ch = char_for_insertion;
|
||||
|
@ -317,22 +317,22 @@ edit_set_buttonbar (WEdit *edit)
|
||||
buttonbar_set_label_data (bb, 10, Q_("ButtonBar|Quit"), (buttonbarfn) cmd_F10, edit);
|
||||
}
|
||||
|
||||
void edit_update_screen (WEdit * e)
|
||||
void
|
||||
edit_update_screen (WEdit * e)
|
||||
{
|
||||
edit_scroll_screen_over_cursor (e);
|
||||
|
||||
edit_update_curs_col (e);
|
||||
edit_status (e);
|
||||
|
||||
/* pop all events for this window for internal handling */
|
||||
|
||||
if (!is_idle ()) {
|
||||
/* pop all events for this window for internal handling */
|
||||
if (!is_idle ())
|
||||
e->force |= REDRAW_PAGE;
|
||||
return;
|
||||
else {
|
||||
if (e->force & REDRAW_COMPLETELY)
|
||||
e->force |= REDRAW_PAGE;
|
||||
edit_render_keypress (e);
|
||||
}
|
||||
if (e->force & REDRAW_COMPLETELY)
|
||||
e->force |= REDRAW_PAGE;
|
||||
edit_render_keypress (e);
|
||||
}
|
||||
|
||||
static cb_ret_t
|
||||
|
@ -944,3 +944,15 @@ lookup_keymap_shortcut (const global_keymap_t *keymap, unsigned long action)
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
unsigned long
|
||||
lookup_keymap_command (const global_keymap_t *keymap, long key)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; keymap[i].key != 0; i++)
|
||||
if (keymap[i].key == key)
|
||||
return keymap[i].command;
|
||||
|
||||
return CK_Ignore_Key;
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ typedef struct global_keymap_t {
|
||||
void keybind_cmd_bind (GArray *keymap, const char *keybind, unsigned long action);
|
||||
unsigned long lookup_action (const char *keyname);
|
||||
const char *lookup_keymap_shortcut (const global_keymap_t *keymap, unsigned long action);
|
||||
unsigned long lookup_keymap_command (const global_keymap_t *keymap, long key);
|
||||
|
||||
/* viewer/actions_cmd.c */
|
||||
extern const global_keymap_t default_viewer_keymap[];
|
||||
|
28
src/main.c
28
src/main.c
@ -1587,7 +1587,8 @@ done_mc_profile (void)
|
||||
static cb_ret_t
|
||||
midnight_callback (struct Dlg_head *h, dlg_msg_t msg, int parm)
|
||||
{
|
||||
int i;
|
||||
unsigned long command;
|
||||
|
||||
switch (msg) {
|
||||
|
||||
case DLG_IDLE:
|
||||
@ -1600,9 +1601,9 @@ midnight_callback (struct Dlg_head *h, dlg_msg_t msg, int parm)
|
||||
case DLG_KEY:
|
||||
if (ctl_x_map_enabled) {
|
||||
ctl_x_map_enabled = FALSE;
|
||||
for (i = 0; main_x_map[i].key; i++)
|
||||
if (parm == main_x_map[i].key)
|
||||
return midnight_execute_cmd (NULL, NULL, main_x_map[i].command, NULL);
|
||||
command = lookup_keymap_command (main_x_map, parm);
|
||||
if (command != CK_Ignore_Key)
|
||||
return midnight_execute_cmd (NULL, NULL, command, NULL);
|
||||
}
|
||||
|
||||
/* FIXME: should handle all menu shortcuts before this point */
|
||||
@ -1613,6 +1614,8 @@ midnight_callback (struct Dlg_head *h, dlg_msg_t msg, int parm)
|
||||
free_completions (cmdline);
|
||||
|
||||
if (parm == '\n') {
|
||||
size_t i;
|
||||
|
||||
for (i = 0; cmdline->buffer[i] && (cmdline->buffer[i] == ' ' ||
|
||||
cmdline->buffer[i] == '\t'); i++)
|
||||
;
|
||||
@ -1694,17 +1697,16 @@ midnight_callback (struct Dlg_head *h, dlg_msg_t msg, int parm)
|
||||
if (v == MSG_HANDLED)
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
|
||||
if (ctl_x_map_enabled) {
|
||||
ctl_x_map_enabled = FALSE;
|
||||
for (i = 0; main_x_map[i].key; i++)
|
||||
if (parm == main_x_map[i].key)
|
||||
return midnight_execute_cmd (NULL, NULL, main_x_map[i].command, NULL);
|
||||
} else {
|
||||
for (i = 0; main_map[i].key; i++)
|
||||
if (parm == main_map[i].key)
|
||||
return midnight_execute_cmd (NULL, NULL, main_map[i].command, NULL);
|
||||
}
|
||||
return MSG_NOT_HANDLED;
|
||||
command = lookup_keymap_command (main_x_map, parm);
|
||||
} else
|
||||
command = lookup_keymap_command (main_map, parm);
|
||||
|
||||
return (command == CK_Ignore_Key)
|
||||
? MSG_NOT_HANDLED
|
||||
: midnight_execute_cmd (NULL, NULL, command, NULL);
|
||||
|
||||
case DLG_DRAW:
|
||||
load_hint (1);
|
||||
|
@ -456,25 +456,25 @@ mcview_execute_cmd (Widget *sender, Widget *receiver,
|
||||
static cb_ret_t
|
||||
mcview_handle_key (mcview_t * view, int key)
|
||||
{
|
||||
int i;
|
||||
unsigned long command;
|
||||
|
||||
key = convert_from_input_c (key);
|
||||
|
||||
if (view->hex_mode) {
|
||||
if (view->hexedit_mode)
|
||||
if (mcview_handle_editkey (view, key) == MSG_HANDLED)
|
||||
if (view->hexedit_mode
|
||||
&& (mcview_handle_editkey (view, key) == MSG_HANDLED))
|
||||
return MSG_HANDLED;
|
||||
|
||||
command = lookup_keymap_command (view->hex_map, key);
|
||||
if ((command != CK_Ignore_Key)
|
||||
&& (mcview_execute_cmd (NULL, &view->widget, command, NULL) == MSG_HANDLED))
|
||||
return MSG_HANDLED;
|
||||
for (i = 0; view->hex_map[i].key != 0; i++)
|
||||
if ((key == view->hex_map[i].key)
|
||||
&& (mcview_execute_cmd (NULL, (Widget *) view,
|
||||
view->hex_map[i].command, (const void *) key) == MSG_HANDLED))
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
for (i = 0; view->plain_map[i].key != 0; i++)
|
||||
if ((key == view->plain_map[i].key)
|
||||
&& (mcview_execute_cmd (NULL, (Widget *) view,
|
||||
view->plain_map[i].command, (const void *) key) == MSG_HANDLED))
|
||||
return MSG_HANDLED;
|
||||
|
||||
command = lookup_keymap_command (view->plain_map, key);
|
||||
if ((command != CK_Ignore_Key)
|
||||
&& (mcview_execute_cmd (NULL, &view->widget, command, NULL) == MSG_HANDLED))
|
||||
return MSG_HANDLED;
|
||||
|
||||
if (mcview_check_left_right_keys (view, key))
|
||||
return MSG_HANDLED;
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user