/
callbacks.c
2169 lines (1619 loc) · 54.6 KB
/
callbacks.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
/*
* callbacks.c - this file is part of Geany, a fast and lightweight IDE
*
* Copyright 2005-2012 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
* Copyright 2006-2012 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.
*/
/*
* Callbacks used by Glade. These are mainly in response to menu item and button events in the
* main window. Callbacks not used by Glade should go elsewhere.
*/
#include "geany.h"
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <gdk/gdkkeysyms.h>
#include <glib/gstdio.h>
#include <time.h>
#include "callbacks.h"
#include "support.h"
#include "keyfile.h"
#include "document.h"
#include "documentprivate.h"
#include "filetypes.h"
#include "sciwrappers.h"
#include "editor.h"
#include "ui_utils.h"
#include "utils.h"
#include "dialogs.h"
#include "about.h"
#include "msgwindow.h"
#include "build.h"
#include "prefs.h"
#include "templates.h"
#include "sidebar.h"
#include "keybindings.h"
#include "encodings.h"
#include "search.h"
#include "main.h"
#include "symbols.h"
#include "tools.h"
#include "project.h"
#include "navqueue.h"
#include "printing.h"
#include "plugins.h"
#include "log.h"
#include "toolbar.h"
#include "highlighting.h"
#include "pluginutils.h"
#ifdef HAVE_VTE
# include "vte.h"
#endif
#ifdef HAVE_SOCKET
# include "socket.h"
#endif
/* flag to indicate that an insert callback was triggered from the file menu,
* so we need to store the current cursor position in editor_info.click_pos. */
static gboolean insert_callback_from_menu = FALSE;
/* represents the state at switching a notebook page(in the left treeviews widget), to not emit
* the selection-changed signal from tv.tree_openfiles */
/*static gboolean switch_tv_notebook_page = FALSE; */
static gboolean check_no_unsaved(void)
{
guint i;
for (i = 0; i < documents_array->len; i++)
{
if (documents[i]->is_valid && documents[i]->changed)
{
return FALSE;
}
}
return TRUE; /* no unsaved edits */
}
/* set editor_info.click_pos to the current cursor position if insert_callback_from_menu is TRUE
* to prevent invalid cursor positions which can cause segfaults */
static void verify_click_pos(GeanyDocument *doc)
{
if (insert_callback_from_menu)
{
editor_info.click_pos = sci_get_current_position(doc->editor->sci);
insert_callback_from_menu = FALSE;
}
}
/* should only be called from on_exit_clicked */
static void quit_app(void)
{
configuration_save();
if (app->project != NULL)
project_close(FALSE); /* save project session files */
document_close_all();
main_status.quitting = TRUE;
main_quit();
}
/* wrapper function to abort exit process if cancel button is pressed */
G_MODULE_EXPORT gboolean on_exit_clicked(GtkWidget *widget, gpointer gdata)
{
main_status.quitting = TRUE;
if (! check_no_unsaved())
{
if (document_account_for_unsaved())
{
quit_app();
return FALSE;
}
}
else
if (! prefs.confirm_exit ||
dialogs_show_question_full(NULL, GTK_STOCK_QUIT, GTK_STOCK_CANCEL, NULL,
_("Do you really want to quit?")))
{
quit_app();
return FALSE;
}
main_status.quitting = FALSE;
return TRUE;
}
/*
* GUI callbacks
*/
G_MODULE_EXPORT void on_new1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
document_new_file(NULL, NULL, NULL);
}
G_MODULE_EXPORT void on_save1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
gint cur_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(main_widgets.notebook));
GeanyDocument *doc = document_get_current();
if (doc != NULL && cur_page >= 0)
{
document_save_file(doc, FALSE);
}
}
G_MODULE_EXPORT void on_save_as1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
dialogs_show_save_as();
}
G_MODULE_EXPORT void on_save_all1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
guint i, max = (guint) gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook));
GeanyDocument *doc, *cur_doc = document_get_current();
guint count = 0;
/* iterate over documents in tabs order */
for (i = 0; i < max; i++)
{
doc = document_get_from_page(i);
if (! doc->changed)
continue;
if (document_save_file(doc, FALSE))
count++;
}
if (!count)
return;
ui_set_statusbar(FALSE, ngettext("%d file saved.", "%d files saved.", count), count);
/* saving may have changed window title, sidebar for another doc, so update */
sidebar_update_tag_list(cur_doc, TRUE);
ui_set_window_title(cur_doc);
}
G_MODULE_EXPORT void on_close_all1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
document_close_all();
}
G_MODULE_EXPORT void on_close1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
GeanyDocument *doc = document_get_current();
g_return_if_fail(doc != NULL);
document_close(doc);
}
G_MODULE_EXPORT void on_quit1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
on_exit_clicked(NULL, NULL);
}
G_MODULE_EXPORT void on_file1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
gtk_widget_set_sensitive(ui_widgets.recent_files_menuitem,
g_queue_get_length(ui_prefs.recent_queue) > 0);
/* hide Page setup when GTK printing is not used */
ui_widget_show_hide(ui_widgets.print_page_setup, printing_prefs.use_gtk_printing);
}
/* edit actions, c&p & co, from menu bar and from popup menu */
G_MODULE_EXPORT void on_edit1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
GtkWidget *item;
GeanyDocument *doc = document_get_current();
ui_update_menu_copy_items(doc);
ui_update_insert_include_item(doc, 1);
item = ui_lookup_widget(main_widgets.window, "plugin_preferences1");
#ifndef HAVE_PLUGINS
gtk_widget_hide(item);
#else
gtk_widget_set_sensitive(item, plugins_have_preferences());
#endif
}
G_MODULE_EXPORT void on_undo1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
GeanyDocument *doc = document_get_current();
g_return_if_fail(doc != NULL);
if (document_can_undo(doc))
{
sci_cancel(doc->editor->sci);
document_undo(doc);
}
}
G_MODULE_EXPORT void on_redo1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
GeanyDocument *doc = document_get_current();
g_return_if_fail(doc != NULL);
if (document_can_redo(doc))
{
sci_cancel(doc->editor->sci);
document_redo(doc);
}
}
G_MODULE_EXPORT void on_cut1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
GeanyDocument *doc = document_get_current();
GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
if (GTK_IS_EDITABLE(focusw))
gtk_editable_cut_clipboard(GTK_EDITABLE(focusw));
else
if (IS_SCINTILLA(focusw) && doc != NULL)
sci_cut(doc->editor->sci);
else
if (GTK_IS_TEXT_VIEW(focusw))
{
GtkTextBuffer *buffer = gtk_text_view_get_buffer(
GTK_TEXT_VIEW(focusw));
gtk_text_buffer_cut_clipboard(buffer, gtk_clipboard_get(GDK_NONE), TRUE);
}
}
G_MODULE_EXPORT void on_copy1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
GeanyDocument *doc = document_get_current();
GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
if (GTK_IS_EDITABLE(focusw))
gtk_editable_copy_clipboard(GTK_EDITABLE(focusw));
else
if (IS_SCINTILLA(focusw) && doc != NULL)
sci_copy(doc->editor->sci);
else
if (GTK_IS_TEXT_VIEW(focusw))
{
GtkTextBuffer *buffer = gtk_text_view_get_buffer(
GTK_TEXT_VIEW(focusw));
gtk_text_buffer_copy_clipboard(buffer, gtk_clipboard_get(GDK_NONE));
}
}
G_MODULE_EXPORT void on_paste1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
GeanyDocument *doc = document_get_current();
GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
if (GTK_IS_EDITABLE(focusw))
gtk_editable_paste_clipboard(GTK_EDITABLE(focusw));
else
if (IS_SCINTILLA(focusw) && doc != NULL)
{
sci_paste(doc->editor->sci);
}
else
if (GTK_IS_TEXT_VIEW(focusw))
{
GtkTextBuffer *buffer = gtk_text_view_get_buffer(
GTK_TEXT_VIEW(focusw));
gtk_text_buffer_paste_clipboard(buffer, gtk_clipboard_get(GDK_NONE), NULL,
TRUE);
}
}
G_MODULE_EXPORT void on_delete1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
GeanyDocument *doc = document_get_current();
GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
if (GTK_IS_EDITABLE(focusw))
gtk_editable_delete_selection(GTK_EDITABLE(focusw));
else
if (IS_SCINTILLA(focusw) && doc != NULL && sci_has_selection(doc->editor->sci))
sci_clear(doc->editor->sci);
else
if (GTK_IS_TEXT_VIEW(focusw))
{
GtkTextBuffer *buffer = gtk_text_view_get_buffer(
GTK_TEXT_VIEW(focusw));
gtk_text_buffer_delete_selection(buffer, TRUE, TRUE);
}
}
G_MODULE_EXPORT void on_preferences1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
prefs_show_dialog();
}
/* about menu item */
G_MODULE_EXPORT void on_info1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
about_dialog_show();
}
/* open file */
G_MODULE_EXPORT void on_open1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
dialogs_show_open_file();
}
/* quit toolbar button */
G_MODULE_EXPORT void on_toolbutton_quit_clicked(GtkAction *action, gpointer user_data)
{
on_exit_clicked(NULL, NULL);
}
/* reload file */
G_MODULE_EXPORT void on_toolbutton_reload_clicked(GtkAction *action, gpointer user_data)
{
on_reload_as_activate(NULL, GINT_TO_POINTER(-1));
}
/* also used for reloading when user_data is -1 */
G_MODULE_EXPORT void on_reload_as_activate(GtkMenuItem *menuitem, gpointer user_data)
{
GeanyDocument *doc = document_get_current();
gchar *base_name;
gint i = GPOINTER_TO_INT(user_data);
const gchar *charset = NULL;
g_return_if_fail(doc != NULL);
/* No need to reload "untitled" (non-file-backed) documents */
if (doc->file_name == NULL)
return;
if (i >= 0)
{
if (i >= GEANY_ENCODINGS_MAX || encodings[i].charset == NULL)
return;
charset = encodings[i].charset;
}
else
charset = doc->encoding;
base_name = g_path_get_basename(doc->file_name);
/* don't prompt if file hasn't been edited at all */
if ((!doc->changed && !document_can_undo(doc) && !document_can_redo(doc)) ||
dialogs_show_question_full(NULL, _("_Reload"), GTK_STOCK_CANCEL,
_("Any unsaved changes will be lost."),
_("Are you sure you want to reload '%s'?"), base_name))
{
document_reload_file(doc, charset);
if (charset != NULL)
ui_update_statusbar(doc, -1);
}
g_free(base_name);
}
G_MODULE_EXPORT void on_change_font1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
dialogs_show_open_font();
}
/* new file */
G_MODULE_EXPORT void on_toolbutton_new_clicked(GtkAction *action, gpointer user_data)
{
document_new_file(NULL, NULL, NULL);
}
/* open file */
G_MODULE_EXPORT void on_toolbutton_open_clicked(GtkAction *action, gpointer user_data)
{
dialogs_show_open_file();
}
/* save file */
G_MODULE_EXPORT void on_toolbutton_save_clicked(GtkAction *action, gpointer user_data)
{
on_save1_activate(NULL, user_data);
}
/* store text, clear search flags so we can use Search->Find Next/Previous */
static void setup_find(const gchar *text, gboolean backwards)
{
SETPTR(search_data.text, g_strdup(text));
SETPTR(search_data.original_text, g_strdup(text));
search_data.flags = 0;
search_data.backwards = backwards;
search_data.search_bar = TRUE;
}
static void do_toolbar_search(const gchar *text, gboolean incremental, gboolean backwards)
{
GeanyDocument *doc = document_get_current();
gboolean result;
setup_find(text, backwards);
result = document_search_bar_find(doc, search_data.text, 0, incremental, backwards);
if (search_data.search_bar)
ui_set_search_entry_background(toolbar_get_widget_child_by_name("SearchEntry"), result);
}
/* search text */
G_MODULE_EXPORT void on_toolbar_search_entry_changed(GtkAction *action, const gchar *text, gpointer user_data)
{
do_toolbar_search(text, TRUE, FALSE);
}
/* search text */
G_MODULE_EXPORT void on_toolbar_search_entry_activate(GtkAction *action, const gchar *text, gpointer user_data)
{
do_toolbar_search(text, FALSE, GPOINTER_TO_INT(user_data));
}
/* search text */
G_MODULE_EXPORT void on_toolbutton_search_clicked(GtkAction *action, gpointer user_data)
{
GeanyDocument *doc = document_get_current();
gboolean result;
GtkWidget *entry = toolbar_get_widget_child_by_name("SearchEntry");
if (entry != NULL)
{
const gchar *text = gtk_entry_get_text(GTK_ENTRY(entry));
setup_find(text, FALSE);
result = document_search_bar_find(doc, search_data.text, 0, FALSE, FALSE);
if (search_data.search_bar)
ui_set_search_entry_background(entry, result);
}
else
on_find1_activate(NULL, NULL);
}
/* hides toolbar from toolbar popup menu */
G_MODULE_EXPORT void on_hide_toolbar1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
GtkWidget *tool_item = ui_lookup_widget(GTK_WIDGET(main_widgets.window), "menu_show_toolbar1");
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(tool_item), FALSE);
}
/* zoom in from menu bar and popup menu */
G_MODULE_EXPORT void on_zoom_in1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
GeanyDocument *doc = document_get_current();
static gint done = 1;
g_return_if_fail(doc != NULL);
if (done++ % 3 == 0)
sci_set_line_numbers(doc->editor->sci, editor_prefs.show_linenumber_margin,
(sci_get_zoom(doc->editor->sci) / 2));
sci_zoom_in(doc->editor->sci);
}
/* zoom out from menu bar and popup menu */
G_MODULE_EXPORT void on_zoom_out1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
GeanyDocument *doc = document_get_current();
g_return_if_fail(doc != NULL);
if (sci_get_zoom(doc->editor->sci) == 0)
sci_set_line_numbers(doc->editor->sci, editor_prefs.show_linenumber_margin, 0);
sci_zoom_out(doc->editor->sci);
}
G_MODULE_EXPORT void on_normal_size1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
GeanyDocument *doc = document_get_current();
g_return_if_fail(doc != NULL);
sci_zoom_off(doc->editor->sci);
sci_set_line_numbers(doc->editor->sci, editor_prefs.show_linenumber_margin, 0);
}
/* close tab */
G_MODULE_EXPORT void on_toolbutton_close_clicked(GtkAction *action, gpointer user_data)
{
on_close1_activate(NULL, NULL);
}
G_MODULE_EXPORT void on_toolbutton_close_all_clicked(GtkAction *action, gpointer user_data)
{
on_close_all1_activate(NULL, NULL);
}
G_MODULE_EXPORT void on_toolbutton_preferences_clicked(GtkAction *action, gpointer user_data)
{
on_preferences1_activate(NULL, NULL);
}
static gboolean delayed_check_disk_status(gpointer data)
{
document_check_disk_status(data, FALSE);
return FALSE;
}
/* Changes window-title after switching tabs and lots of other things.
* note: using 'after' makes Scintilla redraw before the UI, appearing more responsive */
G_MODULE_EXPORT void on_notebook1_switch_page_after(GtkNotebook *notebook, gpointer page,
guint page_num, gpointer user_data)
{
GeanyDocument *doc;
if (G_UNLIKELY(main_status.opening_session_files || main_status.closing_all))
return;
if (page_num == (guint) -1 && page != NULL)
doc = document_find_by_sci(SCINTILLA(page));
else
doc = document_get_from_page(page_num);
if (doc != NULL)
{
sidebar_select_openfiles_item(doc);
ui_save_buttons_toggle(doc->changed);
ui_set_window_title(doc);
ui_update_statusbar(doc, -1);
ui_update_popup_reundo_items(doc);
ui_document_show_hide(doc); /* update the document menu */
build_menu_update(doc);
sidebar_update_tag_list(doc, FALSE);
document_highlight_tags(doc);
/* We delay the check to avoid weird fast, unintended switching of notebook pages when
* the 'file has changed' dialog is shown while the switch event is not yet completely
* finished. So, we check after the switch has been performed to be safe. */
g_idle_add(delayed_check_disk_status, doc);
#ifdef HAVE_VTE
vte_cwd((doc->real_path != NULL) ? doc->real_path : doc->file_name, FALSE);
#endif
g_signal_emit_by_name(geany_object, "document-activate", doc);
}
}
G_MODULE_EXPORT void on_tv_notebook_switch_page(GtkNotebook *notebook, gpointer page,
guint page_num, gpointer user_data)
{
/* suppress selection changed signal when switching to the open files list */
ignore_callback = TRUE;
}
G_MODULE_EXPORT void on_tv_notebook_switch_page_after(GtkNotebook *notebook, gpointer page,
guint page_num, gpointer user_data)
{
ignore_callback = FALSE;
}
static void convert_eol(gint mode)
{
GeanyDocument *doc = document_get_current();
g_return_if_fail(doc != NULL);
sci_convert_eols(doc->editor->sci, mode);
sci_set_eol_mode(doc->editor->sci, mode);
ui_update_statusbar(doc, -1);
}
G_MODULE_EXPORT void on_crlf_activate(GtkCheckMenuItem *menuitem, gpointer user_data)
{
if (ignore_callback || ! gtk_check_menu_item_get_active(menuitem))
return;
convert_eol(SC_EOL_CRLF);
}
G_MODULE_EXPORT void on_lf_activate(GtkCheckMenuItem *menuitem, gpointer user_data)
{
if (ignore_callback || ! gtk_check_menu_item_get_active(menuitem))
return;
convert_eol(SC_EOL_LF);
}
G_MODULE_EXPORT void on_cr_activate(GtkCheckMenuItem *menuitem, gpointer user_data)
{
if (ignore_callback || ! gtk_check_menu_item_get_active(menuitem))
return;
convert_eol(SC_EOL_CR);
}
G_MODULE_EXPORT void on_replace_tabs_activate(GtkMenuItem *menuitem, gpointer user_data)
{
GeanyDocument *doc = document_get_current();
g_return_if_fail(doc != NULL);
editor_replace_tabs(doc->editor);
}
gboolean toolbar_popup_menu(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
{
if (event->button == 3)
{
gtk_menu_popup(GTK_MENU(ui_widgets.toolbar_menu), NULL, NULL, NULL, NULL, event->button, event->time);
return TRUE;
}
return FALSE;
}
G_MODULE_EXPORT void on_toggle_case1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
GeanyDocument *doc = document_get_current();
ScintillaObject *sci;
gchar *text;
gboolean keep_sel = TRUE;
g_return_if_fail(doc != NULL);
sci = doc->editor->sci;
if (! sci_has_selection(sci))
{
keybindings_send_command(GEANY_KEY_GROUP_SELECT, GEANY_KEYS_SELECT_WORD);
keep_sel = FALSE;
}
/* either we already had a selection or we created one for current word */
if (sci_has_selection(sci))
{
gchar *result = NULL;
gint cmd = SCI_LOWERCASE;
gint text_len = sci_get_selected_text_length(sci);
gboolean rectsel = (gboolean) scintilla_send_message(sci, SCI_SELECTIONISRECTANGLE, 0, 0);
text = g_malloc(text_len + 1);
sci_get_selected_text(sci, text);
if (utils_str_has_upper(text))
{
if (rectsel)
cmd = SCI_LOWERCASE;
else
result = g_utf8_strdown(text, -1);
}
else
{
if (rectsel)
cmd = SCI_UPPERCASE;
else
result = g_utf8_strup(text, -1);
}
if (result != NULL)
{
sci_replace_sel(sci, result);
g_free(result);
if (keep_sel)
sci_set_selection_start(sci, sci_get_current_position(sci) - text_len + 1);
}
else
sci_send_command(sci, cmd);
g_free(text);
}
}
G_MODULE_EXPORT void on_show_toolbar1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
{
if (ignore_callback) return;
toolbar_prefs.visible = (toolbar_prefs.visible) ? FALSE : TRUE;;
ui_widget_show_hide(GTK_WIDGET(main_widgets.toolbar), toolbar_prefs.visible);
}
G_MODULE_EXPORT void on_fullscreen1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
{
if (ignore_callback)
return;
ui_prefs.fullscreen = (ui_prefs.fullscreen) ? FALSE : TRUE;
ui_set_fullscreen();
}
G_MODULE_EXPORT void on_show_messages_window1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
{
if (ignore_callback)
return;
ui_prefs.msgwindow_visible = (ui_prefs.msgwindow_visible) ? FALSE : TRUE;
msgwin_show_hide(ui_prefs.msgwindow_visible);
}
G_MODULE_EXPORT void on_menu_color_schemes_activate(GtkImageMenuItem *imagemenuitem, gpointer user_data)
{
highlighting_show_color_scheme_dialog();
}
G_MODULE_EXPORT void on_markers_margin1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
{
if (ignore_callback)
return;
editor_prefs.show_markers_margin = ! editor_prefs.show_markers_margin;
ui_toggle_editor_features(GEANY_EDITOR_SHOW_MARKERS_MARGIN);
}
G_MODULE_EXPORT void on_show_line_numbers1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
{
if (ignore_callback)
return;
editor_prefs.show_linenumber_margin = ! editor_prefs.show_linenumber_margin;
ui_toggle_editor_features(GEANY_EDITOR_SHOW_LINE_NUMBERS);
}
G_MODULE_EXPORT void on_menu_show_white_space1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
{
if (ignore_callback)
return;
editor_prefs.show_white_space = ! editor_prefs.show_white_space;
ui_toggle_editor_features(GEANY_EDITOR_SHOW_WHITE_SPACE);
}
G_MODULE_EXPORT void on_menu_show_line_endings1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
{
if (ignore_callback)
return;
editor_prefs.show_line_endings = ! editor_prefs.show_line_endings;
ui_toggle_editor_features(GEANY_EDITOR_SHOW_LINE_ENDINGS);
}
G_MODULE_EXPORT void on_menu_show_indentation_guides1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
{
if (ignore_callback)
return;
editor_prefs.show_indent_guide = ! editor_prefs.show_indent_guide;
ui_toggle_editor_features(GEANY_EDITOR_SHOW_INDENTATION_GUIDES);
}
G_MODULE_EXPORT void on_line_wrapping1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
{
if (! ignore_callback)
{
GeanyDocument *doc = document_get_current();
g_return_if_fail(doc != NULL);
editor_set_line_wrapping(doc->editor, ! doc->editor->line_wrapping);
}
}
G_MODULE_EXPORT void on_set_file_readonly1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
{
if (! ignore_callback)
{
GeanyDocument *doc = document_get_current();
g_return_if_fail(doc != NULL);
doc->readonly = ! doc->readonly;
sci_set_readonly(doc->editor->sci, doc->readonly);
ui_update_tab_status(doc);
ui_update_statusbar(doc, -1);
}
}
G_MODULE_EXPORT void on_use_auto_indentation1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
{
if (! ignore_callback)
{
GeanyDocument *doc = document_get_current();
g_return_if_fail(doc != NULL);
doc->editor->auto_indent = ! doc->editor->auto_indent;
}
}
static void find_usage(gboolean in_session)
{
gint flags;
gchar *search_text;
GeanyDocument *doc = document_get_current();
g_return_if_fail(doc != NULL);
if (sci_has_selection(doc->editor->sci))
{ /* take selected text if there is a selection */
search_text = g_malloc(sci_get_selected_text_length(doc->editor->sci) + 1);
sci_get_selected_text(doc->editor->sci, search_text);
flags = SCFIND_MATCHCASE;
}
else
{
editor_find_current_word_sciwc(doc->editor, -1,
editor_info.current_word, GEANY_MAX_WORD_LENGTH);
search_text = g_strdup(editor_info.current_word);
flags = SCFIND_MATCHCASE | SCFIND_WHOLEWORD;
}
search_find_usage(search_text, search_text, flags, in_session);
g_free(search_text);
}
G_MODULE_EXPORT void on_find_document_usage1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
find_usage(FALSE);
}
G_MODULE_EXPORT void on_find_usage1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
find_usage(TRUE);
}
static void goto_tag(gboolean definition)
{
GeanyDocument *doc = document_get_current();
g_return_if_fail(doc != NULL);
/* update cursor pos for navigating back afterwards */
if (!sci_has_selection(doc->editor->sci))
sci_set_current_position(doc->editor->sci, editor_info.click_pos, FALSE);
/* use the keybinding callback as it checks for selections as well as current word */
if (definition)
keybindings_send_command(GEANY_KEY_GROUP_GOTO, GEANY_KEYS_GOTO_TAGDEFINITION);
else
keybindings_send_command(GEANY_KEY_GROUP_GOTO, GEANY_KEYS_GOTO_TAGDECLARATION);
}
G_MODULE_EXPORT void on_goto_tag_definition1(GtkMenuItem *menuitem, gpointer user_data)
{
goto_tag(TRUE);
}
G_MODULE_EXPORT void on_goto_tag_declaration1(GtkMenuItem *menuitem, gpointer user_data)
{
goto_tag(FALSE);
}
G_MODULE_EXPORT void on_count_words1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
tools_word_count();
}
G_MODULE_EXPORT void on_show_color_chooser1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
gchar colour[9];
GeanyDocument *doc = document_get_current();
gint pos;
g_return_if_fail(doc != NULL);
pos = sci_get_current_position(doc->editor->sci);
editor_find_current_word(doc->editor, pos, colour, sizeof colour, GEANY_WORDCHARS"#");
tools_color_chooser(colour);
}
G_MODULE_EXPORT void on_toolbutton_compile_clicked(GtkAction *action, gpointer user_data)
{
keybindings_send_command(GEANY_KEY_GROUP_BUILD, GEANY_KEYS_BUILD_COMPILE);
}
G_MODULE_EXPORT void on_find1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
search_show_find_dialog();