/
keybindings.c
2026 lines (1699 loc) · 65.8 KB
/
keybindings.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* keybindings.c - this file is part of Geany, a fast and lightweight IDE
*
* Copyright 2006-2009 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
* Copyright 2006-2009 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $Id$
*/
/*
* Configurable keyboard shortcuts.
*/
#include <gdk/gdkkeysyms.h>
#include "geany.h"
#include "keybindings.h"
#include "support.h"
#include "utils.h"
#include "ui_utils.h"
#include "document.h"
#include "documentprivate.h"
#include "filetypes.h"
#include "callbacks.h"
#include "prefs.h"
#include "msgwindow.h"
#include "editor.h"
#include "sciwrappers.h"
#include "build.h"
#include "tools.h"
#include "navqueue.h"
#include "symbols.h"
#include "vte.h"
#include "toolbar.h"
#include "treeviews.h"
#include "geanywraplabel.h"
#include "main.h"
GPtrArray *keybinding_groups; /* array of GeanyKeyGroup pointers */
/* keyfile group name for non-plugin KB groups */
const gchar keybindings_keyfile_group_name[] = "Bindings";
static gboolean ignore_keybinding = FALSE;
static GtkAccelGroup *kb_accel_group = NULL;
static const gboolean swap_alt_tab_order = FALSE;
const gsize MAX_MRU_DOCS = 20;
static GQueue *mru_docs = NULL;
static gboolean switch_dialog_cancelled = TRUE;
static GtkWidget *switch_dialog = NULL;
static GtkWidget *switch_dialog_label = NULL;
/* central keypress event handler, almost all keypress events go to this function */
static gboolean on_key_press_event(GtkWidget *widget, GdkEventKey *event, gpointer user_data);
static gboolean on_key_release_event(GtkWidget *widget, GdkEventKey *event, gpointer user_data);
static gboolean check_current_word(GeanyDocument *doc);
static gboolean read_current_word(GeanyDocument *doc);
static void cb_func_file_action(guint key_id);
static void cb_func_project_action(guint key_id);
static void cb_func_editor_action(guint key_id);
static void cb_func_select_action(guint key_id);
static void cb_func_format_action(guint key_id);
static void cb_func_insert_action(guint key_id);
static void cb_func_search_action(guint key_id);
static void cb_func_goto_action(guint key_id);
static void cb_func_switch_action(guint key_id);
static void cb_func_clipboard(guint key_id);
static void cb_func_build_action(guint key_id);
static void cb_func_document_action(guint key_id);
static void cb_func_view_action(guint key_id);
/* note: new keybindings should normally use per group callbacks */
static void cb_func_menu_help(guint key_id);
static void cb_func_menu_preferences(guint key_id);
static void cb_func_menu_fullscreen(guint key_id);
static void cb_func_menu_messagewindow(guint key_id);
static void cb_func_menu_opencolorchooser(guint key_id);
static void cb_func_switch_tableft(guint key_id);
static void cb_func_switch_tabright(guint key_id);
static void cb_func_switch_tablastused(guint key_id);
static void cb_func_move_tab(guint key_id);
static void add_popup_menu_accels(void);
static void apply_kb_accel(GeanyKeyGroup *group, GeanyKeyBinding *kb, gpointer user_data);
/* This is used to set default keybindings on startup but at this point we don't want to
* assign the keybinding to the menu_item (apply_kb_accel) otherwise it can't be overridden
* by user keybindings anymore */
/** Simple convenience function to fill a GeanyKeyBinding struct item.
* @param group
* @param key_id
* @param callback
* @param key
* @param mod
* @param name
* @param label
* @param menu_item */
void keybindings_set_item(GeanyKeyGroup *group, gsize key_id,
GeanyKeyCallback callback, guint key, GdkModifierType mod,
gchar *name, gchar *label, GtkWidget *menu_item)
{
GeanyKeyBinding *kb;
g_assert(key_id < group->count);
kb = &group->keys[key_id];
kb->name = name;
kb->label = label;
kb->key = key;
kb->mods = mod;
kb->callback = callback;
kb->menu_item = menu_item;
}
static GeanyKeyGroup *add_kb_group(GeanyKeyGroup *group,
const gchar *name, const gchar *label, gsize count, GeanyKeyBinding *keys)
{
g_ptr_array_add(keybinding_groups, group);
group->name = name;
group->label = label;
group->count = count;
group->keys = keys;
return group;
}
/* Lookup a widget in the main window */
#define LW(widget_name) \
ui_lookup_widget(main_widgets.window, G_STRINGIFY(widget_name))
/* Expansion for group_id = FILE:
* static GeanyKeyBinding FILE_keys[GEANY_KEYS_FILE_COUNT]; */
#define DECLARE_KEYS(group_id) \
static GeanyKeyBinding group_id ## _keys[GEANY_KEYS_ ## group_id ## _COUNT]
/* Expansion for group_id = FILE:
* add_kb_group(&groups[GEANY_KEY_GROUP_FILE], NULL, _("File menu"),
* GEANY_KEYS_FILE_COUNT, FILE_keys); */
#define ADD_KB_GROUP(group_id, label) \
add_kb_group(&groups[GEANY_KEY_GROUP_ ## group_id], keybindings_keyfile_group_name, label, \
GEANY_KEYS_ ## group_id ## _COUNT, group_id ## _keys)
/* Init all fields of keys with default values.
* The menu_item field is always the main menu item, popup menu accelerators are
* set in add_popup_menu_accels(). */
static void init_default_kb(void)
{
static GeanyKeyGroup groups[GEANY_KEY_GROUP_COUNT];
GeanyKeyGroup *group;
DECLARE_KEYS(FILE);
DECLARE_KEYS(PROJECT);
DECLARE_KEYS(EDITOR);
DECLARE_KEYS(CLIPBOARD);
DECLARE_KEYS(SELECT);
DECLARE_KEYS(FORMAT);
DECLARE_KEYS(INSERT);
DECLARE_KEYS(SETTINGS);
DECLARE_KEYS(SEARCH);
DECLARE_KEYS(GOTO);
DECLARE_KEYS(VIEW);
DECLARE_KEYS(FOCUS);
DECLARE_KEYS(NOTEBOOK);
DECLARE_KEYS(DOCUMENT);
DECLARE_KEYS(BUILD);
DECLARE_KEYS(TOOLS);
DECLARE_KEYS(HELP);
group = ADD_KB_GROUP(FILE, _("File"));
keybindings_set_item(group, GEANY_KEYS_FILE_NEW, cb_func_file_action,
GDK_n, GDK_CONTROL_MASK, "menu_new", _("New"), NULL);
keybindings_set_item(group, GEANY_KEYS_FILE_OPEN, cb_func_file_action,
GDK_o, GDK_CONTROL_MASK, "menu_open", _("Open"), NULL);
keybindings_set_item(group, GEANY_KEYS_FILE_OPENSELECTED, cb_func_file_action,
GDK_o, GDK_SHIFT_MASK | GDK_CONTROL_MASK, "menu_open_selected",
_("Open selected file"), LW(menu_open_selected_file1));
keybindings_set_item(group, GEANY_KEYS_FILE_SAVE, cb_func_file_action,
GDK_s, GDK_CONTROL_MASK, "menu_save", _("Save"), NULL);
keybindings_set_item(group, GEANY_KEYS_FILE_SAVEAS, cb_func_file_action,
0, 0, "menu_saveas", _("Save as"), LW(menu_save_as1));
keybindings_set_item(group, GEANY_KEYS_FILE_SAVEALL, cb_func_file_action,
GDK_S, GDK_SHIFT_MASK | GDK_CONTROL_MASK, "menu_saveall", _("Save all"),
LW(menu_save_all1));
keybindings_set_item(group, GEANY_KEYS_FILE_PRINT, cb_func_file_action,
GDK_p, GDK_CONTROL_MASK, "menu_print", _("Print"), LW(print1));
keybindings_set_item(group, GEANY_KEYS_FILE_CLOSE, cb_func_file_action,
GDK_w, GDK_CONTROL_MASK, "menu_close", _("Close"), LW(menu_close1));
keybindings_set_item(group, GEANY_KEYS_FILE_CLOSEALL, cb_func_file_action,
GDK_w, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "menu_closeall", _("Close all"),
LW(menu_close_all1));
keybindings_set_item(group, GEANY_KEYS_FILE_RELOAD, cb_func_file_action,
GDK_r, GDK_CONTROL_MASK, "menu_reloadfile", _("Reload file"), LW(menu_reload1));
group = ADD_KB_GROUP(PROJECT, _("Project"));
keybindings_set_item(group, GEANY_KEYS_PROJECT_PROPERTIES, cb_func_project_action,
0, 0, "project_properties", _("Project properties"), LW(project_properties1));
group = ADD_KB_GROUP(EDITOR, _("Editor"));
keybindings_set_item(group, GEANY_KEYS_EDITOR_UNDO, cb_func_editor_action,
GDK_z, GDK_CONTROL_MASK, "menu_undo", _("Undo"), LW(menu_undo2));
keybindings_set_item(group, GEANY_KEYS_EDITOR_REDO, cb_func_editor_action,
GDK_y, GDK_CONTROL_MASK, "menu_redo", _("Redo"), LW(menu_redo2));
keybindings_set_item(group, GEANY_KEYS_EDITOR_DUPLICATELINE, cb_func_editor_action,
GDK_d, GDK_CONTROL_MASK, "edit_duplicateline", _("Duplicate line or selection"),
LW(menu_duplicate_line1));
keybindings_set_item(group, GEANY_KEYS_EDITOR_DELETELINE, cb_func_editor_action,
GDK_k, GDK_CONTROL_MASK, "edit_deleteline", _("Delete current line(s)"), NULL);
keybindings_set_item(group, GEANY_KEYS_EDITOR_TRANSPOSELINE, cb_func_editor_action,
GDK_t, GDK_CONTROL_MASK, "edit_transposeline", _("Transpose current line"), NULL);
keybindings_set_item(group, GEANY_KEYS_EDITOR_SCROLLTOLINE, cb_func_editor_action,
GDK_l, GDK_SHIFT_MASK | GDK_CONTROL_MASK, "edit_scrolltoline", _("Scroll to current line"), NULL);
keybindings_set_item(group, GEANY_KEYS_EDITOR_SCROLLLINEUP, cb_func_editor_action,
GDK_Up, GDK_MOD1_MASK, "edit_scrolllineup", _("Scroll up the view by one line"), NULL);
keybindings_set_item(group, GEANY_KEYS_EDITOR_SCROLLLINEDOWN, cb_func_editor_action,
GDK_Down, GDK_MOD1_MASK, "edit_scrolllinedown", _("Scroll down the view by one line"), NULL);
/* GEANY_KEYS_EDITOR_COMPLETESNIPPET is handled specially in check_snippet_completion() */
keybindings_set_item(group, GEANY_KEYS_EDITOR_COMPLETESNIPPET, NULL,
GDK_Tab, 0, "edit_completesnippet", _("Complete snippet"), NULL);
keybindings_set_item(group, GEANY_KEYS_EDITOR_SNIPPETNEXTCURSOR, cb_func_editor_action,
0, 0, "move_snippetnextcursor", _("Move cursor in snippet"), NULL);
keybindings_set_item(group, GEANY_KEYS_EDITOR_SUPPRESSSNIPPETCOMPLETION, cb_func_editor_action,
0, 0, "edit_suppresssnippetcompletion", _("Suppress snippet completion"), NULL);
keybindings_set_item(group, GEANY_KEYS_EDITOR_CONTEXTACTION, cb_func_editor_action,
0, 0, "popup_contextaction", _("Context Action"), NULL);
keybindings_set_item(group, GEANY_KEYS_EDITOR_AUTOCOMPLETE, cb_func_editor_action,
GDK_space, GDK_CONTROL_MASK, "edit_autocomplete", _("Complete word"), NULL);
keybindings_set_item(group, GEANY_KEYS_EDITOR_CALLTIP, cb_func_editor_action,
GDK_space, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "edit_calltip", _("Show calltip"), NULL);
keybindings_set_item(group, GEANY_KEYS_EDITOR_MACROLIST, cb_func_editor_action,
GDK_Return, GDK_CONTROL_MASK, "edit_macrolist", _("Show macro list"), NULL);
group = ADD_KB_GROUP(CLIPBOARD, _("Clipboard"));
keybindings_set_item(group, GEANY_KEYS_CLIPBOARD_CUT, cb_func_clipboard,
GDK_x, GDK_CONTROL_MASK, "menu_cut", _("Cut"), NULL);
keybindings_set_item(group, GEANY_KEYS_CLIPBOARD_COPY, cb_func_clipboard,
GDK_c, GDK_CONTROL_MASK, "menu_copy", _("Copy"), NULL);
keybindings_set_item(group, GEANY_KEYS_CLIPBOARD_PASTE, cb_func_clipboard,
GDK_v, GDK_CONTROL_MASK, "menu_paste", _("Paste"), NULL);
keybindings_set_item(group, GEANY_KEYS_CLIPBOARD_COPYLINE, cb_func_clipboard,
GDK_c, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "edit_copyline", _("Copy current line(s)"), NULL);
keybindings_set_item(group, GEANY_KEYS_CLIPBOARD_CUTLINE, cb_func_clipboard,
GDK_x, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "edit_cutline", _("Cut current line(s)"), NULL);
group = ADD_KB_GROUP(SELECT, _("Select"));
keybindings_set_item(group, GEANY_KEYS_SELECT_ALL, cb_func_select_action,
GDK_a, GDK_CONTROL_MASK, "menu_selectall", _("Select All"), LW(menu_select_all1));
keybindings_set_item(group, GEANY_KEYS_SELECT_WORD, cb_func_select_action,
GDK_w, GDK_SHIFT_MASK | GDK_MOD1_MASK, "edit_selectword", _("Select current word"), NULL);
keybindings_set_item(group, GEANY_KEYS_SELECT_LINE, cb_func_select_action,
GDK_l, GDK_SHIFT_MASK | GDK_MOD1_MASK, "edit_selectline", _("Select current line(s)"), NULL);
keybindings_set_item(group, GEANY_KEYS_SELECT_PARAGRAPH, cb_func_select_action,
GDK_p, GDK_SHIFT_MASK | GDK_MOD1_MASK, "edit_selectparagraph", _("Select current paragraph"), NULL);
group = ADD_KB_GROUP(FORMAT, _("Format"));
keybindings_set_item(group, GEANY_KEYS_FORMAT_TOGGLECASE, cb_func_format_action,
GDK_u, GDK_CONTROL_MASK | GDK_MOD1_MASK, "edit_togglecase",
_("Toggle Case of Selection"), LW(menu_toggle_case2));
keybindings_set_item(group, GEANY_KEYS_FORMAT_COMMENTLINETOGGLE, cb_func_format_action,
GDK_e, GDK_CONTROL_MASK, "edit_commentlinetoggle", _("Toggle line commentation"),
LW(menu_toggle_line_commentation1));
keybindings_set_item(group, GEANY_KEYS_FORMAT_COMMENTLINE, cb_func_format_action,
0, 0, "edit_commentline", _("Comment line(s)"), LW(menu_comment_line1));
keybindings_set_item(group, GEANY_KEYS_FORMAT_UNCOMMENTLINE, cb_func_format_action,
0, 0, "edit_uncommentline", _("Uncomment line(s)"), LW(menu_uncomment_line1));
keybindings_set_item(group, GEANY_KEYS_FORMAT_INCREASEINDENT, cb_func_format_action,
GDK_i, GDK_CONTROL_MASK, "edit_increaseindent", _("Increase indent"),
LW(menu_increase_indent1));
keybindings_set_item(group, GEANY_KEYS_FORMAT_DECREASEINDENT, cb_func_format_action,
GDK_u, GDK_CONTROL_MASK, "edit_decreaseindent", _("Decrease indent"),
LW(menu_decrease_indent1));
keybindings_set_item(group, GEANY_KEYS_FORMAT_INCREASEINDENTBYSPACE, cb_func_format_action,
0, 0, "edit_increaseindentbyspace", _("Increase indent by one space"), NULL);
keybindings_set_item(group, GEANY_KEYS_FORMAT_DECREASEINDENTBYSPACE, cb_func_format_action,
0, 0, "edit_decreaseindentbyspace", _("Decrease indent by one space"), NULL);
keybindings_set_item(group, GEANY_KEYS_FORMAT_AUTOINDENT, cb_func_format_action,
0, 0, "edit_autoindent", _("Smart line indent"), NULL);
keybindings_set_item(group, GEANY_KEYS_FORMAT_SENDTOCMD1, cb_func_format_action,
GDK_1, GDK_CONTROL_MASK, "edit_sendtocmd1", _("Send to Custom Command 1"), NULL);
keybindings_set_item(group, GEANY_KEYS_FORMAT_SENDTOCMD2, cb_func_format_action,
GDK_2, GDK_CONTROL_MASK, "edit_sendtocmd2", _("Send to Custom Command 2"), NULL);
keybindings_set_item(group, GEANY_KEYS_FORMAT_SENDTOCMD3, cb_func_format_action,
GDK_3, GDK_CONTROL_MASK, "edit_sendtocmd3", _("Send to Custom Command 3"), NULL);
keybindings_set_item(group, GEANY_KEYS_FORMAT_SENDTOVTE, cb_func_format_action,
0, 0, "edit_sendtovte", _("Send Selection to Terminal"), LW(send_selection_to_vte1));
group = ADD_KB_GROUP(INSERT, _("Insert"));
keybindings_set_item(group, GEANY_KEYS_INSERT_DATE, cb_func_insert_action,
GDK_d, GDK_SHIFT_MASK | GDK_MOD1_MASK, "menu_insert_date", _("Insert date"),
LW(insert_date_custom1));
keybindings_set_item(group, GEANY_KEYS_INSERT_ALTWHITESPACE, cb_func_insert_action,
0, 0, "edit_insertwhitespace", _("Insert alternative white space"), NULL);
group = ADD_KB_GROUP(SETTINGS, _("Settings"));
keybindings_set_item(group, GEANY_KEYS_SETTINGS_PREFERENCES, cb_func_menu_preferences,
GDK_p, GDK_CONTROL_MASK | GDK_MOD1_MASK, "menu_preferences", _("Preferences"),
LW(preferences1));
group = ADD_KB_GROUP(SEARCH, _("Search"));
keybindings_set_item(group, GEANY_KEYS_SEARCH_FIND, cb_func_search_action,
GDK_f, GDK_CONTROL_MASK, "menu_find", _("Find"), LW(find1));
keybindings_set_item(group, GEANY_KEYS_SEARCH_FINDNEXT, cb_func_search_action,
GDK_g, GDK_CONTROL_MASK, "menu_findnext", _("Find Next"), LW(find_next1));
keybindings_set_item(group, GEANY_KEYS_SEARCH_FINDPREVIOUS, cb_func_search_action,
GDK_g, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "menu_findprevious", _("Find Previous"),
LW(find_previous1));
keybindings_set_item(group, GEANY_KEYS_SEARCH_FINDNEXTSEL, cb_func_search_action,
0, 0, "menu_findnextsel", _("Find Next Selection"), LW(find_nextsel1));
keybindings_set_item(group, GEANY_KEYS_SEARCH_FINDPREVSEL, cb_func_search_action,
0, 0, "menu_findprevsel", _("Find Previous Selection"), LW(find_prevsel1));
keybindings_set_item(group, GEANY_KEYS_SEARCH_REPLACE, cb_func_search_action,
GDK_h, GDK_CONTROL_MASK, "menu_replace", _("Replace"), LW(replace1));
keybindings_set_item(group, GEANY_KEYS_SEARCH_FINDINFILES, cb_func_search_action, GDK_f,
GDK_CONTROL_MASK | GDK_SHIFT_MASK, "menu_findinfiles", _("Find in Files"),
LW(find_in_files1));
keybindings_set_item(group, GEANY_KEYS_SEARCH_NEXTMESSAGE, cb_func_search_action,
0, 0, "menu_nextmessage", _("Next Message"), LW(next_message1));
keybindings_set_item(group, GEANY_KEYS_SEARCH_PREVIOUSMESSAGE, cb_func_search_action,
0, 0, "menu_previousmessage", _("Previous Message"), LW(previous_message1));
keybindings_set_item(group, GEANY_KEYS_SEARCH_FINDUSAGE, cb_func_search_action,
0, 0, "popup_findusage", _("Find Usage"), NULL);
keybindings_set_item(group, GEANY_KEYS_SEARCH_FINDDOCUMENTUSAGE, cb_func_search_action,
0, 0, "popup_finddocumentusage", _("Find Document Usage"), NULL);
group = ADD_KB_GROUP(GOTO, _("Go to"));
keybindings_set_item(group, GEANY_KEYS_GOTO_BACK, cb_func_goto_action,
0, 0, "nav_back", _("Navigate back a location"), NULL);
keybindings_set_item(group, GEANY_KEYS_GOTO_FORWARD, cb_func_goto_action,
0, 0, "nav_forward", _("Navigate forward a location"), NULL);
keybindings_set_item(group, GEANY_KEYS_GOTO_LINE, cb_func_goto_action,
GDK_l, GDK_CONTROL_MASK, "menu_gotoline", _("Go to Line"), LW(go_to_line1));
keybindings_set_item(group, GEANY_KEYS_GOTO_MATCHINGBRACE, cb_func_goto_action,
GDK_b, GDK_CONTROL_MASK, "edit_gotomatchingbrace",
_("Go to matching brace"), NULL);
keybindings_set_item(group, GEANY_KEYS_GOTO_TOGGLEMARKER, cb_func_goto_action,
GDK_m, GDK_CONTROL_MASK, "edit_togglemarker",
_("Toggle marker"), NULL);
keybindings_set_item(group, GEANY_KEYS_GOTO_NEXTMARKER, cb_func_goto_action,
GDK_period, GDK_CONTROL_MASK, "edit_gotonextmarker",
_("Go to next marker"), NULL);
keybindings_set_item(group, GEANY_KEYS_GOTO_PREVIOUSMARKER, cb_func_goto_action,
GDK_comma, GDK_CONTROL_MASK, "edit_gotopreviousmarker",
_("Go to previous marker"), NULL);
keybindings_set_item(group, GEANY_KEYS_GOTO_TAGDEFINITION, cb_func_goto_action,
0, 0, "popup_gototagdefinition", _("Go to Tag Definition"), NULL);
keybindings_set_item(group, GEANY_KEYS_GOTO_TAGDECLARATION, cb_func_goto_action,
0, 0, "popup_gototagdeclaration", _("Go to Tag Declaration"), NULL);
keybindings_set_item(group, GEANY_KEYS_GOTO_LINESTART, cb_func_goto_action,
GDK_Home, 0, "edit_gotolinestart", _("Go to Start of Line"), NULL);
keybindings_set_item(group, GEANY_KEYS_GOTO_LINEEND, cb_func_goto_action,
GDK_End, 0, "edit_gotolineend", _("Go to End of Line"), NULL);
keybindings_set_item(group, GEANY_KEYS_GOTO_PREVWORDSTART, cb_func_goto_action,
GDK_slash, GDK_CONTROL_MASK, "edit_prevwordstart", _("Go to Previous Word Part"), NULL);
keybindings_set_item(group, GEANY_KEYS_GOTO_NEXTWORDSTART, cb_func_goto_action,
GDK_backslash, GDK_CONTROL_MASK, "edit_nextwordstart", _("Go to Next Word Part"), NULL);
group = ADD_KB_GROUP(VIEW, _("View"));
keybindings_set_item(group, GEANY_KEYS_VIEW_TOGGLEALL, cb_func_view_action,
0, 0, "menu_toggleall", _("Toggle All Additional Widgets"),
LW(menu_toggle_all_additional_widgets1));
keybindings_set_item(group, GEANY_KEYS_VIEW_FULLSCREEN, cb_func_menu_fullscreen,
GDK_F11, 0, "menu_fullscreen", _("Fullscreen"), LW(menu_fullscreen1));
keybindings_set_item(group, GEANY_KEYS_VIEW_MESSAGEWINDOW, cb_func_menu_messagewindow,
0, 0, "menu_messagewindow", _("Toggle Messages Window"),
LW(menu_show_messages_window1));
keybindings_set_item(group, GEANY_KEYS_VIEW_SIDEBAR, cb_func_view_action,
0, 0, "toggle_sidebar", _("Toggle Sidebar"), LW(menu_show_sidebar1));
keybindings_set_item(group, GEANY_KEYS_VIEW_ZOOMIN, cb_func_view_action,
GDK_plus, GDK_CONTROL_MASK, "menu_zoomin", _("Zoom In"), LW(menu_zoom_in1));
keybindings_set_item(group, GEANY_KEYS_VIEW_ZOOMOUT, cb_func_view_action,
GDK_minus, GDK_CONTROL_MASK, "menu_zoomout", _("Zoom Out"), LW(menu_zoom_out1));
group = ADD_KB_GROUP(FOCUS, _("Focus"));
keybindings_set_item(group, GEANY_KEYS_FOCUS_EDITOR, cb_func_switch_action,
GDK_F2, 0, "switch_editor", _("Switch to Editor"), NULL);
keybindings_set_item(group, GEANY_KEYS_FOCUS_SCRIBBLE, cb_func_switch_action,
GDK_F6, 0, "switch_scribble", _("Switch to Scribble"), NULL);
keybindings_set_item(group, GEANY_KEYS_FOCUS_VTE, cb_func_switch_action,
GDK_F4, 0, "switch_vte", _("Switch to VTE"), NULL);
keybindings_set_item(group, GEANY_KEYS_FOCUS_SEARCHBAR, cb_func_switch_action,
GDK_F7, 0, "switch_search_bar", _("Switch to Search Bar"), NULL);
keybindings_set_item(group, GEANY_KEYS_FOCUS_SIDEBAR, cb_func_switch_action,
0, 0, "switch_sidebar", _("Switch to Sidebar"), NULL);
keybindings_set_item(group, GEANY_KEYS_FOCUS_COMPILER, cb_func_switch_action,
0, 0, "switch_compiler", _("Switch to Compiler"), NULL);
group = ADD_KB_GROUP(NOTEBOOK, _("Notebook tab"));
keybindings_set_item(group, GEANY_KEYS_NOTEBOOK_SWITCHTABLEFT, cb_func_switch_tableft,
GDK_Page_Up, GDK_CONTROL_MASK, "switch_tableft", _("Switch to left document"), NULL);
keybindings_set_item(group, GEANY_KEYS_NOTEBOOK_SWITCHTABRIGHT, cb_func_switch_tabright,
GDK_Page_Down, GDK_CONTROL_MASK, "switch_tabright", _("Switch to right document"), NULL);
keybindings_set_item(group, GEANY_KEYS_NOTEBOOK_SWITCHTABLASTUSED, cb_func_switch_tablastused,
GDK_Tab, GDK_CONTROL_MASK, "switch_tablastused", _("Switch to last used document"), NULL);
keybindings_set_item(group, GEANY_KEYS_NOTEBOOK_MOVETABLEFT, cb_func_move_tab,
GDK_Page_Up, GDK_MOD1_MASK, "move_tableft", _("Move document left"), NULL);
keybindings_set_item(group, GEANY_KEYS_NOTEBOOK_MOVETABRIGHT, cb_func_move_tab,
GDK_Page_Down, GDK_MOD1_MASK, "move_tabright", _("Move document right"), NULL);
keybindings_set_item(group, GEANY_KEYS_NOTEBOOK_MOVETABFIRST, cb_func_move_tab,
0, 0, "move_tabfirst", _("Move document first"), NULL);
keybindings_set_item(group, GEANY_KEYS_NOTEBOOK_MOVETABLAST, cb_func_move_tab,
0, 0, "move_tablast", _("Move document last"), NULL);
group = ADD_KB_GROUP(DOCUMENT, _("Document"));
keybindings_set_item(group, GEANY_KEYS_DOCUMENT_LINEWRAP, cb_func_document_action,
0, 0, "menu_linewrap", _("Toggle Line wrapping"), LW(menu_line_wrapping1));
keybindings_set_item(group, GEANY_KEYS_DOCUMENT_LINEBREAK, cb_func_document_action,
0, 0, "menu_linebreak", _("Toggle Line breaking"), LW(line_breaking1));
keybindings_set_item(group, GEANY_KEYS_DOCUMENT_REPLACETABS, cb_func_document_action,
0, 0, "menu_replacetabs", _("Replace tabs by space"), LW(menu_replace_tabs));
keybindings_set_item(group, GEANY_KEYS_DOCUMENT_REPLACESPACES, cb_func_document_action,
0, 0, "menu_replacespaces", _("Replace spaces by tabs"), LW(menu_replace_spaces));
keybindings_set_item(group, GEANY_KEYS_DOCUMENT_TOGGLEFOLD, cb_func_document_action,
0, 0, "menu_togglefold", _("Toggle current fold"), NULL);
keybindings_set_item(group, GEANY_KEYS_DOCUMENT_FOLDALL, cb_func_document_action,
0, 0, "menu_foldall", _("Fold all"), LW(menu_fold_all1));
keybindings_set_item(group, GEANY_KEYS_DOCUMENT_UNFOLDALL, cb_func_document_action,
0, 0, "menu_unfoldall", _("Unfold all"), LW(menu_unfold_all1));
keybindings_set_item(group, GEANY_KEYS_DOCUMENT_RELOADTAGLIST, cb_func_document_action,
GDK_r, GDK_SHIFT_MASK | GDK_CONTROL_MASK, "reloadtaglist", _("Reload symbol list"), NULL);
group = ADD_KB_GROUP(BUILD, _("Build"));
keybindings_set_item(group, GEANY_KEYS_BUILD_COMPILE, cb_func_build_action,
GDK_F8, 0, "build_compile", _("Compile"), NULL);
keybindings_set_item(group, GEANY_KEYS_BUILD_LINK, cb_func_build_action,
GDK_F9, 0, "build_link", _("Build"), NULL);
keybindings_set_item(group, GEANY_KEYS_BUILD_MAKE, cb_func_build_action,
GDK_F9, GDK_SHIFT_MASK, "build_make", _("Make all"), NULL);
keybindings_set_item(group, GEANY_KEYS_BUILD_MAKEOWNTARGET, cb_func_build_action,
GDK_F9, GDK_SHIFT_MASK | GDK_CONTROL_MASK, "build_makeowntarget",
_("Make custom target"), NULL);
keybindings_set_item(group, GEANY_KEYS_BUILD_MAKEOBJECT, cb_func_build_action,
0, 0, "build_makeobject", _("Make object"), NULL);
keybindings_set_item(group, GEANY_KEYS_BUILD_NEXTERROR, cb_func_build_action,
0, 0, "build_nexterror", _("Next error"), NULL);
keybindings_set_item(group, GEANY_KEYS_BUILD_PREVIOUSERROR, cb_func_build_action,
0, 0, "build_previouserror", _("Previous error"), NULL);
keybindings_set_item(group, GEANY_KEYS_BUILD_RUN, cb_func_build_action,
GDK_F5, 0, "build_run", _("Run"), NULL);
keybindings_set_item(group, GEANY_KEYS_BUILD_RUN2, cb_func_build_action,
0, 0, "build_run2", _("Run (alternative command)"), NULL);
keybindings_set_item(group, GEANY_KEYS_BUILD_OPTIONS, cb_func_build_action,
0, 0, "build_options", _("Build options"), NULL);
group = ADD_KB_GROUP(TOOLS, _("Tools"));
keybindings_set_item(group, GEANY_KEYS_TOOLS_OPENCOLORCHOOSER, cb_func_menu_opencolorchooser,
0, 0, "menu_opencolorchooser", _("Show Color Chooser"), LW(menu_choose_color1));
group = ADD_KB_GROUP(HELP, _("Help"));
keybindings_set_item(group, GEANY_KEYS_HELP_HELP, cb_func_menu_help,
GDK_F1, 0, "menu_help", _("Help"), LW(help1));
}
/* before the tab changes, add the current document to the MRU list */
static void on_notebook_switch_page(void)
{
GeanyDocument *old = document_get_current();
/* when closing current doc, old is NULL */
if (old)
{
g_queue_push_head(mru_docs, old);
if (g_queue_get_length(mru_docs) > MAX_MRU_DOCS)
g_queue_pop_tail(mru_docs);
}
}
/* really this should be just after a document was closed, not idle */
static gboolean on_idle_close(gpointer data)
{
GeanyDocument *current;
current = document_get_current();
while (current && g_queue_peek_head(mru_docs) == current)
g_queue_pop_head(mru_docs);
return FALSE;
}
static void on_document_close(GObject *obj, GeanyDocument *doc)
{
if (! main_status.quitting)
{
g_queue_remove_all(mru_docs, doc);
g_idle_add(on_idle_close, NULL);
}
}
void keybindings_init(void)
{
mru_docs = g_queue_new();
g_signal_connect(main_widgets.notebook, "switch-page",
G_CALLBACK(on_notebook_switch_page), NULL);
g_signal_connect(geany_object, "document-close",
G_CALLBACK(on_document_close), NULL);
keybinding_groups = g_ptr_array_sized_new(GEANY_KEY_GROUP_COUNT);
kb_accel_group = gtk_accel_group_new();
init_default_kb();
gtk_window_add_accel_group(GTK_WINDOW(main_widgets.window), kb_accel_group);
g_signal_connect(main_widgets.window, "key-press-event", G_CALLBACK(on_key_press_event), NULL);
/* in case the switch dialog misses an event while drawing the dialog */
g_signal_connect(main_widgets.window, "key-release-event", G_CALLBACK(on_key_release_event), NULL);
}
static void apply_kb_accel(GeanyKeyGroup *group, GeanyKeyBinding *kb, gpointer user_data)
{
if (kb->key != 0 && kb->menu_item)
{
gtk_widget_add_accelerator(kb->menu_item, "activate", kb_accel_group,
kb->key, kb->mods, GTK_ACCEL_VISIBLE);
}
}
typedef void (*KBItemCallback) (GeanyKeyGroup *group, GeanyKeyBinding *kb, gpointer user_data);
static void keybindings_foreach(KBItemCallback cb, gpointer user_data)
{
gsize g, i;
GeanyKeyGroup *group;
GeanyKeyBinding *kb;
for (g = 0; g < keybinding_groups->len; g++)
{
group = g_ptr_array_index(keybinding_groups, g);
for (i = 0; i < group->count; i++)
{
kb = &group->keys[i];
cb(group, kb, user_data);
}
}
}
static void load_kb(GeanyKeyGroup *group, GeanyKeyBinding *kb, gpointer user_data)
{
GKeyFile *config = user_data;
gchar *val;
guint key;
GdkModifierType mods;
val = g_key_file_get_string(config, group->name, kb->name, NULL);
if (val != NULL)
{
gtk_accelerator_parse(val, &key, &mods);
kb->key = key;
kb->mods = mods;
g_free(val);
}
}
static void load_user_kb(void)
{
gchar *configfile = g_strconcat(app->configdir, G_DIR_SEPARATOR_S, "keybindings.conf", NULL);
GKeyFile *config = g_key_file_new();
/* now load user defined keys */
if (g_key_file_load_from_file(config, configfile, G_KEY_FILE_KEEP_COMMENTS, NULL))
{
keybindings_foreach(load_kb, config);
}
g_free(configfile);
g_key_file_free(config);
}
void keybindings_load_keyfile(void)
{
load_user_kb();
add_popup_menu_accels();
/* set menu accels now, after user keybindings have been read and processed
* if we would set it before, user keybindings could not override menu item's default
* keybindings */
keybindings_foreach(apply_kb_accel, NULL);
}
static void add_menu_accel(GeanyKeyGroup *group, guint kb_id,
GtkAccelGroup *accel_group, GtkWidget *menuitem)
{
GeanyKeyBinding *kb = &group->keys[kb_id];
if (kb->key != 0)
gtk_widget_add_accelerator(menuitem, "activate", accel_group,
kb->key, kb->mods, GTK_ACCEL_VISIBLE);
}
#define GEANY_ADD_POPUP_ACCEL(kb_id, wid) \
add_menu_accel(group, kb_id, accel_group, ui_lookup_widget(main_widgets.editor_menu, G_STRINGIFY(wid)))
/* set the menu item accelerator shortcuts (just for visibility, they are handled anyway) */
static void add_popup_menu_accels(void)
{
GtkAccelGroup *accel_group = gtk_accel_group_new();
GeanyKeyGroup *group;
group = g_ptr_array_index(keybinding_groups, GEANY_KEY_GROUP_EDITOR);
GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_EDITOR_UNDO, undo1);
GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_EDITOR_REDO, redo1);
GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_EDITOR_DUPLICATELINE, menu_duplicate_line2);
GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_EDITOR_CONTEXTACTION, context_action1);
group = g_ptr_array_index(keybinding_groups, GEANY_KEY_GROUP_SELECT);
GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_SELECT_ALL, menu_select_all2);
group = g_ptr_array_index(keybinding_groups, GEANY_KEY_GROUP_INSERT);
GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_INSERT_DATE, insert_date_custom2);
group = g_ptr_array_index(keybinding_groups, GEANY_KEY_GROUP_FILE);
GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_FILE_OPENSELECTED, menu_open_selected_file2);
group = g_ptr_array_index(keybinding_groups, GEANY_KEY_GROUP_SEARCH);
GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_SEARCH_FINDUSAGE, find_usage1);
GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_SEARCH_FINDDOCUMENTUSAGE, find_document_usage1);
group = g_ptr_array_index(keybinding_groups, GEANY_KEY_GROUP_GOTO);
GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_GOTO_LINE, go_to_line);
GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_GOTO_TAGDEFINITION, goto_tag_definition1);
GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_GOTO_TAGDECLARATION, goto_tag_declaration1);
group = g_ptr_array_index(keybinding_groups, GEANY_KEY_GROUP_FORMAT);
GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_FORMAT_TOGGLECASE, toggle_case1);
GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_FORMAT_COMMENTLINE, menu_comment_line2);
GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_FORMAT_UNCOMMENTLINE, menu_uncomment_line2);
GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_FORMAT_COMMENTLINETOGGLE, menu_toggle_line_commentation2);
GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_FORMAT_INCREASEINDENT, menu_increase_indent2);
GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_FORMAT_DECREASEINDENT, menu_decrease_indent2);
GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_FORMAT_SENDTOVTE, send_selection_to_vte2);
/* the build menu items are set if the build menus are created */
gtk_window_add_accel_group(GTK_WINDOW(main_widgets.window), accel_group);
}
static void set_keyfile_kb(GeanyKeyGroup *group, GeanyKeyBinding *kb, gpointer user_data)
{
GKeyFile *config = user_data;
gchar *val;
val = gtk_accelerator_name(kb->key, kb->mods);
g_key_file_set_string(config, group->name, kb->name, val);
g_free(val);
}
/* just write the content of the keys array to the config file */
void keybindings_write_to_file(void)
{
gchar *configfile = g_strconcat(app->configdir, G_DIR_SEPARATOR_S, "keybindings.conf", NULL);
gchar *data;
GKeyFile *config = g_key_file_new();
/* add comment if the file is newly created */
if (! g_key_file_load_from_file(config, configfile, G_KEY_FILE_KEEP_COMMENTS, NULL))
{
g_key_file_set_comment(config, NULL, NULL,
"Keybindings for Geany\nThe format looks like \"<Control>a\" or \"<Shift><Alt>F1\".\n"
"But you can also change the keys in Geany's preferences dialog.", NULL);
}
keybindings_foreach(set_keyfile_kb, config);
/* write the file */
data = g_key_file_to_data(config, NULL, NULL);
utils_write_file(configfile, data);
g_free(data);
g_free(configfile);
g_key_file_free(config);
}
void keybindings_free(void)
{
g_ptr_array_free(keybinding_groups, TRUE);
g_queue_free(mru_docs);
}
static void fill_shortcut_labels_treeview(GtkWidget *tree)
{
gsize g, i;
gchar *shortcut;
GeanyKeyBinding *kb;
GeanyKeyGroup *group;
GtkListStore *store;
GtkTreeIter iter;
store = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_STRING, PANGO_TYPE_WEIGHT);
for (g = 0; g < keybinding_groups->len; g++)
{
group = g_ptr_array_index(keybinding_groups, g);
if (g > 0)
{
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, -1);
}
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, 0, group->label, 2, PANGO_WEIGHT_BOLD, -1);
for (i = 0; i < group->count; i++)
{
kb = &group->keys[i];
shortcut = gtk_accelerator_get_label(kb->key, kb->mods);
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, 0, kb->label, 1, shortcut, 2, PANGO_WEIGHT_NORMAL, -1);
g_free(shortcut);
}
}
gtk_tree_view_set_model(GTK_TREE_VIEW(tree), GTK_TREE_MODEL(store));
g_object_unref(store);
}
static GtkWidget *create_dialog(void)
{
GtkWidget *dialog, *tree, *label, *swin, *vbox;
GtkCellRenderer *text_renderer;
GtkTreeViewColumn *column;
gint height;
dialog = gtk_dialog_new_with_buttons(_("Keyboard Shortcuts"), GTK_WINDOW(main_widgets.window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_STOCK_EDIT, GTK_RESPONSE_APPLY,
GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL, NULL);
vbox = ui_dialog_vbox_new(GTK_DIALOG(dialog));
gtk_box_set_spacing(GTK_BOX(vbox), 6);
gtk_widget_set_name(dialog, "GeanyDialog");
height = GEANY_WINDOW_MINIMAL_HEIGHT;
gtk_window_set_default_size(GTK_WINDOW(dialog), -1, height);
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_CANCEL);
label = gtk_label_new(_("The following keyboard shortcuts are configurable:"));
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
tree = gtk_tree_view_new();
gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(tree), TRUE);
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree), FALSE);
text_renderer = gtk_cell_renderer_text_new();
/* we can't use "weight-set", see http://bugzilla.gnome.org/show_bug.cgi?id=355214 */
column = gtk_tree_view_column_new_with_attributes(
NULL, text_renderer, "text", 0, "weight", 2, NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
text_renderer = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes(NULL, text_renderer, "text", 1, NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
fill_shortcut_labels_treeview(tree);
swin = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swin), GTK_POLICY_NEVER,
GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(swin), GTK_SHADOW_ETCHED_IN);
gtk_container_add(GTK_CONTAINER(swin), tree);
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 6);
gtk_box_pack_start(GTK_BOX(vbox), swin, TRUE, TRUE, 0);
return dialog;
}
/* non-modal keyboard shortcuts dialog, so user can edit whilst seeing the shortcuts */
static GtkWidget *key_dialog = NULL;
static void on_dialog_response(GtkWidget *dialog, gint response, gpointer user_data)
{
if (response == GTK_RESPONSE_APPLY)
{
GtkWidget *wid;
prefs_show_dialog();
/* select the KB page */
wid = ui_lookup_widget(ui_widgets.prefs_dialog, "frame22");
if (wid != NULL)
{
GtkNotebook *nb = GTK_NOTEBOOK(ui_lookup_widget(ui_widgets.prefs_dialog, "notebook2"));
if (nb != NULL)
gtk_notebook_set_current_page(nb, gtk_notebook_page_num(nb, wid));
}
}
gtk_widget_destroy(dialog);
key_dialog = NULL;
}
void keybindings_show_shortcuts(void)
{
if (key_dialog)
gtk_widget_destroy(key_dialog); /* in case the key_dialog is still visible */
key_dialog = create_dialog();
g_signal_connect(key_dialog, "response", G_CALLBACK(on_dialog_response), NULL);
gtk_widget_show_all(key_dialog);
}
static gboolean check_fixed_kb(guint keyval, guint state)
{
/* check alt-0 to alt-9 for setting current notebook page */
if (state & GDK_MOD1_MASK && keyval >= GDK_0 && keyval <= GDK_9)
{
gint page = keyval - GDK_0 - 1;
gint npages = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook));
/* alt-0 is for the rightmost tab */
if (keyval == GDK_0)
page = npages - 1;
/* invert the order if tabs are added on the other side */
if (swap_alt_tab_order && ! file_prefs.tab_order_ltr)
page = (npages - 1) - page;
gtk_notebook_set_current_page(GTK_NOTEBOOK(main_widgets.notebook), page);
return TRUE;
}
if (keyval == GDK_Page_Up || keyval == GDK_Page_Down)
{
/* switch to first or last document */
if (state == (GDK_CONTROL_MASK | GDK_SHIFT_MASK))
{
if (keyval == GDK_Page_Up)
gtk_notebook_set_current_page(GTK_NOTEBOOK(main_widgets.notebook), 0);
if (keyval == GDK_Page_Down)
gtk_notebook_set_current_page(GTK_NOTEBOOK(main_widgets.notebook),
gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)) - 1);
return TRUE;
}
}
return FALSE;
}
/* We have a special case for GEANY_KEYS_EDIT_COMPLETESNIPPET, because we need to
* return FALSE if no completion occurs, so the tab or space is handled normally. */
static gboolean check_snippet_completion(GeanyDocument *doc, guint keyval, guint state)
{
GeanyKeyBinding *kb = keybindings_lookup_item(GEANY_KEY_GROUP_EDITOR,
GEANY_KEYS_EDITOR_COMPLETESNIPPET);
if (kb->key == keyval && kb->mods == state)
{
GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
/* keybinding only valid when scintilla widget has focus */
if (doc != NULL && focusw == GTK_WIDGET(doc->editor->sci))
{
ScintillaObject *sci = doc->editor->sci;
gint pos = sci_get_current_position(sci);
if (editor_prefs.complete_snippets)
return editor_complete_snippet(doc->editor, pos);
}
}
return FALSE;
}
/* Transforms a GdkEventKey event into a GdkEventButton event */
static void trigger_button_event(GtkWidget *widget, guint32 event_time)
{
GdkEventButton *event;
gboolean ret;
event = g_new0(GdkEventButton, 1);
if (GTK_IS_TEXT_VIEW(widget))
event->window = gtk_text_view_get_window(GTK_TEXT_VIEW(widget), GTK_TEXT_WINDOW_TEXT);
else
event->window = widget->window;
event->time = event_time;
event->type = GDK_BUTTON_PRESS;
event->button = 3;
g_signal_emit_by_name(widget, "button-press-event", event, &ret);
g_signal_emit_by_name(widget, "button-release-event", event, &ret);
g_free(event);
}
/* Special case for the Menu key and Shift-F10 to show the right-click popup menu for various
* widgets. Without this special handling, the notebook tab list of the documents' notebook
* would be shown. As a very special case, we differentiate between the Menu key and Shift-F10
* if pressed in the editor widget: the Menu key opens the popup menu, Shift-F10 opens the
* notebook tab list. */
static gboolean check_menu_key(GeanyDocument *doc, guint keyval, guint state, guint32 event_time)
{
if ((keyval == GDK_Menu && state == 0) || (keyval == GDK_F10 && state == GDK_SHIFT_MASK))
{
GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
static GtkWidget *scribble = NULL;
if (scribble == NULL)
scribble = ui_lookup_widget(main_widgets.window, "textview_scribble");
if (doc != NULL)
{
if (focusw == doc->priv->tag_tree)
{
trigger_button_event(focusw, event_time);
return TRUE;
}
if (focusw == GTK_WIDGET(doc->editor->sci))
{
if (keyval == GDK_Menu)
{ /* show editor popup menu */
trigger_button_event(focusw, event_time);
return TRUE;
}
else
{ /* show tab bar menu */
trigger_button_event(main_widgets.notebook, event_time);
return TRUE;
}
}
}
if (focusw == tv.tree_openfiles
|| focusw == msgwindow.tree_status
|| focusw == msgwindow.tree_compiler
|| focusw == msgwindow.tree_msg
|| focusw == scribble
#ifdef HAVE_VTE
|| (vte_info.have_vte && focusw == vc->vte)
#endif
)
{
trigger_button_event(focusw, event_time);
return TRUE;
}
}