2 * keybindings.h - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2006 The Geany contributors
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #ifndef GEANY_KEYBINDINGS_H
22 #define GEANY_KEYBINDINGS_H 1
24 #include "gtkcompat.h"
28 /** Defines the primary modifier mask which is the Ctrl key mask on
29 * UNIX/Windows and Command key mask on OS X. When testing for the mask
30 * presence, use together with keybindings_get_modifiers() which adds
31 * @c GEANY_PRIMARY_MOD_MASK when needed.
34 #define GEANY_PRIMARY_MOD_MASK GDK_META_MASK
36 #define GEANY_PRIMARY_MOD_MASK GDK_CONTROL_MASK
39 /** A collection of keybindings grouped together. */
40 typedef struct GeanyKeyGroup GeanyKeyGroup
;
41 typedef struct GeanyKeyBinding GeanyKeyBinding
;
43 /** Function pointer type used for keybinding group callbacks.
45 * You should return @c TRUE to indicate handling the callback. (Occasionally, if the keybinding
46 * cannot apply in the current situation, it is useful to return @c FALSE to allow a later keybinding
47 * with the same key combination to handle it). */
48 typedef gboolean (*GeanyKeyGroupCallback
) (guint key_id
);
50 /** Function pointer type used for keybinding group callbacks, with userdata for passing context.
52 * You should return @c TRUE to indicate handling the callback. (Occasionally, if the keybinding
53 * cannot apply in the current situation, it is useful to return @c FALSE to allow a later keybinding
54 * with the same key combination to handle it).
56 * @since 1.26 (API 226) */
57 typedef gboolean (*GeanyKeyGroupFunc
)(GeanyKeyGroup
*group
, guint key_id
, gpointer user_data
);
59 /** Function pointer type used for keybinding callbacks. */
60 typedef void (*GeanyKeyCallback
) (guint key_id
);
62 /** Function pointer type used for keybinding callbacks, with userdata for passing context
64 * You should return @c TRUE to indicate handling the callback. (Occasionally, if the keybinding
65 * cannot apply in the current situation, it is useful to return @c FALSE to allow a later keybinding
66 * with the same key combination to handle it).
68 * @since 1.26 (API 226) */
69 typedef gboolean (*GeanyKeyBindingFunc
)(GeanyKeyBinding
*key
, guint key_id
, gpointer user_data
);
71 /** Represents a single keybinding action.
73 * Use keybindings_set_item() to set. */
74 struct GeanyKeyBinding
76 guint key
; /**< Key value in lower-case, such as @c GDK_KEY_a or 0 */
77 GdkModifierType mods
; /**< Modifier keys, such as @c GDK_CONTROL_MASK or 0 */
78 gchar
*name
; /**< Key name for the configuration file, such as @c "menu_new" */
79 /** Label used in the preferences dialog keybindings tab.
80 * May contain underscores - these won't be displayed. */
82 /** Function called when the key combination is pressed, or @c NULL to use the group callback
83 * (preferred). @see plugin_set_key_group(). */
84 GeanyKeyCallback callback
;
85 GtkWidget
*menu_item
; /**< Optional widget to set an accelerator for, or @c NULL */
88 GdkModifierType default_mods
;
89 GeanyKeyBindingFunc cb_func
;
91 GDestroyNotify cb_data_destroy
;
94 /* Note: we don't need to break the plugin ABI when appending keybinding or keygroup IDs,
95 * just make sure to insert immediately before the _COUNT item, so
96 * the existing enum values stay the same. */
98 /** Keybinding group IDs for use with keybindings_send_command(). */
99 /* These IDs are used to lookup a group. */
102 GEANY_KEY_GROUP_FILE
, /**< Group. */
103 GEANY_KEY_GROUP_PROJECT
, /**< Group. */
104 GEANY_KEY_GROUP_EDITOR
, /**< Group. */
105 GEANY_KEY_GROUP_CLIPBOARD
, /**< Group. */
106 GEANY_KEY_GROUP_SELECT
, /**< Group. */
107 GEANY_KEY_GROUP_FORMAT
, /**< Group. */
108 GEANY_KEY_GROUP_INSERT
, /**< Group. */
109 GEANY_KEY_GROUP_SETTINGS
, /**< Group. */
110 GEANY_KEY_GROUP_SEARCH
, /**< Group. */
111 GEANY_KEY_GROUP_GOTO
, /**< Group. */
112 GEANY_KEY_GROUP_VIEW
, /**< Group. */
113 GEANY_KEY_GROUP_FOCUS
, /**< Group. */
114 GEANY_KEY_GROUP_NOTEBOOK
, /**< Group. */
115 GEANY_KEY_GROUP_DOCUMENT
, /**< Group. */
116 GEANY_KEY_GROUP_BUILD
, /**< Group. */
117 GEANY_KEY_GROUP_TOOLS
, /**< Group. */
118 GEANY_KEY_GROUP_HELP
, /**< Group. */
119 GEANY_KEY_GROUP_COUNT
/* must not be used by plugins */
122 /** Keybinding command IDs for use with keybindings_send_command(). */
123 /* These IDs are used to lookup a keybinding. */
124 enum GeanyKeyBindingID
126 GEANY_KEYS_EDITOR_TRANSPOSELINE
, /**< Keybinding. */
127 GEANY_KEYS_DOCUMENT_REMOVE_ERROR_INDICATORS
, /**< Keybinding. */
128 GEANY_KEYS_FOCUS_SEARCHBAR
, /**< Keybinding. */
129 GEANY_KEYS_SEARCH_FIND
, /**< Keybinding. */
130 GEANY_KEYS_FILE_SAVEALL
, /**< Keybinding. */
131 GEANY_KEYS_GOTO_NEXTMARKER
, /**< Keybinding. */
132 GEANY_KEYS_NOTEBOOK_SWITCHTABLEFT
, /**< Keybinding. */
133 GEANY_KEYS_VIEW_ZOOMOUT
, /**< Keybinding. */
134 GEANY_KEYS_GOTO_LINE
, /**< Keybinding. */
135 GEANY_KEYS_DOCUMENT_TOGGLEFOLD
, /**< Keybinding. */
136 GEANY_KEYS_BUILD_COMPILE
, /**< Keybinding. */
137 GEANY_KEYS_EDITOR_SCROLLTOLINE
, /**< Keybinding. */
138 GEANY_KEYS_DOCUMENT_UNFOLDALL
, /**< Keybinding. */
139 GEANY_KEYS_GOTO_MATCHINGBRACE
, /**< Keybinding. */
140 GEANY_KEYS_SEARCH_FINDDOCUMENTUSAGE
, /**< Keybinding. */
141 GEANY_KEYS_CLIPBOARD_PASTE
, /**< Keybinding. */
142 GEANY_KEYS_BUILD_MAKE
, /**< Keybinding. */
143 GEANY_KEYS_INSERT_ALTWHITESPACE
, /**< Keybinding. */
144 GEANY_KEYS_EDITOR_SCROLLLINEDOWN
, /**< Keybinding. */
145 GEANY_KEYS_VIEW_TOGGLEALL
, /**< Keybinding. */
146 GEANY_KEYS_VIEW_FULLSCREEN
, /**< Keybinding. */
147 GEANY_KEYS_GOTO_LINEEND
, /**< Keybinding. */
148 GEANY_KEYS_EDITOR_CALLTIP
, /**< Keybinding. */
149 GEANY_KEYS_FILE_PRINT
, /**< Keybinding. */
150 GEANY_KEYS_EDITOR_DUPLICATELINE
, /**< Keybinding. */
151 GEANY_KEYS_FOCUS_SCRIBBLE
, /**< Keybinding. */
152 GEANY_KEYS_TOOLS_OPENCOLORCHOOSER
, /**< Keybinding. */
153 GEANY_KEYS_SEARCH_PREVIOUSMESSAGE
, /**< Keybinding. */
154 GEANY_KEYS_FILE_CLOSE
, /**< Keybinding. */
155 GEANY_KEYS_DOCUMENT_REPLACETABS
, /**< Keybinding. */
156 GEANY_KEYS_FILE_RELOAD
, /**< Keybinding. */
157 GEANY_KEYS_SEARCH_FINDNEXTSEL
, /**< Keybinding. */
158 GEANY_KEYS_FOCUS_MESSAGES
, /**< Keybinding. */
159 GEANY_KEYS_BUILD_RUN
, /**< Keybinding. */
160 GEANY_KEYS_HELP_HELP
, /**< Keybinding. */
161 GEANY_KEYS_SETTINGS_PLUGINPREFERENCES
, /**< Keybinding. */
162 GEANY_KEYS_VIEW_ZOOMRESET
, /**< Keybinding. */
163 GEANY_KEYS_SELECT_WORD
, /**< Keybinding. */
164 GEANY_KEYS_FORMAT_INCREASEINDENT
, /**< Keybinding. */
165 GEANY_KEYS_SETTINGS_PREFERENCES
, /**< Keybinding. */
166 GEANY_KEYS_FORMAT_SENDTOCMD3
, /**< Keybinding. */
167 GEANY_KEYS_DOCUMENT_FOLDALL
, /**< Keybinding. */
168 GEANY_KEYS_FORMAT_SENDTOVTE
, /**< Keybinding. */
169 GEANY_KEYS_PROJECT_PROPERTIES
, /**< Keybinding. */
170 GEANY_KEYS_DOCUMENT_LINEWRAP
, /**< Keybinding. */
171 GEANY_KEYS_EDITOR_MACROLIST
, /**< Keybinding.
172 * @deprecated 1.25, it doesn't do anything anymore */
173 GEANY_KEYS_EDITOR_SUPPRESSSNIPPETCOMPLETION
, /**< Keybinding. */
174 GEANY_KEYS_FOCUS_SIDEBAR_SYMBOL_LIST
, /**< Keybinding. */
175 GEANY_KEYS_GOTO_LINESTART
, /**< Keybinding. */
176 GEANY_KEYS_SEARCH_FINDUSAGE
, /**< Keybinding. */
177 GEANY_KEYS_FILE_NEW
, /**< Keybinding. */
178 GEANY_KEYS_EDITOR_SNIPPETNEXTCURSOR
, /**< Keybinding. */
179 GEANY_KEYS_NOTEBOOK_SWITCHTABRIGHT
, /**< Keybinding. */
180 GEANY_KEYS_FILE_SAVE
, /**< Keybinding. */
181 GEANY_KEYS_FORMAT_INCREASEINDENTBYSPACE
, /**< Keybinding. */
182 GEANY_KEYS_SEARCH_FINDNEXT
, /**< Keybinding. */
183 GEANY_KEYS_GOTO_TOGGLEMARKER
, /**< Keybinding. */
184 GEANY_KEYS_GOTO_TAGDEFINITION
, /**< Keybinding. */
185 GEANY_KEYS_SEARCH_NEXTMESSAGE
, /**< Keybinding. */
186 GEANY_KEYS_EDITOR_DELETELINETOEND
, /**< Keybinding. */
187 GEANY_KEYS_FORMAT_AUTOINDENT
, /**< Keybinding. */
188 GEANY_KEYS_FILE_OPENSELECTED
, /**< Keybinding. */
189 GEANY_KEYS_GOTO_BACK
, /**< Keybinding. */
190 GEANY_KEYS_INSERT_DATE
, /**< Keybinding. */
191 GEANY_KEYS_BUILD_PREVIOUSERROR
, /**< Keybinding. */
192 GEANY_KEYS_GOTO_LINEENDVISUAL
, /**< Keybinding. */
193 GEANY_KEYS_DOCUMENT_REPLACESPACES
, /**< Keybinding. */
194 GEANY_KEYS_FOCUS_EDITOR
, /**< Keybinding. */
195 GEANY_KEYS_SELECT_WORDPARTRIGHT
, /**< Keybinding. */
196 GEANY_KEYS_VIEW_MESSAGEWINDOW
, /**< Keybinding. */
197 GEANY_KEYS_FOCUS_SIDEBAR_DOCUMENT_LIST
, /**< Keybinding. */
198 GEANY_KEYS_FORMAT_REFLOWPARAGRAPH
, /**< Keybinding. */
199 GEANY_KEYS_EDITOR_MOVELINEUP
, /**< Keybinding. */
200 GEANY_KEYS_NOTEBOOK_MOVETABLEFT
, /**< Keybinding. */
201 GEANY_KEYS_SELECT_LINE
, /**< Keybinding. */
202 GEANY_KEYS_EDITOR_UNDO
, /**< Keybinding. */
203 GEANY_KEYS_EDITOR_MOVELINEDOWN
, /**< Keybinding. */
204 GEANY_KEYS_CLIPBOARD_COPYLINE
, /**< Keybinding. */
205 GEANY_KEYS_BUILD_MAKEOWNTARGET
, /**< Keybinding. */
206 GEANY_KEYS_FORMAT_SENDTOCMD2
, /**< Keybinding. */
207 GEANY_KEYS_SEARCH_MARKALL
, /**< Keybinding. */
208 GEANY_KEYS_BUILD_LINK
, /**< Keybinding. */
209 GEANY_KEYS_FILE_CLOSEALL
, /**< Keybinding. */
210 GEANY_KEYS_GOTO_FORWARD
, /**< Keybinding. */
211 GEANY_KEYS_CLIPBOARD_CUT
, /**< Keybinding. */
212 GEANY_KEYS_NOTEBOOK_SWITCHTABLASTUSED
, /**< Keybinding. */
213 GEANY_KEYS_NOTEBOOK_MOVETABRIGHT
, /**< Keybinding. */
214 GEANY_KEYS_BUILD_OPTIONS
, /**< Keybinding. */
215 GEANY_KEYS_GOTO_TAGDECLARATION
, /**< Keybinding. */
216 GEANY_KEYS_FILE_OPEN
, /**< Keybinding. */
217 GEANY_KEYS_EDITOR_COMPLETESNIPPET
, /**< Keybinding. */
218 GEANY_KEYS_FORMAT_UNCOMMENTLINE
, /**< Keybinding. */
219 GEANY_KEYS_FOCUS_VTE
, /**< Keybinding. */
220 GEANY_KEYS_FORMAT_SENDTOCMD1
, /**< Keybinding. */
221 GEANY_KEYS_SELECT_WORDPARTLEFT
, /**< Keybinding. */
222 GEANY_KEYS_VIEW_ZOOMIN
, /**< Keybinding. */
223 GEANY_KEYS_DOCUMENT_LINEBREAK
, /**< Keybinding. */
224 GEANY_KEYS_EDITOR_REDO
, /**< Keybinding. */
225 GEANY_KEYS_EDITOR_CONTEXTACTION
, /**< Keybinding. */
226 GEANY_KEYS_SEARCH_FINDPREVSEL
, /**< Keybinding. */
227 GEANY_KEYS_FORMAT_DECREASEINDENTBYSPACE
, /**< Keybinding. */
228 GEANY_KEYS_FORMAT_COMMENTLINETOGGLE
, /**< Keybinding. */
229 GEANY_KEYS_SELECT_ALL
, /**< Keybinding. */
230 GEANY_KEYS_DOCUMENT_RELOADTAGLIST
, /**< Keybinding. */
231 GEANY_KEYS_BUILD_NEXTERROR
, /**< Keybinding. */
232 GEANY_KEYS_NOTEBOOK_MOVETABLAST
, /**< Keybinding. */
233 GEANY_KEYS_SELECT_PARAGRAPH
, /**< Keybinding. */
234 GEANY_KEYS_EDITOR_DELETELINE
, /**< Keybinding. */
235 GEANY_KEYS_CLIPBOARD_COPY
, /**< Keybinding. */
236 GEANY_KEYS_VIEW_SIDEBAR
, /**< Keybinding. */
237 GEANY_KEYS_FILE_SAVEAS
, /**< Keybinding. */
238 GEANY_KEYS_FORMAT_COMMENTLINE
, /**< Keybinding. */
239 GEANY_KEYS_GOTO_PREVWORDPART
, /**< Keybinding. */
240 GEANY_KEYS_SEARCH_FINDPREVIOUS
, /**< Keybinding. */
241 GEANY_KEYS_SEARCH_REPLACE
, /**< Keybinding. */
242 GEANY_KEYS_EDITOR_WORDPARTCOMPLETION
, /**< Keybinding. */
243 GEANY_KEYS_EDITOR_AUTOCOMPLETE
, /**< Keybinding. */
244 GEANY_KEYS_FOCUS_SIDEBAR
, /**< Keybinding. */
245 GEANY_KEYS_FOCUS_MESSAGE_WINDOW
, /**< Keybinding. */
246 GEANY_KEYS_NOTEBOOK_MOVETABFIRST
, /**< Keybinding. */
247 GEANY_KEYS_GOTO_PREVIOUSMARKER
, /**< Keybinding. */
248 GEANY_KEYS_EDITOR_SCROLLLINEUP
, /**< Keybinding. */
249 GEANY_KEYS_FOCUS_COMPILER
, /**< Keybinding. */
250 GEANY_KEYS_FORMAT_TOGGLECASE
, /**< Keybinding. */
251 GEANY_KEYS_CLIPBOARD_CUTLINE
, /**< Keybinding. */
252 GEANY_KEYS_DOCUMENT_REMOVE_MARKERS
, /**< Keybinding. */
253 GEANY_KEYS_BUILD_MAKEOBJECT
, /**< Keybinding. */
254 GEANY_KEYS_FORMAT_DECREASEINDENT
, /**< Keybinding. */
255 GEANY_KEYS_FILE_OPENLASTTAB
, /**< Keybinding. */
256 GEANY_KEYS_SEARCH_FINDINFILES
, /**< Keybinding. */
257 GEANY_KEYS_GOTO_NEXTWORDPART
, /**< Keybinding. */
258 GEANY_KEYS_INSERT_LINEAFTER
, /**< Keybinding. */
259 GEANY_KEYS_INSERT_LINEBEFORE
, /**< Keybinding. */
260 GEANY_KEYS_DOCUMENT_REMOVE_MARKERS_INDICATORS
, /**< Keybinding. */
261 GEANY_KEYS_PROJECT_OPEN
, /**< Keybinding. */
262 GEANY_KEYS_PROJECT_NEW
, /**< Keybinding. */
263 GEANY_KEYS_PROJECT_CLOSE
, /**< Keybinding. */
264 GEANY_KEYS_FORMAT_JOINLINES
, /**< Keybinding. */
265 GEANY_KEYS_GOTO_LINESTARTVISUAL
, /**< Keybinding. */
266 GEANY_KEYS_DOCUMENT_CLONE
, /**< Keybinding. */
267 GEANY_KEYS_FILE_QUIT
, /**< Keybinding. */
268 GEANY_KEYS_FILE_PROPERTIES
, /**< Keybinding. */
269 GEANY_KEYS_FORMAT_SENDTOCMD4
, /**< Keybinding. */
270 GEANY_KEYS_FORMAT_SENDTOCMD5
, /**< Keybinding. */
271 GEANY_KEYS_FORMAT_SENDTOCMD6
, /**< Keybinding. */
272 GEANY_KEYS_FORMAT_SENDTOCMD7
, /**< Keybinding. */
273 GEANY_KEYS_FORMAT_SENDTOCMD8
, /**< Keybinding. */
274 GEANY_KEYS_FORMAT_SENDTOCMD9
, /**< Keybinding. */
275 GEANY_KEYS_EDITOR_DELETELINETOBEGINNING
, /**< Keybinding. */
276 GEANY_KEYS_DOCUMENT_STRIPTRAILINGSPACES
, /**< Keybinding.
277 * @since 1.34 (API 238) */
278 GEANY_KEYS_FILE_RELOAD_ALL
, /**< Keybinding.
279 * @since 1.38 (API 240) */
280 GEANY_KEYS_PROJECT_NEW_FROM_FOLDER
, /**< Keybinding.
281 * @since 1.39 (API 243) */
282 GEANY_KEYS_COUNT
/* must not be used by plugins */
286 void keybindings_send_command(guint group_id
, guint key_id
);
288 GeanyKeyBinding
*keybindings_set_item(GeanyKeyGroup
*group
, gsize key_id
,
289 GeanyKeyCallback callback
, guint key
, GdkModifierType mod
,
290 const gchar
*name
, const gchar
*label
, GtkWidget
*menu_item
);
292 GeanyKeyBinding
*keybindings_set_item_full(GeanyKeyGroup
*group
, gsize key_id
,
293 guint key
, GdkModifierType mod
, const gchar
*kf_name
, const gchar
*label
,
294 GtkWidget
*menu_item
, GeanyKeyBindingFunc func
, gpointer pdata
,
295 GDestroyNotify destroy_notify
);
297 GeanyKeyBinding
*keybindings_get_item(GeanyKeyGroup
*group
, gsize key_id
);
299 GdkModifierType
keybindings_get_modifiers(GdkModifierType mods
);
301 void keybindings_load_keyfile(void);
305 extern GPtrArray
*keybinding_groups
; /* array of GeanyKeyGroup pointers */
308 void keybindings_init(void);
310 void keybindings_free(void);
312 GeanyKeyGroup
*keybindings_get_core_group(guint id
);
314 GeanyKeyGroup
*keybindings_set_group(GeanyKeyGroup
*group
, const gchar
*section_name
,
315 const gchar
*label
, gsize count
, GeanyKeyGroupCallback callback
) G_GNUC_WARN_UNUSED_RESULT
;
317 void keybindings_free_group(GeanyKeyGroup
*group
);
319 gchar
*keybindings_get_label(GeanyKeyBinding
*kb
);
321 void keybindings_update_combo(GeanyKeyBinding
*kb
, guint key
, GdkModifierType mods
);
323 GeanyKeyBinding
*keybindings_lookup_item(guint group_id
, guint key_id
);
325 /* just write the content of the keys array to the config file */
326 void keybindings_write_to_file(void);
328 void keybindings_show_shortcuts(void);
330 gboolean
keybindings_check_event(GdkEventKey
*ev
, GeanyKeyBinding
*kb
);
332 void keybindings_dialog_show_prefs_scroll(const gchar
*name
);
334 #endif /* GEANY_PRIVATE */
338 #endif /* GEANY_KEYBINDINGS_H */