~ubuntu-branches/ubuntu/natty/geany/natty

« back to all changes in this revision

Viewing changes to src/keybindings.c

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2010-08-07 03:23:12 UTC
  • mfrom: (1.4.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20100807032312-ot70ac9d50cn79we
Tags: upstream-0.19
ImportĀ upstreamĀ versionĀ 0.19

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *      along with this program; if not, write to the Free Software
19
19
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
20
 *
21
 
 * $Id: keybindings.c 4663 2010-02-13 16:31:45Z eht16 $
 
21
 * $Id: keybindings.c 4885 2010-05-08 13:32:23Z eht16 $
22
22
 */
23
23
 
24
 
/*
 
24
/**
 
25
 * @file keybindings.h
25
26
 * Configurable keyboard shortcuts.
26
 
 */
 
27
 * - keybindings_send_command() mimics a built-in keybinding.
 
28
 * - @ref GeanyKeyGroupID lists groups of built-in keybindings.
 
29
 * @see plugin_set_key_group().
 
30
 **/
 
31
 
 
32
 
 
33
#include "geany.h"
27
34
 
28
35
#include <gdk/gdkkeysyms.h>
 
36
#include <string.h>
29
37
 
30
 
#include "geany.h"
31
38
#include "keybindings.h"
32
39
#include "support.h"
33
40
#include "utils.h"
46
53
#include "symbols.h"
47
54
#include "vte.h"
48
55
#include "toolbar.h"
49
 
#include "treeviews.h"
 
56
#include "sidebar.h"
50
57
#include "geanywraplabel.h"
51
58
#include "main.h"
52
59
#include "search.h"
57
64
/* keyfile group name for non-plugin KB groups */
58
65
const gchar keybindings_keyfile_group_name[] = "Bindings";
59
66
 
60
 
static gboolean ignore_keybinding = FALSE;
61
 
 
62
67
static GtkAccelGroup *kb_accel_group = NULL;
63
68
static const gboolean swap_alt_tab_order = FALSE;
64
69
 
77
82
 
78
83
static gboolean check_current_word(GeanyDocument *doc);
79
84
static gboolean read_current_word(GeanyDocument *doc);
 
85
static gchar *get_current_word_or_sel(GeanyDocument *doc);
80
86
 
81
 
static void cb_func_file_action(guint key_id);
82
 
static void cb_func_project_action(guint key_id);
83
 
static void cb_func_editor_action(guint key_id);
84
 
static void cb_func_select_action(guint key_id);
85
 
static void cb_func_format_action(guint key_id);
86
 
static void cb_func_insert_action(guint key_id);
87
 
static void cb_func_search_action(guint key_id);
88
 
static void cb_func_goto_action(guint key_id);
89
 
static void cb_func_switch_action(guint key_id);
90
 
static void cb_func_clipboard(guint key_id);
91
 
static void cb_func_build_action(guint key_id);
92
 
static void cb_func_document_action(guint key_id);
93
 
static void cb_func_view_action(guint key_id);
 
87
static gboolean cb_func_file_action(guint key_id);
 
88
static gboolean cb_func_project_action(guint key_id);
 
89
static gboolean cb_func_editor_action(guint key_id);
 
90
static gboolean cb_func_select_action(guint key_id);
 
91
static gboolean cb_func_format_action(guint key_id);
 
92
static gboolean cb_func_insert_action(guint key_id);
 
93
static gboolean cb_func_search_action(guint key_id);
 
94
static gboolean cb_func_goto_action(guint key_id);
 
95
static gboolean cb_func_switch_action(guint key_id);
 
96
static gboolean cb_func_clipboard_action(guint key_id);
 
97
static gboolean cb_func_build_action(guint key_id);
 
98
static gboolean cb_func_document_action(guint key_id);
 
99
static gboolean cb_func_view_action(guint key_id);
94
100
 
95
101
/* note: new keybindings should normally use per group callbacks */
96
102
static void cb_func_menu_help(guint key_id);
109
115
static void add_popup_menu_accels(void);
110
116
 
111
117
 
 
118
/** Looks up a keybinding item.
 
119
 * @param group Group.
 
120
 * @param key_id Keybinding index for the group.
 
121
 * @return The keybinding.
 
122
 * @since 0.19. */
 
123
GeanyKeyBinding *keybindings_get_item(GeanyKeyGroup *group, gsize key_id)
 
124
{
 
125
        g_assert(key_id < group->count);
 
126
 
 
127
        return &group->keys[key_id];
 
128
}
 
129
 
 
130
 
112
131
/* This is used to set default keybindings on startup.
113
132
 * Menu accels are set in apply_kb_accel(). */
114
 
/** Simple convenience function to fill a GeanyKeyBinding struct item.
 
133
/** Fills a GeanyKeyBinding struct item.
115
134
 * @param group Group.
116
135
 * @param key_id Keybinding index for the group.
117
 
 * @param callback Function to call when activated.
 
136
 * @param callback Function to call when activated, or @c NULL to use the group callback.
 
137
 * Usually it's better to use the group callback instead - see plugin_set_key_group().
118
138
 * @param key (Lower case) default key, e.g. @c GDK_j, but usually 0 for unset.
119
139
 * @param mod Default modifier, e.g. @c GDK_CONTROL_MASK, but usually 0 for unset.
120
 
 * @param name Not duplicated - use a static string.
121
 
 * @param label Currently not duplicated - use a static or heap-allocated (e.g. translated) string.
122
 
 * @param menu_item Optional widget to set an accelerator for, or @c NULL. */
123
 
void keybindings_set_item(GeanyKeyGroup *group, gsize key_id,
 
140
 * @param kf_name Key name for the configuration file, such as @c "menu_new".
 
141
 * @param label Label used in the preferences dialog keybindings tab. May contain
 
142
 * underscores - these won't be displayed.
 
143
 * @param menu_item Optional widget to set an accelerator for, or @c NULL.
 
144
 * @return The keybinding - normally this is ignored. */
 
145
GeanyKeyBinding *keybindings_set_item(GeanyKeyGroup *group, gsize key_id,
124
146
                GeanyKeyCallback callback, guint key, GdkModifierType mod,
125
 
                gchar *name, gchar *label, GtkWidget *menu_item)
 
147
                const gchar *kf_name, const gchar *label, GtkWidget *menu_item)
126
148
{
127
 
        GeanyKeyBinding *kb;
128
 
 
129
 
        g_assert(key_id < group->count);
130
 
 
131
 
        kb = &group->keys[key_id];
132
 
 
133
 
        kb->name = name;
134
 
        kb->label = label;
 
149
        GeanyKeyBinding *kb = keybindings_get_item(group, key_id);
 
150
 
 
151
        if (group->plugin)
 
152
        {
 
153
                /* some plugins e.g. GeanyLua need these fields duplicated */
 
154
                setptr(kb->name, g_strdup(kf_name));
 
155
                setptr(kb->label, g_strdup(label));
 
156
        }
 
157
        else
 
158
        {
 
159
                /* we don't touch them unless group->plugin is set, cast is safe */
 
160
                kb->name = (gchar *)kf_name;
 
161
                kb->label = (gchar *)label;
 
162
        }
135
163
        kb->key = key;
136
164
        kb->mods = mod;
137
165
        kb->callback = callback;
138
166
        kb->menu_item = menu_item;
 
167
        return kb;
139
168
}
140
169
 
141
170
 
142
171
static GeanyKeyGroup *add_kb_group(GeanyKeyGroup *group,
143
 
                const gchar *name, const gchar *label, gsize count, GeanyKeyBinding *keys)
 
172
                const gchar *name, const gchar *label, gsize count, GeanyKeyBinding *keys,
 
173
                GeanyKeyGroupCallback callback)
144
174
{
145
175
        g_ptr_array_add(keybinding_groups, group);
146
176
 
148
178
        group->label = label;
149
179
        group->count = count;
150
180
        group->keys = keys;
 
181
        group->callback = callback;
151
182
        return group;
152
183
}
153
184
 
163
194
 
164
195
/* Expansion for group_id = FILE:
165
196
 * add_kb_group(&groups[GEANY_KEY_GROUP_FILE], NULL, _("File menu"),
166
 
 *      GEANY_KEYS_FILE_COUNT, FILE_keys); */
167
 
#define ADD_KB_GROUP(group_id, label) \
 
197
 *      GEANY_KEYS_FILE_COUNT, FILE_keys, callback); */
 
198
#define ADD_KB_GROUP(group_id, label, callback) \
168
199
        add_kb_group(&groups[GEANY_KEY_GROUP_ ## group_id], keybindings_keyfile_group_name, label, \
169
 
                GEANY_KEYS_ ## group_id ## _COUNT, group_id ## _keys)
 
200
                GEANY_KEYS_ ## group_id ## _COUNT, group_id ## _keys, callback)
170
201
 
171
202
/* Init all fields of keys with default values.
172
203
 * The menu_item field is always the main menu item, popup menu accelerators are
193
224
        DECLARE_KEYS(TOOLS);
194
225
        DECLARE_KEYS(HELP);
195
226
 
196
 
        group = ADD_KB_GROUP(FILE, _("File"));
 
227
        group = ADD_KB_GROUP(FILE, _("File"), cb_func_file_action);
197
228
 
198
 
        keybindings_set_item(group, GEANY_KEYS_FILE_NEW, cb_func_file_action,
 
229
        keybindings_set_item(group, GEANY_KEYS_FILE_NEW, NULL,
199
230
                GDK_n, GDK_CONTROL_MASK, "menu_new", _("New"), NULL);
200
 
        keybindings_set_item(group, GEANY_KEYS_FILE_OPEN, cb_func_file_action,
 
231
        keybindings_set_item(group, GEANY_KEYS_FILE_OPEN, NULL,
201
232
                GDK_o, GDK_CONTROL_MASK, "menu_open", _("Open"), NULL);
202
 
        keybindings_set_item(group, GEANY_KEYS_FILE_OPENSELECTED, cb_func_file_action,
 
233
        keybindings_set_item(group, GEANY_KEYS_FILE_OPENSELECTED, NULL,
203
234
                GDK_o, GDK_SHIFT_MASK | GDK_CONTROL_MASK, "menu_open_selected",
204
235
                _("Open selected file"), LW(menu_open_selected_file1));
205
 
        keybindings_set_item(group, GEANY_KEYS_FILE_SAVE, cb_func_file_action,
 
236
        keybindings_set_item(group, GEANY_KEYS_FILE_SAVE, NULL,
206
237
                GDK_s, GDK_CONTROL_MASK, "menu_save", _("Save"), NULL);
207
 
        keybindings_set_item(group, GEANY_KEYS_FILE_SAVEAS, cb_func_file_action,
 
238
        keybindings_set_item(group, GEANY_KEYS_FILE_SAVEAS, NULL,
208
239
                0, 0, "menu_saveas", _("Save as"), LW(menu_save_as1));
209
 
        keybindings_set_item(group, GEANY_KEYS_FILE_SAVEALL, cb_func_file_action,
 
240
        keybindings_set_item(group, GEANY_KEYS_FILE_SAVEALL, NULL,
210
241
                GDK_S, GDK_SHIFT_MASK | GDK_CONTROL_MASK, "menu_saveall", _("Save all"),
211
242
                LW(menu_save_all1));
212
 
        keybindings_set_item(group, GEANY_KEYS_FILE_PRINT, cb_func_file_action,
 
243
        keybindings_set_item(group, GEANY_KEYS_FILE_PRINT, NULL,
213
244
                GDK_p, GDK_CONTROL_MASK, "menu_print", _("Print"), LW(print1));
214
 
        keybindings_set_item(group, GEANY_KEYS_FILE_CLOSE, cb_func_file_action,
 
245
        keybindings_set_item(group, GEANY_KEYS_FILE_CLOSE, NULL,
215
246
                GDK_w, GDK_CONTROL_MASK, "menu_close", _("Close"), LW(menu_close1));
216
 
        keybindings_set_item(group, GEANY_KEYS_FILE_CLOSEALL, cb_func_file_action,
 
247
        keybindings_set_item(group, GEANY_KEYS_FILE_CLOSEALL, NULL,
217
248
                GDK_w, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "menu_closeall", _("Close all"),
218
249
                LW(menu_close_all1));
219
 
        keybindings_set_item(group, GEANY_KEYS_FILE_RELOAD, cb_func_file_action,
 
250
        keybindings_set_item(group, GEANY_KEYS_FILE_RELOAD, NULL,
220
251
                GDK_r, GDK_CONTROL_MASK, "menu_reloadfile", _("Reload file"), LW(menu_reload1));
221
 
 
222
 
        group = ADD_KB_GROUP(PROJECT, _("Project"));
223
 
 
224
 
        keybindings_set_item(group, GEANY_KEYS_PROJECT_PROPERTIES, cb_func_project_action,
 
252
        keybindings_set_item(group, GEANY_KEYS_FILE_OPENLASTTAB, NULL,
 
253
                0, 0, "file_openlasttab", _("Re-open last closed tab"), NULL);
 
254
 
 
255
        group = ADD_KB_GROUP(PROJECT, _("Project"), cb_func_project_action);
 
256
 
 
257
        keybindings_set_item(group, GEANY_KEYS_PROJECT_PROPERTIES, NULL,
225
258
                0, 0, "project_properties", _("Project properties"), LW(project_properties1));
226
259
 
227
 
        group = ADD_KB_GROUP(EDITOR, _("Editor"));
 
260
        group = ADD_KB_GROUP(EDITOR, _("Editor"), cb_func_editor_action);
228
261
 
229
 
        keybindings_set_item(group, GEANY_KEYS_EDITOR_UNDO, cb_func_editor_action,
 
262
        keybindings_set_item(group, GEANY_KEYS_EDITOR_UNDO, NULL,
230
263
                GDK_z, GDK_CONTROL_MASK, "menu_undo", _("Undo"), LW(menu_undo2));
231
 
        keybindings_set_item(group, GEANY_KEYS_EDITOR_REDO, cb_func_editor_action,
 
264
        keybindings_set_item(group, GEANY_KEYS_EDITOR_REDO, NULL,
232
265
                GDK_y, GDK_CONTROL_MASK, "menu_redo", _("Redo"), LW(menu_redo2));
233
 
        keybindings_set_item(group, GEANY_KEYS_EDITOR_DUPLICATELINE, cb_func_editor_action,
234
 
                GDK_d, GDK_CONTROL_MASK, "edit_duplicateline", _("Duplicate line or selection"),
235
 
                LW(menu_duplicate_line1));
236
 
        keybindings_set_item(group, GEANY_KEYS_EDITOR_DELETELINE, cb_func_editor_action,
237
 
                GDK_k, GDK_CONTROL_MASK, "edit_deleteline", _("Delete current line(s)"), NULL);
238
 
        keybindings_set_item(group, GEANY_KEYS_EDITOR_DELETELINETOEND, cb_func_editor_action,
 
266
        keybindings_set_item(group, GEANY_KEYS_EDITOR_DUPLICATELINE, NULL,
 
267
                GDK_d, GDK_CONTROL_MASK, "edit_duplicateline", _("_Duplicate Line or Selection"),
 
268
                LW(duplicate_line_or_selection1));
 
269
        keybindings_set_item(group, GEANY_KEYS_EDITOR_DELETELINE, NULL,
 
270
                GDK_k, GDK_CONTROL_MASK, "edit_deleteline", _("_Delete Current Line(s)"),
 
271
                LW(delete_current_line_s_1));
 
272
        keybindings_set_item(group, GEANY_KEYS_EDITOR_DELETELINETOEND, NULL,
239
273
                GDK_Delete, GDK_SHIFT_MASK | GDK_CONTROL_MASK, "edit_deletelinetoend",
240
274
                _("Delete to line end"), NULL);
241
 
        keybindings_set_item(group, GEANY_KEYS_EDITOR_TRANSPOSELINE, cb_func_editor_action,
242
 
                GDK_t, GDK_CONTROL_MASK, "edit_transposeline", _("Transpose current line"), NULL);
243
 
        keybindings_set_item(group, GEANY_KEYS_EDITOR_SCROLLTOLINE, cb_func_editor_action,
 
275
        /* transpose may fit better in format group */
 
276
        keybindings_set_item(group, GEANY_KEYS_EDITOR_TRANSPOSELINE, NULL,
 
277
                GDK_t, GDK_CONTROL_MASK, "edit_transposeline", _("_Transpose Current Line"),
 
278
                LW(transpose_current_line1));
 
279
        keybindings_set_item(group, GEANY_KEYS_EDITOR_SCROLLTOLINE, NULL,
244
280
                GDK_l, GDK_SHIFT_MASK | GDK_CONTROL_MASK, "edit_scrolltoline", _("Scroll to current line"), NULL);
245
 
        keybindings_set_item(group, GEANY_KEYS_EDITOR_SCROLLLINEUP, cb_func_editor_action,
 
281
        keybindings_set_item(group, GEANY_KEYS_EDITOR_SCROLLLINEUP, NULL,
246
282
                GDK_Up, GDK_MOD1_MASK, "edit_scrolllineup", _("Scroll up the view by one line"), NULL);
247
 
        keybindings_set_item(group, GEANY_KEYS_EDITOR_SCROLLLINEDOWN, cb_func_editor_action,
 
283
        keybindings_set_item(group, GEANY_KEYS_EDITOR_SCROLLLINEDOWN, NULL,
248
284
                GDK_Down, GDK_MOD1_MASK, "edit_scrolllinedown", _("Scroll down the view by one line"), NULL);
249
 
        /* GEANY_KEYS_EDITOR_COMPLETESNIPPET is handled specially in check_snippet_completion() */
250
285
        keybindings_set_item(group, GEANY_KEYS_EDITOR_COMPLETESNIPPET, NULL,
251
286
                GDK_Tab, 0, "edit_completesnippet", _("Complete snippet"), NULL);
252
 
        keybindings_set_item(group, GEANY_KEYS_EDITOR_SNIPPETNEXTCURSOR, cb_func_editor_action,
 
287
        keybindings_set_item(group, GEANY_KEYS_EDITOR_SNIPPETNEXTCURSOR, NULL,
253
288
                0, 0, "move_snippetnextcursor", _("Move cursor in snippet"), NULL);
254
 
        keybindings_set_item(group, GEANY_KEYS_EDITOR_SUPPRESSSNIPPETCOMPLETION, cb_func_editor_action,
 
289
        keybindings_set_item(group, GEANY_KEYS_EDITOR_SUPPRESSSNIPPETCOMPLETION, NULL,
255
290
                0, 0, "edit_suppresssnippetcompletion", _("Suppress snippet completion"), NULL);
256
 
        keybindings_set_item(group, GEANY_KEYS_EDITOR_CONTEXTACTION, cb_func_editor_action,
 
291
        keybindings_set_item(group, GEANY_KEYS_EDITOR_CONTEXTACTION, NULL,
257
292
                0, 0, "popup_contextaction", _("Context Action"), NULL);
258
 
        keybindings_set_item(group, GEANY_KEYS_EDITOR_AUTOCOMPLETE, cb_func_editor_action,
 
293
        keybindings_set_item(group, GEANY_KEYS_EDITOR_AUTOCOMPLETE, NULL,
259
294
                GDK_space, GDK_CONTROL_MASK, "edit_autocomplete", _("Complete word"), NULL);
260
 
        keybindings_set_item(group, GEANY_KEYS_EDITOR_CALLTIP, cb_func_editor_action,
 
295
        keybindings_set_item(group, GEANY_KEYS_EDITOR_CALLTIP, NULL,
261
296
                GDK_space, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "edit_calltip", _("Show calltip"), NULL);
262
 
        keybindings_set_item(group, GEANY_KEYS_EDITOR_MACROLIST, cb_func_editor_action,
 
297
        keybindings_set_item(group, GEANY_KEYS_EDITOR_MACROLIST, NULL,
263
298
                GDK_Return, GDK_CONTROL_MASK, "edit_macrolist", _("Show macro list"), NULL);
264
 
 
265
 
        group = ADD_KB_GROUP(CLIPBOARD, _("Clipboard"));
266
 
 
267
 
        keybindings_set_item(group, GEANY_KEYS_CLIPBOARD_CUT, cb_func_clipboard,
 
299
        keybindings_set_item(group, GEANY_KEYS_EDITOR_WORDPARTCOMPLETION, NULL,
 
300
                GDK_Tab, 0, "edit_wordpartcompletion", _("Word part completion"), NULL);
 
301
        keybindings_set_item(group, GEANY_KEYS_EDITOR_MOVELINEUP, NULL,
 
302
                0, 0, "edit_movelineup", _("Move line(s) up"), NULL);
 
303
        keybindings_set_item(group, GEANY_KEYS_EDITOR_MOVELINEDOWN, NULL,
 
304
                0, 0, "edit_movelinedown", _("Move line(s) down"), NULL);
 
305
 
 
306
        group = ADD_KB_GROUP(CLIPBOARD, _("Clipboard"), cb_func_clipboard_action);
 
307
 
 
308
        keybindings_set_item(group, GEANY_KEYS_CLIPBOARD_CUT, NULL,
268
309
                GDK_x, GDK_CONTROL_MASK, "menu_cut", _("Cut"), NULL);
269
 
        keybindings_set_item(group, GEANY_KEYS_CLIPBOARD_COPY, cb_func_clipboard,
 
310
        keybindings_set_item(group, GEANY_KEYS_CLIPBOARD_COPY, NULL,
270
311
                GDK_c, GDK_CONTROL_MASK, "menu_copy", _("Copy"), NULL);
271
 
        keybindings_set_item(group, GEANY_KEYS_CLIPBOARD_PASTE, cb_func_clipboard,
 
312
        keybindings_set_item(group, GEANY_KEYS_CLIPBOARD_PASTE, NULL,
272
313
                GDK_v, GDK_CONTROL_MASK, "menu_paste", _("Paste"), NULL);
273
 
        keybindings_set_item(group, GEANY_KEYS_CLIPBOARD_COPYLINE, cb_func_clipboard,
274
 
                GDK_c, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "edit_copyline", _("Copy current line(s)"), NULL);
275
 
        keybindings_set_item(group, GEANY_KEYS_CLIPBOARD_CUTLINE, cb_func_clipboard,
276
 
                GDK_x, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "edit_cutline", _("Cut current line(s)"), NULL);
277
 
 
278
 
        group = ADD_KB_GROUP(SELECT, _("Select"));
279
 
 
280
 
        keybindings_set_item(group, GEANY_KEYS_SELECT_ALL, cb_func_select_action,
 
314
        keybindings_set_item(group, GEANY_KEYS_CLIPBOARD_COPYLINE, NULL,
 
315
                GDK_c, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "edit_copyline", _("_Copy Current Line(s)"),
 
316
                LW(copy_current_line_s_1));
 
317
        keybindings_set_item(group, GEANY_KEYS_CLIPBOARD_CUTLINE, NULL,
 
318
                GDK_x, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "edit_cutline", _("_Cut Current Line(s)"),
 
319
                LW(cut_current_line_s_1));
 
320
 
 
321
        group = ADD_KB_GROUP(SELECT, _("Select"), cb_func_select_action);
 
322
 
 
323
        keybindings_set_item(group, GEANY_KEYS_SELECT_ALL, NULL,
281
324
                GDK_a, GDK_CONTROL_MASK, "menu_selectall", _("Select All"), LW(menu_select_all1));
282
 
        keybindings_set_item(group, GEANY_KEYS_SELECT_WORD, cb_func_select_action,
 
325
        keybindings_set_item(group, GEANY_KEYS_SELECT_WORD, NULL,
283
326
                GDK_w, GDK_SHIFT_MASK | GDK_MOD1_MASK, "edit_selectword", _("Select current word"), NULL);
284
 
        keybindings_set_item(group, GEANY_KEYS_SELECT_LINE, cb_func_select_action,
285
 
                GDK_l, GDK_SHIFT_MASK | GDK_MOD1_MASK, "edit_selectline", _("Select current line(s)"), NULL);
286
 
        keybindings_set_item(group, GEANY_KEYS_SELECT_PARAGRAPH, cb_func_select_action,
287
 
                GDK_p, GDK_SHIFT_MASK | GDK_MOD1_MASK, "edit_selectparagraph", _("Select current paragraph"), NULL);
288
 
 
289
 
        group = ADD_KB_GROUP(FORMAT, _("Format"));
290
 
 
291
 
        keybindings_set_item(group, GEANY_KEYS_FORMAT_TOGGLECASE, cb_func_format_action,
 
327
        keybindings_set_item(group, GEANY_KEYS_SELECT_LINE, NULL,
 
328
                GDK_l, GDK_SHIFT_MASK | GDK_MOD1_MASK, "edit_selectline", _("_Select Current Line(s)"),
 
329
                LW(select_current_line_s_1));
 
330
        keybindings_set_item(group, GEANY_KEYS_SELECT_PARAGRAPH, NULL,
 
331
                GDK_p, GDK_SHIFT_MASK | GDK_MOD1_MASK, "edit_selectparagraph", _("_Select Current Paragraph"),
 
332
                LW(select_current_paragraph1));
 
333
        keybindings_set_item(group, GEANY_KEYS_SELECT_WORDPARTLEFT, NULL,
 
334
                0, 0, "edit_selectwordpartleft", _("Select to previous word part"), NULL);
 
335
        keybindings_set_item(group, GEANY_KEYS_SELECT_WORDPARTRIGHT, NULL,
 
336
                0, 0, "edit_selectwordpartright", _("Select to next word part"), NULL);
 
337
 
 
338
        group = ADD_KB_GROUP(FORMAT, _("Format"), cb_func_format_action);
 
339
 
 
340
        keybindings_set_item(group, GEANY_KEYS_FORMAT_TOGGLECASE, NULL,
292
341
                GDK_u, GDK_CONTROL_MASK | GDK_MOD1_MASK, "edit_togglecase",
293
342
                _("Toggle Case of Selection"), LW(menu_toggle_case2));
294
 
        keybindings_set_item(group, GEANY_KEYS_FORMAT_COMMENTLINETOGGLE, cb_func_format_action,
 
343
        keybindings_set_item(group, GEANY_KEYS_FORMAT_COMMENTLINETOGGLE, NULL,
295
344
                GDK_e, GDK_CONTROL_MASK, "edit_commentlinetoggle", _("Toggle line commentation"),
296
345
                LW(menu_toggle_line_commentation1));
297
 
        keybindings_set_item(group, GEANY_KEYS_FORMAT_COMMENTLINE, cb_func_format_action,
 
346
        keybindings_set_item(group, GEANY_KEYS_FORMAT_COMMENTLINE, NULL,
298
347
                0, 0, "edit_commentline", _("Comment line(s)"), LW(menu_comment_line1));
299
 
        keybindings_set_item(group, GEANY_KEYS_FORMAT_UNCOMMENTLINE, cb_func_format_action,
 
348
        keybindings_set_item(group, GEANY_KEYS_FORMAT_UNCOMMENTLINE, NULL,
300
349
                0, 0, "edit_uncommentline", _("Uncomment line(s)"), LW(menu_uncomment_line1));
301
 
        keybindings_set_item(group, GEANY_KEYS_FORMAT_INCREASEINDENT, cb_func_format_action,
 
350
        keybindings_set_item(group, GEANY_KEYS_FORMAT_INCREASEINDENT, NULL,
302
351
                GDK_i, GDK_CONTROL_MASK, "edit_increaseindent", _("Increase indent"),
303
352
                LW(menu_increase_indent1));
304
 
        keybindings_set_item(group, GEANY_KEYS_FORMAT_DECREASEINDENT, cb_func_format_action,
 
353
        keybindings_set_item(group, GEANY_KEYS_FORMAT_DECREASEINDENT, NULL,
305
354
                GDK_u, GDK_CONTROL_MASK, "edit_decreaseindent", _("Decrease indent"),
306
355
                LW(menu_decrease_indent1));
307
 
        keybindings_set_item(group, GEANY_KEYS_FORMAT_INCREASEINDENTBYSPACE, cb_func_format_action,
 
356
        keybindings_set_item(group, GEANY_KEYS_FORMAT_INCREASEINDENTBYSPACE, NULL,
308
357
                0, 0, "edit_increaseindentbyspace", _("Increase indent by one space"), NULL);
309
 
        keybindings_set_item(group, GEANY_KEYS_FORMAT_DECREASEINDENTBYSPACE, cb_func_format_action,
 
358
        keybindings_set_item(group, GEANY_KEYS_FORMAT_DECREASEINDENTBYSPACE, NULL,
310
359
                0, 0, "edit_decreaseindentbyspace", _("Decrease indent by one space"), NULL);
311
 
        keybindings_set_item(group, GEANY_KEYS_FORMAT_AUTOINDENT, cb_func_format_action,
312
 
                0, 0, "edit_autoindent", _("Smart line indent"), NULL);
313
 
        keybindings_set_item(group, GEANY_KEYS_FORMAT_SENDTOCMD1, cb_func_format_action,
 
360
        keybindings_set_item(group, GEANY_KEYS_FORMAT_AUTOINDENT, NULL,
 
361
                0, 0, "edit_autoindent", _("_Smart Line Indent"), LW(smart_line_indent1));
 
362
        keybindings_set_item(group, GEANY_KEYS_FORMAT_SENDTOCMD1, NULL,
314
363
                GDK_1, GDK_CONTROL_MASK, "edit_sendtocmd1", _("Send to Custom Command 1"), NULL);
315
 
        keybindings_set_item(group, GEANY_KEYS_FORMAT_SENDTOCMD2, cb_func_format_action,
 
364
        keybindings_set_item(group, GEANY_KEYS_FORMAT_SENDTOCMD2, NULL,
316
365
                GDK_2, GDK_CONTROL_MASK, "edit_sendtocmd2", _("Send to Custom Command 2"), NULL);
317
 
        keybindings_set_item(group, GEANY_KEYS_FORMAT_SENDTOCMD3, cb_func_format_action,
 
366
        keybindings_set_item(group, GEANY_KEYS_FORMAT_SENDTOCMD3, NULL,
318
367
                GDK_3, GDK_CONTROL_MASK, "edit_sendtocmd3", _("Send to Custom Command 3"), NULL);
319
 
        keybindings_set_item(group, GEANY_KEYS_FORMAT_SENDTOVTE, cb_func_format_action,
320
 
                0, 0, "edit_sendtovte", _("Send Selection to Terminal"), LW(send_selection_to_vte1));
321
 
        keybindings_set_item(group, GEANY_KEYS_FORMAT_REFLOWPARAGRAPH, cb_func_format_action,
322
 
                GDK_j, GDK_CONTROL_MASK, "format_reflowparagraph", _("Reflow lines/block"), NULL);
323
 
 
324
 
        group = ADD_KB_GROUP(INSERT, _("Insert"));
325
 
 
326
 
        keybindings_set_item(group, GEANY_KEYS_INSERT_DATE, cb_func_insert_action,
 
368
        /* may fit better in editor group */
 
369
        keybindings_set_item(group, GEANY_KEYS_FORMAT_SENDTOVTE, NULL,
 
370
                0, 0, "edit_sendtovte", _("_Send Selection to Terminal"), LW(send_selection_to_vte1));
 
371
        keybindings_set_item(group, GEANY_KEYS_FORMAT_REFLOWPARAGRAPH, NULL,
 
372
                GDK_j, GDK_CONTROL_MASK, "format_reflowparagraph", _("_Reflow Lines/Block"),
 
373
                LW(reflow_lines_block1));
 
374
 
 
375
        group = ADD_KB_GROUP(INSERT, _("Insert"), cb_func_insert_action);
 
376
 
 
377
        keybindings_set_item(group, GEANY_KEYS_INSERT_DATE, NULL,
327
378
                GDK_d, GDK_SHIFT_MASK | GDK_MOD1_MASK, "menu_insert_date", _("Insert date"),
328
379
                LW(insert_date_custom1));
329
 
        keybindings_set_item(group, GEANY_KEYS_INSERT_ALTWHITESPACE, cb_func_insert_action,
330
 
                0, 0, "edit_insertwhitespace", _("Insert alternative white space"), NULL);
 
380
        keybindings_set_item(group, GEANY_KEYS_INSERT_ALTWHITESPACE, NULL,
 
381
                0, 0, "edit_insertwhitespace", _("_Insert Alternative White Space"),
 
382
                LW(insert_alternative_white_space1));
331
383
 
332
 
        group = ADD_KB_GROUP(SETTINGS, _("Settings"));
 
384
        group = ADD_KB_GROUP(SETTINGS, _("Settings"), NULL);
333
385
 
334
386
        keybindings_set_item(group, GEANY_KEYS_SETTINGS_PREFERENCES, cb_func_menu_preferences,
335
387
                GDK_p, GDK_CONTROL_MASK | GDK_MOD1_MASK, "menu_preferences", _("Preferences"),
336
388
                LW(preferences1));
337
 
 
338
 
        group = ADD_KB_GROUP(SEARCH, _("Search"));
339
 
 
340
 
        keybindings_set_item(group, GEANY_KEYS_SEARCH_FIND, cb_func_search_action,
 
389
        keybindings_set_item(group, GEANY_KEYS_SETTINGS_PLUGINPREFERENCES, cb_func_menu_preferences,
 
390
                0, 0, "menu_pluginpreferences", _("P_lugin Preferences"), LW(plugin_preferences1));
 
391
 
 
392
        group = ADD_KB_GROUP(SEARCH, _("Search"), cb_func_search_action);
 
393
 
 
394
        keybindings_set_item(group, GEANY_KEYS_SEARCH_FIND, NULL,
341
395
                GDK_f, GDK_CONTROL_MASK, "menu_find", _("Find"), LW(find1));
342
 
        keybindings_set_item(group, GEANY_KEYS_SEARCH_FINDNEXT, cb_func_search_action,
 
396
        keybindings_set_item(group, GEANY_KEYS_SEARCH_FINDNEXT, NULL,
343
397
                GDK_g, GDK_CONTROL_MASK, "menu_findnext", _("Find Next"), LW(find_next1));
344
 
        keybindings_set_item(group, GEANY_KEYS_SEARCH_FINDPREVIOUS, cb_func_search_action,
 
398
        keybindings_set_item(group, GEANY_KEYS_SEARCH_FINDPREVIOUS, NULL,
345
399
                GDK_g, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "menu_findprevious", _("Find Previous"),
346
400
                LW(find_previous1));
347
 
        keybindings_set_item(group, GEANY_KEYS_SEARCH_FINDNEXTSEL, cb_func_search_action,
 
401
        keybindings_set_item(group, GEANY_KEYS_SEARCH_FINDNEXTSEL, NULL,
348
402
                0, 0, "menu_findnextsel", _("Find Next Selection"), LW(find_nextsel1));
349
 
        keybindings_set_item(group, GEANY_KEYS_SEARCH_FINDPREVSEL, cb_func_search_action,
 
403
        keybindings_set_item(group, GEANY_KEYS_SEARCH_FINDPREVSEL, NULL,
350
404
                0, 0, "menu_findprevsel", _("Find Previous Selection"), LW(find_prevsel1));
351
 
        keybindings_set_item(group, GEANY_KEYS_SEARCH_REPLACE, cb_func_search_action,
 
405
        keybindings_set_item(group, GEANY_KEYS_SEARCH_REPLACE, NULL,
352
406
                GDK_h, GDK_CONTROL_MASK, "menu_replace", _("Replace"), LW(replace1));
353
 
        keybindings_set_item(group, GEANY_KEYS_SEARCH_FINDINFILES, cb_func_search_action, GDK_f,
 
407
        keybindings_set_item(group, GEANY_KEYS_SEARCH_FINDINFILES, NULL, GDK_f,
354
408
                GDK_CONTROL_MASK | GDK_SHIFT_MASK, "menu_findinfiles", _("Find in Files"),
355
409
                LW(find_in_files1));
356
 
        keybindings_set_item(group, GEANY_KEYS_SEARCH_NEXTMESSAGE, cb_func_search_action,
 
410
        keybindings_set_item(group, GEANY_KEYS_SEARCH_NEXTMESSAGE, NULL,
357
411
                0, 0, "menu_nextmessage", _("Next Message"), LW(next_message1));
358
 
        keybindings_set_item(group, GEANY_KEYS_SEARCH_PREVIOUSMESSAGE, cb_func_search_action,
 
412
        keybindings_set_item(group, GEANY_KEYS_SEARCH_PREVIOUSMESSAGE, NULL,
359
413
                0, 0, "menu_previousmessage", _("Previous Message"), LW(previous_message1));
360
 
        keybindings_set_item(group, GEANY_KEYS_SEARCH_FINDUSAGE, cb_func_search_action,
 
414
        keybindings_set_item(group, GEANY_KEYS_SEARCH_FINDUSAGE, NULL,
361
415
                0, 0, "popup_findusage", _("Find Usage"), NULL);
362
 
        keybindings_set_item(group, GEANY_KEYS_SEARCH_FINDDOCUMENTUSAGE, cb_func_search_action,
 
416
        keybindings_set_item(group, GEANY_KEYS_SEARCH_FINDDOCUMENTUSAGE, NULL,
363
417
                0, 0, "popup_finddocumentusage", _("Find Document Usage"), NULL);
364
 
        keybindings_set_item(group, GEANY_KEYS_SEARCH_MARKALL, cb_func_search_action,
 
418
        keybindings_set_item(group, GEANY_KEYS_SEARCH_MARKALL, NULL,
365
419
                GDK_m, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "find_markall", _("Mark All"), NULL);
366
420
 
367
 
        group = ADD_KB_GROUP(GOTO, _("Go to"));
 
421
        group = ADD_KB_GROUP(GOTO, _("Go to"), cb_func_goto_action);
368
422
 
369
 
        keybindings_set_item(group, GEANY_KEYS_GOTO_BACK, cb_func_goto_action,
 
423
        keybindings_set_item(group, GEANY_KEYS_GOTO_BACK, NULL,
370
424
                0, 0, "nav_back", _("Navigate back a location"), NULL);
371
 
        keybindings_set_item(group, GEANY_KEYS_GOTO_FORWARD, cb_func_goto_action,
 
425
        keybindings_set_item(group, GEANY_KEYS_GOTO_FORWARD, NULL,
372
426
                0, 0, "nav_forward", _("Navigate forward a location"), NULL);
373
 
        keybindings_set_item(group, GEANY_KEYS_GOTO_LINE, cb_func_goto_action,
 
427
        keybindings_set_item(group, GEANY_KEYS_GOTO_LINE, NULL,
374
428
                GDK_l, GDK_CONTROL_MASK, "menu_gotoline", _("Go to Line"), LW(go_to_line1));
375
 
        keybindings_set_item(group, GEANY_KEYS_GOTO_MATCHINGBRACE, cb_func_goto_action,
 
429
        keybindings_set_item(group, GEANY_KEYS_GOTO_MATCHINGBRACE, NULL,
376
430
                GDK_b, GDK_CONTROL_MASK, "edit_gotomatchingbrace",
377
431
                _("Go to matching brace"), NULL);
378
 
        keybindings_set_item(group, GEANY_KEYS_GOTO_TOGGLEMARKER, cb_func_goto_action,
 
432
        keybindings_set_item(group, GEANY_KEYS_GOTO_TOGGLEMARKER, NULL,
379
433
                GDK_m, GDK_CONTROL_MASK, "edit_togglemarker",
380
434
                _("Toggle marker"), NULL);
381
 
        keybindings_set_item(group, GEANY_KEYS_GOTO_NEXTMARKER, cb_func_goto_action,
 
435
        keybindings_set_item(group, GEANY_KEYS_GOTO_NEXTMARKER, NULL,
382
436
                GDK_period, GDK_CONTROL_MASK, "edit_gotonextmarker",
383
 
                _("Go to next marker"), NULL);
384
 
        keybindings_set_item(group, GEANY_KEYS_GOTO_PREVIOUSMARKER, cb_func_goto_action,
 
437
                _("_Go to Next Marker"), LW(go_to_next_marker1));
 
438
        keybindings_set_item(group, GEANY_KEYS_GOTO_PREVIOUSMARKER, NULL,
385
439
                GDK_comma, GDK_CONTROL_MASK, "edit_gotopreviousmarker",
386
 
                _("Go to previous marker"), NULL);
387
 
        keybindings_set_item(group, GEANY_KEYS_GOTO_TAGDEFINITION, cb_func_goto_action,
 
440
                _("_Go to Previous Marker"), LW(go_to_previous_marker1));
 
441
        keybindings_set_item(group, GEANY_KEYS_GOTO_TAGDEFINITION, NULL,
388
442
                0, 0, "popup_gototagdefinition", _("Go to Tag Definition"), NULL);
389
 
        keybindings_set_item(group, GEANY_KEYS_GOTO_TAGDECLARATION, cb_func_goto_action,
 
443
        keybindings_set_item(group, GEANY_KEYS_GOTO_TAGDECLARATION, NULL,
390
444
                0, 0, "popup_gototagdeclaration", _("Go to Tag Declaration"), NULL);
391
 
        keybindings_set_item(group, GEANY_KEYS_GOTO_LINESTART, cb_func_goto_action,
 
445
        keybindings_set_item(group, GEANY_KEYS_GOTO_LINESTART, NULL,
392
446
                GDK_Home, 0, "edit_gotolinestart", _("Go to Start of Line"), NULL);
393
 
        keybindings_set_item(group, GEANY_KEYS_GOTO_LINEEND, cb_func_goto_action,
 
447
        keybindings_set_item(group, GEANY_KEYS_GOTO_LINEEND, NULL,
394
448
                GDK_End, 0, "edit_gotolineend", _("Go to End of Line"), NULL);
395
 
        keybindings_set_item(group, GEANY_KEYS_GOTO_LINEENDVISUAL, cb_func_goto_action,
 
449
        keybindings_set_item(group, GEANY_KEYS_GOTO_LINEENDVISUAL, NULL,
396
450
                GDK_End, GDK_MOD1_MASK, "edit_gotolineendvisual", _("Go to End of Display Line"), NULL);
397
 
        keybindings_set_item(group, GEANY_KEYS_GOTO_PREVWORDSTART, cb_func_goto_action,
 
451
        keybindings_set_item(group, GEANY_KEYS_GOTO_PREVWORDPART, NULL,
398
452
                GDK_slash, GDK_CONTROL_MASK, "edit_prevwordstart", _("Go to Previous Word Part"), NULL);
399
 
        keybindings_set_item(group, GEANY_KEYS_GOTO_NEXTWORDSTART, cb_func_goto_action,
 
453
        keybindings_set_item(group, GEANY_KEYS_GOTO_NEXTWORDPART, NULL,
400
454
                GDK_backslash, GDK_CONTROL_MASK, "edit_nextwordstart", _("Go to Next Word Part"), NULL);
401
455
 
402
 
        group = ADD_KB_GROUP(VIEW, _("View"));
 
456
        group = ADD_KB_GROUP(VIEW, _("View"), cb_func_view_action);
403
457
 
404
 
        keybindings_set_item(group, GEANY_KEYS_VIEW_TOGGLEALL, cb_func_view_action,
 
458
        keybindings_set_item(group, GEANY_KEYS_VIEW_TOGGLEALL, NULL,
405
459
                0, 0, "menu_toggleall", _("Toggle All Additional Widgets"),
406
460
                LW(menu_toggle_all_additional_widgets1));
407
461
        keybindings_set_item(group, GEANY_KEYS_VIEW_FULLSCREEN, cb_func_menu_fullscreen,
409
463
        keybindings_set_item(group, GEANY_KEYS_VIEW_MESSAGEWINDOW, cb_func_menu_messagewindow,
410
464
                0, 0, "menu_messagewindow", _("Toggle Messages Window"),
411
465
                LW(menu_show_messages_window1));
412
 
        keybindings_set_item(group, GEANY_KEYS_VIEW_SIDEBAR, cb_func_view_action,
 
466
        keybindings_set_item(group, GEANY_KEYS_VIEW_SIDEBAR, NULL,
413
467
                0, 0, "toggle_sidebar", _("Toggle Sidebar"), LW(menu_show_sidebar1));
414
 
        keybindings_set_item(group, GEANY_KEYS_VIEW_ZOOMIN, cb_func_view_action,
 
468
        keybindings_set_item(group, GEANY_KEYS_VIEW_ZOOMIN, NULL,
415
469
                GDK_plus, GDK_CONTROL_MASK, "menu_zoomin", _("Zoom In"), LW(menu_zoom_in1));
416
 
        keybindings_set_item(group, GEANY_KEYS_VIEW_ZOOMOUT, cb_func_view_action,
 
470
        keybindings_set_item(group, GEANY_KEYS_VIEW_ZOOMOUT, NULL,
417
471
                GDK_minus, GDK_CONTROL_MASK, "menu_zoomout", _("Zoom Out"), LW(menu_zoom_out1));
418
 
 
419
 
        group = ADD_KB_GROUP(FOCUS, _("Focus"));
420
 
 
421
 
        keybindings_set_item(group, GEANY_KEYS_FOCUS_EDITOR, cb_func_switch_action,
 
472
        keybindings_set_item(group, GEANY_KEYS_VIEW_ZOOMRESET, NULL,
 
473
                GDK_0, GDK_CONTROL_MASK, "normal_size", _("Zoom Reset"), LW(normal_size1));
 
474
 
 
475
        group = ADD_KB_GROUP(FOCUS, _("Focus"), cb_func_switch_action);
 
476
 
 
477
        keybindings_set_item(group, GEANY_KEYS_FOCUS_EDITOR, NULL,
422
478
                GDK_F2, 0, "switch_editor", _("Switch to Editor"), NULL);
423
 
        keybindings_set_item(group, GEANY_KEYS_FOCUS_SCRIBBLE, cb_func_switch_action,
 
479
        keybindings_set_item(group, GEANY_KEYS_FOCUS_SCRIBBLE, NULL,
424
480
                GDK_F6, 0, "switch_scribble", _("Switch to Scribble"), NULL);
425
 
        keybindings_set_item(group, GEANY_KEYS_FOCUS_VTE, cb_func_switch_action,
 
481
        keybindings_set_item(group, GEANY_KEYS_FOCUS_VTE, NULL,
426
482
                GDK_F4, 0, "switch_vte", _("Switch to VTE"), NULL);
427
 
        keybindings_set_item(group, GEANY_KEYS_FOCUS_SEARCHBAR, cb_func_switch_action,
 
483
        keybindings_set_item(group, GEANY_KEYS_FOCUS_SEARCHBAR, NULL,
428
484
                GDK_F7, 0, "switch_search_bar", _("Switch to Search Bar"), NULL);
429
 
        keybindings_set_item(group, GEANY_KEYS_FOCUS_SIDEBAR, cb_func_switch_action,
 
485
        keybindings_set_item(group, GEANY_KEYS_FOCUS_SIDEBAR, NULL,
430
486
                0, 0, "switch_sidebar", _("Switch to Sidebar"), NULL);
431
 
        keybindings_set_item(group, GEANY_KEYS_FOCUS_COMPILER, cb_func_switch_action,
 
487
        keybindings_set_item(group, GEANY_KEYS_FOCUS_COMPILER, NULL,
432
488
                0, 0, "switch_compiler", _("Switch to Compiler"), NULL);
 
489
        keybindings_set_item(group, GEANY_KEYS_FOCUS_MESSAGES, NULL,
 
490
                0, 0, "switch_messages", _("Switch to Messages"), NULL);
 
491
        keybindings_set_item(group, GEANY_KEYS_FOCUS_MESSAGE_WINDOW, NULL,
 
492
                0, 0, "switch_message_window", _("Switch to Message Window"), NULL);
 
493
        keybindings_set_item(group, GEANY_KEYS_FOCUS_SIDEBAR_DOCUMENT_LIST, NULL,
 
494
                0, 0, "switch_sidebar_doc_list", _("Switch to Sidebar Document List"), NULL);
 
495
        keybindings_set_item(group, GEANY_KEYS_FOCUS_SIDEBAR_SYMBOL_LIST, NULL,
 
496
                0, 0, "switch_sidebar_symbol_list", _("Switch to Sidebar Symbol List"), NULL);
433
497
 
434
 
        group = ADD_KB_GROUP(NOTEBOOK, _("Notebook tab"));
 
498
        group = ADD_KB_GROUP(NOTEBOOK, _("Notebook tab"), NULL);
435
499
 
436
500
        keybindings_set_item(group, GEANY_KEYS_NOTEBOOK_SWITCHTABLEFT, cb_func_switch_tableft,
437
501
                GDK_Page_Up, GDK_CONTROL_MASK, "switch_tableft", _("Switch to left document"), NULL);
448
512
        keybindings_set_item(group, GEANY_KEYS_NOTEBOOK_MOVETABLAST, cb_func_move_tab,
449
513
                0, 0, "move_tablast", _("Move document last"), NULL);
450
514
 
451
 
        group = ADD_KB_GROUP(DOCUMENT, _("Document"));
 
515
        group = ADD_KB_GROUP(DOCUMENT, _("Document"), cb_func_document_action);
452
516
 
453
 
        keybindings_set_item(group, GEANY_KEYS_DOCUMENT_LINEWRAP, cb_func_document_action,
 
517
        keybindings_set_item(group, GEANY_KEYS_DOCUMENT_LINEWRAP, NULL,
454
518
                0, 0, "menu_linewrap", _("Toggle Line wrapping"), LW(menu_line_wrapping1));
455
 
        keybindings_set_item(group, GEANY_KEYS_DOCUMENT_LINEBREAK, cb_func_document_action,
 
519
        keybindings_set_item(group, GEANY_KEYS_DOCUMENT_LINEBREAK, NULL,
456
520
                0, 0, "menu_linebreak", _("Toggle Line breaking"), LW(line_breaking1));
457
 
        keybindings_set_item(group, GEANY_KEYS_DOCUMENT_REPLACETABS, cb_func_document_action,
 
521
        keybindings_set_item(group, GEANY_KEYS_DOCUMENT_REPLACETABS, NULL,
458
522
                0, 0, "menu_replacetabs", _("Replace tabs by space"), LW(menu_replace_tabs));
459
 
        keybindings_set_item(group, GEANY_KEYS_DOCUMENT_REPLACESPACES, cb_func_document_action,
 
523
        keybindings_set_item(group, GEANY_KEYS_DOCUMENT_REPLACESPACES, NULL,
460
524
                0, 0, "menu_replacespaces", _("Replace spaces by tabs"), LW(menu_replace_spaces));
461
 
        keybindings_set_item(group, GEANY_KEYS_DOCUMENT_TOGGLEFOLD, cb_func_document_action,
 
525
        keybindings_set_item(group, GEANY_KEYS_DOCUMENT_TOGGLEFOLD, NULL,
462
526
                0, 0, "menu_togglefold", _("Toggle current fold"), NULL);
463
 
        keybindings_set_item(group, GEANY_KEYS_DOCUMENT_FOLDALL, cb_func_document_action,
 
527
        keybindings_set_item(group, GEANY_KEYS_DOCUMENT_FOLDALL, NULL,
464
528
                0, 0, "menu_foldall", _("Fold all"), LW(menu_fold_all1));
465
 
        keybindings_set_item(group, GEANY_KEYS_DOCUMENT_UNFOLDALL, cb_func_document_action,
 
529
        keybindings_set_item(group, GEANY_KEYS_DOCUMENT_UNFOLDALL, NULL,
466
530
                0, 0, "menu_unfoldall", _("Unfold all"), LW(menu_unfold_all1));
467
 
        keybindings_set_item(group, GEANY_KEYS_DOCUMENT_RELOADTAGLIST, cb_func_document_action,
 
531
        keybindings_set_item(group, GEANY_KEYS_DOCUMENT_RELOADTAGLIST, NULL,
468
532
                GDK_r, GDK_SHIFT_MASK | GDK_CONTROL_MASK, "reloadtaglist", _("Reload symbol list"), NULL);
469
 
 
470
 
        group = ADD_KB_GROUP(BUILD, _("Build"));
471
 
 
472
 
        keybindings_set_item(group, GEANY_KEYS_BUILD_COMPILE, cb_func_build_action,
 
533
        keybindings_set_item(group, GEANY_KEYS_DOCUMENT_REMOVE_MARKERS, NULL,
 
534
                0, 0, "remove_markers", _("Remove Markers"), LW(remove_markers1));
 
535
        keybindings_set_item(group, GEANY_KEYS_DOCUMENT_REMOVE_ERROR_INDICATORS, NULL,
 
536
                0, 0, "remove_error_indicators", _("Remove Error Indicators"), LW(menu_remove_indicators1));
 
537
 
 
538
        group = ADD_KB_GROUP(BUILD, _("Build"), cb_func_build_action);
 
539
 
 
540
        keybindings_set_item(group, GEANY_KEYS_BUILD_COMPILE, NULL,
473
541
                GDK_F8, 0, "build_compile", _("Compile"), NULL);
474
 
        keybindings_set_item(group, GEANY_KEYS_BUILD_LINK, cb_func_build_action,
 
542
        keybindings_set_item(group, GEANY_KEYS_BUILD_LINK, NULL,
475
543
                GDK_F9, 0, "build_link", _("Build"), NULL);
476
 
        keybindings_set_item(group, GEANY_KEYS_BUILD_MAKE, cb_func_build_action,
 
544
        keybindings_set_item(group, GEANY_KEYS_BUILD_MAKE, NULL,
477
545
                GDK_F9, GDK_SHIFT_MASK, "build_make", _("Make all"), NULL);
478
 
        keybindings_set_item(group, GEANY_KEYS_BUILD_MAKEOWNTARGET, cb_func_build_action,
 
546
        keybindings_set_item(group, GEANY_KEYS_BUILD_MAKEOWNTARGET, NULL,
479
547
                GDK_F9, GDK_SHIFT_MASK | GDK_CONTROL_MASK, "build_makeowntarget",
480
548
                _("Make custom target"), NULL);
481
 
        keybindings_set_item(group, GEANY_KEYS_BUILD_MAKEOBJECT, cb_func_build_action,
 
549
        keybindings_set_item(group, GEANY_KEYS_BUILD_MAKEOBJECT, NULL,
482
550
                0, 0, "build_makeobject", _("Make object"), NULL);
483
 
        keybindings_set_item(group, GEANY_KEYS_BUILD_NEXTERROR, cb_func_build_action,
 
551
        keybindings_set_item(group, GEANY_KEYS_BUILD_NEXTERROR, NULL,
484
552
                0, 0, "build_nexterror", _("Next error"), NULL);
485
 
        keybindings_set_item(group, GEANY_KEYS_BUILD_PREVIOUSERROR, cb_func_build_action,
 
553
        keybindings_set_item(group, GEANY_KEYS_BUILD_PREVIOUSERROR, NULL,
486
554
                0, 0, "build_previouserror", _("Previous error"), NULL);
487
 
        keybindings_set_item(group, GEANY_KEYS_BUILD_RUN, cb_func_build_action,
 
555
        keybindings_set_item(group, GEANY_KEYS_BUILD_RUN, NULL,
488
556
                GDK_F5, 0, "build_run", _("Run"), NULL);
489
 
        keybindings_set_item(group, GEANY_KEYS_BUILD_RUN2, cb_func_build_action,
490
 
                0, 0, "build_run2", _("Run (alternative command)"), NULL);
491
 
        keybindings_set_item(group, GEANY_KEYS_BUILD_OPTIONS, cb_func_build_action,
 
557
        keybindings_set_item(group, GEANY_KEYS_BUILD_OPTIONS, NULL,
492
558
                0, 0, "build_options", _("Build options"), NULL);
493
559
 
494
 
        group = ADD_KB_GROUP(TOOLS, _("Tools"));
 
560
        group = ADD_KB_GROUP(TOOLS, _("Tools"), NULL);
495
561
 
496
562
        keybindings_set_item(group, GEANY_KEYS_TOOLS_OPENCOLORCHOOSER, cb_func_menu_opencolorchooser,
497
563
                0, 0, "menu_opencolorchooser", _("Show Color Chooser"), LW(menu_choose_color1));
498
564
 
499
 
        group = ADD_KB_GROUP(HELP, _("Help"));
 
565
        group = ADD_KB_GROUP(HELP, _("Help"), NULL);
500
566
 
501
567
        keybindings_set_item(group, GEANY_KEYS_HELP_HELP, cb_func_menu_help,
502
568
                GDK_F1, 0, "menu_help", _("Help"), LW(help1));
661
727
        group = g_ptr_array_index(keybinding_groups, GEANY_KEY_GROUP_EDITOR);
662
728
        GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_EDITOR_UNDO, undo1);
663
729
        GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_EDITOR_REDO, redo1);
664
 
        GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_EDITOR_DUPLICATELINE, menu_duplicate_line2);
665
730
        GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_EDITOR_CONTEXTACTION, context_action1);
666
731
 
667
732
        group = g_ptr_array_index(keybinding_groups, GEANY_KEY_GROUP_SELECT);
682
747
        GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_GOTO_TAGDEFINITION, goto_tag_definition1);
683
748
        GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_GOTO_TAGDECLARATION, goto_tag_declaration1);
684
749
 
685
 
        group = g_ptr_array_index(keybinding_groups, GEANY_KEY_GROUP_FORMAT);
686
 
        GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_FORMAT_TOGGLECASE, toggle_case1);
687
 
        GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_FORMAT_COMMENTLINE, menu_comment_line2);
688
 
        GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_FORMAT_UNCOMMENTLINE, menu_uncomment_line2);
689
 
        GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_FORMAT_COMMENTLINETOGGLE, menu_toggle_line_commentation2);
690
 
        GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_FORMAT_INCREASEINDENT, menu_increase_indent2);
691
 
        GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_FORMAT_DECREASEINDENT, menu_decrease_indent2);
692
 
        GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_FORMAT_SENDTOVTE, send_selection_to_vte2);
693
 
 
694
 
        /* the build menu items are set if the build menus are created */
 
750
        /* Format and Commands share the menu bar submenus */
 
751
        /* Build menu items are set if the build menus are created */
695
752
}
696
753
 
697
754
 
740
797
}
741
798
 
742
799
 
 
800
gchar *keybindings_get_label(GeanyKeyBinding *kb)
 
801
{
 
802
        return utils_str_remove_chars(g_strdup(kb->label), "_");
 
803
}
 
804
 
 
805
 
743
806
static void fill_shortcut_labels_treeview(GtkWidget *tree)
744
807
{
745
808
        gsize g, i;
746
 
        gchar *shortcut;
747
809
        GeanyKeyBinding *kb;
748
810
        GeanyKeyGroup *group;
749
811
        GtkListStore *store;
766
828
 
767
829
                for (i = 0; i < group->count; i++)
768
830
                {
 
831
                        gchar *shortcut, *label;
 
832
 
769
833
                        kb = &group->keys[i];
 
834
                        label = keybindings_get_label(kb);
770
835
                        shortcut = gtk_accelerator_get_label(kb->key, kb->mods);
771
836
 
772
837
                        gtk_list_store_append(store, &iter);
773
 
                        gtk_list_store_set(store, &iter, 0, kb->label, 1, shortcut, 2, PANGO_WEIGHT_NORMAL, -1);
 
838
                        gtk_list_store_set(store, &iter, 0, label, 1, shortcut, 2, PANGO_WEIGHT_NORMAL, -1);
774
839
 
775
840
                        g_free(shortcut);
 
841
                        g_free(label);
776
842
                }
777
843
        }
778
844
 
786
852
        GtkWidget *dialog, *tree, *label, *swin, *vbox;
787
853
        GtkCellRenderer *text_renderer;
788
854
        GtkTreeViewColumn *column;
789
 
        gint height;
790
855
 
791
856
        dialog = gtk_dialog_new_with_buttons(_("Keyboard Shortcuts"), GTK_WINDOW(main_widgets.window),
792
857
                                GTK_DIALOG_DESTROY_WITH_PARENT,
796
861
        gtk_box_set_spacing(GTK_BOX(vbox), 6);
797
862
        gtk_widget_set_name(dialog, "GeanyDialog");
798
863
 
799
 
        height = GEANY_WINDOW_MINIMAL_HEIGHT;
800
 
        gtk_window_set_default_size(GTK_WINDOW(dialog), -1, height);
 
864
        gtk_window_set_default_size(GTK_WINDOW(dialog), -1, GEANY_DEFAULT_DIALOG_HEIGHT);
801
865
 
802
866
        gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_CANCEL);
803
867
 
904
968
}
905
969
 
906
970
 
907
 
/* We have a special case for GEANY_KEYS_EDIT_COMPLETESNIPPET, because we need to
908
 
 * return FALSE if no completion occurs, so the tab or space is handled normally. */
909
 
static gboolean check_snippet_completion(GeanyDocument *doc, guint keyval, guint state)
 
971
static gboolean check_snippet_completion(GeanyDocument *doc)
910
972
{
911
 
        GeanyKeyBinding *kb = keybindings_lookup_item(GEANY_KEY_GROUP_EDITOR,
912
 
                GEANY_KEYS_EDITOR_COMPLETESNIPPET);
 
973
        GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
913
974
 
914
975
        g_return_val_if_fail(doc, FALSE);
915
976
 
916
 
        if (kb->key == keyval && kb->mods == state)
 
977
        /* keybinding only valid when scintilla widget has focus */
 
978
        if (focusw == GTK_WIDGET(doc->editor->sci))
917
979
        {
918
 
                GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
919
 
 
920
 
                /* keybinding only valid when scintilla widget has focus */
921
 
                if (focusw == GTK_WIDGET(doc->editor->sci))
922
 
                {
923
 
                        ScintillaObject *sci = doc->editor->sci;
924
 
                        gint pos = sci_get_current_position(sci);
925
 
 
926
 
                        if (editor_prefs.complete_snippets)
927
 
                                return editor_complete_snippet(doc->editor, pos);
928
 
                }
 
980
                ScintillaObject *sci = doc->editor->sci;
 
981
                gint pos = sci_get_current_position(sci);
 
982
 
 
983
                if (editor_prefs.complete_snippets)
 
984
                        return editor_complete_snippet(doc->editor, pos);
929
985
        }
930
986
        return FALSE;
931
987
}
964
1020
        if ((keyval == GDK_Menu && state == 0) || (keyval == GDK_F10 && state == GDK_SHIFT_MASK))
965
1021
        {
966
1022
                GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
967
 
                static GtkWidget *scribble = NULL;
968
 
 
969
 
                if (scribble == NULL)
970
 
                        scribble = ui_lookup_widget(main_widgets.window, "textview_scribble");
971
 
 
972
1023
                if (doc != NULL)
973
1024
                {
974
1025
                        if (focusw == doc->priv->tag_tree)
994
1045
                 || focusw == msgwindow.tree_status
995
1046
                 || focusw == msgwindow.tree_compiler
996
1047
                 || focusw == msgwindow.tree_msg
997
 
                 || focusw == scribble
 
1048
                 || focusw == msgwindow.scribble
998
1049
#ifdef HAVE_VTE
999
1050
                 || (vte_info.have_vte && focusw == vc->vte)
1000
1051
#endif
1100
1151
}
1101
1152
 
1102
1153
 
 
1154
/* Stripped down version of the main keypress event handler which can be used
 
1155
 * to process foreign events. Instead of executing the keybinding, a pointer to the
 
1156
 * keybinding structure is returned.
 
1157
 * Additionally, the group_id and binding_id are filled with the appropriate indexes
 
1158
 * if non-NULL. */
 
1159
const GeanyKeyBinding *keybindings_check_event(GdkEventKey *ev, gint *group_id, gint *binding_id)
 
1160
{
 
1161
        guint state, keyval;
 
1162
        gsize g, i;
 
1163
        GeanyKeyGroup *group;
 
1164
        GeanyKeyBinding *kb;
 
1165
 
 
1166
        if (ev->keyval == 0)
 
1167
                return FALSE;
 
1168
 
 
1169
        keyval = ev->keyval;
 
1170
        state = ev->state & gtk_accelerator_get_default_mod_mask();
 
1171
        /* hack to get around that CTRL+Shift+r results in GDK_R not GDK_r */
 
1172
        if ((ev->state & GDK_SHIFT_MASK) || (ev->state & GDK_LOCK_MASK))
 
1173
                if (keyval >= GDK_A && keyval <= GDK_Z)
 
1174
                        keyval += GDK_a - GDK_A;
 
1175
 
 
1176
        if (keyval >= GDK_KP_Space && keyval < GDK_KP_Equal)
 
1177
                keyval = key_kp_translate(keyval);
 
1178
 
 
1179
        for (g = 0; g < keybinding_groups->len; g++)
 
1180
        {
 
1181
                group = g_ptr_array_index(keybinding_groups, g);
 
1182
 
 
1183
                for (i = 0; i < group->count; i++)
 
1184
                {
 
1185
                        kb = &group->keys[i];
 
1186
                        if (keyval == kb->key && state == kb->mods)
 
1187
                        {
 
1188
                                if (group_id != NULL)
 
1189
                                        *group_id = g;
 
1190
                                if (binding_id != NULL)
 
1191
                                        *binding_id = i;
 
1192
                                return kb;
 
1193
                        }
 
1194
                }
 
1195
        }
 
1196
        return NULL;
 
1197
}
 
1198
 
 
1199
 
1103
1200
/* central keypress event handler, almost all keypress events go to this function */
1104
1201
static gboolean on_key_press_event(GtkWidget *widget, GdkEventKey *ev, gpointer user_data)
1105
1202
{
1109
1206
        GeanyKeyGroup *group;
1110
1207
        GeanyKeyBinding *kb;
1111
1208
 
1112
 
        if (G_UNLIKELY(ev->keyval == 0))
 
1209
        if (ev->keyval == 0)
1113
1210
                return FALSE;
1114
1211
 
1115
1212
        doc = document_get_current();
1117
1214
                document_check_disk_status(doc, FALSE);
1118
1215
 
1119
1216
        keyval = ev->keyval;
1120
 
    state = ev->state & gtk_accelerator_get_default_mod_mask();
1121
 
 
 
1217
        state = ev->state & gtk_accelerator_get_default_mod_mask();
1122
1218
        /* hack to get around that CTRL+Shift+r results in GDK_R not GDK_r */
1123
1219
        if ((ev->state & GDK_SHIFT_MASK) || (ev->state & GDK_LOCK_MASK))
1124
1220
                if (keyval >= GDK_A && keyval <= GDK_Z)
1134
1230
        if (vte_info.have_vte && check_vte(state, keyval))
1135
1231
                return FALSE;
1136
1232
#endif
1137
 
        if (doc && check_snippet_completion(doc, keyval, state))
1138
 
                return TRUE;
1139
1233
        if (check_menu_key(doc, keyval, state, ev->time))
1140
1234
                return TRUE;
1141
1235
 
1142
 
        ignore_keybinding = FALSE;
1143
1236
        for (g = 0; g < keybinding_groups->len; g++)
1144
1237
        {
1145
1238
                group = g_ptr_array_index(keybinding_groups, g);
1149
1242
                        kb = &group->keys[i];
1150
1243
                        if (keyval == kb->key && state == kb->mods)
1151
1244
                        {
1152
 
                                if (G_UNLIKELY(kb->callback == NULL))
1153
 
                                        return FALSE;   /* ignore the keybinding */
1154
 
 
1155
1245
                                /* call the corresponding callback function for this shortcut */
1156
 
                                kb->callback(i);
1157
 
                                return !ignore_keybinding;
 
1246
                                if (kb->callback)
 
1247
                                {
 
1248
                                        kb->callback(i);
 
1249
                                        return TRUE;
 
1250
                                }
 
1251
                                else if (group->callback)
 
1252
                                {
 
1253
                                        if (group->callback(i))
 
1254
                                                return TRUE;
 
1255
                                        else
 
1256
                                                continue;       /* not handled */
 
1257
                                }
 
1258
                                g_warning("No callback for keybinding %s: %s!", group->name, kb->name);
1158
1259
                        }
1159
1260
                }
1160
1261
        }
1203
1304
}
1204
1305
 
1205
1306
 
1206
 
/** Mimic a (built-in only) keybinding action.
 
1307
/** Mimics a (built-in only) keybinding action.
1207
1308
 *      Example: @code keybindings_send_command(GEANY_KEY_GROUP_FILE, GEANY_KEYS_FILE_OPEN); @endcode
1208
1309
 *      @param group_id The index for the key group that contains the @a key_id keybinding.
1209
1310
 *      @param key_id The keybinding command index. */
1215
1316
 
1216
1317
        kb = keybindings_lookup_item(group_id, key_id);
1217
1318
        if (kb)
1218
 
                kb->callback(key_id);
 
1319
        {
 
1320
                if (kb->callback)
 
1321
                        kb->callback(key_id);
 
1322
                else
 
1323
                {
 
1324
                        GeanyKeyGroup *group = g_ptr_array_index(keybinding_groups, group_id);
 
1325
 
 
1326
                        if (group->callback)
 
1327
                                group->callback(key_id);
 
1328
                }
 
1329
        }
1219
1330
}
1220
1331
 
1221
1332
 
1223
1334
 * own function. */
1224
1335
 
1225
1336
 
1226
 
static void cb_func_file_action(guint key_id)
 
1337
static gboolean cb_func_file_action(guint key_id)
1227
1338
{
1228
1339
        switch (key_id)
1229
1340
        {
1236
1347
                case GEANY_KEYS_FILE_OPENSELECTED:
1237
1348
                        on_menu_open_selected_file1_activate(NULL, NULL);
1238
1349
                        break;
 
1350
                case GEANY_KEYS_FILE_OPENLASTTAB:
 
1351
                {
 
1352
                        gchar *utf8_filename = g_queue_peek_head(ui_prefs.recent_queue);
 
1353
                        gchar *locale_filename = utils_get_locale_from_utf8(utf8_filename);
 
1354
                        document_open_file(locale_filename, FALSE, NULL, NULL);
 
1355
                        g_free(locale_filename);
 
1356
                        break;
 
1357
                }
1239
1358
                case GEANY_KEYS_FILE_SAVE:
1240
1359
                        on_save1_activate(NULL, NULL);
1241
1360
                        break;
1258
1377
                        on_print1_activate(NULL, NULL);
1259
1378
                        break;
1260
1379
        }
 
1380
        return TRUE;
1261
1381
}
1262
1382
 
1263
1383
 
1264
 
static void cb_func_project_action(guint key_id)
 
1384
static gboolean cb_func_project_action(guint key_id)
1265
1385
{
1266
1386
        switch (key_id)
1267
1387
        {
1270
1390
                                on_project_properties1_activate(NULL, NULL);
1271
1391
                        break;
1272
1392
        }
 
1393
        return TRUE;
1273
1394
}
1274
1395
 
1275
1396
 
1276
 
static void cb_func_menu_preferences(G_GNUC_UNUSED guint key_id)
 
1397
static void cb_func_menu_preferences(guint key_id)
1277
1398
{
1278
 
        on_preferences1_activate(NULL, NULL);
 
1399
        switch (key_id)
 
1400
        {
 
1401
                case GEANY_KEYS_SETTINGS_PREFERENCES:
 
1402
                        on_preferences1_activate(NULL, NULL);
 
1403
                        break;
 
1404
                case GEANY_KEYS_SETTINGS_PLUGINPREFERENCES:
 
1405
                        on_plugin_preferences1_activate(NULL, NULL);
 
1406
                        break;
 
1407
        }
1279
1408
}
1280
1409
 
 
1410
 
1281
1411
static void cb_func_menu_help(G_GNUC_UNUSED guint key_id)
1282
1412
{
1283
1413
        on_help1_activate(NULL, NULL);
1284
1414
}
1285
1415
 
1286
 
static void cb_func_search_action(guint key_id)
 
1416
 
 
1417
static gboolean cb_func_search_action(guint key_id)
1287
1418
{
1288
1419
        GeanyDocument *doc = document_get_current();
1289
1420
        ScintillaObject *sci;
1290
1421
 
 
1422
        if (key_id == GEANY_KEYS_SEARCH_FINDINFILES)
 
1423
        {
 
1424
                on_find_in_files1_activate(NULL, NULL); /* works without docs too */
 
1425
                return TRUE;
 
1426
        }
1291
1427
        if (!doc)
1292
 
                return;
 
1428
                return TRUE;
1293
1429
        sci = doc->editor->sci;
1294
1430
 
1295
1431
        switch (key_id)
1306
1442
                        on_find_nextsel1_activate(NULL, NULL); break;
1307
1443
                case GEANY_KEYS_SEARCH_REPLACE:
1308
1444
                        on_replace1_activate(NULL, NULL); break;
1309
 
                case GEANY_KEYS_SEARCH_FINDINFILES:
1310
 
                        on_find_in_files1_activate(NULL, NULL); break;
1311
1445
                case GEANY_KEYS_SEARCH_NEXTMESSAGE:
1312
1446
                        on_next_message1_activate(NULL, NULL); break;
1313
1447
                case GEANY_KEYS_SEARCH_PREVIOUSMESSAGE:
1321
1455
                        on_find_document_usage1_activate(NULL, NULL);
1322
1456
                        break;
1323
1457
                case GEANY_KEYS_SEARCH_MARKALL:
 
1458
                {
 
1459
                        gchar *text = get_current_word_or_sel(doc);
 
1460
 
1324
1461
                        if (sci_has_selection(sci))
1325
 
                        {
1326
 
                                gchar *text = sci_get_selection_contents(sci);
1327
 
 
1328
1462
                                search_mark_all(doc, text, SCFIND_MATCHCASE);
1329
 
                                g_free(text);
1330
 
                        }
1331
1463
                        else
1332
1464
                        {
1333
 
                                read_current_word(doc);
1334
 
                                search_mark_all(doc, editor_info.current_word, SCFIND_MATCHCASE | SCFIND_WHOLEWORD);
 
1465
                                /* clears markers if text is null */
 
1466
                                search_mark_all(doc, text, SCFIND_MATCHCASE | SCFIND_WHOLEWORD);
1335
1467
                        }
 
1468
                        g_free(text);
1336
1469
                        break;
 
1470
                }
1337
1471
        }
 
1472
        return TRUE;
1338
1473
}
1339
1474
 
 
1475
 
1340
1476
static void cb_func_menu_opencolorchooser(G_GNUC_UNUSED guint key_id)
1341
1477
{
1342
1478
        on_show_color_chooser1_activate(NULL, NULL);
1343
1479
}
1344
1480
 
1345
1481
 
1346
 
static void cb_func_view_action(guint key_id)
 
1482
static gboolean cb_func_view_action(guint key_id)
1347
1483
{
1348
1484
        switch (key_id)
1349
1485
        {
1359
1495
                case GEANY_KEYS_VIEW_ZOOMOUT:
1360
1496
                        on_zoom_out1_activate(NULL, NULL);
1361
1497
                        break;
 
1498
                case GEANY_KEYS_VIEW_ZOOMRESET:
 
1499
                        on_normal_size1_activate(NULL, NULL);
 
1500
                        break;
1362
1501
                default:
1363
1502
                        break;
1364
1503
        }
 
1504
        return TRUE;
1365
1505
}
1366
1506
 
1367
1507
 
1373
1513
        gtk_check_menu_item_set_active(c, ! gtk_check_menu_item_get_active(c));
1374
1514
}
1375
1515
 
 
1516
 
1376
1517
static void cb_func_menu_messagewindow(G_GNUC_UNUSED guint key_id)
1377
1518
{
1378
1519
        GtkCheckMenuItem *c = GTK_CHECK_MENU_ITEM(
1382
1523
}
1383
1524
 
1384
1525
 
1385
 
static void cb_func_build_action(guint key_id)
 
1526
static gboolean cb_func_build_action(guint key_id)
1386
1527
{
1387
1528
        GtkWidget *item;
1388
1529
        BuildMenuItems *menu_items;
1389
 
 
1390
1530
        GeanyDocument *doc = document_get_current();
 
1531
 
1391
1532
        if (doc == NULL)
1392
 
                return;
 
1533
                return TRUE;
1393
1534
 
1394
1535
        if (!GTK_WIDGET_IS_SENSITIVE(ui_lookup_widget(main_widgets.window, "menu_build1")))
1395
 
                return;
 
1536
                return TRUE;
 
1537
 
1396
1538
        menu_items = build_get_menu_items(doc->file_type->id);
1397
 
 
 
1539
/* TODO make it a table??*/
1398
1540
        switch (key_id)
1399
1541
        {
1400
1542
                case GEANY_KEYS_BUILD_COMPILE:
1401
 
                        item = menu_items->item_compile;
 
1543
                        item = menu_items->menu_item[GEANY_GBG_FT][GBO_TO_CMD(GEANY_GBO_COMPILE)];
1402
1544
                        break;
1403
1545
                case GEANY_KEYS_BUILD_LINK:
1404
 
                        item = menu_items->item_link;
 
1546
                        item = menu_items->menu_item[GEANY_GBG_FT][GBO_TO_CMD(GEANY_GBO_BUILD)];
1405
1547
                        break;
1406
1548
                case GEANY_KEYS_BUILD_MAKE:
1407
 
                        item = menu_items->item_make_all;
 
1549
                        item = menu_items->menu_item[GEANY_GBG_NON_FT][GBO_TO_CMD(GEANY_GBO_MAKE_ALL)];
1408
1550
                        break;
1409
1551
                case GEANY_KEYS_BUILD_MAKEOWNTARGET:
1410
 
                        item = menu_items->item_make_custom;
 
1552
                        item = menu_items->menu_item[GEANY_GBG_NON_FT][GBO_TO_CMD(GEANY_GBO_CUSTOM)];
1411
1553
                        break;
1412
1554
                case GEANY_KEYS_BUILD_MAKEOBJECT:
1413
 
                        item = menu_items->item_make_object;
 
1555
                        item = menu_items->menu_item[GEANY_GBG_NON_FT][GBO_TO_CMD(GEANY_GBO_MAKE_OBJECT)];
1414
1556
                        break;
1415
1557
                case GEANY_KEYS_BUILD_NEXTERROR:
1416
 
                        item = menu_items->item_next_error;
 
1558
                        item = menu_items->menu_item[GBG_FIXED][GBF_NEXT_ERROR];
1417
1559
                        break;
1418
1560
                case GEANY_KEYS_BUILD_PREVIOUSERROR:
1419
 
                        item = menu_items->item_previous_error;
 
1561
                        item = menu_items->menu_item[GBG_FIXED][GBF_PREV_ERROR];
1420
1562
                        break;
1421
1563
                case GEANY_KEYS_BUILD_RUN:
1422
 
                        item = menu_items->item_exec;
1423
 
                        break;
1424
 
                case GEANY_KEYS_BUILD_RUN2:
1425
 
                        item = menu_items->item_exec2;
 
1564
                        item = menu_items->menu_item[GEANY_GBG_EXEC][GBO_TO_CMD(GEANY_GBO_EXEC)];
1426
1565
                        break;
1427
1566
                case GEANY_KEYS_BUILD_OPTIONS:
1428
 
                        item = menu_items->item_set_args;
 
1567
                        item = menu_items->menu_item[GBG_FIXED][GBF_COMMANDS];
1429
1568
                        break;
1430
1569
                default:
1431
1570
                        item = NULL;
1435
1574
         * they are redrawn. */
1436
1575
        if (item && GTK_WIDGET_IS_SENSITIVE(item))
1437
1576
                gtk_menu_item_activate(GTK_MENU_ITEM(item));
 
1577
        return TRUE;
1438
1578
}
1439
1579
 
1440
1580
 
1465
1605
}
1466
1606
 
1467
1607
 
 
1608
static gchar *get_current_word_or_sel(GeanyDocument *doc)
 
1609
{
 
1610
        ScintillaObject *sci = doc->editor->sci;
 
1611
 
 
1612
        if (sci_has_selection(sci))
 
1613
                return sci_get_selection_contents(sci);
 
1614
 
 
1615
        return read_current_word(doc) ? g_strdup(editor_info.current_word) : NULL;
 
1616
}
 
1617
 
 
1618
 
1468
1619
static void focus_sidebar(void)
1469
1620
{
1470
1621
        if (ui_prefs.sidebar_visible)
1478
1629
}
1479
1630
 
1480
1631
 
1481
 
static void cb_func_switch_action(guint key_id)
 
1632
static void focus_msgwindow(void)
 
1633
{
 
1634
        if (ui_prefs.msgwindow_visible)
 
1635
        {
 
1636
                gint page_num = gtk_notebook_get_current_page(GTK_NOTEBOOK(msgwindow.notebook));
 
1637
                GtkWidget *page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(msgwindow.notebook), page_num);
 
1638
 
 
1639
                gtk_widget_grab_focus(gtk_bin_get_child(GTK_BIN(page)));
 
1640
        }
 
1641
}
 
1642
 
 
1643
 
 
1644
static gboolean cb_func_switch_action(guint key_id)
1482
1645
{
1483
1646
        switch (key_id)
1484
1647
        {
1486
1649
                {
1487
1650
                        GeanyDocument *doc = document_get_current();
1488
1651
                        if (doc != NULL)
1489
 
                                gtk_widget_grab_focus(GTK_WIDGET(doc->editor->sci));
 
1652
                        {
 
1653
                                GtkWidget *sci = GTK_WIDGET(doc->editor->sci);
 
1654
                                if (GTK_WIDGET_HAS_FOCUS(sci))
 
1655
                                        ui_update_statusbar(doc, -1);
 
1656
                                else
 
1657
                                        gtk_widget_grab_focus(sci);
 
1658
                        }
1490
1659
                        break;
1491
1660
                }
1492
1661
                case GEANY_KEYS_FOCUS_SCRIBBLE:
1509
1678
                case GEANY_KEYS_FOCUS_COMPILER:
1510
1679
                        msgwin_switch_tab(MSG_COMPILER, TRUE);
1511
1680
                        break;
 
1681
                case GEANY_KEYS_FOCUS_MESSAGES:
 
1682
                        msgwin_switch_tab(MSG_MESSAGE, TRUE);
 
1683
                        break;
 
1684
                case GEANY_KEYS_FOCUS_MESSAGE_WINDOW:
 
1685
                        focus_msgwindow();
 
1686
                        break;
 
1687
                case GEANY_KEYS_FOCUS_SIDEBAR_DOCUMENT_LIST:
 
1688
                        sidebar_focus_openfiles_tab();
 
1689
                        break;
 
1690
                case GEANY_KEYS_FOCUS_SIDEBAR_SYMBOL_LIST:
 
1691
                        sidebar_focus_symbols_tab();
 
1692
                        break;
1512
1693
        }
 
1694
        return TRUE;
1513
1695
}
1514
1696
 
1515
1697
 
1723
1905
static void goto_matching_brace(GeanyDocument *doc)
1724
1906
{
1725
1907
        gint pos, new_pos;
 
1908
        gint after_brace;
1726
1909
 
1727
1910
        if (doc == NULL)
1728
1911
                return;
1729
1912
 
1730
1913
        pos = sci_get_current_position(doc->editor->sci);
1731
 
        if (! utils_isbrace(sci_get_char_at(doc->editor->sci, pos), TRUE))
1732
 
                pos--; /* set pos to the brace */
 
1914
        after_brace = pos > 0 && utils_isbrace(sci_get_char_at(doc->editor->sci, pos - 1), TRUE);
 
1915
        pos -= after_brace;     /* set pos to the brace */
1733
1916
 
1734
1917
        new_pos = sci_find_matching_brace(doc->editor->sci, pos);
1735
1918
        if (new_pos != -1)
1736
 
        {       /* set the cursor at the brace */
1737
 
                sci_set_current_position(doc->editor->sci, new_pos, FALSE);
 
1919
        {       /* set the cursor at/after the brace */
 
1920
                sci_set_current_position(doc->editor->sci, new_pos + (!after_brace), FALSE);
1738
1921
                editor_display_current_line(doc->editor, 0.5F);
1739
1922
        }
1740
1923
}
1741
1924
 
1742
1925
 
1743
 
static void cb_func_clipboard(guint key_id)
 
1926
static gboolean cb_func_clipboard_action(guint key_id)
1744
1927
{
1745
1928
        GeanyDocument *doc = document_get_current();
1746
1929
 
1747
1930
        if (doc == NULL)
1748
 
                return;
 
1931
                return TRUE;
1749
1932
 
1750
1933
        switch (key_id)
1751
1934
        {
1765
1948
                        sci_send_command(doc->editor->sci, SCI_LINECUT);
1766
1949
                        break;
1767
1950
        }
 
1951
        return TRUE;
 
1952
}
 
1953
 
 
1954
 
 
1955
static void goto_tag(GeanyDocument *doc, gboolean definition)
 
1956
{
 
1957
        gchar *text = get_current_word_or_sel(doc);
 
1958
 
 
1959
        if (text)
 
1960
                symbols_goto_tag(text, definition);
 
1961
        else
 
1962
                utils_beep();
 
1963
 
 
1964
        g_free(text);
1768
1965
}
1769
1966
 
1770
1967
 
1771
1968
/* Common function for goto keybindings, useful even when sci doesn't have focus. */
1772
 
static void cb_func_goto_action(guint key_id)
 
1969
static gboolean cb_func_goto_action(guint key_id)
1773
1970
{
1774
1971
        gint cur_line;
1775
1972
        GeanyDocument *doc = document_get_current();
1776
1973
 
1777
1974
        if (doc == NULL)
1778
 
                return;
 
1975
                return TRUE;
1779
1976
 
1780
1977
        cur_line = sci_get_current_line(doc->editor->sci);
1781
1978
 
1783
1980
        {
1784
1981
                case GEANY_KEYS_GOTO_BACK:
1785
1982
                        navqueue_go_back();
1786
 
                        return;
 
1983
                        return TRUE;
1787
1984
                case GEANY_KEYS_GOTO_FORWARD:
1788
1985
                        navqueue_go_forward();
1789
 
                        return;
 
1986
                        return TRUE;
1790
1987
                case GEANY_KEYS_GOTO_LINE:
 
1988
                {
 
1989
                        if (toolbar_prefs.visible)
 
1990
                        {
 
1991
                                GtkWidget *wid = toolbar_get_widget_child_by_name("GotoEntry");
 
1992
 
 
1993
                                /* use toolbar item if shown */
 
1994
                                if (wid)
 
1995
                                {
 
1996
                                        gtk_widget_grab_focus(wid);
 
1997
                                        return TRUE;
 
1998
                                }
 
1999
                        }
1791
2000
                        on_go_to_line_activate(NULL, NULL);
1792
 
                        return;
 
2001
                        return TRUE;
 
2002
                }
1793
2003
                case GEANY_KEYS_GOTO_MATCHINGBRACE:
1794
2004
                        goto_matching_brace(doc);
1795
 
                        return;
 
2005
                        return TRUE;
1796
2006
                case GEANY_KEYS_GOTO_TOGGLEMARKER:
1797
2007
                {
1798
 
                        gboolean set = sci_is_marker_set_at_line(doc->editor->sci, cur_line, 1);
1799
 
 
1800
 
                        sci_set_marker_at_line(doc->editor->sci, cur_line, ! set, 1);
1801
 
                        return;
 
2008
                        sci_toggle_marker_at_line(doc->editor->sci, cur_line, 1);
 
2009
                        return TRUE;
1802
2010
                }
1803
2011
                case GEANY_KEYS_GOTO_NEXTMARKER:
1804
2012
                {
1809
2017
                                sci_set_current_line(doc->editor->sci, mline);
1810
2018
                                editor_display_current_line(doc->editor, 0.5F);
1811
2019
                        }
1812
 
                        return;
 
2020
                        return TRUE;
1813
2021
                }
1814
2022
                case GEANY_KEYS_GOTO_PREVIOUSMARKER:
1815
2023
                {
1820
2028
                                sci_set_current_line(doc->editor->sci, mline);
1821
2029
                                editor_display_current_line(doc->editor, 0.5F);
1822
2030
                        }
1823
 
                        return;
 
2031
                        return TRUE;
1824
2032
                }
1825
2033
                case GEANY_KEYS_GOTO_TAGDEFINITION:
1826
 
                        if (check_current_word(doc))
1827
 
                                symbols_goto_tag(editor_info.current_word, TRUE);
1828
 
                        return;
 
2034
                        goto_tag(doc, TRUE);
 
2035
                        return TRUE;
1829
2036
                case GEANY_KEYS_GOTO_TAGDECLARATION:
1830
 
                        if (check_current_word(doc))
1831
 
                                symbols_goto_tag(editor_info.current_word, FALSE);
1832
 
                        return;
 
2037
                        goto_tag(doc, FALSE);
 
2038
                        return TRUE;
1833
2039
        }
1834
 
        /* only check editor-sensitive keybindings when editor has focus */
 
2040
        /* only check editor-sensitive keybindings when editor has focus so home,end still
 
2041
         * work in other widgets */
1835
2042
        if (gtk_window_get_focus(GTK_WINDOW(main_widgets.window)) != GTK_WIDGET(doc->editor->sci))
1836
 
        {
1837
 
                ignore_keybinding = TRUE;
1838
 
                return;
1839
 
        }
 
2043
                return FALSE;
 
2044
 
1840
2045
        switch (key_id)
1841
2046
        {
1842
2047
                case GEANY_KEYS_GOTO_LINESTART:
1848
2053
                case GEANY_KEYS_GOTO_LINEENDVISUAL:
1849
2054
                        sci_send_command(doc->editor->sci, SCI_LINEENDDISPLAY);
1850
2055
                        break;
1851
 
                case GEANY_KEYS_GOTO_PREVWORDSTART:
 
2056
                case GEANY_KEYS_GOTO_PREVWORDPART:
1852
2057
                        sci_send_command(doc->editor->sci, SCI_WORDPARTLEFT);
1853
2058
                        break;
1854
 
                case GEANY_KEYS_GOTO_NEXTWORDSTART:
 
2059
                case GEANY_KEYS_GOTO_NEXTWORDPART:
1855
2060
                        sci_send_command(doc->editor->sci, SCI_WORDPARTRIGHT);
1856
2061
                        break;
1857
2062
        }
 
2063
        return TRUE;
1858
2064
}
1859
2065
 
1860
2066
 
1879
2085
}
1880
2086
 
1881
2087
 
 
2088
static void move_lines(GeanyEditor *editor, gboolean down)
 
2089
{
 
2090
        ScintillaObject *sci = editor->sci;
 
2091
        gchar *text;
 
2092
        gint pos, line, len;
 
2093
 
 
2094
        sci_start_undo_action(sci);
 
2095
        editor_select_lines(editor, FALSE);
 
2096
        len = sci_get_selected_text_length(sci);
 
2097
 
 
2098
        pos = sci_get_selection_start(sci);
 
2099
        line = sci_get_line_from_position(sci, pos);
 
2100
        if (down)
 
2101
                line++;
 
2102
        else
 
2103
                line--;
 
2104
 
 
2105
        text = sci_get_selection_contents(sci);
 
2106
        sci_clear(sci);
 
2107
 
 
2108
        pos = sci_get_position_from_line(sci, line);
 
2109
        sci_insert_text(sci, pos, text);
 
2110
        g_free(text);
 
2111
 
 
2112
        sci_set_current_position(sci, pos, TRUE);
 
2113
        sci_set_selection_end(sci, pos + len - 1);
 
2114
 
 
2115
        sci_end_undo_action(sci);
 
2116
}
 
2117
 
 
2118
 
1882
2119
/* common function for editor keybindings, only valid when scintilla has focus. */
1883
 
static void cb_func_editor_action(guint key_id)
 
2120
static gboolean cb_func_editor_action(guint key_id)
1884
2121
{
1885
2122
        GeanyDocument *doc = document_get_current();
1886
2123
        GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
1887
2124
 
1888
2125
        /* edit keybindings only valid when scintilla widget has focus */
1889
2126
        if (doc == NULL || focusw != GTK_WIDGET(doc->editor->sci))
1890
 
                return;
 
2127
                return FALSE; /* also makes tab work outside editor */
1891
2128
 
1892
2129
        switch (key_id)
1893
2130
        {
1910
2147
                        duplicate_lines(doc->editor);
1911
2148
                        break;
1912
2149
                case GEANY_KEYS_EDITOR_SNIPPETNEXTCURSOR:
1913
 
                        snippet_goto_next_cursor(doc->editor->sci,
1914
 
                                        sci_get_current_position(doc->editor->sci));
 
2150
                        editor_goto_next_snippet_cursor(doc->editor);
1915
2151
                        break;
1916
2152
                case GEANY_KEYS_EDITOR_DELETELINE:
1917
2153
                        delete_lines(doc->editor);
1936
2172
                                on_context_action1_activate(GTK_MENU_ITEM(ui_lookup_widget(main_widgets.editor_menu,
1937
2173
                                        "context_action1")), NULL);
1938
2174
                        break;
 
2175
                case GEANY_KEYS_EDITOR_COMPLETESNIPPET:
 
2176
                        /* allow tab to be overloaded */
 
2177
                        return check_snippet_completion(doc);
 
2178
 
1939
2179
                case GEANY_KEYS_EDITOR_SUPPRESSSNIPPETCOMPLETION:
1940
2180
                {
1941
2181
                        GeanyKeyBinding *kb = keybindings_lookup_item(GEANY_KEY_GROUP_EDITOR,
1954
2194
                        }
1955
2195
                        break;
1956
2196
                }
 
2197
                case GEANY_KEYS_EDITOR_WORDPARTCOMPLETION:
 
2198
                        return editor_complete_word_part(doc->editor);
 
2199
 
 
2200
                case GEANY_KEYS_EDITOR_MOVELINEUP:
 
2201
                        move_lines(doc->editor, FALSE);
 
2202
                        break;
 
2203
                case GEANY_KEYS_EDITOR_MOVELINEDOWN:
 
2204
                        move_lines(doc->editor, TRUE);
 
2205
                        break;
1957
2206
        }
 
2207
        return TRUE;
1958
2208
}
1959
2209
 
1960
2210
 
1979
2229
                editor_strip_line_trailing_spaces(editor, i);
1980
2230
 
1981
2231
        /* remove starting spaces from second and following lines due to the same reason */
1982
 
        for (i = start+1; i <= end; i++)
 
2232
        for (i = start + 1; i <= end; i++)
1983
2233
                sci_set_line_indentation(editor->sci, i, 0);
1984
2234
 
1985
2235
        /*
2010
2260
}
2011
2261
 
2012
2262
 
2013
 
static void split_lines(GeanyEditor *editor)
 
2263
static void split_lines(GeanyEditor *editor, gint column)
2014
2264
{
2015
 
        gint start, indent, linescount, i;
 
2265
        gint start, indent, linescount, i, end;
 
2266
        gchar c;
 
2267
        ScintillaObject *sci = editor->sci;
2016
2268
 
2017
 
        /* do nothing if long line marker is disabled */
2018
 
        if (editor_prefs.long_line_type == 2)
2019
 
                return;
 
2269
        /* don't include trailing newlines */
 
2270
        end = sci_get_selection_end(sci);
 
2271
        while ((c = sci_get_char_at(sci, end - 1)) == '\n' || c == '\r') end--;
 
2272
        sci_set_selection_end(sci, end);
2020
2273
 
2021
2274
        start = sci_get_line_from_position(editor->sci,
2022
2275
                sci_get_selection_start(editor->sci));
2031
2284
        /*
2032
2285
         * If this line is short enough, just return
2033
2286
         */
2034
 
        if (editor_prefs.long_line_column >
2035
 
                sci_get_line_end_position(editor->sci, start) -
 
2287
        if (column > sci_get_line_end_position(editor->sci, start) -
2036
2288
                sci_get_position_from_line(editor->sci, start))
2037
2289
        {
2038
2290
                return;
2062
2314
        sci_target_from_selection(editor->sci);
2063
2315
        linescount = sci_get_line_count(editor->sci);
2064
2316
        sci_lines_split(editor->sci,
2065
 
                (editor_prefs.long_line_column - indent) *
2066
 
                sci_text_width(editor->sci, STYLE_DEFAULT, " "));
 
2317
                (column - indent) *     sci_text_width(editor->sci, STYLE_DEFAULT, " "));
2067
2318
        linescount = sci_get_line_count(editor->sci) - linescount;
2068
2319
 
2069
2320
        /* Fix indentation. */
2070
2321
        for (i = start; i <= start + linescount; i++)
2071
2322
                sci_set_line_indentation(editor->sci, i, indent);
 
2323
 
 
2324
        /* Remove trailing spaces. */
 
2325
        if (editor_prefs.newline_strip || file_prefs.strip_trailing_spaces)
 
2326
        {
 
2327
                for (i = start; i <= start + linescount; i++)
 
2328
                        editor_strip_line_trailing_spaces(editor, i);
 
2329
        }
 
2330
}
 
2331
 
 
2332
 
 
2333
/* if cursor < anchor, swap them */
 
2334
static void sci_fix_selection(ScintillaObject *sci)
 
2335
{
 
2336
        gint start, end;
 
2337
 
 
2338
        start = sci_get_selection_start(sci);
 
2339
        end = sci_get_selection_end(sci);
 
2340
        sci_set_selection(sci, start, end);
2072
2341
}
2073
2342
 
2074
2343
 
2076
2345
{
2077
2346
        ScintillaObject *sci = editor->sci;
2078
2347
        gboolean sel;
 
2348
        gint column = -1;
2079
2349
 
 
2350
        if (editor->line_breaking)
 
2351
        {
 
2352
                /* use line break column if enabled */
 
2353
                column = editor_prefs.line_break_column;
 
2354
        }
 
2355
        else if (editor_get_long_line_type() != 2)
 
2356
        {
 
2357
                /* use long line if enabled */
 
2358
                column = editor_get_long_line_column();
 
2359
        }
 
2360
        else
 
2361
        {
 
2362
                /* do nothing if no column is defined */
 
2363
                utils_beep();
 
2364
                return;
 
2365
        }
2080
2366
        sci_start_undo_action(sci);
2081
2367
        sel = sci_has_selection(sci);
2082
2368
        if (!sel)
2094
2380
                        sci_set_selection_end(sci, pos);
2095
2381
                }
2096
2382
        }
2097
 
        split_lines(editor);
 
2383
        sci_fix_selection(sci);
 
2384
        split_lines(editor, column);
2098
2385
        if (!sel)
2099
2386
                sci_set_anchor(sci, -1);
 
2387
 
2100
2388
        sci_end_undo_action(sci);
2101
2389
}
2102
2390
 
2103
2391
 
2104
2392
/* common function for format keybindings, only valid when scintilla has focus. */
2105
 
static void cb_func_format_action(guint key_id)
 
2393
static gboolean cb_func_format_action(guint key_id)
2106
2394
{
2107
2395
        GeanyDocument *doc = document_get_current();
2108
2396
        GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
2109
2397
 
2110
2398
        /* keybindings only valid when scintilla widget has focus */
2111
2399
        if (doc == NULL || focusw != GTK_WIDGET(doc->editor->sci))
2112
 
                return;
 
2400
                return TRUE;
2113
2401
 
2114
2402
        switch (key_id)
2115
2403
        {
2159
2447
                        reflow_paragraph(doc->editor);
2160
2448
                        break;
2161
2449
        }
 
2450
        return TRUE;
2162
2451
}
2163
2452
 
2164
2453
 
2165
2454
/* common function for select keybindings, only valid when scintilla has focus. */
2166
 
static void cb_func_select_action(guint key_id)
 
2455
static gboolean cb_func_select_action(guint key_id)
2167
2456
{
2168
2457
        GeanyDocument *doc;
 
2458
        ScintillaObject *sci;
2169
2459
        GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
2170
 
        static GtkWidget *scribble_widget = NULL;
2171
2460
        GtkWidget *toolbar_search_entry = toolbar_get_widget_child_by_name("SearchEntry");
2172
2461
        GtkWidget *toolbar_goto_entry = toolbar_get_widget_child_by_name("GotoEntry");
2173
2462
 
2174
2463
        /* special case for Select All in the scribble widget */
2175
 
        if (scribble_widget == NULL) /* lookup the scribble widget only once */
2176
 
                scribble_widget = ui_lookup_widget(main_widgets.window, "textview_scribble");
2177
 
        if (key_id == GEANY_KEYS_SELECT_ALL && focusw == scribble_widget)
 
2464
        if (key_id == GEANY_KEYS_SELECT_ALL && focusw == msgwindow.scribble)
2178
2465
        {
2179
 
                g_signal_emit_by_name(scribble_widget, "select-all", TRUE);
2180
 
                return;
 
2466
                g_signal_emit_by_name(msgwindow.scribble, "select-all", TRUE);
 
2467
                return TRUE;
2181
2468
        }
2182
2469
        /* special case for Select All in the toolbar search widget */
2183
2470
        else if (key_id == GEANY_KEYS_SELECT_ALL && focusw == toolbar_search_entry)
2184
2471
        {
2185
2472
                gtk_editable_select_region(GTK_EDITABLE(toolbar_search_entry), 0, -1);
2186
 
                return;
 
2473
                return TRUE;
2187
2474
        }
2188
2475
        else if (key_id == GEANY_KEYS_SELECT_ALL && focusw == toolbar_goto_entry)
2189
2476
        {
2190
2477
                gtk_editable_select_region(GTK_EDITABLE(toolbar_goto_entry), 0, -1);
2191
 
                return;
 
2478
                return TRUE;
2192
2479
        }
2193
2480
 
2194
2481
        doc = document_get_current();
2195
2482
        /* keybindings only valid when scintilla widget has focus */
2196
2483
        if (doc == NULL || focusw != GTK_WIDGET(doc->editor->sci))
2197
 
                return;
 
2484
                return TRUE;
 
2485
        sci = doc->editor->sci;
2198
2486
 
2199
2487
        switch (key_id)
2200
2488
        {
2210
2498
                case GEANY_KEYS_SELECT_PARAGRAPH:
2211
2499
                        editor_select_paragraph(doc->editor);
2212
2500
                        break;
 
2501
                case GEANY_KEYS_SELECT_WORDPARTLEFT:
 
2502
                        sci_send_command(sci, SCI_WORDPARTLEFTEXTEND);
 
2503
                        break;
 
2504
                case GEANY_KEYS_SELECT_WORDPARTRIGHT:
 
2505
                        sci_send_command(sci, SCI_WORDPARTRIGHTEXTEND);
 
2506
                        break;
2213
2507
        }
 
2508
        return TRUE;
2214
2509
}
2215
2510
 
2216
2511
 
2217
 
static void cb_func_document_action(guint key_id)
 
2512
static gboolean cb_func_document_action(guint key_id)
2218
2513
{
2219
2514
        GeanyDocument *doc = document_get_current();
 
2515
 
2220
2516
        if (doc == NULL)
2221
 
                return;
 
2517
                return TRUE;
2222
2518
 
2223
2519
        switch (key_id)
2224
2520
        {
2252
2548
                                editor_toggle_fold(doc->editor, line, 0);
2253
2549
                                break;
2254
2550
                        }
 
2551
                case GEANY_KEYS_DOCUMENT_REMOVE_MARKERS:
 
2552
                        on_remove_markers1_activate(NULL, NULL);
 
2553
                        break;
 
2554
                case GEANY_KEYS_DOCUMENT_REMOVE_ERROR_INDICATORS:
 
2555
                        on_menu_remove_indicators1_activate(NULL, NULL);
 
2556
                        break;
2255
2557
        }
 
2558
        return TRUE;
2256
2559
}
2257
2560
 
2258
2561
 
2259
2562
/* common function for insert keybindings, only valid when scintilla has focus. */
2260
 
static void cb_func_insert_action(guint key_id)
 
2563
static gboolean cb_func_insert_action(guint key_id)
2261
2564
{
2262
2565
        GeanyDocument *doc = document_get_current();
2263
2566
        GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
2264
2567
 
2265
2568
        /* keybindings only valid when scintilla widget has focus */
2266
2569
        if (doc == NULL || focusw != GTK_WIDGET(doc->editor->sci))
2267
 
                return;
 
2570
                return TRUE;
2268
2571
 
2269
2572
        switch (key_id)
2270
2573
        {
2276
2579
                                ui_lookup_widget(main_widgets.window, "insert_date_custom1")));
2277
2580
                        break;
2278
2581
        }
 
2582
        return TRUE;
2279
2583
}
2280
2584
 
2281
2585
 
2295
2599
                        kb->key, kb->mods, GTK_ACCEL_VISIBLE);
2296
2600
}
2297
2601
 
 
2602
 
 
2603
/* used for plugins */
 
2604
GeanyKeyGroup *keybindings_set_group(GeanyKeyGroup *group, const gchar *section_name,
 
2605
                const gchar *label, gsize count, GeanyKeyGroupCallback callback)
 
2606
{
 
2607
        g_return_val_if_fail(section_name, NULL);
 
2608
        g_return_val_if_fail(count, NULL);
 
2609
 
 
2610
        /* prevent conflict with core bindings */
 
2611
        g_return_val_if_fail(!g_str_equal(section_name, keybindings_keyfile_group_name), NULL);
 
2612
 
 
2613
        if (!group)
 
2614
                group = g_new0(GeanyKeyGroup, 1);
 
2615
 
 
2616
        if (!group->keys || count > group->count)
 
2617
        {
 
2618
                /* allow resizing existing array of keys */
 
2619
                group->keys = g_renew(GeanyKeyBinding, group->keys, count);
 
2620
                memset(group->keys + group->count, 0, (count - group->count) * sizeof(GeanyKeyBinding));
 
2621
        }
 
2622
        group->plugin = TRUE;
 
2623
        add_kb_group(group, section_name, label, count, group->keys, callback);
 
2624
        return group;
 
2625
}
 
2626
 
 
2627
 
 
2628
/* used for plugins */
 
2629
void keybindings_free_group(GeanyKeyGroup *group)
 
2630
{
 
2631
        GeanyKeyBinding *kb;
 
2632
 
 
2633
        g_assert(group->plugin);
 
2634
 
 
2635
        foreach_c_array(kb, group->keys, group->count)
 
2636
        {
 
2637
                g_free(kb->name);
 
2638
                g_free(kb->label);
 
2639
        }
 
2640
        g_free(group->keys);
 
2641
        g_ptr_array_remove_fast(keybinding_groups, group);
 
2642
        g_free(group);
 
2643
}