From 228a0f21709c163a84273ff8db3cbc8a4070d95b Mon Sep 17 00:00:00 2001
From: Sebastian Gniazdowski <sgniazdowski@gmail.com>
Date: Fri, 19 Feb 2021 03:33:25 -0600
Subject: =?UTF-8?q?Ctrl-x=201=E2=80=A60=20shortcuts=20to=20switch=20to=20f?=
=?UTF-8?q?ile=201=E2=80=A610.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lib/keybind.c | 13 +++++++++-
lib/keybind.h | 2 +-
lib/widget/order_kept_dialog.c | 47 ++++++++++++++++++++++++++++++++++
src/editor/editwidget.c | 1 +
src/keybind-defaults.c | 10 ++++++++
5 files changed, 71 insertions(+), 2 deletions(-)
diff --git a/lib/keybind.c b/lib/keybind.c
index abd44d3e2..4c7c8212f 100644
a
|
b
|
keybind_lookup_action (const char *name) |
449 | 449 | |
450 | 450 | res = bsearch (&key, command_names, num_command_names, |
451 | 451 | sizeof (command_names[0]), name_keymap_comparator); |
452 | | |
| 452 | if (res == NULL) |
| 453 | { |
| 454 | /* Recognize the parametrized action name WindowN:(idx) */ |
| 455 | if (g_str_has_prefix (name, "WindowN:")) |
| 456 | { |
| 457 | long idx; |
| 458 | errno = 0; |
| 459 | idx = strtol (name + 8, NULL, 10); |
| 460 | if (errno == 0) |
| 461 | return CK_WindowN (idx); |
| 462 | } |
| 463 | } |
453 | 464 | return (res != NULL) ? res->val : CK_IgnoreKey; |
454 | 465 | } |
455 | 466 | |
diff --git a/lib/keybind.h b/lib/keybind.h
index af019df09..8262dba70 100644
a
|
b
|
|
31 | 31 | #define CK_PipeBlock(i) (10000+(i)) |
32 | 32 | #define CK_Macro(i) (20000+(i)) |
33 | 33 | #define CK_MacroLast CK_Macro(0x7FFF) |
34 | | |
| 34 | #define CK_WindowN(i) (5000+(i)) |
35 | 35 | /*** enums ***************************************************************************************/ |
36 | 36 | |
37 | 37 | enum |
diff --git a/lib/widget/order_kept_dialog.c b/lib/widget/order_kept_dialog.c
index 99521ba60..28cd05cf1 100644
a
|
b
|
|
52 | 52 | /*** file scope functions ************************************************************************/ |
53 | 53 | /* --------------------------------------------------------------------------------------------- */ |
54 | 54 | |
| 55 | static gboolean |
| 56 | order_dlg_switch_to_win_idx (WOrderKeptDialog * h, long win_idx) |
| 57 | { |
| 58 | if (win_idx >= 1 && win_idx <= h->ordered_widgets->len) |
| 59 | { |
| 60 | widget_select (g_ptr_array_index (h->ordered_widgets, win_idx - 1)); |
| 61 | return TRUE; |
| 62 | } |
| 63 | return FALSE; |
| 64 | } |
| 65 | |
| 66 | /* --------------------------------------------------------------------------------------------- */ |
| 67 | static cb_ret_t |
| 68 | order_dlg_execute_action (WOrderKeptDialog * h, long action) |
| 69 | { |
| 70 | /* CK_WindowN */ |
| 71 | if ((action / CK_WindowN (0)) == 1) |
| 72 | { |
| 73 | if (order_dlg_switch_to_win_idx (h, action - CK_WindowN (0))) |
| 74 | return MSG_HANDLED; |
| 75 | } |
| 76 | return MSG_NOT_HANDLED; |
| 77 | } |
| 78 | |
| 79 | /* --------------------------------------------------------------------------------------------- */ |
| 80 | |
55 | 81 | /* To search WEdit by file name till extension, if any - extensions and case can differ */ |
56 | 82 | static gboolean |
57 | 83 | similar_filename_edit_widgets (gconstpointer a, gconstpointer b) |
… |
… |
order_dlg_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, voi |
235 | 261 | g_ptr_array_free (h->ordered_widgets, TRUE); |
236 | 262 | h->ordered_widgets = NULL; |
237 | 263 | break; |
| 264 | case MSG_KEY: |
| 265 | { |
| 266 | Widget *we = WIDGET (GROUP (h)->current->data); |
| 267 | |
| 268 | if (edit_widget_is_editor (we)) |
| 269 | { |
| 270 | gboolean ext_mode; |
| 271 | long action; |
| 272 | |
| 273 | /* keep and then extmod flag */ |
| 274 | ext_mode = we->ext_mode; |
| 275 | action = widget_lookup_key (we, parm); |
| 276 | we->ext_mode = ext_mode; |
| 277 | |
| 278 | if (action == CK_IgnoreKey) |
| 279 | we->ext_mode = FALSE; |
| 280 | else |
| 281 | ret = order_dlg_execute_action (h, action); |
| 282 | } |
| 283 | } |
| 284 | break; |
238 | 285 | default: |
239 | 286 | break; |
240 | 287 | } |
diff --git a/src/editor/editwidget.c b/src/editor/editwidget.c
index 72f76d3c7..d00187d11 100644
a
|
b
|
edit_dialog_command_execute (WDialog * h, long command) |
481 | 481 | break; |
482 | 482 | } |
483 | 483 | |
| 484 | |
484 | 485 | return ret; |
485 | 486 | } |
486 | 487 | |
diff --git a/src/keybind-defaults.c b/src/keybind-defaults.c
index 7b87c2f5a..5988f1b5d 100644
a
|
b
|
static const global_keymap_ini_t default_editor_keymap[] = { |
480 | 480 | |
481 | 481 | /* emacs keyboard layout emulation */ |
482 | 482 | static const global_keymap_ini_t default_editor_x_keymap[] = { |
| 483 | {"WindowN:1", "1"}, |
| 484 | {"WindowN:2", "2"}, |
| 485 | {"WindowN:3", "3"}, |
| 486 | {"WindowN:4", "4"}, |
| 487 | {"WindowN:5", "5"}, |
| 488 | {"WindowN:6", "6"}, |
| 489 | {"WindowN:7", "7"}, |
| 490 | {"WindowN:8", "8"}, |
| 491 | {"WindowN:9", "9"}, |
| 492 | {"WindowN:10","0"}, |
483 | 493 | {NULL, NULL} |
484 | 494 | }; |
485 | 495 | #endif /* USE_INTERNAL_EDIT */ |