| 64 | #include "../edit/editcmddef.h" |
| 65 | #include "../edit/edit-widget.h" |
| 66 | |
| 67 | static edit_key_map_type def_common_key_map[] = { |
| 68 | { '\n', CK_Enter }, |
| 69 | { '\t', CK_Tab }, |
| 70 | |
| 71 | { ESC_CHAR, CK_Exit }, |
| 72 | { KEY_BACKSPACE, CK_BackSpace }, |
| 73 | { KEY_DC, CK_Delete }, |
| 74 | { KEY_DOWN, CK_Down }, |
| 75 | { KEY_END, CK_End }, |
| 76 | { KEY_HOME, CK_Home }, |
| 77 | { KEY_IC, CK_Toggle_Insert }, |
| 78 | { KEY_LEFT, CK_Left }, |
| 79 | { KEY_NPAGE, CK_Page_Down }, |
| 80 | { KEY_PPAGE, CK_Page_Up }, |
| 81 | { KEY_RIGHT, CK_Right }, |
| 82 | { KEY_UP, CK_Up }, |
| 83 | |
| 84 | { ALT ('\n'), CK_Return }, |
| 85 | { ALT ('\t'), CK_Complete_Word }, |
| 86 | { ALT ('l'), CK_Goto }, |
| 87 | { ALT ('L'), CK_Goto }, |
| 88 | { ALT ('p'), CK_Paragraph_Format }, |
| 89 | { ALT ('t'), CK_Sort }, |
| 90 | { ALT ('u'), CK_ExtCmd }, |
| 91 | { ALT ('<'), CK_Beginning_Of_Text }, |
| 92 | { ALT ('>'), CK_End_Of_Text }, |
| 93 | { ALT (KEY_BACKSPACE), CK_Delete_Word_Left }, |
| 94 | |
| 95 | { XCTRL ('k'), CK_Delete_To_Line_End }, |
| 96 | { XCTRL ('l'), CK_Refresh }, |
| 97 | { XCTRL ('o'), CK_Shell }, |
| 98 | { XCTRL ('s'), CK_Toggle_Syntax }, |
| 99 | { XCTRL ('u'), CK_Undo }, |
| 100 | { XCTRL ('t'), CK_Select_Codepage }, |
| 101 | { XCTRL ('q'), CK_Insert_Literal }, |
| 102 | { XCTRL ('a'), CK_Execute_Macro }, |
| 103 | { XCTRL ('r'), CK_Begin_End_Macro }, |
| 104 | |
| 105 | { KEY_F (1), CK_Help }, |
| 106 | { KEY_F (2), CK_Save }, |
| 107 | { KEY_F (3), CK_Mark }, |
| 108 | { KEY_F (4), CK_Replace }, |
| 109 | { KEY_F (5), CK_Copy }, |
| 110 | { KEY_F (6), CK_Move }, |
| 111 | { KEY_F (7), CK_Find }, |
| 112 | { KEY_F (8), CK_Remove }, |
| 113 | { KEY_F (10), CK_Exit }, |
| 114 | { KEY_F (11), CK_User_Menu }, /* edit user menu */ |
| 115 | { KEY_F (12), CK_Save_As }, |
| 116 | { KEY_F (13), CK_Column_Mark }, |
| 117 | { KEY_F (14), CK_Replace_Again }, |
| 118 | { KEY_F (15), CK_Insert_File }, |
| 119 | { KEY_F (17), CK_Find_Again }, |
| 120 | { KEY_F (19), CK_Pipe_Block (0) }, /* C formatter */ |
| 121 | |
| 122 | /* Shift */ |
| 123 | { KEY_M_SHIFT | KEY_PPAGE, CK_Page_Up_Highlight }, |
| 124 | { KEY_M_SHIFT | KEY_NPAGE, CK_Page_Down_Highlight }, |
| 125 | { KEY_M_SHIFT | KEY_LEFT, CK_Left_Highlight }, |
| 126 | { KEY_M_SHIFT | KEY_RIGHT, CK_Right_Highlight }, |
| 127 | { KEY_M_SHIFT | KEY_UP, CK_Up_Highlight }, |
| 128 | { KEY_M_SHIFT | KEY_DOWN, CK_Down_Highlight }, |
| 129 | { KEY_M_SHIFT | KEY_HOME, CK_Home_Highlight }, |
| 130 | { KEY_M_SHIFT | KEY_END, CK_End_Highlight }, |
| 131 | { KEY_M_SHIFT | KEY_IC, CK_XPaste }, |
| 132 | { KEY_M_SHIFT | KEY_DC, CK_XCut }, |
| 133 | { KEY_M_SHIFT | '\n', CK_Return }, /* useful for pasting multiline text */ |
| 134 | |
| 135 | /* Ctrl */ |
| 136 | { KEY_M_CTRL | (KEY_F (2)), CK_Save_As }, |
| 137 | { KEY_M_CTRL | (KEY_F (4)), CK_Replace_Again }, |
| 138 | { KEY_M_CTRL | (KEY_F (7)), CK_Find_Again }, |
| 139 | { KEY_M_CTRL | KEY_BACKSPACE, CK_Undo }, |
| 140 | { KEY_M_CTRL | KEY_PPAGE, CK_Beginning_Of_Text }, |
| 141 | { KEY_M_CTRL | KEY_NPAGE, CK_End_Of_Text }, |
| 142 | { KEY_M_CTRL | KEY_HOME, CK_Beginning_Of_Text }, |
| 143 | { KEY_M_CTRL | KEY_END, CK_End_Of_Text }, |
| 144 | { KEY_M_CTRL | KEY_UP, CK_Scroll_Up }, |
| 145 | { KEY_M_CTRL | KEY_DOWN, CK_Scroll_Down }, |
| 146 | { KEY_M_CTRL | KEY_LEFT, CK_Word_Left }, |
| 147 | { KEY_M_CTRL | KEY_RIGHT, CK_Word_Right }, |
| 148 | { KEY_M_CTRL | KEY_IC, CK_XStore }, |
| 149 | { KEY_M_CTRL | KEY_DC, CK_Remove }, |
| 150 | |
| 151 | /* Ctrl + Shift */ |
| 152 | { KEY_M_SHIFT | KEY_M_CTRL | KEY_PPAGE, CK_Beginning_Of_Text_Highlight }, |
| 153 | { KEY_M_SHIFT | KEY_M_CTRL | KEY_NPAGE, CK_End_Of_Text_Highlight }, |
| 154 | { KEY_M_SHIFT | KEY_M_CTRL | KEY_LEFT, CK_Word_Left_Highlight }, |
| 155 | { KEY_M_SHIFT | KEY_M_CTRL | KEY_RIGHT, CK_Word_Right_Highlight }, |
| 156 | { KEY_M_SHIFT | KEY_M_CTRL | KEY_UP, CK_Scroll_Up_Highlight }, |
| 157 | { KEY_M_SHIFT | KEY_M_CTRL | KEY_DOWN, CK_Scroll_Down_Highlight }, |
| 158 | |
| 159 | { 0, 0 } |
| 160 | }; |
| 161 | |
| 162 | |
| 531 | void fill_common_key(void) |
| 532 | { |
| 533 | int k = 0; |
| 534 | for (k = 0; def_common_key_map[k].command != 0 && def_common_key_map[k].key != 0 ; ++k) |
| 535 | continue; |
| 536 | k++; |
| 537 | |
| 538 | common_key_map = (edit_key_map_type*)g_malloc ((k) * sizeof(edit_key_map_type)); |
| 539 | memcpy(common_key_map, def_common_key_map, sizeof(edit_key_map_type) * k); |
| 540 | |
| 541 | for (int i = 0; i<k ; ++i) { |
| 542 | mc_log("common_key_map[%d].key=%d = common_key_map[%d].command=%d \n",i, common_key_map[i].key, i, common_key_map[i].command); |
| 543 | } |
| 544 | |
| 545 | } |
| 546 | |
| 547 | int |
| 548 | remap_key (long x_key, long x_command) |
| 549 | { |
| 550 | int i = 0; |
| 551 | int k = 0; |
| 552 | for (k = 0; common_key_map[k].command != 0 && common_key_map[k].key != 0 ; ++k) |
| 553 | continue; |
| 554 | k++; |
| 555 | |
| 556 | for (i = 0; i<=k ; ++i) { |
| 557 | if (common_key_map[i].command == 0 || common_key_map[i].command == x_command) { |
| 558 | break; |
| 559 | } |
| 560 | } |
| 561 | mc_log("remap i=%d, keys_count=%d \n", i, k); |
| 562 | |
| 563 | if (common_key_map[i].command != 0) { |
| 564 | mc_log("b common_key_map[%d].key=%d = common_key_map[%d].command=%d \n",i, common_key_map[i].key, i, common_key_map[i].command); |
| 565 | common_key_map[i].key = x_key; |
| 566 | mc_log("a common_key_map[%d].key=%d = common_key_map[%d].command=%d \n",i, common_key_map[i].key, i, common_key_map[i].command); |
| 567 | return 1; |
| 568 | } else { |
| 569 | common_key_map[i].key = x_key; |
| 570 | common_key_map[i].command = x_command; |
| 571 | k++; |
| 572 | common_key_map = (edit_key_map_type*)g_realloc(common_key_map, (k + 1) * sizeof(edit_key_map_type)); |
| 573 | common_key_map[k].key = 0; |
| 574 | common_key_map[k].command = 0; |
| 575 | return 2; |
| 576 | } |
| 577 | |
| 578 | } |
| 579 | |