2 Definitions of key bindings.
4 Copyright (C) 2005-2016
5 Free Software Foundation, Inc.
9 Ilia Maslakov <il.smind@gmail.com>, 2009, 2012
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_SFTP
169 {"ConnectSftp", CK_ConnectSftp
},
171 #ifdef ENABLE_VFS_SMB
172 {"ConnectSmb", CK_ConnectSmb
},
174 {"PanelInfo", CK_PanelInfo
},
175 #ifdef ENABLE_BACKGROUND
178 {"OptionsLayout", CK_OptionsLayout
},
179 {"OptionsAppearance", CK_OptionsAppearance
},
181 {"PanelListingChange", CK_PanelListingChange
},
182 {"PanelListing", CK_PanelListing
},
183 #ifdef LISTMODE_EDITOR
184 {"ListMode", CK_ListMode
}.
186 {"OptionsPanel", CK_OptionsPanel
},
187 {"CdQuick", CK_CdQuick
},
188 {"PanelQuickView", CK_PanelQuickView
},
189 {"LinkSymbolicRelative", CK_LinkSymbolicRelative
},
190 {"VfsList", CK_VfsList
},
191 {"SaveSetup", CK_SaveSetup
},
192 {"LinkSymbolic", CK_LinkSymbolic
},
193 {"PanelTree", CK_PanelTree
},
195 #ifdef ENABLE_VFS_UNDELFS
196 {"Undelete", CK_Undelete
},
198 {"PutCurrentLink", CK_PutCurrentLink
},
199 {"PutOtherLink", CK_PutOtherLink
},
200 {"HotListAdd", CK_HotListAdd
},
201 {"ShowHidden", CK_ShowHidden
},
202 {"SplitVertHoriz", CK_SplitVertHoriz
},
203 {"SplitEqual", CK_SplitEqual
},
204 {"SplitMore", CK_SplitMore
},
205 {"SplitLess", CK_SplitLess
},
206 {"PutCurrentPath", CK_PutCurrentPath
},
207 {"PutOtherPath", CK_PutOtherPath
},
208 {"PutCurrentTagged", CK_PutCurrentTagged
},
209 {"PutOtherTagged", CK_PutOtherTagged
},
210 {"Select", CK_Select
},
211 {"Unselect", CK_Unselect
},
214 {"SelectExt", CK_SelectExt
},
215 {"ScrollLeft", CK_ScrollLeft
},
216 {"ScrollRight", CK_ScrollRight
},
217 {"PanelOtherCd", CK_PanelOtherCd
},
218 {"PanelOtherCdLink", CK_PanelOtherCdLink
},
219 {"CopySingle", CK_CopySingle
},
220 {"MoveSingle", CK_MoveSingle
},
221 {"DeleteSingle", CK_DeleteSingle
},
222 {"CdParent", CK_CdParent
},
223 {"CdChild", CK_CdChild
},
224 {"Panelize", CK_Panelize
},
225 {"PanelOtherSync", CK_PanelOtherSync
},
226 {"SortNext", CK_SortNext
},
227 {"SortPrev", CK_SortPrev
},
228 {"SortReverse", CK_SortReverse
},
229 {"SortByName", CK_SortByName
},
230 {"SortByExt", CK_SortByExt
},
231 {"SortBySize", CK_SortBySize
},
232 {"SortByMTime", CK_SortByMTime
},
233 {"CdParentSmart", CK_CdParentSmart
},
237 {"Cancel", CK_Cancel
},
245 {"LinkNext", CK_LinkNext
},
246 {"LinkPrev", CK_LinkPrev
},
247 {"NodeNext", CK_NodeNext
},
248 {"NodePrev", CK_NodePrev
},
251 {"Forget", CK_Forget
},
253 #if defined (USE_INTERNAL_EDIT) || defined (USE_DIFF_VIEW)
254 {"ShowNumbers", CK_ShowNumbers
},
257 #ifdef USE_INTERNAL_EDIT
261 {"ScrollUp", CK_ScrollUp
},
262 {"ScrollDown", CK_ScrollDown
},
263 {"Return", CK_Return
},
264 {"ParagraphUp", CK_ParagraphUp
},
265 {"ParagraphDown", CK_ParagraphDown
},
266 {"EditFile", CK_EditFile
},
267 {"MarkWord", CK_MarkWord
},
268 {"MarkLine", CK_MarkLine
},
269 {"MarkAll", CK_MarkAll
},
270 {"Unmark", CK_Unmark
},
271 {"MarkColumn", CK_MarkColumn
},
272 {"BlockSave", CK_BlockSave
},
273 {"InsertFile", CK_InsertFile
},
274 {"InsertOverwrite", CK_InsertOverwrite
},
276 {"DeleteLine", CK_DeleteLine
},
277 {"EditMail", CK_Mail
},
278 {"ParagraphFormat", CK_ParagraphFormat
},
279 {"MatchBracket", CK_MatchBracket
},
280 {"ExternalCommand", CK_ExternalCommand
},
281 {"MacroStartRecord", CK_MacroStartRecord
},
282 {"MacroStopRecord", CK_MacroStopRecord
},
283 {"MacroStartStopRecord", CK_MacroStartStopRecord
},
284 {"MacroDelete", CK_MacroDelete
},
285 {"RepeatStartStopRecord", CK_RepeatStartStopRecord
},
287 {"SpellCheck", CK_SpellCheck
},
288 {"SpellCheckCurrentWord", CK_SpellCheckCurrentWord
},
289 {"SpellCheckSelectLang", CK_SpellCheckSelectLang
},
290 #endif /* HAVE_ASPELL */
291 {"BookmarkFlush", CK_BookmarkFlush
},
292 {"BookmarkNext", CK_BookmarkNext
},
293 {"BookmarkPrev", CK_BookmarkPrev
},
294 {"MarkPageUp", CK_MarkPageUp
},
295 {"MarkPageDown", CK_MarkPageDown
},
296 {"MarkToFileBegin", CK_MarkToFileBegin
},
297 {"MarkToFileEnd", CK_MarkToFileEnd
},
298 {"MarkToPageBegin", CK_MarkToPageBegin
},
299 {"MarkToPageEnd", CK_MarkToPageEnd
},
300 {"MarkScrollUp", CK_MarkScrollUp
},
301 {"MarkScrollDown", CK_MarkScrollDown
},
302 {"MarkParagraphUp", CK_MarkParagraphUp
},
303 {"MarkParagraphDown", CK_MarkParagraphDown
},
304 {"MarkColumnPageUp", CK_MarkColumnPageUp
},
305 {"MarkColumnPageDown", CK_MarkColumnPageDown
},
306 {"MarkColumnLeft", CK_MarkColumnLeft
},
307 {"MarkColumnRight", CK_MarkColumnRight
},
308 {"MarkColumnUp", CK_MarkColumnUp
},
309 {"MarkColumnDown", CK_MarkColumnDown
},
310 {"MarkColumnScrollUp", CK_MarkColumnScrollUp
},
311 {"MarkColumnScrollDown", CK_MarkColumnScrollDown
},
312 {"MarkColumnParagraphUp", CK_MarkColumnParagraphUp
},
313 {"MarkColumnParagraphDown", CK_MarkColumnParagraphDown
},
314 {"BlockShiftLeft", CK_BlockShiftLeft
},
315 {"BlockShiftRight", CK_BlockShiftRight
},
316 {"InsertLiteral", CK_InsertLiteral
},
317 {"ShowTabTws", CK_ShowTabTws
},
318 {"SyntaxOnOff", CK_SyntaxOnOff
},
319 {"SyntaxChoose", CK_SyntaxChoose
},
320 {"ShowMargin", CK_ShowMargin
},
321 {"OptionsSaveMode", CK_OptionsSaveMode
},
323 /* An action to run external script from macro */
324 {"ExecuteScript", CK_PipeBlock (0)},
325 {"WindowMove", CK_WindowMove
},
326 {"WindowResize", CK_WindowResize
},
327 {"WindowFullscreen", CK_WindowFullscreen
},
328 {"WindowList", CK_WindowList
},
329 {"WindowNext", CK_WindowNext
},
330 {"WindowPrev", CK_WindowPrev
},
331 #endif /* USE_INTERNAL_EDIT */
334 {"WrapMode", CK_WrapMode
},
335 {"HexEditMode", CK_HexEditMode
},
336 {"HexMode", CK_HexMode
},
337 {"MagicMode", CK_MagicMode
},
338 {"NroffMode", CK_NroffMode
},
339 {"BookmarkGoto", CK_BookmarkGoto
},
341 {"SearchForward", CK_SearchForward
},
342 {"SearchBackward", CK_SearchBackward
},
343 {"SearchForwardContinue", CK_SearchForwardContinue
},
344 {"SearchBackwardContinue", CK_SearchBackwardContinue
},
348 {"ShowSymbols", CK_ShowSymbols
},
349 {"SplitFull", CK_SplitFull
},
354 {"HunkNext", CK_HunkNext
},
355 {"HunkPrev", CK_HunkPrev
},
356 {"EditOther", CK_EditOther
},
358 {"MergeOther", CK_MergeOther
},
359 #endif /* USE_DIFF_VIEW */
365 static const size_t num_command_names
= G_N_ELEMENTS (command_names
) - 1;
368 /*** file scope functions ************************************************************************/
369 /* --------------------------------------------------------------------------------------------- */
372 name_keymap_comparator (const void *p1
, const void *p2
)
374 const name_keymap_t
*m1
= (const name_keymap_t
*) p1
;
375 const name_keymap_t
*m2
= (const name_keymap_t
*) p2
;
377 return g_ascii_strcasecmp (m1
->name
, m2
->name
);
380 /* --------------------------------------------------------------------------------------------- */
383 sort_command_names (void)
385 static gboolean has_been_sorted
= FALSE
;
387 if (!has_been_sorted
)
389 qsort (command_names
, num_command_names
,
390 sizeof (command_names
[0]), &name_keymap_comparator
);
391 has_been_sorted
= TRUE
;
395 /* --------------------------------------------------------------------------------------------- */
398 keymap_add (GArray
* keymap
, long key
, long cmd
, const char *caption
)
400 if (key
!= 0 && cmd
!= CK_IgnoreKey
)
402 global_keymap_t new_bind
;
405 new_bind
.command
= cmd
;
406 g_snprintf (new_bind
.caption
, sizeof (new_bind
.caption
), "%s", caption
);
407 g_array_append_val (keymap
, new_bind
);
411 /* --------------------------------------------------------------------------------------------- */
412 /*** public functions ****************************************************************************/
413 /* --------------------------------------------------------------------------------------------- */
416 keybind_cmd_bind (GArray
* keymap
, const char *keybind
, long action
)
418 char *caption
= NULL
;
421 key
= lookup_key (keybind
, &caption
);
422 keymap_add (keymap
, key
, action
, caption
);
426 /* --------------------------------------------------------------------------------------------- */
429 keybind_lookup_action (const char *name
)
431 const name_keymap_t key
= { name
, 0 };
434 sort_command_names ();
436 res
= bsearch (&key
, command_names
, num_command_names
,
437 sizeof (command_names
[0]), name_keymap_comparator
);
439 return (res
!= NULL
) ? res
->val
: CK_IgnoreKey
;
442 /* --------------------------------------------------------------------------------------------- */
445 keybind_lookup_actionname (long action
)
449 for (i
= 0; command_names
[i
].name
!= NULL
; i
++)
450 if (command_names
[i
].val
== action
)
451 return command_names
[i
].name
;
456 /* --------------------------------------------------------------------------------------------- */
459 keybind_lookup_keymap_shortcut (const global_keymap_t
* keymap
, long action
)
465 for (i
= 0; keymap
[i
].key
!= 0; i
++)
466 if (keymap
[i
].command
== action
)
467 return (keymap
[i
].caption
[0] != '\0') ? keymap
[i
].caption
: NULL
;
472 /* --------------------------------------------------------------------------------------------- */
475 keybind_lookup_keymap_command (const global_keymap_t
* keymap
, long key
)
481 for (i
= 0; keymap
[i
].key
!= 0; i
++)
482 if (keymap
[i
].key
== key
)
483 return keymap
[i
].command
;
489 /* --------------------------------------------------------------------------------------------- */