mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 12:32:40 +03:00
Ticket #212: implement keybinding for menu.
Signed-off-by: Ilia Maslakov <il.smind@gmail.com> Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
71c0f7640d
commit
f5f78ea658
@ -13,6 +13,7 @@
|
||||
#define KEYMAP_SECTION_MAIN_EXT "main:xmap"
|
||||
#define KEYMAP_SECTION_PANEL "panel"
|
||||
#define KEYMAP_SECTION_DIALOG "dialog"
|
||||
#define KEYMAP_SECTION_MENU "menu"
|
||||
#define KEYMAP_SECTION_INPUT "input"
|
||||
#define KEYMAP_SECTION_LISTBOX "listbox"
|
||||
#define KEYMAP_SECTION_TREE "tree"
|
||||
|
@ -39,12 +39,15 @@
|
||||
#include "lib/tty/tty.h"
|
||||
#include "lib/skin.h"
|
||||
#include "lib/tty/key.h" /* key macros */
|
||||
#include "lib/keybind.h" /* global_keymap_t */
|
||||
#include "lib/strutil.h"
|
||||
#include "lib/widget.h"
|
||||
#include "lib/event.h" /* mc_event_raise() */
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
const global_keymap_t *menu_map;
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#define MENUENTRY(x) ((menu_entry_t *)(x))
|
||||
@ -449,23 +452,14 @@ menubar_last (WMenuBar * menubar)
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
menubar_handle_key (WMenuBar * menubar, int key)
|
||||
static cb_ret_t
|
||||
menubar_execute_cmd (WMenuBar * menubar, unsigned long command, int key)
|
||||
{
|
||||
/* Lowercase */
|
||||
if (isascii (key))
|
||||
key = g_ascii_tolower (key);
|
||||
cb_ret_t ret = MSG_HANDLED;
|
||||
|
||||
if (is_abort_char (key))
|
||||
switch (command)
|
||||
{
|
||||
menubar_finish (menubar);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* menubar help or menubar navigation */
|
||||
switch (key)
|
||||
{
|
||||
case KEY_F (1):
|
||||
case CK_Help:
|
||||
{
|
||||
ev_help_t event_data = { NULL, NULL };
|
||||
|
||||
@ -477,98 +471,64 @@ menubar_handle_key (WMenuBar * menubar, int key)
|
||||
|
||||
mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
|
||||
menubar_draw (menubar);
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case KEY_LEFT:
|
||||
case XCTRL ('b'):
|
||||
case CK_Left:
|
||||
menubar_left (menubar);
|
||||
return 1;
|
||||
|
||||
case KEY_RIGHT:
|
||||
case XCTRL ('f'):
|
||||
break;
|
||||
case CK_Right:
|
||||
menubar_right (menubar);
|
||||
return 1;
|
||||
break;
|
||||
case CK_Up:
|
||||
if (menubar->is_dropped)
|
||||
menubar_up (menubar);
|
||||
break;
|
||||
case CK_Down:
|
||||
if (menubar->is_dropped)
|
||||
menubar_down (menubar);
|
||||
else
|
||||
menubar_drop (menubar, menubar->selected);
|
||||
break;
|
||||
case CK_Home:
|
||||
if (menubar->is_dropped)
|
||||
menubar_first (menubar);
|
||||
break;
|
||||
case CK_End:
|
||||
if (menubar->is_dropped)
|
||||
menubar_last (menubar);
|
||||
break;
|
||||
|
||||
case CK_Enter:
|
||||
if (menubar->is_dropped)
|
||||
menubar_execute (menubar);
|
||||
else
|
||||
menubar_drop (menubar, menubar->selected);
|
||||
break;
|
||||
case CK_Quit:
|
||||
menubar_finish (menubar);
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = MSG_NOT_HANDLED;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!menubar->is_dropped)
|
||||
{
|
||||
GList *i;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* drop menu by hotkey */
|
||||
for (i = menubar->menu; i != NULL; i = g_list_next (i))
|
||||
{
|
||||
menu_t *menu = MENU (i->data);
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
if ((menu->text.hotkey != NULL) && (key == g_ascii_tolower (menu->text.hotkey[0])))
|
||||
{
|
||||
menubar_drop (menubar, g_list_position (menubar->menu, i));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
static int
|
||||
menubar_handle_key (WMenuBar * menubar, int key)
|
||||
{
|
||||
unsigned long cmd;
|
||||
|
||||
/* drop menu by Enter or Dowwn key */
|
||||
if (key == KEY_ENTER || key == XCTRL ('n') || key == KEY_DOWN || key == '\n')
|
||||
menubar_drop (menubar, menubar->selected);
|
||||
cmd = keybind_lookup_keymap_command (menu_map, key);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
{
|
||||
menu_t *menu = MENU (g_list_nth_data (menubar->menu, menubar->selected));
|
||||
GList *i;
|
||||
|
||||
/* execute menu command by hotkey */
|
||||
for (i = menu->entries; i != NULL; i = g_list_next (i))
|
||||
{
|
||||
const menu_entry_t *entry = MENUENTRY (i->data);
|
||||
|
||||
if ((entry != NULL) && (entry->command != CK_IgnoreKey)
|
||||
&& (entry->text.hotkey != NULL) && (key == g_ascii_tolower (entry->text.hotkey[0])))
|
||||
{
|
||||
menu->selected = g_list_position (menu->entries, i);
|
||||
menubar_execute (menubar);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* menu execute by Enter or menu navigation */
|
||||
switch (key)
|
||||
{
|
||||
case KEY_ENTER:
|
||||
case '\n':
|
||||
menubar_execute (menubar);
|
||||
return 1;
|
||||
|
||||
case KEY_HOME:
|
||||
case ALT ('<'):
|
||||
menubar_first (menubar);
|
||||
break;
|
||||
|
||||
case KEY_END:
|
||||
case ALT ('>'):
|
||||
menubar_last (menubar);
|
||||
break;
|
||||
|
||||
case KEY_DOWN:
|
||||
case XCTRL ('n'):
|
||||
menubar_down (menubar);
|
||||
break;
|
||||
|
||||
case KEY_UP:
|
||||
case XCTRL ('p'):
|
||||
menubar_up (menubar);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return (cmd == CK_IgnoreKey
|
||||
|| menubar_execute_cmd (menubar, cmd,
|
||||
key) == MSG_NOT_HANDLED) ? MSG_NOT_HANDLED : MSG_HANDLED;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -143,6 +143,17 @@ ScreenList = alt-prime
|
||||
ScreenNext = alt-rbrace
|
||||
ScreenPrev = alt-lbrace
|
||||
|
||||
[menu]
|
||||
Help = f1
|
||||
Left = left; ctrl-b
|
||||
Right = right; ctrl-f
|
||||
Up = up; ctrl-p
|
||||
Down = down; ctrl-n
|
||||
Home = home; alt-lt; ctr-a
|
||||
End = end; alt-gt ctrl-e
|
||||
Enter = enter
|
||||
Quit = F10; esc; ctrl-g
|
||||
|
||||
[input]
|
||||
Home = ctrl-a; alt-lt; home; a1
|
||||
End = ctrl-e; alt-gt; end; c1
|
||||
|
@ -143,6 +143,17 @@ ScreenList = alt-prime
|
||||
ScreenNext = alt-rbrace
|
||||
ScreenPrev = alt-lbrace
|
||||
|
||||
[menu]
|
||||
Help = f1
|
||||
Left = left; ctrl-b
|
||||
Right = right; ctrl-f
|
||||
Up = up; ctrl-p
|
||||
Down = down; ctrl-n
|
||||
Home = home; alt-lt; ctr-a
|
||||
End = end; alt-gt ctrl-e
|
||||
Enter = enter
|
||||
Quit = F10; esc; ctrl-g
|
||||
|
||||
[input]
|
||||
Home = ctrl-a; alt-lt; home; a1
|
||||
End = ctrl-e; alt-gt; end; c1
|
||||
|
@ -38,6 +38,7 @@ GArray *main_keymap = NULL;
|
||||
GArray *main_x_keymap = NULL;
|
||||
GArray *panel_keymap = NULL;
|
||||
GArray *dialog_keymap = NULL;
|
||||
GArray *menu_keymap = NULL;
|
||||
GArray *input_keymap = NULL;
|
||||
GArray *listbox_keymap = NULL;
|
||||
GArray *tree_keymap = NULL;
|
||||
@ -55,6 +56,7 @@ GArray *diff_keymap = NULL;
|
||||
const global_keymap_t *main_map = NULL;
|
||||
const global_keymap_t *main_x_map = NULL;
|
||||
const global_keymap_t *panel_map = NULL;
|
||||
const global_keymap_t *menu_map = NULL;
|
||||
const global_keymap_t *tree_map = NULL;
|
||||
const global_keymap_t *help_map = NULL;
|
||||
|
||||
@ -225,6 +227,20 @@ static const global_keymap_ini_t default_dialog_keymap[] = {
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
/* menubar */
|
||||
static const global_keymap_ini_t default_menu_keymap[] = {
|
||||
{"Help", "f1"},
|
||||
{"Left", "left; ctrl-b"},
|
||||
{"Right", "right; ctrl-f"},
|
||||
{"Up", "up; ctrl-p"},
|
||||
{"Down", "down; enter; ctrl-n"},
|
||||
{"Home", "home; alt-lt; ctrl-a"},
|
||||
{"End", "end; alt-gt; ctrl-e"},
|
||||
{"Enter", "enter"},
|
||||
{"Quit", "f10; ctrl-g; esc"},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
/* input line */
|
||||
static const global_keymap_ini_t default_input_keymap[] = {
|
||||
/* Motion */
|
||||
@ -590,6 +606,7 @@ create_default_keymap (void)
|
||||
create_default_keymap_section (keymap, KEYMAP_SECTION_MAIN_EXT, default_main_x_keymap);
|
||||
create_default_keymap_section (keymap, KEYMAP_SECTION_PANEL, default_panel_keymap);
|
||||
create_default_keymap_section (keymap, KEYMAP_SECTION_DIALOG, default_dialog_keymap);
|
||||
create_default_keymap_section (keymap, KEYMAP_SECTION_MENU, default_menu_keymap);
|
||||
create_default_keymap_section (keymap, KEYMAP_SECTION_INPUT, default_input_keymap);
|
||||
create_default_keymap_section (keymap, KEYMAP_SECTION_LISTBOX, default_listbox_keymap);
|
||||
create_default_keymap_section (keymap, KEYMAP_SECTION_TREE, default_tree_keymap);
|
||||
|
@ -17,6 +17,7 @@ extern GArray *main_keymap;
|
||||
extern GArray *main_x_keymap;
|
||||
extern GArray *panel_keymap;
|
||||
extern GArray *dialog_keymap;
|
||||
extern GArray *menu_keymap;
|
||||
extern GArray *input_keymap;
|
||||
extern GArray *listbox_keymap;
|
||||
extern GArray *tree_keymap;
|
||||
@ -31,10 +32,10 @@ extern GArray *viewer_hex_keymap;
|
||||
extern GArray *diff_keymap;
|
||||
#endif
|
||||
|
||||
|
||||
extern const global_keymap_t *main_map;
|
||||
extern const global_keymap_t *main_x_map;
|
||||
extern const global_keymap_t *panel_map;
|
||||
extern const global_keymap_t *menu_map;
|
||||
extern const global_keymap_t *tree_map;
|
||||
extern const global_keymap_t *help_map;
|
||||
|
||||
|
@ -1365,6 +1365,9 @@ load_keymap_defs (gboolean load_from_file)
|
||||
dialog_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
|
||||
load_keymap_from_section (KEYMAP_SECTION_DIALOG, dialog_keymap, mc_global_keymap);
|
||||
|
||||
menu_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
|
||||
load_keymap_from_section (KEYMAP_SECTION_MENU, menu_keymap, mc_global_keymap);
|
||||
|
||||
input_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
|
||||
load_keymap_from_section (KEYMAP_SECTION_INPUT, input_keymap, mc_global_keymap);
|
||||
|
||||
@ -1401,6 +1404,7 @@ load_keymap_defs (gboolean load_from_file)
|
||||
main_x_map = (global_keymap_t *) main_x_keymap->data;
|
||||
panel_map = (global_keymap_t *) panel_keymap->data;
|
||||
dialog_map = (global_keymap_t *) dialog_keymap->data;
|
||||
menu_map = (global_keymap_t *) menu_keymap->data;
|
||||
input_map = (global_keymap_t *) input_keymap->data;
|
||||
listbox_map = (global_keymap_t *) listbox_keymap->data;
|
||||
tree_map = (global_keymap_t *) tree_keymap->data;
|
||||
|
Loading…
Reference in New Issue
Block a user