add redefine keys support in viewer
[midnight-commander.git] / src / keybind.c
blobf84605a437e7a576c3098011c441f153ec1a2f9e
1 /* File management GUI for the text mode edition
3 * Copyright (C) 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003,
4 * 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
6 * Written by: 2005 Vitja Makarov
7 * 2009 Ilia Maslakov
9 * The copy code was based in GNU's cp, and was written by:
10 * Torbjorn Granlund, David MacKenzie, and Jim Meyering.
12 * The move code was based in GNU's mv, and was written by:
13 * Mike Parker and David MacKenzie.
15 * Janne Kukonlehto added much error recovery to them for being used
16 * in an interactive program.
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
33 #include <config.h>
35 #include <ctype.h>
36 #include <errno.h>
37 #include <stdarg.h>
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <string.h>
41 #include <sys/types.h>
42 #include <sys/stat.h>
43 #include <unistd.h>
45 #include "global.h"
47 #include "cmddef.h" /* CK_ cmd name const */
48 #include "tty/win.h"
49 #include "tty/key.h" /* KEY_M_ */
50 #include "tty/tty.h" /* keys */
51 #include "wtools.h"
52 #include "keybind.h"
54 static const name_key_map_t command_names[] = {
55 { "EditNoCommand", CK_Ignore_Key },
56 { "EditIgnoreKey", CK_Ignore_Key },
57 { "EditBackSpace", CK_BackSpace },
58 { "EditDelete", CK_Delete },
59 { "EditEnter", CK_Enter },
60 { "EditPageUp", CK_Page_Up },
61 { "EditPageDown", CK_Page_Down },
62 { "EditLeft", CK_Left },
63 { "EditRight", CK_Right },
64 { "EditWordLeft", CK_Word_Left },
65 { "EditWordRight", CK_Word_Right },
66 { "EditUp", CK_Up },
67 { "EditDown", CK_Down },
68 { "EditHome", CK_Home },
69 { "EditEnd", CK_End },
70 { "EditTab", CK_Tab },
71 { "EditUndo", CK_Undo },
72 { "EditBeginningOfText", CK_Beginning_Of_Text },
73 { "EditEndOfText", CK_End_Of_Text },
74 { "EditScrollUp", CK_Scroll_Up },
75 { "EditScrollDown", CK_Scroll_Down },
76 { "EditReturn", CK_Return },
77 { "EditBeginPage", CK_Begin_Page },
78 { "EditEndPage", CK_End_Page },
79 { "EditDeleteWordLeft", CK_Delete_Word_Left },
80 { "EditDeleteWordRight", CK_Delete_Word_Right },
81 { "EditParagraphUp", CK_Paragraph_Up },
82 { "EditParagraphDown", CK_Paragraph_Down },
83 { "EditSave", CK_Save },
84 { "EditLoad", CK_Load },
85 { "EditNew", CK_New },
86 { "EditSaveas", CK_Save_As },
87 { "EditMark", CK_Mark },
88 { "EditCopy", CK_Copy },
89 { "EditMove", CK_Move },
90 { "EditRemove", CK_Remove },
91 { "EditUnmark", CK_Unmark },
92 { "EditSaveBlock", CK_Save_Block },
93 { "EditColumnMark", CK_Column_Mark },
94 { "EditFind", CK_Find },
95 { "EditFindAgain", CK_Find_Again },
96 { "EditReplace", CK_Replace },
97 { "EditReplaceAgain", CK_Replace_Again },
98 { "EditCompleteWord", CK_Complete_Word },
99 { "EditDebugStart", CK_Debug_Start },
100 { "EditDebugStop", CK_Debug_Stop },
101 { "EditDebugToggleBreak", CK_Debug_Toggle_Break },
102 { "EditDebugClear", CK_Debug_Clear },
103 { "EditDebugNext", CK_Debug_Next },
104 { "EditDebugStep", CK_Debug_Step },
105 { "EditDebugBackTrace", CK_Debug_Back_Trace },
106 { "EditDebugContinue", CK_Debug_Continue },
107 { "EditDebugEnterCommand", CK_Debug_Enter_Command },
108 { "EditDebugUntilCurser", CK_Debug_Until_Curser },
109 { "EditInsertFile", CK_Insert_File },
110 { "EditExit", CK_Exit },
111 { "EditToggleInsert", CK_Toggle_Insert },
112 { "EditHelp", CK_Help },
113 { "EditDate", CK_Date },
114 { "EditRefresh", CK_Refresh },
115 { "EditGoto", CK_Goto },
116 { "EditDeleteLine", CK_Delete_Line },
117 { "EditDeleteToLineEnd", CK_Delete_To_Line_End },
118 { "EditDeleteToLineBegin", CK_Delete_To_Line_Begin },
119 { "EditManPage", CK_Man_Page },
120 { "EditSort", CK_Sort },
121 { "EditMail", CK_Mail },
122 { "EditCancel", CK_Cancel },
123 { "EditComplete", CK_Complete },
124 { "EditParagraphFormat", CK_Paragraph_Format },
125 { "EditUtil", CK_Util },
126 { "EditTypeLoadPython", CK_Type_Load_Python },
127 { "EditFindFile", CK_Find_File },
128 { "EditCtags", CK_Ctags },
129 { "EditMatchBracket", CK_Match_Bracket },
130 { "EditTerminal", CK_Terminal },
131 { "EditTerminalApp", CK_Terminal_App },
132 { "EditExtCmd", CK_ExtCmd },
133 { "EditUserMenu", CK_User_Menu },
134 { "EditSaveDesktop", CK_Save_Desktop },
135 { "EditNewWindow", CK_New_Window },
136 { "EditCycle", CK_Cycle },
137 { "EditMenu", CK_Menu },
138 { "EditSaveAndQuit", CK_Save_And_Quit },
139 { "EditRunAnother", CK_Run_Another },
140 { "EditCheckSaveAndQuit", CK_Check_Save_And_Quit },
141 { "EditMaximize", CK_Maximize },
142 { "EditBeginRecordMacro", CK_Begin_Record_Macro },
143 { "EditEndRecordMacro", CK_End_Record_Macro },
144 { "EditDeleteMacro", CK_Delete_Macro },
145 { "EditToggleBookmark", CK_Toggle_Bookmark },
146 { "EditFlushBookmarks", CK_Flush_Bookmarks },
147 { "EditNextBookmark", CK_Next_Bookmark },
148 { "EditPrevBookmark", CK_Prev_Bookmark },
149 { "EditPageUpHighlight", CK_Page_Up_Highlight },
150 { "EditPageDownHighlight", CK_Page_Down_Highlight },
151 { "EditLeftHighlight", CK_Left_Highlight },
152 { "EditRightHighlight", CK_Right_Highlight },
153 { "EditWordLeftHighlight", CK_Word_Left_Highlight },
154 { "EditWordRightHighlight", CK_Word_Right_Highlight },
155 { "EditUpHighlight", CK_Up_Highlight },
156 { "EditDownHighlight", CK_Down_Highlight },
157 { "EditHomeHighlight", CK_Home_Highlight },
158 { "EditEndHighlight", CK_End_Highlight },
159 { "EditBeginningOfTextHighlight", CK_Beginning_Of_Text_Highlight },
160 { "EditEndOfTextHighlight", CK_End_Of_Text_Highlight },
161 { "EditBeginPageHighlight", CK_Begin_Page_Highlight },
162 { "EditEndPageHighlight", CK_End_Page_Highlight },
163 { "EditScrollUpHighlight", CK_Scroll_Up_Highlight },
164 { "EditScrollDownHighlight", CK_Scroll_Down_Highlight },
165 { "EditParagraphUpHighlight", CK_Paragraph_Up_Highlight },
166 { "EditParagraphDownHighlight", CK_Paragraph_Down_Highlight },
167 { "EditXStore", CK_XStore },
168 { "EditXCut", CK_XCut },
169 { "EditXPaste", CK_XPaste },
170 { "EditSelectionHistory", CK_Selection_History },
171 { "EditShell", CK_Shell },
172 { "EditSelectCodepage", CK_Select_Codepage },
173 { "EditInsertLiteral", CK_Insert_Literal },
174 { "EditExecuteMacro", CK_Execute_Macro },
175 { "EditBeginorEndMacro", CK_Begin_End_Macro },
176 { "EditExtmode", CK_Ext_Mode },
177 { "EditToggleLineState", CK_Toggle_Line_State },
178 #if 0
179 { "EditFocusNext", CK_Focus_Next },
180 { "EditFocusPrev", CK_Focus_Prev },
181 { "EditHeightInc", CK_Height_Inc },
182 { "EditHeightDec", CK_Height_Dec },
183 { "EditMake", CK_Make },
184 { "EditErrorNext", CK_Error_Next },
185 { "EditErrorPrev", CK_Error_Prev },
186 #endif
188 /* viewer */
189 { "ViewSearch", CK_ViewSearch },
190 { "ViewContinueSearch", CK_ViewContinueSearch },
191 { "ViewGotoBookmark", CK_ViewGotoBookmark },
192 { "ViewNewBookmark", CK_ViewNewBookmark },
193 { "ViewMoveUp", CK_ViewMoveUp },
194 { "ViewMoveDown", CK_ViewMoveDown },
195 { "ViewMoveLeft", CK_ViewMoveLeft },
196 { "ViewMoveRight", CK_ViewMoveRight },
197 { "ViewMovePgDn", CK_ViewMovePgDn },
198 { "ViewMovePgUp", CK_ViewMovePgUp },
199 { "ViewMoveHalfPgDn", CK_ViewMoveHalfPgDn },
200 { "ViewMoveHalfPgUp", CK_ViewMoveHalfPgUp },
201 { "ViewMoveToBol", CK_ViewMoveToBol },
202 { "ViewMoveToEol", CK_ViewMoveToEol },
203 { "ViewNextFile", CK_ViewNextFile },
204 { "ViewPrevFile", CK_ViewPrevFile },
205 { "ViewToggleRuler", CK_ViewToggleRuler },
206 { "HexViewToggleNavigationMode", CK_HexViewToggleNavigationMode },
207 { "ViewQuit", CK_ViewQuit },
209 /* main commands */
210 { "CmdChmod", CK_ChmodCmd },
211 { "CmdChownAdvanced", CK_ChownAdvancedCmd },
212 { "CmdChown", CK_ChownCmd },
213 { "CmdCompareDirs", CK_CompareDirsCmd },
214 { "CmdConfigureBox", CK_ConfigureBox },
215 { "CmdConfigureVfs", CK_ConfigureVfs },
216 { "CmdConfirmBox", CK_ConfirmBox },
217 { "CmdCopy", CK_CopyCmd },
218 { "CmdDelete", CK_DeleteCmd },
219 { "CmdDirsizes", CK_DirsizesCmd },
220 { "CmdDisplayBitsBox", CK_DisplayBitsBox },
221 { "CmdEdit", CK_EditCmd },
222 { "CmdEditMcMenu", CK_EditMcMenuCmd },
223 { "CmdEditSymlink", CK_EditSymlinkCmd },
224 { "CmdEditSyntax", CK_EditSyntaxCmd },
225 { "CmdEditUserMenu", CK_EditUserMenuCmd },
226 { "CmdExternalPanelize", CK_ExternalPanelize },
227 { "CmdFilter", CK_FilterCmd },
228 { "CmdFilteredView", CK_FilteredViewCmd },
229 { "CmdFind", CK_FindCmd },
230 { "CmdFishlink", CK_FishlinkCmd },
231 { "CmdFtplink", CK_FtplinkCmd },
232 { "CmdHistory", CK_HistoryCmd },
233 { "CmdInfo", CK_InfoCmd },
234 { "CmdJobs", CK_JobsCmd },
235 { "CmdLayout", CK_LayoutCmd },
236 { "CmdLearnKeys", CK_LearnKeys },
237 { "CmdLink", CK_LinkCmd },
238 { "CmdListing", CK_ListingCmd },
239 { "CmdMkdir", CK_MkdirCmd },
240 { "CmdQuickCd", CK_QuickCdCmd },
241 { "CmdQuickChdir", CK_QuickChdirCmd },
242 { "CmdQuickView", CK_QuickViewCmd },
243 { "CmdQuietQuit", CK_QuietQuitCmd },
244 { "CmdRename", CK_RenCmd },
245 { "CmdReread", CK_RereadCmd },
246 { "CmdReselectVfs", CK_ReselectVfs },
247 { "CmdReverseSelection", CK_ReverseSelectionCmd },
248 { "CmdSaveSetup", CK_SaveSetupCmd },
249 { "CmdSelect", CK_SelectCmd },
250 { "CmdSwapPanel", CK_SwapCmd },
251 { "CmdSymlink", CK_SymlinkCmd },
252 { "CmdTree", CK_TreeCmd },
253 { "CmdUndelete", CK_UndeleteCmd },
254 { "CmdUnselect", CK_UnselectCmd },
255 { "CmdUserFileMenu", CK_UserFileMenuCmd },
256 { "CmdView", CK_ViewCmd },
257 { "CmdViewFile", CK_ViewFileCmd },
258 { "CmdViewOther", CK_ViewOtherCmd },
259 { "CmdCmdCopyCurrentReadlink", CK_CopyCurrentReadlink },
260 { "CmdCopyOtherReadlink", CK_CopyOtherReadlink },
261 { "CmdAddHotlist", CK_AddHotlist },
262 { "CmdStartExt", CK_StartExtCmd },
263 { "CmdQuit", CK_QuitCmd },
264 { "CmdCopyOtherTarget", CK_CopyOtherTarget },
265 { "CmdCopyOthertReadlink", CK_CopyOthertReadlink },
267 /* panel */
268 { "PanelChdirOtherPanel", CK_PanelChdirOtherPanel },
269 { "PanelChdirToReadlink", CK_PanelChdirToReadlink },
270 { "PanelCopyLocal", CK_PanelCmdCopyLocal },
271 { "PanelDeleteLocal", CK_PanelCmdDeleteLocal },
272 { "PanelDoEnter", CK_PanelCmdDoEnter },
273 { "PanelEditNew", CK_PanelCmdEditNew },
274 { "PanelRenameLocal", CK_PanelCmdRenameLocal },
275 { "PanelReverseSelection", CK_PanelCmdReverseSelection },
276 { "PanelSelect", CK_PanelCmdSelect },
277 { "PanelUnselect", CK_PanelCmdUnselect },
278 { "PanelViewSimple", CK_PanelCmdViewSimple },
279 { "PanelCtrlNextPage", CK_PanelCtrlNextPage },
280 { "PanelCtrlPrevPage", CK_PanelCtrlPrevPage },
281 { "PanelDirectoryHistoryList", CK_PanelDirectoryHistoryList },
282 { "PanelDirectoryHistoryNext", CK_PanelDirectoryHistoryNext },
283 { "PanelDirectoryHistoryPrev", CK_PanelDirectoryHistoryPrev },
284 { "PanelGotoBottomFile", CK_PanelGotoBottomFile },
285 { "PanelGotoMiddleFile", CK_PanelGotoMiddleFile },
286 { "PanelGotoTopFile", CK_PanelGotoTopFile },
287 { "PanelMarkFile", CK_PanelMarkFile },
288 { "PanelMoveUp", CK_PanelMoveUp },
289 { "PanelMoveDown", CK_PanelMoveDown },
290 { "PanelMoveLeft", CK_PanelMoveLeft },
291 { "PanelMoveRight", CK_PanelMoveRight },
292 { "PanelMoveEnd", CK_PanelMoveEnd },
293 { "PanelMoveHome", CK_PanelMoveHome },
294 { "PanelNextPage", CK_PanelNextPage },
295 { "PanelPrevPage", CK_PanelPrevPage },
296 { "PanelSetPanelEncoding", CK_PanelSetPanelEncoding },
297 { "PanelStartSearch", CK_PanelStartSearch },
298 { "PanelSyncOtherPanel", CK_PanelSyncOtherPanel },
299 { NULL, 0 }
302 int lookup_action (char *keyname)
304 int i;
306 for (i = 0; command_names [i].name; i++){
307 if (!str_casecmp (command_names [i].name, keyname))
308 return command_names [i].val;
310 return 0;
313 void
314 keymap_add(GArray *keymap, int key, int cmd)
316 global_key_map_t new_bind, *map;
317 guint i;
318 map = &(g_array_index(keymap, global_key_map_t, 0));
320 if (key !=0 && cmd !=0) {
321 new_bind.key = key;
322 new_bind.command = cmd;
323 g_array_append_val(keymap, new_bind);
328 void
329 keybind_cmd_bind(GArray *keymap, char *keybind, int action)
331 keymap_add(keymap, lookup_key(keybind), action);