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; |
280 | 280 | |
281 | 281 | char cmd_buf[512]; |
282 | 282 | |
283 | | static global_command_type global_command [] = { |
| 283 | static panel_command_type panel_command [] = { |
284 | 284 | {CK_ChmodCmd, "ChmodCmd", chmod_cmd}, |
285 | 285 | {CK_ChownAdvancedCmd, "ChownAdvancedCmd", chown_advanced_cmd}, |
286 | 286 | {CK_ChownCmd, "ChownCmd", chown_cmd}, |
… |
… |
static global_command_type global_command [] = { |
336 | 336 | |
337 | 337 | callfn cmdfn_by_name (char *cmd_name) |
338 | 338 | { |
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 | |
| 347 | callfn 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; |
342 | 355 | } |
343 | 356 | } |
344 | 357 | return NULL; |
345 | 358 | } |
346 | 359 | |
| 360 | int 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 | |
| 370 | int 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 | |
| 382 | callfn 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 | } |
347 | 389 | |
348 | 390 | static void |
349 | 391 | reload_panelized (WPanel *panel) |
… |
… |
static cb_ret_t |
1520 | 1562 | midnight_callback (struct Dlg_head *h, dlg_msg_t msg, int parm) |
1521 | 1563 | { |
1522 | 1564 | int i; |
1523 | | |
| 1565 | int x_cmd; |
| 1566 | callfn fn; |
1524 | 1567 | switch (msg) { |
1525 | 1568 | |
1526 | 1569 | case DLG_IDLE: |
… |
… |
midnight_callback (struct Dlg_head *h, dlg_msg_t msg, int parm) |
1532 | 1575 | return MSG_HANDLED; |
1533 | 1576 | |
1534 | 1577 | 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 | /* |
1535 | 1590 | if (ctl_x_map_enabled) { |
1536 | 1591 | ctl_x_map_enabled = 0; |
1537 | 1592 | for (i = 0; ctl_x_map[i].key_code; i++) |
… |
… |
midnight_callback (struct Dlg_head *h, dlg_msg_t msg, int parm) |
1540 | 1595 | return MSG_HANDLED; |
1541 | 1596 | } |
1542 | 1597 | } |
1543 | | |
| 1598 | */ |
1544 | 1599 | /* FIXME: should handle all menu shortcuts before this point */ |
1545 | 1600 | if (the_menubar->active) |
1546 | 1601 | return MSG_NOT_HANDLED; |
… |
… |
midnight_callback (struct Dlg_head *h, dlg_msg_t msg, int parm) |
1627 | 1682 | return MSG_HANDLED; |
1628 | 1683 | |
1629 | 1684 | case DLG_UNHANDLED_KEY: |
| 1685 | mc_log("case DLG_UNHANDLED_KEY: %i", parm); |
1630 | 1686 | if (command_prompt) { |
1631 | 1687 | int v; |
1632 | 1688 | |
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 |
127 | 127 | |
128 | 128 | #endif |
129 | 129 | |
130 | | typedef struct global_command_type { |
131 | | int key; |
| 130 | typedef struct panel_command_type { |
| 131 | int command; |
132 | 132 | char *cmd_name; |
133 | | callfn command; |
134 | | } global_command_type; |
| 133 | callfn command_fn; |
| 134 | } panel_command_type; |