From 68f058f98ccd5b08d8add4c0493b393ba45a257a Mon Sep 17 00:00:00 2001
From: Mooffie <mooffie@gmail.com>
Date: Mon, 14 Nov 2016 13:30:30 +0200
Subject: [PATCH] Ticket #3725: Don't limit hotkeys in user menu to simple
letters only.
---
src/filemanager/usermenu.c | 45 +++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 43 insertions(+), 2 deletions(-)
diff --git a/src/filemanager/usermenu.c b/src/filemanager/usermenu.c
index a9c3a02..3fd88ad 100644
a
|
b
|
|
39 | 39 | #include "lib/global.h" |
40 | 40 | #include "lib/fileloc.h" |
41 | 41 | #include "lib/tty/tty.h" |
| 42 | #include "lib/tty/key.h" /* lookup_key() */ |
42 | 43 | #include "lib/skin.h" |
43 | 44 | #include "lib/search.h" |
44 | 45 | #include "lib/vfs/vfs.h" |
… |
… |
menu_file_own (char *path) |
598 | 599 | } |
599 | 600 | |
600 | 601 | /* --------------------------------------------------------------------------------------------- */ |
| 602 | |
| 603 | /** |
| 604 | * Extracts the hotkey from a menu label. |
| 605 | * |
| 606 | * If the first word in the label is a valid hotkey name, its code is |
| 607 | * returned. Otherwise, the first character is assumed to be the hotkey. |
| 608 | * |
| 609 | * Examples: |
| 610 | * |
| 611 | * "c Copy file to clipboard" => (int)'c' |
| 612 | * "ctrl-c Copy file to clipboard" => 16387 (i.e., the keycode of "ctrl-c") |
| 613 | * "Copy file to clipboard" => (int)'C' |
| 614 | */ |
| 615 | static int |
| 616 | extract_hotkey (const char *s) |
| 617 | { |
| 618 | static char first_word[BUF_MEDIUM]; /* as in extract_line() */ |
| 619 | const char *p; |
| 620 | int hotkey; |
| 621 | |
| 622 | p = strpbrk (s, " \t"); |
| 623 | if (p == NULL) |
| 624 | p = s + strlen (s); |
| 625 | |
| 626 | g_strlcpy (first_word, s, p - s + 1); |
| 627 | |
| 628 | hotkey = lookup_key (first_word, NULL); |
| 629 | |
| 630 | if (hotkey != 0) |
| 631 | return hotkey; |
| 632 | else |
| 633 | return (unsigned char) s[0]; |
| 634 | } |
| 635 | |
| 636 | /* --------------------------------------------------------------------------------------------- */ |
601 | 637 | /*** public functions ****************************************************************************/ |
602 | 638 | /* --------------------------------------------------------------------------------------------- */ |
603 | 639 | |
… |
… |
user_menu_cmd (const WEdit * edit_widget, const char *menu_file, int selected_en |
1101 | 1137 | /* insert all the items found */ |
1102 | 1138 | for (i = 0; i < menu_lines; i++) |
1103 | 1139 | { |
| 1140 | const char *label; |
| 1141 | int hotkey; |
| 1142 | |
1104 | 1143 | p = entries[i]; |
1105 | | LISTBOX_APPEND_TEXT (listbox, (unsigned char) p[0], |
1106 | | extract_line (p, p + MAX_ENTRY_LEN), p, FALSE); |
| 1144 | label = extract_line (p, p + MAX_ENTRY_LEN); |
| 1145 | hotkey = extract_hotkey (label); |
| 1146 | |
| 1147 | LISTBOX_APPEND_TEXT (listbox, hotkey, label, p, FALSE); |
1107 | 1148 | } |
1108 | 1149 | /* Select the default entry */ |
1109 | 1150 | listbox_select_entry (listbox->list, selected); |