2 Definitions of key bindings.
4 Copyright (C) 2005, 2009, 2010, 2011, 2011, 2012
5 The Free Software Foundation, Inc.
9 Ilia Maslakov <il.smind@gmail.com>, 2009
10 Andrew Borodin <aborodin@vmail.ru>, 2009, 2010, 2011, 2012
12 This file is part of the Midnight Commander.
14 The Midnight Commander is free software: you can redistribute it
15 and/or modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation, either version 3 of the License,
17 or (at your option) any later version.
19 The Midnight Commander is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>.
33 #include <sys/types.h>
35 #include "lib/global.h"
36 #include "lib/tty/key.h" /* KEY_M_ */
37 #include "lib/keybind.h"
39 /*** global variables ****************************************************************************/
41 /*** file scope macro definitions ****************************************************************/
43 /*** file scope type declarations ****************************************************************/
45 /*** file scope variables ************************************************************************/
47 static name_keymap_t command_names
[] = {
49 {"InsertChar", CK_InsertChar
},
55 {"LeftQuick", CK_LeftQuick
},
56 {"RightQuick", CK_RightQuick
},
59 {"PageUp", CK_PageUp
},
60 {"PageDown", CK_PageDown
},
61 {"HalfPageUp", CK_HalfPageUp
},
62 {"HalfPageDown", CK_HalfPageDown
},
64 {"Bottom", CK_Bottom
},
65 {"TopOnScreen", CK_TopOnScreen
},
66 {"MiddleOnScreen", CK_MiddleOnScreen
},
67 {"BottomOnScreen", CK_BottomOnScreen
},
68 {"WordLeft", CK_WordLeft
},
69 {"WordRight", CK_WordRight
},
72 {"Delete", CK_Delete
},
73 {"MakeDir", CK_MakeDir
},
74 {"ChangeMode", CK_ChangeMode
},
75 {"ChangeOwn", CK_ChangeOwn
},
76 {"ChangeOwnAdvanced", CK_ChangeOwnAdvanced
},
77 {"Remove", CK_Remove
},
78 {"BackSpace", CK_BackSpace
},
82 {"MenuLastSelected", CK_MenuLastSelected
},
83 {"UserMenu", CK_UserMenu
},
84 {"EditUserMenu", CK_EditUserMenu
},
85 {"Search", CK_Search
},
86 {"SearchContinue", CK_SearchContinue
},
87 {"Replace", CK_Replace
},
88 {"ReplaceContinue", CK_ReplaceContinue
},
92 {"EditNew", CK_EditNew
},
94 {"SelectCodepage", CK_SelectCodepage
},
96 {"History", CK_History
},
97 {"HistoryNext", CK_HistoryNext
},
98 {"HistoryPrev", CK_HistoryPrev
},
99 {"Complete", CK_Complete
},
101 {"SaveAs", CK_SaveAs
},
103 {"Reread", CK_Reread
},
104 {"Refresh", CK_Refresh
},
105 {"Suspend", CK_Suspend
},
107 {"HotList", CK_HotList
},
108 {"SelectInvert", CK_SelectInvert
},
109 {"ScreenList", CK_ScreenList
},
110 {"ScreenNext", CK_ScreenNext
},
111 {"ScreenPrev", CK_ScreenPrev
},
112 {"FileNext", CK_FileNext
},
113 {"FilePrev", CK_FilePrev
},
114 {"DeleteToHome", CK_DeleteToHome
},
115 {"DeleteToEnd", CK_DeleteToEnd
},
116 {"DeleteToWordBegin", CK_DeleteToWordBegin
},
117 {"DeleteToWordEnd", CK_DeleteToWordEnd
},
122 {"MarkLeft", CK_MarkLeft
},
123 {"MarkRight", CK_MarkRight
},
124 {"MarkUp", CK_MarkUp
},
125 {"MarkDown", CK_MarkDown
},
126 {"MarkToWordBegin", CK_MarkToWordBegin
},
127 {"MarkToWordEnd", CK_MarkToWordEnd
},
128 {"MarkToHome", CK_MarkToHome
},
129 {"MarkToEnd", CK_MarkToEnd
},
130 {"ToggleNavigation", CK_ToggleNavigation
},
132 {"Options", CK_Options
},
133 {"LearnKeys", CK_LearnKeys
},
134 {"Bookmark", CK_Bookmark
},
136 {"QuitQuiet", CK_QuitQuiet
},
137 {"ExtendedKeyMap", CK_ExtendedKeyMap
},
140 #ifdef USE_INTERNAL_EDIT
141 {"EditForceInternal", CK_EditForceInternal
},
144 {"ViewRaw", CK_ViewRaw
},
145 {"ViewFile", CK_ViewFile
},
146 {"ViewFiltered", CK_ViewFiltered
},
148 {"DirSize", CK_DirSize
},
149 {"PanelListingSwitch", CK_PanelListingSwitch
},
150 {"CompareDirs", CK_CompareDirs
},
152 {"CompareFiles", CK_CompareFiles
},
154 {"OptionsVfs", CK_OptionsVfs
},
155 {"OptionsConfirm", CK_OptionsConfirm
},
156 {"OptionsDisplayBits", CK_OptionsDisplayBits
},
157 {"EditExtensionsFile", CK_EditExtensionsFile
},
158 {"EditFileHighlightFile", CK_EditFileHighlightFile
},
159 {"LinkSymbolicEdit", CK_LinkSymbolicEdit
},
160 {"ExternalPanelize", CK_ExternalPanelize
},
161 {"Filter", CK_Filter
},
162 #ifdef ENABLE_VFS_FISH
163 {"ConnectFish", CK_ConnectFish
},
165 #ifdef ENABLE_VFS_FTP
166 {"ConnectFtp", CK_ConnectFtp
},
168 #ifdef ENABLE_VFS_SMB
169 {"ConnectSmb", CK_ConnectSmb
},
171 {"PanelInfo", CK_PanelInfo
},
172 #ifdef ENABLE_BACKGROUND
175 {"OptionsLayout", CK_OptionsLayout
},
177 {"PanelListingChange", CK_PanelListingChange
},
178 {"PanelListing", CK_PanelListing
},
179 #ifdef LISTMODE_EDITOR
180 {"ListMode", CK_ListMode
}.
182 {"OptionsPanel", CK_OptionsPanel
},
183 {"CdQuick", CK_CdQuick
},
184 {"PanelQuickView", CK_PanelQuickView
},
185 {"LinkSymbolicRelative", CK_LinkSymbolicRelative
},
186 {"VfsList", CK_VfsList
},
187 {"SaveSetup", CK_SaveSetup
},
188 {"LinkSymbolic", CK_LinkSymbolic
},
189 {"PanelTree", CK_PanelTree
},
191 #ifdef ENABLE_VFS_UNDELFS
192 {"Undelete", CK_Undelete
},
194 {"PutCurrentLink", CK_PutCurrentLink
},
195 {"PutOtherLink", CK_PutOtherLink
},
196 {"HotListAdd", CK_HotListAdd
},
197 {"ShowHidden", CK_ShowHidden
},
198 {"SplitVertHoriz", CK_SplitVertHoriz
},
199 {"SplitEqual", CK_SplitEqual
},
200 {"SplitMore", CK_SplitMore
},
201 {"SplitLess", CK_SplitLess
},
202 {"PutCurrentPath", CK_PutCurrentPath
},
203 {"PutOtherPath", CK_PutOtherPath
},
204 {"PutCurrentTagged", CK_PutCurrentTagged
},
205 {"PutOtherTagged", CK_PutOtherTagged
},
206 {"Select", CK_Select
},
207 {"Unselect", CK_Unselect
},
210 {"ScrollLeft", CK_ScrollLeft
},
211 {"ScrollRight", CK_ScrollRight
},
212 {"PanelOtherCd", CK_PanelOtherCd
},
213 {"PanelOtherCdLink", CK_PanelOtherCdLink
},
214 {"CopySingle", CK_CopySingle
},
215 {"MoveSingle", CK_MoveSingle
},
216 {"DeleteSingle", CK_DeleteSingle
},
217 {"CdParent", CK_CdParent
},
218 {"CdChild", CK_CdChild
},
219 {"Panelize", CK_Panelize
},
220 {"PanelOtherSync", CK_PanelOtherSync
},
221 {"SortNext", CK_SortNext
},
222 {"SortPrev", CK_SortPrev
},
223 {"SortReverse", CK_SortReverse
},
224 {"SortByName", CK_SortByName
},
225 {"SortByExt", CK_SortByExt
},
226 {"SortBySize", CK_SortBySize
},
227 {"SortByMTime", CK_SortByMTime
},
228 {"CdParentSmart", CK_CdParentSmart
},
232 {"Cancel", CK_Cancel
},
240 {"LinkNext", CK_LinkNext
},
241 {"LinkPrev", CK_LinkPrev
},
242 {"NodeNext", CK_NodeNext
},
243 {"NodePrev", CK_NodePrev
},
246 {"Forget", CK_Forget
},
248 #if defined (USE_INTERNAL_EDIT) || defined (USE_DIFF_VIEW)
249 {"ShowNumbers", CK_ShowNumbers
},
252 #ifdef USE_INTERNAL_EDIT
255 {"ScrollUp", CK_ScrollUp
},
256 {"ScrollDown", CK_ScrollDown
},
257 {"Return", CK_Return
},
258 {"ParagraphUp", CK_ParagraphUp
},
259 {"ParagraphDown", CK_ParagraphDown
},
260 {"EditFile", CK_EditFile
},
261 {"MarkWord", CK_MarkWord
},
262 {"MarkLine", CK_MarkLine
},
263 {"MarkAll", CK_MarkAll
},
264 {"Unmark", CK_Unmark
},
265 {"MarkColumn", CK_MarkColumn
},
266 {"BlockSave", CK_BlockSave
},
267 {"InsertFile", CK_InsertFile
},
268 {"InsertOverwrite", CK_InsertOverwrite
},
270 {"DeleteLine", CK_DeleteLine
},
271 {"EditMail", CK_Mail
},
272 {"ParagraphFormat", CK_ParagraphFormat
},
273 {"MatchBracket", CK_MatchBracket
},
274 {"ExternalCommand", CK_ExternalCommand
},
275 {"MacroStartRecord", CK_MacroStartRecord
},
276 {"MacroStopRecord", CK_MacroStopRecord
},
277 {"MacroStartStopRecord", CK_MacroStartStopRecord
},
278 {"MacroDelete", CK_MacroDelete
},
279 {"RepeatStartStopRecord", CK_RepeatStartStopRecord
},
280 {"BookmarkFlush", CK_BookmarkFlush
},
281 {"BookmarkNext", CK_BookmarkNext
},
282 {"BookmarkPrev", CK_BookmarkPrev
},
283 {"MarkPageUp", CK_MarkPageUp
},
284 {"MarkPageDown", CK_MarkPageDown
},
285 {"MarkToFileBegin", CK_MarkToFileBegin
},
286 {"MarkToFileEnd", CK_MarkToFileEnd
},
287 {"MarkToPageBegin", CK_MarkToPageBegin
},
288 {"MarkToPageEnd", CK_MarkToPageEnd
},
289 {"MarkScrollUp", CK_MarkScrollUp
},
290 {"MarkScrollDown", CK_MarkScrollDown
},
291 {"MarkParagraphUp", CK_MarkParagraphUp
},
292 {"MarkParagraphDown", CK_MarkParagraphDown
},
293 {"MarkColumnPageUp", CK_MarkColumnPageUp
},
294 {"MarkColumnPageDown", CK_MarkColumnPageDown
},
295 {"MarkColumnLeft", CK_MarkColumnLeft
},
296 {"MarkColumnRight", CK_MarkColumnRight
},
297 {"MarkColumnUp", CK_MarkColumnUp
},
298 {"MarkColumnDown", CK_MarkColumnDown
},
299 {"MarkColumnScrollUp", CK_MarkColumnScrollUp
},
300 {"MarkColumnScrollDown", CK_MarkColumnScrollDown
},
301 {"MarkColumnParagraphUp", CK_MarkColumnParagraphUp
},
302 {"MarkColumnParagraphDown", CK_MarkColumnParagraphDown
},
303 {"BlockShiftLeft", CK_BlockShiftLeft
},
304 {"BlockShiftRight", CK_BlockShiftRight
},
305 {"InsertLiteral", CK_InsertLiteral
},
306 {"ShowTabTws", CK_ShowTabTws
},
307 {"SyntaxOnOff", CK_SyntaxOnOff
},
308 {"SyntaxChoose", CK_SyntaxChoose
},
309 {"ShowMargin", CK_ShowMargin
},
310 {"OptionsSaveMode", CK_OptionsSaveMode
},
312 /* An action to run external script from macro */
313 {"ExecuteScript", CK_PipeBlock (0)},
314 {"WindowMove", CK_WindowMove
},
315 {"WindowResize", CK_WindowResize
},
316 #endif /* USE_INTERNAL_EDIT */
319 {"WrapMode", CK_WrapMode
},
320 {"HexEditMode", CK_HexEditMode
},
321 {"HexMode", CK_HexMode
},
322 {"MagicMode", CK_MagicMode
},
323 {"NroffMode", CK_NroffMode
},
324 {"BookmarkGoto", CK_BookmarkGoto
},
326 {"SearchForward", CK_SearchForward
},
327 {"SearchBackward", CK_SearchBackward
},
328 {"SearchForwardContinue", CK_SearchForwardContinue
},
329 {"SearchBackwardContinue", CK_SearchBackwardContinue
},
333 {"ShowSymbols", CK_ShowSymbols
},
334 {"SplitFull", CK_SplitFull
},
339 {"HunkNext", CK_HunkNext
},
340 {"HunkPrev", CK_HunkPrev
},
341 {"EditOther", CK_EditOther
},
343 #endif /* USE_DIFF_VIEW */
349 static const size_t num_command_names
= G_N_ELEMENTS (command_names
) - 1;
352 /*** file scope functions ************************************************************************/
353 /* --------------------------------------------------------------------------------------------- */
356 name_keymap_comparator (const void *p1
, const void *p2
)
358 const name_keymap_t
*m1
= (const name_keymap_t
*) p1
;
359 const name_keymap_t
*m2
= (const name_keymap_t
*) p2
;
361 return g_ascii_strcasecmp (m1
->name
, m2
->name
);
364 /* --------------------------------------------------------------------------------------------- */
367 sort_command_names (void)
369 static gboolean has_been_sorted
= FALSE
;
371 if (!has_been_sorted
)
373 qsort (command_names
, num_command_names
,
374 sizeof (command_names
[0]), &name_keymap_comparator
);
375 has_been_sorted
= TRUE
;
379 /* --------------------------------------------------------------------------------------------- */
382 keymap_add (GArray
* keymap
, long key
, unsigned long cmd
, const char *caption
)
384 if (key
!= 0 && cmd
!= CK_IgnoreKey
)
386 global_keymap_t new_bind
;
389 new_bind
.command
= cmd
;
390 g_snprintf (new_bind
.caption
, sizeof (new_bind
.caption
), "%s", caption
);
391 g_array_append_val (keymap
, new_bind
);
395 /* --------------------------------------------------------------------------------------------- */
396 /*** public functions ****************************************************************************/
397 /* --------------------------------------------------------------------------------------------- */
400 keybind_cmd_bind (GArray
* keymap
, const char *keybind
, unsigned long action
)
402 char *caption
= NULL
;
405 key
= lookup_key (keybind
, &caption
);
406 keymap_add (keymap
, key
, action
, caption
);
410 /* --------------------------------------------------------------------------------------------- */
413 keybind_lookup_action (const char *name
)
415 const name_keymap_t key
= { name
, 0 };
418 sort_command_names ();
420 res
= bsearch (&key
, command_names
, num_command_names
,
421 sizeof (command_names
[0]), name_keymap_comparator
);
423 return (res
!= NULL
) ? res
->val
: CK_IgnoreKey
;
426 /* --------------------------------------------------------------------------------------------- */
429 keybind_lookup_actionname (unsigned long action
)
433 for (i
= 0; command_names
[i
].name
!= NULL
; i
++)
434 if (command_names
[i
].val
== action
)
435 return command_names
[i
].name
;
440 /* --------------------------------------------------------------------------------------------- */
443 keybind_lookup_keymap_shortcut (const global_keymap_t
* keymap
, unsigned long action
)
448 for (i
= 0; keymap
[i
].key
!= 0; i
++)
449 if (keymap
[i
].command
== action
)
450 return (keymap
[i
].caption
[0] != '\0') ? keymap
[i
].caption
: NULL
;
455 /* --------------------------------------------------------------------------------------------- */
458 keybind_lookup_keymap_command (const global_keymap_t
* keymap
, long key
)
463 for (i
= 0; keymap
[i
].key
!= 0; i
++)
464 if (keymap
[i
].key
== key
)
465 return keymap
[i
].command
;
470 /* --------------------------------------------------------------------------------------------- */