Add API docs for keybinding enums.
[geany-mirror.git] / src / callbacks.c
blob2173b6fd2799fbf33fbb1759c712d65d72f0b4ff
1 /*
2 * callbacks.c - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2005-2010 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5 * Copyright 2006-2010 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
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * $Id$
25 * Callbacks used by Glade. These are mainly in response to menu item and button events in the
26 * main window. Callbacks not used by Glade should go elsewhere.
29 #include "geany.h"
31 #include <stdlib.h>
32 #include <unistd.h>
33 #include <string.h>
34 #include <gdk/gdkkeysyms.h>
35 #include <glib/gstdio.h>
36 #include <time.h>
38 #include "callbacks.h"
39 #include "support.h"
41 #include "keyfile.h"
42 #include "document.h"
43 #include "documentprivate.h"
44 #include "filetypes.h"
45 #include "sciwrappers.h"
46 #include "editor.h"
47 #include "ui_utils.h"
48 #include "utils.h"
49 #include "dialogs.h"
50 #include "about.h"
51 #include "msgwindow.h"
52 #include "build.h"
53 #include "prefs.h"
54 #include "templates.h"
55 #include "sidebar.h"
56 #include "keybindings.h"
57 #include "encodings.h"
58 #include "search.h"
59 #include "main.h"
60 #include "symbols.h"
61 #include "tools.h"
62 #include "project.h"
63 #include "navqueue.h"
64 #include "printing.h"
65 #include "plugins.h"
66 #include "log.h"
67 #include "toolbar.h"
68 #include "pluginutils.h"
71 #ifdef HAVE_VTE
72 # include "vte.h"
73 #endif
75 #ifdef HAVE_SOCKET
76 # include "socket.h"
77 #endif
80 /* flag to indicate the explicit change of a toggle button of the toolbar menu and so the
81 * toggled callback should ignore the change since it is not triggered by the user */
82 static gboolean ignore_toolbar_toggle = FALSE;
84 /* flag to indicate that an insert callback was triggered from the file menu,
85 * so we need to store the current cursor position in editor_info.click_pos. */
86 static gboolean insert_callback_from_menu = FALSE;
88 /* represents the state at switching a notebook page(in the left treeviews widget), to not emit
89 * the selection-changed signal from tv.tree_openfiles */
90 /*static gboolean switch_tv_notebook_page = FALSE; */
93 static gboolean check_no_unsaved(void)
95 guint i;
97 for (i = 0; i < documents_array->len; i++)
99 if (documents[i]->is_valid && documents[i]->changed)
101 return FALSE;
104 return TRUE; /* no unsaved edits */
108 /* set editor_info.click_pos to the current cursor position if insert_callback_from_menu is TRUE
109 * to prevent invalid cursor positions which can cause segfaults */
110 static void verify_click_pos(GeanyDocument *doc)
112 if (insert_callback_from_menu)
114 editor_info.click_pos = sci_get_current_position(doc->editor->sci);
115 insert_callback_from_menu = FALSE;
120 /* should only be called from on_exit_clicked */
121 static void quit_app(void)
123 configuration_save();
125 if (app->project != NULL)
126 project_close(FALSE); /* save project session files */
128 document_close_all();
130 main_status.quitting = TRUE;
132 main_quit();
136 /* wrapper function to abort exit process if cancel button is pressed */
137 gboolean
138 on_exit_clicked (GtkWidget *widget, gpointer gdata)
140 main_status.quitting = TRUE;
142 if (! check_no_unsaved())
144 if (document_account_for_unsaved())
146 quit_app();
147 return FALSE;
150 else
151 if (! prefs.confirm_exit ||
152 dialogs_show_question_full(NULL, GTK_STOCK_QUIT, GTK_STOCK_CANCEL, NULL,
153 _("Do you really want to quit?")))
155 quit_app();
156 return FALSE;
159 main_status.quitting = FALSE;
160 return TRUE;
165 * GUI callbacks
168 void
169 on_new1_activate (GtkMenuItem *menuitem,
170 gpointer user_data)
172 document_new_file(NULL, NULL, NULL);
176 void
177 on_save1_activate (GtkMenuItem *menuitem,
178 gpointer user_data)
180 gint cur_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(main_widgets.notebook));
181 GeanyDocument *doc = document_get_current();
183 if (doc != NULL && cur_page >= 0)
185 if (document_need_save_as(doc))
186 dialogs_show_save_as();
187 else
188 document_save_file(doc, FALSE);
193 void
194 on_save_as1_activate (GtkMenuItem *menuitem,
195 gpointer user_data)
197 dialogs_show_save_as();
201 void
202 on_save_all1_activate (GtkMenuItem *menuitem,
203 gpointer user_data)
205 gint i, max = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook));
206 GeanyDocument *doc, *cur_doc = document_get_current();
207 gint count = 0;
209 for (i = 0; i < max; i++)
211 doc = document_get_from_page(i);
212 if (! doc->changed)
213 continue;
214 if (document_need_save_as(doc))
216 /* display unnamed document */
217 gtk_notebook_set_current_page(GTK_NOTEBOOK(main_widgets.notebook),
218 document_get_notebook_page(doc));
219 if (dialogs_show_save_as())
220 count++;
222 else
224 if (document_save_file(doc, FALSE))
225 count++;
228 if (!count)
229 return;
231 ui_set_statusbar(FALSE, ngettext("%d file saved.", "%d files saved.", count), count);
232 /* saving may have changed window title, sidebar for another doc, so update */
233 sidebar_update_tag_list(cur_doc, TRUE);
234 ui_set_window_title(cur_doc);
238 void
239 on_close_all1_activate (GtkMenuItem *menuitem,
240 gpointer user_data)
242 document_close_all();
246 void
247 on_close1_activate (GtkMenuItem *menuitem,
248 gpointer user_data)
250 GeanyDocument *doc = document_get_current();
252 g_return_if_fail(doc != NULL);
254 document_close(doc);
258 void
259 on_quit1_activate (GtkMenuItem *menuitem,
260 gpointer user_data)
262 on_exit_clicked(NULL, NULL);
266 void
267 on_file1_activate (GtkMenuItem *menuitem,
268 gpointer user_data)
270 gtk_widget_set_sensitive(ui_widgets.recent_files_menuitem,
271 g_queue_get_length(ui_prefs.recent_queue) > 0);
272 #if GTK_CHECK_VERSION(2, 10, 0)
273 /* hide Page setup when GTK printing is not used
274 * (on GTK < 2.10 the menu item is hidden completely) */
275 ui_widget_show_hide(ui_widgets.print_page_setup,
276 printing_prefs.use_gtk_printing || gtk_check_version(2, 10, 0) != NULL);
277 #endif
281 /* edit actions, c&p & co, from menu bar and from popup menu */
282 void
283 on_edit1_activate (GtkMenuItem *menuitem,
284 gpointer user_data)
286 GtkWidget *item;
287 GeanyDocument *doc = document_get_current();
289 ui_update_menu_copy_items(doc);
290 ui_update_insert_include_item(doc, 1);
292 item = ui_lookup_widget(main_widgets.window, "plugin_preferences1");
293 #ifndef HAVE_PLUGINS
294 gtk_widget_hide(item);
295 #else
296 gtk_widget_set_sensitive(item, plugins_have_preferences());
297 #endif
301 void
302 on_undo1_activate (GtkMenuItem *menuitem,
303 gpointer user_data)
305 GeanyDocument *doc = document_get_current();
307 g_return_if_fail(doc != NULL);
309 if (document_can_undo(doc))
311 sci_cancel(doc->editor->sci);
312 document_undo(doc);
317 void
318 on_redo1_activate (GtkMenuItem *menuitem,
319 gpointer user_data)
321 GeanyDocument *doc = document_get_current();
323 g_return_if_fail(doc != NULL);
325 if (document_can_redo(doc))
327 sci_cancel(doc->editor->sci);
328 document_redo(doc);
333 void
334 on_cut1_activate (GtkMenuItem *menuitem,
335 gpointer user_data)
337 GeanyDocument *doc = document_get_current();
338 GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
340 if (GTK_IS_EDITABLE(focusw))
341 gtk_editable_cut_clipboard(GTK_EDITABLE(focusw));
342 else
343 if (IS_SCINTILLA(focusw) && doc != NULL)
344 sci_cut(doc->editor->sci);
345 else
346 if (GTK_IS_TEXT_VIEW(focusw))
348 GtkTextBuffer *buffer = gtk_text_view_get_buffer(
349 GTK_TEXT_VIEW(focusw));
350 gtk_text_buffer_cut_clipboard(buffer, gtk_clipboard_get(GDK_NONE), TRUE);
355 void
356 on_copy1_activate (GtkMenuItem *menuitem,
357 gpointer user_data)
359 GeanyDocument *doc = document_get_current();
360 GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
362 if (GTK_IS_EDITABLE(focusw))
363 gtk_editable_copy_clipboard(GTK_EDITABLE(focusw));
364 else
365 if (IS_SCINTILLA(focusw) && doc != NULL)
366 sci_copy(doc->editor->sci);
367 else
368 if (GTK_IS_TEXT_VIEW(focusw))
370 GtkTextBuffer *buffer = gtk_text_view_get_buffer(
371 GTK_TEXT_VIEW(focusw));
372 gtk_text_buffer_copy_clipboard(buffer, gtk_clipboard_get(GDK_NONE));
377 void
378 on_paste1_activate (GtkMenuItem *menuitem,
379 gpointer user_data)
381 GeanyDocument *doc = document_get_current();
382 GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
384 if (GTK_IS_EDITABLE(focusw))
385 gtk_editable_paste_clipboard(GTK_EDITABLE(focusw));
386 else
387 if (IS_SCINTILLA(focusw) && doc != NULL)
389 sci_paste(doc->editor->sci);
391 else
392 if (GTK_IS_TEXT_VIEW(focusw))
394 GtkTextBuffer *buffer = gtk_text_view_get_buffer(
395 GTK_TEXT_VIEW(focusw));
396 gtk_text_buffer_paste_clipboard(buffer, gtk_clipboard_get(GDK_NONE), NULL,
397 TRUE);
402 void
403 on_delete1_activate (GtkMenuItem *menuitem,
404 gpointer user_data)
406 GeanyDocument *doc = document_get_current();
407 GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
409 if (GTK_IS_EDITABLE(focusw))
410 gtk_editable_delete_selection(GTK_EDITABLE(focusw));
411 else
412 if (IS_SCINTILLA(focusw) && doc != NULL && sci_has_selection(doc->editor->sci))
413 sci_clear(doc->editor->sci);
414 else
415 if (GTK_IS_TEXT_VIEW(focusw))
417 GtkTextBuffer *buffer = gtk_text_view_get_buffer(
418 GTK_TEXT_VIEW(focusw));
419 gtk_text_buffer_delete_selection(buffer, TRUE, TRUE);
424 void
425 on_preferences1_activate (GtkMenuItem *menuitem,
426 gpointer user_data)
428 prefs_show_dialog();
432 /* about menu item */
433 void
434 on_info1_activate (GtkMenuItem *menuitem,
435 gpointer user_data)
437 about_dialog_show();
441 /* open file */
442 void
443 on_open1_activate (GtkMenuItem *menuitem,
444 gpointer user_data)
446 dialogs_show_open_file();
450 /* quit toolbar button */
451 void
452 on_toolbutton_quit_clicked (GtkAction *action,
453 gpointer user_data)
455 on_exit_clicked(NULL, NULL);
459 /* reload file */
460 void
461 on_toolbutton_reload_clicked (GtkAction *action,
462 gpointer user_data)
464 on_reload_as_activate(NULL, GINT_TO_POINTER(-1));
468 /* also used for reloading when user_data is -1 */
469 void
470 on_reload_as_activate (GtkMenuItem *menuitem,
471 gpointer user_data)
473 GeanyDocument *doc = document_get_current();
474 gchar *base_name;
475 gint i = GPOINTER_TO_INT(user_data);
476 gchar *charset = NULL;
478 g_return_if_fail(doc != NULL);
479 g_return_if_fail(doc->file_name != NULL);
481 if (i >= 0)
483 if (i >= GEANY_ENCODINGS_MAX || encodings[i].charset == NULL)
484 return;
485 charset = encodings[i].charset;
487 else
488 charset = doc->encoding;
490 base_name = g_path_get_basename(doc->file_name);
491 if (dialogs_show_question_full(NULL, _("_Reload"), GTK_STOCK_CANCEL,
492 _("Any unsaved changes will be lost."),
493 _("Are you sure you want to reload '%s'?"), base_name))
495 document_reload_file(doc, charset);
496 if (charset != NULL)
497 ui_update_statusbar(doc, -1);
499 g_free(base_name);
503 void
504 on_images_and_text2_activate (GtkCheckMenuItem *menuitem,
505 gpointer user_data)
507 if (ignore_toolbar_toggle || ! gtk_check_menu_item_get_active(menuitem))
508 return;
510 gtk_toolbar_set_style(GTK_TOOLBAR(main_widgets.toolbar), GTK_TOOLBAR_BOTH);
511 toolbar_prefs.icon_style = GTK_TOOLBAR_BOTH;
515 void
516 on_images_only2_activate (GtkCheckMenuItem *menuitem,
517 gpointer user_data)
519 if (ignore_toolbar_toggle || ! gtk_check_menu_item_get_active(menuitem))
520 return;
522 gtk_toolbar_set_style(GTK_TOOLBAR(main_widgets.toolbar), GTK_TOOLBAR_ICONS);
523 toolbar_prefs.icon_style = GTK_TOOLBAR_ICONS;
527 void
528 on_text_only2_activate (GtkCheckMenuItem *menuitem,
529 gpointer user_data)
531 if (ignore_toolbar_toggle || ! gtk_check_menu_item_get_active(menuitem))
532 return;
534 gtk_toolbar_set_style(GTK_TOOLBAR(main_widgets.toolbar), GTK_TOOLBAR_TEXT);
535 toolbar_prefs.icon_style = GTK_TOOLBAR_TEXT;
539 void
540 on_change_font1_activate (GtkMenuItem *menuitem,
541 gpointer user_data)
543 dialogs_show_open_font();
547 /* new file */
548 void
549 on_toolbutton_new_clicked (GtkAction *action,
550 gpointer user_data)
552 document_new_file(NULL, NULL, NULL);
556 /* open file */
557 void
558 on_toolbutton_open_clicked (GtkAction *action,
559 gpointer user_data)
561 dialogs_show_open_file();
565 /* save file */
566 void
567 on_toolbutton_save_clicked (GtkAction *action,
568 gpointer user_data)
570 on_save1_activate(NULL, user_data);
574 /* store text, clear search flags so we can use Search->Find Next/Previous */
575 static void setup_find_next(const gchar *text)
577 setptr(search_data.text, g_strdup(text));
578 search_data.flags = 0;
579 search_data.backwards = FALSE;
580 search_data.search_bar = TRUE;
584 /* search text */
585 void
586 on_toolbar_search_entry_changed(GtkAction *action, const gchar *text, gpointer user_data)
588 GeanyDocument *doc = document_get_current();
589 gboolean result;
591 setup_find_next(text);
592 result = document_search_bar_find(doc, search_data.text, 0, GPOINTER_TO_INT(user_data));
593 if (search_data.search_bar)
594 ui_set_search_entry_background(toolbar_get_widget_child_by_name("SearchEntry"), result);
598 /* search text */
599 void
600 on_toolbutton_search_clicked (GtkAction *action,
601 gpointer user_data)
603 GeanyDocument *doc = document_get_current();
604 gboolean result;
605 GtkWidget *entry = toolbar_get_widget_child_by_name("SearchEntry");
607 if (entry != NULL)
609 const gchar *text = gtk_entry_get_text(GTK_ENTRY(entry));
611 setup_find_next(text);
612 result = document_search_bar_find(doc, search_data.text, 0, FALSE);
613 if (search_data.search_bar)
614 ui_set_search_entry_background(entry, result);
616 else
617 on_find1_activate(NULL, NULL);
621 void
622 on_toolbar_large_icons1_activate (GtkCheckMenuItem *menuitem,
623 gpointer user_data)
625 if (ignore_toolbar_toggle || ! gtk_check_menu_item_get_active(menuitem))
626 return;
628 toolbar_prefs.icon_size = GTK_ICON_SIZE_LARGE_TOOLBAR;
629 gtk_toolbar_set_icon_size(GTK_TOOLBAR(main_widgets.toolbar), toolbar_prefs.icon_size);
633 void
634 on_toolbar_small_icons1_activate (GtkCheckMenuItem *menuitem,
635 gpointer user_data)
637 if (ignore_toolbar_toggle || ! gtk_check_menu_item_get_active(menuitem))
638 return;
640 toolbar_prefs.icon_size = GTK_ICON_SIZE_SMALL_TOOLBAR;
641 gtk_toolbar_set_icon_size(GTK_TOOLBAR(main_widgets.toolbar), toolbar_prefs.icon_size);
645 void
646 on_very_small_icons1_activate (GtkCheckMenuItem *menuitem,
647 gpointer user_data)
649 if (ignore_toolbar_toggle || ! gtk_check_menu_item_get_active(menuitem))
650 return;
652 toolbar_prefs.icon_size = GTK_ICON_SIZE_MENU;
653 gtk_toolbar_set_icon_size(GTK_TOOLBAR(main_widgets.toolbar), toolbar_prefs.icon_size);
657 /* hides toolbar from toolbar popup menu */
658 void
659 on_hide_toolbar1_activate (GtkMenuItem *menuitem,
660 gpointer user_data)
662 GtkWidget *tool_item = ui_lookup_widget(GTK_WIDGET(main_widgets.window), "menu_show_toolbar1");
663 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(tool_item), FALSE);
667 /* zoom in from menu bar and popup menu */
668 void
669 on_zoom_in1_activate (GtkMenuItem *menuitem,
670 gpointer user_data)
672 GeanyDocument *doc = document_get_current();
673 static gint done = 1;
675 g_return_if_fail(doc != NULL);
677 if (done++ % 3 == 0)
678 sci_set_line_numbers(doc->editor->sci, editor_prefs.show_linenumber_margin,
679 (sci_get_zoom(doc->editor->sci) / 2));
680 sci_zoom_in(doc->editor->sci);
684 /* zoom out from menu bar and popup menu */
685 void
686 on_zoom_out1_activate (GtkMenuItem *menuitem,
687 gpointer user_data)
689 GeanyDocument *doc = document_get_current();
691 g_return_if_fail(doc != NULL);
693 if (sci_get_zoom(doc->editor->sci) == 0)
694 sci_set_line_numbers(doc->editor->sci, editor_prefs.show_linenumber_margin, 0);
695 sci_zoom_out(doc->editor->sci);
699 void
700 on_normal_size1_activate (GtkMenuItem *menuitem,
701 gpointer user_data)
703 GeanyDocument *doc = document_get_current();
705 g_return_if_fail(doc != NULL);
707 sci_zoom_off(doc->editor->sci);
708 sci_set_line_numbers(doc->editor->sci, editor_prefs.show_linenumber_margin, 0);
712 /* close tab */
713 void
714 on_toolbutton_close_clicked (GtkAction *action,
715 gpointer user_data)
717 on_close1_activate(NULL, NULL);
721 void
722 on_toolbutton_close_all_clicked (GtkAction *action,
723 gpointer user_data)
725 on_close_all1_activate(NULL, NULL);
729 void
730 on_toolbutton_preferences_clicked (GtkAction *action,
731 gpointer user_data)
733 on_preferences1_activate(NULL, NULL);
737 static gboolean delayed_check_disk_status(gpointer data)
739 document_check_disk_status(data, FALSE);
740 return FALSE;
744 /* Changes window-title after switching tabs and lots of other things.
745 * note: using 'after' makes Scintilla redraw before the UI, appearing more responsive */
746 void
747 on_notebook1_switch_page_after (GtkNotebook *notebook,
748 GtkNotebookPage *page,
749 guint page_num,
750 gpointer user_data)
752 GeanyDocument *doc;
754 if (G_UNLIKELY(main_status.opening_session_files) || G_UNLIKELY(main_status.closing_all))
755 return;
757 if (page_num == (guint) -1 && page != NULL)
758 doc = document_find_by_sci(SCINTILLA(page));
759 else
760 doc = document_get_from_page(page_num);
762 if (doc != NULL)
764 sidebar_select_openfiles_item(doc);
765 document_set_text_changed(doc, doc->changed); /* also sets window title and status bar */
766 ui_update_popup_reundo_items(doc);
767 ui_document_show_hide(doc); /* update the document menu */
768 build_menu_update(doc);
769 sidebar_update_tag_list(doc, FALSE);
771 /* We delay the check to avoid weird fast, unintended switching of notebook pages when
772 * the 'file has changed' dialog is shown while the switch event is not yet completely
773 * finished. So, we check after the switch has been performed to be safe. */
774 g_idle_add(delayed_check_disk_status, doc);
776 #ifdef HAVE_VTE
777 vte_cwd((doc->real_path != NULL) ? doc->real_path : doc->file_name, FALSE);
778 #endif
780 g_signal_emit_by_name(geany_object, "document-activate", doc);
785 void
786 on_tv_notebook_switch_page (GtkNotebook *notebook,
787 GtkNotebookPage *page,
788 guint page_num,
789 gpointer user_data)
791 /* suppress selection changed signal when switching to the open files list */
792 ignore_callback = TRUE;
796 void
797 on_tv_notebook_switch_page_after (GtkNotebook *notebook,
798 GtkNotebookPage *page,
799 guint page_num,
800 gpointer user_data)
802 ignore_callback = FALSE;
806 void
807 on_crlf_activate (GtkCheckMenuItem *menuitem,
808 gpointer user_data)
810 GeanyDocument *doc;
811 if (ignore_callback || ! gtk_check_menu_item_get_active(menuitem))
812 return;
813 doc = document_get_current();
814 g_return_if_fail(doc != NULL);
816 sci_convert_eols(doc->editor->sci, SC_EOL_CRLF);
817 sci_set_eol_mode(doc->editor->sci, SC_EOL_CRLF);
821 void
822 on_lf_activate (GtkCheckMenuItem *menuitem,
823 gpointer user_data)
825 GeanyDocument *doc;
826 if (ignore_callback || ! gtk_check_menu_item_get_active(menuitem))
827 return;
828 doc = document_get_current();
829 g_return_if_fail(doc != NULL);
831 sci_convert_eols(doc->editor->sci, SC_EOL_LF);
832 sci_set_eol_mode(doc->editor->sci, SC_EOL_LF);
836 void
837 on_cr_activate (GtkCheckMenuItem *menuitem,
838 gpointer user_data)
840 GeanyDocument *doc;
841 if (ignore_callback || ! gtk_check_menu_item_get_active(menuitem))
842 return;
843 doc = document_get_current();
844 g_return_if_fail(doc != NULL);
846 sci_convert_eols(doc->editor->sci, SC_EOL_CR);
847 sci_set_eol_mode(doc->editor->sci, SC_EOL_CR);
851 void
852 on_replace_tabs_activate (GtkMenuItem *menuitem,
853 gpointer user_data)
855 GeanyDocument *doc = document_get_current();
857 g_return_if_fail(doc != NULL);
859 editor_replace_tabs(doc->editor);
863 gboolean
864 toolbar_popup_menu (GtkWidget *widget,
865 GdkEventButton *event,
866 gpointer user_data)
868 if (event->button == 3)
870 GtkWidget *w;
872 ignore_toolbar_toggle = TRUE;
874 switch (toolbar_prefs.icon_style)
876 case 0: w = ui_lookup_widget(ui_widgets.toolbar_menu, "images_only2"); break;
877 case 1: w = ui_lookup_widget(ui_widgets.toolbar_menu, "text_only2"); break;
878 default: w = ui_lookup_widget(ui_widgets.toolbar_menu, "images_and_text2"); break;
880 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w), TRUE);
882 switch (toolbar_prefs.icon_size)
884 case GTK_ICON_SIZE_LARGE_TOOLBAR:
885 w = ui_lookup_widget(ui_widgets.toolbar_menu, "large_icons1"); break;
886 case GTK_ICON_SIZE_SMALL_TOOLBAR:
887 w = ui_lookup_widget(ui_widgets.toolbar_menu, "small_icons1"); break;
888 default: w = ui_lookup_widget(ui_widgets.toolbar_menu, "very_small_icons1"); break;
890 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w), TRUE);
892 ignore_toolbar_toggle = FALSE;
894 gtk_menu_popup(GTK_MENU(ui_widgets.toolbar_menu), NULL, NULL, NULL, NULL, event->button, event->time);
896 return TRUE;
898 return FALSE;
902 void on_toggle_case1_activate(GtkMenuItem *menuitem, gpointer user_data)
904 GeanyDocument *doc = document_get_current();
905 ScintillaObject *sci;
906 gchar *text;
907 gboolean keep_sel = TRUE;
909 g_return_if_fail(doc != NULL);
911 sci = doc->editor->sci;
912 if (! sci_has_selection(sci))
914 keybindings_send_command(GEANY_KEY_GROUP_SELECT, GEANY_KEYS_SELECT_WORD);
915 keep_sel = FALSE;
917 else
919 gchar *result = NULL;
920 gint cmd = SCI_LOWERCASE;
921 gint text_len = sci_get_selected_text_length(sci);
922 gboolean rectsel = scintilla_send_message(sci, SCI_SELECTIONISRECTANGLE, 0, 0);
924 text = g_malloc(text_len + 1);
925 sci_get_selected_text(sci, text);
927 if (utils_str_has_upper(text))
929 if (rectsel)
930 cmd = SCI_LOWERCASE;
931 else
932 result = g_utf8_strdown(text, -1);
935 else
937 if (rectsel)
938 cmd = SCI_UPPERCASE;
939 else
940 result = g_utf8_strup(text, -1);
944 if (result != NULL)
946 sci_replace_sel(sci, result);
947 g_free(result);
948 if (keep_sel)
949 sci_set_selection_start(sci, sci_get_current_position(sci) - text_len + 1);
951 else
952 sci_send_command(sci, cmd);
954 g_free(text);
960 void
961 on_show_toolbar1_toggled (GtkCheckMenuItem *checkmenuitem,
962 gpointer user_data)
964 if (ignore_callback) return;
966 toolbar_prefs.visible = (toolbar_prefs.visible) ? FALSE : TRUE;;
967 ui_widget_show_hide(GTK_WIDGET(main_widgets.toolbar), toolbar_prefs.visible);
971 void
972 on_fullscreen1_toggled (GtkCheckMenuItem *checkmenuitem,
973 gpointer user_data)
975 if (ignore_callback)
976 return;
978 ui_prefs.fullscreen = (ui_prefs.fullscreen) ? FALSE : TRUE;
979 ui_set_fullscreen();
983 void
984 on_show_messages_window1_toggled (GtkCheckMenuItem *checkmenuitem,
985 gpointer user_data)
987 if (ignore_callback)
988 return;
990 ui_prefs.msgwindow_visible = (ui_prefs.msgwindow_visible) ? FALSE : TRUE;
991 msgwin_show_hide(ui_prefs.msgwindow_visible);
995 void
996 on_markers_margin1_toggled (GtkCheckMenuItem *checkmenuitem,
997 gpointer user_data)
999 if (ignore_callback)
1000 return;
1002 editor_prefs.show_markers_margin = ! editor_prefs.show_markers_margin;
1003 ui_toggle_editor_features(GEANY_EDITOR_SHOW_MARKERS_MARGIN);
1007 void
1008 on_show_line_numbers1_toggled (GtkCheckMenuItem *checkmenuitem,
1009 gpointer user_data)
1011 if (ignore_callback)
1012 return;
1014 editor_prefs.show_linenumber_margin = ! editor_prefs.show_linenumber_margin;
1015 ui_toggle_editor_features(GEANY_EDITOR_SHOW_LINE_NUMBERS);
1019 void
1020 on_menu_show_white_space1_toggled (GtkCheckMenuItem *checkmenuitem,
1021 gpointer user_data)
1023 if (ignore_callback)
1024 return;
1026 editor_prefs.show_white_space = ! editor_prefs.show_white_space;
1027 ui_toggle_editor_features(GEANY_EDITOR_SHOW_WHITE_SPACE);
1031 void
1032 on_menu_show_line_endings1_toggled (GtkCheckMenuItem *checkmenuitem,
1033 gpointer user_data)
1035 if (ignore_callback)
1036 return;
1038 editor_prefs.show_line_endings = ! editor_prefs.show_line_endings;
1039 ui_toggle_editor_features(GEANY_EDITOR_SHOW_LINE_ENDINGS);
1043 void
1044 on_menu_show_indentation_guides1_toggled (GtkCheckMenuItem *checkmenuitem,
1045 gpointer user_data)
1047 if (ignore_callback)
1048 return;
1050 editor_prefs.show_indent_guide = ! editor_prefs.show_indent_guide;
1051 ui_toggle_editor_features(GEANY_EDITOR_SHOW_INDENTATION_GUIDES);
1055 void
1056 on_line_wrapping1_toggled (GtkCheckMenuItem *checkmenuitem,
1057 gpointer user_data)
1059 if (! ignore_callback)
1061 GeanyDocument *doc = document_get_current();
1062 g_return_if_fail(doc != NULL);
1064 editor_set_line_wrapping(doc->editor, ! doc->editor->line_wrapping);
1069 void
1070 on_set_file_readonly1_toggled (GtkCheckMenuItem *checkmenuitem,
1071 gpointer user_data)
1073 if (! ignore_callback)
1075 GeanyDocument *doc = document_get_current();
1076 g_return_if_fail(doc != NULL);
1078 doc->readonly = ! doc->readonly;
1079 sci_set_readonly(doc->editor->sci, doc->readonly);
1080 ui_update_tab_status(doc);
1081 ui_update_statusbar(doc, -1);
1086 void
1087 on_use_auto_indentation1_toggled (GtkCheckMenuItem *checkmenuitem,
1088 gpointer user_data)
1090 if (! ignore_callback)
1092 GeanyDocument *doc = document_get_current();
1093 g_return_if_fail(doc != NULL);
1095 doc->editor->auto_indent = ! doc->editor->auto_indent;
1100 static void find_usage(gboolean in_session)
1102 gint flags;
1103 gchar *search_text;
1104 GeanyDocument *doc = document_get_current();
1106 g_return_if_fail(doc != NULL);
1108 if (sci_has_selection(doc->editor->sci))
1109 { /* take selected text if there is a selection */
1110 search_text = g_malloc(sci_get_selected_text_length(doc->editor->sci) + 1);
1111 sci_get_selected_text(doc->editor->sci, search_text);
1112 flags = SCFIND_MATCHCASE;
1114 else
1116 search_text = g_strdup(editor_info.current_word);
1117 flags = SCFIND_MATCHCASE | SCFIND_WHOLEWORD;
1120 search_find_usage(search_text, flags, in_session);
1121 g_free(search_text);
1125 void
1126 on_find_document_usage1_activate (GtkMenuItem *menuitem,
1127 gpointer user_data)
1129 find_usage(FALSE);
1133 void
1134 on_find_usage1_activate (GtkMenuItem *menuitem,
1135 gpointer user_data)
1137 find_usage(TRUE);
1141 void
1142 on_goto_tag_activate (GtkMenuItem *menuitem,
1143 gpointer user_data)
1145 gboolean definition = (menuitem ==
1146 GTK_MENU_ITEM(ui_lookup_widget(main_widgets.editor_menu, "goto_tag_definition1")));
1147 GeanyDocument *doc = document_get_current();
1149 g_return_if_fail(doc != NULL);
1151 /* update cursor pos for navigating back afterwards */
1152 if (!sci_has_selection(doc->editor->sci))
1153 sci_set_current_position(doc->editor->sci, editor_info.click_pos, FALSE);
1155 /* use the keybinding callback as it checks for selections as well as current word */
1156 if (definition)
1157 keybindings_send_command(GEANY_KEY_GROUP_GOTO, GEANY_KEYS_GOTO_TAGDEFINITION);
1158 else
1159 keybindings_send_command(GEANY_KEY_GROUP_GOTO, GEANY_KEYS_GOTO_TAGDECLARATION);
1163 void
1164 on_count_words1_activate (GtkMenuItem *menuitem,
1165 gpointer user_data)
1167 tools_word_count();
1171 void
1172 on_show_color_chooser1_activate (GtkMenuItem *menuitem,
1173 gpointer user_data)
1175 gchar colour[9];
1176 GeanyDocument *doc = document_get_current();
1177 gint pos;
1179 g_return_if_fail(doc != NULL);
1181 pos = sci_get_current_position(doc->editor->sci);
1182 editor_find_current_word(doc->editor, pos, colour, sizeof colour, GEANY_WORDCHARS"#");
1183 tools_color_chooser(colour);
1187 void
1188 on_toolbutton_compile_clicked (GtkAction *action,
1189 gpointer user_data)
1191 keybindings_send_command(GEANY_KEY_GROUP_BUILD, GEANY_KEYS_BUILD_COMPILE);
1195 void
1196 on_find1_activate (GtkMenuItem *menuitem,
1197 gpointer user_data)
1199 search_show_find_dialog();
1203 static void find_again(gboolean change_direction)
1205 GeanyDocument *doc = document_get_current();
1207 g_return_if_fail(doc != NULL);
1209 if (search_data.text)
1211 gboolean forward = ! search_data.backwards;
1212 gint result = document_find_text(doc, search_data.text, search_data.flags,
1213 change_direction ? forward : !forward, FALSE, NULL);
1215 if (result > -1)
1216 editor_display_current_line(doc->editor, 0.3F);
1218 if (search_data.search_bar)
1219 ui_set_search_entry_background(
1220 toolbar_get_widget_child_by_name("SearchEntry"), (result > -1));
1225 void
1226 on_find_next1_activate (GtkMenuItem *menuitem,
1227 gpointer user_data)
1229 find_again(FALSE);
1233 void
1234 on_find_previous1_activate (GtkMenuItem *menuitem,
1235 gpointer user_data)
1237 if (search_data.flags & SCFIND_REGEXP)
1238 /* Can't reverse search order for a regex (find next ignores search backwards) */
1239 utils_beep();
1240 else
1241 find_again(TRUE);
1245 void
1246 on_find_nextsel1_activate (GtkMenuItem *menuitem,
1247 gpointer user_data)
1249 search_find_selection(document_get_current(), FALSE);
1253 void
1254 on_find_prevsel1_activate (GtkMenuItem *menuitem,
1255 gpointer user_data)
1257 search_find_selection(document_get_current(), TRUE);
1261 void
1262 on_replace1_activate (GtkMenuItem *menuitem,
1263 gpointer user_data)
1265 search_show_replace_dialog();
1269 void
1270 on_find_in_files1_activate (GtkMenuItem *menuitem,
1271 gpointer user_data)
1273 search_show_find_in_files_dialog(NULL);
1277 void
1278 on_go_to_line_activate (GtkMenuItem *menuitem,
1279 gpointer user_data)
1281 static gdouble val = 1;
1283 if (dialogs_show_input_numeric(_("Go to Line"), _("Enter the line you want to go to:"),
1284 &val, 1, 100000000, 1))
1286 GeanyDocument *doc = document_get_current();
1288 g_return_if_fail(doc != NULL);
1290 if (! editor_goto_line(doc->editor, (gint) val - 1))
1291 utils_beep();
1296 void
1297 on_toolbutton_goto_entry_activate(GtkAction *action, const gchar *text, gpointer user_data)
1299 GeanyDocument *doc = document_get_current();
1301 g_return_if_fail(doc != NULL);
1303 if (! editor_goto_line(doc->editor, atoi(text) - 1))
1304 utils_beep();
1305 else
1306 keybindings_send_command(GEANY_KEY_GROUP_FOCUS, GEANY_KEYS_FOCUS_EDITOR);
1310 void
1311 on_toolbutton_goto_clicked (GtkAction *action,
1312 gpointer user_data)
1314 GtkWidget *entry = toolbar_get_widget_child_by_name("GotoEntry");
1316 if (entry != NULL)
1318 const gchar *text = gtk_entry_get_text(GTK_ENTRY(entry));
1320 on_toolbutton_goto_entry_activate(NULL, text, NULL);
1322 else
1323 on_go_to_line_activate(NULL, NULL);
1327 void
1328 on_help1_activate (GtkMenuItem *menuitem,
1329 gpointer user_data)
1331 gchar *uri;
1333 uri = utils_get_help_url(NULL);
1334 utils_open_browser(uri);
1335 g_free(uri);
1339 void
1340 on_help_shortcuts1_activate (GtkMenuItem *menuitem,
1341 gpointer user_data)
1343 keybindings_show_shortcuts();
1347 void
1348 on_website1_activate (GtkMenuItem *menuitem,
1349 gpointer user_data)
1351 utils_open_browser(GEANY_HOMEPAGE);
1355 void
1356 on_comments_function_activate (GtkMenuItem *menuitem,
1357 gpointer user_data)
1359 GeanyDocument *doc = document_get_current();
1360 gchar *text;
1361 const gchar *cur_tag = NULL;
1362 gint line = -1, pos = 0;
1364 if (doc == NULL || doc->file_type == NULL)
1366 ui_set_statusbar(FALSE,
1367 _("Please set the filetype for the current file before using this function."));
1368 return;
1371 /* symbols_get_current_function returns -1 on failure, so sci_get_position_from_line
1372 * returns the current position, so it should be safe */
1373 line = symbols_get_current_function(doc, &cur_tag);
1374 pos = sci_get_position_from_line(doc->editor->sci, line - 1);
1376 text = templates_get_template_function(doc, cur_tag);
1378 sci_insert_text(doc->editor->sci, pos, text);
1379 g_free(text);
1383 void
1384 on_comments_multiline_activate (GtkMenuItem *menuitem,
1385 gpointer user_data)
1387 GeanyDocument *doc = document_get_current();
1389 if (doc == NULL || doc->file_type == NULL)
1391 ui_set_statusbar(FALSE,
1392 _("Please set the filetype for the current file before using this function."));
1393 return;
1396 verify_click_pos(doc); /* make sure that the click_pos is valid */
1398 if (doc->file_type->comment_open)
1399 editor_insert_multiline_comment(doc->editor);
1400 else
1401 utils_beep();
1405 void
1406 on_comments_gpl_activate (GtkMenuItem *menuitem,
1407 gpointer user_data)
1409 GeanyDocument *doc = document_get_current();
1410 gchar *text;
1412 g_return_if_fail(doc != NULL);
1414 text = templates_get_template_licence(doc, GEANY_TEMPLATE_GPL);
1416 verify_click_pos(doc); /* make sure that the click_pos is valid */
1418 sci_insert_text(doc->editor->sci, editor_info.click_pos, text);
1419 g_free(text);
1423 void
1424 on_comments_bsd_activate (GtkMenuItem *menuitem,
1425 gpointer user_data)
1428 GeanyDocument *doc = document_get_current();
1429 gchar *text;
1431 g_return_if_fail(doc != NULL);
1433 text = templates_get_template_licence(doc, GEANY_TEMPLATE_BSD);
1435 verify_click_pos(doc); /* make sure that the click_pos is valid */
1437 sci_insert_text(doc->editor->sci, editor_info.click_pos, text);
1438 g_free(text);
1443 void
1444 on_comments_changelog_activate (GtkMenuItem *menuitem,
1445 gpointer user_data)
1447 GeanyDocument *doc = document_get_current();
1448 gchar *text;
1450 g_return_if_fail(doc != NULL);
1452 text = templates_get_template_changelog(doc);
1453 sci_insert_text(doc->editor->sci, 0, text);
1454 /* sets the cursor to the right position to type the changelog text,
1455 * the template has 21 chars + length of name and email */
1456 sci_goto_pos(doc->editor->sci, 21 + strlen(template_prefs.developer) + strlen(template_prefs.mail), TRUE);
1458 g_free(text);
1462 void
1463 on_comments_fileheader_activate (GtkMenuItem *menuitem,
1464 gpointer user_data)
1466 GeanyDocument *doc = document_get_current();
1467 gchar *text;
1468 gchar *fname;
1469 GeanyFiletype *ft;
1471 g_return_if_fail(doc != NULL);
1473 ft = doc->file_type;
1474 fname = doc->file_name;
1475 text = templates_get_template_fileheader(FILETYPE_ID(ft), fname);
1477 sci_insert_text(doc->editor->sci, 0, text);
1478 sci_goto_pos(doc->editor->sci, 0, FALSE);
1479 g_free(text);
1483 void
1484 on_insert_date_activate (GtkMenuItem *menuitem,
1485 gpointer user_data)
1487 GeanyDocument *doc = document_get_current();
1488 gchar *format = NULL;
1489 gchar *time_str;
1491 g_return_if_fail(doc != NULL);
1493 /* set default value */
1494 if (utils_str_equal("", ui_prefs.custom_date_format))
1496 g_free(ui_prefs.custom_date_format);
1497 ui_prefs.custom_date_format = g_strdup("%d.%m.%Y");
1500 if (utils_str_equal(_("dd.mm.yyyy"), (gchar*) user_data))
1501 format = "%d.%m.%Y";
1502 else if (utils_str_equal(_("mm.dd.yyyy"), (gchar*) user_data))
1503 format = "%m.%d.%Y";
1504 else if (utils_str_equal(_("yyyy/mm/dd"), (gchar*) user_data))
1505 format = "%Y/%m/%d";
1506 else if (utils_str_equal(_("dd.mm.yyyy hh:mm:ss"), (gchar*) user_data))
1507 format = "%d.%m.%Y %H:%M:%S";
1508 else if (utils_str_equal(_("mm.dd.yyyy hh:mm:ss"), (gchar*) user_data))
1509 format = "%m.%d.%Y %H:%M:%S";
1510 else if (utils_str_equal(_("yyyy/mm/dd hh:mm:ss"), (gchar*) user_data))
1511 format = "%Y/%m/%d %H:%M:%S";
1512 else if (utils_str_equal(_("_Use Custom Date Format"), (gchar*) user_data))
1513 format = ui_prefs.custom_date_format;
1514 else
1516 setptr(ui_prefs.custom_date_format,
1517 dialogs_show_input(_("Custom Date Format"),
1518 _("Enter here a custom date and time format. "
1519 "You can use any conversion specifiers which can be used with the ANSI C strftime function."),
1520 ui_prefs.custom_date_format));
1521 return;
1524 time_str = utils_get_date_time(format, NULL);
1525 if (time_str != NULL)
1527 verify_click_pos(doc); /* make sure that the click_pos is valid */
1529 sci_insert_text(doc->editor->sci, editor_info.click_pos, time_str);
1530 sci_goto_pos(doc->editor->sci, editor_info.click_pos + strlen(time_str), FALSE);
1531 g_free(time_str);
1533 else
1535 utils_beep();
1536 ui_set_statusbar(TRUE,
1537 _("Date format string could not be converted (possibly too long)."));
1542 void
1543 on_insert_include_activate (GtkMenuItem *menuitem,
1544 gpointer user_data)
1546 GeanyDocument *doc = document_get_current();
1547 gint pos = -1;
1548 gchar *text;
1550 g_return_if_fail(doc != NULL);
1551 g_return_if_fail(user_data != NULL);
1553 verify_click_pos(doc); /* make sure that the click_pos is valid */
1555 if (utils_str_equal(user_data, "blank"))
1557 text = g_strdup("#include \"\"\n");
1558 pos = editor_info.click_pos + 10;
1560 else
1562 text = g_strconcat("#include <", user_data, ">\n", NULL);
1565 sci_insert_text(doc->editor->sci, editor_info.click_pos, text);
1566 g_free(text);
1567 if (pos >= 0)
1568 sci_goto_pos(doc->editor->sci, pos, FALSE);
1572 void
1573 on_file_properties_activate (GtkMenuItem *menuitem,
1574 gpointer user_data)
1576 GeanyDocument *doc = document_get_current();
1577 g_return_if_fail(doc != NULL);
1579 dialogs_show_file_properties(doc);
1583 void
1584 on_menu_fold_all1_activate (GtkMenuItem *menuitem,
1585 gpointer user_data)
1587 GeanyDocument *doc = document_get_current();
1588 g_return_if_fail(doc != NULL);
1590 editor_fold_all(doc->editor);
1594 void
1595 on_menu_unfold_all1_activate (GtkMenuItem *menuitem,
1596 gpointer user_data)
1598 GeanyDocument *doc = document_get_current();
1599 g_return_if_fail(doc != NULL);
1601 editor_unfold_all(doc->editor);
1605 void
1606 on_toolbutton_run_clicked (GtkAction *action,
1607 gpointer user_data)
1609 keybindings_send_command(GEANY_KEY_GROUP_BUILD, GEANY_KEYS_BUILD_RUN);
1613 void
1614 on_menu_remove_indicators1_activate (GtkMenuItem *menuitem,
1615 gpointer user_data)
1617 GeanyDocument *doc = document_get_current();
1618 g_return_if_fail(doc != NULL);
1620 editor_indicator_clear(doc->editor, GEANY_INDICATOR_ERROR);
1624 void
1625 on_print1_activate (GtkMenuItem *menuitem,
1626 gpointer user_data)
1628 GeanyDocument *doc = document_get_current();
1629 g_return_if_fail(doc != NULL);
1631 printing_print_doc(doc);
1635 void
1636 on_menu_select_all1_activate (GtkMenuItem *menuitem,
1637 gpointer user_data)
1639 GeanyDocument *doc = document_get_current();
1640 g_return_if_fail(doc != NULL);
1642 sci_select_all(doc->editor->sci);
1646 void
1647 on_menu_show_sidebar1_toggled (GtkCheckMenuItem *checkmenuitem,
1648 gpointer user_data)
1650 if (ignore_callback)
1651 return;
1653 ui_prefs.sidebar_visible = ! ui_prefs.sidebar_visible;
1655 if (! interface_prefs.sidebar_openfiles_visible && ! interface_prefs.sidebar_symbol_visible)
1657 interface_prefs.sidebar_openfiles_visible = TRUE;
1658 interface_prefs.sidebar_symbol_visible = TRUE;
1661 #if GTK_CHECK_VERSION(2, 14, 0)
1662 /* if window has input focus, set it back to the editor before toggling off */
1663 if (! ui_prefs.sidebar_visible &&
1664 gtk_container_get_focus_child(GTK_CONTAINER(main_widgets.sidebar_notebook)) != NULL)
1666 keybindings_send_command(GEANY_KEY_GROUP_FOCUS, GEANY_KEYS_FOCUS_EDITOR);
1668 #endif
1670 ui_sidebar_show_hide();
1674 void
1675 on_menu_write_unicode_bom1_toggled (GtkCheckMenuItem *checkmenuitem,
1676 gpointer user_data)
1678 if (! ignore_callback)
1680 GeanyDocument *doc = document_get_current();
1682 g_return_if_fail(doc != NULL);
1683 if (doc->readonly)
1685 utils_beep();
1686 return;
1689 document_undo_add(doc, UNDO_BOM, GINT_TO_POINTER(doc->has_bom));
1691 doc->has_bom = ! doc->has_bom;
1693 ui_update_statusbar(doc, -1);
1698 void
1699 on_menu_comment_line1_activate (GtkMenuItem *menuitem,
1700 gpointer user_data)
1702 GeanyDocument *doc = document_get_current();
1703 g_return_if_fail(doc != NULL);
1705 editor_do_comment(doc->editor, -1, FALSE, FALSE);
1709 void
1710 on_menu_uncomment_line1_activate (GtkMenuItem *menuitem,
1711 gpointer user_data)
1713 GeanyDocument *doc = document_get_current();
1714 g_return_if_fail(doc != NULL);
1716 editor_do_uncomment(doc->editor, -1, FALSE);
1720 void
1721 on_menu_toggle_line_commentation1_activate
1722 (GtkMenuItem *menuitem,
1723 gpointer user_data)
1725 GeanyDocument *doc = document_get_current();
1726 g_return_if_fail(doc != NULL);
1728 editor_do_comment_toggle(doc->editor);
1732 void
1733 on_menu_increase_indent1_activate (GtkMenuItem *menuitem,
1734 gpointer user_data)
1736 GeanyDocument *doc = document_get_current();
1737 g_return_if_fail(doc != NULL);
1739 editor_indent(doc->editor, TRUE);
1743 void
1744 on_menu_decrease_indent1_activate (GtkMenuItem *menuitem,
1745 gpointer user_data)
1747 GeanyDocument *doc = document_get_current();
1748 g_return_if_fail(doc != NULL);
1750 editor_indent(doc->editor, FALSE);
1754 void
1755 on_next_message1_activate (GtkMenuItem *menuitem,
1756 gpointer user_data)
1758 if (! ui_tree_view_find_next(GTK_TREE_VIEW(msgwindow.tree_msg),
1759 msgwin_goto_messages_file_line))
1760 ui_set_statusbar(FALSE, _("No more message items."));
1764 void
1765 on_previous_message1_activate (GtkMenuItem *menuitem,
1766 gpointer user_data)
1768 if (! ui_tree_view_find_previous(GTK_TREE_VIEW(msgwindow.tree_msg),
1769 msgwin_goto_messages_file_line))
1770 ui_set_statusbar(FALSE, _("No more message items."));
1774 void
1775 on_menu_comments_multiline_activate (GtkMenuItem *menuitem,
1776 gpointer user_data)
1778 insert_callback_from_menu = TRUE;
1779 on_comments_multiline_activate(menuitem, user_data);
1783 void
1784 on_menu_comments_gpl_activate (GtkMenuItem *menuitem,
1785 gpointer user_data)
1787 insert_callback_from_menu = TRUE;
1788 on_comments_gpl_activate(menuitem, user_data);
1792 void
1793 on_menu_comments_bsd_activate (GtkMenuItem *menuitem,
1794 gpointer user_data)
1796 insert_callback_from_menu = TRUE;
1797 on_comments_bsd_activate(menuitem, user_data);
1801 void
1802 on_menu_insert_include_activate (GtkMenuItem *menuitem,
1803 gpointer user_data)
1805 insert_callback_from_menu = TRUE;
1806 on_insert_include_activate(menuitem, user_data);
1810 void
1811 on_menu_insert_date_activate (GtkMenuItem *menuitem,
1812 gpointer user_data)
1814 insert_callback_from_menu = TRUE;
1815 on_insert_date_activate(menuitem, user_data);
1819 void
1820 on_project_new1_activate (GtkMenuItem *menuitem,
1821 gpointer user_data)
1823 project_new();
1827 void
1828 on_project_open1_activate (GtkMenuItem *menuitem,
1829 gpointer user_data)
1831 project_open();
1835 void
1836 on_project_close1_activate (GtkMenuItem *menuitem,
1837 gpointer user_data)
1839 project_close(TRUE);
1843 void
1844 on_project_properties1_activate (GtkMenuItem *menuitem,
1845 gpointer user_data)
1847 project_properties();
1851 void
1852 on_menu_project1_activate (GtkMenuItem *menuitem,
1853 gpointer user_data)
1855 static GtkWidget *item_close = NULL;
1856 static GtkWidget *item_properties = NULL;
1858 if (item_close == NULL)
1860 item_close = ui_lookup_widget(main_widgets.window, "project_close1");
1861 item_properties = ui_lookup_widget(main_widgets.window, "project_properties1");
1864 gtk_widget_set_sensitive(item_close, (app->project != NULL));
1865 gtk_widget_set_sensitive(item_properties, (app->project != NULL));
1866 gtk_widget_set_sensitive(ui_widgets.recent_projects_menuitem,
1867 g_queue_get_length(ui_prefs.recent_projects_queue) > 0);
1871 void
1872 on_menu_open_selected_file1_activate (GtkMenuItem *menuitem,
1873 gpointer user_data)
1875 GeanyDocument *doc = document_get_current();
1876 gchar *sel = NULL;
1877 const gchar *wc;
1879 #ifdef G_OS_WIN32
1880 wc = GEANY_WORDCHARS "./-" "\\";
1881 #else
1882 wc = GEANY_WORDCHARS "./-";
1883 #endif
1885 g_return_if_fail(doc != NULL);
1887 sel = editor_get_default_selection(doc->editor, TRUE, wc);
1889 if (sel != NULL)
1891 gchar *locale_filename, *filename = NULL;
1893 if (g_path_is_absolute(sel))
1894 filename = g_strdup(sel);
1895 else
1896 { /* relative filename, add the path of the current file */
1897 gchar *path;
1899 path = utils_get_current_file_dir_utf8();
1900 if (!path)
1901 path = g_get_current_dir();
1903 filename = g_build_path(G_DIR_SEPARATOR_S, path, sel, NULL);
1905 if (! g_file_test(filename, G_FILE_TEST_EXISTS) &&
1906 app->project != NULL && NZV(app->project->base_path))
1908 /* try the project's base path */
1909 setptr(path, project_get_base_path());
1910 setptr(filename, g_build_path(G_DIR_SEPARATOR_S, path, sel, NULL));
1912 g_free(path);
1915 locale_filename = utils_get_locale_from_utf8(filename);
1916 document_open_file(locale_filename, FALSE, NULL, NULL);
1918 g_free(filename);
1919 g_free(locale_filename);
1920 g_free(sel);
1925 void
1926 on_remove_markers1_activate (GtkMenuItem *menuitem,
1927 gpointer user_data)
1929 GeanyDocument *doc = document_get_current();
1930 g_return_if_fail(doc != NULL);
1932 sci_marker_delete_all(doc->editor->sci, 0); /* delete the yellow tag marker */
1933 sci_marker_delete_all(doc->editor->sci, 1); /* delete user markers */
1934 editor_indicator_clear(doc->editor, GEANY_INDICATOR_SEARCH);
1938 void
1939 on_load_tags1_activate (GtkMenuItem *menuitem,
1940 gpointer user_data)
1942 symbols_show_load_tags_dialog();
1946 void
1947 on_context_action1_activate (GtkMenuItem *menuitem,
1948 gpointer user_data)
1950 gchar *word, *command;
1951 GError *error = NULL;
1952 GeanyDocument *doc = document_get_current();
1954 g_return_if_fail(doc != NULL);
1956 if (sci_has_selection(doc->editor->sci))
1957 { /* take selected text if there is a selection */
1958 word = g_malloc(sci_get_selected_text_length(doc->editor->sci) + 1);
1959 sci_get_selected_text(doc->editor->sci, word);
1961 else
1963 word = g_strdup(editor_info.current_word);
1966 /* use the filetype specific command if available, fallback to global command otherwise */
1967 if (doc->file_type != NULL &&
1968 NZV(doc->file_type->context_action_cmd))
1970 command = g_strdup(doc->file_type->context_action_cmd);
1972 else
1974 command = g_strdup(tool_prefs.context_action_cmd);
1977 /* substitute the wildcard %s and run the command if it is non empty */
1978 if (NZV(command))
1980 utils_str_replace_all(&command, "%s", word);
1982 if (! g_spawn_command_line_async(command, &error))
1984 ui_set_statusbar(TRUE, "Context action command failed: %s", error->message);
1985 g_error_free(error);
1988 g_free(word);
1989 g_free(command);
1993 void
1994 on_menu_toggle_all_additional_widgets1_activate
1995 (GtkMenuItem *menuitem,
1996 gpointer user_data)
1998 static gint hide_all = -1;
1999 GtkCheckMenuItem *msgw = GTK_CHECK_MENU_ITEM(
2000 ui_lookup_widget(main_widgets.window, "menu_show_messages_window1"));
2001 GtkCheckMenuItem *toolbari = GTK_CHECK_MENU_ITEM(
2002 ui_lookup_widget(main_widgets.window, "menu_show_toolbar1"));
2004 /* get the initial state (necessary if Geany was closed with hide_all = TRUE) */
2005 if (G_UNLIKELY(hide_all == -1))
2007 if (! gtk_check_menu_item_get_active(msgw) &&
2008 ! interface_prefs.show_notebook_tabs &&
2009 ! gtk_check_menu_item_get_active(toolbari))
2011 hide_all = TRUE;
2013 else
2014 hide_all = FALSE;
2017 hide_all = ! hide_all; /* toggle */
2019 if (hide_all)
2021 if (gtk_check_menu_item_get_active(msgw))
2022 gtk_check_menu_item_set_active(msgw, ! gtk_check_menu_item_get_active(msgw));
2024 interface_prefs.show_notebook_tabs = FALSE;
2025 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets.notebook), interface_prefs.show_notebook_tabs);
2027 ui_statusbar_showhide(FALSE);
2029 if (gtk_check_menu_item_get_active(toolbari))
2030 gtk_check_menu_item_set_active(toolbari, ! gtk_check_menu_item_get_active(toolbari));
2032 else
2035 if (! gtk_check_menu_item_get_active(msgw))
2036 gtk_check_menu_item_set_active(msgw, ! gtk_check_menu_item_get_active(msgw));
2038 interface_prefs.show_notebook_tabs = TRUE;
2039 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets.notebook), interface_prefs.show_notebook_tabs);
2041 ui_statusbar_showhide(TRUE);
2043 if (! gtk_check_menu_item_get_active(toolbari))
2044 gtk_check_menu_item_set_active(toolbari, ! gtk_check_menu_item_get_active(toolbari));
2049 void
2050 on_forward_activate (GtkMenuItem *menuitem,
2051 gpointer user_data)
2053 navqueue_go_forward();
2057 void
2058 on_back_activate (GtkMenuItem *menuitem,
2059 gpointer user_data)
2061 navqueue_go_back();
2065 gboolean on_motion_event(GtkWidget *widget, GdkEventMotion *event, gpointer user_data)
2067 if (prefs.auto_focus && ! GTK_WIDGET_HAS_FOCUS(widget))
2068 gtk_widget_grab_focus(widget);
2070 return FALSE;
2074 static void set_indent_type(GtkCheckMenuItem *menuitem, GeanyIndentType type)
2076 GeanyDocument *doc;
2078 if (ignore_callback || ! gtk_check_menu_item_get_active(menuitem))
2079 return;
2081 doc = document_get_current();
2082 g_return_if_fail(doc != NULL);
2084 editor_set_indent_type(doc->editor, type);
2085 ui_update_statusbar(doc, -1);
2089 void
2090 on_tabs1_activate (GtkCheckMenuItem *menuitem,
2091 gpointer user_data)
2093 set_indent_type(menuitem, GEANY_INDENT_TYPE_TABS);
2097 void
2098 on_spaces1_activate (GtkCheckMenuItem *menuitem,
2099 gpointer user_data)
2101 set_indent_type(menuitem, GEANY_INDENT_TYPE_SPACES);
2105 void
2106 on_tabs_and_spaces1_activate (GtkCheckMenuItem *menuitem,
2107 gpointer user_data)
2109 set_indent_type(menuitem, GEANY_INDENT_TYPE_BOTH);
2113 void
2114 on_strip_trailing_spaces1_activate (GtkMenuItem *menuitem,
2115 gpointer user_data)
2117 GeanyDocument *doc;
2119 if (ignore_callback)
2120 return;
2122 doc = document_get_current();
2123 g_return_if_fail(doc != NULL);
2125 editor_strip_trailing_spaces(doc->editor);
2129 void
2130 on_page_setup1_activate (GtkMenuItem *menuitem,
2131 gpointer user_data)
2133 #if GTK_CHECK_VERSION(2, 10, 0)
2134 printing_page_setup_gtk();
2135 #endif
2139 gboolean
2140 on_escape_key_press_event (GtkWidget *widget,
2141 GdkEventKey *event,
2142 gpointer user_data)
2144 guint state = event->state & gtk_accelerator_get_default_mod_mask();
2146 /* make pressing escape in the sidebar and toolbar focus the editor */
2147 if (event->keyval == GDK_Escape && state == 0)
2149 keybindings_send_command(GEANY_KEY_GROUP_FOCUS, GEANY_KEYS_FOCUS_EDITOR);
2150 return TRUE;
2152 return FALSE;
2156 void
2157 on_line_breaking1_activate (GtkMenuItem *menuitem,
2158 gpointer user_data)
2160 GeanyDocument *doc;
2162 if (ignore_callback)
2163 return;
2165 doc = document_get_current();
2166 g_return_if_fail(doc != NULL);
2168 doc->editor->line_breaking = !doc->editor->line_breaking;
2172 void
2173 on_replace_spaces_activate (GtkMenuItem *menuitem,
2174 gpointer user_data)
2176 GeanyDocument *doc = document_get_current();
2178 g_return_if_fail(doc != NULL);
2180 editor_replace_spaces(doc->editor);
2184 void
2185 on_search1_activate (GtkMenuItem *menuitem,
2186 gpointer user_data)
2188 GtkWidget *next_message = ui_lookup_widget(main_widgets.window, "next_message1");
2189 GtkWidget *previous_message = ui_lookup_widget(main_widgets.window, "previous_message1");
2190 gboolean have_messages;
2192 /* enable commands if the messages window has any items */
2193 have_messages = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(msgwindow.store_msg),
2194 NULL) > 0;
2196 gtk_widget_set_sensitive(next_message, have_messages);
2197 gtk_widget_set_sensitive(previous_message, have_messages);
2201 /* simple implementation (vs. close all which doesn't close documents if cancelled) */
2202 void
2203 on_close_other_documents1_activate (GtkMenuItem *menuitem,
2204 gpointer user_data)
2206 guint i;
2207 GeanyDocument *doc, *cur_doc = document_get_current();
2209 for (i = 0; i < documents_array->len; i++)
2211 doc = documents[i];
2213 if (doc == cur_doc || ! doc->is_valid)
2214 continue;
2216 if (! document_close(doc))
2217 break;
2222 void
2223 on_menu_reload_configuration1_activate (GtkMenuItem *menuitem,
2224 gpointer user_data)
2226 main_reload_configuration();
2230 void
2231 on_debug_messages1_activate (GtkMenuItem *menuitem,
2232 gpointer user_data)
2234 log_show_debug_messages_dialog();
2238 void
2239 on_send_selection_to_vte1_activate (GtkMenuItem *menuitem,
2240 gpointer user_data)
2242 #ifdef HAVE_VTE
2243 if (vte_info.load_vte)
2244 vte_send_selection_to_vte();
2245 #endif
2249 gboolean on_window_state_event (GtkWidget *widget,
2250 GdkEventWindowState *event,
2251 gpointer user_data)
2254 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
2256 static GtkWidget *menuitem = NULL;
2258 if (menuitem == NULL)
2259 menuitem = ui_lookup_widget(widget, "menu_fullscreen1");
2261 ignore_callback = TRUE;
2263 ui_prefs.fullscreen = (event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN) ? TRUE : FALSE;
2264 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), ui_prefs.fullscreen);
2266 ignore_callback = FALSE;
2268 return FALSE;
2272 void
2273 on_customize_toolbar1_activate (GtkMenuItem *menuitem,
2274 gpointer user_data)
2276 toolbar_configure(GTK_WINDOW(main_widgets.window));
2280 void
2281 on_button_customize_toolbar_clicked (GtkButton *button,
2282 gpointer user_data)
2284 toolbar_configure(GTK_WINDOW(ui_widgets.prefs_dialog));
2288 void
2289 on_cut_current_line_s_1_activate (GtkMenuItem *menuitem,
2290 gpointer user_data)
2292 keybindings_send_command(GEANY_KEY_GROUP_CLIPBOARD, GEANY_KEYS_CLIPBOARD_CUTLINE);
2296 void
2297 on_copy_current_line_s_1_activate (GtkMenuItem *menuitem,
2298 gpointer user_data)
2300 keybindings_send_command(GEANY_KEY_GROUP_CLIPBOARD, GEANY_KEYS_CLIPBOARD_COPYLINE);
2304 void
2305 on_delete_current_line_s_1_activate (GtkMenuItem *menuitem,
2306 gpointer user_data)
2308 keybindings_send_command(GEANY_KEY_GROUP_EDITOR, GEANY_KEYS_EDITOR_DELETELINE);
2312 void
2313 on_duplicate_line_or_selection1_activate
2314 (GtkMenuItem *menuitem,
2315 gpointer user_data)
2317 keybindings_send_command(GEANY_KEY_GROUP_EDITOR, GEANY_KEYS_EDITOR_DUPLICATELINE);
2321 void
2322 on_select_current_line_s_1_activate (GtkMenuItem *menuitem,
2323 gpointer user_data)
2325 keybindings_send_command(GEANY_KEY_GROUP_SELECT, GEANY_KEYS_SELECT_LINE);
2329 void
2330 on_select_current_paragraph1_activate (GtkMenuItem *menuitem,
2331 gpointer user_data)
2333 keybindings_send_command(GEANY_KEY_GROUP_SELECT, GEANY_KEYS_SELECT_PARAGRAPH);
2337 void
2338 on_insert_alternative_white_space1_activate
2339 (GtkMenuItem *menuitem,
2340 gpointer user_data)
2342 keybindings_send_command(GEANY_KEY_GROUP_INSERT, GEANY_KEYS_INSERT_ALTWHITESPACE);
2346 void
2347 on_go_to_next_marker1_activate (GtkMenuItem *menuitem,
2348 gpointer user_data)
2350 keybindings_send_command(GEANY_KEY_GROUP_GOTO, GEANY_KEYS_GOTO_NEXTMARKER);
2354 void
2355 on_go_to_previous_marker1_activate (GtkMenuItem *menuitem,
2356 gpointer user_data)
2358 keybindings_send_command(GEANY_KEY_GROUP_GOTO, GEANY_KEYS_GOTO_PREVIOUSMARKER);
2362 void
2363 on_reflow_lines_block1_activate (GtkMenuItem *menuitem,
2364 gpointer user_data)
2366 keybindings_send_command(GEANY_KEY_GROUP_FORMAT, GEANY_KEYS_FORMAT_REFLOWPARAGRAPH);
2370 void
2371 on_transpose_current_line1_activate (GtkMenuItem *menuitem,
2372 gpointer user_data)
2374 keybindings_send_command(GEANY_KEY_GROUP_EDITOR, GEANY_KEYS_EDITOR_TRANSPOSELINE);
2378 void
2379 on_smart_line_indent1_activate (GtkMenuItem *menuitem,
2380 gpointer user_data)
2382 keybindings_send_command(GEANY_KEY_GROUP_FORMAT, GEANY_KEYS_FORMAT_AUTOINDENT);
2386 void
2387 on_plugin_preferences1_activate (GtkMenuItem *menuitem,
2388 gpointer user_data)
2390 #ifdef HAVE_PLUGINS
2391 plugin_show_configure(NULL);
2392 #endif