Fix unused warning when building without VTE support
[geany-mirror.git] / src / callbacks.c
blobb09f822cb445bbb5a63d192eda3a92faed71cd24
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 #include "geany.h"
29 #include <stdlib.h>
30 #include <unistd.h>
31 #include <string.h>
32 #include <gdk/gdkkeysyms.h>
33 #include <glib/gstdio.h>
34 #include <time.h>
36 #include "callbacks.h"
37 #include "support.h"
39 #include "keyfile.h"
40 #include "document.h"
41 #include "documentprivate.h"
42 #include "filetypes.h"
43 #include "sciwrappers.h"
44 #include "editor.h"
45 #include "ui_utils.h"
46 #include "utils.h"
47 #include "dialogs.h"
48 #include "about.h"
49 #include "msgwindow.h"
50 #include "build.h"
51 #include "prefs.h"
52 #include "templates.h"
53 #include "sidebar.h"
54 #include "keybindings.h"
55 #include "encodings.h"
56 #include "search.h"
57 #include "main.h"
58 #include "symbols.h"
59 #include "tools.h"
60 #include "project.h"
61 #include "navqueue.h"
62 #include "printing.h"
63 #include "plugins.h"
64 #include "log.h"
65 #include "toolbar.h"
66 #include "highlighting.h"
67 #include "pluginutils.h"
68 #include "gtkcompat.h"
71 #ifdef HAVE_VTE
72 # include "vte.h"
73 #endif
75 #ifdef HAVE_SOCKET
76 # include "socket.h"
77 #endif
81 /* flag to indicate that an insert callback was triggered from the file menu,
82 * so we need to store the current cursor position in editor_info.click_pos. */
83 static gboolean insert_callback_from_menu = FALSE;
85 /* represents the state at switching a notebook page(in the left treeviews widget), to not emit
86 * the selection-changed signal from tv.tree_openfiles */
87 /*static gboolean switch_tv_notebook_page = FALSE; */
90 static gboolean check_no_unsaved(void)
92 guint i;
94 for (i = 0; i < documents_array->len; i++)
96 if (documents[i]->is_valid && documents[i]->changed)
98 return FALSE;
101 return TRUE; /* no unsaved edits */
105 /* set editor_info.click_pos to the current cursor position if insert_callback_from_menu is TRUE
106 * to prevent invalid cursor positions which can cause segfaults */
107 static void verify_click_pos(GeanyDocument *doc)
109 if (insert_callback_from_menu)
111 editor_info.click_pos = sci_get_current_position(doc->editor->sci);
112 insert_callback_from_menu = FALSE;
117 /* should only be called from on_exit_clicked */
118 static void quit_app(void)
120 configuration_save();
122 if (app->project != NULL)
123 project_close(FALSE); /* save project session files */
125 document_close_all();
127 main_status.quitting = TRUE;
129 main_quit();
133 /* wrapper function to abort exit process if cancel button is pressed */
134 G_MODULE_EXPORT gboolean on_exit_clicked(GtkWidget *widget, gpointer gdata)
136 main_status.quitting = TRUE;
138 if (! check_no_unsaved())
140 if (document_account_for_unsaved())
142 quit_app();
143 return FALSE;
146 else
147 if (! prefs.confirm_exit ||
148 dialogs_show_question_full(NULL, GTK_STOCK_QUIT, GTK_STOCK_CANCEL, NULL,
149 _("Do you really want to quit?")))
151 quit_app();
152 return FALSE;
155 main_status.quitting = FALSE;
156 return TRUE;
161 * GUI callbacks
164 G_MODULE_EXPORT void on_new1_activate(GtkMenuItem *menuitem, gpointer user_data)
166 document_new_file(NULL, NULL, NULL);
170 G_MODULE_EXPORT void on_save1_activate(GtkMenuItem *menuitem, gpointer user_data)
172 gint cur_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(main_widgets.notebook));
173 GeanyDocument *doc = document_get_current();
175 if (doc != NULL && cur_page >= 0)
177 document_save_file(doc, ui_prefs.allow_always_save);
182 G_MODULE_EXPORT void on_save_as1_activate(GtkMenuItem *menuitem, gpointer user_data)
184 dialogs_show_save_as();
188 G_MODULE_EXPORT void on_save_all1_activate(GtkMenuItem *menuitem, gpointer user_data)
190 guint i, max = (guint) gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook));
191 GeanyDocument *doc, *cur_doc = document_get_current();
192 guint count = 0;
194 /* iterate over documents in tabs order */
195 for (i = 0; i < max; i++)
197 doc = document_get_from_page(i);
198 if (! doc->changed)
199 continue;
201 if (document_save_file(doc, FALSE))
202 count++;
204 if (!count)
205 return;
207 ui_set_statusbar(FALSE, ngettext("%d file saved.", "%d files saved.", count), count);
208 /* saving may have changed window title, sidebar for another doc, so update */
209 sidebar_update_tag_list(cur_doc, TRUE);
210 ui_set_window_title(cur_doc);
214 G_MODULE_EXPORT void on_close_all1_activate(GtkMenuItem *menuitem, gpointer user_data)
216 document_close_all();
220 G_MODULE_EXPORT void on_close1_activate(GtkMenuItem *menuitem, gpointer user_data)
222 GeanyDocument *doc = document_get_current();
224 if (doc != NULL)
225 document_close(doc);
229 G_MODULE_EXPORT void on_quit1_activate(GtkMenuItem *menuitem, gpointer user_data)
231 on_exit_clicked(NULL, NULL);
235 G_MODULE_EXPORT void on_file1_activate(GtkMenuItem *menuitem, gpointer user_data)
237 gtk_widget_set_sensitive(ui_widgets.recent_files_menuitem,
238 g_queue_get_length(ui_prefs.recent_queue) > 0);
239 /* hide Page setup when GTK printing is not used */
240 ui_widget_show_hide(ui_widgets.print_page_setup, printing_prefs.use_gtk_printing);
244 /* edit actions, c&p & co, from menu bar and from popup menu */
245 G_MODULE_EXPORT void on_edit1_activate(GtkMenuItem *menuitem, gpointer user_data)
247 GtkWidget *item;
248 GeanyDocument *doc = document_get_current();
250 ui_update_menu_copy_items(doc);
251 ui_update_insert_include_item(doc, 1);
253 item = ui_lookup_widget(main_widgets.window, "plugin_preferences1");
254 #ifndef HAVE_PLUGINS
255 gtk_widget_hide(item);
256 #else
257 gtk_widget_set_sensitive(item, plugins_have_preferences());
258 #endif
262 G_MODULE_EXPORT void on_undo1_activate(GtkMenuItem *menuitem, gpointer user_data)
264 GeanyDocument *doc = document_get_current();
266 g_return_if_fail(doc != NULL);
268 if (document_can_undo(doc))
270 sci_cancel(doc->editor->sci);
271 document_undo(doc);
276 G_MODULE_EXPORT void on_redo1_activate(GtkMenuItem *menuitem, gpointer user_data)
278 GeanyDocument *doc = document_get_current();
280 g_return_if_fail(doc != NULL);
282 if (document_can_redo(doc))
284 sci_cancel(doc->editor->sci);
285 document_redo(doc);
290 G_MODULE_EXPORT void on_cut1_activate(GtkMenuItem *menuitem, gpointer user_data)
292 GeanyDocument *doc = document_get_current();
293 GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
295 if (GTK_IS_EDITABLE(focusw))
296 gtk_editable_cut_clipboard(GTK_EDITABLE(focusw));
297 else
298 if (IS_SCINTILLA(focusw) && doc != NULL)
299 sci_cut(doc->editor->sci);
300 else
301 if (GTK_IS_TEXT_VIEW(focusw))
303 GtkTextBuffer *buffer = gtk_text_view_get_buffer(
304 GTK_TEXT_VIEW(focusw));
305 gtk_text_buffer_cut_clipboard(buffer, gtk_clipboard_get(GDK_NONE), TRUE);
310 G_MODULE_EXPORT void on_copy1_activate(GtkMenuItem *menuitem, gpointer user_data)
312 GeanyDocument *doc = document_get_current();
313 GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
315 if (GTK_IS_EDITABLE(focusw))
316 gtk_editable_copy_clipboard(GTK_EDITABLE(focusw));
317 else
318 if (IS_SCINTILLA(focusw) && doc != NULL)
319 sci_copy(doc->editor->sci);
320 else
321 if (GTK_IS_TEXT_VIEW(focusw))
323 GtkTextBuffer *buffer = gtk_text_view_get_buffer(
324 GTK_TEXT_VIEW(focusw));
325 gtk_text_buffer_copy_clipboard(buffer, gtk_clipboard_get(GDK_NONE));
330 G_MODULE_EXPORT void on_paste1_activate(GtkMenuItem *menuitem, gpointer user_data)
332 GeanyDocument *doc = document_get_current();
333 GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
335 if (GTK_IS_EDITABLE(focusw))
336 gtk_editable_paste_clipboard(GTK_EDITABLE(focusw));
337 else
338 if (IS_SCINTILLA(focusw) && doc != NULL)
340 sci_paste(doc->editor->sci);
342 else
343 if (GTK_IS_TEXT_VIEW(focusw))
345 GtkTextBuffer *buffer = gtk_text_view_get_buffer(
346 GTK_TEXT_VIEW(focusw));
347 gtk_text_buffer_paste_clipboard(buffer, gtk_clipboard_get(GDK_NONE), NULL,
348 TRUE);
353 G_MODULE_EXPORT void on_delete1_activate(GtkMenuItem *menuitem, gpointer user_data)
355 GeanyDocument *doc = document_get_current();
356 GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
358 if (GTK_IS_EDITABLE(focusw))
359 gtk_editable_delete_selection(GTK_EDITABLE(focusw));
360 else
361 if (IS_SCINTILLA(focusw) && doc != NULL && sci_has_selection(doc->editor->sci))
362 sci_clear(doc->editor->sci);
363 else
364 if (GTK_IS_TEXT_VIEW(focusw))
366 GtkTextBuffer *buffer = gtk_text_view_get_buffer(
367 GTK_TEXT_VIEW(focusw));
368 gtk_text_buffer_delete_selection(buffer, TRUE, TRUE);
373 G_MODULE_EXPORT void on_preferences1_activate(GtkMenuItem *menuitem, gpointer user_data)
375 prefs_show_dialog();
379 /* about menu item */
380 G_MODULE_EXPORT void on_info1_activate(GtkMenuItem *menuitem, gpointer user_data)
382 about_dialog_show();
386 /* open file */
387 G_MODULE_EXPORT void on_open1_activate(GtkMenuItem *menuitem, gpointer user_data)
389 dialogs_show_open_file();
393 /* quit toolbar button */
394 G_MODULE_EXPORT void on_toolbutton_quit_clicked(GtkAction *action, gpointer user_data)
396 on_exit_clicked(NULL, NULL);
400 /* reload file */
401 G_MODULE_EXPORT void on_toolbutton_reload_clicked(GtkAction *action, gpointer user_data)
403 on_reload_as_activate(NULL, GINT_TO_POINTER(-1));
407 /* also used for reloading when user_data is -1 */
408 G_MODULE_EXPORT void on_reload_as_activate(GtkMenuItem *menuitem, gpointer user_data)
410 GeanyDocument *doc = document_get_current();
411 gchar *base_name;
412 gint i = GPOINTER_TO_INT(user_data);
413 const gchar *charset = NULL;
415 g_return_if_fail(doc != NULL);
417 /* No need to reload "untitled" (non-file-backed) documents */
418 if (doc->file_name == NULL)
419 return;
421 if (i >= 0)
423 if (i >= GEANY_ENCODINGS_MAX || encodings[i].charset == NULL)
424 return;
425 charset = encodings[i].charset;
427 else
428 charset = doc->encoding;
430 base_name = g_path_get_basename(doc->file_name);
431 /* don't prompt if file hasn't been edited at all */
432 if ((!doc->changed && !document_can_undo(doc) && !document_can_redo(doc)) ||
433 dialogs_show_question_full(NULL, _("_Reload"), GTK_STOCK_CANCEL,
434 _("Any unsaved changes will be lost."),
435 _("Are you sure you want to reload '%s'?"), base_name))
437 document_reload_file(doc, charset);
438 if (charset != NULL)
439 ui_update_statusbar(doc, -1);
441 g_free(base_name);
445 G_MODULE_EXPORT void on_change_font1_activate(GtkMenuItem *menuitem, gpointer user_data)
447 dialogs_show_open_font();
451 /* new file */
452 G_MODULE_EXPORT void on_toolbutton_new_clicked(GtkAction *action, gpointer user_data)
454 document_new_file(NULL, NULL, NULL);
458 /* open file */
459 G_MODULE_EXPORT void on_toolbutton_open_clicked(GtkAction *action, gpointer user_data)
461 dialogs_show_open_file();
465 /* save file */
466 G_MODULE_EXPORT void on_toolbutton_save_clicked(GtkAction *action, gpointer user_data)
468 on_save1_activate(NULL, user_data);
472 /* store text, clear search flags so we can use Search->Find Next/Previous */
473 static void setup_find(const gchar *text, gboolean backwards)
475 SETPTR(search_data.text, g_strdup(text));
476 SETPTR(search_data.original_text, g_strdup(text));
477 search_data.flags = 0;
478 search_data.backwards = backwards;
479 search_data.search_bar = TRUE;
483 static void do_toolbar_search(const gchar *text, gboolean incremental, gboolean backwards)
485 GeanyDocument *doc = document_get_current();
486 gboolean result;
488 setup_find(text, backwards);
489 result = document_search_bar_find(doc, search_data.text, 0, incremental, backwards);
490 if (search_data.search_bar)
491 ui_set_search_entry_background(toolbar_get_widget_child_by_name("SearchEntry"), result);
495 /* search text */
496 G_MODULE_EXPORT void on_toolbar_search_entry_changed(GtkAction *action, const gchar *text, gpointer user_data)
498 do_toolbar_search(text, TRUE, FALSE);
502 /* search text */
503 G_MODULE_EXPORT void on_toolbar_search_entry_activate(GtkAction *action, const gchar *text, gpointer user_data)
505 do_toolbar_search(text, FALSE, GPOINTER_TO_INT(user_data));
509 /* search text */
510 G_MODULE_EXPORT void on_toolbutton_search_clicked(GtkAction *action, gpointer user_data)
512 GeanyDocument *doc = document_get_current();
513 gboolean result;
514 GtkWidget *entry = toolbar_get_widget_child_by_name("SearchEntry");
516 if (entry != NULL)
518 const gchar *text = gtk_entry_get_text(GTK_ENTRY(entry));
520 setup_find(text, FALSE);
521 result = document_search_bar_find(doc, search_data.text, 0, FALSE, FALSE);
522 if (search_data.search_bar)
523 ui_set_search_entry_background(entry, result);
525 else
526 on_find1_activate(NULL, NULL);
530 /* hides toolbar from toolbar popup menu */
531 G_MODULE_EXPORT void on_hide_toolbar1_activate(GtkMenuItem *menuitem, gpointer user_data)
533 GtkWidget *tool_item = ui_lookup_widget(GTK_WIDGET(main_widgets.window), "menu_show_toolbar1");
534 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(tool_item), FALSE);
538 /* zoom in from menu bar and popup menu */
539 G_MODULE_EXPORT void on_zoom_in1_activate(GtkMenuItem *menuitem, gpointer user_data)
541 GeanyDocument *doc = document_get_current();
542 static gint done = 1;
544 g_return_if_fail(doc != NULL);
546 if (done++ % 3 == 0)
547 sci_set_line_numbers(doc->editor->sci, editor_prefs.show_linenumber_margin,
548 (sci_get_zoom(doc->editor->sci) / 2));
549 sci_zoom_in(doc->editor->sci);
553 /* zoom out from menu bar and popup menu */
554 G_MODULE_EXPORT void on_zoom_out1_activate(GtkMenuItem *menuitem, gpointer user_data)
556 GeanyDocument *doc = document_get_current();
558 g_return_if_fail(doc != NULL);
560 if (sci_get_zoom(doc->editor->sci) == 0)
561 sci_set_line_numbers(doc->editor->sci, editor_prefs.show_linenumber_margin, 0);
562 sci_zoom_out(doc->editor->sci);
566 G_MODULE_EXPORT void on_normal_size1_activate(GtkMenuItem *menuitem, gpointer user_data)
568 GeanyDocument *doc = document_get_current();
570 g_return_if_fail(doc != NULL);
572 sci_zoom_off(doc->editor->sci);
573 sci_set_line_numbers(doc->editor->sci, editor_prefs.show_linenumber_margin, 0);
577 /* close tab */
578 G_MODULE_EXPORT void on_toolbutton_close_clicked(GtkAction *action, gpointer user_data)
580 on_close1_activate(NULL, NULL);
584 G_MODULE_EXPORT void on_toolbutton_close_all_clicked(GtkAction *action, gpointer user_data)
586 on_close_all1_activate(NULL, NULL);
590 G_MODULE_EXPORT void on_toolbutton_preferences_clicked(GtkAction *action, gpointer user_data)
592 on_preferences1_activate(NULL, NULL);
596 static gboolean delayed_check_disk_status(gpointer data)
598 document_check_disk_status(data, FALSE);
599 return FALSE;
603 /* Changes window-title after switching tabs and lots of other things.
604 * note: using 'after' makes Scintilla redraw before the UI, appearing more responsive */
605 G_MODULE_EXPORT void on_notebook1_switch_page_after(GtkNotebook *notebook, gpointer page,
606 guint page_num, gpointer user_data)
608 GeanyDocument *doc;
610 if (G_UNLIKELY(main_status.opening_session_files || main_status.closing_all))
611 return;
613 if (page_num == (guint) -1 && page != NULL)
614 doc = document_find_by_sci(SCINTILLA(page));
615 else
616 doc = document_get_from_page(page_num);
618 if (doc != NULL)
620 sidebar_select_openfiles_item(doc);
621 ui_save_buttons_toggle(doc->changed);
622 ui_set_window_title(doc);
623 ui_update_statusbar(doc, -1);
624 ui_update_popup_reundo_items(doc);
625 ui_document_show_hide(doc); /* update the document menu */
626 build_menu_update(doc);
627 sidebar_update_tag_list(doc, FALSE);
628 document_highlight_tags(doc);
630 /* We delay the check to avoid weird fast, unintended switching of notebook pages when
631 * the 'file has changed' dialog is shown while the switch event is not yet completely
632 * finished. So, we check after the switch has been performed to be safe. */
633 g_idle_add(delayed_check_disk_status, doc);
635 #ifdef HAVE_VTE
636 vte_cwd((doc->real_path != NULL) ? doc->real_path : doc->file_name, FALSE);
637 #endif
639 g_signal_emit_by_name(geany_object, "document-activate", doc);
644 G_MODULE_EXPORT void on_tv_notebook_switch_page(GtkNotebook *notebook, gpointer page,
645 guint page_num, gpointer user_data)
647 /* suppress selection changed signal when switching to the open files list */
648 ignore_callback = TRUE;
652 G_MODULE_EXPORT void on_tv_notebook_switch_page_after(GtkNotebook *notebook, gpointer page,
653 guint page_num, gpointer user_data)
655 ignore_callback = FALSE;
659 static void convert_eol(gint mode)
661 GeanyDocument *doc = document_get_current();
663 g_return_if_fail(doc != NULL);
665 sci_convert_eols(doc->editor->sci, mode);
666 sci_set_eol_mode(doc->editor->sci, mode);
667 ui_update_statusbar(doc, -1);
671 G_MODULE_EXPORT void on_crlf_activate(GtkCheckMenuItem *menuitem, gpointer user_data)
673 if (ignore_callback || ! gtk_check_menu_item_get_active(menuitem))
674 return;
676 convert_eol(SC_EOL_CRLF);
680 G_MODULE_EXPORT void on_lf_activate(GtkCheckMenuItem *menuitem, gpointer user_data)
682 if (ignore_callback || ! gtk_check_menu_item_get_active(menuitem))
683 return;
685 convert_eol(SC_EOL_LF);
689 G_MODULE_EXPORT void on_cr_activate(GtkCheckMenuItem *menuitem, gpointer user_data)
691 if (ignore_callback || ! gtk_check_menu_item_get_active(menuitem))
692 return;
694 convert_eol(SC_EOL_CR);
698 G_MODULE_EXPORT void on_replace_tabs_activate(GtkMenuItem *menuitem, gpointer user_data)
700 GeanyDocument *doc = document_get_current();
702 g_return_if_fail(doc != NULL);
704 editor_replace_tabs(doc->editor);
708 gboolean toolbar_popup_menu(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
710 if (event->button == 3)
712 gtk_menu_popup(GTK_MENU(ui_widgets.toolbar_menu), NULL, NULL, NULL, NULL, event->button, event->time);
713 return TRUE;
715 return FALSE;
719 G_MODULE_EXPORT void on_toggle_case1_activate(GtkMenuItem *menuitem, gpointer user_data)
721 GeanyDocument *doc = document_get_current();
722 ScintillaObject *sci;
723 gchar *text;
724 gboolean keep_sel = TRUE;
726 g_return_if_fail(doc != NULL);
728 sci = doc->editor->sci;
729 if (! sci_has_selection(sci))
731 keybindings_send_command(GEANY_KEY_GROUP_SELECT, GEANY_KEYS_SELECT_WORD);
732 keep_sel = FALSE;
735 /* either we already had a selection or we created one for current word */
736 if (sci_has_selection(sci))
738 gchar *result = NULL;
739 gint cmd = SCI_LOWERCASE;
740 gboolean rectsel = (gboolean) scintilla_send_message(sci, SCI_SELECTIONISRECTANGLE, 0, 0);
742 text = sci_get_selection_contents(sci);
744 if (utils_str_has_upper(text))
746 if (rectsel)
747 cmd = SCI_LOWERCASE;
748 else
749 result = g_utf8_strdown(text, -1);
751 else
753 if (rectsel)
754 cmd = SCI_UPPERCASE;
755 else
756 result = g_utf8_strup(text, -1);
759 if (result != NULL)
761 sci_replace_sel(sci, result);
762 g_free(result);
763 if (keep_sel)
764 sci_set_selection_start(sci, sci_get_current_position(sci) - strlen(text));
766 else
767 sci_send_command(sci, cmd);
769 g_free(text);
775 G_MODULE_EXPORT void on_show_toolbar1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
777 if (ignore_callback) return;
779 toolbar_prefs.visible = (toolbar_prefs.visible) ? FALSE : TRUE;;
780 ui_widget_show_hide(GTK_WIDGET(main_widgets.toolbar), toolbar_prefs.visible);
784 G_MODULE_EXPORT void on_fullscreen1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
786 if (ignore_callback)
787 return;
789 ui_prefs.fullscreen = (ui_prefs.fullscreen) ? FALSE : TRUE;
790 ui_set_fullscreen();
794 G_MODULE_EXPORT void on_show_messages_window1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
796 if (ignore_callback)
797 return;
799 ui_prefs.msgwindow_visible = (ui_prefs.msgwindow_visible) ? FALSE : TRUE;
800 msgwin_show_hide(ui_prefs.msgwindow_visible);
804 G_MODULE_EXPORT void on_menu_color_schemes_activate(GtkImageMenuItem *imagemenuitem, gpointer user_data)
806 highlighting_show_color_scheme_dialog();
810 G_MODULE_EXPORT void on_markers_margin1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
812 if (ignore_callback)
813 return;
815 editor_prefs.show_markers_margin = ! editor_prefs.show_markers_margin;
816 ui_toggle_editor_features(GEANY_EDITOR_SHOW_MARKERS_MARGIN);
820 G_MODULE_EXPORT void on_show_line_numbers1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
822 if (ignore_callback)
823 return;
825 editor_prefs.show_linenumber_margin = ! editor_prefs.show_linenumber_margin;
826 ui_toggle_editor_features(GEANY_EDITOR_SHOW_LINE_NUMBERS);
830 G_MODULE_EXPORT void on_menu_show_white_space1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
832 if (ignore_callback)
833 return;
835 editor_prefs.show_white_space = ! editor_prefs.show_white_space;
836 ui_toggle_editor_features(GEANY_EDITOR_SHOW_WHITE_SPACE);
840 G_MODULE_EXPORT void on_menu_show_line_endings1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
842 if (ignore_callback)
843 return;
845 editor_prefs.show_line_endings = ! editor_prefs.show_line_endings;
846 ui_toggle_editor_features(GEANY_EDITOR_SHOW_LINE_ENDINGS);
850 G_MODULE_EXPORT void on_menu_show_indentation_guides1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
852 if (ignore_callback)
853 return;
855 editor_prefs.show_indent_guide = ! editor_prefs.show_indent_guide;
856 ui_toggle_editor_features(GEANY_EDITOR_SHOW_INDENTATION_GUIDES);
860 G_MODULE_EXPORT void on_line_wrapping1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
862 if (! ignore_callback)
864 GeanyDocument *doc = document_get_current();
865 g_return_if_fail(doc != NULL);
867 editor_set_line_wrapping(doc->editor, ! doc->editor->line_wrapping);
872 G_MODULE_EXPORT void on_set_file_readonly1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
874 if (! ignore_callback)
876 GeanyDocument *doc = document_get_current();
877 g_return_if_fail(doc != NULL);
879 doc->readonly = ! doc->readonly;
880 sci_set_readonly(doc->editor->sci, doc->readonly);
881 ui_update_tab_status(doc);
882 ui_update_statusbar(doc, -1);
887 G_MODULE_EXPORT void on_use_auto_indentation1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
889 if (! ignore_callback)
891 GeanyDocument *doc = document_get_current();
892 g_return_if_fail(doc != NULL);
894 doc->editor->auto_indent = ! doc->editor->auto_indent;
899 static void find_usage(gboolean in_session)
901 gint flags;
902 gchar *search_text;
903 GeanyDocument *doc = document_get_current();
905 g_return_if_fail(doc != NULL);
907 if (sci_has_selection(doc->editor->sci))
908 { /* take selected text if there is a selection */
909 search_text = sci_get_selection_contents(doc->editor->sci);
910 flags = SCFIND_MATCHCASE;
912 else
914 editor_find_current_word_sciwc(doc->editor, -1,
915 editor_info.current_word, GEANY_MAX_WORD_LENGTH);
916 search_text = g_strdup(editor_info.current_word);
917 flags = SCFIND_MATCHCASE | SCFIND_WHOLEWORD;
920 search_find_usage(search_text, search_text, flags, in_session);
921 g_free(search_text);
925 G_MODULE_EXPORT void on_find_document_usage1_activate(GtkMenuItem *menuitem, gpointer user_data)
927 find_usage(FALSE);
931 G_MODULE_EXPORT void on_find_usage1_activate(GtkMenuItem *menuitem, gpointer user_data)
933 find_usage(TRUE);
937 static void goto_tag(gboolean definition)
939 GeanyDocument *doc = document_get_current();
941 g_return_if_fail(doc != NULL);
943 /* update cursor pos for navigating back afterwards */
944 if (!sci_has_selection(doc->editor->sci))
945 sci_set_current_position(doc->editor->sci, editor_info.click_pos, FALSE);
947 /* use the keybinding callback as it checks for selections as well as current word */
948 if (definition)
949 keybindings_send_command(GEANY_KEY_GROUP_GOTO, GEANY_KEYS_GOTO_TAGDEFINITION);
950 else
951 keybindings_send_command(GEANY_KEY_GROUP_GOTO, GEANY_KEYS_GOTO_TAGDECLARATION);
955 G_MODULE_EXPORT void on_goto_tag_definition1(GtkMenuItem *menuitem, gpointer user_data)
957 goto_tag(TRUE);
961 G_MODULE_EXPORT void on_goto_tag_declaration1(GtkMenuItem *menuitem, gpointer user_data)
963 goto_tag(FALSE);
967 G_MODULE_EXPORT void on_count_words1_activate(GtkMenuItem *menuitem, gpointer user_data)
969 tools_word_count();
973 G_MODULE_EXPORT void on_show_color_chooser1_activate(GtkMenuItem *menuitem, gpointer user_data)
975 gchar colour[9];
976 GeanyDocument *doc = document_get_current();
977 gint pos;
979 g_return_if_fail(doc != NULL);
981 pos = sci_get_current_position(doc->editor->sci);
982 editor_find_current_word(doc->editor, pos, colour, sizeof colour, GEANY_WORDCHARS"#");
983 tools_color_chooser(colour);
987 G_MODULE_EXPORT void on_toolbutton_compile_clicked(GtkAction *action, gpointer user_data)
989 keybindings_send_command(GEANY_KEY_GROUP_BUILD, GEANY_KEYS_BUILD_COMPILE);
993 G_MODULE_EXPORT void on_find1_activate(GtkMenuItem *menuitem, gpointer user_data)
995 search_show_find_dialog();
999 G_MODULE_EXPORT void on_find_next1_activate(GtkMenuItem *menuitem, gpointer user_data)
1001 search_find_again(FALSE);
1005 G_MODULE_EXPORT void on_find_previous1_activate(GtkMenuItem *menuitem, gpointer user_data)
1007 if (search_data.flags & SCFIND_REGEXP)
1008 /* Can't reverse search order for a regex (find next ignores search backwards) */
1009 utils_beep();
1010 else
1011 search_find_again(TRUE);
1015 G_MODULE_EXPORT void on_find_nextsel1_activate(GtkMenuItem *menuitem, gpointer user_data)
1017 search_find_selection(document_get_current(), FALSE);
1021 G_MODULE_EXPORT void on_find_prevsel1_activate(GtkMenuItem *menuitem, gpointer user_data)
1023 search_find_selection(document_get_current(), TRUE);
1027 G_MODULE_EXPORT void on_replace1_activate(GtkMenuItem *menuitem, gpointer user_data)
1029 search_show_replace_dialog();
1033 G_MODULE_EXPORT void on_find_in_files1_activate(GtkMenuItem *menuitem, gpointer user_data)
1035 search_show_find_in_files_dialog(NULL);
1039 static void get_line_and_offset_from_text(const gchar *text, gint *line_no, gint *offset)
1041 if (*text == '+' || *text == '-')
1043 *line_no = atoi(text + 1);
1044 *offset = (*text == '+') ? 1 : -1;
1046 else
1048 *line_no = atoi(text) - 1;
1049 *offset = 0;
1054 G_MODULE_EXPORT void on_go_to_line_activate(GtkMenuItem *menuitem, gpointer user_data)
1056 static gchar value[16] = "";
1057 gchar *result;
1059 result = dialogs_show_input_goto_line(
1060 _("Go to Line"), GTK_WINDOW(main_widgets.window),
1061 _("Enter the line you want to go to:"), value);
1062 if (result != NULL)
1064 GeanyDocument *doc = document_get_current();
1065 gint offset;
1066 gint line_no;
1068 g_return_if_fail(doc != NULL);
1070 get_line_and_offset_from_text(result, &line_no, &offset);
1071 if (! editor_goto_line(doc->editor, line_no, offset))
1072 utils_beep();
1073 /* remember value for future calls */
1074 g_snprintf(value, sizeof(value), "%s", result);
1076 g_free(result);
1081 G_MODULE_EXPORT void on_toolbutton_goto_entry_activate(GtkAction *action, const gchar *text, gpointer user_data)
1083 GeanyDocument *doc = document_get_current();
1084 gint offset;
1085 gint line_no;
1087 g_return_if_fail(doc != NULL);
1089 get_line_and_offset_from_text(text, &line_no, &offset);
1090 if (! editor_goto_line(doc->editor, line_no, offset))
1091 utils_beep();
1092 else
1093 keybindings_send_command(GEANY_KEY_GROUP_FOCUS, GEANY_KEYS_FOCUS_EDITOR);
1097 G_MODULE_EXPORT void on_toolbutton_goto_clicked(GtkAction *action, gpointer user_data)
1099 GtkWidget *entry = toolbar_get_widget_child_by_name("GotoEntry");
1101 if (entry != NULL)
1103 const gchar *text = gtk_entry_get_text(GTK_ENTRY(entry));
1105 on_toolbutton_goto_entry_activate(NULL, text, NULL);
1107 else
1108 on_go_to_line_activate(NULL, NULL);
1112 G_MODULE_EXPORT void on_help1_activate(GtkMenuItem *menuitem, gpointer user_data)
1114 gchar *uri;
1116 uri = utils_get_help_url(NULL);
1117 utils_open_browser(uri);
1118 g_free(uri);
1122 G_MODULE_EXPORT void on_help_shortcuts1_activate(GtkMenuItem *menuitem, gpointer user_data)
1124 keybindings_show_shortcuts();
1128 G_MODULE_EXPORT void on_website1_activate(GtkMenuItem *menuitem, gpointer user_data)
1130 utils_open_browser(GEANY_HOMEPAGE);
1134 G_MODULE_EXPORT void on_help_menu_item_donate_activate(GtkMenuItem *item, gpointer user_data)
1136 utils_open_browser(GEANY_DONATE);
1140 G_MODULE_EXPORT void on_help_menu_item_wiki_activate(GtkMenuItem *item, gpointer user_data)
1142 utils_open_browser(GEANY_WIKI);
1146 G_MODULE_EXPORT void on_help_menu_item_bug_report_activate(GtkMenuItem *item, gpointer user_data)
1148 utils_open_browser(GEANY_BUG_REPORT);
1152 G_MODULE_EXPORT void on_comments_function_activate(GtkMenuItem *menuitem, gpointer user_data)
1154 GeanyDocument *doc = document_get_current();
1155 gchar *text;
1156 const gchar *cur_tag = NULL;
1157 gint line = -1, pos = 0;
1159 if (doc == NULL || doc->file_type == NULL)
1161 ui_set_statusbar(FALSE,
1162 _("Please set the filetype for the current file before using this function."));
1163 return;
1166 /* symbols_get_current_function returns -1 on failure, so sci_get_position_from_line
1167 * returns the current position, so it should be safe */
1168 line = symbols_get_current_function(doc, &cur_tag);
1169 pos = sci_get_position_from_line(doc->editor->sci, line);
1171 text = templates_get_template_function(doc, cur_tag);
1173 sci_start_undo_action(doc->editor->sci);
1174 sci_insert_text(doc->editor->sci, pos, text);
1175 sci_end_undo_action(doc->editor->sci);
1176 g_free(text);
1180 G_MODULE_EXPORT void on_comments_multiline_activate(GtkMenuItem *menuitem, gpointer user_data)
1182 GeanyDocument *doc = document_get_current();
1184 if (doc == NULL || doc->file_type == NULL)
1186 ui_set_statusbar(FALSE,
1187 _("Please set the filetype for the current file before using this function."));
1188 return;
1191 verify_click_pos(doc); /* make sure that the click_pos is valid */
1193 if (doc->file_type->comment_open || doc->file_type->comment_single)
1194 editor_insert_multiline_comment(doc->editor);
1195 else
1196 utils_beep();
1200 G_MODULE_EXPORT void on_comments_gpl_activate(GtkMenuItem *menuitem, gpointer user_data)
1202 GeanyDocument *doc = document_get_current();
1203 gchar *text;
1205 g_return_if_fail(doc != NULL);
1207 text = templates_get_template_licence(doc, GEANY_TEMPLATE_GPL);
1209 verify_click_pos(doc); /* make sure that the click_pos is valid */
1211 sci_start_undo_action(doc->editor->sci);
1212 sci_insert_text(doc->editor->sci, editor_info.click_pos, text);
1213 sci_end_undo_action(doc->editor->sci);
1214 g_free(text);
1218 G_MODULE_EXPORT void on_comments_bsd_activate(GtkMenuItem *menuitem, gpointer user_data)
1220 GeanyDocument *doc = document_get_current();
1221 gchar *text;
1223 g_return_if_fail(doc != NULL);
1225 text = templates_get_template_licence(doc, GEANY_TEMPLATE_BSD);
1227 verify_click_pos(doc); /* make sure that the click_pos is valid */
1229 sci_start_undo_action(doc->editor->sci);
1230 sci_insert_text(doc->editor->sci, editor_info.click_pos, text);
1231 sci_end_undo_action(doc->editor->sci);
1232 g_free(text);
1237 G_MODULE_EXPORT void on_comments_changelog_activate(GtkMenuItem *menuitem, gpointer user_data)
1239 GeanyDocument *doc = document_get_current();
1240 gchar *text;
1242 g_return_if_fail(doc != NULL);
1244 text = templates_get_template_changelog(doc);
1245 sci_start_undo_action(doc->editor->sci);
1246 sci_insert_text(doc->editor->sci, 0, text);
1247 /* sets the cursor to the right position to type the changelog text,
1248 * the template has 21 chars + length of name and email */
1249 sci_goto_pos(doc->editor->sci, 21 + strlen(template_prefs.developer) + strlen(template_prefs.mail), TRUE);
1250 sci_end_undo_action(doc->editor->sci);
1252 g_free(text);
1256 G_MODULE_EXPORT void on_comments_fileheader_activate(GtkMenuItem *menuitem, gpointer user_data)
1258 GeanyDocument *doc = document_get_current();
1259 gchar *text;
1260 const gchar *fname;
1261 GeanyFiletype *ft;
1263 g_return_if_fail(doc != NULL);
1265 ft = doc->file_type;
1266 fname = doc->file_name;
1267 text = templates_get_template_fileheader(FILETYPE_ID(ft), fname);
1269 sci_start_undo_action(doc->editor->sci);
1270 sci_insert_text(doc->editor->sci, 0, text);
1271 sci_goto_pos(doc->editor->sci, 0, FALSE);
1272 sci_end_undo_action(doc->editor->sci);
1273 g_free(text);
1277 G_MODULE_EXPORT void on_insert_date_activate(GtkMenuItem *menuitem, gpointer user_data)
1279 GeanyDocument *doc = document_get_current();
1280 const gchar *format = NULL;
1281 gchar *time_str;
1283 g_return_if_fail(doc != NULL);
1285 /* set default value */
1286 if (utils_str_equal("", ui_prefs.custom_date_format))
1288 g_free(ui_prefs.custom_date_format);
1289 ui_prefs.custom_date_format = g_strdup("%d.%m.%Y");
1292 if (utils_str_equal(_("dd.mm.yyyy"), (gchar*) user_data))
1293 format = "%d.%m.%Y";
1294 else if (utils_str_equal(_("mm.dd.yyyy"), (gchar*) user_data))
1295 format = "%m.%d.%Y";
1296 else if (utils_str_equal(_("yyyy/mm/dd"), (gchar*) user_data))
1297 format = "%Y/%m/%d";
1298 else if (utils_str_equal(_("dd.mm.yyyy hh:mm:ss"), (gchar*) user_data))
1299 format = "%d.%m.%Y %H:%M:%S";
1300 else if (utils_str_equal(_("mm.dd.yyyy hh:mm:ss"), (gchar*) user_data))
1301 format = "%m.%d.%Y %H:%M:%S";
1302 else if (utils_str_equal(_("yyyy/mm/dd hh:mm:ss"), (gchar*) user_data))
1303 format = "%Y/%m/%d %H:%M:%S";
1304 else if (utils_str_equal(_("_Use Custom Date Format"), (gchar*) user_data))
1305 format = ui_prefs.custom_date_format;
1306 else
1308 gchar *str = dialogs_show_input(_("Custom Date Format"), GTK_WINDOW(main_widgets.window),
1309 _("Enter here a custom date and time format. "
1310 "You can use any conversion specifiers which can be used with the ANSI C strftime function."),
1311 ui_prefs.custom_date_format);
1312 if (str)
1313 SETPTR(ui_prefs.custom_date_format, str);
1314 return;
1317 time_str = utils_get_date_time(format, NULL);
1318 if (time_str != NULL)
1320 verify_click_pos(doc); /* make sure that the click_pos is valid */
1322 sci_start_undo_action(doc->editor->sci);
1323 sci_insert_text(doc->editor->sci, editor_info.click_pos, time_str);
1324 sci_goto_pos(doc->editor->sci, editor_info.click_pos + strlen(time_str), FALSE);
1325 sci_end_undo_action(doc->editor->sci);
1326 g_free(time_str);
1328 else
1330 utils_beep();
1331 ui_set_statusbar(TRUE,
1332 _("Date format string could not be converted (possibly too long)."));
1337 G_MODULE_EXPORT void on_insert_include_activate(GtkMenuItem *menuitem, gpointer user_data)
1339 GeanyDocument *doc = document_get_current();
1340 gint pos = -1;
1341 gchar *text;
1343 g_return_if_fail(doc != NULL);
1344 g_return_if_fail(user_data != NULL);
1346 verify_click_pos(doc); /* make sure that the click_pos is valid */
1348 if (utils_str_equal(user_data, "blank"))
1350 text = g_strdup("#include \"\"\n");
1351 pos = editor_info.click_pos + 10;
1353 else
1355 text = g_strconcat("#include <", user_data, ">\n", NULL);
1358 sci_start_undo_action(doc->editor->sci);
1359 sci_insert_text(doc->editor->sci, editor_info.click_pos, text);
1360 sci_end_undo_action(doc->editor->sci);
1361 g_free(text);
1362 if (pos >= 0)
1363 sci_goto_pos(doc->editor->sci, pos, FALSE);
1367 G_MODULE_EXPORT void on_file_properties_activate(GtkMenuItem *menuitem, gpointer user_data)
1369 GeanyDocument *doc = document_get_current();
1370 g_return_if_fail(doc != NULL);
1372 dialogs_show_file_properties(doc);
1376 G_MODULE_EXPORT void on_menu_fold_all1_activate(GtkMenuItem *menuitem, gpointer user_data)
1378 GeanyDocument *doc = document_get_current();
1379 g_return_if_fail(doc != NULL);
1381 editor_fold_all(doc->editor);
1385 G_MODULE_EXPORT void on_menu_unfold_all1_activate(GtkMenuItem *menuitem, gpointer user_data)
1387 GeanyDocument *doc = document_get_current();
1388 g_return_if_fail(doc != NULL);
1390 editor_unfold_all(doc->editor);
1394 G_MODULE_EXPORT void on_toolbutton_run_clicked(GtkAction *action, gpointer user_data)
1396 keybindings_send_command(GEANY_KEY_GROUP_BUILD, GEANY_KEYS_BUILD_RUN);
1400 G_MODULE_EXPORT void on_menu_remove_indicators1_activate(GtkMenuItem *menuitem, gpointer user_data)
1402 GeanyDocument *doc = document_get_current();
1403 g_return_if_fail(doc != NULL);
1405 editor_indicator_clear(doc->editor, GEANY_INDICATOR_ERROR);
1409 G_MODULE_EXPORT void on_print1_activate(GtkMenuItem *menuitem, gpointer user_data)
1411 GeanyDocument *doc = document_get_current();
1412 g_return_if_fail(doc != NULL);
1414 printing_print_doc(doc);
1418 G_MODULE_EXPORT void on_menu_select_all1_activate(GtkMenuItem *menuitem, gpointer user_data)
1420 GeanyDocument *doc = document_get_current();
1421 g_return_if_fail(doc != NULL);
1423 sci_select_all(doc->editor->sci);
1427 G_MODULE_EXPORT void on_menu_show_sidebar1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
1429 if (ignore_callback)
1430 return;
1432 ui_prefs.sidebar_visible = ! ui_prefs.sidebar_visible;
1434 /* show built-in tabs if no tabs visible */
1435 if (ui_prefs.sidebar_visible &&
1436 ! interface_prefs.sidebar_openfiles_visible && ! interface_prefs.sidebar_symbol_visible &&
1437 gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.sidebar_notebook)) <= 2)
1439 interface_prefs.sidebar_openfiles_visible = TRUE;
1440 interface_prefs.sidebar_symbol_visible = TRUE;
1443 /* if window has input focus, set it back to the editor before toggling off */
1444 if (! ui_prefs.sidebar_visible &&
1445 gtk_container_get_focus_child(GTK_CONTAINER(main_widgets.sidebar_notebook)) != NULL)
1447 keybindings_send_command(GEANY_KEY_GROUP_FOCUS, GEANY_KEYS_FOCUS_EDITOR);
1450 ui_sidebar_show_hide();
1454 G_MODULE_EXPORT void on_menu_write_unicode_bom1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data)
1456 if (! ignore_callback)
1458 GeanyDocument *doc = document_get_current();
1460 g_return_if_fail(doc != NULL);
1461 if (doc->readonly)
1463 utils_beep();
1464 return;
1467 document_undo_add(doc, UNDO_BOM, GINT_TO_POINTER(doc->has_bom));
1469 doc->has_bom = ! doc->has_bom;
1471 ui_update_statusbar(doc, -1);
1476 G_MODULE_EXPORT void on_menu_comment_line1_activate(GtkMenuItem *menuitem, gpointer user_data)
1478 GeanyDocument *doc = document_get_current();
1479 g_return_if_fail(doc != NULL);
1481 editor_do_comment(doc->editor, -1, FALSE, FALSE, TRUE);
1485 G_MODULE_EXPORT void on_menu_uncomment_line1_activate(GtkMenuItem *menuitem, gpointer user_data)
1487 GeanyDocument *doc = document_get_current();
1488 g_return_if_fail(doc != NULL);
1490 editor_do_uncomment(doc->editor, -1, FALSE);
1494 G_MODULE_EXPORT void on_menu_toggle_line_commentation1_activate(GtkMenuItem *menuitem, gpointer user_data)
1496 GeanyDocument *doc = document_get_current();
1497 g_return_if_fail(doc != NULL);
1499 editor_do_comment_toggle(doc->editor);
1503 G_MODULE_EXPORT void on_menu_increase_indent1_activate(GtkMenuItem *menuitem, gpointer user_data)
1505 GeanyDocument *doc = document_get_current();
1506 g_return_if_fail(doc != NULL);
1508 editor_indent(doc->editor, TRUE);
1512 G_MODULE_EXPORT void on_menu_decrease_indent1_activate(GtkMenuItem *menuitem, gpointer user_data)
1514 GeanyDocument *doc = document_get_current();
1515 g_return_if_fail(doc != NULL);
1517 editor_indent(doc->editor, FALSE);
1521 G_MODULE_EXPORT void on_next_message1_activate(GtkMenuItem *menuitem, gpointer user_data)
1523 if (! ui_tree_view_find_next(GTK_TREE_VIEW(msgwindow.tree_msg),
1524 msgwin_goto_messages_file_line))
1525 ui_set_statusbar(FALSE, _("No more message items."));
1529 G_MODULE_EXPORT void on_previous_message1_activate(GtkMenuItem *menuitem, gpointer user_data)
1531 if (! ui_tree_view_find_previous(GTK_TREE_VIEW(msgwindow.tree_msg),
1532 msgwin_goto_messages_file_line))
1533 ui_set_statusbar(FALSE, _("No more message items."));
1537 G_MODULE_EXPORT void on_menu_comments_multiline_activate(GtkMenuItem *menuitem, gpointer user_data)
1539 insert_callback_from_menu = TRUE;
1540 on_comments_multiline_activate(menuitem, user_data);
1544 G_MODULE_EXPORT void on_menu_comments_gpl_activate(GtkMenuItem *menuitem, gpointer user_data)
1546 insert_callback_from_menu = TRUE;
1547 on_comments_gpl_activate(menuitem, user_data);
1551 G_MODULE_EXPORT void on_menu_comments_bsd_activate(GtkMenuItem *menuitem, gpointer user_data)
1553 insert_callback_from_menu = TRUE;
1554 on_comments_bsd_activate(menuitem, user_data);
1558 G_MODULE_EXPORT void on_menu_insert_include_activate(GtkMenuItem *menuitem, gpointer user_data)
1560 insert_callback_from_menu = TRUE;
1561 on_insert_include_activate(menuitem, user_data);
1565 G_MODULE_EXPORT void on_menu_insert_date_activate(GtkMenuItem *menuitem, gpointer user_data)
1567 insert_callback_from_menu = TRUE;
1568 on_insert_date_activate(menuitem, user_data);
1572 G_MODULE_EXPORT void on_project_new1_activate(GtkMenuItem *menuitem, gpointer user_data)
1574 project_new();
1578 G_MODULE_EXPORT void on_project_open1_activate(GtkMenuItem *menuitem, gpointer user_data)
1580 project_open();
1584 G_MODULE_EXPORT void on_project_close1_activate(GtkMenuItem *menuitem, gpointer user_data)
1586 project_close(TRUE);
1590 G_MODULE_EXPORT void on_project_properties1_activate(GtkMenuItem *menuitem, gpointer user_data)
1592 project_properties();
1596 G_MODULE_EXPORT void on_menu_project1_activate(GtkMenuItem *menuitem, gpointer user_data)
1598 static GtkWidget *item_close = NULL;
1599 static GtkWidget *item_properties = NULL;
1601 if (item_close == NULL)
1603 item_close = ui_lookup_widget(main_widgets.window, "project_close1");
1604 item_properties = ui_lookup_widget(main_widgets.window, "project_properties1");
1607 gtk_widget_set_sensitive(item_close, (app->project != NULL));
1608 gtk_widget_set_sensitive(item_properties, (app->project != NULL));
1609 gtk_widget_set_sensitive(ui_widgets.recent_projects_menuitem,
1610 g_queue_get_length(ui_prefs.recent_projects_queue) > 0);
1614 G_MODULE_EXPORT void on_menu_open_selected_file1_activate(GtkMenuItem *menuitem, gpointer user_data)
1616 GeanyDocument *doc = document_get_current();
1617 gchar *sel = NULL;
1618 const gchar *wc;
1620 #ifdef G_OS_WIN32
1621 wc = GEANY_WORDCHARS "./-" "\\";
1622 #else
1623 wc = GEANY_WORDCHARS "./-";
1624 #endif
1626 g_return_if_fail(doc != NULL);
1628 sel = editor_get_default_selection(doc->editor, TRUE, wc);
1629 SETPTR(sel, utils_get_locale_from_utf8(sel));
1631 if (sel != NULL)
1633 gchar *filename = NULL;
1635 if (g_path_is_absolute(sel))
1636 filename = g_strdup(sel);
1637 else
1638 { /* relative filename, add the path of the current file */
1639 gchar *path;
1641 path = utils_get_current_file_dir_utf8();
1642 SETPTR(path, utils_get_locale_from_utf8(path));
1643 if (!path)
1644 path = g_get_current_dir();
1646 filename = g_build_path(G_DIR_SEPARATOR_S, path, sel, NULL);
1648 if (! g_file_test(filename, G_FILE_TEST_EXISTS) &&
1649 app->project != NULL && !EMPTY(app->project->base_path))
1651 /* try the project's base path */
1652 SETPTR(path, project_get_base_path());
1653 SETPTR(path, utils_get_locale_from_utf8(path));
1654 SETPTR(filename, g_build_path(G_DIR_SEPARATOR_S, path, sel, NULL));
1656 g_free(path);
1657 #ifdef G_OS_UNIX
1658 if (! g_file_test(filename, G_FILE_TEST_EXISTS))
1659 SETPTR(filename, g_build_path(G_DIR_SEPARATOR_S, "/usr/local/include", sel, NULL));
1661 if (! g_file_test(filename, G_FILE_TEST_EXISTS))
1662 SETPTR(filename, g_build_path(G_DIR_SEPARATOR_S, "/usr/include", sel, NULL));
1663 #endif
1666 if (g_file_test(filename, G_FILE_TEST_EXISTS))
1667 document_open_file(filename, FALSE, NULL, NULL);
1668 else
1670 SETPTR(sel, utils_get_utf8_from_locale(sel));
1671 ui_set_statusbar(TRUE, _("Could not open file %s (File not found)"), sel);
1674 g_free(filename);
1675 g_free(sel);
1680 G_MODULE_EXPORT void on_remove_markers1_activate(GtkMenuItem *menuitem, gpointer user_data)
1682 GeanyDocument *doc = document_get_current();
1683 g_return_if_fail(doc != NULL);
1685 sci_marker_delete_all(doc->editor->sci, 0); /* delete the yellow tag marker */
1686 sci_marker_delete_all(doc->editor->sci, 1); /* delete user markers */
1687 editor_indicator_clear(doc->editor, GEANY_INDICATOR_SEARCH);
1691 G_MODULE_EXPORT void on_load_tags1_activate(GtkMenuItem *menuitem, gpointer user_data)
1693 symbols_show_load_tags_dialog();
1697 G_MODULE_EXPORT void on_context_action1_activate(GtkMenuItem *menuitem, gpointer user_data)
1699 gchar *word, *command;
1700 GError *error = NULL;
1701 GeanyDocument *doc = document_get_current();
1703 g_return_if_fail(doc != NULL);
1705 if (sci_has_selection(doc->editor->sci))
1706 { /* take selected text if there is a selection */
1707 word = sci_get_selection_contents(doc->editor->sci);
1709 else
1711 word = g_strdup(editor_info.current_word);
1714 /* use the filetype specific command if available, fallback to global command otherwise */
1715 if (doc->file_type != NULL &&
1716 !EMPTY(doc->file_type->context_action_cmd))
1718 command = g_strdup(doc->file_type->context_action_cmd);
1720 else
1722 command = g_strdup(tool_prefs.context_action_cmd);
1725 /* substitute the wildcard %s and run the command if it is non empty */
1726 if (G_LIKELY(!EMPTY(command)))
1728 utils_str_replace_all(&command, "%s", word);
1730 if (! g_spawn_command_line_async(command, &error))
1732 ui_set_statusbar(TRUE, "Context action command failed: %s", error->message);
1733 g_error_free(error);
1736 g_free(word);
1737 g_free(command);
1741 G_MODULE_EXPORT void on_menu_toggle_all_additional_widgets1_activate(GtkMenuItem *menuitem, gpointer user_data)
1743 static gint hide_all = -1;
1744 GtkCheckMenuItem *msgw = GTK_CHECK_MENU_ITEM(
1745 ui_lookup_widget(main_widgets.window, "menu_show_messages_window1"));
1746 GtkCheckMenuItem *toolbari = GTK_CHECK_MENU_ITEM(
1747 ui_lookup_widget(main_widgets.window, "menu_show_toolbar1"));
1749 /* get the initial state (necessary if Geany was closed with hide_all = TRUE) */
1750 if (G_UNLIKELY(hide_all == -1))
1752 if (! gtk_check_menu_item_get_active(msgw) &&
1753 ! interface_prefs.show_notebook_tabs &&
1754 ! gtk_check_menu_item_get_active(toolbari))
1756 hide_all = TRUE;
1758 else
1759 hide_all = FALSE;
1762 hide_all = ! hide_all; /* toggle */
1764 if (hide_all)
1766 if (gtk_check_menu_item_get_active(msgw))
1767 gtk_check_menu_item_set_active(msgw, ! gtk_check_menu_item_get_active(msgw));
1769 interface_prefs.show_notebook_tabs = FALSE;
1770 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets.notebook), interface_prefs.show_notebook_tabs);
1772 ui_statusbar_showhide(FALSE);
1774 if (gtk_check_menu_item_get_active(toolbari))
1775 gtk_check_menu_item_set_active(toolbari, ! gtk_check_menu_item_get_active(toolbari));
1777 else
1780 if (! gtk_check_menu_item_get_active(msgw))
1781 gtk_check_menu_item_set_active(msgw, ! gtk_check_menu_item_get_active(msgw));
1783 interface_prefs.show_notebook_tabs = TRUE;
1784 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets.notebook), interface_prefs.show_notebook_tabs);
1786 ui_statusbar_showhide(TRUE);
1788 if (! gtk_check_menu_item_get_active(toolbari))
1789 gtk_check_menu_item_set_active(toolbari, ! gtk_check_menu_item_get_active(toolbari));
1794 G_MODULE_EXPORT void on_forward_activate(GtkMenuItem *menuitem, gpointer user_data)
1796 navqueue_go_forward();
1800 G_MODULE_EXPORT void on_back_activate(GtkMenuItem *menuitem, gpointer user_data)
1802 navqueue_go_back();
1806 G_MODULE_EXPORT gboolean on_motion_event(GtkWidget *widget, GdkEventMotion *event, gpointer user_data)
1808 if (prefs.auto_focus && ! gtk_widget_has_focus(widget))
1809 gtk_widget_grab_focus(widget);
1811 return FALSE;
1815 static void set_indent_type(GtkCheckMenuItem *menuitem, GeanyIndentType type)
1817 GeanyDocument *doc;
1819 if (ignore_callback || ! gtk_check_menu_item_get_active(menuitem))
1820 return;
1822 doc = document_get_current();
1823 g_return_if_fail(doc != NULL);
1825 editor_set_indent(doc->editor, type, doc->editor->indent_width);
1826 ui_update_statusbar(doc, -1);
1830 G_MODULE_EXPORT void on_tabs1_activate(GtkCheckMenuItem *menuitem, gpointer user_data)
1832 set_indent_type(menuitem, GEANY_INDENT_TYPE_TABS);
1836 G_MODULE_EXPORT void on_spaces1_activate(GtkCheckMenuItem *menuitem, gpointer user_data)
1838 set_indent_type(menuitem, GEANY_INDENT_TYPE_SPACES);
1842 G_MODULE_EXPORT void on_tabs_and_spaces1_activate(GtkCheckMenuItem *menuitem, gpointer user_data)
1844 set_indent_type(menuitem, GEANY_INDENT_TYPE_BOTH);
1848 G_MODULE_EXPORT void on_strip_trailing_spaces1_activate(GtkMenuItem *menuitem, gpointer user_data)
1850 GeanyDocument *doc;
1852 if (ignore_callback)
1853 return;
1855 doc = document_get_current();
1856 g_return_if_fail(doc != NULL);
1858 editor_strip_trailing_spaces(doc->editor);
1862 G_MODULE_EXPORT void on_page_setup1_activate(GtkMenuItem *menuitem, gpointer user_data)
1864 printing_page_setup_gtk();
1868 G_MODULE_EXPORT gboolean on_escape_key_press_event(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
1870 guint state = event->state & gtk_accelerator_get_default_mod_mask();
1872 /* make pressing escape in the sidebar and toolbar focus the editor */
1873 if (event->keyval == GDK_Escape && state == 0)
1875 keybindings_send_command(GEANY_KEY_GROUP_FOCUS, GEANY_KEYS_FOCUS_EDITOR);
1876 return TRUE;
1878 return FALSE;
1882 G_MODULE_EXPORT void on_line_breaking1_activate(GtkMenuItem *menuitem, gpointer user_data)
1884 GeanyDocument *doc;
1886 if (ignore_callback)
1887 return;
1889 doc = document_get_current();
1890 g_return_if_fail(doc != NULL);
1892 doc->editor->line_breaking = !doc->editor->line_breaking;
1896 G_MODULE_EXPORT void on_replace_spaces_activate(GtkMenuItem *menuitem, gpointer user_data)
1898 GeanyDocument *doc = document_get_current();
1900 g_return_if_fail(doc != NULL);
1902 editor_replace_spaces(doc->editor);
1906 G_MODULE_EXPORT void on_search1_activate(GtkMenuItem *menuitem, gpointer user_data)
1908 GtkWidget *next_message = ui_lookup_widget(main_widgets.window, "next_message1");
1909 GtkWidget *previous_message = ui_lookup_widget(main_widgets.window, "previous_message1");
1910 gboolean have_messages;
1912 /* enable commands if the messages window has any items */
1913 have_messages = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(msgwindow.store_msg),
1914 NULL) > 0;
1916 gtk_widget_set_sensitive(next_message, have_messages);
1917 gtk_widget_set_sensitive(previous_message, have_messages);
1921 /* simple implementation (vs. close all which doesn't close documents if cancelled),
1922 * if user_data is set, it is a GtkNotebook child widget */
1923 G_MODULE_EXPORT void on_close_other_documents1_activate(GtkMenuItem *menuitem, gpointer user_data)
1925 guint i;
1926 GeanyDocument *doc, *cur_doc;
1928 if (user_data != NULL)
1930 gint page_num = gtk_notebook_page_num(
1931 GTK_NOTEBOOK(main_widgets.notebook), GTK_WIDGET(user_data));
1932 cur_doc = document_get_from_page(page_num);
1934 else
1935 cur_doc = document_get_current();
1938 for (i = 0; i < documents_array->len; i++)
1940 doc = documents[i];
1942 if (doc == cur_doc || ! doc->is_valid)
1943 continue;
1945 if (! document_close(doc))
1946 break;
1951 G_MODULE_EXPORT void on_menu_reload_configuration1_activate(GtkMenuItem *menuitem, gpointer user_data)
1953 main_reload_configuration();
1957 G_MODULE_EXPORT void on_debug_messages1_activate(GtkMenuItem *menuitem, gpointer user_data)
1959 log_show_debug_messages_dialog();
1963 G_MODULE_EXPORT void on_send_selection_to_vte1_activate(GtkMenuItem *menuitem, gpointer user_data)
1965 #ifdef HAVE_VTE
1966 if (vte_info.have_vte)
1967 vte_send_selection_to_vte();
1968 #endif
1972 G_MODULE_EXPORT gboolean on_window_state_event(GtkWidget *widget, GdkEventWindowState *event, gpointer user_data)
1975 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
1977 static GtkWidget *menuitem = NULL;
1979 if (menuitem == NULL)
1980 menuitem = ui_lookup_widget(widget, "menu_fullscreen1");
1982 ignore_callback = TRUE;
1984 ui_prefs.fullscreen = (event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN) ? TRUE : FALSE;
1985 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), ui_prefs.fullscreen);
1987 ignore_callback = FALSE;
1989 return FALSE;
1993 static void show_notebook_page(const gchar *notebook_name, const gchar *page_name)
1995 GtkWidget *widget;
1996 GtkNotebook *notebook;
1998 widget = ui_lookup_widget(ui_widgets.prefs_dialog, page_name);
1999 notebook = GTK_NOTEBOOK(ui_lookup_widget(ui_widgets.prefs_dialog, notebook_name));
2001 if (notebook != NULL && widget != NULL)
2002 gtk_notebook_set_current_page(notebook, gtk_notebook_page_num(notebook, widget));
2006 G_MODULE_EXPORT void on_customize_toolbar1_activate(GtkMenuItem *menuitem, gpointer user_data)
2008 prefs_show_dialog();
2010 /* select the Interface page */
2011 show_notebook_page("notebook2", "notebook6");
2012 /* select the Toolbar subpage */
2013 show_notebook_page("notebook6", "vbox15");
2017 G_MODULE_EXPORT void on_button_customize_toolbar_clicked(GtkButton *button, gpointer user_data)
2019 toolbar_configure(GTK_WINDOW(ui_widgets.prefs_dialog));
2023 G_MODULE_EXPORT void on_cut_current_lines1_activate(GtkMenuItem *menuitem, gpointer user_data)
2025 keybindings_send_command(GEANY_KEY_GROUP_CLIPBOARD, GEANY_KEYS_CLIPBOARD_CUTLINE);
2029 G_MODULE_EXPORT void on_copy_current_lines1_activate(GtkMenuItem *menuitem, gpointer user_data)
2031 keybindings_send_command(GEANY_KEY_GROUP_CLIPBOARD, GEANY_KEYS_CLIPBOARD_COPYLINE);
2035 G_MODULE_EXPORT void on_delete_current_lines1_activate(GtkMenuItem *menuitem, gpointer user_data)
2037 keybindings_send_command(GEANY_KEY_GROUP_EDITOR, GEANY_KEYS_EDITOR_DELETELINE);
2041 G_MODULE_EXPORT void on_duplicate_line_or_selection1_activate(GtkMenuItem *menuitem, gpointer user_data)
2043 keybindings_send_command(GEANY_KEY_GROUP_EDITOR, GEANY_KEYS_EDITOR_DUPLICATELINE);
2047 G_MODULE_EXPORT void on_select_current_lines1_activate(GtkMenuItem *menuitem, gpointer user_data)
2049 keybindings_send_command(GEANY_KEY_GROUP_SELECT, GEANY_KEYS_SELECT_LINE);
2053 G_MODULE_EXPORT void on_select_current_paragraph1_activate(GtkMenuItem *menuitem, gpointer user_data)
2055 keybindings_send_command(GEANY_KEY_GROUP_SELECT, GEANY_KEYS_SELECT_PARAGRAPH);
2059 G_MODULE_EXPORT void on_insert_alternative_white_space1_activate(GtkMenuItem *menuitem, gpointer user_data)
2061 keybindings_send_command(GEANY_KEY_GROUP_INSERT, GEANY_KEYS_INSERT_ALTWHITESPACE);
2065 G_MODULE_EXPORT void on_go_to_next_marker1_activate(GtkMenuItem *menuitem, gpointer user_data)
2067 keybindings_send_command(GEANY_KEY_GROUP_GOTO, GEANY_KEYS_GOTO_NEXTMARKER);
2071 G_MODULE_EXPORT void on_go_to_previous_marker1_activate(GtkMenuItem *menuitem, gpointer user_data)
2073 keybindings_send_command(GEANY_KEY_GROUP_GOTO, GEANY_KEYS_GOTO_PREVIOUSMARKER);
2077 G_MODULE_EXPORT void on_reflow_lines_block1_activate(GtkMenuItem *menuitem, gpointer user_data)
2079 keybindings_send_command(GEANY_KEY_GROUP_FORMAT, GEANY_KEYS_FORMAT_REFLOWPARAGRAPH);
2083 G_MODULE_EXPORT void on_move_lines_up1_activate(GtkMenuItem *menuitem, gpointer user_data)
2085 keybindings_send_command(GEANY_KEY_GROUP_EDITOR, GEANY_KEYS_EDITOR_MOVELINEUP);
2089 G_MODULE_EXPORT void on_move_lines_down1_activate(GtkMenuItem *menuitem, gpointer user_data)
2091 keybindings_send_command(GEANY_KEY_GROUP_EDITOR, GEANY_KEYS_EDITOR_MOVELINEDOWN);
2095 G_MODULE_EXPORT void on_smart_line_indent1_activate(GtkMenuItem *menuitem, gpointer user_data)
2097 keybindings_send_command(GEANY_KEY_GROUP_FORMAT, GEANY_KEYS_FORMAT_AUTOINDENT);
2101 G_MODULE_EXPORT void on_plugin_preferences1_activate(GtkMenuItem *menuitem, gpointer user_data)
2103 #ifdef HAVE_PLUGINS
2104 plugin_show_configure(NULL);
2105 #endif
2109 G_MODULE_EXPORT void on_indent_width_activate(GtkMenuItem *menuitem, gpointer user_data)
2111 GeanyDocument *doc;
2112 gchar *label;
2113 gint width;
2115 if (ignore_callback)
2116 return;
2118 label = ui_menu_item_get_text(menuitem);
2119 width = atoi(label);
2120 g_free(label);
2122 doc = document_get_current();
2123 if (doc != NULL && width > 0)
2124 editor_set_indent_width(doc->editor, width);
2128 G_MODULE_EXPORT void on_reset_indentation1_activate(GtkMenuItem *menuitem, gpointer user_data)
2130 guint i;
2132 foreach_document(i)
2133 document_apply_indent_settings(documents[i]);
2135 ui_update_statusbar(NULL, -1);
2136 ui_document_show_hide(NULL);
2140 G_MODULE_EXPORT void on_mark_all1_activate(GtkMenuItem *menuitem, gpointer user_data)
2142 keybindings_send_command(GEANY_KEY_GROUP_SEARCH, GEANY_KEYS_SEARCH_MARKALL);
2146 G_MODULE_EXPORT void on_detect_type_from_file_activate(GtkMenuItem *menuitem, gpointer user_data)
2148 GeanyDocument *doc = document_get_current();
2149 GeanyIndentType type;
2151 if (doc != NULL && document_detect_indent_type(doc, &type))
2153 editor_set_indent_type(doc->editor, type);
2154 ui_document_show_hide(doc);
2159 G_MODULE_EXPORT void on_detect_width_from_file_activate(GtkMenuItem *menuitem, gpointer user_data)
2161 GeanyDocument *doc = document_get_current();
2162 gint width;
2164 if (doc != NULL && document_detect_indent_width(doc, &width))
2166 editor_set_indent_width(doc->editor, width);
2167 ui_document_show_hide(doc);