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, 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
},
180 {"PanelListingChange", CK_PanelListingChange
},
181 {"PanelListing", CK_PanelListing
},
182 #ifdef LISTMODE_EDITOR
183 {"ListMode", CK_ListMode
}.
185 {"OptionsPanel", CK_OptionsPanel
},
186 {"CdQuick", CK_CdQuick
},
187 {"PanelQuickView", CK_PanelQuickView
},
188 {"LinkSymbolicRelative", CK_LinkSymbolicRelative
},
189 {"VfsList", CK_VfsList
},
190 {"SaveSetup", CK_SaveSetup
},
191 {"LinkSymbolic", CK_LinkSymbolic
},
192 {"PanelTree", CK_PanelTree
},
194 #ifdef ENABLE_VFS_UNDELFS
195 {"Undelete", CK_Undelete
},
197 {"PutCurrentLink", CK_PutCurrentLink
},
198 {"PutOtherLink", CK_PutOtherLink
},
199 {"HotListAdd", CK_HotListAdd
},
200 {"ShowHidden", CK_ShowHidden
},
201 {"SplitVertHoriz", CK_SplitVertHoriz
},
202 {"SplitEqual", CK_SplitEqual
},
203 {"SplitMore", CK_SplitMore
},
204 {"SplitLess", CK_SplitLess
},
205 {"PutCurrentPath", CK_PutCurrentPath
},
206 {"PutOtherPath", CK_PutOtherPath
},
207 {"PutCurrentTagged", CK_PutCurrentTagged
},
208 {"PutOtherTagged", CK_PutOtherTagged
},
209 {"Select", CK_Select
},
210 {"Unselect", CK_Unselect
},
213 {"ScrollLeft", CK_ScrollLeft
},
214 {"ScrollRight", CK_ScrollRight
},
215 {"PanelOtherCd", CK_PanelOtherCd
},
216 {"PanelOtherCdLink", CK_PanelOtherCdLink
},
217 {"CopySingle", CK_CopySingle
},
218 {"MoveSingle", CK_MoveSingle
},
219 {"DeleteSingle", CK_DeleteSingle
},
220 {"CdParent", CK_CdParent
},
221 {"CdChild", CK_CdChild
},
222 {"Panelize", CK_Panelize
},
223 {"PanelOtherSync", CK_PanelOtherSync
},
224 {"SortNext", CK_SortNext
},
225 {"SortPrev", CK_SortPrev
},
226 {"SortReverse", CK_SortReverse
},
227 {"SortByName", CK_SortByName
},
228 {"SortByExt", CK_SortByExt
},
229 {"SortBySize", CK_SortBySize
},
230 {"SortByMTime", CK_SortByMTime
},
231 {"CdParentSmart", CK_CdParentSmart
},
235 {"Cancel", CK_Cancel
},
243 {"LinkNext", CK_LinkNext
},
244 {"LinkPrev", CK_LinkPrev
},
245 {"NodeNext", CK_NodeNext
},
246 {"NodePrev", CK_NodePrev
},
249 {"Forget", CK_Forget
},
251 #if defined (USE_INTERNAL_EDIT) || defined (USE_DIFF_VIEW)
252 {"ShowNumbers", CK_ShowNumbers
},
255 #ifdef USE_INTERNAL_EDIT
259 {"ScrollUp", CK_ScrollUp
},
260 {"ScrollDown", CK_ScrollDown
},
261 {"Return", CK_Return
},
262 {"ParagraphUp", CK_ParagraphUp
},
263 {"ParagraphDown", CK_ParagraphDown
},
264 {"EditFile", CK_EditFile
},
265 {"MarkWord", CK_MarkWord
},
266 {"MarkLine", CK_MarkLine
},
267 {"MarkAll", CK_MarkAll
},
268 {"Unmark", CK_Unmark
},
269 {"MarkColumn", CK_MarkColumn
},
270 {"BlockSave", CK_BlockSave
},
271 {"InsertFile", CK_InsertFile
},
272 {"InsertOverwrite", CK_InsertOverwrite
},
274 {"DeleteLine", CK_DeleteLine
},
275 {"EditMail", CK_Mail
},
276 {"ParagraphFormat", CK_ParagraphFormat
},
277 {"MatchBracket", CK_MatchBracket
},
278 {"ExternalCommand", CK_ExternalCommand
},
279 {"MacroStartRecord", CK_MacroStartRecord
},
280 {"MacroStopRecord", CK_MacroStopRecord
},
281 {"MacroStartStopRecord", CK_MacroStartStopRecord
},
282 {"MacroDelete", CK_MacroDelete
},
283 {"RepeatStartStopRecord", CK_RepeatStartStopRecord
},
285 {"SpellCheck", CK_SpellCheck
},
286 {"SpellCheckCurrentWord", CK_SpellCheckCurrentWord
},
287 {"SpellCheckSelectLang", CK_SpellCheckSelectLang
},
288 #endif /* HAVE_ASPELL */
289 {"BookmarkFlush", CK_BookmarkFlush
},
290 {"BookmarkNext", CK_BookmarkNext
},
291 {"BookmarkPrev", CK_BookmarkPrev
},
292 {"MarkPageUp", CK_MarkPageUp
},
293 {"MarkPageDown", CK_MarkPageDown
},
294 {"MarkToFileBegin", CK_MarkToFileBegin
},
295 {"MarkToFileEnd", CK_MarkToFileEnd
},
296 {"MarkToPageBegin", CK_MarkToPageBegin
},
297 {"MarkToPageEnd", CK_MarkToPageEnd
},
298 {"MarkScrollUp", CK_MarkScrollUp
},
299 {"MarkScrollDown", CK_MarkScrollDown
},
300 {"MarkParagraphUp", CK_MarkParagraphUp
},
301 {"MarkParagraphDown", CK_MarkParagraphDown
},
302 {"MarkColumnPageUp", CK_MarkColumnPageUp
},
303 {"MarkColumnPageDown", CK_MarkColumnPageDown
},
304 {"MarkColumnLeft", CK_MarkColumnLeft
},
305 {"MarkColumnRight", CK_MarkColumnRight
},
306 {"MarkColumnUp", CK_MarkColumnUp
},
307 {"MarkColumnDown", CK_MarkColumnDown
},
308 {"MarkColumnScrollUp", CK_MarkColumnScrollUp
},
309 {"MarkColumnScrollDown", CK_MarkColumnScrollDown
},
310 {"MarkColumnParagraphUp", CK_MarkColumnParagraphUp
},
311 {"MarkColumnParagraphDown", CK_MarkColumnParagraphDown
},
312 {"BlockShiftLeft", CK_BlockShiftLeft
},
313 {"BlockShiftRight", CK_BlockShiftRight
},
314 {"InsertLiteral", CK_InsertLiteral
},
315 {"ShowTabTws", CK_ShowTabTws
},
316 {"SyntaxOnOff", CK_SyntaxOnOff
},
317 {"SyntaxChoose", CK_SyntaxChoose
},
318 {"ShowMargin", CK_ShowMargin
},
319 {"OptionsSaveMode", CK_OptionsSaveMode
},
321 /* An action to run external script from macro */
322 {"ExecuteScript", CK_PipeBlock (0)},
323 {"WindowMove", CK_WindowMove
},
324 {"WindowResize", CK_WindowResize
},
325 {"WindowFullscreen", CK_WindowFullscreen
},
326 {"WindowList", CK_WindowList
},
327 {"WindowNext", CK_WindowNext
},
328 {"WindowPrev", CK_WindowPrev
},
329 #endif /* USE_INTERNAL_EDIT */
332 {"WrapMode", CK_WrapMode
},
333 {"HexEditMode", CK_HexEditMode
},
334 {"HexMode", CK_HexMode
},
335 {"MagicMode", CK_MagicMode
},
336 {"NroffMode", CK_NroffMode
},
337 {"BookmarkGoto", CK_BookmarkGoto
},
339 {"SearchForward", CK_SearchForward
},
340 {"SearchBackward", CK_SearchBackward
},
341 {"SearchForwardContinue", CK_SearchForwardContinue
},
342 {"SearchBackwardContinue", CK_SearchBackwardContinue
},
346 {"ShowSymbols", CK_ShowSymbols
},
347 {"SplitFull", CK_SplitFull
},
352 {"HunkNext", CK_HunkNext
},
353 {"HunkPrev", CK_HunkPrev
},
354 {"EditOther", CK_EditOther
},
356 {"MergeOther", CK_MergeOther
},
357 #endif /* USE_DIFF_VIEW */
363 static const size_t num_command_names
= G_N_ELEMENTS (command_names
) - 1;
366 /*** file scope functions ************************************************************************/
367 /* --------------------------------------------------------------------------------------------- */
370 name_keymap_comparator (const void *p1
, const void *p2
)
372 const name_keymap_t
*m1
= (const name_keymap_t
*) p1
;
373 const name_keymap_t
*m2
= (const name_keymap_t
*) p2
;
375 return g_ascii_strcasecmp (m1
->name
, m2
->name
);
378 /* --------------------------------------------------------------------------------------------- */
381 sort_command_names (void)
383 static gboolean has_been_sorted
= FALSE
;
385 if (!has_been_sorted
)
387 qsort (command_names
, num_command_names
,
388 sizeof (command_names
[0]), &name_keymap_comparator
);
389 has_been_sorted
= TRUE
;
393 /* --------------------------------------------------------------------------------------------- */
396 keymap_add (GArray
* keymap
, long key
, unsigned long cmd
, const char *caption
)
398 if (key
!= 0 && cmd
!= CK_IgnoreKey
)
400 global_keymap_t new_bind
;
403 new_bind
.command
= cmd
;
404 g_snprintf (new_bind
.caption
, sizeof (new_bind
.caption
), "%s", caption
);
405 g_array_append_val (keymap
, new_bind
);
409 /* --------------------------------------------------------------------------------------------- */
410 /*** public functions ****************************************************************************/
411 /* --------------------------------------------------------------------------------------------- */
414 keybind_cmd_bind (GArray
* keymap
, const char *keybind
, unsigned long action
)
416 char *caption
= NULL
;
419 key
= lookup_key (keybind
, &caption
);
420 keymap_add (keymap
, key
, action
, caption
);
424 /* --------------------------------------------------------------------------------------------- */
427 keybind_lookup_action (const char *name
)
429 const name_keymap_t key
= { name
, 0 };
432 sort_command_names ();
434 res
= bsearch (&key
, command_names
, num_command_names
,
435 sizeof (command_names
[0]), name_keymap_comparator
);
437 return (res
!= NULL
) ? res
->val
: CK_IgnoreKey
;
440 /* --------------------------------------------------------------------------------------------- */
443 keybind_lookup_actionname (unsigned long action
)
447 for (i
= 0; command_names
[i
].name
!= NULL
; i
++)
448 if (command_names
[i
].val
== action
)
449 return command_names
[i
].name
;
454 /* --------------------------------------------------------------------------------------------- */
457 keybind_lookup_keymap_shortcut (const global_keymap_t
* keymap
, unsigned long action
)
462 for (i
= 0; keymap
[i
].key
!= 0; i
++)
463 if (keymap
[i
].command
== action
)
464 return (keymap
[i
].caption
[0] != '\0') ? keymap
[i
].caption
: NULL
;
469 /* --------------------------------------------------------------------------------------------- */
472 keybind_lookup_keymap_command (const global_keymap_t
* keymap
, long key
)
477 for (i
= 0; keymap
[i
].key
!= 0; i
++)
478 if (keymap
[i
].key
== key
)
479 return keymap
[i
].command
;
484 /* --------------------------------------------------------------------------------------------- */