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
);
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();
1456 g_return_if_fail(doc
!= NULL
);
1458 if (sci_has_selection(doc
->editor
->sci
))
1459 { /* take selected text if there is a selection */
1460 word
= sci_get_selection_contents(doc
->editor
->sci
);
1464 word
= g_strdup(editor_info
.current_word
);
1467 /* use the filetype specific command if available, fallback to global command otherwise */
1468 if (doc
->file_type
!= NULL
&&
1469 !EMPTY(doc
->file_type
->context_action_cmd
))
1471 command
= g_strdup(doc
->file_type
->context_action_cmd
);
1475 command
= g_strdup(tool_prefs
.context_action_cmd
);
1478 /* substitute the wildcard %s and run the command if it is non empty */
1479 if (G_LIKELY(!EMPTY(command
)))
1481 utils_str_replace_all(&command
, "%s", word
);
1483 if (!spawn_async(NULL
, command
, NULL
, NULL
, NULL
, &error
))
1485 ui_set_statusbar(TRUE
, "Context action command failed: %s", error
->message
);
1486 g_error_free(error
);
1494 void on_menu_toggle_all_additional_widgets1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1496 static gint hide_all
= -1;
1497 GtkCheckMenuItem
*msgw
= GTK_CHECK_MENU_ITEM(
1498 ui_lookup_widget(main_widgets
.window
, "menu_show_messages_window1"));
1499 GtkCheckMenuItem
*toolbari
= GTK_CHECK_MENU_ITEM(
1500 ui_lookup_widget(main_widgets
.window
, "menu_show_toolbar1"));
1502 /* get the initial state (necessary if Geany was closed with hide_all = TRUE) */
1503 if (G_UNLIKELY(hide_all
== -1))
1505 if (! gtk_check_menu_item_get_active(msgw
) &&
1506 ! interface_prefs
.show_notebook_tabs
&&
1507 ! gtk_check_menu_item_get_active(toolbari
))
1515 hide_all
= ! hide_all
; /* toggle */
1519 if (gtk_check_menu_item_get_active(msgw
))
1520 gtk_check_menu_item_set_active(msgw
, ! gtk_check_menu_item_get_active(msgw
));
1522 interface_prefs
.show_notebook_tabs
= FALSE
;
1523 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets
.notebook
), interface_prefs
.show_notebook_tabs
);
1525 ui_statusbar_showhide(FALSE
);
1527 if (gtk_check_menu_item_get_active(toolbari
))
1528 gtk_check_menu_item_set_active(toolbari
, ! gtk_check_menu_item_get_active(toolbari
));
1533 if (! gtk_check_menu_item_get_active(msgw
))
1534 gtk_check_menu_item_set_active(msgw
, ! gtk_check_menu_item_get_active(msgw
));
1536 interface_prefs
.show_notebook_tabs
= TRUE
;
1537 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets
.notebook
), interface_prefs
.show_notebook_tabs
);
1539 ui_statusbar_showhide(TRUE
);
1541 if (! gtk_check_menu_item_get_active(toolbari
))
1542 gtk_check_menu_item_set_active(toolbari
, ! gtk_check_menu_item_get_active(toolbari
));
1547 void on_toolbutton_forward_activate(GtkAction
*menuitem
, gpointer user_data
)
1549 navqueue_go_forward();
1553 void on_toolbutton_back_activate(GtkAction
*menuitem
, gpointer user_data
)
1559 gboolean
on_motion_event(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
)
1561 if (prefs
.auto_focus
&& ! gtk_widget_has_focus(widget
))
1562 gtk_widget_grab_focus(widget
);
1568 static void set_indent_type(GtkCheckMenuItem
*menuitem
, GeanyIndentType type
)
1572 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
1575 doc
= document_get_current();
1576 g_return_if_fail(doc
!= NULL
);
1578 editor_set_indent(doc
->editor
, type
, doc
->editor
->indent_width
);
1579 ui_update_statusbar(doc
, -1);
1583 static void on_tabs1_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
1585 set_indent_type(menuitem
, GEANY_INDENT_TYPE_TABS
);
1589 static void on_spaces1_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
1591 set_indent_type(menuitem
, GEANY_INDENT_TYPE_SPACES
);
1595 static void on_tabs_and_spaces1_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
1597 set_indent_type(menuitem
, GEANY_INDENT_TYPE_BOTH
);
1601 static void on_strip_trailing_spaces1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1605 if (ignore_callback
)
1608 doc
= document_get_current();
1609 g_return_if_fail(doc
!= NULL
);
1611 editor_strip_trailing_spaces(doc
->editor
);
1615 static void on_page_setup1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1617 printing_page_setup_gtk();
1621 gboolean
on_escape_key_press_event(GtkWidget
*widget
, GdkEventKey
*event
, gpointer user_data
)
1623 guint state
= keybindings_get_modifiers(event
->state
);
1625 /* make pressing escape in the sidebar and toolbar focus the editor */
1626 if (event
->keyval
== GDK_Escape
&& state
== 0)
1628 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
1635 void on_line_breaking1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1639 if (ignore_callback
)
1642 doc
= document_get_current();
1643 g_return_if_fail(doc
!= NULL
);
1645 doc
->editor
->line_breaking
= !doc
->editor
->line_breaking
;
1649 void on_replace_spaces_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1651 GeanyDocument
*doc
= document_get_current();
1653 g_return_if_fail(doc
!= NULL
);
1655 editor_replace_spaces(doc
->editor
);
1659 static void on_search1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1661 GtkWidget
*next_message
= ui_lookup_widget(main_widgets
.window
, "next_message1");
1662 GtkWidget
*previous_message
= ui_lookup_widget(main_widgets
.window
, "previous_message1");
1663 gboolean have_messages
;
1665 /* enable commands if the messages window has any items */
1666 have_messages
= gtk_tree_model_iter_n_children(GTK_TREE_MODEL(msgwindow
.store_msg
),
1669 gtk_widget_set_sensitive(next_message
, have_messages
);
1670 gtk_widget_set_sensitive(previous_message
, have_messages
);
1674 /* simple implementation (vs. close all which doesn't close documents if cancelled),
1675 * if user_data is set, it is the GeanyDocument to keep */
1676 void on_close_other_documents1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1679 GeanyDocument
*cur_doc
= user_data
;
1681 if (cur_doc
== NULL
)
1682 cur_doc
= document_get_current();
1684 for (i
= 0; i
< documents_array
->len
; i
++)
1686 GeanyDocument
*doc
= documents
[i
];
1688 if (doc
== cur_doc
|| ! doc
->is_valid
)
1691 if (! document_close(doc
))
1697 static void on_menu_reload_configuration1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1699 main_reload_configuration();
1703 static void on_debug_messages1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1705 log_show_debug_messages_dialog();
1709 void on_send_selection_to_vte1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1712 if (vte_info
.have_vte
)
1713 vte_send_selection_to_vte();
1718 static gboolean
on_window_state_event(GtkWidget
*widget
, GdkEventWindowState
*event
, gpointer user_data
)
1721 if (event
->changed_mask
& GDK_WINDOW_STATE_FULLSCREEN
)
1723 static GtkWidget
*menuitem
= NULL
;
1725 if (menuitem
== NULL
)
1726 menuitem
= ui_lookup_widget(widget
, "menu_fullscreen1");
1728 ignore_callback
= TRUE
;
1730 ui_prefs
.fullscreen
= (event
->new_window_state
& GDK_WINDOW_STATE_FULLSCREEN
) ? TRUE
: FALSE
;
1731 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem
), ui_prefs
.fullscreen
);
1733 ignore_callback
= FALSE
;
1739 static void show_notebook_page(const gchar
*notebook_name
, const gchar
*page_name
)
1742 GtkNotebook
*notebook
;
1744 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, page_name
);
1745 notebook
= GTK_NOTEBOOK(ui_lookup_widget(ui_widgets
.prefs_dialog
, notebook_name
));
1747 if (notebook
!= NULL
&& widget
!= NULL
)
1748 gtk_notebook_set_current_page(notebook
, gtk_notebook_page_num(notebook
, widget
));
1752 static void on_customize_toolbar1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1754 prefs_show_dialog();
1756 /* select the Interface page */
1757 show_notebook_page("notebook2", "notebook6");
1758 /* select the Toolbar subpage */
1759 show_notebook_page("notebook6", "vbox15");
1763 static void on_button_customize_toolbar_clicked(GtkButton
*button
, gpointer user_data
)
1765 toolbar_configure(GTK_WINDOW(ui_widgets
.prefs_dialog
));
1769 static void on_cut_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1771 keybindings_send_command(GEANY_KEY_GROUP_CLIPBOARD
, GEANY_KEYS_CLIPBOARD_CUTLINE
);
1775 static void on_copy_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1777 keybindings_send_command(GEANY_KEY_GROUP_CLIPBOARD
, GEANY_KEYS_CLIPBOARD_COPYLINE
);
1781 static void on_delete_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1783 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_DELETELINE
);
1787 static void on_duplicate_line_or_selection1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1789 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_DUPLICATELINE
);
1793 static void on_select_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1795 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_LINE
);
1799 static void on_select_current_paragraph1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1801 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_PARAGRAPH
);
1805 static void on_insert_alternative_white_space1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1807 keybindings_send_command(GEANY_KEY_GROUP_INSERT
, GEANY_KEYS_INSERT_ALTWHITESPACE
);
1811 static void on_go_to_next_marker1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1813 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_NEXTMARKER
);
1817 static void on_go_to_previous_marker1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1819 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_PREVIOUSMARKER
);
1823 static void on_reflow_lines_block1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1825 keybindings_send_command(GEANY_KEY_GROUP_FORMAT
, GEANY_KEYS_FORMAT_REFLOWPARAGRAPH
);
1829 static void on_move_lines_up1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1831 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_MOVELINEUP
);
1835 static void on_move_lines_down1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1837 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_MOVELINEDOWN
);
1841 static void on_smart_line_indent1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1843 keybindings_send_command(GEANY_KEY_GROUP_FORMAT
, GEANY_KEYS_FORMAT_AUTOINDENT
);
1847 void on_plugin_preferences1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1850 plugin_show_configure(NULL
);
1855 static void on_indent_width_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1861 if (ignore_callback
)
1864 label
= ui_menu_item_get_text(menuitem
);
1865 width
= atoi(label
);
1868 doc
= document_get_current();
1869 if (doc
!= NULL
&& width
> 0)
1870 editor_set_indent_width(doc
->editor
, width
);
1874 static void on_reset_indentation1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1879 document_apply_indent_settings(documents
[i
]);
1881 ui_update_statusbar(NULL
, -1);
1882 ui_document_show_hide(NULL
);
1886 static void on_mark_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1888 keybindings_send_command(GEANY_KEY_GROUP_SEARCH
, GEANY_KEYS_SEARCH_MARKALL
);
1892 static void on_detect_type_from_file_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1894 GeanyDocument
*doc
= document_get_current();
1895 GeanyIndentType type
;
1897 if (doc
!= NULL
&& document_detect_indent_type(doc
, &type
))
1899 editor_set_indent_type(doc
->editor
, type
);
1900 ui_document_show_hide(doc
);
1905 static void on_detect_width_from_file_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1907 GeanyDocument
*doc
= document_get_current();
1910 if (doc
!= NULL
&& document_detect_indent_width(doc
, &width
))
1912 editor_set_indent_width(doc
->editor
, width
);
1913 ui_document_show_hide(doc
);
1918 static void builder_connect_func(GtkBuilder
*builder
, GObject
*object
,
1919 const gchar
*signal_name
, const gchar
*handler_name
, GObject
*connect_obj
,
1920 GConnectFlags flags
, gpointer user_data
)
1922 GHashTable
*hash
= user_data
;
1925 callback
= g_hash_table_lookup(hash
, handler_name
);
1926 g_return_if_fail(callback
);
1928 if (connect_obj
== NULL
)
1929 g_signal_connect_data(object
, signal_name
, callback
, NULL
, NULL
, flags
);
1931 g_signal_connect_object(object
, signal_name
, callback
, connect_obj
, flags
);
1935 void callbacks_connect(GtkBuilder
*builder
)
1939 g_return_if_fail(GTK_IS_BUILDER(builder
));
1941 hash
= g_hash_table_new(g_str_hash
, g_str_equal
);
1943 #define ITEM(n) g_hash_table_insert(hash, (gpointer) #n, G_CALLBACK(n));
1944 # include "signallist.i"
1947 gtk_builder_connect_signals_full(builder
, builder_connect_func
, hash
);
1948 g_hash_table_destroy(hash
);