2 * callbacks.c - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2005-2012 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5 * Copyright 2006-2012 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 * Callbacks used by Glade. These are mainly in response to menu item and button events in the
24 * main window. Callbacks not used by Glade should go elsewhere.
31 #include "callbacks.h"
37 #include "documentprivate.h"
38 #include "encodings.h"
39 #include "filetypes.h"
40 #include "geanyobject.h"
41 #include "highlighting.h"
42 #include "keybindings.h"
46 #include "msgwindow.h"
49 #include "pluginutils.h"
52 #include "sciwrappers.h"
60 #include "templates.h"
67 #include "gtkcompat.h"
72 #include <gdk/gdkkeysyms.h>
73 #include <glib/gstdio.h>
77 /* represents the state at switching a notebook page(in the left treeviews widget), to not emit
78 * the selection-changed signal from tv.tree_openfiles */
79 /*static gboolean switch_tv_notebook_page = FALSE; */
83 /* wrapper function to abort exit process if cancel button is pressed */
84 static gboolean
on_window_delete_event(GtkWidget
*widget
, GdkEvent
*event
, gpointer gdata
)
94 void on_new1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
96 document_new_file(NULL
, NULL
, NULL
);
100 /* create a new file and copy file content and properties */
101 static void on_clone1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
103 GeanyDocument
*old_doc
= document_get_current();
106 document_clone(old_doc
);
110 void on_save1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
112 GeanyDocument
*doc
= document_get_current();
116 document_save_file(doc
, ui_prefs
.allow_always_save
);
121 void on_save_as1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
123 dialogs_show_save_as();
127 void on_save_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
129 guint i
, max
= (guint
) gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets
.notebook
));
130 GeanyDocument
*doc
, *cur_doc
= document_get_current();
133 /* iterate over documents in tabs order */
134 for (i
= 0; i
< max
; i
++)
136 doc
= document_get_from_page(i
);
140 if (document_save_file(doc
, FALSE
))
146 ui_set_statusbar(FALSE
, ngettext("%d file saved.", "%d files saved.", count
), count
);
147 /* saving may have changed window title, sidebar for another doc, so update */
148 document_show_tab(cur_doc
);
149 sidebar_update_tag_list(cur_doc
, TRUE
);
150 ui_set_window_title(cur_doc
);
154 void on_close_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
156 document_close_all();
160 void on_close1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
162 GeanyDocument
*doc
= document_get_current();
169 void on_quit1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
175 static void on_file1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
177 gtk_widget_set_sensitive(ui_widgets
.recent_files_menuitem
,
178 g_queue_get_length(ui_prefs
.recent_queue
) > 0);
179 /* hide Page setup when GTK printing is not used */
180 ui_widget_show_hide(ui_widgets
.print_page_setup
, printing_prefs
.use_gtk_printing
);
184 /* edit actions, c&p & co, from menu bar and from popup menu */
185 static void on_edit1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
188 GeanyDocument
*doc
= document_get_current();
190 ui_update_menu_copy_items(doc
);
191 ui_update_insert_include_item(doc
, 1);
193 item
= ui_lookup_widget(main_widgets
.window
, "plugin_preferences1");
195 gtk_widget_hide(item
);
197 gtk_widget_set_sensitive(item
, plugins_have_preferences());
202 void on_undo1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
204 GeanyDocument
*doc
= document_get_current();
206 g_return_if_fail(doc
!= NULL
);
208 if (document_can_undo(doc
))
210 sci_cancel(doc
->editor
->sci
);
216 void on_redo1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
218 GeanyDocument
*doc
= document_get_current();
220 g_return_if_fail(doc
!= NULL
);
222 if (document_can_redo(doc
))
224 sci_cancel(doc
->editor
->sci
);
230 void on_cut1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
232 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
234 if (GTK_IS_EDITABLE(focusw
))
235 gtk_editable_cut_clipboard(GTK_EDITABLE(focusw
));
236 else if (IS_SCINTILLA(focusw
))
237 sci_cut(SCINTILLA(focusw
));
238 else if (GTK_IS_TEXT_VIEW(focusw
))
240 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(
241 GTK_TEXT_VIEW(focusw
));
242 gtk_text_buffer_cut_clipboard(buffer
, gtk_clipboard_get(GDK_NONE
), TRUE
);
247 void on_copy1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
249 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
251 if (GTK_IS_EDITABLE(focusw
))
252 gtk_editable_copy_clipboard(GTK_EDITABLE(focusw
));
253 else if (IS_SCINTILLA(focusw
))
254 sci_copy(SCINTILLA(focusw
));
255 else if (GTK_IS_TEXT_VIEW(focusw
))
257 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(
258 GTK_TEXT_VIEW(focusw
));
259 gtk_text_buffer_copy_clipboard(buffer
, gtk_clipboard_get(GDK_NONE
));
264 void on_paste1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
266 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
268 if (GTK_IS_EDITABLE(focusw
))
269 gtk_editable_paste_clipboard(GTK_EDITABLE(focusw
));
270 else if (IS_SCINTILLA(focusw
))
271 sci_paste(SCINTILLA(focusw
));
272 else if (GTK_IS_TEXT_VIEW(focusw
))
274 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(
275 GTK_TEXT_VIEW(focusw
));
276 gtk_text_buffer_paste_clipboard(buffer
, gtk_clipboard_get(GDK_NONE
), NULL
,
282 void on_delete1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
284 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
286 if (GTK_IS_EDITABLE(focusw
))
287 gtk_editable_delete_selection(GTK_EDITABLE(focusw
));
288 else if (IS_SCINTILLA(focusw
) && sci_has_selection(SCINTILLA(focusw
)))
289 sci_clear(SCINTILLA(focusw
));
290 else if (GTK_IS_TEXT_VIEW(focusw
))
292 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(
293 GTK_TEXT_VIEW(focusw
));
294 gtk_text_buffer_delete_selection(buffer
, TRUE
, TRUE
);
299 void on_preferences1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
305 /* about menu item */
306 static void on_info1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
313 void on_open1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
315 dialogs_show_open_file();
320 void on_toolbutton_reload_clicked(GtkAction
*action
, gpointer user_data
)
322 GeanyDocument
*doc
= document_get_current();
324 g_return_if_fail(doc
!= NULL
);
326 document_reload_prompt(doc
, NULL
);
330 static void on_change_font1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
332 dialogs_show_open_font();
336 /* store text, clear search flags so we can use Search->Find Next/Previous */
337 static void setup_find(const gchar
*text
, gboolean backwards
)
339 SETPTR(search_data
.text
, g_strdup(text
));
340 SETPTR(search_data
.original_text
, g_strdup(text
));
341 search_data
.flags
= 0;
342 search_data
.backwards
= backwards
;
343 search_data
.search_bar
= TRUE
;
347 static void do_toolbar_search(const gchar
*text
, gboolean incremental
, gboolean backwards
)
349 GeanyDocument
*doc
= document_get_current();
352 setup_find(text
, backwards
);
353 result
= document_search_bar_find(doc
, search_data
.text
, incremental
, backwards
);
354 if (search_data
.search_bar
)
355 ui_set_search_entry_background(toolbar_get_widget_child_by_name("SearchEntry"), result
);
360 void on_toolbar_search_entry_changed(GtkAction
*action
, const gchar
*text
, gpointer user_data
)
362 do_toolbar_search(text
, TRUE
, FALSE
);
367 void on_toolbar_search_entry_activate(GtkAction
*action
, const gchar
*text
, gpointer user_data
)
369 do_toolbar_search(text
, FALSE
, GPOINTER_TO_INT(user_data
));
374 void on_toolbutton_search_clicked(GtkAction
*action
, gpointer user_data
)
376 GeanyDocument
*doc
= document_get_current();
378 GtkWidget
*entry
= toolbar_get_widget_child_by_name("SearchEntry");
382 const gchar
*text
= gtk_entry_get_text(GTK_ENTRY(entry
));
384 setup_find(text
, FALSE
);
385 result
= document_search_bar_find(doc
, search_data
.text
, FALSE
, FALSE
);
386 if (search_data
.search_bar
)
387 ui_set_search_entry_background(entry
, result
);
390 on_find1_activate(NULL
, NULL
);
394 /* hides toolbar from toolbar popup menu */
395 static void on_hide_toolbar1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
397 GtkWidget
*tool_item
= ui_lookup_widget(GTK_WIDGET(main_widgets
.window
), "menu_show_toolbar1");
398 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(tool_item
), FALSE
);
402 /* zoom in from menu bar and popup menu */
403 void on_zoom_in1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
405 GeanyDocument
*doc
= document_get_current();
407 g_return_if_fail(doc
!= NULL
);
409 sci_zoom_in(doc
->editor
->sci
);
413 /* zoom out from menu bar and popup menu */
414 void on_zoom_out1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
416 GeanyDocument
*doc
= document_get_current();
418 g_return_if_fail(doc
!= NULL
);
420 sci_zoom_out(doc
->editor
->sci
);
424 void on_normal_size1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
426 GeanyDocument
*doc
= document_get_current();
428 g_return_if_fail(doc
!= NULL
);
430 sci_zoom_off(doc
->editor
->sci
);
434 static gboolean
delayed_check_disk_status(gpointer data
)
436 document_check_disk_status(data
, FALSE
);
441 /* Changes window-title after switching tabs and lots of other things.
442 * note: using 'after' makes Scintilla redraw before the UI, appearing more responsive */
443 static void on_notebook1_switch_page_after(GtkNotebook
*notebook
, gpointer page
,
444 guint page_num
, gpointer user_data
)
448 if (G_UNLIKELY(main_status
.opening_session_files
|| main_status
.closing_all
))
451 doc
= document_get_from_notebook_child(page
);
455 sidebar_select_openfiles_item(doc
);
456 ui_save_buttons_toggle(doc
->changed
);
457 ui_set_window_title(doc
);
458 ui_update_statusbar(doc
, -1);
459 ui_update_popup_reundo_items(doc
);
460 ui_document_show_hide(doc
); /* update the document menu */
461 build_menu_update(doc
);
462 sidebar_update_tag_list(doc
, FALSE
);
463 document_highlight_tags(doc
);
465 /* We delay the check to avoid weird fast, unintended switching of notebook pages when
466 * the 'file has changed' dialog is shown while the switch event is not yet completely
467 * finished. So, we check after the switch has been performed to be safe. */
468 g_idle_add(delayed_check_disk_status
, doc
);
471 vte_cwd((doc
->real_path
!= NULL
) ? doc
->real_path
: doc
->file_name
, FALSE
);
474 g_signal_emit_by_name(geany_object
, "document-activate", doc
);
479 static void on_tv_notebook_switch_page(GtkNotebook
*notebook
, gpointer page
,
480 guint page_num
, gpointer user_data
)
482 /* suppress selection changed signal when switching to the open files list */
483 ignore_callback
= TRUE
;
487 static void on_tv_notebook_switch_page_after(GtkNotebook
*notebook
, gpointer page
,
488 guint page_num
, gpointer user_data
)
490 ignore_callback
= FALSE
;
494 static void convert_eol(gint mode
)
496 GeanyDocument
*doc
= document_get_current();
498 g_return_if_fail(doc
!= NULL
);
500 sci_convert_eols(doc
->editor
->sci
, mode
);
501 sci_set_eol_mode(doc
->editor
->sci
, mode
);
502 ui_update_statusbar(doc
, -1);
506 static void on_crlf_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
508 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
511 convert_eol(SC_EOL_CRLF
);
515 static void on_lf_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
517 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
520 convert_eol(SC_EOL_LF
);
524 static void on_cr_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
526 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
529 convert_eol(SC_EOL_CR
);
533 void on_replace_tabs_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
535 GeanyDocument
*doc
= document_get_current();
537 g_return_if_fail(doc
!= NULL
);
539 editor_replace_tabs(doc
->editor
, FALSE
);
543 gboolean
toolbar_popup_menu(GtkWidget
*widget
, GdkEventButton
*event
, gpointer user_data
)
545 if (event
->button
== 3)
547 gtk_menu_popup(GTK_MENU(ui_widgets
.toolbar_menu
), NULL
, NULL
, NULL
, NULL
, event
->button
, event
->time
);
554 void on_toggle_case1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
556 GeanyDocument
*doc
= document_get_current();
557 ScintillaObject
*sci
;
559 gboolean keep_sel
= TRUE
;
561 g_return_if_fail(doc
!= NULL
);
563 sci
= doc
->editor
->sci
;
564 if (! sci_has_selection(sci
))
566 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_WORD
);
570 /* either we already had a selection or we created one for current word */
571 if (sci_has_selection(sci
))
573 gchar
*result
= NULL
;
574 gint cmd
= SCI_LOWERCASE
;
575 gboolean rectsel
= (gboolean
) scintilla_send_message(sci
, SCI_SELECTIONISRECTANGLE
, 0, 0);
577 text
= sci_get_selection_contents(sci
);
579 if (utils_str_has_upper(text
))
584 result
= g_utf8_strdown(text
, -1);
591 result
= g_utf8_strup(text
, -1);
596 sci_replace_sel(sci
, result
);
599 sci_set_selection_start(sci
, sci_get_current_position(sci
) - strlen(text
));
602 sci_send_command(sci
, cmd
);
610 static void on_show_toolbar1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
612 if (ignore_callback
) return;
614 toolbar_prefs
.visible
= (toolbar_prefs
.visible
) ? FALSE
: TRUE
;;
615 ui_widget_show_hide(GTK_WIDGET(main_widgets
.toolbar
), toolbar_prefs
.visible
);
619 static void on_fullscreen1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
624 ui_prefs
.fullscreen
= (ui_prefs
.fullscreen
) ? FALSE
: TRUE
;
629 static void on_show_messages_window1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
634 ui_prefs
.msgwindow_visible
= (ui_prefs
.msgwindow_visible
) ? FALSE
: TRUE
;
635 msgwin_show_hide(ui_prefs
.msgwindow_visible
);
639 static void on_menu_color_schemes_activate(GtkImageMenuItem
*imagemenuitem
, gpointer user_data
)
641 highlighting_show_color_scheme_dialog();
645 static void on_markers_margin1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
650 editor_prefs
.show_markers_margin
= ! editor_prefs
.show_markers_margin
;
651 ui_toggle_editor_features(GEANY_EDITOR_SHOW_MARKERS_MARGIN
);
655 static void on_show_line_numbers1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
660 editor_prefs
.show_linenumber_margin
= ! editor_prefs
.show_linenumber_margin
;
661 ui_toggle_editor_features(GEANY_EDITOR_SHOW_LINE_NUMBERS
);
665 static void on_menu_show_white_space1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
670 editor_prefs
.show_white_space
= ! editor_prefs
.show_white_space
;
671 ui_toggle_editor_features(GEANY_EDITOR_SHOW_WHITE_SPACE
);
675 static void on_menu_show_line_endings1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
680 editor_prefs
.show_line_endings
= ! editor_prefs
.show_line_endings
;
681 ui_toggle_editor_features(GEANY_EDITOR_SHOW_LINE_ENDINGS
);
685 static void on_menu_show_indentation_guides1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
690 editor_prefs
.show_indent_guide
= ! editor_prefs
.show_indent_guide
;
691 ui_toggle_editor_features(GEANY_EDITOR_SHOW_INDENTATION_GUIDES
);
695 void on_line_wrapping1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
697 if (! ignore_callback
)
699 GeanyDocument
*doc
= document_get_current();
700 g_return_if_fail(doc
!= NULL
);
702 editor_set_line_wrapping(doc
->editor
, ! doc
->editor
->line_wrapping
);
707 static void on_set_file_readonly1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
709 if (! ignore_callback
)
711 GeanyDocument
*doc
= document_get_current();
712 g_return_if_fail(doc
!= NULL
);
714 doc
->readonly
= ! doc
->readonly
;
715 sci_set_readonly(doc
->editor
->sci
, doc
->readonly
);
716 ui_update_tab_status(doc
);
717 ui_update_statusbar(doc
, -1);
722 static void on_use_auto_indentation1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
724 if (! ignore_callback
)
726 GeanyDocument
*doc
= document_get_current();
727 g_return_if_fail(doc
!= NULL
);
729 doc
->editor
->auto_indent
= ! doc
->editor
->auto_indent
;
734 static void find_usage(gboolean in_session
)
736 GeanyFindFlags flags
;
738 GeanyDocument
*doc
= document_get_current();
740 g_return_if_fail(doc
!= NULL
);
742 if (sci_has_selection(doc
->editor
->sci
))
743 { /* take selected text if there is a selection */
744 search_text
= sci_get_selection_contents(doc
->editor
->sci
);
745 flags
= GEANY_FIND_MATCHCASE
;
749 editor_find_current_word_sciwc(doc
->editor
, -1,
750 editor_info
.current_word
, GEANY_MAX_WORD_LENGTH
);
751 search_text
= g_strdup(editor_info
.current_word
);
752 flags
= GEANY_FIND_MATCHCASE
| GEANY_FIND_WHOLEWORD
;
755 search_find_usage(search_text
, search_text
, flags
, in_session
);
760 void on_find_document_usage1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
766 void on_find_usage1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
772 static void goto_tag(gboolean definition
)
774 GeanyDocument
*doc
= document_get_current();
776 g_return_if_fail(doc
!= NULL
);
778 /* update cursor pos for navigating back afterwards */
779 if (!sci_has_selection(doc
->editor
->sci
))
780 sci_set_current_position(doc
->editor
->sci
, editor_info
.click_pos
, FALSE
);
782 /* use the keybinding callback as it checks for selections as well as current word */
784 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_TAGDEFINITION
);
786 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_TAGDECLARATION
);
790 static void on_goto_tag_definition1(GtkMenuItem
*menuitem
, gpointer user_data
)
796 static void on_goto_tag_declaration1(GtkMenuItem
*menuitem
, gpointer user_data
)
802 static void on_count_words1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
808 void on_show_color_chooser1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
811 GeanyDocument
*doc
= document_get_current();
814 g_return_if_fail(doc
!= NULL
);
816 pos
= sci_get_current_position(doc
->editor
->sci
);
817 editor_find_current_word(doc
->editor
, pos
, colour
, sizeof colour
, GEANY_WORDCHARS
"#");
818 tools_color_chooser(colour
);
822 void on_toolbutton_compile_clicked(GtkAction
*action
, gpointer user_data
)
824 keybindings_send_command(GEANY_KEY_GROUP_BUILD
, GEANY_KEYS_BUILD_COMPILE
);
828 void on_find1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
830 search_show_find_dialog();
834 void on_find_next1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
836 search_find_again(FALSE
);
840 void on_find_previous1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
842 if (search_data
.flags
& GEANY_FIND_REGEXP
)
843 /* Can't reverse search order for a regex (find next ignores search backwards) */
846 search_find_again(TRUE
);
850 void on_find_nextsel1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
852 search_find_selection(document_get_current(), FALSE
);
856 void on_find_prevsel1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
858 search_find_selection(document_get_current(), TRUE
);
862 void on_replace1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
864 search_show_replace_dialog();
868 void on_find_in_files1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
870 search_show_find_in_files_dialog(NULL
);
874 static void get_line_and_offset_from_text(const gchar
*text
, gint
*line_no
, gint
*offset
)
876 if (*text
== '+' || *text
== '-')
878 *line_no
= atoi(text
+ 1);
879 *offset
= (*text
== '+') ? 1 : -1;
883 *line_no
= atoi(text
) - 1;
889 void on_go_to_line_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
891 static gchar value
[16] = "";
894 result
= dialogs_show_input_goto_line(
895 _("Go to Line"), GTK_WINDOW(main_widgets
.window
),
896 _("Enter the line you want to go to:"), value
);
899 GeanyDocument
*doc
= document_get_current();
903 g_return_if_fail(doc
!= NULL
);
905 get_line_and_offset_from_text(result
, &line_no
, &offset
);
906 if (! editor_goto_line(doc
->editor
, line_no
, offset
))
908 /* remember value for future calls */
909 g_snprintf(value
, sizeof(value
), "%s", result
);
916 void on_toolbutton_goto_entry_activate(GtkAction
*action
, const gchar
*text
, gpointer user_data
)
918 GeanyDocument
*doc
= document_get_current();
922 g_return_if_fail(doc
!= NULL
);
924 get_line_and_offset_from_text(text
, &line_no
, &offset
);
925 if (! editor_goto_line(doc
->editor
, line_no
, offset
))
928 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
932 void on_toolbutton_goto_clicked(GtkAction
*action
, gpointer user_data
)
934 GtkWidget
*entry
= toolbar_get_widget_child_by_name("GotoEntry");
938 const gchar
*text
= gtk_entry_get_text(GTK_ENTRY(entry
));
940 on_toolbutton_goto_entry_activate(NULL
, text
, NULL
);
943 on_go_to_line_activate(NULL
, NULL
);
947 void on_help1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
951 uri
= utils_get_help_url(NULL
);
952 utils_open_browser(uri
);
957 static void on_help_shortcuts1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
959 keybindings_show_shortcuts();
963 static void on_website1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
965 utils_open_browser(GEANY_HOMEPAGE
);
969 static void on_help_menu_item_donate_activate(GtkMenuItem
*item
, gpointer user_data
)
971 utils_open_browser(GEANY_DONATE
);
975 static void on_help_menu_item_wiki_activate(GtkMenuItem
*item
, gpointer user_data
)
977 utils_open_browser(GEANY_WIKI
);
981 static void on_help_menu_item_bug_report_activate(GtkMenuItem
*item
, gpointer user_data
)
983 utils_open_browser(GEANY_BUG_REPORT
);
987 static void on_comments_function_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
989 GeanyDocument
*doc
= document_get_current();
991 const gchar
*cur_tag
= NULL
;
992 gint line
= -1, pos
= 0;
994 if (doc
== NULL
|| doc
->file_type
== NULL
)
996 ui_set_statusbar(FALSE
,
997 _("Please set the filetype for the current file before using this function."));
1001 /* symbols_get_current_function returns -1 on failure, so sci_get_position_from_line
1002 * returns the current position, so it should be safe */
1003 line
= symbols_get_current_function(doc
, &cur_tag
);
1004 pos
= sci_get_position_from_line(doc
->editor
->sci
, line
);
1006 text
= templates_get_template_function(doc
, cur_tag
);
1008 sci_start_undo_action(doc
->editor
->sci
);
1009 sci_insert_text(doc
->editor
->sci
, pos
, text
);
1010 sci_end_undo_action(doc
->editor
->sci
);
1015 static void insert_multiline_comment(GeanyDocument
*doc
, gint pos
)
1017 g_return_if_fail(doc
!= NULL
);
1018 g_return_if_fail(pos
== -1 || pos
>= 0);
1020 if (doc
->file_type
== NULL
)
1022 ui_set_statusbar(FALSE
,
1023 _("Please set the filetype for the current file before using this function."));
1027 if (doc
->file_type
->comment_open
|| doc
->file_type
->comment_single
)
1029 /* editor_insert_multiline_comment() uses editor_info.click_pos */
1031 editor_info
.click_pos
= sci_get_current_position(doc
->editor
->sci
);
1033 editor_info
.click_pos
= pos
;
1034 editor_insert_multiline_comment(doc
->editor
);
1041 static void on_comments_multiline_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1043 insert_multiline_comment(document_get_current(), editor_info
.click_pos
);
1047 static void on_menu_comments_multiline_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1049 insert_multiline_comment(document_get_current(), -1);
1053 static void insert_comment_template(GeanyDocument
*doc
, gint pos
, guint
template)
1057 g_return_if_fail(doc
!= NULL
);
1058 g_return_if_fail(pos
== -1 || pos
>= 0);
1059 g_return_if_fail(template < GEANY_MAX_TEMPLATES
);
1062 pos
= sci_get_current_position(doc
->editor
->sci
);
1064 text
= templates_get_template_licence(doc
, template);
1066 sci_start_undo_action(doc
->editor
->sci
);
1067 sci_insert_text(doc
->editor
->sci
, pos
, text
);
1068 sci_end_undo_action(doc
->editor
->sci
);
1073 static void on_comments_gpl_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1075 insert_comment_template(document_get_current(), editor_info
.click_pos
, GEANY_TEMPLATE_GPL
);
1079 static void on_menu_comments_gpl_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1081 insert_comment_template(document_get_current(), -1, GEANY_TEMPLATE_GPL
);
1085 static void on_comments_bsd_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1087 insert_comment_template(document_get_current(), editor_info
.click_pos
, GEANY_TEMPLATE_BSD
);
1091 static void on_menu_comments_bsd_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1093 insert_comment_template(document_get_current(), -1, GEANY_TEMPLATE_BSD
);
1097 static void on_comments_changelog_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1099 GeanyDocument
*doc
= document_get_current();
1102 g_return_if_fail(doc
!= NULL
);
1104 text
= templates_get_template_changelog(doc
);
1105 sci_start_undo_action(doc
->editor
->sci
);
1106 sci_insert_text(doc
->editor
->sci
, 0, text
);
1107 /* sets the cursor to the right position to type the changelog text,
1108 * the template has 21 chars + length of name and email */
1109 sci_goto_pos(doc
->editor
->sci
, 21 + strlen(template_prefs
.developer
) + strlen(template_prefs
.mail
), TRUE
);
1110 sci_end_undo_action(doc
->editor
->sci
);
1116 static void on_comments_fileheader_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1118 GeanyDocument
*doc
= document_get_current();
1123 g_return_if_fail(doc
!= NULL
);
1125 ft
= doc
->file_type
;
1126 fname
= doc
->file_name
;
1127 text
= templates_get_template_fileheader(FILETYPE_ID(ft
), fname
);
1129 sci_start_undo_action(doc
->editor
->sci
);
1130 sci_insert_text(doc
->editor
->sci
, 0, text
);
1131 sci_goto_pos(doc
->editor
->sci
, 0, FALSE
);
1132 sci_end_undo_action(doc
->editor
->sci
);
1137 static void on_file_properties_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1139 GeanyDocument
*doc
= document_get_current();
1140 g_return_if_fail(doc
!= NULL
);
1142 dialogs_show_file_properties(doc
);
1146 static void on_menu_fold_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1148 GeanyDocument
*doc
= document_get_current();
1149 g_return_if_fail(doc
!= NULL
);
1151 editor_fold_all(doc
->editor
);
1155 static void on_menu_unfold_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1157 GeanyDocument
*doc
= document_get_current();
1158 g_return_if_fail(doc
!= NULL
);
1160 editor_unfold_all(doc
->editor
);
1164 void on_toolbutton_run_clicked(GtkAction
*action
, gpointer user_data
)
1166 keybindings_send_command(GEANY_KEY_GROUP_BUILD
, GEANY_KEYS_BUILD_RUN
);
1170 void on_menu_remove_indicators1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1172 GeanyDocument
*doc
= document_get_current();
1173 g_return_if_fail(doc
!= NULL
);
1175 editor_indicator_clear(doc
->editor
, GEANY_INDICATOR_ERROR
);
1179 void on_print1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1181 GeanyDocument
*doc
= document_get_current();
1182 g_return_if_fail(doc
!= NULL
);
1184 printing_print_doc(doc
);
1188 void on_menu_select_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1190 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
1192 /* special case for Select All in the scribble widget */
1193 if (GTK_IS_TEXT_VIEW(focusw
))
1195 g_signal_emit_by_name(focusw
, "select-all", TRUE
);
1197 /* special case for Select All in the VTE widget */
1199 else if (vte_info
.have_vte
&& focusw
== vc
->vte
)
1204 else if (GTK_IS_EDITABLE(focusw
))
1206 gtk_editable_select_region(GTK_EDITABLE(focusw
), 0, -1);
1208 else if (IS_SCINTILLA(focusw
))
1210 sci_select_all(SCINTILLA(focusw
));
1215 void on_menu_show_sidebar1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
1217 if (ignore_callback
)
1220 ui_prefs
.sidebar_visible
= ! ui_prefs
.sidebar_visible
;
1222 /* show built-in tabs if no tabs visible */
1223 if (ui_prefs
.sidebar_visible
&&
1224 ! interface_prefs
.sidebar_openfiles_visible
&& ! interface_prefs
.sidebar_symbol_visible
&&
1225 gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets
.sidebar_notebook
)) <= 2)
1227 interface_prefs
.sidebar_openfiles_visible
= TRUE
;
1228 interface_prefs
.sidebar_symbol_visible
= TRUE
;
1231 /* if window has input focus, set it back to the editor before toggling off */
1232 if (! ui_prefs
.sidebar_visible
&&
1233 gtk_container_get_focus_child(GTK_CONTAINER(main_widgets
.sidebar_notebook
)) != NULL
)
1235 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
1238 ui_sidebar_show_hide();
1242 static void on_menu_write_unicode_bom1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
1244 if (! ignore_callback
)
1246 GeanyDocument
*doc
= document_get_current();
1248 g_return_if_fail(doc
!= NULL
);
1255 document_undo_add(doc
, UNDO_BOM
, GINT_TO_POINTER(doc
->has_bom
));
1257 doc
->has_bom
= ! doc
->has_bom
;
1259 ui_update_statusbar(doc
, -1);
1264 void on_menu_comment_line1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1266 GeanyDocument
*doc
= document_get_current();
1267 g_return_if_fail(doc
!= NULL
);
1269 editor_do_comment(doc
->editor
, -1, FALSE
, FALSE
, TRUE
);
1273 void on_menu_uncomment_line1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1275 GeanyDocument
*doc
= document_get_current();
1276 g_return_if_fail(doc
!= NULL
);
1278 editor_do_uncomment(doc
->editor
, -1, FALSE
);
1282 void on_menu_toggle_line_commentation1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1284 GeanyDocument
*doc
= document_get_current();
1285 g_return_if_fail(doc
!= NULL
);
1287 editor_do_comment_toggle(doc
->editor
);
1291 void on_menu_increase_indent1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1293 GeanyDocument
*doc
= document_get_current();
1294 g_return_if_fail(doc
!= NULL
);
1296 editor_indent(doc
->editor
, TRUE
);
1300 void on_menu_decrease_indent1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1302 GeanyDocument
*doc
= document_get_current();
1303 g_return_if_fail(doc
!= NULL
);
1305 editor_indent(doc
->editor
, FALSE
);
1309 void on_next_message1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1311 if (! ui_tree_view_find_next(GTK_TREE_VIEW(msgwindow
.tree_msg
),
1312 msgwin_goto_messages_file_line
))
1313 ui_set_statusbar(FALSE
, _("No more message items."));
1317 void on_previous_message1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1319 if (! ui_tree_view_find_previous(GTK_TREE_VIEW(msgwindow
.tree_msg
),
1320 msgwin_goto_messages_file_line
))
1321 ui_set_statusbar(FALSE
, _("No more message items."));
1325 void on_project_new1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1331 void on_project_open1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1337 void on_project_close1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1339 project_close(TRUE
);
1343 void on_project_properties1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1345 project_properties();
1349 static void on_menu_project1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1351 static GtkWidget
*item_close
= NULL
;
1352 static GtkWidget
*item_properties
= NULL
;
1354 if (item_close
== NULL
)
1356 item_close
= ui_lookup_widget(main_widgets
.window
, "project_close1");
1357 item_properties
= ui_lookup_widget(main_widgets
.window
, "project_properties1");
1360 gtk_widget_set_sensitive(item_close
, (app
->project
!= NULL
));
1361 gtk_widget_set_sensitive(item_properties
, (app
->project
!= NULL
));
1362 gtk_widget_set_sensitive(ui_widgets
.recent_projects_menuitem
,
1363 g_queue_get_length(ui_prefs
.recent_projects_queue
) > 0);
1367 void on_menu_open_selected_file1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1369 GeanyDocument
*doc
= document_get_current();
1374 wc
= GEANY_WORDCHARS
"./-" "\\";
1376 wc
= GEANY_WORDCHARS
"./-";
1379 g_return_if_fail(doc
!= NULL
);
1381 sel
= editor_get_default_selection(doc
->editor
, TRUE
, wc
);
1382 SETPTR(sel
, utils_get_locale_from_utf8(sel
));
1386 gchar
*filename
= NULL
;
1388 if (g_path_is_absolute(sel
))
1389 filename
= g_strdup(sel
);
1391 { /* relative filename, add the path of the current file */
1394 path
= utils_get_current_file_dir_utf8();
1395 SETPTR(path
, utils_get_locale_from_utf8(path
));
1397 path
= g_get_current_dir();
1399 filename
= g_build_path(G_DIR_SEPARATOR_S
, path
, sel
, NULL
);
1401 if (! g_file_test(filename
, G_FILE_TEST_EXISTS
) &&
1402 app
->project
!= NULL
&& !EMPTY(app
->project
->base_path
))
1404 /* try the project's base path */
1405 SETPTR(path
, project_get_base_path());
1406 SETPTR(path
, utils_get_locale_from_utf8(path
));
1407 SETPTR(filename
, g_build_path(G_DIR_SEPARATOR_S
, path
, sel
, NULL
));
1411 if (! g_file_test(filename
, G_FILE_TEST_EXISTS
))
1412 SETPTR(filename
, g_build_path(G_DIR_SEPARATOR_S
, "/usr/local/include", sel
, NULL
));
1414 if (! g_file_test(filename
, G_FILE_TEST_EXISTS
))
1415 SETPTR(filename
, g_build_path(G_DIR_SEPARATOR_S
, "/usr/include", sel
, NULL
));
1419 if (g_file_test(filename
, G_FILE_TEST_EXISTS
))
1420 document_open_file(filename
, FALSE
, NULL
, NULL
);
1423 SETPTR(sel
, utils_get_utf8_from_locale(sel
));
1424 ui_set_statusbar(TRUE
, _("Could not open file %s (File not found)"), sel
);
1433 void on_remove_markers1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1435 GeanyDocument
*doc
= document_get_current();
1436 g_return_if_fail(doc
!= NULL
);
1438 sci_marker_delete_all(doc
->editor
->sci
, 0); /* delete the yellow tag marker */
1439 sci_marker_delete_all(doc
->editor
->sci
, 1); /* delete user markers */
1440 editor_indicator_clear(doc
->editor
, GEANY_INDICATOR_SEARCH
);
1444 static void on_load_tags1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1446 symbols_show_load_tags_dialog();
1450 void on_context_action1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1452 gchar
*word
, *command
;
1453 GError
*error
= NULL
;
1454 GeanyDocument
*doc
= document_get_current();
1455 const gchar
*check_msg
;
1457 g_return_if_fail(doc
!= NULL
);
1459 if (sci_has_selection(doc
->editor
->sci
))
1460 { /* take selected text if there is a selection */
1461 word
= sci_get_selection_contents(doc
->editor
->sci
);
1465 word
= g_strdup(editor_info
.current_word
);
1468 /* use the filetype specific command if available, fallback to global command otherwise */
1469 if (doc
->file_type
!= NULL
&&
1470 !EMPTY(doc
->file_type
->context_action_cmd
))
1472 command
= g_strdup(doc
->file_type
->context_action_cmd
);
1473 check_msg
= _("Check the path setting in Filetype configuration.");
1477 command
= g_strdup(tool_prefs
.context_action_cmd
);
1478 check_msg
= _("Check the path setting in Preferences.");
1481 /* substitute the wildcard %s and run the command if it is non empty */
1482 if (G_LIKELY(!EMPTY(command
)))
1484 gchar
*command_line
= g_strdup(command
);
1486 utils_str_replace_all(&command_line
, "%s", word
);
1488 if (!spawn_async(NULL
, command_line
, NULL
, NULL
, NULL
, &error
))
1490 /* G_SHELL_ERROR is parsing error, it may be caused by %s word with quotes */
1491 ui_set_statusbar(TRUE
, _("Cannot execute context action command \"%s\": %s. %s"),
1492 error
->domain
== G_SHELL_ERROR
? command_line
: command
, error
->message
,
1494 g_error_free(error
);
1496 g_free(command_line
);
1503 void on_menu_toggle_all_additional_widgets1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1505 static gint hide_all
= -1;
1506 GtkCheckMenuItem
*msgw
= GTK_CHECK_MENU_ITEM(
1507 ui_lookup_widget(main_widgets
.window
, "menu_show_messages_window1"));
1508 GtkCheckMenuItem
*toolbari
= GTK_CHECK_MENU_ITEM(
1509 ui_lookup_widget(main_widgets
.window
, "menu_show_toolbar1"));
1511 /* get the initial state (necessary if Geany was closed with hide_all = TRUE) */
1512 if (G_UNLIKELY(hide_all
== -1))
1514 if (! gtk_check_menu_item_get_active(msgw
) &&
1515 ! interface_prefs
.show_notebook_tabs
&&
1516 ! gtk_check_menu_item_get_active(toolbari
))
1524 hide_all
= ! hide_all
; /* toggle */
1528 if (gtk_check_menu_item_get_active(msgw
))
1529 gtk_check_menu_item_set_active(msgw
, ! gtk_check_menu_item_get_active(msgw
));
1531 interface_prefs
.show_notebook_tabs
= FALSE
;
1532 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets
.notebook
), interface_prefs
.show_notebook_tabs
);
1534 ui_statusbar_showhide(FALSE
);
1536 if (gtk_check_menu_item_get_active(toolbari
))
1537 gtk_check_menu_item_set_active(toolbari
, ! gtk_check_menu_item_get_active(toolbari
));
1542 if (! gtk_check_menu_item_get_active(msgw
))
1543 gtk_check_menu_item_set_active(msgw
, ! gtk_check_menu_item_get_active(msgw
));
1545 interface_prefs
.show_notebook_tabs
= TRUE
;
1546 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets
.notebook
), interface_prefs
.show_notebook_tabs
);
1548 ui_statusbar_showhide(TRUE
);
1550 if (! gtk_check_menu_item_get_active(toolbari
))
1551 gtk_check_menu_item_set_active(toolbari
, ! gtk_check_menu_item_get_active(toolbari
));
1556 void on_toolbutton_forward_activate(GtkAction
*menuitem
, gpointer user_data
)
1558 navqueue_go_forward();
1562 void on_toolbutton_back_activate(GtkAction
*menuitem
, gpointer user_data
)
1568 gboolean
on_motion_event(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
)
1570 if (prefs
.auto_focus
&& ! gtk_widget_has_focus(widget
))
1571 gtk_widget_grab_focus(widget
);
1577 static void set_indent_type(GtkCheckMenuItem
*menuitem
, GeanyIndentType type
)
1581 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
1584 doc
= document_get_current();
1585 g_return_if_fail(doc
!= NULL
);
1587 editor_set_indent(doc
->editor
, type
, doc
->editor
->indent_width
);
1588 ui_update_statusbar(doc
, -1);
1592 static void on_tabs1_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
1594 set_indent_type(menuitem
, GEANY_INDENT_TYPE_TABS
);
1598 static void on_spaces1_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
1600 set_indent_type(menuitem
, GEANY_INDENT_TYPE_SPACES
);
1604 static void on_tabs_and_spaces1_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
1606 set_indent_type(menuitem
, GEANY_INDENT_TYPE_BOTH
);
1610 static void on_strip_trailing_spaces1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1614 if (ignore_callback
)
1617 doc
= document_get_current();
1618 g_return_if_fail(doc
!= NULL
);
1620 editor_strip_trailing_spaces(doc
->editor
, FALSE
);
1624 static void on_page_setup1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1626 printing_page_setup_gtk();
1630 gboolean
on_escape_key_press_event(GtkWidget
*widget
, GdkEventKey
*event
, gpointer user_data
)
1632 guint state
= keybindings_get_modifiers(event
->state
);
1634 /* make pressing escape in the sidebar and toolbar focus the editor */
1635 if (event
->keyval
== GDK_Escape
&& state
== 0)
1637 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
1644 void on_line_breaking1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1648 if (ignore_callback
)
1651 doc
= document_get_current();
1652 g_return_if_fail(doc
!= NULL
);
1654 doc
->editor
->line_breaking
= !doc
->editor
->line_breaking
;
1658 void on_replace_spaces_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1660 GeanyDocument
*doc
= document_get_current();
1662 g_return_if_fail(doc
!= NULL
);
1664 editor_replace_spaces(doc
->editor
, FALSE
);
1668 static void on_search1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1670 GtkWidget
*next_message
= ui_lookup_widget(main_widgets
.window
, "next_message1");
1671 GtkWidget
*previous_message
= ui_lookup_widget(main_widgets
.window
, "previous_message1");
1672 gboolean have_messages
;
1674 /* enable commands if the messages window has any items */
1675 have_messages
= gtk_tree_model_iter_n_children(GTK_TREE_MODEL(msgwindow
.store_msg
),
1678 gtk_widget_set_sensitive(next_message
, have_messages
);
1679 gtk_widget_set_sensitive(previous_message
, have_messages
);
1683 /* simple implementation (vs. close all which doesn't close documents if cancelled),
1684 * if user_data is set, it is the GeanyDocument to keep */
1685 void on_close_other_documents1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1688 GeanyDocument
*cur_doc
= user_data
;
1690 if (cur_doc
== NULL
)
1691 cur_doc
= document_get_current();
1693 for (i
= 0; i
< documents_array
->len
; i
++)
1695 GeanyDocument
*doc
= documents
[i
];
1697 if (doc
== cur_doc
|| ! doc
->is_valid
)
1700 if (! document_close(doc
))
1706 static void on_menu_reload_configuration1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1708 main_reload_configuration();
1712 static void on_debug_messages1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1714 log_show_debug_messages_dialog();
1718 void on_send_selection_to_vte1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1721 if (vte_info
.have_vte
)
1722 vte_send_selection_to_vte();
1727 static gboolean
on_window_state_event(GtkWidget
*widget
, GdkEventWindowState
*event
, gpointer user_data
)
1730 if (event
->changed_mask
& GDK_WINDOW_STATE_FULLSCREEN
)
1732 static GtkWidget
*menuitem
= NULL
;
1734 if (menuitem
== NULL
)
1735 menuitem
= ui_lookup_widget(widget
, "menu_fullscreen1");
1737 ignore_callback
= TRUE
;
1739 ui_prefs
.fullscreen
= (event
->new_window_state
& GDK_WINDOW_STATE_FULLSCREEN
) ? TRUE
: FALSE
;
1740 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem
), ui_prefs
.fullscreen
);
1742 ignore_callback
= FALSE
;
1748 static void show_notebook_page(const gchar
*notebook_name
, const gchar
*page_name
)
1751 GtkNotebook
*notebook
;
1753 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, page_name
);
1754 notebook
= GTK_NOTEBOOK(ui_lookup_widget(ui_widgets
.prefs_dialog
, notebook_name
));
1756 if (notebook
!= NULL
&& widget
!= NULL
)
1757 gtk_notebook_set_current_page(notebook
, gtk_notebook_page_num(notebook
, widget
));
1761 static void on_customize_toolbar1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1763 prefs_show_dialog();
1765 /* select the Interface page */
1766 show_notebook_page("notebook2", "notebook6");
1767 /* select the Toolbar subpage */
1768 show_notebook_page("notebook6", "vbox15");
1772 static void on_button_customize_toolbar_clicked(GtkButton
*button
, gpointer user_data
)
1774 toolbar_configure(GTK_WINDOW(ui_widgets
.prefs_dialog
));
1778 static void on_cut_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1780 keybindings_send_command(GEANY_KEY_GROUP_CLIPBOARD
, GEANY_KEYS_CLIPBOARD_CUTLINE
);
1784 static void on_copy_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1786 keybindings_send_command(GEANY_KEY_GROUP_CLIPBOARD
, GEANY_KEYS_CLIPBOARD_COPYLINE
);
1790 static void on_delete_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1792 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_DELETELINE
);
1796 static void on_duplicate_line_or_selection1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1798 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_DUPLICATELINE
);
1802 static void on_select_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1804 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_LINE
);
1808 static void on_select_current_paragraph1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1810 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_PARAGRAPH
);
1814 static void on_insert_alternative_white_space1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1816 keybindings_send_command(GEANY_KEY_GROUP_INSERT
, GEANY_KEYS_INSERT_ALTWHITESPACE
);
1820 static void on_go_to_next_marker1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1822 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_NEXTMARKER
);
1826 static void on_go_to_previous_marker1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1828 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_PREVIOUSMARKER
);
1832 static void on_reflow_lines_block1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1834 keybindings_send_command(GEANY_KEY_GROUP_FORMAT
, GEANY_KEYS_FORMAT_REFLOWPARAGRAPH
);
1838 static void on_move_lines_up1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1840 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_MOVELINEUP
);
1844 static void on_move_lines_down1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1846 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_MOVELINEDOWN
);
1850 static void on_smart_line_indent1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1852 keybindings_send_command(GEANY_KEY_GROUP_FORMAT
, GEANY_KEYS_FORMAT_AUTOINDENT
);
1856 void on_plugin_preferences1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1859 plugin_show_configure(NULL
);
1864 static void on_indent_width_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1870 if (ignore_callback
)
1873 label
= ui_menu_item_get_text(menuitem
);
1874 width
= atoi(label
);
1877 doc
= document_get_current();
1878 if (doc
!= NULL
&& width
> 0)
1879 editor_set_indent_width(doc
->editor
, width
);
1883 static void on_reset_indentation1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1888 document_apply_indent_settings(documents
[i
]);
1890 ui_update_statusbar(NULL
, -1);
1891 ui_document_show_hide(NULL
);
1895 static void on_mark_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1897 keybindings_send_command(GEANY_KEY_GROUP_SEARCH
, GEANY_KEYS_SEARCH_MARKALL
);
1901 static void on_detect_type_from_file_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1903 GeanyDocument
*doc
= document_get_current();
1904 GeanyIndentType type
;
1906 if (doc
!= NULL
&& document_detect_indent_type(doc
, &type
))
1908 editor_set_indent_type(doc
->editor
, type
);
1909 ui_document_show_hide(doc
);
1914 static void on_detect_width_from_file_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1916 GeanyDocument
*doc
= document_get_current();
1919 if (doc
!= NULL
&& document_detect_indent_width(doc
, &width
))
1921 editor_set_indent_width(doc
->editor
, width
);
1922 ui_document_show_hide(doc
);
1927 static void builder_connect_func(GtkBuilder
*builder
, GObject
*object
,
1928 const gchar
*signal_name
, const gchar
*handler_name
, GObject
*connect_obj
,
1929 GConnectFlags flags
, gpointer user_data
)
1931 GHashTable
*hash
= user_data
;
1934 callback
= g_hash_table_lookup(hash
, handler_name
);
1935 g_return_if_fail(callback
);
1937 if (connect_obj
== NULL
)
1938 g_signal_connect_data(object
, signal_name
, callback
, NULL
, NULL
, flags
);
1940 g_signal_connect_object(object
, signal_name
, callback
, connect_obj
, flags
);
1944 void callbacks_connect(GtkBuilder
*builder
)
1948 g_return_if_fail(GTK_IS_BUILDER(builder
));
1950 hash
= g_hash_table_new(g_str_hash
, g_str_equal
);
1952 #define ITEM(n) g_hash_table_insert(hash, (gpointer) #n, G_CALLBACK(n));
1953 # include "signallist.i"
1956 gtk_builder_connect_signals_full(builder
, builder_connect_func
, hash
);
1957 g_hash_table_destroy(hash
);