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 {"PutCurrentSelected", CK_PutCurrentSelected
},
209 {"PutCurrentFullSelected", CK_PutCurrentFullSelected
},
210 {"PutCurrentTagged", CK_PutCurrentTagged
},
211 {"PutOtherTagged", CK_PutOtherTagged
},
212 {"Select", CK_Select
},
213 {"Unselect", CK_Unselect
},
216 {"SelectExt", CK_SelectExt
},
217 {"ScrollLeft", CK_ScrollLeft
},
218 {"ScrollRight", CK_ScrollRight
},
219 {"PanelOtherCd", CK_PanelOtherCd
},
220 {"PanelOtherCdLink", CK_PanelOtherCdLink
},
221 {"CopySingle", CK_CopySingle
},
222 {"MoveSingle", CK_MoveSingle
},
223 {"DeleteSingle", CK_DeleteSingle
},
224 {"CdParent", CK_CdParent
},
225 {"CdChild", CK_CdChild
},
226 {"Panelize", CK_Panelize
},
227 {"PanelOtherSync", CK_PanelOtherSync
},
228 {"SortNext", CK_SortNext
},
229 {"SortPrev", CK_SortPrev
},
230 {"SortReverse", CK_SortReverse
},
231 {"SortByName", CK_SortByName
},
232 {"SortByExt", CK_SortByExt
},
233 {"SortBySize", CK_SortBySize
},
234 {"SortByMTime", CK_SortByMTime
},
235 {"CdParentSmart", CK_CdParentSmart
},
239 {"Cancel", CK_Cancel
},
247 {"LinkNext", CK_LinkNext
},
248 {"LinkPrev", CK_LinkPrev
},
249 {"NodeNext", CK_NodeNext
},
250 {"NodePrev", CK_NodePrev
},
253 {"Forget", CK_Forget
},
255 #if defined (USE_INTERNAL_EDIT) || defined (USE_DIFF_VIEW)
256 {"ShowNumbers", CK_ShowNumbers
},
259 #ifdef USE_INTERNAL_EDIT
263 {"ScrollUp", CK_ScrollUp
},
264 {"ScrollDown", CK_ScrollDown
},
265 {"Return", CK_Return
},
266 {"ParagraphUp", CK_ParagraphUp
},
267 {"ParagraphDown", CK_ParagraphDown
},
268 {"EditFile", CK_EditFile
},
269 {"MarkWord", CK_MarkWord
},
270 {"MarkLine", CK_MarkLine
},
271 {"MarkAll", CK_MarkAll
},
272 {"Unmark", CK_Unmark
},
273 {"MarkColumn", CK_MarkColumn
},
274 {"BlockSave", CK_BlockSave
},
275 {"InsertFile", CK_InsertFile
},
276 {"InsertOverwrite", CK_InsertOverwrite
},
278 {"DeleteLine", CK_DeleteLine
},
279 {"EditMail", CK_Mail
},
280 {"ParagraphFormat", CK_ParagraphFormat
},
281 {"MatchBracket", CK_MatchBracket
},
282 {"ExternalCommand", CK_ExternalCommand
},
283 {"MacroStartRecord", CK_MacroStartRecord
},
284 {"MacroStopRecord", CK_MacroStopRecord
},
285 {"MacroStartStopRecord", CK_MacroStartStopRecord
},
286 {"MacroDelete", CK_MacroDelete
},
287 {"RepeatStartStopRecord", CK_RepeatStartStopRecord
},
289 {"SpellCheck", CK_SpellCheck
},
290 {"SpellCheckCurrentWord", CK_SpellCheckCurrentWord
},
291 {"SpellCheckSelectLang", CK_SpellCheckSelectLang
},
292 #endif /* HAVE_ASPELL */
293 {"BookmarkFlush", CK_BookmarkFlush
},
294 {"BookmarkNext", CK_BookmarkNext
},
295 {"BookmarkPrev", CK_BookmarkPrev
},
296 {"MarkPageUp", CK_MarkPageUp
},
297 {"MarkPageDown", CK_MarkPageDown
},
298 {"MarkToFileBegin", CK_MarkToFileBegin
},
299 {"MarkToFileEnd", CK_MarkToFileEnd
},
300 {"MarkToPageBegin", CK_MarkToPageBegin
},
301 {"MarkToPageEnd", CK_MarkToPageEnd
},
302 {"MarkScrollUp", CK_MarkScrollUp
},
303 {"MarkScrollDown", CK_MarkScrollDown
},
304 {"MarkParagraphUp", CK_MarkParagraphUp
},
305 {"MarkParagraphDown", CK_MarkParagraphDown
},
306 {"MarkColumnPageUp", CK_MarkColumnPageUp
},
307 {"MarkColumnPageDown", CK_MarkColumnPageDown
},
308 {"MarkColumnLeft", CK_MarkColumnLeft
},
309 {"MarkColumnRight", CK_MarkColumnRight
},
310 {"MarkColumnUp", CK_MarkColumnUp
},
311 {"MarkColumnDown", CK_MarkColumnDown
},
312 {"MarkColumnScrollUp", CK_MarkColumnScrollUp
},
313 {"MarkColumnScrollDown", CK_MarkColumnScrollDown
},
314 {"MarkColumnParagraphUp", CK_MarkColumnParagraphUp
},
315 {"MarkColumnParagraphDown", CK_MarkColumnParagraphDown
},
316 {"BlockShiftLeft", CK_BlockShiftLeft
},
317 {"BlockShiftRight", CK_BlockShiftRight
},
318 {"InsertLiteral", CK_InsertLiteral
},
319 {"ShowTabTws", CK_ShowTabTws
},
320 {"SyntaxOnOff", CK_SyntaxOnOff
},
321 {"SyntaxChoose", CK_SyntaxChoose
},
322 {"ShowMargin", CK_ShowMargin
},
323 {"OptionsSaveMode", CK_OptionsSaveMode
},
325 /* An action to run external script from macro */
326 {"ExecuteScript", CK_PipeBlock (0)},
327 {"WindowMove", CK_WindowMove
},
328 {"WindowResize", CK_WindowResize
},
329 {"WindowFullscreen", CK_WindowFullscreen
},
330 {"WindowList", CK_WindowList
},
331 {"WindowNext", CK_WindowNext
},
332 {"WindowPrev", CK_WindowPrev
},
333 #endif /* USE_INTERNAL_EDIT */
336 {"WrapMode", CK_WrapMode
},
337 {"HexEditMode", CK_HexEditMode
},
338 {"HexMode", CK_HexMode
},
339 {"MagicMode", CK_MagicMode
},
340 {"NroffMode", CK_NroffMode
},
341 {"BookmarkGoto", CK_BookmarkGoto
},
343 {"SearchForward", CK_SearchForward
},
344 {"SearchBackward", CK_SearchBackward
},
345 {"SearchForwardContinue", CK_SearchForwardContinue
},
346 {"SearchBackwardContinue", CK_SearchBackwardContinue
},
350 {"ShowSymbols", CK_ShowSymbols
},
351 {"SplitFull", CK_SplitFull
},
356 {"HunkNext", CK_HunkNext
},
357 {"HunkPrev", CK_HunkPrev
},
358 {"EditOther", CK_EditOther
},
360 {"MergeOther", CK_MergeOther
},
361 #endif /* USE_DIFF_VIEW */
367 static const size_t num_command_names
= G_N_ELEMENTS (command_names
) - 1;
370 /*** file scope functions ************************************************************************/
371 /* --------------------------------------------------------------------------------------------- */
374 name_keymap_comparator (const void *p1
, const void *p2
)
376 const name_keymap_t
*m1
= (const name_keymap_t
*) p1
;
377 const name_keymap_t
*m2
= (const name_keymap_t
*) p2
;
379 return g_ascii_strcasecmp (m1
->name
, m2
->name
);
382 /* --------------------------------------------------------------------------------------------- */
385 sort_command_names (void)
387 static gboolean has_been_sorted
= FALSE
;
389 if (!has_been_sorted
)
391 qsort (command_names
, num_command_names
,
392 sizeof (command_names
[0]), &name_keymap_comparator
);
393 has_been_sorted
= TRUE
;
397 /* --------------------------------------------------------------------------------------------- */
400 keymap_add (GArray
* keymap
, long key
, long cmd
, const char *caption
)
402 if (key
!= 0 && cmd
!= CK_IgnoreKey
)
404 global_keymap_t new_bind
;
407 new_bind
.command
= cmd
;
408 g_snprintf (new_bind
.caption
, sizeof (new_bind
.caption
), "%s", caption
);
409 g_array_append_val (keymap
, new_bind
);
413 /* --------------------------------------------------------------------------------------------- */
414 /*** public functions ****************************************************************************/
415 /* --------------------------------------------------------------------------------------------- */
418 keybind_cmd_bind (GArray
* keymap
, const char *keybind
, long action
)
420 char *caption
= NULL
;
423 key
= lookup_key (keybind
, &caption
);
424 keymap_add (keymap
, key
, action
, caption
);
428 /* --------------------------------------------------------------------------------------------- */
431 keybind_lookup_action (const char *name
)
433 const name_keymap_t key
= { name
, 0 };
436 sort_command_names ();
438 res
= bsearch (&key
, command_names
, num_command_names
,
439 sizeof (command_names
[0]), name_keymap_comparator
);
441 return (res
!= NULL
) ? res
->val
: CK_IgnoreKey
;
444 /* --------------------------------------------------------------------------------------------- */
447 keybind_lookup_actionname (long action
)
451 for (i
= 0; command_names
[i
].name
!= NULL
; i
++)
452 if (command_names
[i
].val
== action
)
453 return command_names
[i
].name
;
458 /* --------------------------------------------------------------------------------------------- */
461 keybind_lookup_keymap_shortcut (const global_keymap_t
* keymap
, long action
)
467 for (i
= 0; keymap
[i
].key
!= 0; i
++)
468 if (keymap
[i
].command
== action
)
469 return (keymap
[i
].caption
[0] != '\0') ? keymap
[i
].caption
: NULL
;
474 /* --------------------------------------------------------------------------------------------- */
477 keybind_lookup_keymap_command (const global_keymap_t
* keymap
, long key
)
483 for (i
= 0; keymap
[i
].key
!= 0; i
++)
484 if (keymap
[i
].key
== key
)
485 return keymap
[i
].command
;
491 /* --------------------------------------------------------------------------------------------- */