Ticket #212: 0001-add-user-defined-hotkeys-support-in-panel-too.patch

File 0001-add-user-defined-hotkeys-support-in-panel-too.patch, 4.3 KB (added by angel_il, 16 years ago)
  • src/main.c

    From c2f690cee6a27aca7b369d19832de8493b5b62d8 Mon Sep 17 00:00:00 2001
    From: admin <admin@holmes.(none)>
    Date: Fri, 13 Feb 2009 08:50:29 +0000
    Subject: [PATCH] add user defined hotkeys support in panel too
    
    ---
     src/main.c |   68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
     src/main.h |    8 +++---
     2 files changed, 66 insertions(+), 10 deletions(-)
    
    diff --git a/src/main.c b/src/main.c
    index 0134098..a5b8acf 100644
    a b char *mc_home = NULL; 
    280280 
    281281char cmd_buf[512]; 
    282282 
    283 static global_command_type global_command [] = { 
     283static panel_command_type panel_command [] = { 
    284284    {CK_ChmodCmd,            "ChmodCmd",            chmod_cmd}, 
    285285    {CK_ChownAdvancedCmd,    "ChownAdvancedCmd",    chown_advanced_cmd}, 
    286286    {CK_ChownCmd,            "ChownCmd",            chown_cmd}, 
    static global_command_type global_command [] = { 
    336336 
    337337callfn cmdfn_by_name (char *cmd_name) 
    338338{ 
    339     for (int i = 0; global_command[i].command != NULL && global_command[i].key != 0 ; i++) { 
    340         if (strcmp(global_command[i].cmd_name, cmd_name) == 0) { 
    341             return global_command[i].command; 
     339    for (int i = 0; panel_command[i].command != 0 ; i++) { 
     340        if (strcmp(panel_command[i].cmd_name, cmd_name) == 0) { 
     341            return panel_command[i].command_fn; 
     342        } 
     343    } 
     344    return 0; 
     345} 
     346 
     347callfn cmdfn_by_command (int x_command) 
     348{ 
     349    mc_log("[[[[[[[cmdfn_by_command (%i)\n", x_command); 
     350    for (int i = 0; panel_command[i].command != 0 ; i++) { 
     351        //mc_log("panel_command[%i].command=%i / panel_command[%i].cmd_name=%s\n",i ,panel_command[i].command, i, panel_command[i].cmd_name); 
     352        if (panel_command[i].command == x_command) { 
     353            mc_log("    !! cmdfn_by_command (%i)=%s\n", x_command, panel_command[i].cmd_name); 
     354            return panel_command[i].command_fn; 
    342355        } 
    343356    } 
    344357    return NULL; 
    345358} 
    346359 
     360int cmd_by_name (char *cmd_name) 
     361{ 
     362    for (int i = 0; panel_command[i].command != 0 ; i++) { 
     363        if (strcmp(panel_command[i].cmd_name, cmd_name) == 0) { 
     364            return panel_command[i].command; 
     365        } 
     366    } 
     367    return 0; 
     368} 
     369 
     370int command_by_key (int x_key) 
     371{ 
     372    mc_log("=========command_by_key\n"); 
     373    for (int i = 0; panel_user_key_map[i].command != 0 ; i++) { 
     374        mc_log("panel_user_key_map[%i].key=%i = panel_user_key_map[%i].command=%i\n", i, panel_user_key_map[i].key, i, panel_user_key_map[i].command ); 
     375        if (panel_user_key_map[i].key == x_key) { 
     376            return panel_user_key_map[i].command; 
     377        } 
     378    } 
     379    return 0; 
     380} 
     381 
     382callfn cmdfn_by_key (int x_key) 
     383{ 
     384    int cmd = command_by_key(x_key); 
     385    if (cmd > 0){ 
     386        return cmdfn_by_command(cmd); 
     387    } 
     388} 
    347389 
    348390static void 
    349391reload_panelized (WPanel *panel) 
    static cb_ret_t 
    15201562midnight_callback (struct Dlg_head *h, dlg_msg_t msg, int parm) 
    15211563{ 
    15221564    int i; 
    1523  
     1565    int x_cmd; 
     1566    callfn fn; 
    15241567    switch (msg) { 
    15251568 
    15261569    case DLG_IDLE: 
    midnight_callback (struct Dlg_head *h, dlg_msg_t msg, int parm) 
    15321575        return MSG_HANDLED; 
    15331576 
    15341577    case DLG_KEY: 
     1578        x_cmd = command_by_key(parm); 
     1579        mc_log("x_cmd=%i\n", x_cmd); 
     1580        if (x_cmd > 0){ 
     1581            fn = cmdfn_by_key (parm); 
     1582            if (fn) { 
     1583                (fn) (); 
     1584                return MSG_HANDLED; 
     1585            } 
     1586        } 
     1587        /* 
     1588        */ 
     1589        /* 
    15351590        if (ctl_x_map_enabled) { 
    15361591            ctl_x_map_enabled = 0; 
    15371592            for (i = 0; ctl_x_map[i].key_code; i++) 
    midnight_callback (struct Dlg_head *h, dlg_msg_t msg, int parm) 
    15401595                    return MSG_HANDLED; 
    15411596                } 
    15421597        } 
    1543  
     1598        */ 
    15441599        /* FIXME: should handle all menu shortcuts before this point */ 
    15451600        if (the_menubar->active) 
    15461601            return MSG_NOT_HANDLED; 
    midnight_callback (struct Dlg_head *h, dlg_msg_t msg, int parm) 
    16271682        return MSG_HANDLED; 
    16281683 
    16291684    case DLG_UNHANDLED_KEY: 
     1685        mc_log("case DLG_UNHANDLED_KEY: %i", parm); 
    16301686        if (command_prompt) { 
    16311687            int v; 
    16321688 
  • src/main.h

    diff --git a/src/main.h b/src/main.h
    index 9768236..ffb2afb 100644
    a b int do_panel_cd (struct WPanel *panel, const char *new_dir, enum cd 
    127127 
    128128#endif 
    129129 
    130 typedef struct global_command_type { 
    131     int    key; 
     130typedef struct panel_command_type { 
     131    int     command; 
    132132    char   *cmd_name; 
    133     callfn command; 
    134 } global_command_type; 
     133    callfn  command_fn; 
     134} panel_command_type;