Ticket #3725: 3725-Don-t-limit-hotkeys-in-user-menu-to-simp.patch

File 3725-Don-t-limit-hotkeys-in-user-menu-to-simp.patch, 2.8 KB (added by mooffie, 8 years ago)
  • src/filemanager/usermenu.c

    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  
    3939#include "lib/global.h" 
    4040#include "lib/fileloc.h" 
    4141#include "lib/tty/tty.h" 
     42#include "lib/tty/key.h"        /* lookup_key() */ 
    4243#include "lib/skin.h" 
    4344#include "lib/search.h" 
    4445#include "lib/vfs/vfs.h" 
    menu_file_own (char *path) 
    598599} 
    599600 
    600601/* --------------------------------------------------------------------------------------------- */ 
     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 */ 
     615static int 
     616extract_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/* --------------------------------------------------------------------------------------------- */ 
    601637/*** public functions ****************************************************************************/ 
    602638/* --------------------------------------------------------------------------------------------- */ 
    603639 
    user_menu_cmd (const WEdit * edit_widget, const char *menu_file, int selected_en 
    11011137            /* insert all the items found */ 
    11021138            for (i = 0; i < menu_lines; i++) 
    11031139            { 
     1140                const char *label; 
     1141                int hotkey; 
     1142 
    11041143                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); 
    11071148            } 
    11081149            /* Select the default entry */ 
    11091150            listbox_select_entry (listbox->list, selected);