From 097c1d3a9b0ff0ce895d2c8589765455390c8824 Mon Sep 17 00:00:00 2001
From: Mooffie <mooffie@gmail.com>
Date: Sun, 17 Jul 2016 20:32:50 +0300
Subject: [PATCH] Ticket #3664: (midnight_callback): don't hardcode +, -, \, *.
---
lib/tty/key.c | 33 +++++++++++++++++++++++++++++
lib/tty/key.h | 1 +
misc/mc.default.keymap | 6 +++---
misc/mc.emacs.keymap | 6 +++---
src/filemanager/midnight.c | 53 +++++++++++++++++++++-------------------------
src/keybind-defaults.c | 7 +++---
src/setup.c | 5 +++--
7 files changed, 71 insertions(+), 40 deletions(-)
diff --git a/lib/tty/key.c b/lib/tty/key.c
index 344141c..4a9afdf 100644
a
|
b
|
application_keypad_mode (void) |
2275 | 2275 | |
2276 | 2276 | /* --------------------------------------------------------------------------------------------- */ |
2277 | 2277 | |
| 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 | */ |
| 2286 | gboolean |
| 2287 | tty_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 | |
2278 | 2311 | void |
2279 | 2312 | enable_bracketed_paste (void) |
2280 | 2313 | { |
diff --git a/lib/tty/key.h b/lib/tty/key.h
index 7b866ac..b050924 100644
a
|
b
|
int get_key_code (int nodelay); |
106 | 106 | /* Set keypad mode (xterm and linux console only) */ |
107 | 107 | void numeric_keypad_mode (void); |
108 | 108 | void application_keypad_mode (void); |
| 109 | gboolean tty_has_alternate_key_representation (int keycode); |
109 | 110 | |
110 | 111 | /* Bracketed paste mode */ |
111 | 112 | void enable_bracketed_paste (void); |
diff --git a/misc/mc.default.keymap b/misc/mc.default.keymap
index 7d61ff8..877b879 100644
a
|
b
|
PutOtherPath = alt-shift-a |
35 | 35 | PutCurrentSelected = alt-enter; ctrl-enter |
36 | 36 | PutCurrentFullSelected = ctrl-shift-enter |
37 | 37 | ViewFiltered = alt-exclamation |
38 | | Select = kpplus |
39 | | Unselect = kpminus |
40 | | SelectInvert = kpasterisk |
| 38 | Select = kpplus; plus |
| 39 | Unselect = kpminus; minus; backslash |
| 40 | SelectInvert = kpasterisk; asterisk |
41 | 41 | ScreenList = alt-prime |
42 | 42 | # OptionsLayout = |
43 | 43 | # OptionsAppearance = |
diff --git a/misc/mc.emacs.keymap b/misc/mc.emacs.keymap
index 8b4842a..7d7ba18 100644
a
|
b
|
PutOtherPath = alt-shift-a |
35 | 35 | PutCurrentSelected = alt-enter; ctrl-enter |
36 | 36 | PutCurrentFullSelected = ctrl-shift-enter |
37 | 37 | ViewFiltered = alt-exclamation |
38 | | Select = kpplus |
39 | | Unselect = kpminus |
40 | | SelectInvert = kpasterisk |
| 38 | Select = kpplus; plus |
| 39 | Unselect = kpminus; minus; backslash |
| 40 | SelectInvert = kpasterisk; asterisk |
41 | 41 | ScreenList = alt-prime |
42 | 42 | # OptionsLayout = |
43 | 43 | # OptionsAppearance = |
diff --git a/src/filemanager/midnight.c b/src/filemanager/midnight.c
index e312b2c..edf2e54 100644
a
|
b
|
midnight_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void |
1491 | 1491 | cmdline->point = 0; |
1492 | 1492 | } |
1493 | 1493 | |
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 ((parm < 128) && g_ascii_ispunct ((char) parm) /* "< 128" because g_ascii_ispunct() accepts char, not int. */ |
| 1500 | && !tty_has_alternate_key_representation (parm) && !quote && !current_panel->searching) |
1497 | 1501 | { |
1498 | | if (!only_leading_plus_minus) |
| 1502 | /* |
| 1503 | * The idea here is that punctuation marks are unlikely to start |
| 1504 | * a shell command. Therefore we only activate them 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 them dominant. |
| 1507 | */ |
| 1508 | if (!only_leading_plus_minus || !command_prompt || input_is_empty (cmdline)) |
1499 | 1509 | { |
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); |
| 1510 | command = keybind_lookup_keymap_command (main_map, parm); |
| 1511 | if (command != CK_IgnoreKey) |
| 1512 | { |
| 1513 | cb_ret_t res; |
1503 | 1514 | |
1504 | | if (parm == '\\' || parm == '-') |
1505 | | return send_message (current_panel, midnight_dlg, MSG_ACTION, CK_Unselect, |
1506 | | NULL); |
| 1515 | /* First try the panel, then the filemanager. */ |
| 1516 | res = send_message (current_panel, NULL, MSG_ACTION, command, NULL); |
| 1517 | if (res == MSG_NOT_HANDLED) |
| 1518 | res = midnight_execute_cmd (NULL, command); |
1507 | 1519 | |
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); |
| 1520 | return res; |
| 1521 | } |
1527 | 1522 | } |
1528 | 1523 | } |
1529 | 1524 | return MSG_NOT_HANDLED; |
diff --git a/src/keybind-defaults.c b/src/keybind-defaults.c
index 38b4afb..8b2561f 100644
a
|
b
|
static const global_keymap_ini_t default_main_keymap[] = { |
127 | 127 | {"SplitVertHoriz", "alt-comma"}, |
128 | 128 | {"ExtendedKeyMap", "ctrl-x"}, |
129 | 129 | /* Select/unselect group */ |
130 | | {"Select", "kpplus"}, |
131 | | {"Unselect", "kpminus"}, |
132 | | {"SelectInvert", "kpasterisk"}, |
| 130 | /* Note: ASCII punctuation keys (like plus, but unlike kpplus) are only effective when they're the first char typed on the command-line. */ |
| 131 | {"Select", "kpplus; plus"}, |
| 132 | {"Unselect", "kpminus; minus; backslash"}, |
| 133 | {"SelectInvert", "kpasterisk; asterisk"}, |
133 | 134 | /* List of screens */ |
134 | 135 | {"ScreenList", "alt-prime"}, |
135 | 136 | {NULL, NULL} |
diff --git a/src/setup.c b/src/setup.c
index 951edb8..f707af8 100644
a
|
b
|
int easy_patterns = 1; |
153 | 153 | /* It true saves the setup when quitting */ |
154 | 154 | int auto_save_setup = 1; |
155 | 155 | |
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. |
158 | 159 | */ |
159 | 160 | int only_leading_plus_minus = 1; |
160 | 161 | |