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 const 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 /* don't prompt if file hasn't been edited at all */
489 if ((!doc
->changed
&& !document_can_undo(doc
) && !document_can_redo(doc
)) ||
490 dialogs_show_question_full(NULL
, _("_Reload"), GTK_STOCK_CANCEL
,
491 _("Any unsaved changes will be lost."),
492 _("Are you sure you want to reload '%s'?"), base_name
))
494 document_reload_file(doc
, charset
);
496 ui_update_statusbar(doc
, -1);
503 on_change_font1_activate (GtkMenuItem
*menuitem
,
506 dialogs_show_open_font();
512 on_toolbutton_new_clicked (GtkAction
*action
,
515 document_new_file(NULL
, NULL
, NULL
);
521 on_toolbutton_open_clicked (GtkAction
*action
,
524 dialogs_show_open_file();
530 on_toolbutton_save_clicked (GtkAction
*action
,
533 on_save1_activate(NULL
, user_data
);
537 /* store text, clear search flags so we can use Search->Find Next/Previous */
538 static void setup_find_next(const gchar
*text
)
540 setptr(search_data
.text
, g_strdup(text
));
541 search_data
.flags
= 0;
542 search_data
.backwards
= FALSE
;
543 search_data
.search_bar
= TRUE
;
549 on_toolbar_search_entry_changed(GtkAction
*action
, const gchar
*text
, gpointer user_data
)
551 GeanyDocument
*doc
= document_get_current();
554 setup_find_next(text
);
555 result
= document_search_bar_find(doc
, search_data
.text
, 0, GPOINTER_TO_INT(user_data
));
556 if (search_data
.search_bar
)
557 ui_set_search_entry_background(toolbar_get_widget_child_by_name("SearchEntry"), result
);
563 on_toolbutton_search_clicked (GtkAction
*action
,
566 GeanyDocument
*doc
= document_get_current();
568 GtkWidget
*entry
= toolbar_get_widget_child_by_name("SearchEntry");
572 const gchar
*text
= gtk_entry_get_text(GTK_ENTRY(entry
));
574 setup_find_next(text
);
575 result
= document_search_bar_find(doc
, search_data
.text
, 0, FALSE
);
576 if (search_data
.search_bar
)
577 ui_set_search_entry_background(entry
, result
);
580 on_find1_activate(NULL
, NULL
);
584 /* hides toolbar from toolbar popup menu */
586 on_hide_toolbar1_activate (GtkMenuItem
*menuitem
,
589 GtkWidget
*tool_item
= ui_lookup_widget(GTK_WIDGET(main_widgets
.window
), "menu_show_toolbar1");
590 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(tool_item
), FALSE
);
594 /* zoom in from menu bar and popup menu */
596 on_zoom_in1_activate (GtkMenuItem
*menuitem
,
599 GeanyDocument
*doc
= document_get_current();
600 static gint done
= 1;
602 g_return_if_fail(doc
!= NULL
);
605 sci_set_line_numbers(doc
->editor
->sci
, editor_prefs
.show_linenumber_margin
,
606 (sci_get_zoom(doc
->editor
->sci
) / 2));
607 sci_zoom_in(doc
->editor
->sci
);
611 /* zoom out from menu bar and popup menu */
613 on_zoom_out1_activate (GtkMenuItem
*menuitem
,
616 GeanyDocument
*doc
= document_get_current();
618 g_return_if_fail(doc
!= NULL
);
620 if (sci_get_zoom(doc
->editor
->sci
) == 0)
621 sci_set_line_numbers(doc
->editor
->sci
, editor_prefs
.show_linenumber_margin
, 0);
622 sci_zoom_out(doc
->editor
->sci
);
627 on_normal_size1_activate (GtkMenuItem
*menuitem
,
630 GeanyDocument
*doc
= document_get_current();
632 g_return_if_fail(doc
!= NULL
);
634 sci_zoom_off(doc
->editor
->sci
);
635 sci_set_line_numbers(doc
->editor
->sci
, editor_prefs
.show_linenumber_margin
, 0);
641 on_toolbutton_close_clicked (GtkAction
*action
,
644 on_close1_activate(NULL
, NULL
);
649 on_toolbutton_close_all_clicked (GtkAction
*action
,
652 on_close_all1_activate(NULL
, NULL
);
657 on_toolbutton_preferences_clicked (GtkAction
*action
,
660 on_preferences1_activate(NULL
, NULL
);
664 static gboolean
delayed_check_disk_status(gpointer data
)
666 document_check_disk_status(data
, FALSE
);
671 /* Changes window-title after switching tabs and lots of other things.
672 * note: using 'after' makes Scintilla redraw before the UI, appearing more responsive */
674 on_notebook1_switch_page_after (GtkNotebook
*notebook
,
675 GtkNotebookPage
*page
,
681 if (G_UNLIKELY(main_status
.opening_session_files
) || G_UNLIKELY(main_status
.closing_all
))
684 if (page_num
== (guint
) -1 && page
!= NULL
)
685 doc
= document_find_by_sci(SCINTILLA(page
));
687 doc
= document_get_from_page(page_num
);
691 sidebar_select_openfiles_item(doc
);
692 ui_save_buttons_toggle(doc
->changed
);
693 ui_set_window_title(doc
);
694 ui_update_statusbar(doc
, -1);
695 ui_update_popup_reundo_items(doc
);
696 ui_document_show_hide(doc
); /* update the document menu */
697 build_menu_update(doc
);
698 sidebar_update_tag_list(doc
, FALSE
);
700 /* We delay the check to avoid weird fast, unintended switching of notebook pages when
701 * the 'file has changed' dialog is shown while the switch event is not yet completely
702 * finished. So, we check after the switch has been performed to be safe. */
703 g_idle_add(delayed_check_disk_status
, doc
);
706 vte_cwd((doc
->real_path
!= NULL
) ? doc
->real_path
: doc
->file_name
, FALSE
);
709 g_signal_emit_by_name(geany_object
, "document-activate", doc
);
715 on_tv_notebook_switch_page (GtkNotebook
*notebook
,
716 GtkNotebookPage
*page
,
720 /* suppress selection changed signal when switching to the open files list */
721 ignore_callback
= TRUE
;
726 on_tv_notebook_switch_page_after (GtkNotebook
*notebook
,
727 GtkNotebookPage
*page
,
731 ignore_callback
= FALSE
;
735 static void convert_eol(gint mode
)
737 GeanyDocument
*doc
= document_get_current();
739 g_return_if_fail(doc
!= NULL
);
741 sci_convert_eols(doc
->editor
->sci
, mode
);
742 sci_set_eol_mode(doc
->editor
->sci
, mode
);
743 ui_update_statusbar(doc
, -1);
748 on_crlf_activate (GtkCheckMenuItem
*menuitem
,
751 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
754 convert_eol(SC_EOL_CRLF
);
759 on_lf_activate (GtkCheckMenuItem
*menuitem
,
762 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
765 convert_eol(SC_EOL_LF
);
770 on_cr_activate (GtkCheckMenuItem
*menuitem
,
773 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
776 convert_eol(SC_EOL_CR
);
781 on_replace_tabs_activate (GtkMenuItem
*menuitem
,
784 GeanyDocument
*doc
= document_get_current();
786 g_return_if_fail(doc
!= NULL
);
788 editor_replace_tabs(doc
->editor
);
793 toolbar_popup_menu (GtkWidget
*widget
,
794 GdkEventButton
*event
,
797 if (event
->button
== 3)
799 gtk_menu_popup(GTK_MENU(ui_widgets
.toolbar_menu
), NULL
, NULL
, NULL
, NULL
, event
->button
, event
->time
);
806 void on_toggle_case1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
808 GeanyDocument
*doc
= document_get_current();
809 ScintillaObject
*sci
;
811 gboolean keep_sel
= TRUE
;
813 g_return_if_fail(doc
!= NULL
);
815 sci
= doc
->editor
->sci
;
816 if (! sci_has_selection(sci
))
818 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_WORD
);
823 gchar
*result
= NULL
;
824 gint cmd
= SCI_LOWERCASE
;
825 gint text_len
= sci_get_selected_text_length(sci
);
826 gboolean rectsel
= scintilla_send_message(sci
, SCI_SELECTIONISRECTANGLE
, 0, 0);
828 text
= g_malloc(text_len
+ 1);
829 sci_get_selected_text(sci
, text
);
831 if (utils_str_has_upper(text
))
836 result
= g_utf8_strdown(text
, -1);
844 result
= g_utf8_strup(text
, -1);
850 sci_replace_sel(sci
, result
);
853 sci_set_selection_start(sci
, sci_get_current_position(sci
) - text_len
+ 1);
856 sci_send_command(sci
, cmd
);
865 on_show_toolbar1_toggled (GtkCheckMenuItem
*checkmenuitem
,
868 if (ignore_callback
) return;
870 toolbar_prefs
.visible
= (toolbar_prefs
.visible
) ? FALSE
: TRUE
;;
871 ui_widget_show_hide(GTK_WIDGET(main_widgets
.toolbar
), toolbar_prefs
.visible
);
876 on_fullscreen1_toggled (GtkCheckMenuItem
*checkmenuitem
,
882 ui_prefs
.fullscreen
= (ui_prefs
.fullscreen
) ? FALSE
: TRUE
;
888 on_show_messages_window1_toggled (GtkCheckMenuItem
*checkmenuitem
,
894 ui_prefs
.msgwindow_visible
= (ui_prefs
.msgwindow_visible
) ? FALSE
: TRUE
;
895 msgwin_show_hide(ui_prefs
.msgwindow_visible
);
900 on_markers_margin1_toggled (GtkCheckMenuItem
*checkmenuitem
,
906 editor_prefs
.show_markers_margin
= ! editor_prefs
.show_markers_margin
;
907 ui_toggle_editor_features(GEANY_EDITOR_SHOW_MARKERS_MARGIN
);
912 on_show_line_numbers1_toggled (GtkCheckMenuItem
*checkmenuitem
,
918 editor_prefs
.show_linenumber_margin
= ! editor_prefs
.show_linenumber_margin
;
919 ui_toggle_editor_features(GEANY_EDITOR_SHOW_LINE_NUMBERS
);
924 on_menu_show_white_space1_toggled (GtkCheckMenuItem
*checkmenuitem
,
930 editor_prefs
.show_white_space
= ! editor_prefs
.show_white_space
;
931 ui_toggle_editor_features(GEANY_EDITOR_SHOW_WHITE_SPACE
);
936 on_menu_show_line_endings1_toggled (GtkCheckMenuItem
*checkmenuitem
,
942 editor_prefs
.show_line_endings
= ! editor_prefs
.show_line_endings
;
943 ui_toggle_editor_features(GEANY_EDITOR_SHOW_LINE_ENDINGS
);
948 on_menu_show_indentation_guides1_toggled (GtkCheckMenuItem
*checkmenuitem
,
954 editor_prefs
.show_indent_guide
= ! editor_prefs
.show_indent_guide
;
955 ui_toggle_editor_features(GEANY_EDITOR_SHOW_INDENTATION_GUIDES
);
960 on_line_wrapping1_toggled (GtkCheckMenuItem
*checkmenuitem
,
963 if (! ignore_callback
)
965 GeanyDocument
*doc
= document_get_current();
966 g_return_if_fail(doc
!= NULL
);
968 editor_set_line_wrapping(doc
->editor
, ! doc
->editor
->line_wrapping
);
974 on_set_file_readonly1_toggled (GtkCheckMenuItem
*checkmenuitem
,
977 if (! ignore_callback
)
979 GeanyDocument
*doc
= document_get_current();
980 g_return_if_fail(doc
!= NULL
);
982 doc
->readonly
= ! doc
->readonly
;
983 sci_set_readonly(doc
->editor
->sci
, doc
->readonly
);
984 ui_update_tab_status(doc
);
985 ui_update_statusbar(doc
, -1);
991 on_use_auto_indentation1_toggled (GtkCheckMenuItem
*checkmenuitem
,
994 if (! ignore_callback
)
996 GeanyDocument
*doc
= document_get_current();
997 g_return_if_fail(doc
!= NULL
);
999 doc
->editor
->auto_indent
= ! doc
->editor
->auto_indent
;
1004 static void find_usage(gboolean in_session
)
1008 GeanyDocument
*doc
= document_get_current();
1010 g_return_if_fail(doc
!= NULL
);
1012 if (sci_has_selection(doc
->editor
->sci
))
1013 { /* take selected text if there is a selection */
1014 search_text
= g_malloc(sci_get_selected_text_length(doc
->editor
->sci
) + 1);
1015 sci_get_selected_text(doc
->editor
->sci
, search_text
);
1016 flags
= SCFIND_MATCHCASE
;
1020 editor_find_current_word(doc
->editor
, -1,
1021 editor_info
.current_word
, GEANY_MAX_WORD_LENGTH
, NULL
);
1022 search_text
= g_strdup(editor_info
.current_word
);
1023 flags
= SCFIND_MATCHCASE
| SCFIND_WHOLEWORD
;
1026 search_find_usage(search_text
, flags
, in_session
);
1027 g_free(search_text
);
1032 on_find_document_usage1_activate (GtkMenuItem
*menuitem
,
1040 on_find_usage1_activate (GtkMenuItem
*menuitem
,
1047 static void goto_tag(gboolean definition
)
1049 GeanyDocument
*doc
= document_get_current();
1051 g_return_if_fail(doc
!= NULL
);
1053 /* update cursor pos for navigating back afterwards */
1054 if (!sci_has_selection(doc
->editor
->sci
))
1055 sci_set_current_position(doc
->editor
->sci
, editor_info
.click_pos
, FALSE
);
1057 /* use the keybinding callback as it checks for selections as well as current word */
1059 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_TAGDEFINITION
);
1061 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_TAGDECLARATION
);
1066 on_goto_tag_definition1 (GtkMenuItem
*menuitem
,
1074 on_goto_tag_declaration1 (GtkMenuItem
*menuitem
,
1082 on_count_words1_activate (GtkMenuItem
*menuitem
,
1090 on_show_color_chooser1_activate (GtkMenuItem
*menuitem
,
1094 GeanyDocument
*doc
= document_get_current();
1097 g_return_if_fail(doc
!= NULL
);
1099 pos
= sci_get_current_position(doc
->editor
->sci
);
1100 editor_find_current_word(doc
->editor
, pos
, colour
, sizeof colour
, GEANY_WORDCHARS
"#");
1101 tools_color_chooser(colour
);
1106 on_toolbutton_compile_clicked (GtkAction
*action
,
1109 keybindings_send_command(GEANY_KEY_GROUP_BUILD
, GEANY_KEYS_BUILD_COMPILE
);
1114 on_find1_activate (GtkMenuItem
*menuitem
,
1117 search_show_find_dialog();
1122 on_find_next1_activate (GtkMenuItem
*menuitem
,
1125 search_find_again(FALSE
);
1130 on_find_previous1_activate (GtkMenuItem
*menuitem
,
1133 if (search_data
.flags
& SCFIND_REGEXP
)
1134 /* Can't reverse search order for a regex (find next ignores search backwards) */
1137 search_find_again(TRUE
);
1142 on_find_nextsel1_activate (GtkMenuItem
*menuitem
,
1145 search_find_selection(document_get_current(), FALSE
);
1150 on_find_prevsel1_activate (GtkMenuItem
*menuitem
,
1153 search_find_selection(document_get_current(), TRUE
);
1158 on_replace1_activate (GtkMenuItem
*menuitem
,
1161 search_show_replace_dialog();
1166 on_find_in_files1_activate (GtkMenuItem
*menuitem
,
1169 search_show_find_in_files_dialog(NULL
);
1173 static void get_line_and_offset_from_text(const gchar
*text
, gint
*line_no
, gint
*offset
)
1175 if (*text
== '+' || *text
== '-')
1177 *line_no
= atoi(text
+ 1);
1178 *offset
= (*text
== '+') ? 1 : -1;
1182 *line_no
= atoi(text
) - 1;
1189 on_go_to_line_activate (GtkMenuItem
*menuitem
,
1192 static gchar value
[16] = "";
1195 result
= dialogs_show_input_goto_line(
1196 _("Go to Line"), GTK_WINDOW(main_widgets
.window
),
1197 _("Enter the line you want to go to:"), value
);
1200 GeanyDocument
*doc
= document_get_current();
1204 g_return_if_fail(doc
!= NULL
);
1206 get_line_and_offset_from_text(result
, &line_no
, &offset
);
1207 if (! editor_goto_line(doc
->editor
, line_no
, offset
))
1209 /* remember value for future calls */
1210 g_snprintf(value
, sizeof(value
), "%s", result
);
1218 on_toolbutton_goto_entry_activate(GtkAction
*action
, const gchar
*text
, gpointer user_data
)
1220 GeanyDocument
*doc
= document_get_current();
1224 g_return_if_fail(doc
!= NULL
);
1226 get_line_and_offset_from_text(text
, &line_no
, &offset
);
1227 if (! editor_goto_line(doc
->editor
, line_no
, offset
))
1230 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
1235 on_toolbutton_goto_clicked (GtkAction
*action
,
1238 GtkWidget
*entry
= toolbar_get_widget_child_by_name("GotoEntry");
1242 const gchar
*text
= gtk_entry_get_text(GTK_ENTRY(entry
));
1244 on_toolbutton_goto_entry_activate(NULL
, text
, NULL
);
1247 on_go_to_line_activate(NULL
, NULL
);
1252 on_help1_activate (GtkMenuItem
*menuitem
,
1257 uri
= utils_get_help_url(NULL
);
1258 utils_open_browser(uri
);
1264 on_help_shortcuts1_activate (GtkMenuItem
*menuitem
,
1267 keybindings_show_shortcuts();
1272 on_website1_activate (GtkMenuItem
*menuitem
,
1275 utils_open_browser(GEANY_HOMEPAGE
);
1280 on_comments_function_activate (GtkMenuItem
*menuitem
,
1283 GeanyDocument
*doc
= document_get_current();
1285 const gchar
*cur_tag
= NULL
;
1286 gint line
= -1, pos
= 0;
1288 if (doc
== NULL
|| doc
->file_type
== NULL
)
1290 ui_set_statusbar(FALSE
,
1291 _("Please set the filetype for the current file before using this function."));
1295 /* symbols_get_current_function returns -1 on failure, so sci_get_position_from_line
1296 * returns the current position, so it should be safe */
1297 line
= symbols_get_current_function(doc
, &cur_tag
);
1298 pos
= sci_get_position_from_line(doc
->editor
->sci
, line
- 1);
1300 text
= templates_get_template_function(doc
, cur_tag
);
1302 sci_insert_text(doc
->editor
->sci
, pos
, text
);
1308 on_comments_multiline_activate (GtkMenuItem
*menuitem
,
1311 GeanyDocument
*doc
= document_get_current();
1313 if (doc
== NULL
|| doc
->file_type
== NULL
)
1315 ui_set_statusbar(FALSE
,
1316 _("Please set the filetype for the current file before using this function."));
1320 verify_click_pos(doc
); /* make sure that the click_pos is valid */
1322 if (doc
->file_type
->comment_open
)
1323 editor_insert_multiline_comment(doc
->editor
);
1330 on_comments_gpl_activate (GtkMenuItem
*menuitem
,
1333 GeanyDocument
*doc
= document_get_current();
1336 g_return_if_fail(doc
!= NULL
);
1338 text
= templates_get_template_licence(doc
, GEANY_TEMPLATE_GPL
);
1340 verify_click_pos(doc
); /* make sure that the click_pos is valid */
1342 sci_insert_text(doc
->editor
->sci
, editor_info
.click_pos
, text
);
1348 on_comments_bsd_activate (GtkMenuItem
*menuitem
,
1352 GeanyDocument
*doc
= document_get_current();
1355 g_return_if_fail(doc
!= NULL
);
1357 text
= templates_get_template_licence(doc
, GEANY_TEMPLATE_BSD
);
1359 verify_click_pos(doc
); /* make sure that the click_pos is valid */
1361 sci_insert_text(doc
->editor
->sci
, editor_info
.click_pos
, text
);
1368 on_comments_changelog_activate (GtkMenuItem
*menuitem
,
1371 GeanyDocument
*doc
= document_get_current();
1374 g_return_if_fail(doc
!= NULL
);
1376 text
= templates_get_template_changelog(doc
);
1377 sci_insert_text(doc
->editor
->sci
, 0, text
);
1378 /* sets the cursor to the right position to type the changelog text,
1379 * the template has 21 chars + length of name and email */
1380 sci_goto_pos(doc
->editor
->sci
, 21 + strlen(template_prefs
.developer
) + strlen(template_prefs
.mail
), TRUE
);
1387 on_comments_fileheader_activate (GtkMenuItem
*menuitem
,
1390 GeanyDocument
*doc
= document_get_current();
1395 g_return_if_fail(doc
!= NULL
);
1397 ft
= doc
->file_type
;
1398 fname
= doc
->file_name
;
1399 text
= templates_get_template_fileheader(FILETYPE_ID(ft
), fname
);
1401 sci_insert_text(doc
->editor
->sci
, 0, text
);
1402 sci_goto_pos(doc
->editor
->sci
, 0, FALSE
);
1408 on_insert_date_activate (GtkMenuItem
*menuitem
,
1411 GeanyDocument
*doc
= document_get_current();
1412 const gchar
*format
= NULL
;
1415 g_return_if_fail(doc
!= NULL
);
1417 /* set default value */
1418 if (utils_str_equal("", ui_prefs
.custom_date_format
))
1420 g_free(ui_prefs
.custom_date_format
);
1421 ui_prefs
.custom_date_format
= g_strdup("%d.%m.%Y");
1424 if (utils_str_equal(_("dd.mm.yyyy"), (gchar
*) user_data
))
1425 format
= "%d.%m.%Y";
1426 else if (utils_str_equal(_("mm.dd.yyyy"), (gchar
*) user_data
))
1427 format
= "%m.%d.%Y";
1428 else if (utils_str_equal(_("yyyy/mm/dd"), (gchar
*) user_data
))
1429 format
= "%Y/%m/%d";
1430 else if (utils_str_equal(_("dd.mm.yyyy hh:mm:ss"), (gchar
*) user_data
))
1431 format
= "%d.%m.%Y %H:%M:%S";
1432 else if (utils_str_equal(_("mm.dd.yyyy hh:mm:ss"), (gchar
*) user_data
))
1433 format
= "%m.%d.%Y %H:%M:%S";
1434 else if (utils_str_equal(_("yyyy/mm/dd hh:mm:ss"), (gchar
*) user_data
))
1435 format
= "%Y/%m/%d %H:%M:%S";
1436 else if (utils_str_equal(_("_Use Custom Date Format"), (gchar
*) user_data
))
1437 format
= ui_prefs
.custom_date_format
;
1440 gchar
*str
= dialogs_show_input(_("Custom Date Format"), GTK_WINDOW(main_widgets
.window
),
1441 _("Enter here a custom date and time format. "
1442 "You can use any conversion specifiers which can be used with the ANSI C strftime function."),
1443 ui_prefs
.custom_date_format
);
1445 setptr(ui_prefs
.custom_date_format
, str
);
1449 time_str
= utils_get_date_time(format
, NULL
);
1450 if (time_str
!= NULL
)
1452 verify_click_pos(doc
); /* make sure that the click_pos is valid */
1454 sci_insert_text(doc
->editor
->sci
, editor_info
.click_pos
, time_str
);
1455 sci_goto_pos(doc
->editor
->sci
, editor_info
.click_pos
+ strlen(time_str
), FALSE
);
1461 ui_set_statusbar(TRUE
,
1462 _("Date format string could not be converted (possibly too long)."));
1468 on_insert_include_activate (GtkMenuItem
*menuitem
,
1471 GeanyDocument
*doc
= document_get_current();
1475 g_return_if_fail(doc
!= NULL
);
1476 g_return_if_fail(user_data
!= NULL
);
1478 verify_click_pos(doc
); /* make sure that the click_pos is valid */
1480 if (utils_str_equal(user_data
, "blank"))
1482 text
= g_strdup("#include \"\"\n");
1483 pos
= editor_info
.click_pos
+ 10;
1487 text
= g_strconcat("#include <", user_data
, ">\n", NULL
);
1490 sci_insert_text(doc
->editor
->sci
, editor_info
.click_pos
, text
);
1493 sci_goto_pos(doc
->editor
->sci
, pos
, FALSE
);
1498 on_file_properties_activate (GtkMenuItem
*menuitem
,
1501 GeanyDocument
*doc
= document_get_current();
1502 g_return_if_fail(doc
!= NULL
);
1504 dialogs_show_file_properties(doc
);
1509 on_menu_fold_all1_activate (GtkMenuItem
*menuitem
,
1512 GeanyDocument
*doc
= document_get_current();
1513 g_return_if_fail(doc
!= NULL
);
1515 editor_fold_all(doc
->editor
);
1520 on_menu_unfold_all1_activate (GtkMenuItem
*menuitem
,
1523 GeanyDocument
*doc
= document_get_current();
1524 g_return_if_fail(doc
!= NULL
);
1526 editor_unfold_all(doc
->editor
);
1531 on_toolbutton_run_clicked (GtkAction
*action
,
1534 keybindings_send_command(GEANY_KEY_GROUP_BUILD
, GEANY_KEYS_BUILD_RUN
);
1539 on_menu_remove_indicators1_activate (GtkMenuItem
*menuitem
,
1542 GeanyDocument
*doc
= document_get_current();
1543 g_return_if_fail(doc
!= NULL
);
1545 editor_indicator_clear(doc
->editor
, GEANY_INDICATOR_ERROR
);
1550 on_print1_activate (GtkMenuItem
*menuitem
,
1553 GeanyDocument
*doc
= document_get_current();
1554 g_return_if_fail(doc
!= NULL
);
1556 printing_print_doc(doc
);
1561 on_menu_select_all1_activate (GtkMenuItem
*menuitem
,
1564 GeanyDocument
*doc
= document_get_current();
1565 g_return_if_fail(doc
!= NULL
);
1567 sci_select_all(doc
->editor
->sci
);
1572 on_menu_show_sidebar1_toggled (GtkCheckMenuItem
*checkmenuitem
,
1575 if (ignore_callback
)
1578 ui_prefs
.sidebar_visible
= ! ui_prefs
.sidebar_visible
;
1580 /* show built-in tabs if no tabs visible */
1581 if (ui_prefs
.sidebar_visible
&&
1582 ! interface_prefs
.sidebar_openfiles_visible
&& ! interface_prefs
.sidebar_symbol_visible
&&
1583 gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets
.sidebar_notebook
)) <= 2)
1585 interface_prefs
.sidebar_openfiles_visible
= TRUE
;
1586 interface_prefs
.sidebar_symbol_visible
= TRUE
;
1589 #if GTK_CHECK_VERSION(2, 14, 0)
1590 /* if window has input focus, set it back to the editor before toggling off */
1591 if (! ui_prefs
.sidebar_visible
&&
1592 gtk_container_get_focus_child(GTK_CONTAINER(main_widgets
.sidebar_notebook
)) != NULL
)
1594 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
1598 ui_sidebar_show_hide();
1603 on_menu_write_unicode_bom1_toggled (GtkCheckMenuItem
*checkmenuitem
,
1606 if (! ignore_callback
)
1608 GeanyDocument
*doc
= document_get_current();
1610 g_return_if_fail(doc
!= NULL
);
1617 document_undo_add(doc
, UNDO_BOM
, GINT_TO_POINTER(doc
->has_bom
));
1619 doc
->has_bom
= ! doc
->has_bom
;
1621 ui_update_statusbar(doc
, -1);
1627 on_menu_comment_line1_activate (GtkMenuItem
*menuitem
,
1630 GeanyDocument
*doc
= document_get_current();
1631 g_return_if_fail(doc
!= NULL
);
1633 editor_do_comment(doc
->editor
, -1, FALSE
, FALSE
);
1638 on_menu_uncomment_line1_activate (GtkMenuItem
*menuitem
,
1641 GeanyDocument
*doc
= document_get_current();
1642 g_return_if_fail(doc
!= NULL
);
1644 editor_do_uncomment(doc
->editor
, -1, FALSE
);
1649 on_menu_toggle_line_commentation1_activate
1650 (GtkMenuItem
*menuitem
,
1653 GeanyDocument
*doc
= document_get_current();
1654 g_return_if_fail(doc
!= NULL
);
1656 editor_do_comment_toggle(doc
->editor
);
1661 on_menu_increase_indent1_activate (GtkMenuItem
*menuitem
,
1664 GeanyDocument
*doc
= document_get_current();
1665 g_return_if_fail(doc
!= NULL
);
1667 editor_indent(doc
->editor
, TRUE
);
1672 on_menu_decrease_indent1_activate (GtkMenuItem
*menuitem
,
1675 GeanyDocument
*doc
= document_get_current();
1676 g_return_if_fail(doc
!= NULL
);
1678 editor_indent(doc
->editor
, FALSE
);
1683 on_next_message1_activate (GtkMenuItem
*menuitem
,
1686 if (! ui_tree_view_find_next(GTK_TREE_VIEW(msgwindow
.tree_msg
),
1687 msgwin_goto_messages_file_line
))
1688 ui_set_statusbar(FALSE
, _("No more message items."));
1693 on_previous_message1_activate (GtkMenuItem
*menuitem
,
1696 if (! ui_tree_view_find_previous(GTK_TREE_VIEW(msgwindow
.tree_msg
),
1697 msgwin_goto_messages_file_line
))
1698 ui_set_statusbar(FALSE
, _("No more message items."));
1703 on_menu_comments_multiline_activate (GtkMenuItem
*menuitem
,
1706 insert_callback_from_menu
= TRUE
;
1707 on_comments_multiline_activate(menuitem
, user_data
);
1712 on_menu_comments_gpl_activate (GtkMenuItem
*menuitem
,
1715 insert_callback_from_menu
= TRUE
;
1716 on_comments_gpl_activate(menuitem
, user_data
);
1721 on_menu_comments_bsd_activate (GtkMenuItem
*menuitem
,
1724 insert_callback_from_menu
= TRUE
;
1725 on_comments_bsd_activate(menuitem
, user_data
);
1730 on_menu_insert_include_activate (GtkMenuItem
*menuitem
,
1733 insert_callback_from_menu
= TRUE
;
1734 on_insert_include_activate(menuitem
, user_data
);
1739 on_menu_insert_date_activate (GtkMenuItem
*menuitem
,
1742 insert_callback_from_menu
= TRUE
;
1743 on_insert_date_activate(menuitem
, user_data
);
1748 on_project_new1_activate (GtkMenuItem
*menuitem
,
1756 on_project_open1_activate (GtkMenuItem
*menuitem
,
1764 on_project_close1_activate (GtkMenuItem
*menuitem
,
1767 project_close(TRUE
);
1772 on_project_properties1_activate (GtkMenuItem
*menuitem
,
1775 project_properties();
1780 on_menu_project1_activate (GtkMenuItem
*menuitem
,
1783 static GtkWidget
*item_close
= NULL
;
1784 static GtkWidget
*item_properties
= NULL
;
1786 if (item_close
== NULL
)
1788 item_close
= ui_lookup_widget(main_widgets
.window
, "project_close1");
1789 item_properties
= ui_lookup_widget(main_widgets
.window
, "project_properties1");
1792 gtk_widget_set_sensitive(item_close
, (app
->project
!= NULL
));
1793 gtk_widget_set_sensitive(item_properties
, (app
->project
!= NULL
));
1794 gtk_widget_set_sensitive(ui_widgets
.recent_projects_menuitem
,
1795 g_queue_get_length(ui_prefs
.recent_projects_queue
) > 0);
1800 on_menu_open_selected_file1_activate (GtkMenuItem
*menuitem
,
1803 GeanyDocument
*doc
= document_get_current();
1808 wc
= GEANY_WORDCHARS
"./-" "\\";
1810 wc
= GEANY_WORDCHARS
"./-";
1813 g_return_if_fail(doc
!= NULL
);
1815 sel
= editor_get_default_selection(doc
->editor
, TRUE
, wc
);
1819 gchar
*locale_filename
, *filename
= NULL
;
1821 if (g_path_is_absolute(sel
))
1822 filename
= g_strdup(sel
);
1824 { /* relative filename, add the path of the current file */
1827 path
= utils_get_current_file_dir_utf8();
1829 path
= g_get_current_dir();
1831 filename
= g_build_path(G_DIR_SEPARATOR_S
, path
, sel
, NULL
);
1833 if (! g_file_test(filename
, G_FILE_TEST_EXISTS
) &&
1834 app
->project
!= NULL
&& NZV(app
->project
->base_path
))
1836 /* try the project's base path */
1837 setptr(path
, project_get_base_path());
1838 setptr(filename
, g_build_path(G_DIR_SEPARATOR_S
, path
, sel
, NULL
));
1843 locale_filename
= utils_get_locale_from_utf8(filename
);
1844 document_open_file(locale_filename
, FALSE
, NULL
, NULL
);
1847 g_free(locale_filename
);
1854 on_remove_markers1_activate (GtkMenuItem
*menuitem
,
1857 GeanyDocument
*doc
= document_get_current();
1858 g_return_if_fail(doc
!= NULL
);
1860 sci_marker_delete_all(doc
->editor
->sci
, 0); /* delete the yellow tag marker */
1861 sci_marker_delete_all(doc
->editor
->sci
, 1); /* delete user markers */
1862 editor_indicator_clear(doc
->editor
, GEANY_INDICATOR_SEARCH
);
1867 on_load_tags1_activate (GtkMenuItem
*menuitem
,
1870 symbols_show_load_tags_dialog();
1875 on_context_action1_activate (GtkMenuItem
*menuitem
,
1878 gchar
*word
, *command
;
1879 GError
*error
= NULL
;
1880 GeanyDocument
*doc
= document_get_current();
1882 g_return_if_fail(doc
!= NULL
);
1884 if (sci_has_selection(doc
->editor
->sci
))
1885 { /* take selected text if there is a selection */
1886 word
= g_malloc(sci_get_selected_text_length(doc
->editor
->sci
) + 1);
1887 sci_get_selected_text(doc
->editor
->sci
, word
);
1891 word
= g_strdup(editor_info
.current_word
);
1894 /* use the filetype specific command if available, fallback to global command otherwise */
1895 if (doc
->file_type
!= NULL
&&
1896 NZV(doc
->file_type
->context_action_cmd
))
1898 command
= g_strdup(doc
->file_type
->context_action_cmd
);
1902 command
= g_strdup(tool_prefs
.context_action_cmd
);
1905 /* substitute the wildcard %s and run the command if it is non empty */
1908 utils_str_replace_all(&command
, "%s", word
);
1910 if (! g_spawn_command_line_async(command
, &error
))
1912 ui_set_statusbar(TRUE
, "Context action command failed: %s", error
->message
);
1913 g_error_free(error
);
1922 on_menu_toggle_all_additional_widgets1_activate
1923 (GtkMenuItem
*menuitem
,
1926 static gint hide_all
= -1;
1927 GtkCheckMenuItem
*msgw
= GTK_CHECK_MENU_ITEM(
1928 ui_lookup_widget(main_widgets
.window
, "menu_show_messages_window1"));
1929 GtkCheckMenuItem
*toolbari
= GTK_CHECK_MENU_ITEM(
1930 ui_lookup_widget(main_widgets
.window
, "menu_show_toolbar1"));
1932 /* get the initial state (necessary if Geany was closed with hide_all = TRUE) */
1933 if (G_UNLIKELY(hide_all
== -1))
1935 if (! gtk_check_menu_item_get_active(msgw
) &&
1936 ! interface_prefs
.show_notebook_tabs
&&
1937 ! gtk_check_menu_item_get_active(toolbari
))
1945 hide_all
= ! hide_all
; /* toggle */
1949 if (gtk_check_menu_item_get_active(msgw
))
1950 gtk_check_menu_item_set_active(msgw
, ! gtk_check_menu_item_get_active(msgw
));
1952 interface_prefs
.show_notebook_tabs
= FALSE
;
1953 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets
.notebook
), interface_prefs
.show_notebook_tabs
);
1955 ui_statusbar_showhide(FALSE
);
1957 if (gtk_check_menu_item_get_active(toolbari
))
1958 gtk_check_menu_item_set_active(toolbari
, ! gtk_check_menu_item_get_active(toolbari
));
1963 if (! gtk_check_menu_item_get_active(msgw
))
1964 gtk_check_menu_item_set_active(msgw
, ! gtk_check_menu_item_get_active(msgw
));
1966 interface_prefs
.show_notebook_tabs
= TRUE
;
1967 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets
.notebook
), interface_prefs
.show_notebook_tabs
);
1969 ui_statusbar_showhide(TRUE
);
1971 if (! gtk_check_menu_item_get_active(toolbari
))
1972 gtk_check_menu_item_set_active(toolbari
, ! gtk_check_menu_item_get_active(toolbari
));
1978 on_forward_activate (GtkMenuItem
*menuitem
,
1981 navqueue_go_forward();
1986 on_back_activate (GtkMenuItem
*menuitem
,
1993 gboolean
on_motion_event(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
)
1995 if (prefs
.auto_focus
&& ! GTK_WIDGET_HAS_FOCUS(widget
))
1996 gtk_widget_grab_focus(widget
);
2002 static void set_indent_type(GtkCheckMenuItem
*menuitem
, GeanyIndentType type
)
2006 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
2009 doc
= document_get_current();
2010 g_return_if_fail(doc
!= NULL
);
2012 editor_set_indent(doc
->editor
, type
, doc
->editor
->indent_width
);
2013 ui_update_statusbar(doc
, -1);
2018 on_tabs1_activate (GtkCheckMenuItem
*menuitem
,
2021 set_indent_type(menuitem
, GEANY_INDENT_TYPE_TABS
);
2026 on_spaces1_activate (GtkCheckMenuItem
*menuitem
,
2029 set_indent_type(menuitem
, GEANY_INDENT_TYPE_SPACES
);
2034 on_tabs_and_spaces1_activate (GtkCheckMenuItem
*menuitem
,
2037 set_indent_type(menuitem
, GEANY_INDENT_TYPE_BOTH
);
2042 on_strip_trailing_spaces1_activate (GtkMenuItem
*menuitem
,
2047 if (ignore_callback
)
2050 doc
= document_get_current();
2051 g_return_if_fail(doc
!= NULL
);
2053 editor_strip_trailing_spaces(doc
->editor
);
2058 on_page_setup1_activate (GtkMenuItem
*menuitem
,
2061 #if GTK_CHECK_VERSION(2, 10, 0)
2062 printing_page_setup_gtk();
2068 on_escape_key_press_event (GtkWidget
*widget
,
2072 guint state
= event
->state
& gtk_accelerator_get_default_mod_mask();
2074 /* make pressing escape in the sidebar and toolbar focus the editor */
2075 if (event
->keyval
== GDK_Escape
&& state
== 0)
2077 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
2085 on_line_breaking1_activate (GtkMenuItem
*menuitem
,
2090 if (ignore_callback
)
2093 doc
= document_get_current();
2094 g_return_if_fail(doc
!= NULL
);
2096 doc
->editor
->line_breaking
= !doc
->editor
->line_breaking
;
2101 on_replace_spaces_activate (GtkMenuItem
*menuitem
,
2104 GeanyDocument
*doc
= document_get_current();
2106 g_return_if_fail(doc
!= NULL
);
2108 editor_replace_spaces(doc
->editor
);
2113 on_search1_activate (GtkMenuItem
*menuitem
,
2116 GtkWidget
*next_message
= ui_lookup_widget(main_widgets
.window
, "next_message1");
2117 GtkWidget
*previous_message
= ui_lookup_widget(main_widgets
.window
, "previous_message1");
2118 gboolean have_messages
;
2120 /* enable commands if the messages window has any items */
2121 have_messages
= gtk_tree_model_iter_n_children(GTK_TREE_MODEL(msgwindow
.store_msg
),
2124 gtk_widget_set_sensitive(next_message
, have_messages
);
2125 gtk_widget_set_sensitive(previous_message
, have_messages
);
2129 /* simple implementation (vs. close all which doesn't close documents if cancelled) */
2131 on_close_other_documents1_activate (GtkMenuItem
*menuitem
,
2135 GeanyDocument
*doc
, *cur_doc
= document_get_current();
2137 for (i
= 0; i
< documents_array
->len
; i
++)
2141 if (doc
== cur_doc
|| ! doc
->is_valid
)
2144 if (! document_close(doc
))
2151 on_menu_reload_configuration1_activate (GtkMenuItem
*menuitem
,
2154 main_reload_configuration();
2159 on_debug_messages1_activate (GtkMenuItem
*menuitem
,
2162 log_show_debug_messages_dialog();
2167 on_send_selection_to_vte1_activate (GtkMenuItem
*menuitem
,
2171 if (vte_info
.load_vte
)
2172 vte_send_selection_to_vte();
2177 gboolean
on_window_state_event (GtkWidget
*widget
,
2178 GdkEventWindowState
*event
,
2182 if (event
->changed_mask
& GDK_WINDOW_STATE_FULLSCREEN
)
2184 static GtkWidget
*menuitem
= NULL
;
2186 if (menuitem
== NULL
)
2187 menuitem
= ui_lookup_widget(widget
, "menu_fullscreen1");
2189 ignore_callback
= TRUE
;
2191 ui_prefs
.fullscreen
= (event
->new_window_state
& GDK_WINDOW_STATE_FULLSCREEN
) ? TRUE
: FALSE
;
2192 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem
), ui_prefs
.fullscreen
);
2194 ignore_callback
= FALSE
;
2201 on_customize_toolbar1_activate (GtkMenuItem
*menuitem
,
2205 GtkNotebook
*notebook
;
2207 prefs_show_dialog();
2209 /* select the KB page */
2210 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "vbox15");
2211 notebook
= GTK_NOTEBOOK(ui_lookup_widget(ui_widgets
.prefs_dialog
, "notebook2"));
2213 if (notebook
!= NULL
&& widget
!= NULL
)
2214 gtk_notebook_set_current_page(notebook
, gtk_notebook_page_num(notebook
, widget
));
2219 on_button_customize_toolbar_clicked (GtkButton
*button
,
2222 toolbar_configure(GTK_WINDOW(ui_widgets
.prefs_dialog
));
2227 on_cut_current_line_s_1_activate (GtkMenuItem
*menuitem
,
2230 keybindings_send_command(GEANY_KEY_GROUP_CLIPBOARD
, GEANY_KEYS_CLIPBOARD_CUTLINE
);
2235 on_copy_current_line_s_1_activate (GtkMenuItem
*menuitem
,
2238 keybindings_send_command(GEANY_KEY_GROUP_CLIPBOARD
, GEANY_KEYS_CLIPBOARD_COPYLINE
);
2243 on_delete_current_line_s_1_activate (GtkMenuItem
*menuitem
,
2246 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_DELETELINE
);
2251 on_duplicate_line_or_selection1_activate
2252 (GtkMenuItem
*menuitem
,
2255 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_DUPLICATELINE
);
2260 on_select_current_line_s_1_activate (GtkMenuItem
*menuitem
,
2263 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_LINE
);
2268 on_select_current_paragraph1_activate (GtkMenuItem
*menuitem
,
2271 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_PARAGRAPH
);
2276 on_insert_alternative_white_space1_activate
2277 (GtkMenuItem
*menuitem
,
2280 keybindings_send_command(GEANY_KEY_GROUP_INSERT
, GEANY_KEYS_INSERT_ALTWHITESPACE
);
2285 on_go_to_next_marker1_activate (GtkMenuItem
*menuitem
,
2288 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_NEXTMARKER
);
2293 on_go_to_previous_marker1_activate (GtkMenuItem
*menuitem
,
2296 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_PREVIOUSMARKER
);
2301 on_reflow_lines_block1_activate (GtkMenuItem
*menuitem
,
2304 keybindings_send_command(GEANY_KEY_GROUP_FORMAT
, GEANY_KEYS_FORMAT_REFLOWPARAGRAPH
);
2309 on_transpose_current_line1_activate (GtkMenuItem
*menuitem
,
2312 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_TRANSPOSELINE
);
2317 on_smart_line_indent1_activate (GtkMenuItem
*menuitem
,
2320 keybindings_send_command(GEANY_KEY_GROUP_FORMAT
, GEANY_KEYS_FORMAT_AUTOINDENT
);
2325 on_plugin_preferences1_activate (GtkMenuItem
*menuitem
,
2329 plugin_show_configure(NULL
);
2334 static void set_indent_width(guint width
)
2338 if (ignore_callback
)
2341 doc
= document_get_current();
2342 g_return_if_fail(doc
!= NULL
);
2344 editor_set_indent(doc
->editor
, doc
->editor
->indent_type
, width
);
2349 on_indent_width_activate (GtkMenuItem
*menuitem
,
2352 gchar
*label
= ui_menu_item_get_text(menuitem
);
2353 gint width
= atoi(label
);
2357 set_indent_width(width
);
2362 on_reset_indentation1_activate (GtkMenuItem
*menuitem
,
2368 document_apply_indent_settings(documents
[i
]);
2370 ui_update_statusbar(NULL
, -1);
2371 ui_document_show_hide(NULL
);
2376 on_mark_all1_activate (GtkMenuItem
*menuitem
,
2379 keybindings_send_command(GEANY_KEY_GROUP_SEARCH
, GEANY_KEYS_SEARCH_MARKALL
);