calltips: Allow for more than one space between the brace and the word
[geany-mirror.git] / src / callbacks.c
blob86b3c52d52f0022fbe7f5bbbe1153c6216e7cbfc
1 /*
2 * callbacks.c - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2005-2012 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5 * Copyright 2006-2012 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 * Callbacks used by Glade. These are mainly in response to menu item and button events in the
24 * main window. Callbacks not used by Glade should go elsewhere.
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
31 #include "callbacks.h"
33 #include "about.h"
34 #include "app.h"
35 #include "build.h"
36 #include "dialogs.h"
37 #include "documentprivate.h"
38 #include "encodings.h"
39 #include "filetypes.h"
40 #include "geanyobject.h"
41 #include "highlighting.h"
42 #include "keybindings.h"
43 #include "keyfile.h"
44 #include "log.h"
45 #include "main.h"
46 #include "msgwindow.h"
47 #include "navqueue.h"
48 #include "plugins.h"
49 #include "pluginutils.h"
50 #include "prefs.h"
51 #include "printing.h"
52 #include "sciwrappers.h"
53 #include "sidebar.h"
54 #include "spawn.h"
55 #ifdef HAVE_SOCKET
56 # include "socket.h"
57 #endif
58 #include "support.h"
59 #include "symbols.h"
60 #include "templates.h"
61 #include "toolbar.h"
62 #include "tools.h"
63 #include "ui_utils.h"
64 #include "utils.h"
65 #include "vte.h"
67 #include "gtkcompat.h"
69 #include <stdlib.h>
70 #include <unistd.h>
71 #include <string.h>
72 #include <gdk/gdkkeysyms.h>
73 #include <glib/gstdio.h>
74 #include <time.h>
77 /* represents the state at switching a notebook page(in the left treeviews widget), to not emit
78 * the selection-changed signal from tv.tree_openfiles */
79 /*static gboolean switch_tv_notebook_page = FALSE; */
83 /* wrapper function to abort exit process if cancel button is pressed */
84 static gboolean on_window_delete_event(GtkWidget *widget, GdkEvent *event, gpointer gdata)
86 return !main_quit();
91 * GUI callbacks
94 void on_new1_activate(GtkMenuItem *menuitem, gpointer user_data)
96 document_new_file(NULL, NULL, NULL);
100 /* create a new file and copy file content and properties */
101 static void on_clone1_activate(GtkMenuItem *menuitem, gpointer user_data)
103 GeanyDocument *old_doc = document_get_current();
105 if (old_doc)
106 document_clone(old_doc);
110 void on_save1_activate(GtkMenuItem *menuitem, gpointer user_data)
112 GeanyDocument *doc = document_get_current();
114 if (doc != NULL)
116 document_save_file(doc, ui_prefs.allow_always_save);
121 void on_save_as1_activate(GtkMenuItem *menuitem, gpointer user_data)
123 dialogs_show_save_as();
127 void on_save_all1_activate(GtkMenuItem *menuitem, gpointer user_data)
129 guint i, max = (guint) gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook));
130 GeanyDocument *doc, *cur_doc = document_get_current();
131 guint count = 0;
133 /* iterate over documents in tabs order */
134 for (i = 0; i < max; i++)
136 doc = document_get_from_page(i);
137 if (! doc->changed)
138 continue;
140 if (document_save_file(doc, FALSE))
141 count++;
143 if (!count)
144 return;
146 ui_set_statusbar(FALSE, ngettext("%d file saved.", "%d files saved.", count), count);
147 /* saving may have changed window title, sidebar for another doc, so update */
148 document_show_tab(cur_doc);
149 sidebar_update_tag_list(cur_doc, TRUE);
150 ui_set_window_title(cur_doc);
154 void on_close_all1_activate(GtkMenuItem *menuitem, gpointer user_data)
156 document_close_all();
160 void on_close1_activate(GtkMenuItem *menuitem, gpointer user_data)
162 GeanyDocument *doc = document_get_current();
164 if (doc != NULL)
165 document_close(doc);
169 void on_quit1_activate(GtkMenuItem *menuitem, gpointer user_data)
171 main_quit();
175 static void on_file1_activate(GtkMenuItem *menuitem, gpointer user_data)
177 gtk_widget_set_sensitive(ui_widgets.recent_files_menuitem,
178 g_queue_get_length(ui_prefs.recent_queue) > 0);
179 /* hide Page setup when GTK printing is not used */
180 ui_widget_show_hide(ui_widgets.print_page_setup, printing_prefs.use_gtk_printing);
184 /* edit actions, c&p & co, from menu bar and from popup menu */
185 static void on_edit1_activate(GtkMenuItem *menuitem, gpointer user_data)
187 GtkWidget *item;
188 GeanyDocument *doc = document_get_current();
190 ui_update_menu_copy_items(doc);
191 ui_update_insert_include_item(doc, 1);
193 item = ui_lookup_widget(main_widgets.window, "plugin_preferences1");
194 #ifndef HAVE_PLUGINS
195 gtk_widget_hide(item);
196 #else
197 gtk_widget_set_sensitive(item, plugins_have_preferences());
198 #endif
202 void on_undo1_activate(GtkMenuItem *menuitem, gpointer user_data)
204 GeanyDocument *doc = document_get_current();
206 g_return_if_fail(doc != NULL);
208 if (document_can_undo(doc))
210 sci_cancel(doc->editor->sci);
211 document_undo(doc);
216 void on_redo1_activate(GtkMenuItem *menuitem, gpointer user_data)
218 GeanyDocument *doc = document_get_current();
220 g_return_if_fail(doc != NULL);
222 if (document_can_redo(doc))
224 sci_cancel(doc->editor->sci);
225 document_redo(doc);
230 void on_cut1_activate(GtkMenuItem *menuitem, gpointer user_data)
232 GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
234 if (GTK_IS_EDITABLE(focusw))
235 gtk_editable_cut_clipboard(GTK_EDITABLE(focusw));
236 else if (IS_SCINTILLA(focusw))
237 sci_cut(SCINTILLA(focusw));
238 else if (GTK_IS_TEXT_VIEW(focusw))
240 GtkTextBuffer *buffer = gtk_text_view_get_buffer(
241 GTK_TEXT_VIEW(focusw));
242 gtk_text_buffer_cut_clipboard(buffer, gtk_clipboard_get(GDK_NONE), TRUE);
247 void on_copy1_activate(GtkMenuItem *menuitem, gpointer user_data)
249 GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
251 if (GTK_IS_EDITABLE(focusw))
252 gtk_editable_copy_clipboard(GTK_EDITABLE(focusw));
253 else if (IS_SCINTILLA(focusw))
254 sci_copy(SCINTILLA(focusw));
255 else if (GTK_IS_TEXT_VIEW(focusw))
257 GtkTextBuffer *buffer = gtk_text_view_get_buffer(
258 GTK_TEXT_VIEW(focusw));
259 gtk_text_buffer_copy_clipboard(buffer, gtk_clipboard_get(GDK_NONE));
264 void on_paste1_activate(GtkMenuItem *menuitem, gpointer user_data)
266 GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
268 if (GTK_IS_EDITABLE(focusw))
269 gtk_editable_paste_clipboard(GTK_EDITABLE(focusw));
270 else if (IS_SCINTILLA(focusw))
271 sci_paste(SCINTILLA(focusw));
272 else if (GTK_IS_TEXT_VIEW(focusw))
274 GtkTextBuffer *buffer = gtk_text_view_get_buffer(
275 GTK_TEXT_VIEW(focusw));
276 gtk_text_buffer_paste_clipboard(buffer, gtk_clipboard_get(GDK_NONE), NULL,
277 TRUE);
282 void on_delete1_activate(GtkMenuItem *menuitem, gpointer user_data)
284 GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
286 if (GTK_IS_EDITABLE(focusw))
287 gtk_editable_delete_selection(GTK_EDITABLE(focusw));
288 else if (IS_SCINTILLA(focusw) && sci_has_selection(SCINTILLA(focusw)))
289 sci_clear(SCINTILLA(focusw));
290 else if (GTK_IS_TEXT_VIEW(focusw))
292 GtkTextBuffer *buffer = gtk_text_view_get_buffer(
293 GTK_TEXT_VIEW(focusw));
294 gtk_text_buffer_delete_selection(buffer, TRUE, TRUE);
299 void on_preferences1_activate(GtkMenuItem *menuitem, gpointer user_data)
301 prefs_show_dialog();
305 /* about menu item */
306 static void on_info1_activate(GtkMenuItem *menuitem, gpointer user_data)
308 about_dialog_show();
312 /* open file */
313 void on_open1_activate(GtkMenuItem *menuitem, gpointer user_data)
315 dialogs_show_open_file();
319 /* reload file */
320 void on_toolbutton_reload_clicked(GtkAction *action, gpointer user_data)
322 GeanyDocument *doc = document_get_current();
324 g_return_if_fail(doc != NULL);
326 document_reload_prompt(doc, NULL);
330 static void on_change_font1_activate(GtkMenuItem *menuitem, gpointer user_data)
332 dialogs_show_open_font();
336 /* store text, clear search flags so we can use Search->Find Next/Previous */
337 static void setup_find(const gchar *text, gboolean backwards)
339 SETPTR(search_data.text, g_strdup(text));
340 SETPTR(search_data.original_text, g_strdup(text));
341 search_data.flags = 0;
342 search_data.backwards = backwards;
343 search_data.search_bar = TRUE;
347 static void do_toolbar_search(const gchar *text, gboolean incremental, gboolean backwards)
349 GeanyDocument *doc = document_get_current();
350 gboolean result;
352 setup_find(text, backwards);
353 result = document_search_bar_find(doc, search_data.text, incremental, backwards);
354 if (search_data.search_bar)
355 ui_set_search_entry_background(toolbar_get_widget_child_by_name("SearchEntry"), result);
359 /* search text */
360 void on_toolbar_search_entry_changed(GtkAction *action, const gchar *text, gpointer user_data)
362 do_toolbar_search(text, TRUE, FALSE);
366 /* search text */
367 void on_toolbar_search_entry_activate(GtkAction *action, const gchar *text, gpointer user_data)
369 do_toolbar_search(text, FALSE, GPOINTER_TO_INT(user_data));
373 /* search text */
374 void on_toolbutton_search_clicked(GtkAction *action, gpointer user_data)
376 GeanyDocument *doc = document_get_current();
377 gboolean result;
378 GtkWidget *entry = toolbar_get_widget_child_by_name("SearchEntry");
380 if (entry != NULL)
382 const gchar *text = gtk_entry_get_text(GTK_ENTRY(entry));
384 setup_find(text, FALSE);
385 result = document_search_bar_find(doc, search_data.text, FALSE, FALSE);
386 if (search_data.search_bar)
387 ui_set_search_entry_background(entry, result);
389 else
390 on_find1_activate(NULL, NULL);
394 /* hides toolbar from toolbar popup menu */
395 static void on_hide_toolbar1_activate(GtkMenuItem *menuitem, gpointer user_data)
397 GtkWidget *tool_item = ui_lookup_widget(GTK_WIDGET(main_widgets.window), "menu_show_toolbar1");
398 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(tool_item), FALSE);
402 /* zoom in from menu bar and popup menu */
403 void on_zoom_in1_activate(GtkMenuItem *menuitem, gpointer user_data)
405 GeanyDocument *doc = document_get_current();
407 g_return_if_fail(doc != NULL);
409 sci_zoom_in(doc->editor->sci);
413 /* zoom out from menu bar and popup menu */
414 void on_zoom_out1_activate(GtkMenuItem *menuitem, gpointer user_data)
416 GeanyDocument *doc = document_get_current();
418 g_return_if_fail(doc != NULL);
420 sci_zoom_out(doc->editor->sci);
424 void on_normal_size1_activate(GtkMenuItem *menuitem, gpointer user_data)
426 GeanyDocument *doc = document_get_current();
428 g_return_if_fail(doc != NULL);
430 sci_zoom_off(doc->editor->sci);
434 /* Changes window-title after switching tabs and lots of other things.
435 * note: using 'after' makes Scintilla redraw before the UI, appearing more responsive */
436 static void on_notebook1_switch_page_after(GtkNotebook *notebook, gpointer page,
437 guint page_num, gpointer user_data)
439 GeanyDocument *doc;
441 if (G_UNLIKELY(main_status.opening_session_files || main_status.closing_all))
442 return;
444 doc = document_get_from_notebook_child(page);
446 if (doc != NULL)
448 sidebar_select_openfiles_item(doc);
449 ui_save_buttons_toggle(doc->changed);
450 ui_set_window_title(doc);
451 ui_update_statusbar(doc, -1);
452 ui_update_popup_reundo_items(doc);
453 ui_document_show_hide(doc); /* update the document menu */
454 build_menu_update(doc);
455 sidebar_update_tag_list(doc, FALSE);
456 document_highlight_tags(doc);
458 document_check_disk_status(doc, TRUE);
460 #ifdef HAVE_VTE
461 vte_cwd((doc->real_path != NULL) ? doc->real_path : doc->file_name, FALSE);
462 #endif
464 g_signal_emit_by_name(geany_object, "document-activate", doc);
469 static void on_tv_notebook_switch_page(GtkNotebook *notebook, gpointer page,
470 guint page_num, gpointer user_data)
472 /* suppress selection changed signal when switching to the open files list */
473 ignore_callback = TRUE;
477 static void on_tv_notebook_switch_page_after(GtkNotebook *notebook, gpointer page,
478 guint page_num, gpointer user_data)
480 ignore_callback = FALSE;
484 static void convert_eol(gint mode)
486 GeanyDocument *doc = document_get_current();
488 g_return_if_fail(doc != NULL);
490 sci_convert_eols(doc->editor->sci, mode);
491 sci_set_eol_mode(doc->editor->sci, mode);
492 ui_update_statusbar(doc, -1);
496 static void on_crlf_activate(GtkCheckMenuItem *menuitem, gpointer user_data)
498 if (ignore_callback || ! gtk_check_menu_item_get_active(menuitem))
499 return;
501 convert_eol(SC_EOL_CRLF);
505 static void on_lf_activate(GtkCheckMenuItem *menuitem, gpointer user_data)
507 if (ignore_callback || ! gtk_check_menu_item_get_active(menuitem))
508 return;
510 convert_eol(SC_EOL_LF);
514 static void on_cr_activate(GtkCheckMenuItem *menuitem, gpointer user_data)
516 if (ignore_callback || ! gtk_check_menu_item_get_active(menuitem))
517 return;
519 convert_eol(SC_EOL_CR);
523 void on_replace_tabs_activate(GtkMenuItem *menuitem, gpointer user_data)
525 GeanyDocument *doc = document_get_current();
527 g_return_if_fail(doc != NULL);
529 editor_replace_tabs(doc->editor, FALSE);
533 gboolean toolbar_popup_menu(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
535 if (event->button == 3)
537 gtk_menu_popup(GTK_MENU(ui_widgets.toolbar_menu), NULL, NULL, NULL, NULL, event->button, event->time);
538 return TRUE;
540 return FALSE;
544 void on_toggle_case1_activate(GtkMenuItem *menuitem, gpointer user_data)
546 GeanyDocument *doc = document_get_current();
547 ScintillaObject *sci;
548 gchar *text;
549 gboolean keep_sel = TRUE;
551 g_return_if_fail(doc != NULL);
553 sci = doc->editor->sci;
554 if (! sci_has_selection(sci))
556 keybindings_send_command(GEANY_KEY_GROUP_SELECT, GEANY_KEYS_SELECT_WORD);
557 keep_sel = FALSE;
560 /* either we already had a selection or we created one for current word */
561 if (sci_has_selection(sci))
563 gchar *result = NULL;
564 gint cmd = SCI_LOWERCASE;
565 gboolean rectsel = (gboolean) scintilla_send_message(sci, SCI_SELECTIONISRECTANGLE, 0, 0);
567 text = sci_get_selection_contents(sci);
569 if (utils_str_has_upper(text))
571 if (rectsel)
572 cmd = SCI_LOWERCASE;
573 else
574 result = g_utf8_strdown(text, -1);
576 else
578 if (rectsel)
579 cmd = SCI_UPPERCASE;
580 else
581 result = g_utf8_strup(text, -1);
584 if (result != NULL)
586 sci_replace_sel(sci, result);
587 g_free(result);
588 if (keep_sel)
589 sci_set_selection_start(sci, sci_get_current_position(sci) - strlen(text));
591 else
592 sci_send_command(sci, cmd);
594 g_free(text);
600 static void on_show_toolbar1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
602 if (ignore_callback) return;
604 toolbar_prefs.visible = (toolbar_prefs.visible) ? FALSE : TRUE;;
605 ui_widget_show_hide(GTK_WIDGET(main_widgets.toolbar), toolbar_prefs.visible);
609 static void on_fullscreen1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
611 if (ignore_callback)
612 return;
614 ui_prefs.fullscreen = (ui_prefs.fullscreen) ? FALSE : TRUE;
615 ui_set_fullscreen();
619 static void on_show_messages_window1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
621 if (ignore_callback)
622 return;
624 ui_prefs.msgwindow_visible = (ui_prefs.msgwindow_visible) ? FALSE : TRUE;
625 msgwin_show_hide(ui_prefs.msgwindow_visible);
629 static void on_menu_color_schemes_activate(GtkImageMenuItem *imagemenuitem, gpointer user_data)
631 highlighting_show_color_scheme_dialog();
635 static void on_markers_margin1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
637 if (ignore_callback)
638 return;
640 editor_prefs.show_markers_margin = ! editor_prefs.show_markers_margin;
641 ui_toggle_editor_features(GEANY_EDITOR_SHOW_MARKERS_MARGIN);
645 static void on_show_line_numbers1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
647 if (ignore_callback)
648 return;
650 editor_prefs.show_linenumber_margin = ! editor_prefs.show_linenumber_margin;
651 ui_toggle_editor_features(GEANY_EDITOR_SHOW_LINE_NUMBERS);
655 static void on_menu_show_white_space1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
657 if (ignore_callback)
658 return;
660 editor_prefs.show_white_space = ! editor_prefs.show_white_space;
661 ui_toggle_editor_features(GEANY_EDITOR_SHOW_WHITE_SPACE);
665 static void on_menu_show_line_endings1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
667 if (ignore_callback)
668 return;
670 editor_prefs.show_line_endings = ! editor_prefs.show_line_endings;
671 ui_toggle_editor_features(GEANY_EDITOR_SHOW_LINE_ENDINGS);
675 static void on_menu_show_indentation_guides1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
677 if (ignore_callback)
678 return;
680 editor_prefs.show_indent_guide = ! editor_prefs.show_indent_guide;
681 ui_toggle_editor_features(GEANY_EDITOR_SHOW_INDENTATION_GUIDES);
685 void on_line_wrapping1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
687 if (! ignore_callback)
689 GeanyDocument *doc = document_get_current();
690 g_return_if_fail(doc != NULL);
692 editor_set_line_wrapping(doc->editor, ! doc->editor->line_wrapping);
697 static void on_set_file_readonly1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
699 if (! ignore_callback)
701 GeanyDocument *doc = document_get_current();
702 g_return_if_fail(doc != NULL);
704 doc->readonly = ! doc->readonly;
705 sci_set_readonly(doc->editor->sci, doc->readonly);
706 ui_update_tab_status(doc);
707 ui_update_statusbar(doc, -1);
712 static void on_use_auto_indentation1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
714 if (! ignore_callback)
716 GeanyDocument *doc = document_get_current();
717 g_return_if_fail(doc != NULL);
719 doc->editor->auto_indent = ! doc->editor->auto_indent;
724 static void find_usage(gboolean in_session)
726 GeanyFindFlags flags;
727 gchar *search_text;
728 GeanyDocument *doc = document_get_current();
730 g_return_if_fail(doc != NULL);
732 if (sci_has_selection(doc->editor->sci))
733 { /* take selected text if there is a selection */
734 search_text = sci_get_selection_contents(doc->editor->sci);
735 flags = GEANY_FIND_MATCHCASE;
737 else
739 editor_find_current_word_sciwc(doc->editor, -1,
740 editor_info.current_word, GEANY_MAX_WORD_LENGTH);
741 search_text = g_strdup(editor_info.current_word);
742 flags = GEANY_FIND_MATCHCASE | GEANY_FIND_WHOLEWORD;
745 search_find_usage(search_text, search_text, flags, in_session);
746 g_free(search_text);
750 void on_find_document_usage1_activate(GtkMenuItem *menuitem, gpointer user_data)
752 find_usage(FALSE);
756 void on_find_usage1_activate(GtkMenuItem *menuitem, gpointer user_data)
758 find_usage(TRUE);
762 static void goto_tag(gboolean definition)
764 GeanyDocument *doc = document_get_current();
766 g_return_if_fail(doc != NULL);
768 /* update cursor pos for navigating back afterwards */
769 if (!sci_has_selection(doc->editor->sci))
770 sci_set_current_position(doc->editor->sci, editor_info.click_pos, FALSE);
772 /* use the keybinding callback as it checks for selections as well as current word */
773 if (definition)
774 keybindings_send_command(GEANY_KEY_GROUP_GOTO, GEANY_KEYS_GOTO_TAGDEFINITION);
775 else
776 keybindings_send_command(GEANY_KEY_GROUP_GOTO, GEANY_KEYS_GOTO_TAGDECLARATION);
780 static void on_goto_tag_definition1(GtkMenuItem *menuitem, gpointer user_data)
782 goto_tag(TRUE);
786 static void on_goto_tag_declaration1(GtkMenuItem *menuitem, gpointer user_data)
788 goto_tag(FALSE);
792 static void on_count_words1_activate(GtkMenuItem *menuitem, gpointer user_data)
794 tools_word_count();
798 void on_show_color_chooser1_activate(GtkMenuItem *menuitem, gpointer user_data)
800 gchar colour[9];
801 GeanyDocument *doc = document_get_current();
802 gint pos;
804 g_return_if_fail(doc != NULL);
806 pos = sci_get_current_position(doc->editor->sci);
807 editor_find_current_word(doc->editor, pos, colour, sizeof colour, GEANY_WORDCHARS"#");
808 tools_color_chooser(colour);
812 void on_toolbutton_compile_clicked(GtkAction *action, gpointer user_data)
814 keybindings_send_command(GEANY_KEY_GROUP_BUILD, GEANY_KEYS_BUILD_COMPILE);
818 void on_find1_activate(GtkMenuItem *menuitem, gpointer user_data)
820 search_show_find_dialog();
824 void on_find_next1_activate(GtkMenuItem *menuitem, gpointer user_data)
826 search_find_again(FALSE);
830 void on_find_previous1_activate(GtkMenuItem *menuitem, gpointer user_data)
832 if (search_data.flags & GEANY_FIND_REGEXP)
833 /* Can't reverse search order for a regex (find next ignores search backwards) */
834 utils_beep();
835 else
836 search_find_again(TRUE);
840 void on_find_nextsel1_activate(GtkMenuItem *menuitem, gpointer user_data)
842 search_find_selection(document_get_current(), FALSE);
846 void on_find_prevsel1_activate(GtkMenuItem *menuitem, gpointer user_data)
848 search_find_selection(document_get_current(), TRUE);
852 void on_replace1_activate(GtkMenuItem *menuitem, gpointer user_data)
854 search_show_replace_dialog();
858 void on_find_in_files1_activate(GtkMenuItem *menuitem, gpointer user_data)
860 search_show_find_in_files_dialog(NULL);
864 static void get_line_and_offset_from_text(const gchar *text, gint *line_no, gint *offset)
866 if (*text == '+' || *text == '-')
868 *line_no = atoi(text + 1);
869 *offset = (*text == '+') ? 1 : -1;
871 else
873 *line_no = atoi(text) - 1;
874 *offset = 0;
879 void on_go_to_line_activate(GtkMenuItem *menuitem, gpointer user_data)
881 static gchar value[16] = "";
882 gchar *result;
884 result = dialogs_show_input_goto_line(
885 _("Go to Line"), GTK_WINDOW(main_widgets.window),
886 _("Enter the line you want to go to:"), value);
887 if (result != NULL)
889 GeanyDocument *doc = document_get_current();
890 gint offset;
891 gint line_no;
893 g_return_if_fail(doc != NULL);
895 get_line_and_offset_from_text(result, &line_no, &offset);
896 if (! editor_goto_line(doc->editor, line_no, offset))
897 utils_beep();
898 /* remember value for future calls */
899 g_snprintf(value, sizeof(value), "%s", result);
901 g_free(result);
906 void on_toolbutton_goto_entry_activate(GtkAction *action, const gchar *text, gpointer user_data)
908 GeanyDocument *doc = document_get_current();
909 gint offset;
910 gint line_no;
912 g_return_if_fail(doc != NULL);
914 get_line_and_offset_from_text(text, &line_no, &offset);
915 if (! editor_goto_line(doc->editor, line_no, offset))
916 utils_beep();
917 else
918 keybindings_send_command(GEANY_KEY_GROUP_FOCUS, GEANY_KEYS_FOCUS_EDITOR);
922 void on_toolbutton_goto_clicked(GtkAction *action, gpointer user_data)
924 GtkWidget *entry = toolbar_get_widget_child_by_name("GotoEntry");
926 if (entry != NULL)
928 const gchar *text = gtk_entry_get_text(GTK_ENTRY(entry));
930 on_toolbutton_goto_entry_activate(NULL, text, NULL);
932 else
933 on_go_to_line_activate(NULL, NULL);
937 void on_help1_activate(GtkMenuItem *menuitem, gpointer user_data)
939 gchar *uri;
941 uri = utils_get_help_url(NULL);
942 utils_open_browser(uri);
943 g_free(uri);
947 static void on_help_shortcuts1_activate(GtkMenuItem *menuitem, gpointer user_data)
949 keybindings_show_shortcuts();
953 static void on_website1_activate(GtkMenuItem *menuitem, gpointer user_data)
955 utils_open_browser(GEANY_HOMEPAGE);
959 static void on_help_menu_item_donate_activate(GtkMenuItem *item, gpointer user_data)
961 utils_open_browser(GEANY_DONATE);
965 static void on_help_menu_item_wiki_activate(GtkMenuItem *item, gpointer user_data)
967 utils_open_browser(GEANY_WIKI);
971 static void on_help_menu_item_bug_report_activate(GtkMenuItem *item, gpointer user_data)
973 utils_open_browser(GEANY_BUG_REPORT);
977 static void on_comments_function_activate(GtkMenuItem *menuitem, gpointer user_data)
979 GeanyDocument *doc = document_get_current();
980 gchar *text;
981 const gchar *cur_tag = NULL;
982 gint line = -1, pos = 0;
984 if (doc == NULL || doc->file_type == NULL)
986 ui_set_statusbar(FALSE,
987 _("Please set the filetype for the current file before using this function."));
988 return;
991 /* symbols_get_current_function returns -1 on failure, so sci_get_position_from_line
992 * returns the current position, so it should be safe */
993 line = symbols_get_current_function(doc, &cur_tag);
994 pos = sci_get_position_from_line(doc->editor->sci, line);
996 text = templates_get_template_function(doc, cur_tag);
998 sci_start_undo_action(doc->editor->sci);
999 sci_insert_text(doc->editor->sci, pos, text);
1000 sci_end_undo_action(doc->editor->sci);
1001 g_free(text);
1005 static void insert_multiline_comment(GeanyDocument *doc, gint pos)
1007 g_return_if_fail(doc != NULL);
1008 g_return_if_fail(pos == -1 || pos >= 0);
1010 if (doc->file_type == NULL)
1012 ui_set_statusbar(FALSE,
1013 _("Please set the filetype for the current file before using this function."));
1014 return;
1017 if (doc->file_type->comment_open || doc->file_type->comment_single)
1019 /* editor_insert_multiline_comment() uses editor_info.click_pos */
1020 if (pos == -1)
1021 editor_info.click_pos = sci_get_current_position(doc->editor->sci);
1022 else
1023 editor_info.click_pos = pos;
1024 editor_insert_multiline_comment(doc->editor);
1026 else
1027 utils_beep();
1031 static void on_comments_multiline_activate(GtkMenuItem *menuitem, gpointer user_data)
1033 insert_multiline_comment(document_get_current(), editor_info.click_pos);
1037 static void on_menu_comments_multiline_activate(GtkMenuItem *menuitem, gpointer user_data)
1039 insert_multiline_comment(document_get_current(), -1);
1043 static void insert_comment_template(GeanyDocument *doc, gint pos, guint template)
1045 gchar *text;
1047 g_return_if_fail(doc != NULL);
1048 g_return_if_fail(pos == -1 || pos >= 0);
1049 g_return_if_fail(template < GEANY_MAX_TEMPLATES);
1051 if (pos == -1)
1052 pos = sci_get_current_position(doc->editor->sci);
1054 text = templates_get_template_licence(doc, template);
1056 sci_start_undo_action(doc->editor->sci);
1057 sci_insert_text(doc->editor->sci, pos, text);
1058 sci_end_undo_action(doc->editor->sci);
1059 g_free(text);
1063 static void on_comments_gpl_activate(GtkMenuItem *menuitem, gpointer user_data)
1065 insert_comment_template(document_get_current(), editor_info.click_pos, GEANY_TEMPLATE_GPL);
1069 static void on_menu_comments_gpl_activate(GtkMenuItem *menuitem, gpointer user_data)
1071 insert_comment_template(document_get_current(), -1, GEANY_TEMPLATE_GPL);
1075 static void on_comments_bsd_activate(GtkMenuItem *menuitem, gpointer user_data)
1077 insert_comment_template(document_get_current(), editor_info.click_pos, GEANY_TEMPLATE_BSD);
1081 static void on_menu_comments_bsd_activate(GtkMenuItem *menuitem, gpointer user_data)
1083 insert_comment_template(document_get_current(), -1, GEANY_TEMPLATE_BSD);
1087 static void on_comments_changelog_activate(GtkMenuItem *menuitem, gpointer user_data)
1089 GeanyDocument *doc = document_get_current();
1090 gchar *text;
1092 g_return_if_fail(doc != NULL);
1094 text = templates_get_template_changelog(doc);
1095 sci_start_undo_action(doc->editor->sci);
1096 sci_insert_text(doc->editor->sci, 0, text);
1097 /* sets the cursor to the right position to type the changelog text,
1098 * the template has 21 chars + length of name and email */
1099 sci_goto_pos(doc->editor->sci, 21 + strlen(template_prefs.developer) + strlen(template_prefs.mail), TRUE);
1100 sci_end_undo_action(doc->editor->sci);
1102 g_free(text);
1106 static void on_comments_fileheader_activate(GtkMenuItem *menuitem, gpointer user_data)
1108 GeanyDocument *doc = document_get_current();
1109 gchar *text;
1110 const gchar *fname;
1111 GeanyFiletype *ft;
1113 g_return_if_fail(doc != NULL);
1115 ft = doc->file_type;
1116 fname = doc->file_name;
1117 text = templates_get_template_fileheader(FILETYPE_ID(ft), fname);
1119 sci_start_undo_action(doc->editor->sci);
1120 sci_insert_text(doc->editor->sci, 0, text);
1121 sci_goto_pos(doc->editor->sci, 0, FALSE);
1122 sci_end_undo_action(doc->editor->sci);
1123 g_free(text);
1127 void on_file_properties_activate(GtkMenuItem *menuitem, gpointer user_data)
1129 GeanyDocument *doc = document_get_current();
1130 g_return_if_fail(doc != NULL);
1132 dialogs_show_file_properties(doc);
1136 static void on_menu_fold_all1_activate(GtkMenuItem *menuitem, gpointer user_data)
1138 GeanyDocument *doc = document_get_current();
1139 g_return_if_fail(doc != NULL);
1141 editor_fold_all(doc->editor);
1145 static void on_menu_unfold_all1_activate(GtkMenuItem *menuitem, gpointer user_data)
1147 GeanyDocument *doc = document_get_current();
1148 g_return_if_fail(doc != NULL);
1150 editor_unfold_all(doc->editor);
1154 void on_toolbutton_run_clicked(GtkAction *action, gpointer user_data)
1156 keybindings_send_command(GEANY_KEY_GROUP_BUILD, GEANY_KEYS_BUILD_RUN);
1160 void on_menu_remove_indicators1_activate(GtkMenuItem *menuitem, gpointer user_data)
1162 GeanyDocument *doc = document_get_current();
1163 g_return_if_fail(doc != NULL);
1165 editor_indicator_clear(doc->editor, GEANY_INDICATOR_ERROR);
1169 void on_print1_activate(GtkMenuItem *menuitem, gpointer user_data)
1171 GeanyDocument *doc = document_get_current();
1172 g_return_if_fail(doc != NULL);
1174 printing_print_doc(doc);
1178 void on_menu_select_all1_activate(GtkMenuItem *menuitem, gpointer user_data)
1180 GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
1182 /* special case for Select All in the scribble widget */
1183 if (GTK_IS_TEXT_VIEW(focusw))
1185 g_signal_emit_by_name(focusw, "select-all", TRUE);
1187 /* special case for Select All in the VTE widget */
1188 #ifdef HAVE_VTE
1189 else if (vte_info.have_vte && focusw == vc->vte)
1191 vte_select_all();
1193 #endif
1194 else if (GTK_IS_EDITABLE(focusw))
1196 gtk_editable_select_region(GTK_EDITABLE(focusw), 0, -1);
1198 else if (IS_SCINTILLA(focusw))
1200 sci_select_all(SCINTILLA(focusw));
1205 void on_menu_show_sidebar1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
1207 if (ignore_callback)
1208 return;
1210 ui_prefs.sidebar_visible = ! ui_prefs.sidebar_visible;
1212 /* show built-in tabs if no tabs visible */
1213 if (ui_prefs.sidebar_visible &&
1214 ! interface_prefs.sidebar_openfiles_visible && ! interface_prefs.sidebar_symbol_visible &&
1215 gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.sidebar_notebook)) <= 2)
1217 interface_prefs.sidebar_openfiles_visible = TRUE;
1218 interface_prefs.sidebar_symbol_visible = TRUE;
1221 /* if window has input focus, set it back to the editor before toggling off */
1222 if (! ui_prefs.sidebar_visible &&
1223 gtk_container_get_focus_child(GTK_CONTAINER(main_widgets.sidebar_notebook)) != NULL)
1225 keybindings_send_command(GEANY_KEY_GROUP_FOCUS, GEANY_KEYS_FOCUS_EDITOR);
1228 ui_sidebar_show_hide();
1232 static void on_menu_write_unicode_bom1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
1234 if (! ignore_callback)
1236 GeanyDocument *doc = document_get_current();
1238 g_return_if_fail(doc != NULL);
1239 if (doc->readonly)
1241 utils_beep();
1242 return;
1245 document_undo_add(doc, UNDO_BOM, GINT_TO_POINTER(doc->has_bom));
1247 doc->has_bom = ! doc->has_bom;
1249 ui_update_statusbar(doc, -1);
1254 void on_menu_comment_line1_activate(GtkMenuItem *menuitem, gpointer user_data)
1256 GeanyDocument *doc = document_get_current();
1257 g_return_if_fail(doc != NULL);
1259 editor_do_comment(doc->editor, -1, FALSE, FALSE, TRUE);
1263 void on_menu_uncomment_line1_activate(GtkMenuItem *menuitem, gpointer user_data)
1265 GeanyDocument *doc = document_get_current();
1266 g_return_if_fail(doc != NULL);
1268 editor_do_uncomment(doc->editor, -1, FALSE);
1272 void on_menu_toggle_line_commentation1_activate(GtkMenuItem *menuitem, gpointer user_data)
1274 GeanyDocument *doc = document_get_current();
1275 g_return_if_fail(doc != NULL);
1277 editor_do_comment_toggle(doc->editor);
1281 void on_menu_increase_indent1_activate(GtkMenuItem *menuitem, gpointer user_data)
1283 GeanyDocument *doc = document_get_current();
1284 g_return_if_fail(doc != NULL);
1286 editor_indent(doc->editor, TRUE);
1290 void on_menu_decrease_indent1_activate(GtkMenuItem *menuitem, gpointer user_data)
1292 GeanyDocument *doc = document_get_current();
1293 g_return_if_fail(doc != NULL);
1295 editor_indent(doc->editor, FALSE);
1299 void on_next_message1_activate(GtkMenuItem *menuitem, gpointer user_data)
1301 if (! ui_tree_view_find_next(GTK_TREE_VIEW(msgwindow.tree_msg),
1302 msgwin_goto_messages_file_line))
1303 ui_set_statusbar(FALSE, _("No more message items."));
1307 void on_previous_message1_activate(GtkMenuItem *menuitem, gpointer user_data)
1309 if (! ui_tree_view_find_previous(GTK_TREE_VIEW(msgwindow.tree_msg),
1310 msgwin_goto_messages_file_line))
1311 ui_set_statusbar(FALSE, _("No more message items."));
1315 void on_project_new1_activate(GtkMenuItem *menuitem, gpointer user_data)
1317 project_new();
1321 void on_project_open1_activate(GtkMenuItem *menuitem, gpointer user_data)
1323 project_open();
1327 void on_project_close1_activate(GtkMenuItem *menuitem, gpointer user_data)
1329 project_close(TRUE);
1333 void on_project_properties1_activate(GtkMenuItem *menuitem, gpointer user_data)
1335 project_properties();
1339 static void on_menu_project1_activate(GtkMenuItem *menuitem, gpointer user_data)
1341 static GtkWidget *item_close = NULL;
1342 static GtkWidget *item_properties = NULL;
1344 if (item_close == NULL)
1346 item_close = ui_lookup_widget(main_widgets.window, "project_close1");
1347 item_properties = ui_lookup_widget(main_widgets.window, "project_properties1");
1350 gtk_widget_set_sensitive(item_close, (app->project != NULL));
1351 gtk_widget_set_sensitive(item_properties, (app->project != NULL));
1352 gtk_widget_set_sensitive(ui_widgets.recent_projects_menuitem,
1353 g_queue_get_length(ui_prefs.recent_projects_queue) > 0);
1357 void on_menu_open_selected_file1_activate(GtkMenuItem *menuitem, gpointer user_data)
1359 GeanyDocument *doc = document_get_current();
1360 gchar *sel = NULL;
1361 const gchar *wc;
1363 #ifdef G_OS_WIN32
1364 wc = GEANY_WORDCHARS "./-" "\\";
1365 #else
1366 wc = GEANY_WORDCHARS "./-";
1367 #endif
1369 g_return_if_fail(doc != NULL);
1371 sel = editor_get_default_selection(doc->editor, TRUE, wc);
1372 SETPTR(sel, utils_get_locale_from_utf8(sel));
1374 if (sel != NULL)
1376 gchar *filename = NULL;
1378 if (g_path_is_absolute(sel))
1379 filename = g_strdup(sel);
1380 else
1381 { /* relative filename, add the path of the current file */
1382 gchar *path;
1384 path = utils_get_current_file_dir_utf8();
1385 SETPTR(path, utils_get_locale_from_utf8(path));
1386 if (!path)
1387 path = g_get_current_dir();
1389 filename = g_build_path(G_DIR_SEPARATOR_S, path, sel, NULL);
1391 if (! g_file_test(filename, G_FILE_TEST_EXISTS) &&
1392 app->project != NULL && !EMPTY(app->project->base_path))
1394 /* try the project's base path */
1395 SETPTR(path, project_get_base_path());
1396 SETPTR(path, utils_get_locale_from_utf8(path));
1397 SETPTR(filename, g_build_path(G_DIR_SEPARATOR_S, path, sel, NULL));
1399 g_free(path);
1400 #ifdef G_OS_UNIX
1401 if (! g_file_test(filename, G_FILE_TEST_EXISTS))
1402 SETPTR(filename, g_build_path(G_DIR_SEPARATOR_S, "/usr/local/include", sel, NULL));
1404 if (! g_file_test(filename, G_FILE_TEST_EXISTS))
1405 SETPTR(filename, g_build_path(G_DIR_SEPARATOR_S, "/usr/include", sel, NULL));
1406 #endif
1409 if (g_file_test(filename, G_FILE_TEST_EXISTS))
1410 document_open_file(filename, FALSE, NULL, NULL);
1411 else
1413 SETPTR(sel, utils_get_utf8_from_locale(sel));
1414 ui_set_statusbar(TRUE, _("Could not open file %s (File not found)"), sel);
1417 g_free(filename);
1418 g_free(sel);
1423 void on_remove_markers1_activate(GtkMenuItem *menuitem, gpointer user_data)
1425 GeanyDocument *doc = document_get_current();
1426 g_return_if_fail(doc != NULL);
1428 sci_marker_delete_all(doc->editor->sci, 0); /* delete the yellow tag marker */
1429 sci_marker_delete_all(doc->editor->sci, 1); /* delete user markers */
1430 editor_indicator_clear(doc->editor, GEANY_INDICATOR_SEARCH);
1434 static void on_load_tags1_activate(GtkMenuItem *menuitem, gpointer user_data)
1436 symbols_show_load_tags_dialog();
1440 void on_context_action1_activate(GtkMenuItem *menuitem, gpointer user_data)
1442 gchar *word, *command;
1443 GError *error = NULL;
1444 GeanyDocument *doc = document_get_current();
1445 const gchar *check_msg;
1447 g_return_if_fail(doc != NULL);
1449 if (sci_has_selection(doc->editor->sci))
1450 { /* take selected text if there is a selection */
1451 word = sci_get_selection_contents(doc->editor->sci);
1453 else
1455 word = g_strdup(editor_info.current_word);
1458 /* use the filetype specific command if available, fallback to global command otherwise */
1459 if (doc->file_type != NULL &&
1460 !EMPTY(doc->file_type->context_action_cmd))
1462 command = g_strdup(doc->file_type->context_action_cmd);
1463 check_msg = _("Check the path setting in Filetype configuration.");
1465 else
1467 command = g_strdup(tool_prefs.context_action_cmd);
1468 check_msg = _("Check the path setting in Preferences.");
1471 /* substitute the wildcard %s and run the command if it is non empty */
1472 if (G_LIKELY(!EMPTY(command)))
1474 gchar *command_line = g_strdup(command);
1476 utils_str_replace_all(&command_line, "%s", word);
1478 if (!spawn_async(NULL, command_line, NULL, NULL, NULL, &error))
1480 /* G_SHELL_ERROR is parsing error, it may be caused by %s word with quotes */
1481 ui_set_statusbar(TRUE, _("Cannot execute context action command \"%s\": %s. %s"),
1482 error->domain == G_SHELL_ERROR ? command_line : command, error->message,
1483 check_msg);
1484 g_error_free(error);
1486 g_free(command_line);
1488 g_free(word);
1489 g_free(command);
1493 void on_menu_toggle_all_additional_widgets1_activate(GtkMenuItem *menuitem, gpointer user_data)
1495 static gint hide_all = -1;
1496 GtkCheckMenuItem *msgw = GTK_CHECK_MENU_ITEM(
1497 ui_lookup_widget(main_widgets.window, "menu_show_messages_window1"));
1498 GtkCheckMenuItem *toolbari = GTK_CHECK_MENU_ITEM(
1499 ui_lookup_widget(main_widgets.window, "menu_show_toolbar1"));
1501 /* get the initial state (necessary if Geany was closed with hide_all = TRUE) */
1502 if (G_UNLIKELY(hide_all == -1))
1504 if (! gtk_check_menu_item_get_active(msgw) &&
1505 ! interface_prefs.show_notebook_tabs &&
1506 ! gtk_check_menu_item_get_active(toolbari))
1508 hide_all = TRUE;
1510 else
1511 hide_all = FALSE;
1514 hide_all = ! hide_all; /* toggle */
1516 if (hide_all)
1518 if (gtk_check_menu_item_get_active(msgw))
1519 gtk_check_menu_item_set_active(msgw, ! gtk_check_menu_item_get_active(msgw));
1521 interface_prefs.show_notebook_tabs = FALSE;
1522 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets.notebook), interface_prefs.show_notebook_tabs);
1524 ui_statusbar_showhide(FALSE);
1526 if (gtk_check_menu_item_get_active(toolbari))
1527 gtk_check_menu_item_set_active(toolbari, ! gtk_check_menu_item_get_active(toolbari));
1529 else
1532 if (! gtk_check_menu_item_get_active(msgw))
1533 gtk_check_menu_item_set_active(msgw, ! gtk_check_menu_item_get_active(msgw));
1535 interface_prefs.show_notebook_tabs = TRUE;
1536 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets.notebook), interface_prefs.show_notebook_tabs);
1538 ui_statusbar_showhide(TRUE);
1540 if (! gtk_check_menu_item_get_active(toolbari))
1541 gtk_check_menu_item_set_active(toolbari, ! gtk_check_menu_item_get_active(toolbari));
1546 void on_toolbutton_forward_activate(GtkAction *menuitem, gpointer user_data)
1548 navqueue_go_forward();
1552 void on_toolbutton_back_activate(GtkAction *menuitem, gpointer user_data)
1554 navqueue_go_back();
1558 gboolean on_motion_event(GtkWidget *widget, GdkEventMotion *event, gpointer user_data)
1560 if (prefs.auto_focus && ! gtk_widget_has_focus(widget))
1561 gtk_widget_grab_focus(widget);
1563 return FALSE;
1567 static void set_indent_type(GtkCheckMenuItem *menuitem, GeanyIndentType type)
1569 GeanyDocument *doc;
1571 if (ignore_callback || ! gtk_check_menu_item_get_active(menuitem))
1572 return;
1574 doc = document_get_current();
1575 g_return_if_fail(doc != NULL);
1577 editor_set_indent(doc->editor, type, doc->editor->indent_width);
1578 ui_update_statusbar(doc, -1);
1582 static void on_tabs1_activate(GtkCheckMenuItem *menuitem, gpointer user_data)
1584 set_indent_type(menuitem, GEANY_INDENT_TYPE_TABS);
1588 static void on_spaces1_activate(GtkCheckMenuItem *menuitem, gpointer user_data)
1590 set_indent_type(menuitem, GEANY_INDENT_TYPE_SPACES);
1594 static void on_tabs_and_spaces1_activate(GtkCheckMenuItem *menuitem, gpointer user_data)
1596 set_indent_type(menuitem, GEANY_INDENT_TYPE_BOTH);
1600 static void on_strip_trailing_spaces1_activate(GtkMenuItem *menuitem, gpointer user_data)
1602 GeanyDocument *doc;
1604 if (ignore_callback)
1605 return;
1607 doc = document_get_current();
1608 g_return_if_fail(doc != NULL);
1610 editor_strip_trailing_spaces(doc->editor, FALSE);
1614 static void on_page_setup1_activate(GtkMenuItem *menuitem, gpointer user_data)
1616 printing_page_setup_gtk();
1620 gboolean on_escape_key_press_event(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
1622 guint state = keybindings_get_modifiers(event->state);
1624 /* make pressing escape in the sidebar and toolbar focus the editor */
1625 if (event->keyval == GDK_Escape && state == 0)
1627 keybindings_send_command(GEANY_KEY_GROUP_FOCUS, GEANY_KEYS_FOCUS_EDITOR);
1628 return TRUE;
1630 return FALSE;
1634 void on_line_breaking1_activate(GtkMenuItem *menuitem, gpointer user_data)
1636 GeanyDocument *doc;
1638 if (ignore_callback)
1639 return;
1641 doc = document_get_current();
1642 g_return_if_fail(doc != NULL);
1644 doc->editor->line_breaking = !doc->editor->line_breaking;
1648 void on_replace_spaces_activate(GtkMenuItem *menuitem, gpointer user_data)
1650 GeanyDocument *doc = document_get_current();
1652 g_return_if_fail(doc != NULL);
1654 editor_replace_spaces(doc->editor, FALSE);
1658 static void on_search1_activate(GtkMenuItem *menuitem, gpointer user_data)
1660 GtkWidget *next_message = ui_lookup_widget(main_widgets.window, "next_message1");
1661 GtkWidget *previous_message = ui_lookup_widget(main_widgets.window, "previous_message1");
1662 gboolean have_messages;
1664 /* enable commands if the messages window has any items */
1665 have_messages = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(msgwindow.store_msg),
1666 NULL) > 0;
1668 gtk_widget_set_sensitive(next_message, have_messages);
1669 gtk_widget_set_sensitive(previous_message, have_messages);
1673 /* simple implementation (vs. close all which doesn't close documents if cancelled),
1674 * if user_data is set, it is the GeanyDocument to keep */
1675 void on_close_other_documents1_activate(GtkMenuItem *menuitem, gpointer user_data)
1677 guint i;
1678 GeanyDocument *cur_doc = user_data;
1680 if (cur_doc == NULL)
1681 cur_doc = document_get_current();
1683 for (i = 0; i < documents_array->len; i++)
1685 GeanyDocument *doc = documents[i];
1687 if (doc == cur_doc || ! doc->is_valid)
1688 continue;
1690 if (! document_close(doc))
1691 break;
1696 static void on_menu_reload_configuration1_activate(GtkMenuItem *menuitem, gpointer user_data)
1698 main_reload_configuration();
1702 static void on_debug_messages1_activate(GtkMenuItem *menuitem, gpointer user_data)
1704 log_show_debug_messages_dialog();
1708 void on_send_selection_to_vte1_activate(GtkMenuItem *menuitem, gpointer user_data)
1710 #ifdef HAVE_VTE
1711 if (vte_info.have_vte)
1712 vte_send_selection_to_vte();
1713 #endif
1717 static gboolean on_window_state_event(GtkWidget *widget, GdkEventWindowState *event, gpointer user_data)
1720 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
1722 static GtkWidget *menuitem = NULL;
1724 if (menuitem == NULL)
1725 menuitem = ui_lookup_widget(widget, "menu_fullscreen1");
1727 ignore_callback = TRUE;
1729 ui_prefs.fullscreen = (event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN) ? TRUE : FALSE;
1730 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), ui_prefs.fullscreen);
1732 ignore_callback = FALSE;
1734 return FALSE;
1738 static void show_notebook_page(const gchar *notebook_name, const gchar *page_name)
1740 GtkWidget *widget;
1741 GtkNotebook *notebook;
1743 widget = ui_lookup_widget(ui_widgets.prefs_dialog, page_name);
1744 notebook = GTK_NOTEBOOK(ui_lookup_widget(ui_widgets.prefs_dialog, notebook_name));
1746 if (notebook != NULL && widget != NULL)
1747 gtk_notebook_set_current_page(notebook, gtk_notebook_page_num(notebook, widget));
1751 static void on_customize_toolbar1_activate(GtkMenuItem *menuitem, gpointer user_data)
1753 prefs_show_dialog();
1755 /* select the Interface page */
1756 show_notebook_page("notebook2", "notebook6");
1757 /* select the Toolbar subpage */
1758 show_notebook_page("notebook6", "vbox15");
1762 static void on_button_customize_toolbar_clicked(GtkButton *button, gpointer user_data)
1764 toolbar_configure(GTK_WINDOW(ui_widgets.prefs_dialog));
1768 static void on_cut_current_lines1_activate(GtkMenuItem *menuitem, gpointer user_data)
1770 keybindings_send_command(GEANY_KEY_GROUP_CLIPBOARD, GEANY_KEYS_CLIPBOARD_CUTLINE);
1774 static void on_copy_current_lines1_activate(GtkMenuItem *menuitem, gpointer user_data)
1776 keybindings_send_command(GEANY_KEY_GROUP_CLIPBOARD, GEANY_KEYS_CLIPBOARD_COPYLINE);
1780 static void on_delete_current_lines1_activate(GtkMenuItem *menuitem, gpointer user_data)
1782 keybindings_send_command(GEANY_KEY_GROUP_EDITOR, GEANY_KEYS_EDITOR_DELETELINE);
1786 static void on_duplicate_line_or_selection1_activate(GtkMenuItem *menuitem, gpointer user_data)
1788 keybindings_send_command(GEANY_KEY_GROUP_EDITOR, GEANY_KEYS_EDITOR_DUPLICATELINE);
1792 static void on_select_current_lines1_activate(GtkMenuItem *menuitem, gpointer user_data)
1794 keybindings_send_command(GEANY_KEY_GROUP_SELECT, GEANY_KEYS_SELECT_LINE);
1798 static void on_select_current_paragraph1_activate(GtkMenuItem *menuitem, gpointer user_data)
1800 keybindings_send_command(GEANY_KEY_GROUP_SELECT, GEANY_KEYS_SELECT_PARAGRAPH);
1804 static void on_insert_alternative_white_space1_activate(GtkMenuItem *menuitem, gpointer user_data)
1806 keybindings_send_command(GEANY_KEY_GROUP_INSERT, GEANY_KEYS_INSERT_ALTWHITESPACE);
1810 static void on_go_to_next_marker1_activate(GtkMenuItem *menuitem, gpointer user_data)
1812 keybindings_send_command(GEANY_KEY_GROUP_GOTO, GEANY_KEYS_GOTO_NEXTMARKER);
1816 static void on_go_to_previous_marker1_activate(GtkMenuItem *menuitem, gpointer user_data)
1818 keybindings_send_command(GEANY_KEY_GROUP_GOTO, GEANY_KEYS_GOTO_PREVIOUSMARKER);
1822 static void on_reflow_lines_block1_activate(GtkMenuItem *menuitem, gpointer user_data)
1824 keybindings_send_command(GEANY_KEY_GROUP_FORMAT, GEANY_KEYS_FORMAT_REFLOWPARAGRAPH);
1828 static void on_move_lines_up1_activate(GtkMenuItem *menuitem, gpointer user_data)
1830 keybindings_send_command(GEANY_KEY_GROUP_EDITOR, GEANY_KEYS_EDITOR_MOVELINEUP);
1834 static void on_move_lines_down1_activate(GtkMenuItem *menuitem, gpointer user_data)
1836 keybindings_send_command(GEANY_KEY_GROUP_EDITOR, GEANY_KEYS_EDITOR_MOVELINEDOWN);
1840 static void on_smart_line_indent1_activate(GtkMenuItem *menuitem, gpointer user_data)
1842 keybindings_send_command(GEANY_KEY_GROUP_FORMAT, GEANY_KEYS_FORMAT_AUTOINDENT);
1846 void on_plugin_preferences1_activate(GtkMenuItem *menuitem, gpointer user_data)
1848 #ifdef HAVE_PLUGINS
1849 plugin_show_configure(NULL);
1850 #endif
1854 static void on_indent_width_activate(GtkMenuItem *menuitem, gpointer user_data)
1856 GeanyDocument *doc;
1857 gchar *label;
1858 gint width;
1860 if (ignore_callback)
1861 return;
1863 label = ui_menu_item_get_text(menuitem);
1864 width = atoi(label);
1865 g_free(label);
1867 doc = document_get_current();
1868 if (doc != NULL && width > 0)
1869 editor_set_indent_width(doc->editor, width);
1873 static void on_reset_indentation1_activate(GtkMenuItem *menuitem, gpointer user_data)
1875 guint i;
1877 foreach_document(i)
1878 document_apply_indent_settings(documents[i]);
1880 ui_update_statusbar(NULL, -1);
1881 ui_document_show_hide(NULL);
1885 static void on_mark_all1_activate(GtkMenuItem *menuitem, gpointer user_data)
1887 keybindings_send_command(GEANY_KEY_GROUP_SEARCH, GEANY_KEYS_SEARCH_MARKALL);
1891 static void on_detect_type_from_file_activate(GtkMenuItem *menuitem, gpointer user_data)
1893 GeanyDocument *doc = document_get_current();
1894 GeanyIndentType type;
1896 if (doc != NULL && document_detect_indent_type(doc, &type))
1898 editor_set_indent_type(doc->editor, type);
1899 ui_document_show_hide(doc);
1904 static void on_show_symbol_list_toggled(GtkToggleButton *button, gpointer user_data)
1906 GtkWidget *widget = ui_lookup_widget(ui_widgets.prefs_dialog, "box_show_symbol_list_children");
1908 gtk_widget_set_sensitive(widget, gtk_toggle_button_get_active(button));
1912 static void on_detect_width_from_file_activate(GtkMenuItem *menuitem, gpointer user_data)
1914 GeanyDocument *doc = document_get_current();
1915 gint width;
1917 if (doc != NULL && document_detect_indent_width(doc, &width))
1919 editor_set_indent_width(doc->editor, width);
1920 ui_document_show_hide(doc);
1925 static void builder_connect_func(GtkBuilder *builder, GObject *object,
1926 const gchar *signal_name, const gchar *handler_name, GObject *connect_obj,
1927 GConnectFlags flags, gpointer user_data)
1929 GHashTable *hash = user_data;
1930 GCallback callback;
1932 callback = g_hash_table_lookup(hash, handler_name);
1933 g_return_if_fail(callback);
1935 if (connect_obj == NULL)
1936 g_signal_connect_data(object, signal_name, callback, NULL, NULL, flags);
1937 else
1938 g_signal_connect_object(object, signal_name, callback, connect_obj, flags);
1942 void callbacks_connect(GtkBuilder *builder)
1944 GHashTable *hash;
1946 g_return_if_fail(GTK_IS_BUILDER(builder));
1948 hash = g_hash_table_new(g_str_hash, g_str_equal);
1950 #define ITEM(n) g_hash_table_insert(hash, (gpointer) #n, G_CALLBACK(n));
1951 # include "signallist.i"
1952 #undef ITEM
1954 gtk_builder_connect_signals_full(builder, builder_connect_func, hash);
1955 g_hash_table_destroy(hash);