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, 7 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 11 11 /* keymap sections */ 12 12 #define KEYMAP_SECTION_MAIN "main" 13 13 #define KEYMAP_SECTION_MAIN_EXT "main:xmap" 14 #define KEYMAP_SECTION_MAIN_EMPTY_CMDLINE "main:empty-cmdline" 14 15 #define KEYMAP_SECTION_PANEL "panel" 15 16 #define KEYMAP_SECTION_DIALOG "dialog" 16 17 #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) 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 { -
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); 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); -
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 78 78 PutCurrentLink = r 79 79 PutOtherLink = ctrl-r 80 80 81 [main:empty-cmdline] 82 Select = plus 83 Unselect = minus; backslash 84 SelectInvert = asterisk 85 81 86 [panel] 82 87 Search = ctrl-s; alt-s 83 88 Mark = 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 78 78 PutCurrentLink = r 79 79 PutOtherLink = ctrl-r 80 80 81 [main:empty-cmdline] 82 Select = plus 83 Unselect = minus; backslash 84 SelectInvert = asterisk 85 81 86 [panel] 82 87 Search = ctrl-s; alt-s 83 88 Mark = 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 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 (!tty_has_alternate_key_representation (parm) && !quote && !current_panel->searching) 1497 1500 { 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)) 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); 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); 1527 1513 } 1528 1514 } 1529 1515 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 36 36 37 37 GArray *main_keymap = NULL; 38 38 GArray *main_x_keymap = NULL; 39 GArray *main_empty_cmdline_keymap = NULL; 39 40 GArray *panel_keymap = NULL; 40 41 GArray *dialog_keymap = NULL; 41 42 GArray *input_keymap = NULL; … … GArray *diff_keymap = NULL; 54 55 55 56 const global_keymap_t *main_map = NULL; 56 57 const global_keymap_t *main_x_map = NULL; 58 const global_keymap_t *main_empty_cmdline_map = NULL; 57 59 const global_keymap_t *panel_map = NULL; 58 60 const global_keymap_t *tree_map = NULL; 59 61 const global_keymap_t *help_map = NULL; … … static const global_keymap_ini_t default_main_x_keymap[] = { 165 167 {NULL, NULL} 166 168 }; 167 169 170 static 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 168 177 /* panel */ 169 178 static const global_keymap_ini_t default_panel_keymap[] = { 170 179 {"PanelOtherCd", "alt-o"}, … … create_default_keymap (void) 585 594 586 595 create_default_keymap_section (keymap, KEYMAP_SECTION_MAIN, default_main_keymap); 587 596 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); 588 599 create_default_keymap_section (keymap, KEYMAP_SECTION_PANEL, default_panel_keymap); 589 600 create_default_keymap_section (keymap, KEYMAP_SECTION_DIALOG, default_dialog_keymap); 590 601 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 15 15 16 16 extern GArray *main_keymap; 17 17 extern GArray *main_x_keymap; 18 extern GArray *main_empty_cmdline_keymap; 18 19 extern GArray *panel_keymap; 19 20 extern GArray *dialog_keymap; 20 21 extern GArray *input_keymap; … … extern GArray *diff_keymap; 34 35 35 36 extern const global_keymap_t *main_map; 36 37 extern const global_keymap_t *main_x_map; 38 extern const global_keymap_t *main_empty_cmdline_map; 37 39 extern const global_keymap_t *panel_map; 38 40 extern const global_keymap_t *tree_map; 39 41 extern 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; 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 … … load_keymap_defs (gboolean load_from_file) 1323 1324 load_keymap_from_section (KEYMAP_SECTION_MAIN, main_keymap, mc_global_keymap); 1324 1325 main_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t)); 1325 1326 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); 1326 1330 1327 1331 panel_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t)); 1328 1332 load_keymap_from_section (KEYMAP_SECTION_PANEL, panel_keymap, mc_global_keymap); … … load_keymap_defs (gboolean load_from_file) 1364 1368 1365 1369 main_map = (global_keymap_t *) main_keymap->data; 1366 1370 main_x_map = (global_keymap_t *) main_x_keymap->data; 1371 main_empty_cmdline_map = (global_keymap_t *) main_empty_cmdline_keymap->data; 1367 1372 panel_map = (global_keymap_t *) panel_keymap->data; 1368 1373 dialog_map = (global_keymap_t *) dialog_keymap->data; 1369 1374 input_map = (global_keymap_t *) input_keymap->data;