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