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"
81 /* flag to indicate that an insert callback was triggered from the file menu,
82 * so we need to store the current cursor position in editor_info.click_pos. */
83 static gboolean insert_callback_from_menu
= FALSE
;
85 /* represents the state at switching a notebook page(in the left treeviews widget), to not emit
86 * the selection-changed signal from tv.tree_openfiles */
87 /*static gboolean switch_tv_notebook_page = FALSE; */
90 static gboolean
check_no_unsaved(void)
94 for (i
= 0; i
< documents_array
->len
; i
++)
96 if (documents
[i
]->is_valid
&& documents
[i
]->changed
)
101 return TRUE
; /* no unsaved edits */
105 /* set editor_info.click_pos to the current cursor position if insert_callback_from_menu is TRUE
106 * to prevent invalid cursor positions which can cause segfaults */
107 static void verify_click_pos(GeanyDocument
*doc
)
109 if (insert_callback_from_menu
)
111 editor_info
.click_pos
= sci_get_current_position(doc
->editor
->sci
);
112 insert_callback_from_menu
= FALSE
;
117 /* should only be called from on_exit_clicked */
118 static void quit_app(void)
120 configuration_save();
122 if (app
->project
!= NULL
)
123 project_close(FALSE
); /* save project session files */
125 document_close_all();
127 main_status
.quitting
= TRUE
;
133 /* wrapper function to abort exit process if cancel button is pressed */
135 on_exit_clicked (GtkWidget
*widget
, gpointer gdata
)
137 main_status
.quitting
= TRUE
;
139 if (! check_no_unsaved())
141 if (document_account_for_unsaved())
148 if (! prefs
.confirm_exit
||
149 dialogs_show_question_full(NULL
, GTK_STOCK_QUIT
, GTK_STOCK_CANCEL
, NULL
,
150 _("Do you really want to quit?")))
156 main_status
.quitting
= FALSE
;
166 on_new1_activate (GtkMenuItem
*menuitem
,
169 document_new_file(NULL
, NULL
, NULL
);
174 on_save1_activate (GtkMenuItem
*menuitem
,
177 gint cur_page
= gtk_notebook_get_current_page(GTK_NOTEBOOK(main_widgets
.notebook
));
178 GeanyDocument
*doc
= document_get_current();
180 if (doc
!= NULL
&& cur_page
>= 0)
182 if (document_need_save_as(doc
))
183 dialogs_show_save_as();
185 document_save_file(doc
, FALSE
);
191 on_save_as1_activate (GtkMenuItem
*menuitem
,
194 dialogs_show_save_as();
199 on_save_all1_activate (GtkMenuItem
*menuitem
,
202 gint i
, max
= gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets
.notebook
));
203 GeanyDocument
*doc
, *cur_doc
= document_get_current();
206 for (i
= 0; i
< max
; i
++)
208 doc
= document_get_from_page(i
);
211 if (document_need_save_as(doc
))
213 /* display unnamed document */
214 gtk_notebook_set_current_page(GTK_NOTEBOOK(main_widgets
.notebook
),
215 document_get_notebook_page(doc
));
216 if (dialogs_show_save_as())
221 if (document_save_file(doc
, FALSE
))
228 ui_set_statusbar(FALSE
, ngettext("%d file saved.", "%d files saved.", count
), count
);
229 /* saving may have changed window title, sidebar for another doc, so update */
230 sidebar_update_tag_list(cur_doc
, TRUE
);
231 ui_set_window_title(cur_doc
);
236 on_close_all1_activate (GtkMenuItem
*menuitem
,
239 document_close_all();
244 on_close1_activate (GtkMenuItem
*menuitem
,
247 GeanyDocument
*doc
= document_get_current();
249 g_return_if_fail(doc
!= NULL
);
256 on_quit1_activate (GtkMenuItem
*menuitem
,
259 on_exit_clicked(NULL
, NULL
);
264 on_file1_activate (GtkMenuItem
*menuitem
,
267 gtk_widget_set_sensitive(ui_widgets
.recent_files_menuitem
,
268 g_queue_get_length(ui_prefs
.recent_queue
) > 0);
269 #if GTK_CHECK_VERSION(2, 10, 0)
270 /* hide Page setup when GTK printing is not used
271 * (on GTK < 2.10 the menu item is hidden completely) */
272 ui_widget_show_hide(ui_widgets
.print_page_setup
,
273 printing_prefs
.use_gtk_printing
|| gtk_check_version(2, 10, 0) != NULL
);
278 /* edit actions, c&p & co, from menu bar and from popup menu */
280 on_edit1_activate (GtkMenuItem
*menuitem
,
284 GeanyDocument
*doc
= document_get_current();
286 ui_update_menu_copy_items(doc
);
287 ui_update_insert_include_item(doc
, 1);
289 item
= ui_lookup_widget(main_widgets
.window
, "plugin_preferences1");
291 gtk_widget_hide(item
);
293 gtk_widget_set_sensitive(item
, plugins_have_preferences());
299 on_undo1_activate (GtkMenuItem
*menuitem
,
302 GeanyDocument
*doc
= document_get_current();
304 g_return_if_fail(doc
!= NULL
);
306 if (document_can_undo(doc
))
308 sci_cancel(doc
->editor
->sci
);
315 on_redo1_activate (GtkMenuItem
*menuitem
,
318 GeanyDocument
*doc
= document_get_current();
320 g_return_if_fail(doc
!= NULL
);
322 if (document_can_redo(doc
))
324 sci_cancel(doc
->editor
->sci
);
331 on_cut1_activate (GtkMenuItem
*menuitem
,
334 GeanyDocument
*doc
= document_get_current();
335 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
337 if (GTK_IS_EDITABLE(focusw
))
338 gtk_editable_cut_clipboard(GTK_EDITABLE(focusw
));
340 if (IS_SCINTILLA(focusw
) && doc
!= NULL
)
341 sci_cut(doc
->editor
->sci
);
343 if (GTK_IS_TEXT_VIEW(focusw
))
345 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(
346 GTK_TEXT_VIEW(focusw
));
347 gtk_text_buffer_cut_clipboard(buffer
, gtk_clipboard_get(GDK_NONE
), TRUE
);
353 on_copy1_activate (GtkMenuItem
*menuitem
,
356 GeanyDocument
*doc
= document_get_current();
357 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
359 if (GTK_IS_EDITABLE(focusw
))
360 gtk_editable_copy_clipboard(GTK_EDITABLE(focusw
));
362 if (IS_SCINTILLA(focusw
) && doc
!= NULL
)
363 sci_copy(doc
->editor
->sci
);
365 if (GTK_IS_TEXT_VIEW(focusw
))
367 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(
368 GTK_TEXT_VIEW(focusw
));
369 gtk_text_buffer_copy_clipboard(buffer
, gtk_clipboard_get(GDK_NONE
));
375 on_paste1_activate (GtkMenuItem
*menuitem
,
378 GeanyDocument
*doc
= document_get_current();
379 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
381 if (GTK_IS_EDITABLE(focusw
))
382 gtk_editable_paste_clipboard(GTK_EDITABLE(focusw
));
384 if (IS_SCINTILLA(focusw
) && doc
!= NULL
)
386 sci_paste(doc
->editor
->sci
);
389 if (GTK_IS_TEXT_VIEW(focusw
))
391 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(
392 GTK_TEXT_VIEW(focusw
));
393 gtk_text_buffer_paste_clipboard(buffer
, gtk_clipboard_get(GDK_NONE
), NULL
,
400 on_delete1_activate (GtkMenuItem
*menuitem
,
403 GeanyDocument
*doc
= document_get_current();
404 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
406 if (GTK_IS_EDITABLE(focusw
))
407 gtk_editable_delete_selection(GTK_EDITABLE(focusw
));
409 if (IS_SCINTILLA(focusw
) && doc
!= NULL
&& sci_has_selection(doc
->editor
->sci
))
410 sci_clear(doc
->editor
->sci
);
412 if (GTK_IS_TEXT_VIEW(focusw
))
414 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(
415 GTK_TEXT_VIEW(focusw
));
416 gtk_text_buffer_delete_selection(buffer
, TRUE
, TRUE
);
422 on_preferences1_activate (GtkMenuItem
*menuitem
,
429 /* about menu item */
431 on_info1_activate (GtkMenuItem
*menuitem
,
440 on_open1_activate (GtkMenuItem
*menuitem
,
443 dialogs_show_open_file();
447 /* quit toolbar button */
449 on_toolbutton_quit_clicked (GtkAction
*action
,
452 on_exit_clicked(NULL
, NULL
);
458 on_toolbutton_reload_clicked (GtkAction
*action
,
461 on_reload_as_activate(NULL
, GINT_TO_POINTER(-1));
465 /* also used for reloading when user_data is -1 */
467 on_reload_as_activate (GtkMenuItem
*menuitem
,
470 GeanyDocument
*doc
= document_get_current();
472 gint i
= GPOINTER_TO_INT(user_data
);
473 gchar
*charset
= NULL
;
475 g_return_if_fail(doc
!= NULL
);
476 g_return_if_fail(doc
->file_name
!= NULL
);
480 if (i
>= GEANY_ENCODINGS_MAX
|| encodings
[i
].charset
== NULL
)
482 charset
= encodings
[i
].charset
;
485 charset
= doc
->encoding
;
487 base_name
= g_path_get_basename(doc
->file_name
);
488 if (dialogs_show_question_full(NULL
, _("_Reload"), GTK_STOCK_CANCEL
,
489 _("Any unsaved changes will be lost."),
490 _("Are you sure you want to reload '%s'?"), base_name
))
492 document_reload_file(doc
, charset
);
494 ui_update_statusbar(doc
, -1);
501 on_change_font1_activate (GtkMenuItem
*menuitem
,
504 dialogs_show_open_font();
510 on_toolbutton_new_clicked (GtkAction
*action
,
513 document_new_file(NULL
, NULL
, NULL
);
519 on_toolbutton_open_clicked (GtkAction
*action
,
522 dialogs_show_open_file();
528 on_toolbutton_save_clicked (GtkAction
*action
,
531 on_save1_activate(NULL
, user_data
);
535 /* store text, clear search flags so we can use Search->Find Next/Previous */
536 static void setup_find_next(const gchar
*text
)
538 setptr(search_data
.text
, g_strdup(text
));
539 search_data
.flags
= 0;
540 search_data
.backwards
= FALSE
;
541 search_data
.search_bar
= TRUE
;
547 on_toolbar_search_entry_changed(GtkAction
*action
, const gchar
*text
, gpointer user_data
)
549 GeanyDocument
*doc
= document_get_current();
552 setup_find_next(text
);
553 result
= document_search_bar_find(doc
, search_data
.text
, 0, GPOINTER_TO_INT(user_data
));
554 if (search_data
.search_bar
)
555 ui_set_search_entry_background(toolbar_get_widget_child_by_name("SearchEntry"), result
);
561 on_toolbutton_search_clicked (GtkAction
*action
,
564 GeanyDocument
*doc
= document_get_current();
566 GtkWidget
*entry
= toolbar_get_widget_child_by_name("SearchEntry");
570 const gchar
*text
= gtk_entry_get_text(GTK_ENTRY(entry
));
572 setup_find_next(text
);
573 result
= document_search_bar_find(doc
, search_data
.text
, 0, FALSE
);
574 if (search_data
.search_bar
)
575 ui_set_search_entry_background(entry
, result
);
578 on_find1_activate(NULL
, NULL
);
582 /* hides toolbar from toolbar popup menu */
584 on_hide_toolbar1_activate (GtkMenuItem
*menuitem
,
587 GtkWidget
*tool_item
= ui_lookup_widget(GTK_WIDGET(main_widgets
.window
), "menu_show_toolbar1");
588 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(tool_item
), FALSE
);
592 /* zoom in from menu bar and popup menu */
594 on_zoom_in1_activate (GtkMenuItem
*menuitem
,
597 GeanyDocument
*doc
= document_get_current();
598 static gint done
= 1;
600 g_return_if_fail(doc
!= NULL
);
603 sci_set_line_numbers(doc
->editor
->sci
, editor_prefs
.show_linenumber_margin
,
604 (sci_get_zoom(doc
->editor
->sci
) / 2));
605 sci_zoom_in(doc
->editor
->sci
);
609 /* zoom out from menu bar and popup menu */
611 on_zoom_out1_activate (GtkMenuItem
*menuitem
,
614 GeanyDocument
*doc
= document_get_current();
616 g_return_if_fail(doc
!= NULL
);
618 if (sci_get_zoom(doc
->editor
->sci
) == 0)
619 sci_set_line_numbers(doc
->editor
->sci
, editor_prefs
.show_linenumber_margin
, 0);
620 sci_zoom_out(doc
->editor
->sci
);
625 on_normal_size1_activate (GtkMenuItem
*menuitem
,
628 GeanyDocument
*doc
= document_get_current();
630 g_return_if_fail(doc
!= NULL
);
632 sci_zoom_off(doc
->editor
->sci
);
633 sci_set_line_numbers(doc
->editor
->sci
, editor_prefs
.show_linenumber_margin
, 0);
639 on_toolbutton_close_clicked (GtkAction
*action
,
642 on_close1_activate(NULL
, NULL
);
647 on_toolbutton_close_all_clicked (GtkAction
*action
,
650 on_close_all1_activate(NULL
, NULL
);
655 on_toolbutton_preferences_clicked (GtkAction
*action
,
658 on_preferences1_activate(NULL
, NULL
);
662 static gboolean
delayed_check_disk_status(gpointer data
)
664 document_check_disk_status(data
, FALSE
);
669 /* Changes window-title after switching tabs and lots of other things.
670 * note: using 'after' makes Scintilla redraw before the UI, appearing more responsive */
672 on_notebook1_switch_page_after (GtkNotebook
*notebook
,
673 GtkNotebookPage
*page
,
679 if (G_UNLIKELY(main_status
.opening_session_files
) || G_UNLIKELY(main_status
.closing_all
))
682 if (page_num
== (guint
) -1 && page
!= NULL
)
683 doc
= document_find_by_sci(SCINTILLA(page
));
685 doc
= document_get_from_page(page_num
);
689 sidebar_select_openfiles_item(doc
);
690 document_set_text_changed(doc
, doc
->changed
); /* also sets window title and status bar */
691 ui_update_popup_reundo_items(doc
);
692 ui_document_show_hide(doc
); /* update the document menu */
693 build_menu_update(doc
);
694 sidebar_update_tag_list(doc
, FALSE
);
696 /* We delay the check to avoid weird fast, unintended switching of notebook pages when
697 * the 'file has changed' dialog is shown while the switch event is not yet completely
698 * finished. So, we check after the switch has been performed to be safe. */
699 g_idle_add(delayed_check_disk_status
, doc
);
702 vte_cwd((doc
->real_path
!= NULL
) ? doc
->real_path
: doc
->file_name
, FALSE
);
705 g_signal_emit_by_name(geany_object
, "document-activate", doc
);
711 on_tv_notebook_switch_page (GtkNotebook
*notebook
,
712 GtkNotebookPage
*page
,
716 /* suppress selection changed signal when switching to the open files list */
717 ignore_callback
= TRUE
;
722 on_tv_notebook_switch_page_after (GtkNotebook
*notebook
,
723 GtkNotebookPage
*page
,
727 ignore_callback
= FALSE
;
731 static void convert_eol(gint mode
)
733 GeanyDocument
*doc
= document_get_current();
735 g_return_if_fail(doc
!= NULL
);
737 sci_convert_eols(doc
->editor
->sci
, mode
);
738 sci_set_eol_mode(doc
->editor
->sci
, mode
);
739 ui_update_statusbar(doc
, -1);
744 on_crlf_activate (GtkCheckMenuItem
*menuitem
,
747 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
750 convert_eol(SC_EOL_CRLF
);
755 on_lf_activate (GtkCheckMenuItem
*menuitem
,
758 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
761 convert_eol(SC_EOL_LF
);
766 on_cr_activate (GtkCheckMenuItem
*menuitem
,
769 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
772 convert_eol(SC_EOL_CR
);
777 on_replace_tabs_activate (GtkMenuItem
*menuitem
,
780 GeanyDocument
*doc
= document_get_current();
782 g_return_if_fail(doc
!= NULL
);
784 editor_replace_tabs(doc
->editor
);
789 toolbar_popup_menu (GtkWidget
*widget
,
790 GdkEventButton
*event
,
793 if (event
->button
== 3)
795 gtk_menu_popup(GTK_MENU(ui_widgets
.toolbar_menu
), NULL
, NULL
, NULL
, NULL
, event
->button
, event
->time
);
802 void on_toggle_case1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
804 GeanyDocument
*doc
= document_get_current();
805 ScintillaObject
*sci
;
807 gboolean keep_sel
= TRUE
;
809 g_return_if_fail(doc
!= NULL
);
811 sci
= doc
->editor
->sci
;
812 if (! sci_has_selection(sci
))
814 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_WORD
);
819 gchar
*result
= NULL
;
820 gint cmd
= SCI_LOWERCASE
;
821 gint text_len
= sci_get_selected_text_length(sci
);
822 gboolean rectsel
= scintilla_send_message(sci
, SCI_SELECTIONISRECTANGLE
, 0, 0);
824 text
= g_malloc(text_len
+ 1);
825 sci_get_selected_text(sci
, text
);
827 if (utils_str_has_upper(text
))
832 result
= g_utf8_strdown(text
, -1);
840 result
= g_utf8_strup(text
, -1);
846 sci_replace_sel(sci
, result
);
849 sci_set_selection_start(sci
, sci_get_current_position(sci
) - text_len
+ 1);
852 sci_send_command(sci
, cmd
);
861 on_show_toolbar1_toggled (GtkCheckMenuItem
*checkmenuitem
,
864 if (ignore_callback
) return;
866 toolbar_prefs
.visible
= (toolbar_prefs
.visible
) ? FALSE
: TRUE
;;
867 ui_widget_show_hide(GTK_WIDGET(main_widgets
.toolbar
), toolbar_prefs
.visible
);
872 on_fullscreen1_toggled (GtkCheckMenuItem
*checkmenuitem
,
878 ui_prefs
.fullscreen
= (ui_prefs
.fullscreen
) ? FALSE
: TRUE
;
884 on_show_messages_window1_toggled (GtkCheckMenuItem
*checkmenuitem
,
890 ui_prefs
.msgwindow_visible
= (ui_prefs
.msgwindow_visible
) ? FALSE
: TRUE
;
891 msgwin_show_hide(ui_prefs
.msgwindow_visible
);
896 on_markers_margin1_toggled (GtkCheckMenuItem
*checkmenuitem
,
902 editor_prefs
.show_markers_margin
= ! editor_prefs
.show_markers_margin
;
903 ui_toggle_editor_features(GEANY_EDITOR_SHOW_MARKERS_MARGIN
);
908 on_show_line_numbers1_toggled (GtkCheckMenuItem
*checkmenuitem
,
914 editor_prefs
.show_linenumber_margin
= ! editor_prefs
.show_linenumber_margin
;
915 ui_toggle_editor_features(GEANY_EDITOR_SHOW_LINE_NUMBERS
);
920 on_menu_show_white_space1_toggled (GtkCheckMenuItem
*checkmenuitem
,
926 editor_prefs
.show_white_space
= ! editor_prefs
.show_white_space
;
927 ui_toggle_editor_features(GEANY_EDITOR_SHOW_WHITE_SPACE
);
932 on_menu_show_line_endings1_toggled (GtkCheckMenuItem
*checkmenuitem
,
938 editor_prefs
.show_line_endings
= ! editor_prefs
.show_line_endings
;
939 ui_toggle_editor_features(GEANY_EDITOR_SHOW_LINE_ENDINGS
);
944 on_menu_show_indentation_guides1_toggled (GtkCheckMenuItem
*checkmenuitem
,
950 editor_prefs
.show_indent_guide
= ! editor_prefs
.show_indent_guide
;
951 ui_toggle_editor_features(GEANY_EDITOR_SHOW_INDENTATION_GUIDES
);
956 on_line_wrapping1_toggled (GtkCheckMenuItem
*checkmenuitem
,
959 if (! ignore_callback
)
961 GeanyDocument
*doc
= document_get_current();
962 g_return_if_fail(doc
!= NULL
);
964 editor_set_line_wrapping(doc
->editor
, ! doc
->editor
->line_wrapping
);
970 on_set_file_readonly1_toggled (GtkCheckMenuItem
*checkmenuitem
,
973 if (! ignore_callback
)
975 GeanyDocument
*doc
= document_get_current();
976 g_return_if_fail(doc
!= NULL
);
978 doc
->readonly
= ! doc
->readonly
;
979 sci_set_readonly(doc
->editor
->sci
, doc
->readonly
);
980 ui_update_tab_status(doc
);
981 ui_update_statusbar(doc
, -1);
987 on_use_auto_indentation1_toggled (GtkCheckMenuItem
*checkmenuitem
,
990 if (! ignore_callback
)
992 GeanyDocument
*doc
= document_get_current();
993 g_return_if_fail(doc
!= NULL
);
995 doc
->editor
->auto_indent
= ! doc
->editor
->auto_indent
;
1000 static void find_usage(gboolean in_session
)
1004 GeanyDocument
*doc
= document_get_current();
1006 g_return_if_fail(doc
!= NULL
);
1008 if (sci_has_selection(doc
->editor
->sci
))
1009 { /* take selected text if there is a selection */
1010 search_text
= g_malloc(sci_get_selected_text_length(doc
->editor
->sci
) + 1);
1011 sci_get_selected_text(doc
->editor
->sci
, search_text
);
1012 flags
= SCFIND_MATCHCASE
;
1016 search_text
= g_strdup(editor_info
.current_word
);
1017 flags
= SCFIND_MATCHCASE
| SCFIND_WHOLEWORD
;
1020 search_find_usage(search_text
, flags
, in_session
);
1021 g_free(search_text
);
1026 on_find_document_usage1_activate (GtkMenuItem
*menuitem
,
1034 on_find_usage1_activate (GtkMenuItem
*menuitem
,
1042 on_goto_tag_activate (GtkMenuItem
*menuitem
,
1045 gboolean definition
= (menuitem
==
1046 GTK_MENU_ITEM(ui_lookup_widget(main_widgets
.editor_menu
, "goto_tag_definition1")));
1047 GeanyDocument
*doc
= document_get_current();
1049 g_return_if_fail(doc
!= NULL
);
1051 /* update cursor pos for navigating back afterwards */
1052 if (!sci_has_selection(doc
->editor
->sci
))
1053 sci_set_current_position(doc
->editor
->sci
, editor_info
.click_pos
, FALSE
);
1055 /* use the keybinding callback as it checks for selections as well as current word */
1057 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_TAGDEFINITION
);
1059 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_TAGDECLARATION
);
1064 on_count_words1_activate (GtkMenuItem
*menuitem
,
1072 on_show_color_chooser1_activate (GtkMenuItem
*menuitem
,
1076 GeanyDocument
*doc
= document_get_current();
1079 g_return_if_fail(doc
!= NULL
);
1081 pos
= sci_get_current_position(doc
->editor
->sci
);
1082 editor_find_current_word(doc
->editor
, pos
, colour
, sizeof colour
, GEANY_WORDCHARS
"#");
1083 tools_color_chooser(colour
);
1088 on_toolbutton_compile_clicked (GtkAction
*action
,
1091 keybindings_send_command(GEANY_KEY_GROUP_BUILD
, GEANY_KEYS_BUILD_COMPILE
);
1096 on_find1_activate (GtkMenuItem
*menuitem
,
1099 search_show_find_dialog();
1103 static void find_again(gboolean change_direction
)
1105 GeanyDocument
*doc
= document_get_current();
1107 g_return_if_fail(doc
!= NULL
);
1109 if (search_data
.text
)
1111 gboolean forward
= ! search_data
.backwards
;
1112 gint result
= document_find_text(doc
, search_data
.text
, search_data
.flags
,
1113 change_direction
? forward
: !forward
, FALSE
, NULL
);
1116 editor_display_current_line(doc
->editor
, 0.3F
);
1118 if (search_data
.search_bar
)
1119 ui_set_search_entry_background(
1120 toolbar_get_widget_child_by_name("SearchEntry"), (result
> -1));
1126 on_find_next1_activate (GtkMenuItem
*menuitem
,
1134 on_find_previous1_activate (GtkMenuItem
*menuitem
,
1137 if (search_data
.flags
& SCFIND_REGEXP
)
1138 /* Can't reverse search order for a regex (find next ignores search backwards) */
1146 on_find_nextsel1_activate (GtkMenuItem
*menuitem
,
1149 search_find_selection(document_get_current(), FALSE
);
1154 on_find_prevsel1_activate (GtkMenuItem
*menuitem
,
1157 search_find_selection(document_get_current(), TRUE
);
1162 on_replace1_activate (GtkMenuItem
*menuitem
,
1165 search_show_replace_dialog();
1170 on_find_in_files1_activate (GtkMenuItem
*menuitem
,
1173 search_show_find_in_files_dialog(NULL
);
1178 on_go_to_line_activate (GtkMenuItem
*menuitem
,
1181 static gdouble val
= 1;
1183 if (dialogs_show_input_numeric(_("Go to Line"), _("Enter the line you want to go to:"),
1184 &val
, 1, 100000000, 1))
1186 GeanyDocument
*doc
= document_get_current();
1188 g_return_if_fail(doc
!= NULL
);
1190 if (! editor_goto_line(doc
->editor
, (gint
) val
- 1))
1197 on_toolbutton_goto_entry_activate(GtkAction
*action
, const gchar
*text
, gpointer user_data
)
1199 GeanyDocument
*doc
= document_get_current();
1201 g_return_if_fail(doc
!= NULL
);
1203 if (! editor_goto_line(doc
->editor
, atoi(text
) - 1))
1206 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
1211 on_toolbutton_goto_clicked (GtkAction
*action
,
1214 GtkWidget
*entry
= toolbar_get_widget_child_by_name("GotoEntry");
1218 const gchar
*text
= gtk_entry_get_text(GTK_ENTRY(entry
));
1220 on_toolbutton_goto_entry_activate(NULL
, text
, NULL
);
1223 on_go_to_line_activate(NULL
, NULL
);
1228 on_help1_activate (GtkMenuItem
*menuitem
,
1233 uri
= utils_get_help_url(NULL
);
1234 utils_open_browser(uri
);
1240 on_help_shortcuts1_activate (GtkMenuItem
*menuitem
,
1243 keybindings_show_shortcuts();
1248 on_website1_activate (GtkMenuItem
*menuitem
,
1251 utils_open_browser(GEANY_HOMEPAGE
);
1256 on_comments_function_activate (GtkMenuItem
*menuitem
,
1259 GeanyDocument
*doc
= document_get_current();
1261 const gchar
*cur_tag
= NULL
;
1262 gint line
= -1, pos
= 0;
1264 if (doc
== NULL
|| doc
->file_type
== NULL
)
1266 ui_set_statusbar(FALSE
,
1267 _("Please set the filetype for the current file before using this function."));
1271 /* symbols_get_current_function returns -1 on failure, so sci_get_position_from_line
1272 * returns the current position, so it should be safe */
1273 line
= symbols_get_current_function(doc
, &cur_tag
);
1274 pos
= sci_get_position_from_line(doc
->editor
->sci
, line
- 1);
1276 text
= templates_get_template_function(doc
, cur_tag
);
1278 sci_insert_text(doc
->editor
->sci
, pos
, text
);
1284 on_comments_multiline_activate (GtkMenuItem
*menuitem
,
1287 GeanyDocument
*doc
= document_get_current();
1289 if (doc
== NULL
|| doc
->file_type
== NULL
)
1291 ui_set_statusbar(FALSE
,
1292 _("Please set the filetype for the current file before using this function."));
1296 verify_click_pos(doc
); /* make sure that the click_pos is valid */
1298 if (doc
->file_type
->comment_open
)
1299 editor_insert_multiline_comment(doc
->editor
);
1306 on_comments_gpl_activate (GtkMenuItem
*menuitem
,
1309 GeanyDocument
*doc
= document_get_current();
1312 g_return_if_fail(doc
!= NULL
);
1314 text
= templates_get_template_licence(doc
, GEANY_TEMPLATE_GPL
);
1316 verify_click_pos(doc
); /* make sure that the click_pos is valid */
1318 sci_insert_text(doc
->editor
->sci
, editor_info
.click_pos
, text
);
1324 on_comments_bsd_activate (GtkMenuItem
*menuitem
,
1328 GeanyDocument
*doc
= document_get_current();
1331 g_return_if_fail(doc
!= NULL
);
1333 text
= templates_get_template_licence(doc
, GEANY_TEMPLATE_BSD
);
1335 verify_click_pos(doc
); /* make sure that the click_pos is valid */
1337 sci_insert_text(doc
->editor
->sci
, editor_info
.click_pos
, text
);
1344 on_comments_changelog_activate (GtkMenuItem
*menuitem
,
1347 GeanyDocument
*doc
= document_get_current();
1350 g_return_if_fail(doc
!= NULL
);
1352 text
= templates_get_template_changelog(doc
);
1353 sci_insert_text(doc
->editor
->sci
, 0, text
);
1354 /* sets the cursor to the right position to type the changelog text,
1355 * the template has 21 chars + length of name and email */
1356 sci_goto_pos(doc
->editor
->sci
, 21 + strlen(template_prefs
.developer
) + strlen(template_prefs
.mail
), TRUE
);
1363 on_comments_fileheader_activate (GtkMenuItem
*menuitem
,
1366 GeanyDocument
*doc
= document_get_current();
1371 g_return_if_fail(doc
!= NULL
);
1373 ft
= doc
->file_type
;
1374 fname
= doc
->file_name
;
1375 text
= templates_get_template_fileheader(FILETYPE_ID(ft
), fname
);
1377 sci_insert_text(doc
->editor
->sci
, 0, text
);
1378 sci_goto_pos(doc
->editor
->sci
, 0, FALSE
);
1384 on_insert_date_activate (GtkMenuItem
*menuitem
,
1387 GeanyDocument
*doc
= document_get_current();
1388 gchar
*format
= NULL
;
1391 g_return_if_fail(doc
!= NULL
);
1393 /* set default value */
1394 if (utils_str_equal("", ui_prefs
.custom_date_format
))
1396 g_free(ui_prefs
.custom_date_format
);
1397 ui_prefs
.custom_date_format
= g_strdup("%d.%m.%Y");
1400 if (utils_str_equal(_("dd.mm.yyyy"), (gchar
*) user_data
))
1401 format
= "%d.%m.%Y";
1402 else if (utils_str_equal(_("mm.dd.yyyy"), (gchar
*) user_data
))
1403 format
= "%m.%d.%Y";
1404 else if (utils_str_equal(_("yyyy/mm/dd"), (gchar
*) user_data
))
1405 format
= "%Y/%m/%d";
1406 else if (utils_str_equal(_("dd.mm.yyyy hh:mm:ss"), (gchar
*) user_data
))
1407 format
= "%d.%m.%Y %H:%M:%S";
1408 else if (utils_str_equal(_("mm.dd.yyyy hh:mm:ss"), (gchar
*) user_data
))
1409 format
= "%m.%d.%Y %H:%M:%S";
1410 else if (utils_str_equal(_("yyyy/mm/dd hh:mm:ss"), (gchar
*) user_data
))
1411 format
= "%Y/%m/%d %H:%M:%S";
1412 else if (utils_str_equal(_("_Use Custom Date Format"), (gchar
*) user_data
))
1413 format
= ui_prefs
.custom_date_format
;
1416 setptr(ui_prefs
.custom_date_format
,
1417 dialogs_show_input(_("Custom Date Format"),
1418 _("Enter here a custom date and time format. "
1419 "You can use any conversion specifiers which can be used with the ANSI C strftime function."),
1420 ui_prefs
.custom_date_format
));
1424 time_str
= utils_get_date_time(format
, NULL
);
1425 if (time_str
!= NULL
)
1427 verify_click_pos(doc
); /* make sure that the click_pos is valid */
1429 sci_insert_text(doc
->editor
->sci
, editor_info
.click_pos
, time_str
);
1430 sci_goto_pos(doc
->editor
->sci
, editor_info
.click_pos
+ strlen(time_str
), FALSE
);
1436 ui_set_statusbar(TRUE
,
1437 _("Date format string could not be converted (possibly too long)."));
1443 on_insert_include_activate (GtkMenuItem
*menuitem
,
1446 GeanyDocument
*doc
= document_get_current();
1450 g_return_if_fail(doc
!= NULL
);
1451 g_return_if_fail(user_data
!= NULL
);
1453 verify_click_pos(doc
); /* make sure that the click_pos is valid */
1455 if (utils_str_equal(user_data
, "blank"))
1457 text
= g_strdup("#include \"\"\n");
1458 pos
= editor_info
.click_pos
+ 10;
1462 text
= g_strconcat("#include <", user_data
, ">\n", NULL
);
1465 sci_insert_text(doc
->editor
->sci
, editor_info
.click_pos
, text
);
1468 sci_goto_pos(doc
->editor
->sci
, pos
, FALSE
);
1473 on_file_properties_activate (GtkMenuItem
*menuitem
,
1476 GeanyDocument
*doc
= document_get_current();
1477 g_return_if_fail(doc
!= NULL
);
1479 dialogs_show_file_properties(doc
);
1484 on_menu_fold_all1_activate (GtkMenuItem
*menuitem
,
1487 GeanyDocument
*doc
= document_get_current();
1488 g_return_if_fail(doc
!= NULL
);
1490 editor_fold_all(doc
->editor
);
1495 on_menu_unfold_all1_activate (GtkMenuItem
*menuitem
,
1498 GeanyDocument
*doc
= document_get_current();
1499 g_return_if_fail(doc
!= NULL
);
1501 editor_unfold_all(doc
->editor
);
1506 on_toolbutton_run_clicked (GtkAction
*action
,
1509 keybindings_send_command(GEANY_KEY_GROUP_BUILD
, GEANY_KEYS_BUILD_RUN
);
1514 on_menu_remove_indicators1_activate (GtkMenuItem
*menuitem
,
1517 GeanyDocument
*doc
= document_get_current();
1518 g_return_if_fail(doc
!= NULL
);
1520 editor_indicator_clear(doc
->editor
, GEANY_INDICATOR_ERROR
);
1525 on_print1_activate (GtkMenuItem
*menuitem
,
1528 GeanyDocument
*doc
= document_get_current();
1529 g_return_if_fail(doc
!= NULL
);
1531 printing_print_doc(doc
);
1536 on_menu_select_all1_activate (GtkMenuItem
*menuitem
,
1539 GeanyDocument
*doc
= document_get_current();
1540 g_return_if_fail(doc
!= NULL
);
1542 sci_select_all(doc
->editor
->sci
);
1547 on_menu_show_sidebar1_toggled (GtkCheckMenuItem
*checkmenuitem
,
1550 if (ignore_callback
)
1553 ui_prefs
.sidebar_visible
= ! ui_prefs
.sidebar_visible
;
1555 if (! interface_prefs
.sidebar_openfiles_visible
&& ! interface_prefs
.sidebar_symbol_visible
)
1557 interface_prefs
.sidebar_openfiles_visible
= TRUE
;
1558 interface_prefs
.sidebar_symbol_visible
= TRUE
;
1561 #if GTK_CHECK_VERSION(2, 14, 0)
1562 /* if window has input focus, set it back to the editor before toggling off */
1563 if (! ui_prefs
.sidebar_visible
&&
1564 gtk_container_get_focus_child(GTK_CONTAINER(main_widgets
.sidebar_notebook
)) != NULL
)
1566 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
1570 ui_sidebar_show_hide();
1575 on_menu_write_unicode_bom1_toggled (GtkCheckMenuItem
*checkmenuitem
,
1578 if (! ignore_callback
)
1580 GeanyDocument
*doc
= document_get_current();
1582 g_return_if_fail(doc
!= NULL
);
1589 document_undo_add(doc
, UNDO_BOM
, GINT_TO_POINTER(doc
->has_bom
));
1591 doc
->has_bom
= ! doc
->has_bom
;
1593 ui_update_statusbar(doc
, -1);
1599 on_menu_comment_line1_activate (GtkMenuItem
*menuitem
,
1602 GeanyDocument
*doc
= document_get_current();
1603 g_return_if_fail(doc
!= NULL
);
1605 editor_do_comment(doc
->editor
, -1, FALSE
, FALSE
);
1610 on_menu_uncomment_line1_activate (GtkMenuItem
*menuitem
,
1613 GeanyDocument
*doc
= document_get_current();
1614 g_return_if_fail(doc
!= NULL
);
1616 editor_do_uncomment(doc
->editor
, -1, FALSE
);
1621 on_menu_toggle_line_commentation1_activate
1622 (GtkMenuItem
*menuitem
,
1625 GeanyDocument
*doc
= document_get_current();
1626 g_return_if_fail(doc
!= NULL
);
1628 editor_do_comment_toggle(doc
->editor
);
1633 on_menu_increase_indent1_activate (GtkMenuItem
*menuitem
,
1636 GeanyDocument
*doc
= document_get_current();
1637 g_return_if_fail(doc
!= NULL
);
1639 editor_indent(doc
->editor
, TRUE
);
1644 on_menu_decrease_indent1_activate (GtkMenuItem
*menuitem
,
1647 GeanyDocument
*doc
= document_get_current();
1648 g_return_if_fail(doc
!= NULL
);
1650 editor_indent(doc
->editor
, FALSE
);
1655 on_next_message1_activate (GtkMenuItem
*menuitem
,
1658 if (! ui_tree_view_find_next(GTK_TREE_VIEW(msgwindow
.tree_msg
),
1659 msgwin_goto_messages_file_line
))
1660 ui_set_statusbar(FALSE
, _("No more message items."));
1665 on_previous_message1_activate (GtkMenuItem
*menuitem
,
1668 if (! ui_tree_view_find_previous(GTK_TREE_VIEW(msgwindow
.tree_msg
),
1669 msgwin_goto_messages_file_line
))
1670 ui_set_statusbar(FALSE
, _("No more message items."));
1675 on_menu_comments_multiline_activate (GtkMenuItem
*menuitem
,
1678 insert_callback_from_menu
= TRUE
;
1679 on_comments_multiline_activate(menuitem
, user_data
);
1684 on_menu_comments_gpl_activate (GtkMenuItem
*menuitem
,
1687 insert_callback_from_menu
= TRUE
;
1688 on_comments_gpl_activate(menuitem
, user_data
);
1693 on_menu_comments_bsd_activate (GtkMenuItem
*menuitem
,
1696 insert_callback_from_menu
= TRUE
;
1697 on_comments_bsd_activate(menuitem
, user_data
);
1702 on_menu_insert_include_activate (GtkMenuItem
*menuitem
,
1705 insert_callback_from_menu
= TRUE
;
1706 on_insert_include_activate(menuitem
, user_data
);
1711 on_menu_insert_date_activate (GtkMenuItem
*menuitem
,
1714 insert_callback_from_menu
= TRUE
;
1715 on_insert_date_activate(menuitem
, user_data
);
1720 on_project_new1_activate (GtkMenuItem
*menuitem
,
1728 on_project_open1_activate (GtkMenuItem
*menuitem
,
1736 on_project_close1_activate (GtkMenuItem
*menuitem
,
1739 project_close(TRUE
);
1744 on_project_properties1_activate (GtkMenuItem
*menuitem
,
1747 project_properties();
1752 on_menu_project1_activate (GtkMenuItem
*menuitem
,
1755 static GtkWidget
*item_close
= NULL
;
1756 static GtkWidget
*item_properties
= NULL
;
1758 if (item_close
== NULL
)
1760 item_close
= ui_lookup_widget(main_widgets
.window
, "project_close1");
1761 item_properties
= ui_lookup_widget(main_widgets
.window
, "project_properties1");
1764 gtk_widget_set_sensitive(item_close
, (app
->project
!= NULL
));
1765 gtk_widget_set_sensitive(item_properties
, (app
->project
!= NULL
));
1766 gtk_widget_set_sensitive(ui_widgets
.recent_projects_menuitem
,
1767 g_queue_get_length(ui_prefs
.recent_projects_queue
) > 0);
1772 on_menu_open_selected_file1_activate (GtkMenuItem
*menuitem
,
1775 GeanyDocument
*doc
= document_get_current();
1780 wc
= GEANY_WORDCHARS
"./-" "\\";
1782 wc
= GEANY_WORDCHARS
"./-";
1785 g_return_if_fail(doc
!= NULL
);
1787 sel
= editor_get_default_selection(doc
->editor
, TRUE
, wc
);
1791 gchar
*locale_filename
, *filename
= NULL
;
1793 if (g_path_is_absolute(sel
))
1794 filename
= g_strdup(sel
);
1796 { /* relative filename, add the path of the current file */
1799 path
= utils_get_current_file_dir_utf8();
1801 path
= g_get_current_dir();
1803 filename
= g_build_path(G_DIR_SEPARATOR_S
, path
, sel
, NULL
);
1805 if (! g_file_test(filename
, G_FILE_TEST_EXISTS
) &&
1806 app
->project
!= NULL
&& NZV(app
->project
->base_path
))
1808 /* try the project's base path */
1809 setptr(path
, project_get_base_path());
1810 setptr(filename
, g_build_path(G_DIR_SEPARATOR_S
, path
, sel
, NULL
));
1815 locale_filename
= utils_get_locale_from_utf8(filename
);
1816 document_open_file(locale_filename
, FALSE
, NULL
, NULL
);
1819 g_free(locale_filename
);
1826 on_remove_markers1_activate (GtkMenuItem
*menuitem
,
1829 GeanyDocument
*doc
= document_get_current();
1830 g_return_if_fail(doc
!= NULL
);
1832 sci_marker_delete_all(doc
->editor
->sci
, 0); /* delete the yellow tag marker */
1833 sci_marker_delete_all(doc
->editor
->sci
, 1); /* delete user markers */
1834 editor_indicator_clear(doc
->editor
, GEANY_INDICATOR_SEARCH
);
1839 on_load_tags1_activate (GtkMenuItem
*menuitem
,
1842 symbols_show_load_tags_dialog();
1847 on_context_action1_activate (GtkMenuItem
*menuitem
,
1850 gchar
*word
, *command
;
1851 GError
*error
= NULL
;
1852 GeanyDocument
*doc
= document_get_current();
1854 g_return_if_fail(doc
!= NULL
);
1856 if (sci_has_selection(doc
->editor
->sci
))
1857 { /* take selected text if there is a selection */
1858 word
= g_malloc(sci_get_selected_text_length(doc
->editor
->sci
) + 1);
1859 sci_get_selected_text(doc
->editor
->sci
, word
);
1863 word
= g_strdup(editor_info
.current_word
);
1866 /* use the filetype specific command if available, fallback to global command otherwise */
1867 if (doc
->file_type
!= NULL
&&
1868 NZV(doc
->file_type
->context_action_cmd
))
1870 command
= g_strdup(doc
->file_type
->context_action_cmd
);
1874 command
= g_strdup(tool_prefs
.context_action_cmd
);
1877 /* substitute the wildcard %s and run the command if it is non empty */
1880 utils_str_replace_all(&command
, "%s", word
);
1882 if (! g_spawn_command_line_async(command
, &error
))
1884 ui_set_statusbar(TRUE
, "Context action command failed: %s", error
->message
);
1885 g_error_free(error
);
1894 on_menu_toggle_all_additional_widgets1_activate
1895 (GtkMenuItem
*menuitem
,
1898 static gint hide_all
= -1;
1899 GtkCheckMenuItem
*msgw
= GTK_CHECK_MENU_ITEM(
1900 ui_lookup_widget(main_widgets
.window
, "menu_show_messages_window1"));
1901 GtkCheckMenuItem
*toolbari
= GTK_CHECK_MENU_ITEM(
1902 ui_lookup_widget(main_widgets
.window
, "menu_show_toolbar1"));
1904 /* get the initial state (necessary if Geany was closed with hide_all = TRUE) */
1905 if (G_UNLIKELY(hide_all
== -1))
1907 if (! gtk_check_menu_item_get_active(msgw
) &&
1908 ! interface_prefs
.show_notebook_tabs
&&
1909 ! gtk_check_menu_item_get_active(toolbari
))
1917 hide_all
= ! hide_all
; /* toggle */
1921 if (gtk_check_menu_item_get_active(msgw
))
1922 gtk_check_menu_item_set_active(msgw
, ! gtk_check_menu_item_get_active(msgw
));
1924 interface_prefs
.show_notebook_tabs
= FALSE
;
1925 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets
.notebook
), interface_prefs
.show_notebook_tabs
);
1927 ui_statusbar_showhide(FALSE
);
1929 if (gtk_check_menu_item_get_active(toolbari
))
1930 gtk_check_menu_item_set_active(toolbari
, ! gtk_check_menu_item_get_active(toolbari
));
1935 if (! gtk_check_menu_item_get_active(msgw
))
1936 gtk_check_menu_item_set_active(msgw
, ! gtk_check_menu_item_get_active(msgw
));
1938 interface_prefs
.show_notebook_tabs
= TRUE
;
1939 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets
.notebook
), interface_prefs
.show_notebook_tabs
);
1941 ui_statusbar_showhide(TRUE
);
1943 if (! gtk_check_menu_item_get_active(toolbari
))
1944 gtk_check_menu_item_set_active(toolbari
, ! gtk_check_menu_item_get_active(toolbari
));
1950 on_forward_activate (GtkMenuItem
*menuitem
,
1953 navqueue_go_forward();
1958 on_back_activate (GtkMenuItem
*menuitem
,
1965 gboolean
on_motion_event(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
)
1967 if (prefs
.auto_focus
&& ! GTK_WIDGET_HAS_FOCUS(widget
))
1968 gtk_widget_grab_focus(widget
);
1974 static void set_indent_type(GtkCheckMenuItem
*menuitem
, GeanyIndentType type
)
1978 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
1981 doc
= document_get_current();
1982 g_return_if_fail(doc
!= NULL
);
1984 editor_set_indent_type(doc
->editor
, type
);
1985 ui_update_statusbar(doc
, -1);
1990 on_tabs1_activate (GtkCheckMenuItem
*menuitem
,
1993 set_indent_type(menuitem
, GEANY_INDENT_TYPE_TABS
);
1998 on_spaces1_activate (GtkCheckMenuItem
*menuitem
,
2001 set_indent_type(menuitem
, GEANY_INDENT_TYPE_SPACES
);
2006 on_tabs_and_spaces1_activate (GtkCheckMenuItem
*menuitem
,
2009 set_indent_type(menuitem
, GEANY_INDENT_TYPE_BOTH
);
2014 on_strip_trailing_spaces1_activate (GtkMenuItem
*menuitem
,
2019 if (ignore_callback
)
2022 doc
= document_get_current();
2023 g_return_if_fail(doc
!= NULL
);
2025 editor_strip_trailing_spaces(doc
->editor
);
2030 on_page_setup1_activate (GtkMenuItem
*menuitem
,
2033 #if GTK_CHECK_VERSION(2, 10, 0)
2034 printing_page_setup_gtk();
2040 on_escape_key_press_event (GtkWidget
*widget
,
2044 guint state
= event
->state
& gtk_accelerator_get_default_mod_mask();
2046 /* make pressing escape in the sidebar and toolbar focus the editor */
2047 if (event
->keyval
== GDK_Escape
&& state
== 0)
2049 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
2057 on_line_breaking1_activate (GtkMenuItem
*menuitem
,
2062 if (ignore_callback
)
2065 doc
= document_get_current();
2066 g_return_if_fail(doc
!= NULL
);
2068 doc
->editor
->line_breaking
= !doc
->editor
->line_breaking
;
2073 on_replace_spaces_activate (GtkMenuItem
*menuitem
,
2076 GeanyDocument
*doc
= document_get_current();
2078 g_return_if_fail(doc
!= NULL
);
2080 editor_replace_spaces(doc
->editor
);
2085 on_search1_activate (GtkMenuItem
*menuitem
,
2088 GtkWidget
*next_message
= ui_lookup_widget(main_widgets
.window
, "next_message1");
2089 GtkWidget
*previous_message
= ui_lookup_widget(main_widgets
.window
, "previous_message1");
2090 gboolean have_messages
;
2092 /* enable commands if the messages window has any items */
2093 have_messages
= gtk_tree_model_iter_n_children(GTK_TREE_MODEL(msgwindow
.store_msg
),
2096 gtk_widget_set_sensitive(next_message
, have_messages
);
2097 gtk_widget_set_sensitive(previous_message
, have_messages
);
2101 /* simple implementation (vs. close all which doesn't close documents if cancelled) */
2103 on_close_other_documents1_activate (GtkMenuItem
*menuitem
,
2107 GeanyDocument
*doc
, *cur_doc
= document_get_current();
2109 for (i
= 0; i
< documents_array
->len
; i
++)
2113 if (doc
== cur_doc
|| ! doc
->is_valid
)
2116 if (! document_close(doc
))
2123 on_menu_reload_configuration1_activate (GtkMenuItem
*menuitem
,
2126 main_reload_configuration();
2131 on_debug_messages1_activate (GtkMenuItem
*menuitem
,
2134 log_show_debug_messages_dialog();
2139 on_send_selection_to_vte1_activate (GtkMenuItem
*menuitem
,
2143 if (vte_info
.load_vte
)
2144 vte_send_selection_to_vte();
2149 gboolean
on_window_state_event (GtkWidget
*widget
,
2150 GdkEventWindowState
*event
,
2154 if (event
->changed_mask
& GDK_WINDOW_STATE_FULLSCREEN
)
2156 static GtkWidget
*menuitem
= NULL
;
2158 if (menuitem
== NULL
)
2159 menuitem
= ui_lookup_widget(widget
, "menu_fullscreen1");
2161 ignore_callback
= TRUE
;
2163 ui_prefs
.fullscreen
= (event
->new_window_state
& GDK_WINDOW_STATE_FULLSCREEN
) ? TRUE
: FALSE
;
2164 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem
), ui_prefs
.fullscreen
);
2166 ignore_callback
= FALSE
;
2173 on_customize_toolbar1_activate (GtkMenuItem
*menuitem
,
2177 GtkNotebook
*notebook
;
2179 prefs_show_dialog();
2181 /* select the KB page */
2182 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "vbox15");
2183 notebook
= GTK_NOTEBOOK(ui_lookup_widget(ui_widgets
.prefs_dialog
, "notebook2"));
2185 if (notebook
!= NULL
&& widget
!= NULL
)
2186 gtk_notebook_set_current_page(notebook
, gtk_notebook_page_num(notebook
, widget
));
2191 on_button_customize_toolbar_clicked (GtkButton
*button
,
2194 toolbar_configure(GTK_WINDOW(ui_widgets
.prefs_dialog
));
2199 on_cut_current_line_s_1_activate (GtkMenuItem
*menuitem
,
2202 keybindings_send_command(GEANY_KEY_GROUP_CLIPBOARD
, GEANY_KEYS_CLIPBOARD_CUTLINE
);
2207 on_copy_current_line_s_1_activate (GtkMenuItem
*menuitem
,
2210 keybindings_send_command(GEANY_KEY_GROUP_CLIPBOARD
, GEANY_KEYS_CLIPBOARD_COPYLINE
);
2215 on_delete_current_line_s_1_activate (GtkMenuItem
*menuitem
,
2218 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_DELETELINE
);
2223 on_duplicate_line_or_selection1_activate
2224 (GtkMenuItem
*menuitem
,
2227 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_DUPLICATELINE
);
2232 on_select_current_line_s_1_activate (GtkMenuItem
*menuitem
,
2235 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_LINE
);
2240 on_select_current_paragraph1_activate (GtkMenuItem
*menuitem
,
2243 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_PARAGRAPH
);
2248 on_insert_alternative_white_space1_activate
2249 (GtkMenuItem
*menuitem
,
2252 keybindings_send_command(GEANY_KEY_GROUP_INSERT
, GEANY_KEYS_INSERT_ALTWHITESPACE
);
2257 on_go_to_next_marker1_activate (GtkMenuItem
*menuitem
,
2260 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_NEXTMARKER
);
2265 on_go_to_previous_marker1_activate (GtkMenuItem
*menuitem
,
2268 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_PREVIOUSMARKER
);
2273 on_reflow_lines_block1_activate (GtkMenuItem
*menuitem
,
2276 keybindings_send_command(GEANY_KEY_GROUP_FORMAT
, GEANY_KEYS_FORMAT_REFLOWPARAGRAPH
);
2281 on_transpose_current_line1_activate (GtkMenuItem
*menuitem
,
2284 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_TRANSPOSELINE
);
2289 on_smart_line_indent1_activate (GtkMenuItem
*menuitem
,
2292 keybindings_send_command(GEANY_KEY_GROUP_FORMAT
, GEANY_KEYS_FORMAT_AUTOINDENT
);
2297 on_plugin_preferences1_activate (GtkMenuItem
*menuitem
,
2301 plugin_show_configure(NULL
);