From 592ddbf39edc173a3decbb1c405d66be3757edaa Mon Sep 17 00:00:00 2001 From: Ilia Maslakov Date: Sun, 20 Sep 2009 19:43:56 +0000 Subject: [PATCH] refactoring editor keybindings add more keys into mc.keymap Signed-off-by: Ilia Maslakov --- edit/edit.c | 6 +- edit/editkeys.c | 82 +--------------- misc/mc.keymap | 59 +++++++++++- src/keybind.c | 285 +++++++++++++++++++++++++++++++++++++++----------------- src/keybind.h | 7 +- 5 files changed, 275 insertions(+), 164 deletions(-) diff --git a/edit/edit.c b/edit/edit.c index ea0b2093c..4559da81f 100644 --- a/edit/edit.c +++ b/edit/edit.c @@ -722,7 +722,11 @@ edit_purge_widget (WEdit *edit) static void edit_set_keymap (WEdit *edit) { - edit->user_map = (global_key_map_t *) editor_keymap->data; + edit->user_map = default_edit_keymap; + if (editor_keymap && editor_keymap->len > 0) { + edit->user_map = (global_key_map_t *) editor_keymap->data; + mc_log ("edit->user_map"); + } } diff --git a/edit/editkeys.c b/edit/editkeys.c index 17bea03a1..fb966cffd 100644 --- a/edit/editkeys.c +++ b/edit/editkeys.c @@ -218,56 +218,6 @@ edit_translate_key (WEdit *edit, long x_key, int *cmd, int *ch) int extmod = 0; int c; - const global_key_map_t *key_map = NULL; - switch (edit_key_emulation) { - case EDIT_KEY_EMULATION_NORMAL: - key_map = cooledit_key_map; - break; - case EDIT_KEY_EMULATION_EMACS: - key_map = emacs_key_map; - if (x_key == XCTRL ('x')) { - int ext_key; - ext_key = - editcmd_dialog_raw_key_query (" Ctrl-X ", _(" Emacs key: "), 0); - switch (ext_key) { - case 's': - command = CK_Save; - goto fin; - case 'x': - command = CK_Exit; - goto fin; - case 'k': - command = CK_New; - goto fin; - case 'e': - command = - CK_Macro (editcmd_dialog_raw_key_query - (_(" Execute Macro "), - _(" Press macro hotkey: "), 1)); - if (command == CK_Macro (0)) - command = CK_Insert_Char; - goto fin; - } - goto fin; - } - break; - - case EDIT_KEY_EMULATION_USER: - if (edit->user_map != NULL) { - if (edit->extmod && edit->ext_map != NULL) { - key_map = edit->ext_map; - extmod = 1; - } else { - key_map = edit->user_map; - } - edit->extmod = 0; - } else { - key_map = edit->user_map = cooledit_key_map; - } - break; - } - assert (key_map != NULL); - /* an ordinary insertable character */ if (x_key < 256 && !extmod) { #ifdef HAVE_CHARSET @@ -292,7 +242,7 @@ edit_translate_key (WEdit *edit, long x_key, int *cmd, int *ch) } #ifdef HAVE_CHARSET } else { - c = convert_from_input_c (x_key); + c = convert_from_input_c (x_key); if (is_printable (c)) { char_for_insertion = convert_from_8bit_to_utf_c2((unsigned char) x_key); goto fin; @@ -347,34 +297,12 @@ edit_translate_key (WEdit *edit, long x_key, int *cmd, int *ch) } /* Commands specific to the key emulation */ - for (i = 0; key_map[i].key != 0 && key_map[i].key != x_key; i++) - continue; - if (key_map[i].key != 0) { - command = key_map[i].command; - goto fin; - } - - /* Commands common for the key emulations */ - key_map = common_key_map; - for (i = 0; key_map[i].key != 0 && key_map[i].key != x_key; i++) - continue; - if (key_map[i].key != 0) { - command = key_map[i].command; - goto fin; + for (i = 0; edit->user_map[i].key != 0; i++) { + if (x_key == edit->user_map[i].key) { + command = edit->user_map[i].command; + } } - /* Function still not found for this key, so try macros */ - /* This allows the same macro to be - enabled by either eg "ALT('f')" or "XCTRL('f')" or "XCTRL('a'), 'f'" */ - - if (x_key & ALT (0)) { /* is an alt key ? */ - command = CK_Macro (x_key - ALT (0)); - goto fin; - } - if (x_key < ' ') { /* is a ctrl key ? */ - command = CK_Macro (x_key); - goto fin; - } fin: *cmd = command; diff --git a/misc/mc.keymap b/misc/mc.keymap index e521b2aef..fbcf81f1f 100644 --- a/misc/mc.keymap +++ b/misc/mc.keymap @@ -3,6 +3,63 @@ EditXStore = ctrl g EditXPaste = ctrl v EditXCut = ctrl x EditDeleteLine = ctrl y +EditLeft = left +EditRight = right +EditUp = up +EditDown = down +EditEnter = enter +EditBackSpace = backspace +EditDelete = delete +EditPageUp = pgup +EditPageDown = pgdn +EditWordLeft = ctrl left +EditWordRight = ctrl right +EditHome = home +EditEnd = end +EditTab = tab +EditUndo = alt backspace +EditBeginningOfText = ctrl shift pgup +EditEndOfText = ctrl shift pgdn +EditScrollUp = ctrl up +EditScrollDown = ctrl down +EditReturn = shift enter +EditBeginPage = +EditEndPage = +EditDeleteWordLeft = alt f +EditDeleteWordRight = alt d +EditParagraphUp = +EditParagraphDown = +EditSave = f2 +EditLoad = +EditNew = +EditSaveas = f12 +EditMark = f3 +EditCopy = f5 +EditMove = f6 +EditRemove = f8 +EditUnmark = +EditFind = f7 +EditPageUpHighlight = shift pgup +EditPageDownHighlight = shift pgdn +EditLeftHighlight = shift left +EditRightHighlight = shift right +EditWordLeftHighlight = ctrl shift left +EditWordRightHighlight = ctrl shift right +EditUpHighlight = shift up +EditDownHighlight = shift down +EditHomeHighlight = shift home +EditEndHighlight = shift end +EditBeginningOfTextHighlight = ctrl shift home +EditEndOfTextHighlight = ctrl shift end +EditBeginPageHighlight = ctrl shift pgup +EditEndPageHighlight = ctrl shift pgdn +EditScrollUpHighlight = +EditScrollDownHighlight = +EditParagraphUpHighlight = +EditParagraphDownHighlight = + + + [viewer:hex] HexViewToggleNavigationMode = tab @@ -62,8 +119,6 @@ PanelMoveDown = down PanelMoveUp = up PanelMoveLeft = left PanelMoveRight = right -PanelMoveHome = home -PanelMoveEnd = end PanelPrevPage = pgup PanelNextPage = pgdn PanelDoEnter = enter diff --git a/src/keybind.c b/src/keybind.c index 7e64c6587..0c57f12c4 100644 --- a/src/keybind.c +++ b/src/keybind.c @@ -333,116 +333,235 @@ static const name_key_map_t command_names[] = { /* viewer/actions_cmd.c */ const global_key_map_t default_viewer_keymap[] = { - { '?', CK_ViewSearch }, - { '/', CK_ViewSearch }, - { XCTRL('r'), CK_ViewContinueSearch }, - { XCTRL('s'), CK_ViewContinueSearch }, - { KEY_F (17), CK_ViewContinueSearch }, - { ALT('r'), CK_ViewToggleRuler }, + { '?', CK_ViewSearch }, + { '/', CK_ViewSearch }, + { XCTRL('r'), CK_ViewContinueSearch }, + { XCTRL('s'), CK_ViewContinueSearch }, + { KEY_F (17), CK_ViewContinueSearch }, + { ALT('r'), CK_ViewToggleRuler }, - { KEY_HOME, CK_ViewMoveToBol }, - { KEY_END, CK_ViewMoveToEol }, + { KEY_HOME, CK_ViewMoveToBol }, + { KEY_END, CK_ViewMoveToEol }, - { 'h', CK_ViewMoveLeft }, - { KEY_LEFT, CK_ViewMoveLeft }, + { 'h', CK_ViewMoveLeft }, + { KEY_LEFT, CK_ViewMoveLeft }, - { 'l', CK_ViewMoveRight }, - { KEY_RIGHT, CK_ViewMoveRight }, + { 'l', CK_ViewMoveRight }, + { KEY_RIGHT, CK_ViewMoveRight }, - { 'k', CK_ViewMoveUp }, - { 'y', CK_ViewMoveUp }, - { KEY_IC, CK_ViewMoveUp }, - { KEY_UP, CK_ViewMoveUp }, + { 'k', CK_ViewMoveUp }, + { 'y', CK_ViewMoveUp }, + { KEY_IC, CK_ViewMoveUp }, + { KEY_UP, CK_ViewMoveUp }, - { 'j', CK_ViewMoveDown }, - { 'e', CK_ViewMoveDown }, - { KEY_DOWN, CK_ViewMoveDown }, - { KEY_DC, CK_ViewMoveDown }, + { 'j', CK_ViewMoveDown }, + { 'e', CK_ViewMoveDown }, + { KEY_DOWN, CK_ViewMoveDown }, + { KEY_DC, CK_ViewMoveDown }, + { ' ', CK_ViewMovePgDn }, + { 'f', CK_ViewMovePgDn }, + { KEY_NPAGE, CK_ViewMovePgDn }, - { ' ', CK_ViewMovePgDn }, - { 'f', CK_ViewMovePgDn }, - { KEY_NPAGE, CK_ViewMovePgDn }, + { 'b', CK_ViewMovePgUp }, + { KEY_PPAGE, CK_ViewMovePgUp }, - { 'b', CK_ViewMovePgUp }, - { KEY_PPAGE, CK_ViewMovePgUp }, + { 'd', CK_ViewMoveHalfPgDn }, + { 'u', CK_ViewMoveHalfPgUp }, - { 'd', CK_ViewMoveHalfPgDn }, + { 'm', CK_ViewGotoBookmark }, + { 'r', CK_ViewNewBookmark }, - { 'u', CK_ViewMoveHalfPgUp }, + { XCTRL ('f'), CK_ViewNextFile }, + { XCTRL ('b'), CK_ViewPrevFile }, - { 'm', CK_ViewGotoBookmark }, - { 'r', CK_ViewNewBookmark }, + { 'q', CK_ViewQuit }, + { XCTRL ('g'), CK_ViewQuit }, + { ESC_CHAR, CK_ViewQuit }, - { XCTRL ('f'), CK_ViewNextFile }, - { XCTRL ('b'), CK_ViewPrevFile }, - - { 'q', CK_ViewQuit }, - { XCTRL ('g'), CK_ViewQuit }, - { ESC_CHAR, CK_ViewQuit }, - - { XCTRL ('t'), CK_SelectCodepage }, - { XCTRL('o'), CK_ShowCommandLine }, + { XCTRL ('t'), CK_SelectCodepage }, + { XCTRL('o'), CK_ShowCommandLine }, { 0, 0 } }; const global_key_map_t default_viewer_hex_keymap[] = { - { '\t', CK_HexViewToggleNavigationMode }, - { XCTRL ('a'), CK_ViewMoveToBol }, - { XCTRL ('e'), CK_ViewMoveToEol }, + { '\t', CK_HexViewToggleNavigationMode }, + { XCTRL ('a'), CK_ViewMoveToBol }, + { XCTRL ('e'), CK_ViewMoveToEol }, - { 'b', CK_ViewMoveLeft }, - { KEY_LEFT, CK_ViewMoveLeft }, + { 'b', CK_ViewMoveLeft }, + { KEY_LEFT, CK_ViewMoveLeft }, - { 'f', CK_ViewMoveRight }, - { KEY_RIGHT, CK_ViewMoveRight }, + { 'f', CK_ViewMoveRight }, + { KEY_RIGHT, CK_ViewMoveRight }, - { 'k', CK_ViewMoveUp }, - { 'y', CK_ViewMoveUp }, - { KEY_UP, CK_ViewMoveUp }, + { 'k', CK_ViewMoveUp }, + { 'y', CK_ViewMoveUp }, + { KEY_UP, CK_ViewMoveUp }, - { 'j', CK_ViewMoveDown }, - { KEY_DOWN, CK_ViewMoveDown }, - { KEY_DC, CK_ViewMoveDown }, + { 'j', CK_ViewMoveDown }, + { KEY_DOWN, CK_ViewMoveDown }, + { KEY_DC, CK_ViewMoveDown }, { 0, 0 } }; + +/* ../edit/editkeys.c */ +const global_key_map_t default_editor_keymap[] = { + { '\n', CK_Enter }, + { '\t', CK_Tab }, + + { ESC_CHAR, CK_Exit }, + { KEY_BACKSPACE, CK_BackSpace }, + { KEY_DC, CK_Delete }, + { KEY_DOWN, CK_Down }, + { KEY_END, CK_End }, + { KEY_HOME, CK_Home }, + { KEY_IC, CK_Toggle_Insert }, + { KEY_LEFT, CK_Left }, + { KEY_NPAGE, CK_Page_Down }, + { KEY_PPAGE, CK_Page_Up }, + { KEY_RIGHT, CK_Right }, + { KEY_UP, CK_Up }, + + { ALT ('\n'), CK_Find_Definition }, + { ALT ('\t'), CK_Complete_Word }, + { ALT ('l'), CK_Goto }, + { ALT ('L'), CK_Goto }, + { ALT ('p'), CK_Paragraph_Format }, + { ALT ('t'), CK_Sort }, + { ALT ('u'), CK_ExtCmd }, + { ALT ('<'), CK_Beginning_Of_Text }, + { ALT ('>'), CK_End_Of_Text }, + { ALT ('-'), CK_Load_Prev_File }, + { ALT ('='), CK_Load_Next_File }, + { ALT ('d'), CK_Delete_Word_Right }, + { ALT (KEY_BACKSPACE), CK_Delete_Word_Left }, + { ALT ('n'), CK_Toggle_Line_State }, + { ALT ('_'), CK_Toggle_Tab_TWS }, + { ALT ('k'), CK_Toggle_Bookmark }, + { ALT ('i'), CK_Prev_Bookmark }, + { ALT ('j'), CK_Next_Bookmark }, + { ALT ('o'), CK_Flush_Bookmarks }, + + { XCTRL ('k'), CK_Delete_To_Line_End }, + { XCTRL ('l'), CK_Refresh }, + { XCTRL ('o'), CK_Shell }, + { XCTRL ('s'), CK_Toggle_Syntax }, + { XCTRL ('u'), CK_Undo }, + { XCTRL ('t'), CK_SelectCodepage }, + { XCTRL ('q'), CK_Insert_Literal }, + { XCTRL ('a'), CK_Execute_Macro }, + { XCTRL ('r'), CK_Begin_End_Macro }, + + { KEY_F (1), CK_Help }, + { KEY_F (2), CK_Save }, + { KEY_F (3), CK_Mark }, + { KEY_F (4), CK_Replace }, + { KEY_F (5), CK_Copy }, + { KEY_F (6), CK_Move }, + { KEY_F (7), CK_Find }, + { KEY_F (8), CK_Remove }, + { KEY_F (10), CK_Exit }, + /* edit user menu */ + { KEY_F (11), CK_User_Menu }, + { KEY_F (12), CK_Save_As }, + { KEY_F (13), CK_Column_Mark }, + { KEY_F (14), CK_Replace_Again }, + { KEY_F (15), CK_Insert_File }, + { KEY_F (17), CK_Find_Again }, + /* C formatter */ + { KEY_F (19), CK_Pipe_Block (0) }, + + /* Shift */ + { KEY_M_SHIFT | KEY_PPAGE, CK_Page_Up_Highlight }, + { KEY_M_SHIFT | KEY_NPAGE, CK_Page_Down_Highlight }, + { KEY_M_SHIFT | KEY_LEFT, CK_Left_Highlight }, + { KEY_M_SHIFT | KEY_RIGHT, CK_Right_Highlight }, + { KEY_M_SHIFT | KEY_UP, CK_Up_Highlight }, + { KEY_M_SHIFT | KEY_DOWN, CK_Down_Highlight }, + { KEY_M_SHIFT | KEY_HOME, CK_Home_Highlight }, + { KEY_M_SHIFT | KEY_END, CK_End_Highlight }, + { KEY_M_SHIFT | KEY_IC, CK_XPaste }, + { KEY_M_SHIFT | KEY_DC, CK_XCut }, + /* useful for pasting multiline text */ + { KEY_M_SHIFT | '\n', CK_Return }, + + /* Alt */ + { KEY_M_ALT | KEY_PPAGE, CK_Page_Up_Alt_Highlight }, + { KEY_M_ALT | KEY_NPAGE, CK_Page_Down_Highlight }, + { KEY_M_ALT | KEY_LEFT, CK_Left_Alt_Highlight }, + { KEY_M_ALT | KEY_RIGHT, CK_Right_Alt_Highlight }, + { KEY_M_ALT | KEY_UP, CK_Up_Alt_Highlight }, + { KEY_M_ALT | KEY_DOWN, CK_Down_Alt_Highlight }, + { KEY_M_ALT | KEY_HOME, CK_Home_Highlight }, + { KEY_M_ALT | KEY_END, CK_End_Alt_Highlight }, + + /* Ctrl */ + { KEY_M_CTRL | (KEY_F (2)), CK_Save_As }, + { KEY_M_CTRL | (KEY_F (4)), CK_Replace_Again }, + { KEY_M_CTRL | (KEY_F (7)), CK_Find_Again }, + { KEY_M_CTRL | KEY_BACKSPACE, CK_Undo }, + { KEY_M_CTRL | KEY_PPAGE, CK_Beginning_Of_Text }, + { KEY_M_CTRL | KEY_NPAGE, CK_End_Of_Text }, + { KEY_M_CTRL | KEY_HOME, CK_Beginning_Of_Text }, + { KEY_M_CTRL | KEY_END, CK_End_Of_Text }, + { KEY_M_CTRL | KEY_UP, CK_Scroll_Up }, + { KEY_M_CTRL | KEY_DOWN, CK_Scroll_Down }, + { KEY_M_CTRL | KEY_LEFT, CK_Word_Left }, + { KEY_M_CTRL | KEY_RIGHT, CK_Word_Right }, + { KEY_M_CTRL | KEY_IC, CK_XStore }, + { KEY_M_CTRL | KEY_DC, CK_Remove }, + + /* Ctrl + Shift */ + { KEY_M_SHIFT | KEY_M_CTRL | KEY_PPAGE, CK_Beginning_Of_Text_Highlight }, + { KEY_M_SHIFT | KEY_M_CTRL | KEY_NPAGE, CK_End_Of_Text_Highlight }, + { KEY_M_SHIFT | KEY_M_CTRL | KEY_LEFT, CK_Word_Left_Highlight }, + { KEY_M_SHIFT | KEY_M_CTRL | KEY_RIGHT, CK_Word_Right_Highlight }, + { KEY_M_SHIFT | KEY_M_CTRL | KEY_UP, CK_Scroll_Up_Highlight }, + { KEY_M_SHIFT | KEY_M_CTRL | KEY_DOWN, CK_Scroll_Down_Highlight }, + + { XCTRL ('x'), CK_StartExtMap1 }, + + { 0, 0 } +}; + /* screen.c */ const global_key_map_t default_panel_keymap[] = { - { ALT('o'), CK_PanelChdirOtherPanel }, - { ALT('l'), CK_PanelChdirToReadlink }, - { KEY_F(15), CK_PanelCmdCopyLocal }, - { KEY_F(18), CK_PanelCmdDeleteLocal }, - { KEY_ENTER, CK_PanelCmdDoEnter }, - { '\n', CK_PanelCmdDoEnter }, - { KEY_F(14), CK_PanelCmdEditNew }, - { KEY_F(16), CK_PanelCmdRenameLocal }, - { ALT('*'), CK_PanelCmdReverseSelection }, - { KEY_KP_ADD, CK_PanelCmdSelect }, - { KEY_KP_SUBTRACT, CK_PanelCmdUnselect }, - { KEY_F(13), CK_PanelCmdViewSimple }, - { KEY_M_CTRL | KEY_NPAGE, CK_PanelCtrlNextPage }, - { KEY_M_CTRL | KEY_PPAGE, CK_PanelCtrlPrevPage }, - { ALT('H'), CK_PanelDirectoryHistoryList }, - { ALT('u'), CK_PanelDirectoryHistoryNext }, - { ALT('y'), CK_PanelDirectoryHistoryPrev }, - { ALT('j'), CK_PanelGotoBottomFile }, - { ALT('r'), CK_PanelGotoMiddleFile }, - { ALT('g'), CK_PanelGotoTopFile }, - { KEY_IC, CK_PanelMarkFile }, - { KEY_UP, CK_PanelMoveUp }, - { KEY_DOWN, CK_PanelMoveDown }, - { KEY_LEFT, CK_PanelMoveLeft }, - { KEY_RIGHT, CK_PanelMoveRight }, - { KEY_END, CK_PanelMoveEnd }, - { KEY_HOME, CK_PanelMoveHome }, - { KEY_NPAGE, CK_PanelNextPage }, - { KEY_PPAGE, CK_PanelPrevPage }, - { XCTRL('t'), CK_PanelSetPanelEncoding }, - { XCTRL('s'), CK_PanelStartSearch }, - { ALT('i'), CK_PanelSyncOtherPanel }, + { ALT('o'), CK_PanelChdirOtherPanel }, + { ALT('l'), CK_PanelChdirToReadlink }, + { KEY_F(15), CK_PanelCmdCopyLocal }, + { KEY_F(18), CK_PanelCmdDeleteLocal }, + { KEY_ENTER, CK_PanelCmdDoEnter }, + { '\n', CK_PanelCmdDoEnter }, + { KEY_F(14), CK_PanelCmdEditNew }, + { KEY_F(16), CK_PanelCmdRenameLocal }, + { ALT('*'), CK_PanelCmdReverseSelection }, + { KEY_KP_ADD, CK_PanelCmdSelect }, + { KEY_KP_SUBTRACT, CK_PanelCmdUnselect }, + { KEY_F(13), CK_PanelCmdViewSimple }, + { KEY_M_CTRL | KEY_NPAGE, CK_PanelCtrlNextPage }, + { KEY_M_CTRL | KEY_PPAGE, CK_PanelCtrlPrevPage }, + { ALT('H'), CK_PanelDirectoryHistoryList }, + { ALT('u'), CK_PanelDirectoryHistoryNext }, + { ALT('y'), CK_PanelDirectoryHistoryPrev }, + { ALT('j'), CK_PanelGotoBottomFile }, + { ALT('r'), CK_PanelGotoMiddleFile }, + { ALT('g'), CK_PanelGotoTopFile }, + { KEY_IC, CK_PanelMarkFile }, + { KEY_UP, CK_PanelMoveUp }, + { KEY_DOWN, CK_PanelMoveDown }, + { KEY_LEFT, CK_PanelMoveLeft }, + { KEY_RIGHT, CK_PanelMoveRight }, + { KEY_END, CK_PanelMoveEnd }, + { KEY_HOME, CK_PanelMoveHome }, + { KEY_NPAGE, CK_PanelNextPage }, + { KEY_PPAGE, CK_PanelPrevPage }, + { XCTRL('t'), CK_PanelSetPanelEncoding }, + { XCTRL('s'), CK_PanelStartSearch }, + { ALT('i'), CK_PanelSyncOtherPanel }, { 0, 0 } }; diff --git a/src/keybind.h b/src/keybind.h index c11b5749a..274bcf1b8 100644 --- a/src/keybind.h +++ b/src/keybind.h @@ -33,6 +33,10 @@ void keybind_cmd_bind(GArray *keymap, char *keybind, int action); extern const global_key_map_t default_viewer_keymap[]; extern const global_key_map_t default_viewer_hex_keymap[]; +/* ../edit/editkey.c */ +extern const global_key_map_t default_edit_keymap[]; +extern const global_key_map_t default_edit_x_keymap[]; + /* screen.c */ extern const global_key_map_t default_panel_keymap[]; @@ -41,4 +45,5 @@ extern const global_key_map_t default_widget_keymap[]; /* main.c */ extern const global_key_map_t default_main_map[]; -extern const global_key_map_t default_main_x_map[]; \ No newline at end of file +extern const global_key_map_t default_main_x_map[]; + -- 2.11.4.GIT