1 /*
2 * callbacks.c - this file is part of Geany, a fast and lightweight IDE
3 *
4 * Copyright 2005 The Geany contributors
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21 /*
22 * Callbacks used by Glade. These are mainly in response to menu item and button events in the
23 * main window. Callbacks not used by Glade should go elsewhere.
24 */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include "callbacks.h"
31
32 #include "about.h"
33 #include "app.h"
34 #include "build.h"
35 #include "dialogs.h"
36 #include "documentprivate.h"
37 #include "encodings.h"
38 #include "filetypes.h"
39 #include "geanyobject.h"
40 #include "highlighting.h"
41 #include "keybindings.h"
42 #include "keyfile.h"
43 #include "log.h"
44 #include "main.h"
45 #include "msgwindow.h"
46 #include "navqueue.h"
47 #include "plugins.h"
48 #include "pluginutils.h"
49 #include "prefs.h"
50 #include "printing.h"
51 #include "sciwrappers.h"
52 #include "sidebar.h"
53 #include "spawn.h"
54 #ifdef HAVE_SOCKET
55 # include "socket.h"
56 #endif
57 #include "support.h"
58 #include "symbols.h"
59 #include "templates.h"
60 #include "toolbar.h"
61 #include "tools.h"
62 #include "ui_utils.h"
63 #include "utils.h"
64 #include "vte.h"
65
66 #include <stdlib.h>
67 #include <unistd.h>
68 #include <string.h>
69 #include <gtk/gtk.h>
70 #include <gdk/gdkkeysyms.h>
71 #include <glib/gstdio.h>
72 #include <time.h>
73
74
75 /* represents the state at switching a notebook page(in the left treeviews widget), to not emit
76 * the selection-changed signal from tv.tree_openfiles */
77 /*static gboolean switch_tv_notebook_page = FALSE; */
78
79
80
81 /* wrapper function to abort exit process if cancel button is pressed */
on_window_delete_event(GtkWidget * widget,GdkEvent * event,gpointer gdata)82 static gboolean on_window_delete_event(GtkWidget *widget, GdkEvent *event, gpointer gdata)
83 {
84 return !main_quit();
85 }
86
87
88 /*
89 * GUI callbacks
90 */
91
on_new1_activate(GtkMenuItem * menuitem,gpointer user_data)92 void on_new1_activate(GtkMenuItem *menuitem, gpointer user_data)
93 {
94 document_new_file(NULL, NULL, NULL);
95 }
96
97
98 /* create a new file and copy file content and properties */
on_clone1_activate(GtkMenuItem * menuitem,gpointer user_data)99 static void on_clone1_activate(GtkMenuItem *menuitem, gpointer user_data)
100 {
101 GeanyDocument *old_doc = document_get_current();
102
103 if (old_doc)
104 document_clone(old_doc);
105 }
106
107
on_save1_activate(GtkMenuItem * menuitem,gpointer user_data)108 void on_save1_activate(GtkMenuItem *menuitem, gpointer user_data)
109 {
110 GeanyDocument *doc = document_get_current();
111
112 if (doc != NULL)
113 {
114 document_save_file(doc, ui_prefs.allow_always_save);
115 }
116 }
117
118
on_save_as1_activate(GtkMenuItem * menuitem,gpointer user_data)119 void on_save_as1_activate(GtkMenuItem *menuitem, gpointer user_data)
120 {
121 dialogs_show_save_as();
122 }
123
124
on_save_all1_activate(GtkMenuItem * menuitem,gpointer user_data)125 void on_save_all1_activate(GtkMenuItem *menuitem, gpointer user_data)
126 {
127 guint i, max = (guint) gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook));
128 GeanyDocument *cur_doc = document_get_current();
129 guint count = 0;
130
131 /* iterate over documents in tabs order */
132 for (i = 0; i < max; i++)
133 {
134 GeanyDocument *doc = document_get_from_page(i);
135
136 if (! doc->changed)
137 continue;
138
139 if (document_save_file(doc, FALSE))
140 count++;
141 }
142 if (!count)
143 return;
144
145 ui_set_statusbar(FALSE, ngettext("%d file saved.", "%d files saved.", count), count);
146 /* saving may have changed window title, sidebar for another doc, so update */
147 document_show_tab(cur_doc);
148 sidebar_update_tag_list(cur_doc, TRUE);
149 ui_set_window_title(cur_doc);
150 }
151
152
on_close_all1_activate(GtkMenuItem * menuitem,gpointer user_data)153 void on_close_all1_activate(GtkMenuItem *menuitem, gpointer user_data)
154 {
155 document_close_all();
156 }
157
158
on_close1_activate(GtkMenuItem * menuitem,gpointer user_data)159 void on_close1_activate(GtkMenuItem *menuitem, gpointer user_data)
160 {
161 GeanyDocument *doc = document_get_current();
162
163 if (doc != NULL)
164 document_close(doc);
165 }
166
167
on_quit1_activate(GtkMenuItem * menuitem,gpointer user_data)168 void on_quit1_activate(GtkMenuItem *menuitem, gpointer user_data)
169 {
170 main_quit();
171 }
172
173
on_file1_activate(GtkMenuItem * menuitem,gpointer user_data)174 static void on_file1_activate(GtkMenuItem *menuitem, gpointer user_data)
175 {
176 gtk_widget_set_sensitive(ui_widgets.recent_files_menuitem,
177 g_queue_get_length(ui_prefs.recent_queue) > 0);
178 /* hide Page setup when GTK printing is not used */
179 ui_widget_show_hide(ui_widgets.print_page_setup, printing_prefs.use_gtk_printing);
180 }
181
182
183 /* edit actions, c&p & co, from menu bar and from popup menu */
on_edit1_select(GtkMenuItem * menuitem,gpointer user_data)184 static void on_edit1_select(GtkMenuItem *menuitem, gpointer user_data)
185 {
186 GtkWidget *item;
187 GeanyDocument *doc = document_get_current();
188
189 ui_update_menu_copy_items(doc);
190 ui_update_insert_include_item(doc, 1);
191
192 item = ui_lookup_widget(main_widgets.window, "plugin_preferences1");
193 #ifndef HAVE_PLUGINS
194 gtk_widget_hide(item);
195 #else
196 gtk_widget_set_sensitive(item, plugins_have_preferences());
197 #endif
198 }
199
200
on_edit1_deselect(GtkMenuShell * menushell,gpointer user_data)201 static void on_edit1_deselect(GtkMenuShell *menushell, gpointer user_data)
202 {
203 /* we re-enable items that were disabled in on_edit1_select() on menu popdown to
204 * workaround mutli-layout keyboard issues in our keybinding handling code, so that
205 * GTK's accelerator handling can catch them.
206 * See https://github.com/geany/geany/issues/1368#issuecomment-273678207 */
207 ui_menu_copy_items_set_sensitive(TRUE);
208 }
209
210
on_undo1_activate(GtkMenuItem * menuitem,gpointer user_data)211 void on_undo1_activate(GtkMenuItem *menuitem, gpointer user_data)
212 {
213 GeanyDocument *doc = document_get_current();
214
215 g_return_if_fail(doc != NULL);
216
217 if (document_can_undo(doc))
218 {
219 sci_cancel(doc->editor->sci);
220 document_undo(doc);
221 }
222 }
223
224
on_redo1_activate(GtkMenuItem * menuitem,gpointer user_data)225 void on_redo1_activate(GtkMenuItem *menuitem, gpointer user_data)
226 {
227 GeanyDocument *doc = document_get_current();
228
229 g_return_if_fail(doc != NULL);
230
231 if (document_can_redo(doc))
232 {
233 sci_cancel(doc->editor->sci);
234 document_redo(doc);
235 }
236 }
237
238
on_cut1_activate(GtkMenuItem * menuitem,gpointer user_data)239 void on_cut1_activate(GtkMenuItem *menuitem, gpointer user_data)
240 {
241 GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
242
243 if (GTK_IS_EDITABLE(focusw))
244 gtk_editable_cut_clipboard(GTK_EDITABLE(focusw));
245 else if (IS_SCINTILLA(focusw))
246 sci_cut(SCINTILLA(focusw));
247 else if (GTK_IS_TEXT_VIEW(focusw))
248 {
249 GtkTextBuffer *buffer = gtk_text_view_get_buffer(
250 GTK_TEXT_VIEW(focusw));
251 gtk_text_buffer_cut_clipboard(buffer, gtk_clipboard_get(GDK_NONE), TRUE);
252 }
253 }
254
255
on_copy1_activate(GtkMenuItem * menuitem,gpointer user_data)256 void on_copy1_activate(GtkMenuItem *menuitem, gpointer user_data)
257 {
258 GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
259
260 if (GTK_IS_EDITABLE(focusw))
261 gtk_editable_copy_clipboard(GTK_EDITABLE(focusw));
262 else if (IS_SCINTILLA(focusw))
263 sci_copy(SCINTILLA(focusw));
264 else if (GTK_IS_TEXT_VIEW(focusw))
265 {
266 GtkTextBuffer *buffer = gtk_text_view_get_buffer(
267 GTK_TEXT_VIEW(focusw));
268 gtk_text_buffer_copy_clipboard(buffer, gtk_clipboard_get(GDK_NONE));
269 }
270 }
271
272
on_paste1_activate(GtkMenuItem * menuitem,gpointer user_data)273 void on_paste1_activate(GtkMenuItem *menuitem, gpointer user_data)
274 {
275 GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
276
277 if (GTK_IS_EDITABLE(focusw))
278 gtk_editable_paste_clipboard(GTK_EDITABLE(focusw));
279 else if (IS_SCINTILLA(focusw))
280 sci_paste(SCINTILLA(focusw));
281 else if (GTK_IS_TEXT_VIEW(focusw))
282 {
283 GtkTextBuffer *buffer = gtk_text_view_get_buffer(
284 GTK_TEXT_VIEW(focusw));
285 gtk_text_buffer_paste_clipboard(buffer, gtk_clipboard_get(GDK_NONE), NULL,
286 TRUE);
287 }
288 }
289
290
on_delete1_activate(GtkMenuItem * menuitem,gpointer user_data)291 void on_delete1_activate(GtkMenuItem *menuitem, gpointer user_data)
292 {
293 GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
294
295 if (GTK_IS_EDITABLE(focusw))
296 gtk_editable_delete_selection(GTK_EDITABLE(focusw));
297 else if (IS_SCINTILLA(focusw) && sci_has_selection(SCINTILLA(focusw)))
298 sci_clear(SCINTILLA(focusw));
299 else if (GTK_IS_TEXT_VIEW(focusw))
300 {
301 GtkTextBuffer *buffer = gtk_text_view_get_buffer(
302 GTK_TEXT_VIEW(focusw));
303 gtk_text_buffer_delete_selection(buffer, TRUE, TRUE);
304 }
305 }
306
307
on_preferences1_activate(GtkMenuItem * menuitem,gpointer user_data)308 void on_preferences1_activate(GtkMenuItem *menuitem, gpointer user_data)
309 {
310 prefs_show_dialog();
311 }
312
313
314 /* about menu item */
on_info1_activate(GtkMenuItem * menuitem,gpointer user_data)315 static void on_info1_activate(GtkMenuItem *menuitem, gpointer user_data)
316 {
317 about_dialog_show();
318 }
319
320
321 /* open file */
on_open1_activate(GtkMenuItem * menuitem,gpointer user_data)322 void on_open1_activate(GtkMenuItem *menuitem, gpointer user_data)
323 {
324 dialogs_show_open_file();
325 }
326
327
328 /* reload file */
on_toolbutton_reload_clicked(GtkAction * action,gpointer user_data)329 void on_toolbutton_reload_clicked(GtkAction *action, gpointer user_data)
330 {
331 GeanyDocument *doc = document_get_current();
332
333 g_return_if_fail(doc != NULL);
334
335 document_reload_prompt(doc, NULL);
336 }
337
338 /* reload all files */
on_reload_all(GtkAction * action,gpointer user_data)339 void on_reload_all(GtkAction *action, gpointer user_data)
340 {
341 guint i;
342 gint cur_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(main_widgets.notebook));
343
344 if (!file_prefs.keep_edit_history_on_reload)
345 {
346 GeanyDocument *doc;
347 foreach_document(i)
348 {
349 doc = documents[i];
350 if (doc->changed || document_can_undo(doc) || document_can_redo(doc))
351 {
352 if (dialogs_show_question_full(NULL, _("_Reload"), GTK_STOCK_CANCEL,
353 _("Changes detected, reloading all will lose any changes and history."),
354 _("Are you sure you want to reload all files?")))
355 {
356 break; // break the loop and continue with reloading below
357 }
358 else
359 {
360 return; // cancel reloading
361 }
362 }
363 }
364 }
365
366 foreach_document(i)
367 {
368 if (! (documents[i]->file_name == NULL))
369 document_reload_force(documents[i], documents[i]->encoding);
370 }
371
372 gtk_notebook_set_current_page(GTK_NOTEBOOK(main_widgets.notebook), cur_page);
373 }
374
375
on_change_font1_activate(GtkMenuItem * menuitem,gpointer user_data)376 static void on_change_font1_activate(GtkMenuItem *menuitem, gpointer user_data)
377 {
378 dialogs_show_open_font();
379 }
380
381
382 /* store text, clear search flags so we can use Search->Find Next/Previous */
setup_find(const gchar * text,gboolean backwards)383 static void setup_find(const gchar *text, gboolean backwards)
384 {
385 SETPTR(search_data.text, g_strdup(text));
386 SETPTR(search_data.original_text, g_strdup(text));
387 search_data.flags = 0;
388 search_data.backwards = backwards;
389 search_data.search_bar = TRUE;
390 }
391
392
do_toolbar_search(const gchar * text,gboolean incremental,gboolean backwards)393 static void do_toolbar_search(const gchar *text, gboolean incremental, gboolean backwards)
394 {
395 GeanyDocument *doc = document_get_current();
396 gboolean result;
397
398 setup_find(text, backwards);
399 result = document_search_bar_find(doc, search_data.text, incremental, backwards);
400 if (search_data.search_bar)
401 ui_set_search_entry_background(toolbar_get_widget_child_by_name("SearchEntry"), result);
402 }
403
404
405 /* search text */
on_toolbar_search_entry_changed(GtkAction * action,const gchar * text,gpointer user_data)406 void on_toolbar_search_entry_changed(GtkAction *action, const gchar *text, gpointer user_data)
407 {
408 do_toolbar_search(text, TRUE, FALSE);
409 }
410
411
412 /* search text */
on_toolbar_search_entry_activate(GtkAction * action,const gchar * text,gpointer user_data)413 void on_toolbar_search_entry_activate(GtkAction *action, const gchar *text, gpointer user_data)
414 {
415 do_toolbar_search(text, FALSE, GPOINTER_TO_INT(user_data));
416 }
417
418
419 /* search text */
on_toolbutton_search_clicked(GtkAction * action,gpointer user_data)420 void on_toolbutton_search_clicked(GtkAction *action, gpointer user_data)
421 {
422 GeanyDocument *doc = document_get_current();
423 gboolean result;
424 GtkWidget *entry = toolbar_get_widget_child_by_name("SearchEntry");
425
426 if (entry != NULL)
427 {
428 const gchar *text = gtk_entry_get_text(GTK_ENTRY(entry));
429
430 setup_find(text, FALSE);
431 result = document_search_bar_find(doc, search_data.text, FALSE, FALSE);
432 if (search_data.search_bar)
433 ui_set_search_entry_background(entry, result);
434 }
435 else
436 on_find1_activate(NULL, NULL);
437 }
438
439
440 /* hides toolbar from toolbar popup menu */
on_hide_toolbar1_activate(GtkMenuItem * menuitem,gpointer user_data)441 static void on_hide_toolbar1_activate(GtkMenuItem *menuitem, gpointer user_data)
442 {
443 GtkWidget *tool_item = ui_lookup_widget(GTK_WIDGET(main_widgets.window), "menu_show_toolbar1");
444 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(tool_item), FALSE);
445 }
446
447
448 /* zoom in from menu bar and popup menu */
on_zoom_in1_activate(GtkMenuItem * menuitem,gpointer user_data)449 void on_zoom_in1_activate(GtkMenuItem *menuitem, gpointer user_data)
450 {
451 GeanyDocument *doc = document_get_current();
452
453 g_return_if_fail(doc != NULL);
454
455 sci_zoom_in(doc->editor->sci);
456 }
457
458
459 /* zoom out from menu bar and popup menu */
on_zoom_out1_activate(GtkMenuItem * menuitem,gpointer user_data)460 void on_zoom_out1_activate(GtkMenuItem *menuitem, gpointer user_data)
461 {
462 GeanyDocument *doc = document_get_current();
463
464 g_return_if_fail(doc != NULL);
465
466 sci_zoom_out(doc->editor->sci);
467 }
468
469
on_normal_size1_activate(GtkMenuItem * menuitem,gpointer user_data)470 void on_normal_size1_activate(GtkMenuItem *menuitem, gpointer user_data)
471 {
472 GeanyDocument *doc = document_get_current();
473
474 g_return_if_fail(doc != NULL);
475
476 sci_zoom_off(doc->editor->sci);
477 }
478
479
480 /* Changes window-title after switching tabs and lots of other things.
481 * note: using 'after' makes Scintilla redraw before the UI, appearing more responsive */
on_notebook1_switch_page_after(GtkNotebook * notebook,gpointer page,guint page_num,gpointer user_data)482 static void on_notebook1_switch_page_after(GtkNotebook *notebook, gpointer page,
483 guint page_num, gpointer user_data)
484 {
485 GeanyDocument *doc;
486
487 if (G_UNLIKELY(main_status.opening_session_files || main_status.closing_all))
488 return;
489
490 doc = document_get_from_notebook_child(page);
491
492 if (doc != NULL)
493 {
494 sidebar_select_openfiles_item(doc);
495 ui_save_buttons_toggle(doc->changed);
496 ui_set_window_title(doc);
497 ui_update_statusbar(doc, -1);
498 ui_update_popup_reundo_items(doc);
499 ui_document_show_hide(doc); /* update the document menu */
500 build_menu_update(doc);
501 sidebar_update_tag_list(doc, FALSE);
502 document_highlight_tags(doc);
503
504 document_check_disk_status(doc, TRUE);
505
506 #ifdef HAVE_VTE
507 vte_cwd((doc->real_path != NULL) ? doc->real_path : doc->file_name, FALSE);
508 #endif
509
510 g_signal_emit_by_name(geany_object, "document-activate", doc);
511 }
512 }
513
514
on_tv_notebook_switch_page(GtkNotebook * notebook,gpointer page,guint page_num,gpointer user_data)515 static void on_tv_notebook_switch_page(GtkNotebook *notebook, gpointer page,
516 guint page_num, gpointer user_data)
517 {
518 /* suppress selection changed signal when switching to the open files list */
519 ignore_callback = TRUE;
520 }
521
522
on_tv_notebook_switch_page_after(GtkNotebook * notebook,gpointer page,guint page_num,gpointer user_data)523 static void on_tv_notebook_switch_page_after(GtkNotebook *notebook, gpointer page,
524 guint page_num, gpointer user_data)
525 {
526 ignore_callback = FALSE;
527 }
528
529
convert_eol(gint mode)530 static void convert_eol(gint mode)
531 {
532 GeanyDocument *doc = document_get_current();
533
534 g_return_if_fail(doc != NULL);
535
536 /* sci_convert_eols() adds UNDO_SCINTILLA action in on_editor_notify().
537 * It is added to the undo stack before sci_convert_eols() finishes
538 * so after adding UNDO_EOL, UNDO_EOL will be at the top of the stack
539 * and UNDO_SCINTILLA below it. */
540 sci_convert_eols(doc->editor->sci, mode);
541 document_undo_add(doc, UNDO_EOL, GINT_TO_POINTER(sci_get_eol_mode(doc->editor->sci)));
542
543 sci_set_eol_mode(doc->editor->sci, mode);
544
545 ui_update_statusbar(doc, -1);
546 }
547
548
on_crlf_activate(GtkCheckMenuItem * menuitem,gpointer user_data)549 static void on_crlf_activate(GtkCheckMenuItem *menuitem, gpointer user_data)
550 {
551 if (ignore_callback || ! gtk_check_menu_item_get_active(menuitem))
552 return;
553
554 convert_eol(SC_EOL_CRLF);
555 }
556
557
on_lf_activate(GtkCheckMenuItem * menuitem,gpointer user_data)558 static void on_lf_activate(GtkCheckMenuItem *menuitem, gpointer user_data)
559 {
560 if (ignore_callback || ! gtk_check_menu_item_get_active(menuitem))
561 return;
562
563 convert_eol(SC_EOL_LF);
564 }
565
566
on_cr_activate(GtkCheckMenuItem * menuitem,gpointer user_data)567 static void on_cr_activate(GtkCheckMenuItem *menuitem, gpointer user_data)
568 {
569 if (ignore_callback || ! gtk_check_menu_item_get_active(menuitem))
570 return;
571
572 convert_eol(SC_EOL_CR);
573 }
574
575
on_replace_tabs_activate(GtkMenuItem * menuitem,gpointer user_data)576 void on_replace_tabs_activate(GtkMenuItem *menuitem, gpointer user_data)
577 {
578 GeanyDocument *doc = document_get_current();
579
580 g_return_if_fail(doc != NULL);
581
582 editor_replace_tabs(doc->editor, FALSE);
583 }
584
585
toolbar_popup_menu(GtkWidget * widget,GdkEventButton * event,gpointer user_data)586 gboolean toolbar_popup_menu(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
587 {
588 if (event->button == 3)
589 {
590 gtk_menu_popup(GTK_MENU(ui_widgets.toolbar_menu), NULL, NULL, NULL, NULL, event->button, event->time);
591 return TRUE;
592 }
593 return FALSE;
594 }
595
596
on_toggle_case1_activate(GtkMenuItem * menuitem,gpointer user_data)597 void on_toggle_case1_activate(GtkMenuItem *menuitem, gpointer user_data)
598 {
599 GeanyDocument *doc = document_get_current();
600 ScintillaObject *sci;
601 gboolean keep_sel = TRUE;
602
603 g_return_if_fail(doc != NULL);
604
605 sci = doc->editor->sci;
606 if (! sci_has_selection(sci))
607 {
608 keybindings_send_command(GEANY_KEY_GROUP_SELECT, GEANY_KEYS_SELECT_WORD);
609 keep_sel = FALSE;
610 }
611
612 /* either we already had a selection or we created one for current word */
613 if (sci_has_selection(sci))
614 {
615 gchar *result = NULL;
616 gint cmd = SCI_LOWERCASE;
617 gboolean rectsel = (gboolean) SSM(sci, SCI_SELECTIONISRECTANGLE, 0, 0);
618 gchar *text = sci_get_selection_contents(sci);
619
620 if (utils_str_has_upper(text))
621 {
622 if (rectsel)
623 cmd = SCI_LOWERCASE;
624 else
625 result = g_utf8_strdown(text, -1);
626 }
627 else
628 {
629 if (rectsel)
630 cmd = SCI_UPPERCASE;
631 else
632 result = g_utf8_strup(text, -1);
633 }
634
635 if (result != NULL)
636 {
637 sci_replace_sel(sci, result);
638 g_free(result);
639 if (keep_sel)
640 sci_set_selection_start(sci, sci_get_current_position(sci) - strlen(text));
641 }
642 else
643 sci_send_command(sci, cmd);
644
645 g_free(text);
646 }
647 }
648
649
on_show_toolbar1_toggled(GtkCheckMenuItem * checkmenuitem,gpointer user_data)650 static void on_show_toolbar1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
651 {
652 if (ignore_callback) return;
653
654 toolbar_prefs.visible = (toolbar_prefs.visible) ? FALSE : TRUE;;
655 ui_widget_show_hide(GTK_WIDGET(main_widgets.toolbar), toolbar_prefs.visible);
656 }
657
658
on_fullscreen1_toggled(GtkCheckMenuItem * checkmenuitem,gpointer user_data)659 static void on_fullscreen1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
660 {
661 if (ignore_callback)
662 return;
663
664 ui_prefs.fullscreen = (ui_prefs.fullscreen) ? FALSE : TRUE;
665 ui_set_fullscreen();
666 }
667
668
on_show_messages_window1_toggled(GtkCheckMenuItem * checkmenuitem,gpointer user_data)669 static void on_show_messages_window1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
670 {
671 if (ignore_callback)
672 return;
673
674 ui_prefs.msgwindow_visible = (ui_prefs.msgwindow_visible) ? FALSE : TRUE;
675 msgwin_show_hide(ui_prefs.msgwindow_visible);
676 }
677
678
on_menu_color_schemes_activate(GtkImageMenuItem * imagemenuitem,gpointer user_data)679 static void on_menu_color_schemes_activate(GtkImageMenuItem *imagemenuitem, gpointer user_data)
680 {
681 highlighting_show_color_scheme_dialog();
682 }
683
684
on_markers_margin1_toggled(GtkCheckMenuItem * checkmenuitem,gpointer user_data)685 static void on_markers_margin1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
686 {
687 if (ignore_callback)
688 return;
689
690 editor_prefs.show_markers_margin = ! editor_prefs.show_markers_margin;
691 ui_toggle_editor_features(GEANY_EDITOR_SHOW_MARKERS_MARGIN);
692 }
693
694
on_show_line_numbers1_toggled(GtkCheckMenuItem * checkmenuitem,gpointer user_data)695 static void on_show_line_numbers1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
696 {
697 if (ignore_callback)
698 return;
699
700 editor_prefs.show_linenumber_margin = ! editor_prefs.show_linenumber_margin;
701 ui_toggle_editor_features(GEANY_EDITOR_SHOW_LINE_NUMBERS);
702 }
703
704
on_menu_show_white_space1_toggled(GtkCheckMenuItem * checkmenuitem,gpointer user_data)705 static void on_menu_show_white_space1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
706 {
707 if (ignore_callback)
708 return;
709
710 editor_prefs.show_white_space = ! editor_prefs.show_white_space;
711 ui_toggle_editor_features(GEANY_EDITOR_SHOW_WHITE_SPACE);
712 }
713
714
on_menu_show_line_endings1_toggled(GtkCheckMenuItem * checkmenuitem,gpointer user_data)715 static void on_menu_show_line_endings1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
716 {
717 if (ignore_callback)
718 return;
719
720 editor_prefs.show_line_endings = ! editor_prefs.show_line_endings;
721 ui_toggle_editor_features(GEANY_EDITOR_SHOW_LINE_ENDINGS);
722 }
723
724
on_menu_show_indentation_guides1_toggled(GtkCheckMenuItem * checkmenuitem,gpointer user_data)725 static void on_menu_show_indentation_guides1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
726 {
727 if (ignore_callback)
728 return;
729
730 editor_prefs.show_indent_guide = ! editor_prefs.show_indent_guide;
731 ui_toggle_editor_features(GEANY_EDITOR_SHOW_INDENTATION_GUIDES);
732 }
733
734
on_line_wrapping1_toggled(GtkCheckMenuItem * checkmenuitem,gpointer user_data)735 void on_line_wrapping1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
736 {
737 if (! ignore_callback)
738 {
739 GeanyDocument *doc = document_get_current();
740 g_return_if_fail(doc != NULL);
741
742 editor_set_line_wrapping(doc->editor, ! doc->editor->line_wrapping);
743 }
744 }
745
746
on_set_file_readonly1_toggled(GtkCheckMenuItem * checkmenuitem,gpointer user_data)747 static void on_set_file_readonly1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
748 {
749 if (! ignore_callback)
750 {
751 GeanyDocument *doc = document_get_current();
752 g_return_if_fail(doc != NULL);
753
754 doc->readonly = ! doc->readonly;
755 sci_set_readonly(doc->editor->sci, doc->readonly);
756 ui_update_tab_status(doc);
757 ui_update_statusbar(doc, -1);
758 }
759 }
760
761
on_use_auto_indentation1_toggled(GtkCheckMenuItem * checkmenuitem,gpointer user_data)762 static void on_use_auto_indentation1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
763 {
764 if (! ignore_callback)
765 {
766 GeanyDocument *doc = document_get_current();
767 g_return_if_fail(doc != NULL);
768
769 doc->editor->auto_indent = ! doc->editor->auto_indent;
770 }
771 }
772
773
find_usage(gboolean in_session)774 static void find_usage(gboolean in_session)
775 {
776 GeanyFindFlags flags;
777 gchar *search_text;
778 GeanyDocument *doc = document_get_current();
779
780 g_return_if_fail(doc != NULL);
781
782 if (sci_has_selection(doc->editor->sci))
783 { /* take selected text if there is a selection */
784 search_text = sci_get_selection_contents(doc->editor->sci);
785 flags = GEANY_FIND_MATCHCASE;
786 }
787 else
788 {
789 editor_find_current_word_sciwc(doc->editor, -1,
790 editor_info.current_word, GEANY_MAX_WORD_LENGTH);
791 search_text = g_strdup(editor_info.current_word);
792 flags = GEANY_FIND_MATCHCASE | GEANY_FIND_WHOLEWORD;
793 }
794
795 search_find_usage(search_text, search_text, flags, in_session);
796 g_free(search_text);
797 }
798
799
on_find_document_usage1_activate(GtkMenuItem * menuitem,gpointer user_data)800 void on_find_document_usage1_activate(GtkMenuItem *menuitem, gpointer user_data)
801 {
802 find_usage(FALSE);
803 }
804
805
on_find_usage1_activate(GtkMenuItem * menuitem,gpointer user_data)806 void on_find_usage1_activate(GtkMenuItem *menuitem, gpointer user_data)
807 {
808 find_usage(TRUE);
809 }
810
811
goto_tag(gboolean definition)812 static void goto_tag(gboolean definition)
813 {
814 GeanyDocument *doc = document_get_current();
815
816 g_return_if_fail(doc != NULL);
817
818 /* update cursor pos for navigating back afterwards */
819 if (!sci_has_selection(doc->editor->sci))
820 sci_set_current_position(doc->editor->sci, editor_info.click_pos, FALSE);
821
822 /* use the keybinding callback as it checks for selections as well as current word */
823 if (definition)
824 keybindings_send_command(GEANY_KEY_GROUP_GOTO, GEANY_KEYS_GOTO_TAGDEFINITION);
825 else
826 keybindings_send_command(GEANY_KEY_GROUP_GOTO, GEANY_KEYS_GOTO_TAGDECLARATION);
827 }
828
829
on_goto_tag_definition1(GtkMenuItem * menuitem,gpointer user_data)830 static void on_goto_tag_definition1(GtkMenuItem *menuitem, gpointer user_data)
831 {
832 goto_tag(TRUE);
833 }
834
835
on_goto_tag_declaration1(GtkMenuItem * menuitem,gpointer user_data)836 static void on_goto_tag_declaration1(GtkMenuItem *menuitem, gpointer user_data)
837 {
838 goto_tag(FALSE);
839 }
840
841
on_count_words1_activate(GtkMenuItem * menuitem,gpointer user_data)842 static void on_count_words1_activate(GtkMenuItem *menuitem, gpointer user_data)
843 {
844 tools_word_count();
845 }
846
847
on_show_color_chooser1_activate(GtkMenuItem * menuitem,gpointer user_data)848 void on_show_color_chooser1_activate(GtkMenuItem *menuitem, gpointer user_data)
849 {
850 gchar colour[9];
851 GeanyDocument *doc = document_get_current();
852 gint pos;
853
854 g_return_if_fail(doc != NULL);
855
856 pos = sci_get_current_position(doc->editor->sci);
857 editor_find_current_word(doc->editor, pos, colour, sizeof colour, GEANY_WORDCHARS"#");
858 tools_color_chooser(colour);
859 }
860
861
on_toolbutton_compile_clicked(GtkAction * action,gpointer user_data)862 void on_toolbutton_compile_clicked(GtkAction *action, gpointer user_data)
863 {
864 keybindings_send_command(GEANY_KEY_GROUP_BUILD, GEANY_KEYS_BUILD_COMPILE);
865 }
866
867
on_find1_activate(GtkMenuItem * menuitem,gpointer user_data)868 void on_find1_activate(GtkMenuItem *menuitem, gpointer user_data)
869 {
870 search_show_find_dialog();
871 }
872
873
on_find_next1_activate(GtkMenuItem * menuitem,gpointer user_data)874 void on_find_next1_activate(GtkMenuItem *menuitem, gpointer user_data)
875 {
876 search_find_again(FALSE);
877 }
878
879
on_find_previous1_activate(GtkMenuItem * menuitem,gpointer user_data)880 void on_find_previous1_activate(GtkMenuItem *menuitem, gpointer user_data)
881 {
882 if (search_data.flags & GEANY_FIND_REGEXP)
883 /* Can't reverse search order for a regex (find next ignores search backwards) */
884 utils_beep();
885 else
886 search_find_again(TRUE);
887 }
888
889
on_find_nextsel1_activate(GtkMenuItem * menuitem,gpointer user_data)890 void on_find_nextsel1_activate(GtkMenuItem *menuitem, gpointer user_data)
891 {
892 search_find_selection(document_get_current(), FALSE);
893 }
894
895
on_find_prevsel1_activate(GtkMenuItem * menuitem,gpointer user_data)896 void on_find_prevsel1_activate(GtkMenuItem *menuitem, gpointer user_data)
897 {
898 search_find_selection(document_get_current(), TRUE);
899 }
900
901
on_replace1_activate(GtkMenuItem * menuitem,gpointer user_data)902 void on_replace1_activate(GtkMenuItem *menuitem, gpointer user_data)
903 {
904 search_show_replace_dialog();
905 }
906
907
on_find_in_files1_activate(GtkMenuItem * menuitem,gpointer user_data)908 void on_find_in_files1_activate(GtkMenuItem *menuitem, gpointer user_data)
909 {
910 search_show_find_in_files_dialog(NULL);
911 }
912
913
get_line_and_offset_from_text(const gchar * text,gint * line_no,gint * offset)914 static void get_line_and_offset_from_text(const gchar *text, gint *line_no, gint *offset)
915 {
916 if (*text == '+' || *text == '-')
917 {
918 *line_no = atoi(text + 1);
919 *offset = (*text == '+') ? 1 : -1;
920 }
921 else
922 {
923 *line_no = atoi(text) - 1;
924 *offset = 0;
925 }
926 }
927
928
on_go_to_line_activate(GtkMenuItem * menuitem,gpointer user_data)929 void on_go_to_line_activate(GtkMenuItem *menuitem, gpointer user_data)
930 {
931 static gchar value[16] = "";
932 gchar *result;
933
934 result = dialogs_show_input_goto_line(
935 _("Go to Line"), GTK_WINDOW(main_widgets.window),
936 _("Enter the line you want to go to:"), value);
937 if (result != NULL)
938 {
939 GeanyDocument *doc = document_get_current();
940 gint offset;
941 gint line_no;
942
943 g_return_if_fail(doc != NULL);
944
945 get_line_and_offset_from_text(result, &line_no, &offset);
946 if (! editor_goto_line(doc->editor, line_no, offset))
947 utils_beep();
948 /* remember value for future calls */
949 g_snprintf(value, sizeof(value), "%s", result);
950
951 g_free(result);
952 }
953 }
954
955
on_toolbutton_goto_entry_activate(GtkAction * action,const gchar * text,gpointer user_data)956 void on_toolbutton_goto_entry_activate(GtkAction *action, const gchar *text, gpointer user_data)
957 {
958 GeanyDocument *doc = document_get_current();
959 gint offset;
960 gint line_no;
961
962 g_return_if_fail(doc != NULL);
963
964 get_line_and_offset_from_text(text, &line_no, &offset);
965 if (! editor_goto_line(doc->editor, line_no, offset))
966 utils_beep();
967 else
968 keybindings_send_command(GEANY_KEY_GROUP_FOCUS, GEANY_KEYS_FOCUS_EDITOR);
969 }
970
971
on_toolbutton_goto_clicked(GtkAction * action,gpointer user_data)972 void on_toolbutton_goto_clicked(GtkAction *action, gpointer user_data)
973 {
974 GtkWidget *entry = toolbar_get_widget_child_by_name("GotoEntry");
975
976 if (entry != NULL)
977 {
978 const gchar *text = gtk_entry_get_text(GTK_ENTRY(entry));
979
980 on_toolbutton_goto_entry_activate(NULL, text, NULL);
981 }
982 else
983 on_go_to_line_activate(NULL, NULL);
984 }
985
986
on_help1_activate(GtkMenuItem * menuitem,gpointer user_data)987 void on_help1_activate(GtkMenuItem *menuitem, gpointer user_data)
988 {
989 gchar *uri;
990
991 uri = utils_get_help_url(NULL);
992 utils_open_browser(uri);
993 g_free(uri);
994 }
995
996
on_help_shortcuts1_activate(GtkMenuItem * menuitem,gpointer user_data)997 static void on_help_shortcuts1_activate(GtkMenuItem *menuitem, gpointer user_data)
998 {
999 keybindings_show_shortcuts();
1000 }
1001
1002
on_website1_activate(GtkMenuItem * menuitem,gpointer user_data)1003 static void on_website1_activate(GtkMenuItem *menuitem, gpointer user_data)
1004 {
1005 utils_open_browser(GEANY_HOMEPAGE);
1006 }
1007
1008
on_help_menu_item_donate_activate(GtkMenuItem * item,gpointer user_data)1009 static void on_help_menu_item_donate_activate(GtkMenuItem *item, gpointer user_data)
1010 {
1011 utils_open_browser(GEANY_DONATE);
1012 }
1013
1014
on_help_menu_item_wiki_activate(GtkMenuItem * item,gpointer user_data)1015 static void on_help_menu_item_wiki_activate(GtkMenuItem *item, gpointer user_data)
1016 {
1017 utils_open_browser(GEANY_WIKI);
1018 }
1019
1020
on_help_menu_item_bug_report_activate(GtkMenuItem * item,gpointer user_data)1021 static void on_help_menu_item_bug_report_activate(GtkMenuItem *item, gpointer user_data)
1022 {
1023 utils_open_browser(GEANY_BUG_REPORT);
1024 }
1025
1026
on_comments_function_activate(GtkMenuItem * menuitem,gpointer user_data)1027 static void on_comments_function_activate(GtkMenuItem *menuitem, gpointer user_data)
1028 {
1029 GeanyDocument *doc = document_get_current();
1030 gchar *text;
1031 const gchar *cur_tag = NULL;
1032 gint line = -1, pos = 0;
1033
1034 if (doc == NULL || doc->file_type == NULL)
1035 {
1036 ui_set_statusbar(FALSE,
1037 _("Please set the filetype for the current file before using this function."));
1038 return;
1039 }
1040
1041 /* symbols_get_current_function returns -1 on failure, so sci_get_position_from_line
1042 * returns the current position, so it should be safe */
1043 line = symbols_get_current_function(doc, &cur_tag);
1044 pos = sci_get_position_from_line(doc->editor->sci, line);
1045
1046 text = templates_get_template_function(doc, cur_tag);
1047
1048 sci_start_undo_action(doc->editor->sci);
1049 sci_insert_text(doc->editor->sci, pos, text);
1050 sci_end_undo_action(doc->editor->sci);
1051 g_free(text);
1052 }
1053
1054
insert_multiline_comment(GeanyDocument * doc,gint pos)1055 static void insert_multiline_comment(GeanyDocument *doc, gint pos)
1056 {
1057 g_return_if_fail(doc != NULL);
1058 g_return_if_fail(pos == -1 || pos >= 0);
1059
1060 if (doc->file_type == NULL)
1061 {
1062 ui_set_statusbar(FALSE,
1063 _("Please set the filetype for the current file before using this function."));
1064 return;
1065 }
1066
1067 if (doc->file_type->comment_open || doc->file_type->comment_single)
1068 {
1069 /* editor_insert_multiline_comment() uses editor_info.click_pos */
1070 if (pos == -1)
1071 editor_info.click_pos = sci_get_current_position(doc->editor->sci);
1072 else
1073 editor_info.click_pos = pos;
1074 editor_insert_multiline_comment(doc->editor);
1075 }
1076 else
1077 utils_beep();
1078 }
1079
1080
on_comments_multiline_activate(GtkMenuItem * menuitem,gpointer user_data)1081 static void on_comments_multiline_activate(GtkMenuItem *menuitem, gpointer user_data)
1082 {
1083 insert_multiline_comment(document_get_current(), editor_info.click_pos);
1084 }
1085
1086
on_menu_comments_multiline_activate(GtkMenuItem * menuitem,gpointer user_data)1087 static void on_menu_comments_multiline_activate(GtkMenuItem *menuitem, gpointer user_data)
1088 {
1089 insert_multiline_comment(document_get_current(), -1);
1090 }
1091
1092
insert_comment_template(GeanyDocument * doc,gint pos,guint template)1093 static void insert_comment_template(GeanyDocument *doc, gint pos, guint template)
1094 {
1095 gchar *text;
1096
1097 g_return_if_fail(doc != NULL);
1098 g_return_if_fail(pos == -1 || pos >= 0);
1099 g_return_if_fail(template < GEANY_MAX_TEMPLATES);
1100
1101 if (pos == -1)
1102 pos = sci_get_current_position(doc->editor->sci);
1103
1104 text = templates_get_template_licence(doc, template);
1105
1106 sci_start_undo_action(doc->editor->sci);
1107 sci_insert_text(doc->editor->sci, pos, text);
1108 sci_end_undo_action(doc->editor->sci);
1109 g_free(text);
1110 }
1111
1112
on_comments_gpl_activate(GtkMenuItem * menuitem,gpointer user_data)1113 static void on_comments_gpl_activate(GtkMenuItem *menuitem, gpointer user_data)
1114 {
1115 insert_comment_template(document_get_current(), editor_info.click_pos, GEANY_TEMPLATE_GPL);
1116 }
1117
1118
on_menu_comments_gpl_activate(GtkMenuItem * menuitem,gpointer user_data)1119 static void on_menu_comments_gpl_activate(GtkMenuItem *menuitem, gpointer user_data)
1120 {
1121 insert_comment_template(document_get_current(), -1, GEANY_TEMPLATE_GPL);
1122 }
1123
1124
on_comments_bsd_activate(GtkMenuItem * menuitem,gpointer user_data)1125 static void on_comments_bsd_activate(GtkMenuItem *menuitem, gpointer user_data)
1126 {
1127 insert_comment_template(document_get_current(), editor_info.click_pos, GEANY_TEMPLATE_BSD);
1128 }
1129
1130
on_menu_comments_bsd_activate(GtkMenuItem * menuitem,gpointer user_data)1131 static void on_menu_comments_bsd_activate(GtkMenuItem *menuitem, gpointer user_data)
1132 {
1133 insert_comment_template(document_get_current(), -1, GEANY_TEMPLATE_BSD);
1134 }
1135
1136
on_comments_changelog_activate(GtkMenuItem * menuitem,gpointer user_data)1137 static void on_comments_changelog_activate(GtkMenuItem *menuitem, gpointer user_data)
1138 {
1139 GeanyDocument *doc = document_get_current();
1140 gchar *text;
1141
1142 g_return_if_fail(doc != NULL);
1143
1144 text = templates_get_template_changelog(doc);
1145 sci_start_undo_action(doc->editor->sci);
1146 sci_insert_text(doc->editor->sci, 0, text);
1147 /* sets the cursor to the right position to type the changelog text,
1148 * the template has 21 chars + length of name and email */
1149 sci_goto_pos(doc->editor->sci, 21 + strlen(template_prefs.developer) + strlen(template_prefs.mail), TRUE);
1150 sci_end_undo_action(doc->editor->sci);
1151
1152 g_free(text);
1153 }
1154
1155
on_comments_fileheader_activate(GtkMenuItem * menuitem,gpointer user_data)1156 static void on_comments_fileheader_activate(GtkMenuItem *menuitem, gpointer user_data)
1157 {
1158 GeanyDocument *doc = document_get_current();
1159 gchar *text;
1160 const gchar *fname;
1161 GeanyFiletype *ft;
1162
1163 g_return_if_fail(doc != NULL);
1164
1165 ft = doc->file_type;
1166 fname = doc->file_name;
1167 text = templates_get_template_fileheader(FILETYPE_ID(ft), fname);
1168
1169 sci_start_undo_action(doc->editor->sci);
1170 sci_insert_text(doc->editor->sci, 0, text);
1171 sci_goto_pos(doc->editor->sci, 0, FALSE);
1172 sci_end_undo_action(doc->editor->sci);
1173 g_free(text);
1174 }
1175
1176
on_file_properties_activate(GtkMenuItem * menuitem,gpointer user_data)1177 void on_file_properties_activate(GtkMenuItem *menuitem, gpointer user_data)
1178 {
1179 GeanyDocument *doc = document_get_current();
1180 g_return_if_fail(doc != NULL);
1181
1182 dialogs_show_file_properties(doc);
1183 }
1184
1185
on_menu_fold_all1_activate(GtkMenuItem * menuitem,gpointer user_data)1186 static void on_menu_fold_all1_activate(GtkMenuItem *menuitem, gpointer user_data)
1187 {
1188 GeanyDocument *doc = document_get_current();
1189 g_return_if_fail(doc != NULL);
1190
1191 editor_fold_all(doc->editor);
1192 }
1193
1194
on_menu_unfold_all1_activate(GtkMenuItem * menuitem,gpointer user_data)1195 static void on_menu_unfold_all1_activate(GtkMenuItem *menuitem, gpointer user_data)
1196 {
1197 GeanyDocument *doc = document_get_current();
1198 g_return_if_fail(doc != NULL);
1199
1200 editor_unfold_all(doc->editor);
1201 }
1202
1203
on_toolbutton_run_clicked(GtkAction * action,gpointer user_data)1204 void on_toolbutton_run_clicked(GtkAction *action, gpointer user_data)
1205 {
1206 keybindings_send_command(GEANY_KEY_GROUP_BUILD, GEANY_KEYS_BUILD_RUN);
1207 }
1208
1209
on_menu_remove_indicators1_activate(GtkMenuItem * menuitem,gpointer user_data)1210 void on_menu_remove_indicators1_activate(GtkMenuItem *menuitem, gpointer user_data)
1211 {
1212 GeanyDocument *doc = document_get_current();
1213 g_return_if_fail(doc != NULL);
1214
1215 editor_indicator_clear(doc->editor, GEANY_INDICATOR_ERROR);
1216 }
1217
1218
on_print1_activate(GtkMenuItem * menuitem,gpointer user_data)1219 void on_print1_activate(GtkMenuItem *menuitem, gpointer user_data)
1220 {
1221 GeanyDocument *doc = document_get_current();
1222 g_return_if_fail(doc != NULL);
1223
1224 printing_print_doc(doc);
1225 }
1226
1227
on_menu_select_all1_activate(GtkMenuItem * menuitem,gpointer user_data)1228 void on_menu_select_all1_activate(GtkMenuItem *menuitem, gpointer user_data)
1229 {
1230 GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
1231
1232 /* special case for Select All in the scribble widget */
1233 if (GTK_IS_TEXT_VIEW(focusw))
1234 {
1235 g_signal_emit_by_name(focusw, "select-all", TRUE);
1236 }
1237 /* special case for Select All in the VTE widget */
1238 #ifdef HAVE_VTE
1239 else if (vte_info.have_vte && focusw == vc->vte)
1240 {
1241 vte_select_all();
1242 }
1243 #endif
1244 else if (GTK_IS_EDITABLE(focusw))
1245 {
1246 gtk_editable_select_region(GTK_EDITABLE(focusw), 0, -1);
1247 }
1248 else if (IS_SCINTILLA(focusw))
1249 {
1250 sci_select_all(SCINTILLA(focusw));
1251 }
1252 }
1253
1254
on_menu_show_sidebar1_toggled(GtkCheckMenuItem * checkmenuitem,gpointer user_data)1255 void on_menu_show_sidebar1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
1256 {
1257 if (ignore_callback)
1258 return;
1259
1260 ui_prefs.sidebar_visible = ! ui_prefs.sidebar_visible;
1261
1262 /* show built-in tabs if no tabs visible */
1263 if (ui_prefs.sidebar_visible &&
1264 ! interface_prefs.sidebar_openfiles_visible && ! interface_prefs.sidebar_symbol_visible &&
1265 gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.sidebar_notebook)) <= 2)
1266 {
1267 interface_prefs.sidebar_openfiles_visible = TRUE;
1268 interface_prefs.sidebar_symbol_visible = TRUE;
1269 }
1270
1271 /* if window has input focus, set it back to the editor before toggling off */
1272 if (! ui_prefs.sidebar_visible &&
1273 gtk_container_get_focus_child(GTK_CONTAINER(main_widgets.sidebar_notebook)) != NULL)
1274 {
1275 keybindings_send_command(GEANY_KEY_GROUP_FOCUS, GEANY_KEYS_FOCUS_EDITOR);
1276 }
1277
1278 ui_sidebar_show_hide();
1279 }
1280
1281
on_menu_write_unicode_bom1_toggled(GtkCheckMenuItem * checkmenuitem,gpointer user_data)1282 static void on_menu_write_unicode_bom1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
1283 {
1284 if (! ignore_callback)
1285 {
1286 GeanyDocument *doc = document_get_current();
1287
1288 g_return_if_fail(doc != NULL);
1289 if (doc->readonly)
1290 {
1291 utils_beep();
1292 return;
1293 }
1294
1295 document_undo_add(doc, UNDO_BOM, GINT_TO_POINTER(doc->has_bom));
1296
1297 doc->has_bom = ! doc->has_bom;
1298
1299 ui_update_statusbar(doc, -1);
1300 }
1301 }
1302
1303
on_menu_comment_line1_activate(GtkMenuItem * menuitem,gpointer user_data)1304 void on_menu_comment_line1_activate(GtkMenuItem *menuitem, gpointer user_data)
1305 {
1306 GeanyDocument *doc = document_get_current();
1307 g_return_if_fail(doc != NULL);
1308
1309 editor_do_comment(doc->editor, -1, FALSE, FALSE, TRUE);
1310 }
1311
1312
on_menu_uncomment_line1_activate(GtkMenuItem * menuitem,gpointer user_data)1313 void on_menu_uncomment_line1_activate(GtkMenuItem *menuitem, gpointer user_data)
1314 {
1315 GeanyDocument *doc = document_get_current();
1316 g_return_if_fail(doc != NULL);
1317
1318 editor_do_uncomment(doc->editor, -1, FALSE);
1319 }
1320
1321
on_menu_toggle_line_commentation1_activate(GtkMenuItem * menuitem,gpointer user_data)1322 void on_menu_toggle_line_commentation1_activate(GtkMenuItem *menuitem, gpointer user_data)
1323 {
1324 GeanyDocument *doc = document_get_current();
1325 g_return_if_fail(doc != NULL);
1326
1327 editor_do_comment_toggle(doc->editor);
1328 }
1329
1330
on_menu_increase_indent1_activate(GtkMenuItem * menuitem,gpointer user_data)1331 void on_menu_increase_indent1_activate(GtkMenuItem *menuitem, gpointer user_data)
1332 {
1333 GeanyDocument *doc = document_get_current();
1334 g_return_if_fail(doc != NULL);
1335
1336 editor_indent(doc->editor, TRUE);
1337 }
1338
1339
on_menu_decrease_indent1_activate(GtkMenuItem * menuitem,gpointer user_data)1340 void on_menu_decrease_indent1_activate(GtkMenuItem *menuitem, gpointer user_data)
1341 {
1342 GeanyDocument *doc = document_get_current();
1343 g_return_if_fail(doc != NULL);
1344
1345 editor_indent(doc->editor, FALSE);
1346 }
1347
1348
on_next_message1_activate(GtkMenuItem * menuitem,gpointer user_data)1349 void on_next_message1_activate(GtkMenuItem *menuitem, gpointer user_data)
1350 {
1351 if (! ui_tree_view_find_next(GTK_TREE_VIEW(msgwindow.tree_msg),
1352 msgwin_goto_messages_file_line))
1353 ui_set_statusbar(FALSE, _("No more message items."));
1354 }
1355
1356
on_previous_message1_activate(GtkMenuItem * menuitem,gpointer user_data)1357 void on_previous_message1_activate(GtkMenuItem *menuitem, gpointer user_data)
1358 {
1359 if (! ui_tree_view_find_previous(GTK_TREE_VIEW(msgwindow.tree_msg),
1360 msgwin_goto_messages_file_line))
1361 ui_set_statusbar(FALSE, _("No more message items."));
1362 }
1363
1364
on_project_new1_activate(GtkMenuItem * menuitem,gpointer user_data)1365 void on_project_new1_activate(GtkMenuItem *menuitem, gpointer user_data)
1366 {
1367 project_new();
1368 }
1369
1370
on_project_open1_activate(GtkMenuItem * menuitem,gpointer user_data)1371 void on_project_open1_activate(GtkMenuItem *menuitem, gpointer user_data)
1372 {
1373 project_open();
1374 }
1375
1376
on_project_close1_activate(GtkMenuItem * menuitem,gpointer user_data)1377 void on_project_close1_activate(GtkMenuItem *menuitem, gpointer user_data)
1378 {
1379 project_close(TRUE);
1380 }
1381
1382
on_project_properties1_activate(GtkMenuItem * menuitem,gpointer user_data)1383 void on_project_properties1_activate(GtkMenuItem *menuitem, gpointer user_data)
1384 {
1385 project_properties();
1386 }
1387
1388
on_menu_project1_activate(GtkMenuItem * menuitem,gpointer user_data)1389 static void on_menu_project1_activate(GtkMenuItem *menuitem, gpointer user_data)
1390 {
1391 static GtkWidget *item_close = NULL;
1392 static GtkWidget *item_properties = NULL;
1393
1394 if (item_close == NULL)
1395 {
1396 item_close = ui_lookup_widget(main_widgets.window, "project_close1");
1397 item_properties = ui_lookup_widget(main_widgets.window, "project_properties1");
1398 }
1399
1400 gtk_widget_set_sensitive(item_close, (app->project != NULL));
1401 gtk_widget_set_sensitive(item_properties, (app->project != NULL));
1402 gtk_widget_set_sensitive(ui_widgets.recent_projects_menuitem,
1403 g_queue_get_length(ui_prefs.recent_projects_queue) > 0);
1404 }
1405
1406
on_menu_open_selected_file1_activate(GtkMenuItem * menuitem,gpointer user_data)1407 void on_menu_open_selected_file1_activate(GtkMenuItem *menuitem, gpointer user_data)
1408 {
1409 GeanyDocument *doc = document_get_current();
1410 gchar *sel = NULL;
1411 const gchar *wc;
1412
1413 #ifdef G_OS_WIN32
1414 wc = GEANY_WORDCHARS "./-" "\\";
1415 #else
1416 wc = GEANY_WORDCHARS "./-";
1417 #endif
1418
1419 g_return_if_fail(doc != NULL);
1420
1421 sel = editor_get_default_selection(doc->editor, TRUE, wc);
1422 SETPTR(sel, utils_get_locale_from_utf8(sel));
1423
1424 if (sel != NULL)
1425 {
1426 gchar *filename = NULL;
1427
1428 if (g_path_is_absolute(sel))
1429 filename = g_strdup(sel);
1430 else
1431 { /* relative filename, add the path of the current file */
1432 gchar *path;
1433
1434 path = utils_get_current_file_dir_utf8();
1435 SETPTR(path, utils_get_locale_from_utf8(path));
1436 if (!path)
1437 path = g_get_current_dir();
1438
1439 filename = g_build_path(G_DIR_SEPARATOR_S, path, sel, NULL);
1440
1441 if (! g_file_test(filename, G_FILE_TEST_EXISTS) &&
1442 app->project != NULL && !EMPTY(app->project->base_path))
1443 {
1444 /* try the project's base path */
1445 SETPTR(path, project_get_base_path());
1446 SETPTR(path, utils_get_locale_from_utf8(path));
1447 SETPTR(filename, g_build_path(G_DIR_SEPARATOR_S, path, sel, NULL));
1448 }
1449 g_free(path);
1450 #ifdef G_OS_UNIX
1451 if (! g_file_test(filename, G_FILE_TEST_EXISTS))
1452 SETPTR(filename, g_build_path(G_DIR_SEPARATOR_S, "/usr/local/include", sel, NULL));
1453
1454 if (! g_file_test(filename, G_FILE_TEST_EXISTS))
1455 SETPTR(filename, g_build_path(G_DIR_SEPARATOR_S, "/usr/include", sel, NULL));
1456 #endif
1457 }
1458
1459 if (g_file_test(filename, G_FILE_TEST_EXISTS))
1460 document_open_file(filename, FALSE, NULL, NULL);
1461 else
1462 {
1463 SETPTR(sel, utils_get_utf8_from_locale(sel));
1464 ui_set_statusbar(TRUE, _("Could not open file %s (File not found)"), sel);
1465 }
1466
1467 g_free(filename);
1468 g_free(sel);
1469 }
1470 }
1471
1472
on_remove_markers1_activate(GtkMenuItem * menuitem,gpointer user_data)1473 void on_remove_markers1_activate(GtkMenuItem *menuitem, gpointer user_data)
1474 {
1475 GeanyDocument *doc = document_get_current();
1476 g_return_if_fail(doc != NULL);
1477
1478 sci_marker_delete_all(doc->editor->sci, 0); /* delete the yellow tag marker */
1479 sci_marker_delete_all(doc->editor->sci, 1); /* delete user markers */
1480 editor_indicator_clear(doc->editor, GEANY_INDICATOR_SEARCH);
1481 }
1482
1483
on_load_tags1_activate(GtkMenuItem * menuitem,gpointer user_data)1484 static void on_load_tags1_activate(GtkMenuItem *menuitem, gpointer user_data)
1485 {
1486 symbols_show_load_tags_dialog();
1487 }
1488
1489
on_context_action1_activate(GtkMenuItem * menuitem,gpointer user_data)1490 void on_context_action1_activate(GtkMenuItem *menuitem, gpointer user_data)
1491 {
1492 gchar *word, *command;
1493 GError *error = NULL;
1494 GeanyDocument *doc = document_get_current();
1495 const gchar *check_msg;
1496
1497 g_return_if_fail(doc != NULL);
1498
1499 if (sci_has_selection(doc->editor->sci))
1500 { /* take selected text if there is a selection */
1501 word = sci_get_selection_contents(doc->editor->sci);
1502 }
1503 else
1504 {
1505 word = g_strdup(editor_info.current_word);
1506 }
1507
1508 /* use the filetype specific command if available, fallback to global command otherwise */
1509 if (doc->file_type != NULL &&
1510 !EMPTY(doc->file_type->context_action_cmd))
1511 {
1512 command = g_strdup(doc->file_type->context_action_cmd);
1513 check_msg = _("Check the path setting in Filetype configuration.");
1514 }
1515 else
1516 {
1517 command = g_strdup(tool_prefs.context_action_cmd);
1518 check_msg = _("Check the path setting in Preferences.");
1519 }
1520
1521 /* substitute the wildcard %s and run the command if it is non empty */
1522 if (G_LIKELY(!EMPTY(command)))
1523 {
1524 gchar *command_line = g_strdup(command);
1525
1526 utils_str_replace_all(&command_line, "%s", word);
1527
1528 if (!spawn_async(NULL, command_line, NULL, NULL, NULL, &error))
1529 {
1530 /* G_SHELL_ERROR is parsing error, it may be caused by %s word with quotes */
1531 ui_set_statusbar(TRUE, _("Cannot execute context action command \"%s\": %s. %s"),
1532 error->domain == G_SHELL_ERROR ? command_line : command, error->message,
1533 check_msg);
1534 g_error_free(error);
1535 }
1536 g_free(command_line);
1537 }
1538 else
1539 {
1540 ui_set_statusbar(TRUE, _("No context action set."));
1541 }
1542 g_free(word);
1543 g_free(command);
1544 }
1545
1546
on_menu_toggle_all_additional_widgets1_activate(GtkMenuItem * menuitem,gpointer user_data)1547 void on_menu_toggle_all_additional_widgets1_activate(GtkMenuItem *menuitem, gpointer user_data)
1548 {
1549 static gint hide_all = -1;
1550 GtkCheckMenuItem *msgw = GTK_CHECK_MENU_ITEM(
1551 ui_lookup_widget(main_widgets.window, "menu_show_messages_window1"));
1552 GtkCheckMenuItem *toolbari = GTK_CHECK_MENU_ITEM(
1553 ui_lookup_widget(main_widgets.window, "menu_show_toolbar1"));
1554
1555 /* get the initial state (necessary if Geany was closed with hide_all = TRUE) */
1556 if (G_UNLIKELY(hide_all == -1))
1557 {
1558 if (! gtk_check_menu_item_get_active(msgw) &&
1559 ! interface_prefs.show_notebook_tabs &&
1560 ! gtk_check_menu_item_get_active(toolbari))
1561 {
1562 hide_all = TRUE;
1563 }
1564 else
1565 hide_all = FALSE;
1566 }
1567
1568 hide_all = ! hide_all; /* toggle */
1569
1570 if (hide_all)
1571 {
1572 if (gtk_check_menu_item_get_active(msgw))
1573 gtk_check_menu_item_set_active(msgw, ! gtk_check_menu_item_get_active(msgw));
1574
1575 interface_prefs.show_notebook_tabs = FALSE;
1576 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets.notebook), interface_prefs.show_notebook_tabs);
1577
1578 ui_statusbar_showhide(FALSE);
1579
1580 if (gtk_check_menu_item_get_active(toolbari))
1581 gtk_check_menu_item_set_active(toolbari, ! gtk_check_menu_item_get_active(toolbari));
1582 }
1583 else
1584 {
1585
1586 if (! gtk_check_menu_item_get_active(msgw))
1587 gtk_check_menu_item_set_active(msgw, ! gtk_check_menu_item_get_active(msgw));
1588
1589 interface_prefs.show_notebook_tabs = TRUE;
1590 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets.notebook), interface_prefs.show_notebook_tabs);
1591
1592 ui_statusbar_showhide(TRUE);
1593
1594 if (! gtk_check_menu_item_get_active(toolbari))
1595 gtk_check_menu_item_set_active(toolbari, ! gtk_check_menu_item_get_active(toolbari));
1596 }
1597 }
1598
1599
on_toolbutton_forward_activate(GtkAction * menuitem,gpointer user_data)1600 void on_toolbutton_forward_activate(GtkAction *menuitem, gpointer user_data)
1601 {
1602 navqueue_go_forward();
1603 }
1604
1605
on_toolbutton_back_activate(GtkAction * menuitem,gpointer user_data)1606 void on_toolbutton_back_activate(GtkAction *menuitem, gpointer user_data)
1607 {
1608 navqueue_go_back();
1609 }
1610
1611
on_motion_event(GtkWidget * widget,GdkEventMotion * event,gpointer user_data)1612 gboolean on_motion_event(GtkWidget *widget, GdkEventMotion *event, gpointer user_data)
1613 {
1614 if (prefs.auto_focus && ! gtk_widget_has_focus(widget))
1615 gtk_widget_grab_focus(widget);
1616
1617 return FALSE;
1618 }
1619
1620
set_indent_type(GtkCheckMenuItem * menuitem,GeanyIndentType type)1621 static void set_indent_type(GtkCheckMenuItem *menuitem, GeanyIndentType type)
1622 {
1623 GeanyDocument *doc;
1624
1625 if (ignore_callback || ! gtk_check_menu_item_get_active(menuitem))
1626 return;
1627
1628 doc = document_get_current();
1629 g_return_if_fail(doc != NULL);
1630
1631 editor_set_indent(doc->editor, type, doc->editor->indent_width);
1632 ui_update_statusbar(doc, -1);
1633 }
1634
1635
on_tabs1_activate(GtkCheckMenuItem * menuitem,gpointer user_data)1636 static void on_tabs1_activate(GtkCheckMenuItem *menuitem, gpointer user_data)
1637 {
1638 set_indent_type(menuitem, GEANY_INDENT_TYPE_TABS);
1639 }
1640
1641
on_spaces1_activate(GtkCheckMenuItem * menuitem,gpointer user_data)1642 static void on_spaces1_activate(GtkCheckMenuItem *menuitem, gpointer user_data)
1643 {
1644 set_indent_type(menuitem, GEANY_INDENT_TYPE_SPACES);
1645 }
1646
1647
on_tabs_and_spaces1_activate(GtkCheckMenuItem * menuitem,gpointer user_data)1648 static void on_tabs_and_spaces1_activate(GtkCheckMenuItem *menuitem, gpointer user_data)
1649 {
1650 set_indent_type(menuitem, GEANY_INDENT_TYPE_BOTH);
1651 }
1652
1653
on_strip_trailing_spaces1_activate(GtkMenuItem * menuitem,gpointer user_data)1654 static void on_strip_trailing_spaces1_activate(GtkMenuItem *menuitem, gpointer user_data)
1655 {
1656 GeanyDocument *doc;
1657
1658 if (ignore_callback)
1659 return;
1660
1661 doc = document_get_current();
1662 g_return_if_fail(doc != NULL);
1663
1664 editor_strip_trailing_spaces(doc->editor, FALSE);
1665 }
1666
1667
on_page_setup1_activate(GtkMenuItem * menuitem,gpointer user_data)1668 static void on_page_setup1_activate(GtkMenuItem *menuitem, gpointer user_data)
1669 {
1670 printing_page_setup_gtk();
1671 }
1672
1673
on_escape_key_press_event(GtkWidget * widget,GdkEventKey * event,gpointer user_data)1674 gboolean on_escape_key_press_event(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
1675 {
1676 guint state = keybindings_get_modifiers(event->state);
1677
1678 /* make pressing escape in the sidebar and toolbar focus the editor */
1679 if (event->keyval == GDK_KEY_Escape && state == 0)
1680 {
1681 keybindings_send_command(GEANY_KEY_GROUP_FOCUS, GEANY_KEYS_FOCUS_EDITOR);
1682 return TRUE;
1683 }
1684 return FALSE;
1685 }
1686
1687
on_line_breaking1_activate(GtkMenuItem * menuitem,gpointer user_data)1688 void on_line_breaking1_activate(GtkMenuItem *menuitem, gpointer user_data)
1689 {
1690 GeanyDocument *doc;
1691
1692 if (ignore_callback)
1693 return;
1694
1695 doc = document_get_current();
1696 g_return_if_fail(doc != NULL);
1697
1698 doc->editor->line_breaking = !doc->editor->line_breaking;
1699 }
1700
1701
on_replace_spaces_activate(GtkMenuItem * menuitem,gpointer user_data)1702 void on_replace_spaces_activate(GtkMenuItem *menuitem, gpointer user_data)
1703 {
1704 GeanyDocument *doc = document_get_current();
1705
1706 g_return_if_fail(doc != NULL);
1707
1708 editor_replace_spaces(doc->editor, FALSE);
1709 }
1710
1711
on_search1_activate(GtkMenuItem * menuitem,gpointer user_data)1712 static void on_search1_activate(GtkMenuItem *menuitem, gpointer user_data)
1713 {
1714 GtkWidget *next_message = ui_lookup_widget(main_widgets.window, "next_message1");
1715 GtkWidget *previous_message = ui_lookup_widget(main_widgets.window, "previous_message1");
1716 gboolean have_messages;
1717
1718 /* enable commands if the messages window has any items */
1719 have_messages = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(msgwindow.store_msg),
1720 NULL) > 0;
1721
1722 gtk_widget_set_sensitive(next_message, have_messages);
1723 gtk_widget_set_sensitive(previous_message, have_messages);
1724 }
1725
1726
1727 /* simple implementation (vs. close all which doesn't close documents if cancelled),
1728 * if user_data is set, it is the GeanyDocument to keep */
on_close_other_documents1_activate(GtkMenuItem * menuitem,gpointer user_data)1729 void on_close_other_documents1_activate(GtkMenuItem *menuitem, gpointer user_data)
1730 {
1731 guint i;
1732 GeanyDocument *cur_doc = user_data;
1733
1734 if (cur_doc == NULL)
1735 cur_doc = document_get_current();
1736
1737 for (i = 0; i < documents_array->len; i++)
1738 {
1739 GeanyDocument *doc = documents[i];
1740
1741 if (doc == cur_doc || ! doc->is_valid)
1742 continue;
1743
1744 if (! document_close(doc))
1745 break;
1746 }
1747 }
1748
1749
on_menu_reload_configuration1_activate(GtkMenuItem * menuitem,gpointer user_data)1750 static void on_menu_reload_configuration1_activate(GtkMenuItem *menuitem, gpointer user_data)
1751 {
1752 main_reload_configuration();
1753 }
1754
1755
on_debug_messages1_activate(GtkMenuItem * menuitem,gpointer user_data)1756 static void on_debug_messages1_activate(GtkMenuItem *menuitem, gpointer user_data)
1757 {
1758 log_show_debug_messages_dialog();
1759 }
1760
1761
on_send_selection_to_vte1_activate(GtkMenuItem * menuitem,gpointer user_data)1762 void on_send_selection_to_vte1_activate(GtkMenuItem *menuitem, gpointer user_data)
1763 {
1764 #ifdef HAVE_VTE
1765 if (vte_info.have_vte)
1766 vte_send_selection_to_vte();
1767 #endif
1768 }
1769
1770
on_window_state_event(GtkWidget * widget,GdkEventWindowState * event,gpointer user_data)1771 static gboolean on_window_state_event(GtkWidget *widget, GdkEventWindowState *event, gpointer user_data)
1772 {
1773
1774 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
1775 {
1776 static GtkWidget *menuitem = NULL;
1777
1778 if (menuitem == NULL)
1779 menuitem = ui_lookup_widget(widget, "menu_fullscreen1");
1780
1781 ignore_callback = TRUE;
1782
1783 ui_prefs.fullscreen = (event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN) ? TRUE : FALSE;
1784 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), ui_prefs.fullscreen);
1785
1786 ignore_callback = FALSE;
1787 }
1788 return FALSE;
1789 }
1790
1791
show_notebook_page(const gchar * notebook_name,const gchar * page_name)1792 static void show_notebook_page(const gchar *notebook_name, const gchar *page_name)
1793 {
1794 GtkWidget *widget;
1795 GtkNotebook *notebook;
1796
1797 widget = ui_lookup_widget(ui_widgets.prefs_dialog, page_name);
1798 notebook = GTK_NOTEBOOK(ui_lookup_widget(ui_widgets.prefs_dialog, notebook_name));
1799
1800 if (notebook != NULL && widget != NULL)
1801 gtk_notebook_set_current_page(notebook, gtk_notebook_page_num(notebook, widget));
1802 }
1803
1804
on_customize_toolbar1_activate(GtkMenuItem * menuitem,gpointer user_data)1805 static void on_customize_toolbar1_activate(GtkMenuItem *menuitem, gpointer user_data)
1806 {
1807 prefs_show_dialog();
1808
1809 /* select the Interface page */
1810 show_notebook_page("notebook2", "notebook6");
1811 /* select the Toolbar subpage */
1812 show_notebook_page("notebook6", "vbox15");
1813 }
1814
1815
on_button_customize_toolbar_clicked(GtkButton * button,gpointer user_data)1816 static void on_button_customize_toolbar_clicked(GtkButton *button, gpointer user_data)
1817 {
1818 toolbar_configure(GTK_WINDOW(ui_widgets.prefs_dialog));
1819 }
1820
1821
on_cut_current_lines1_activate(GtkMenuItem * menuitem,gpointer user_data)1822 static void on_cut_current_lines1_activate(GtkMenuItem *menuitem, gpointer user_data)
1823 {
1824 keybindings_send_command(GEANY_KEY_GROUP_CLIPBOARD, GEANY_KEYS_CLIPBOARD_CUTLINE);
1825 }
1826
1827
on_copy_current_lines1_activate(GtkMenuItem * menuitem,gpointer user_data)1828 static void on_copy_current_lines1_activate(GtkMenuItem *menuitem, gpointer user_data)
1829 {
1830 keybindings_send_command(GEANY_KEY_GROUP_CLIPBOARD, GEANY_KEYS_CLIPBOARD_COPYLINE);
1831 }
1832
1833
on_delete_current_lines1_activate(GtkMenuItem * menuitem,gpointer user_data)1834 static void on_delete_current_lines1_activate(GtkMenuItem *menuitem, gpointer user_data)
1835 {
1836 keybindings_send_command(GEANY_KEY_GROUP_EDITOR, GEANY_KEYS_EDITOR_DELETELINE);
1837 }
1838
1839
on_duplicate_line_or_selection1_activate(GtkMenuItem * menuitem,gpointer user_data)1840 static void on_duplicate_line_or_selection1_activate(GtkMenuItem *menuitem, gpointer user_data)
1841 {
1842 keybindings_send_command(GEANY_KEY_GROUP_EDITOR, GEANY_KEYS_EDITOR_DUPLICATELINE);
1843 }
1844
1845
on_select_current_lines1_activate(GtkMenuItem * menuitem,gpointer user_data)1846 static void on_select_current_lines1_activate(GtkMenuItem *menuitem, gpointer user_data)
1847 {
1848 keybindings_send_command(GEANY_KEY_GROUP_SELECT, GEANY_KEYS_SELECT_LINE);
1849 }
1850
1851
on_select_current_paragraph1_activate(GtkMenuItem * menuitem,gpointer user_data)1852 static void on_select_current_paragraph1_activate(GtkMenuItem *menuitem, gpointer user_data)
1853 {
1854 keybindings_send_command(GEANY_KEY_GROUP_SELECT, GEANY_KEYS_SELECT_PARAGRAPH);
1855 }
1856
1857
on_insert_alternative_white_space1_activate(GtkMenuItem * menuitem,gpointer user_data)1858 static void on_insert_alternative_white_space1_activate(GtkMenuItem *menuitem, gpointer user_data)
1859 {
1860 keybindings_send_command(GEANY_KEY_GROUP_INSERT, GEANY_KEYS_INSERT_ALTWHITESPACE);
1861 }
1862
1863
on_go_to_next_marker1_activate(GtkMenuItem * menuitem,gpointer user_data)1864 static void on_go_to_next_marker1_activate(GtkMenuItem *menuitem, gpointer user_data)
1865 {
1866 keybindings_send_command(GEANY_KEY_GROUP_GOTO, GEANY_KEYS_GOTO_NEXTMARKER);
1867 }
1868
1869
on_go_to_previous_marker1_activate(GtkMenuItem * menuitem,gpointer user_data)1870 static void on_go_to_previous_marker1_activate(GtkMenuItem *menuitem, gpointer user_data)
1871 {
1872 keybindings_send_command(GEANY_KEY_GROUP_GOTO, GEANY_KEYS_GOTO_PREVIOUSMARKER);
1873 }
1874
1875
on_reflow_lines_block1_activate(GtkMenuItem * menuitem,gpointer user_data)1876 static void on_reflow_lines_block1_activate(GtkMenuItem *menuitem, gpointer user_data)
1877 {
1878 keybindings_send_command(GEANY_KEY_GROUP_FORMAT, GEANY_KEYS_FORMAT_REFLOWPARAGRAPH);
1879 }
1880
1881
on_move_lines_up1_activate(GtkMenuItem * menuitem,gpointer user_data)1882 static void on_move_lines_up1_activate(GtkMenuItem *menuitem, gpointer user_data)
1883 {
1884 keybindings_send_command(GEANY_KEY_GROUP_EDITOR, GEANY_KEYS_EDITOR_MOVELINEUP);
1885 }
1886
1887
on_move_lines_down1_activate(GtkMenuItem * menuitem,gpointer user_data)1888 static void on_move_lines_down1_activate(GtkMenuItem *menuitem, gpointer user_data)
1889 {
1890 keybindings_send_command(GEANY_KEY_GROUP_EDITOR, GEANY_KEYS_EDITOR_MOVELINEDOWN);
1891 }
1892
1893
on_smart_line_indent1_activate(GtkMenuItem * menuitem,gpointer user_data)1894 static void on_smart_line_indent1_activate(GtkMenuItem *menuitem, gpointer user_data)
1895 {
1896 keybindings_send_command(GEANY_KEY_GROUP_FORMAT, GEANY_KEYS_FORMAT_AUTOINDENT);
1897 }
1898
1899
on_plugin_preferences1_activate(GtkMenuItem * menuitem,gpointer user_data)1900 void on_plugin_preferences1_activate(GtkMenuItem *menuitem, gpointer user_data)
1901 {
1902 #ifdef HAVE_PLUGINS
1903 plugin_show_configure(NULL);
1904 #endif
1905 }
1906
1907
on_indent_width_activate(GtkMenuItem * menuitem,gpointer user_data)1908 static void on_indent_width_activate(GtkMenuItem *menuitem, gpointer user_data)
1909 {
1910 GeanyDocument *doc;
1911 gchar *label;
1912 gint width;
1913
1914 if (ignore_callback)
1915 return;
1916
1917 label = ui_menu_item_get_text(menuitem);
1918 width = atoi(label);
1919 g_free(label);
1920
1921 doc = document_get_current();
1922 if (doc != NULL && width > 0)
1923 editor_set_indent_width(doc->editor, width);
1924 }
1925
1926
on_reset_indentation1_activate(GtkMenuItem * menuitem,gpointer user_data)1927 static void on_reset_indentation1_activate(GtkMenuItem *menuitem, gpointer user_data)
1928 {
1929 guint i;
1930
1931 foreach_document(i)
1932 document_apply_indent_settings(documents[i]);
1933
1934 ui_update_statusbar(NULL, -1);
1935 ui_document_show_hide(NULL);
1936 }
1937
1938
on_mark_all1_activate(GtkMenuItem * menuitem,gpointer user_data)1939 static void on_mark_all1_activate(GtkMenuItem *menuitem, gpointer user_data)
1940 {
1941 keybindings_send_command(GEANY_KEY_GROUP_SEARCH, GEANY_KEYS_SEARCH_MARKALL);
1942 }
1943
1944
on_detect_type_from_file_activate(GtkMenuItem * menuitem,gpointer user_data)1945 static void on_detect_type_from_file_activate(GtkMenuItem *menuitem, gpointer user_data)
1946 {
1947 GeanyDocument *doc = document_get_current();
1948 GeanyIndentType type;
1949
1950 if (doc != NULL && document_detect_indent_type(doc, &type))
1951 {
1952 editor_set_indent_type(doc->editor, type);
1953 ui_document_show_hide(doc);
1954 ui_update_statusbar(doc, -1);
1955 }
1956 }
1957
1958
on_show_symbol_list_toggled(GtkToggleButton * button,gpointer user_data)1959 static void on_show_symbol_list_toggled(GtkToggleButton *button, gpointer user_data)
1960 {
1961 GtkWidget *widget = ui_lookup_widget(ui_widgets.prefs_dialog, "box_show_symbol_list_children");
1962
1963 gtk_widget_set_sensitive(widget, gtk_toggle_button_get_active(button));
1964 }
1965
1966
on_detect_width_from_file_activate(GtkMenuItem * menuitem,gpointer user_data)1967 static void on_detect_width_from_file_activate(GtkMenuItem *menuitem, gpointer user_data)
1968 {
1969 GeanyDocument *doc = document_get_current();
1970 gint width;
1971
1972 if (doc != NULL && document_detect_indent_width(doc, &width))
1973 {
1974 editor_set_indent_width(doc->editor, width);
1975 ui_document_show_hide(doc);
1976 }
1977 }
1978
1979
builder_connect_func(GtkBuilder * builder,GObject * object,const gchar * signal_name,const gchar * handler_name,GObject * connect_obj,GConnectFlags flags,gpointer user_data)1980 static void builder_connect_func(GtkBuilder *builder, GObject *object,
1981 const gchar *signal_name, const gchar *handler_name, GObject *connect_obj,
1982 GConnectFlags flags, gpointer user_data)
1983 {
1984 GHashTable *hash = user_data;
1985 GCallback callback;
1986
1987 callback = g_hash_table_lookup(hash, handler_name);
1988 g_return_if_fail(callback);
1989
1990 if (connect_obj == NULL)
1991 g_signal_connect_data(object, signal_name, callback, NULL, NULL, flags);
1992 else
1993 g_signal_connect_object(object, signal_name, callback, connect_obj, flags);
1994 }
1995
1996
callbacks_connect(GtkBuilder * builder)1997 void callbacks_connect(GtkBuilder *builder)
1998 {
1999 GHashTable *hash;
2000
2001 g_return_if_fail(GTK_IS_BUILDER(builder));
2002
2003 hash = g_hash_table_new(g_str_hash, g_str_equal);
2004
2005 #define ITEM(n) g_hash_table_insert(hash, (gpointer) #n, G_CALLBACK(n));
2006 # include "signallist.i"
2007 #undef ITEM
2008
2009 gtk_builder_connect_signals_full(builder, builder_connect_func, hash);
2010 g_hash_table_destroy(hash);
2011 }
2012