Ticket #4206: Ctrl-x_1…0_Window_Switch.patch

File Ctrl-x_1…0_Window_Switch.patch, 4.8 KB (added by psprint, 3 years ago)
  • lib/keybind.c

    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) 
    449449 
    450450    res = bsearch (&key, command_names, num_command_names, 
    451451                   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    } 
    453464    return (res != NULL) ? res->val : CK_IgnoreKey; 
    454465} 
    455466 
  • lib/keybind.h

    diff --git a/lib/keybind.h b/lib/keybind.h
    index af019df09..8262dba70 100644
    a b  
    3131#define CK_PipeBlock(i)  (10000+(i)) 
    3232#define CK_Macro(i)      (20000+(i)) 
    3333#define CK_MacroLast     CK_Macro(0x7FFF) 
    34  
     34#define CK_WindowN(i)    (5000+(i)) 
    3535/*** enums ***************************************************************************************/ 
    3636 
    3737enum 
  • lib/widget/order_kept_dialog.c

    diff --git a/lib/widget/order_kept_dialog.c b/lib/widget/order_kept_dialog.c
    index 99521ba60..28cd05cf1 100644
    a b  
    5252/*** file scope functions ************************************************************************/ 
    5353/* --------------------------------------------------------------------------------------------- */ 
    5454 
     55static gboolean 
     56order_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/* --------------------------------------------------------------------------------------------- */ 
     67static cb_ret_t 
     68order_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 
    5581/* To search WEdit by file name till extension, if any - extensions and case can differ */ 
    5682static gboolean 
    5783similar_filename_edit_widgets (gconstpointer a, gconstpointer b) 
    order_dlg_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, voi 
    235261        g_ptr_array_free (h->ordered_widgets, TRUE); 
    236262        h->ordered_widgets = NULL; 
    237263        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; 
    238285    default: 
    239286        break; 
    240287    } 
  • src/editor/editwidget.c

    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) 
    481481        break; 
    482482    } 
    483483 
     484 
    484485    return ret; 
    485486} 
    486487 
  • src/keybind-defaults.c

    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[] = { 
    480480 
    481481/* emacs keyboard layout emulation */ 
    482482static 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"}, 
    483493    {NULL, NULL} 
    484494}; 
    485495#endif /* USE_INTERNAL_EDIT */