Ticket #3664: 002-3664-don-t-hardcode-plus-minus-etc.patch

File 002-3664-don-t-hardcode-plus-minus-etc.patch, 10.7 KB (added by mooffie, 5 years ago)
  • lib/keybind.h

    From a9f7ecf0a624ea87af758db627ca89fe6fb71de1 Mon Sep 17 00:00:00 2001
    From: Mooffie <mooffie@gmail.com>
    Date: Sun, 17 Jul 2016 20:32:50 +0300
    Subject: [PATCH 2/2] Ticket #3664: (midnight_callback): don't hardcode +, -,
     \, *.
    
    ---
     lib/keybind.h              |  1 +
     lib/tty/key.c              | 33 +++++++++++++++++++++++++++++++
     lib/tty/key.h              |  1 +
     misc/mc.default.keymap     |  5 +++++
     misc/mc.emacs.keymap       |  5 +++++
     src/filemanager/midnight.c | 48 ++++++++++++++++------------------------------
     src/keybind-defaults.c     | 11 +++++++++++
     src/keybind-defaults.h     |  2 ++
     src/setup.c                |  9 +++++++--
     9 files changed, 82 insertions(+), 33 deletions(-)
    
    diff --git a/lib/keybind.h b/lib/keybind.h
    index 3484591..094ddb1 100644
    a b  
    1111/* keymap sections */ 
    1212#define KEYMAP_SECTION_MAIN "main" 
    1313#define KEYMAP_SECTION_MAIN_EXT "main:xmap" 
     14#define KEYMAP_SECTION_MAIN_EMPTY_CMDLINE "main:empty-cmdline" 
    1415#define KEYMAP_SECTION_PANEL "panel" 
    1516#define KEYMAP_SECTION_DIALOG "dialog" 
    1617#define KEYMAP_SECTION_INPUT "input" 
  • lib/tty/key.c

    diff --git a/lib/tty/key.c b/lib/tty/key.c
    index 344141c..4a9afdf 100644
    a b application_keypad_mode (void) 
    22752275 
    22762276/* --------------------------------------------------------------------------------------------- */ 
    22772277 
     2278/** 
     2279 * Returns TRUE if a user has asked to prefer the keypad version of a key. 
     2280 * 
     2281 * That is, if the user has asked for "+ - / *" to be effective (in some 
     2282 * situations) only if typed via the keypad. 
     2283 * 
     2284 * @see application_keypad_mode(), numeric_keypad_mode(). 
     2285 */ 
     2286gboolean 
     2287tty_has_alternate_key_representation (int keycode) 
     2288{ 
     2289    if (mc_global.tty.alternate_plus_minus 
     2290        && (mc_global.tty.console_flag != '\0' || mc_global.tty.xterm_flag)) 
     2291    { 
     2292        /* Yes, "application mode" is active. The following keys have a 
     2293         * different representation when typed via the keypad. */ 
     2294        switch (keycode) 
     2295        { 
     2296        case '+': 
     2297        case '-': 
     2298        case '/': /* Note: This is slash. It's not the *backslash* used (by default) to Unselect files. */ 
     2299        case '*': 
     2300            return TRUE; 
     2301        default: 
     2302            break; 
     2303        } 
     2304    } 
     2305 
     2306    return FALSE; 
     2307} 
     2308 
     2309/* --------------------------------------------------------------------------------------------- */ 
     2310 
    22782311void 
    22792312enable_bracketed_paste (void) 
    22802313{ 
  • lib/tty/key.h

    diff --git a/lib/tty/key.h b/lib/tty/key.h
    index 7b866ac..b050924 100644
    a b int get_key_code (int nodelay); 
    106106/* Set keypad mode (xterm and linux console only) */ 
    107107void numeric_keypad_mode (void); 
    108108void application_keypad_mode (void); 
     109gboolean tty_has_alternate_key_representation (int keycode); 
    109110 
    110111/* Bracketed paste mode */ 
    111112void enable_bracketed_paste (void); 
  • misc/mc.default.keymap

    diff --git a/misc/mc.default.keymap b/misc/mc.default.keymap
    index 7d61ff8..3ab1d19 100644
    a b PutOtherTagged = ctrl-t 
    7878PutCurrentLink = r 
    7979PutOtherLink = ctrl-r 
    8080 
     81[main:empty-cmdline] 
     82Select = plus 
     83Unselect = minus; backslash 
     84SelectInvert = asterisk 
     85 
    8186[panel] 
    8287Search = ctrl-s; alt-s 
    8388Mark = insert; ctrl-t 
  • misc/mc.emacs.keymap

    diff --git a/misc/mc.emacs.keymap b/misc/mc.emacs.keymap
    index 8b4842a..e340c31 100644
    a b PutOtherTagged = ctrl-t 
    7878PutCurrentLink = r 
    7979PutOtherLink = ctrl-r 
    8080 
     81[main:empty-cmdline] 
     82Select = plus 
     83Unselect = minus; backslash 
     84SelectInvert = asterisk 
     85 
    8186[panel] 
    8287Search = ctrl-s; alt-s 
    8388Mark = insert; ctrl-t 
  • src/filemanager/midnight.c

    diff --git a/src/filemanager/midnight.c b/src/filemanager/midnight.c
    index e312b2c..e1c93c5 100644
    a b midnight_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void 
    14911491            cmdline->point = 0; 
    14921492        } 
    14931493 
    1494         if ((!mc_global.tty.alternate_plus_minus 
    1495              || !(mc_global.tty.console_flag != '\0' || mc_global.tty.xterm_flag)) && !quote 
    1496             && !current_panel->searching) 
     1494        /* 
     1495         * Handle '+' (Select), '-' '\\' (Unselect), '*' (SelectInvert), and 
     1496         * possibly other punctuation keys, "when they're typed as the first 
     1497         * character on the command-line". 
     1498         */ 
     1499        if (!tty_has_alternate_key_representation (parm) && !quote && !current_panel->searching) 
    14971500        { 
    1498             if (!only_leading_plus_minus) 
     1501            /* 
     1502             * The idea behind the 'main_empty_cmdline_map' keymap is to utilize 
     1503             * some characters, like punctuation marks, that are unlikely to start 
     1504             * a shell command. This keymap, therefore, is only effective when the 
     1505             * command-line is still empty. Or when the user (by turning off the 
     1506             * 'only_leading_plus_minus' option) asks to make it dominant. 
     1507             */ 
     1508            if (!only_leading_plus_minus || !command_prompt || input_is_empty (cmdline)) 
    14991509            { 
    1500                 /* Special treatement, since the input line will eat them */ 
    1501                 if (parm == '+') 
    1502                     return send_message (current_panel, midnight_dlg, MSG_ACTION, CK_Select, NULL); 
    1503  
    1504                 if (parm == '\\' || parm == '-') 
    1505                     return send_message (current_panel, midnight_dlg, MSG_ACTION, CK_Unselect, 
    1506                                          NULL); 
    1507  
    1508                 if (parm == '*') 
    1509                     return send_message (current_panel, midnight_dlg, MSG_ACTION, CK_SelectInvert, 
    1510                                          NULL); 
    1511             } 
    1512             else if (!command_prompt || cmdline->buffer[0] == '\0') 
    1513             { 
    1514                 /* Special treatement '+', '-', '\', '*' only when this is 
    1515                  * first char on input line 
    1516                  */ 
    1517                 if (parm == '+') 
    1518                     return send_message (current_panel, midnight_dlg, MSG_ACTION, CK_Select, NULL); 
    1519  
    1520                 if (parm == '\\' || parm == '-') 
    1521                     return send_message (current_panel, midnight_dlg, MSG_ACTION, CK_Unselect, 
    1522                                          NULL); 
    1523  
    1524                 if (parm == '*') 
    1525                     return send_message (current_panel, midnight_dlg, MSG_ACTION, CK_SelectInvert, 
    1526                                          NULL); 
     1510                command = keybind_lookup_keymap_command (main_empty_cmdline_map, parm); 
     1511                if (command != CK_IgnoreKey) 
     1512                    return midnight_execute_cmd (NULL, command); 
    15271513            } 
    15281514        } 
    15291515        return MSG_NOT_HANDLED; 
  • src/keybind-defaults.c

    diff --git a/src/keybind-defaults.c b/src/keybind-defaults.c
    index 38b4afb..a7166fa 100644
    a b  
    3636 
    3737GArray *main_keymap = NULL; 
    3838GArray *main_x_keymap = NULL; 
     39GArray *main_empty_cmdline_keymap = NULL; 
    3940GArray *panel_keymap = NULL; 
    4041GArray *dialog_keymap = NULL; 
    4142GArray *input_keymap = NULL; 
    GArray *diff_keymap = NULL; 
    5455 
    5556const global_keymap_t *main_map = NULL; 
    5657const global_keymap_t *main_x_map = NULL; 
     58const global_keymap_t *main_empty_cmdline_map = NULL; 
    5759const global_keymap_t *panel_map = NULL; 
    5860const global_keymap_t *tree_map = NULL; 
    5961const global_keymap_t *help_map = NULL; 
    static const global_keymap_ini_t default_main_x_keymap[] = { 
    165167    {NULL, NULL} 
    166168}; 
    167169 
     170static const global_keymap_ini_t default_main_empty_cmdline_keymap[] = { 
     171    {"Select", "plus"}, 
     172    {"Unselect", "minus; backslash"}, 
     173    {"SelectInvert", "asterisk"}, 
     174    {NULL, NULL} 
     175}; 
     176 
    168177/* panel */ 
    169178static const global_keymap_ini_t default_panel_keymap[] = { 
    170179    {"PanelOtherCd", "alt-o"}, 
    create_default_keymap (void) 
    585594 
    586595    create_default_keymap_section (keymap, KEYMAP_SECTION_MAIN, default_main_keymap); 
    587596    create_default_keymap_section (keymap, KEYMAP_SECTION_MAIN_EXT, default_main_x_keymap); 
     597    create_default_keymap_section (keymap, KEYMAP_SECTION_MAIN_EMPTY_CMDLINE, 
     598                                   default_main_empty_cmdline_keymap); 
    588599    create_default_keymap_section (keymap, KEYMAP_SECTION_PANEL, default_panel_keymap); 
    589600    create_default_keymap_section (keymap, KEYMAP_SECTION_DIALOG, default_dialog_keymap); 
    590601    create_default_keymap_section (keymap, KEYMAP_SECTION_INPUT, default_input_keymap); 
  • src/keybind-defaults.h

    diff --git a/src/keybind-defaults.h b/src/keybind-defaults.h
    index 7b569c6..1845a3b 100644
    a b  
    1515 
    1616extern GArray *main_keymap; 
    1717extern GArray *main_x_keymap; 
     18extern GArray *main_empty_cmdline_keymap; 
    1819extern GArray *panel_keymap; 
    1920extern GArray *dialog_keymap; 
    2021extern GArray *input_keymap; 
    extern GArray *diff_keymap; 
    3435 
    3536extern const global_keymap_t *main_map; 
    3637extern const global_keymap_t *main_x_map; 
     38extern const global_keymap_t *main_empty_cmdline_map; 
    3739extern const global_keymap_t *panel_map; 
    3840extern const global_keymap_t *tree_map; 
    3941extern const global_keymap_t *help_map; 
  • src/setup.c

    diff --git a/src/setup.c b/src/setup.c
    index 951edb8..a74436f 100644
    a b int easy_patterns = 1; 
    153153/* It true saves the setup when quitting */ 
    154154int auto_save_setup = 1; 
    155155 
    156 /* If true, then the +, - and \ keys have their special meaning only if the 
    157  * command line is emtpy, otherwise they behave like regular letters 
     156/* If true, then the +, -, \ and * keys have their special meaning only if the 
     157 * command line is empty, otherwise they're *always* special (and you'll have 
     158 * to quote them (C-q) whenever you want to use them in the command line. 
    158159 */ 
    159160int only_leading_plus_minus = 1; 
    160161 
    load_keymap_defs (gboolean load_from_file) 
    13231324        load_keymap_from_section (KEYMAP_SECTION_MAIN, main_keymap, mc_global_keymap); 
    13241325        main_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t)); 
    13251326        load_keymap_from_section (KEYMAP_SECTION_MAIN_EXT, main_x_keymap, mc_global_keymap); 
     1327        main_empty_cmdline_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t)); 
     1328        load_keymap_from_section (KEYMAP_SECTION_MAIN_EMPTY_CMDLINE, main_empty_cmdline_keymap, 
     1329                                  mc_global_keymap); 
    13261330 
    13271331        panel_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t)); 
    13281332        load_keymap_from_section (KEYMAP_SECTION_PANEL, panel_keymap, mc_global_keymap); 
    load_keymap_defs (gboolean load_from_file) 
    13641368 
    13651369    main_map = (global_keymap_t *) main_keymap->data; 
    13661370    main_x_map = (global_keymap_t *) main_x_keymap->data; 
     1371    main_empty_cmdline_map = (global_keymap_t *) main_empty_cmdline_keymap->data; 
    13671372    panel_map = (global_keymap_t *) panel_keymap->data; 
    13681373    dialog_map = (global_keymap_t *) dialog_keymap->data; 
    13691374    input_map = (global_keymap_t *) input_keymap->data;