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.
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.
34 #include <gdk/gdkkeysyms.h>
35 #include <glib/gstdio.h>
38 #include "callbacks.h"
43 #include "documentprivate.h"
44 #include "filetypes.h"
45 #include "sciwrappers.h"
51 #include "msgwindow.h"
54 #include "templates.h"
56 #include "keybindings.h"
57 #include "encodings.h"
68 #include "pluginutils.h"
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)
97 for (i
= 0; i
< documents_array
->len
; i
++)
99 if (documents
[i
]->is_valid
&& documents
[i
]->changed
)
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
;
136 /* wrapper function to abort exit process if cancel button is pressed */
138 on_exit_clicked (GtkWidget
*widget
, gpointer gdata
)
140 main_status
.quitting
= TRUE
;
142 if (! check_no_unsaved())
144 if (document_account_for_unsaved())
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?")))
159 main_status
.quitting
= FALSE
;
169 on_new1_activate (GtkMenuItem
*menuitem
,
172 document_new_file(NULL
, NULL
, NULL
);
177 on_save1_activate (GtkMenuItem
*menuitem
,
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();
188 document_save_file(doc
, FALSE
);
194 on_save_as1_activate (GtkMenuItem
*menuitem
,
197 dialogs_show_save_as();
202 on_save_all1_activate (GtkMenuItem
*menuitem
,
205 gint i
, max
= gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets
.notebook
));
206 GeanyDocument
*doc
, *cur_doc
= document_get_current();
209 for (i
= 0; i
< max
; i
++)
211 doc
= document_get_from_page(i
);
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())
224 if (document_save_file(doc
, FALSE
))
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
);
239 on_close_all1_activate (GtkMenuItem
*menuitem
,
242 document_close_all();
247 on_close1_activate (GtkMenuItem
*menuitem
,
250 GeanyDocument
*doc
= document_get_current();
252 g_return_if_fail(doc
!= NULL
);
259 on_quit1_activate (GtkMenuItem
*menuitem
,
262 on_exit_clicked(NULL
, NULL
);
267 on_file1_activate (GtkMenuItem
*menuitem
,
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
);
281 /* edit actions, c&p & co, from menu bar and from popup menu */
283 on_edit1_activate (GtkMenuItem
*menuitem
,
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");
294 gtk_widget_hide(item
);
296 gtk_widget_set_sensitive(item
, plugins_have_preferences());
302 on_undo1_activate (GtkMenuItem
*menuitem
,
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
);
318 on_redo1_activate (GtkMenuItem
*menuitem
,
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
);
334 on_cut1_activate (GtkMenuItem
*menuitem
,
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
));
343 if (IS_SCINTILLA(focusw
) && doc
!= NULL
)
344 sci_cut(doc
->editor
->sci
);
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
);
356 on_copy1_activate (GtkMenuItem
*menuitem
,
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
));
365 if (IS_SCINTILLA(focusw
) && doc
!= NULL
)
366 sci_copy(doc
->editor
->sci
);
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
));
378 on_paste1_activate (GtkMenuItem
*menuitem
,
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
));
387 if (IS_SCINTILLA(focusw
) && doc
!= NULL
)
389 sci_paste(doc
->editor
->sci
);
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
,
403 on_delete1_activate (GtkMenuItem
*menuitem
,
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
));
412 if (IS_SCINTILLA(focusw
) && doc
!= NULL
&& sci_has_selection(doc
->editor
->sci
))
413 sci_clear(doc
->editor
->sci
);
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
);
425 on_preferences1_activate (GtkMenuItem
*menuitem
,
432 /* about menu item */
434 on_info1_activate (GtkMenuItem
*menuitem
,
443 on_open1_activate (GtkMenuItem
*menuitem
,
446 dialogs_show_open_file();
450 /* quit toolbar button */
452 on_toolbutton_quit_clicked (GtkAction
*action
,
455 on_exit_clicked(NULL
, NULL
);
461 on_toolbutton_reload_clicked (GtkAction
*action
,
464 on_reload_as_activate(NULL
, GINT_TO_POINTER(-1));
468 /* also used for reloading when user_data is -1 */
470 on_reload_as_activate (GtkMenuItem
*menuitem
,
473 GeanyDocument
*doc
= document_get_current();
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
);
483 if (i
>= GEANY_ENCODINGS_MAX
|| encodings
[i
].charset
== NULL
)
485 charset
= encodings
[i
].charset
;
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
);
497 ui_update_statusbar(doc
, -1);
504 on_images_and_text2_activate (GtkCheckMenuItem
*menuitem
,
507 if (ignore_toolbar_toggle
|| ! gtk_check_menu_item_get_active(menuitem
))
510 gtk_toolbar_set_style(GTK_TOOLBAR(main_widgets
.toolbar
), GTK_TOOLBAR_BOTH
);
511 toolbar_prefs
.icon_style
= GTK_TOOLBAR_BOTH
;
516 on_images_only2_activate (GtkCheckMenuItem
*menuitem
,
519 if (ignore_toolbar_toggle
|| ! gtk_check_menu_item_get_active(menuitem
))
522 gtk_toolbar_set_style(GTK_TOOLBAR(main_widgets
.toolbar
), GTK_TOOLBAR_ICONS
);
523 toolbar_prefs
.icon_style
= GTK_TOOLBAR_ICONS
;
528 on_text_only2_activate (GtkCheckMenuItem
*menuitem
,
531 if (ignore_toolbar_toggle
|| ! gtk_check_menu_item_get_active(menuitem
))
534 gtk_toolbar_set_style(GTK_TOOLBAR(main_widgets
.toolbar
), GTK_TOOLBAR_TEXT
);
535 toolbar_prefs
.icon_style
= GTK_TOOLBAR_TEXT
;
540 on_change_font1_activate (GtkMenuItem
*menuitem
,
543 dialogs_show_open_font();
549 on_toolbutton_new_clicked (GtkAction
*action
,
552 document_new_file(NULL
, NULL
, NULL
);
558 on_toolbutton_open_clicked (GtkAction
*action
,
561 dialogs_show_open_file();
567 on_toolbutton_save_clicked (GtkAction
*action
,
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
;
586 on_toolbar_search_entry_changed(GtkAction
*action
, const gchar
*text
, gpointer user_data
)
588 GeanyDocument
*doc
= document_get_current();
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
);
600 on_toolbutton_search_clicked (GtkAction
*action
,
603 GeanyDocument
*doc
= document_get_current();
605 GtkWidget
*entry
= toolbar_get_widget_child_by_name("SearchEntry");
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
);
617 on_find1_activate(NULL
, NULL
);
622 on_toolbar_large_icons1_activate (GtkCheckMenuItem
*menuitem
,
625 if (ignore_toolbar_toggle
|| ! gtk_check_menu_item_get_active(menuitem
))
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
);
634 on_toolbar_small_icons1_activate (GtkCheckMenuItem
*menuitem
,
637 if (ignore_toolbar_toggle
|| ! gtk_check_menu_item_get_active(menuitem
))
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
);
646 on_very_small_icons1_activate (GtkCheckMenuItem
*menuitem
,
649 if (ignore_toolbar_toggle
|| ! gtk_check_menu_item_get_active(menuitem
))
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 */
659 on_hide_toolbar1_activate (GtkMenuItem
*menuitem
,
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 */
669 on_zoom_in1_activate (GtkMenuItem
*menuitem
,
672 GeanyDocument
*doc
= document_get_current();
673 static gint done
= 1;
675 g_return_if_fail(doc
!= NULL
);
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 */
686 on_zoom_out1_activate (GtkMenuItem
*menuitem
,
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
);
700 on_normal_size1_activate (GtkMenuItem
*menuitem
,
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);
714 on_toolbutton_close_clicked (GtkAction
*action
,
717 on_close1_activate(NULL
, NULL
);
722 on_toolbutton_close_all_clicked (GtkAction
*action
,
725 on_close_all1_activate(NULL
, NULL
);
730 on_toolbutton_preferences_clicked (GtkAction
*action
,
733 on_preferences1_activate(NULL
, NULL
);
737 static gboolean
delayed_check_disk_status(gpointer data
)
739 document_check_disk_status(data
, 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 */
747 on_notebook1_switch_page_after (GtkNotebook
*notebook
,
748 GtkNotebookPage
*page
,
754 if (G_UNLIKELY(main_status
.opening_session_files
) || G_UNLIKELY(main_status
.closing_all
))
757 if (page_num
== (guint
) -1 && page
!= NULL
)
758 doc
= document_find_by_sci(SCINTILLA(page
));
760 doc
= document_get_from_page(page_num
);
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
);
777 vte_cwd((doc
->real_path
!= NULL
) ? doc
->real_path
: doc
->file_name
, FALSE
);
780 g_signal_emit_by_name(geany_object
, "document-activate", doc
);
786 on_tv_notebook_switch_page (GtkNotebook
*notebook
,
787 GtkNotebookPage
*page
,
791 /* suppress selection changed signal when switching to the open files list */
792 ignore_callback
= TRUE
;
797 on_tv_notebook_switch_page_after (GtkNotebook
*notebook
,
798 GtkNotebookPage
*page
,
802 ignore_callback
= FALSE
;
807 on_crlf_activate (GtkCheckMenuItem
*menuitem
,
811 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
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
);
822 on_lf_activate (GtkCheckMenuItem
*menuitem
,
826 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
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
);
837 on_cr_activate (GtkCheckMenuItem
*menuitem
,
841 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
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
);
852 on_replace_tabs_activate (GtkMenuItem
*menuitem
,
855 GeanyDocument
*doc
= document_get_current();
857 g_return_if_fail(doc
!= NULL
);
859 editor_replace_tabs(doc
->editor
);
864 toolbar_popup_menu (GtkWidget
*widget
,
865 GdkEventButton
*event
,
868 if (event
->button
== 3)
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
);
902 void on_toggle_case1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
904 GeanyDocument
*doc
= document_get_current();
905 ScintillaObject
*sci
;
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
);
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
))
932 result
= g_utf8_strdown(text
, -1);
940 result
= g_utf8_strup(text
, -1);
946 sci_replace_sel(sci
, result
);
949 sci_set_selection_start(sci
, sci_get_current_position(sci
) - text_len
+ 1);
952 sci_send_command(sci
, cmd
);
961 on_show_toolbar1_toggled (GtkCheckMenuItem
*checkmenuitem
,
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
);
972 on_fullscreen1_toggled (GtkCheckMenuItem
*checkmenuitem
,
978 ui_prefs
.fullscreen
= (ui_prefs
.fullscreen
) ? FALSE
: TRUE
;
984 on_show_messages_window1_toggled (GtkCheckMenuItem
*checkmenuitem
,
990 ui_prefs
.msgwindow_visible
= (ui_prefs
.msgwindow_visible
) ? FALSE
: TRUE
;
991 msgwin_show_hide(ui_prefs
.msgwindow_visible
);
996 on_markers_margin1_toggled (GtkCheckMenuItem
*checkmenuitem
,
1002 editor_prefs
.show_markers_margin
= ! editor_prefs
.show_markers_margin
;
1003 ui_toggle_editor_features(GEANY_EDITOR_SHOW_MARKERS_MARGIN
);
1008 on_show_line_numbers1_toggled (GtkCheckMenuItem
*checkmenuitem
,
1011 if (ignore_callback
)
1014 editor_prefs
.show_linenumber_margin
= ! editor_prefs
.show_linenumber_margin
;
1015 ui_toggle_editor_features(GEANY_EDITOR_SHOW_LINE_NUMBERS
);
1020 on_menu_show_white_space1_toggled (GtkCheckMenuItem
*checkmenuitem
,
1023 if (ignore_callback
)
1026 editor_prefs
.show_white_space
= ! editor_prefs
.show_white_space
;
1027 ui_toggle_editor_features(GEANY_EDITOR_SHOW_WHITE_SPACE
);
1032 on_menu_show_line_endings1_toggled (GtkCheckMenuItem
*checkmenuitem
,
1035 if (ignore_callback
)
1038 editor_prefs
.show_line_endings
= ! editor_prefs
.show_line_endings
;
1039 ui_toggle_editor_features(GEANY_EDITOR_SHOW_LINE_ENDINGS
);
1044 on_menu_show_indentation_guides1_toggled (GtkCheckMenuItem
*checkmenuitem
,
1047 if (ignore_callback
)
1050 editor_prefs
.show_indent_guide
= ! editor_prefs
.show_indent_guide
;
1051 ui_toggle_editor_features(GEANY_EDITOR_SHOW_INDENTATION_GUIDES
);
1056 on_line_wrapping1_toggled (GtkCheckMenuItem
*checkmenuitem
,
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
);
1070 on_set_file_readonly1_toggled (GtkCheckMenuItem
*checkmenuitem
,
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);
1087 on_use_auto_indentation1_toggled (GtkCheckMenuItem
*checkmenuitem
,
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
)
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
;
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
);
1126 on_find_document_usage1_activate (GtkMenuItem
*menuitem
,
1134 on_find_usage1_activate (GtkMenuItem
*menuitem
,
1142 on_goto_tag_activate (GtkMenuItem
*menuitem
,
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 */
1157 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_TAGDEFINITION
);
1159 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_TAGDECLARATION
);
1164 on_count_words1_activate (GtkMenuItem
*menuitem
,
1172 on_show_color_chooser1_activate (GtkMenuItem
*menuitem
,
1176 GeanyDocument
*doc
= document_get_current();
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
);
1188 on_toolbutton_compile_clicked (GtkAction
*action
,
1191 keybindings_send_command(GEANY_KEY_GROUP_BUILD
, GEANY_KEYS_BUILD_COMPILE
);
1196 on_find1_activate (GtkMenuItem
*menuitem
,
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
);
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));
1226 on_find_next1_activate (GtkMenuItem
*menuitem
,
1234 on_find_previous1_activate (GtkMenuItem
*menuitem
,
1237 if (search_data
.flags
& SCFIND_REGEXP
)
1238 /* Can't reverse search order for a regex (find next ignores search backwards) */
1246 on_find_nextsel1_activate (GtkMenuItem
*menuitem
,
1249 search_find_selection(document_get_current(), FALSE
);
1254 on_find_prevsel1_activate (GtkMenuItem
*menuitem
,
1257 search_find_selection(document_get_current(), TRUE
);
1262 on_replace1_activate (GtkMenuItem
*menuitem
,
1265 search_show_replace_dialog();
1270 on_find_in_files1_activate (GtkMenuItem
*menuitem
,
1273 search_show_find_in_files_dialog(NULL
);
1278 on_go_to_line_activate (GtkMenuItem
*menuitem
,
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))
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))
1306 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
1311 on_toolbutton_goto_clicked (GtkAction
*action
,
1314 GtkWidget
*entry
= toolbar_get_widget_child_by_name("GotoEntry");
1318 const gchar
*text
= gtk_entry_get_text(GTK_ENTRY(entry
));
1320 on_toolbutton_goto_entry_activate(NULL
, text
, NULL
);
1323 on_go_to_line_activate(NULL
, NULL
);
1328 on_help1_activate (GtkMenuItem
*menuitem
,
1333 uri
= utils_get_help_url(NULL
);
1334 utils_open_browser(uri
);
1340 on_help_shortcuts1_activate (GtkMenuItem
*menuitem
,
1343 keybindings_show_shortcuts();
1348 on_website1_activate (GtkMenuItem
*menuitem
,
1351 utils_open_browser(GEANY_HOMEPAGE
);
1356 on_comments_function_activate (GtkMenuItem
*menuitem
,
1359 GeanyDocument
*doc
= document_get_current();
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."));
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
);
1384 on_comments_multiline_activate (GtkMenuItem
*menuitem
,
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."));
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
);
1406 on_comments_gpl_activate (GtkMenuItem
*menuitem
,
1409 GeanyDocument
*doc
= document_get_current();
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
);
1424 on_comments_bsd_activate (GtkMenuItem
*menuitem
,
1428 GeanyDocument
*doc
= document_get_current();
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
);
1444 on_comments_changelog_activate (GtkMenuItem
*menuitem
,
1447 GeanyDocument
*doc
= document_get_current();
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
);
1463 on_comments_fileheader_activate (GtkMenuItem
*menuitem
,
1466 GeanyDocument
*doc
= document_get_current();
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
);
1484 on_insert_date_activate (GtkMenuItem
*menuitem
,
1487 GeanyDocument
*doc
= document_get_current();
1488 gchar
*format
= NULL
;
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
;
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
));
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
);
1536 ui_set_statusbar(TRUE
,
1537 _("Date format string could not be converted (possibly too long)."));
1543 on_insert_include_activate (GtkMenuItem
*menuitem
,
1546 GeanyDocument
*doc
= document_get_current();
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;
1562 text
= g_strconcat("#include <", user_data
, ">\n", NULL
);
1565 sci_insert_text(doc
->editor
->sci
, editor_info
.click_pos
, text
);
1568 sci_goto_pos(doc
->editor
->sci
, pos
, FALSE
);
1573 on_file_properties_activate (GtkMenuItem
*menuitem
,
1576 GeanyDocument
*doc
= document_get_current();
1577 g_return_if_fail(doc
!= NULL
);
1579 dialogs_show_file_properties(doc
);
1584 on_menu_fold_all1_activate (GtkMenuItem
*menuitem
,
1587 GeanyDocument
*doc
= document_get_current();
1588 g_return_if_fail(doc
!= NULL
);
1590 editor_fold_all(doc
->editor
);
1595 on_menu_unfold_all1_activate (GtkMenuItem
*menuitem
,
1598 GeanyDocument
*doc
= document_get_current();
1599 g_return_if_fail(doc
!= NULL
);
1601 editor_unfold_all(doc
->editor
);
1606 on_toolbutton_run_clicked (GtkAction
*action
,
1609 keybindings_send_command(GEANY_KEY_GROUP_BUILD
, GEANY_KEYS_BUILD_RUN
);
1614 on_menu_remove_indicators1_activate (GtkMenuItem
*menuitem
,
1617 GeanyDocument
*doc
= document_get_current();
1618 g_return_if_fail(doc
!= NULL
);
1620 editor_indicator_clear(doc
->editor
, GEANY_INDICATOR_ERROR
);
1625 on_print1_activate (GtkMenuItem
*menuitem
,
1628 GeanyDocument
*doc
= document_get_current();
1629 g_return_if_fail(doc
!= NULL
);
1631 printing_print_doc(doc
);
1636 on_menu_select_all1_activate (GtkMenuItem
*menuitem
,
1639 GeanyDocument
*doc
= document_get_current();
1640 g_return_if_fail(doc
!= NULL
);
1642 sci_select_all(doc
->editor
->sci
);
1647 on_menu_show_sidebar1_toggled (GtkCheckMenuItem
*checkmenuitem
,
1650 if (ignore_callback
)
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
);
1670 ui_sidebar_show_hide();
1675 on_menu_write_unicode_bom1_toggled (GtkCheckMenuItem
*checkmenuitem
,
1678 if (! ignore_callback
)
1680 GeanyDocument
*doc
= document_get_current();
1682 g_return_if_fail(doc
!= NULL
);
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);
1699 on_menu_comment_line1_activate (GtkMenuItem
*menuitem
,
1702 GeanyDocument
*doc
= document_get_current();
1703 g_return_if_fail(doc
!= NULL
);
1705 editor_do_comment(doc
->editor
, -1, FALSE
, FALSE
);
1710 on_menu_uncomment_line1_activate (GtkMenuItem
*menuitem
,
1713 GeanyDocument
*doc
= document_get_current();
1714 g_return_if_fail(doc
!= NULL
);
1716 editor_do_uncomment(doc
->editor
, -1, FALSE
);
1721 on_menu_toggle_line_commentation1_activate
1722 (GtkMenuItem
*menuitem
,
1725 GeanyDocument
*doc
= document_get_current();
1726 g_return_if_fail(doc
!= NULL
);
1728 editor_do_comment_toggle(doc
->editor
);
1733 on_menu_increase_indent1_activate (GtkMenuItem
*menuitem
,
1736 GeanyDocument
*doc
= document_get_current();
1737 g_return_if_fail(doc
!= NULL
);
1739 editor_indent(doc
->editor
, TRUE
);
1744 on_menu_decrease_indent1_activate (GtkMenuItem
*menuitem
,
1747 GeanyDocument
*doc
= document_get_current();
1748 g_return_if_fail(doc
!= NULL
);
1750 editor_indent(doc
->editor
, FALSE
);
1755 on_next_message1_activate (GtkMenuItem
*menuitem
,
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."));
1765 on_previous_message1_activate (GtkMenuItem
*menuitem
,
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."));
1775 on_menu_comments_multiline_activate (GtkMenuItem
*menuitem
,
1778 insert_callback_from_menu
= TRUE
;
1779 on_comments_multiline_activate(menuitem
, user_data
);
1784 on_menu_comments_gpl_activate (GtkMenuItem
*menuitem
,
1787 insert_callback_from_menu
= TRUE
;
1788 on_comments_gpl_activate(menuitem
, user_data
);
1793 on_menu_comments_bsd_activate (GtkMenuItem
*menuitem
,
1796 insert_callback_from_menu
= TRUE
;
1797 on_comments_bsd_activate(menuitem
, user_data
);
1802 on_menu_insert_include_activate (GtkMenuItem
*menuitem
,
1805 insert_callback_from_menu
= TRUE
;
1806 on_insert_include_activate(menuitem
, user_data
);
1811 on_menu_insert_date_activate (GtkMenuItem
*menuitem
,
1814 insert_callback_from_menu
= TRUE
;
1815 on_insert_date_activate(menuitem
, user_data
);
1820 on_project_new1_activate (GtkMenuItem
*menuitem
,
1828 on_project_open1_activate (GtkMenuItem
*menuitem
,
1836 on_project_close1_activate (GtkMenuItem
*menuitem
,
1839 project_close(TRUE
);
1844 on_project_properties1_activate (GtkMenuItem
*menuitem
,
1847 project_properties();
1852 on_menu_project1_activate (GtkMenuItem
*menuitem
,
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);
1872 on_menu_open_selected_file1_activate (GtkMenuItem
*menuitem
,
1875 GeanyDocument
*doc
= document_get_current();
1880 wc
= GEANY_WORDCHARS
"./-" "\\";
1882 wc
= GEANY_WORDCHARS
"./-";
1885 g_return_if_fail(doc
!= NULL
);
1887 sel
= editor_get_default_selection(doc
->editor
, TRUE
, wc
);
1891 gchar
*locale_filename
, *filename
= NULL
;
1893 if (g_path_is_absolute(sel
))
1894 filename
= g_strdup(sel
);
1896 { /* relative filename, add the path of the current file */
1899 path
= utils_get_current_file_dir_utf8();
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
));
1915 locale_filename
= utils_get_locale_from_utf8(filename
);
1916 document_open_file(locale_filename
, FALSE
, NULL
, NULL
);
1919 g_free(locale_filename
);
1926 on_remove_markers1_activate (GtkMenuItem
*menuitem
,
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
);
1939 on_load_tags1_activate (GtkMenuItem
*menuitem
,
1942 symbols_show_load_tags_dialog();
1947 on_context_action1_activate (GtkMenuItem
*menuitem
,
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
);
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
);
1974 command
= g_strdup(tool_prefs
.context_action_cmd
);
1977 /* substitute the wildcard %s and run the command if it is non empty */
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
);
1994 on_menu_toggle_all_additional_widgets1_activate
1995 (GtkMenuItem
*menuitem
,
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
))
2017 hide_all
= ! hide_all
; /* toggle */
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
));
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
));
2050 on_forward_activate (GtkMenuItem
*menuitem
,
2053 navqueue_go_forward();
2058 on_back_activate (GtkMenuItem
*menuitem
,
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
);
2074 static void set_indent_type(GtkCheckMenuItem
*menuitem
, GeanyIndentType type
)
2078 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
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);
2090 on_tabs1_activate (GtkCheckMenuItem
*menuitem
,
2093 set_indent_type(menuitem
, GEANY_INDENT_TYPE_TABS
);
2098 on_spaces1_activate (GtkCheckMenuItem
*menuitem
,
2101 set_indent_type(menuitem
, GEANY_INDENT_TYPE_SPACES
);
2106 on_tabs_and_spaces1_activate (GtkCheckMenuItem
*menuitem
,
2109 set_indent_type(menuitem
, GEANY_INDENT_TYPE_BOTH
);
2114 on_strip_trailing_spaces1_activate (GtkMenuItem
*menuitem
,
2119 if (ignore_callback
)
2122 doc
= document_get_current();
2123 g_return_if_fail(doc
!= NULL
);
2125 editor_strip_trailing_spaces(doc
->editor
);
2130 on_page_setup1_activate (GtkMenuItem
*menuitem
,
2133 #if GTK_CHECK_VERSION(2, 10, 0)
2134 printing_page_setup_gtk();
2140 on_escape_key_press_event (GtkWidget
*widget
,
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
);
2157 on_line_breaking1_activate (GtkMenuItem
*menuitem
,
2162 if (ignore_callback
)
2165 doc
= document_get_current();
2166 g_return_if_fail(doc
!= NULL
);
2168 doc
->editor
->line_breaking
= !doc
->editor
->line_breaking
;
2173 on_replace_spaces_activate (GtkMenuItem
*menuitem
,
2176 GeanyDocument
*doc
= document_get_current();
2178 g_return_if_fail(doc
!= NULL
);
2180 editor_replace_spaces(doc
->editor
);
2185 on_search1_activate (GtkMenuItem
*menuitem
,
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
),
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) */
2203 on_close_other_documents1_activate (GtkMenuItem
*menuitem
,
2207 GeanyDocument
*doc
, *cur_doc
= document_get_current();
2209 for (i
= 0; i
< documents_array
->len
; i
++)
2213 if (doc
== cur_doc
|| ! doc
->is_valid
)
2216 if (! document_close(doc
))
2223 on_menu_reload_configuration1_activate (GtkMenuItem
*menuitem
,
2226 main_reload_configuration();
2231 on_debug_messages1_activate (GtkMenuItem
*menuitem
,
2234 log_show_debug_messages_dialog();
2239 on_send_selection_to_vte1_activate (GtkMenuItem
*menuitem
,
2243 if (vte_info
.load_vte
)
2244 vte_send_selection_to_vte();
2249 gboolean
on_window_state_event (GtkWidget
*widget
,
2250 GdkEventWindowState
*event
,
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
;
2273 on_customize_toolbar1_activate (GtkMenuItem
*menuitem
,
2276 toolbar_configure(GTK_WINDOW(main_widgets
.window
));
2281 on_button_customize_toolbar_clicked (GtkButton
*button
,
2284 toolbar_configure(GTK_WINDOW(ui_widgets
.prefs_dialog
));
2289 on_cut_current_line_s_1_activate (GtkMenuItem
*menuitem
,
2292 keybindings_send_command(GEANY_KEY_GROUP_CLIPBOARD
, GEANY_KEYS_CLIPBOARD_CUTLINE
);
2297 on_copy_current_line_s_1_activate (GtkMenuItem
*menuitem
,
2300 keybindings_send_command(GEANY_KEY_GROUP_CLIPBOARD
, GEANY_KEYS_CLIPBOARD_COPYLINE
);
2305 on_delete_current_line_s_1_activate (GtkMenuItem
*menuitem
,
2308 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_DELETELINE
);
2313 on_duplicate_line_or_selection1_activate
2314 (GtkMenuItem
*menuitem
,
2317 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_DUPLICATELINE
);
2322 on_select_current_line_s_1_activate (GtkMenuItem
*menuitem
,
2325 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_LINE
);
2330 on_select_current_paragraph1_activate (GtkMenuItem
*menuitem
,
2333 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_PARAGRAPH
);
2338 on_insert_alternative_white_space1_activate
2339 (GtkMenuItem
*menuitem
,
2342 keybindings_send_command(GEANY_KEY_GROUP_INSERT
, GEANY_KEYS_INSERT_ALTWHITESPACE
);
2347 on_go_to_next_marker1_activate (GtkMenuItem
*menuitem
,
2350 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_NEXTMARKER
);
2355 on_go_to_previous_marker1_activate (GtkMenuItem
*menuitem
,
2358 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_PREVIOUSMARKER
);
2363 on_reflow_lines_block1_activate (GtkMenuItem
*menuitem
,
2366 keybindings_send_command(GEANY_KEY_GROUP_FORMAT
, GEANY_KEYS_FORMAT_REFLOWPARAGRAPH
);
2371 on_transpose_current_line1_activate (GtkMenuItem
*menuitem
,
2374 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_TRANSPOSELINE
);
2379 on_smart_line_indent1_activate (GtkMenuItem
*menuitem
,
2382 keybindings_send_command(GEANY_KEY_GROUP_FORMAT
, GEANY_KEYS_FORMAT_AUTOINDENT
);
2387 on_plugin_preferences1_activate (GtkMenuItem
*menuitem
,
2391 plugin_show_configure(NULL
);