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"
59 #include "templates.h"
66 #include "gtkcompat.h"
71 #include <gdk/gdkkeysyms.h>
72 #include <glib/gstdio.h>
76 /* prototypes of Glade-only callback to let the compiler know they really are meant to be exported */
77 G_MODULE_EXPORT gboolean
on_window_delete_event(GtkWidget
*widget
, GdkEvent
*event
, gpointer gdata
);
78 G_MODULE_EXPORT
void on_info1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
79 G_MODULE_EXPORT
void on_change_font1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
80 G_MODULE_EXPORT
void on_crlf_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
);
81 G_MODULE_EXPORT
void on_lf_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
);
82 G_MODULE_EXPORT
void on_cr_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
);
83 G_MODULE_EXPORT
void on_hide_toolbar1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
84 G_MODULE_EXPORT
void on_show_toolbar1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
);
85 G_MODULE_EXPORT
void on_fullscreen1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
);
86 G_MODULE_EXPORT
void on_markers_margin1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
);
87 G_MODULE_EXPORT
void on_show_messages_window1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
);
88 G_MODULE_EXPORT
void on_menu_color_schemes_activate(GtkImageMenuItem
*imagemenuitem
, gpointer user_data
);
89 G_MODULE_EXPORT
void on_count_words1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
90 G_MODULE_EXPORT
void on_edit1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
91 G_MODULE_EXPORT
void on_website1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
92 G_MODULE_EXPORT
void on_help_menu_item_donate_activate(GtkMenuItem
*item
, gpointer user_data
);
93 G_MODULE_EXPORT
void on_help_menu_item_wiki_activate(GtkMenuItem
*item
, gpointer user_data
);
94 G_MODULE_EXPORT
void on_help_menu_item_bug_report_activate(GtkMenuItem
*item
, gpointer user_data
);
95 G_MODULE_EXPORT
void on_comments_function_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
96 G_MODULE_EXPORT
void on_comments_multiline_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
97 G_MODULE_EXPORT
void on_comments_changelog_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
98 G_MODULE_EXPORT
void on_comments_gpl_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
99 G_MODULE_EXPORT
void on_comments_fileheader_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
100 G_MODULE_EXPORT
void on_set_file_readonly1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
);
101 G_MODULE_EXPORT
void on_tv_notebook_switch_page(GtkNotebook
*notebook
, gpointer page
, guint page_num
, gpointer user_data
);
102 G_MODULE_EXPORT
void on_help_shortcuts1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
103 G_MODULE_EXPORT
void on_file_properties_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
104 G_MODULE_EXPORT
void on_show_line_numbers1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
);
105 G_MODULE_EXPORT
void on_use_auto_indentation1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
);
106 G_MODULE_EXPORT
void on_menu_fold_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
107 G_MODULE_EXPORT
void on_menu_unfold_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
108 G_MODULE_EXPORT
void on_notebook1_switch_page_after(GtkNotebook
*notebook
, gpointer page
, guint page_num
, gpointer user_data
);
109 G_MODULE_EXPORT
void on_menu_write_unicode_bom1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
);
110 G_MODULE_EXPORT
void on_menu_comments_multiline_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
111 G_MODULE_EXPORT
void on_menu_comments_gpl_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
112 G_MODULE_EXPORT
void on_menu_comments_bsd_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
113 G_MODULE_EXPORT
void on_comments_bsd_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
114 G_MODULE_EXPORT
void on_menu_project1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
115 G_MODULE_EXPORT
void on_load_tags1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
116 G_MODULE_EXPORT
void on_file1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
117 G_MODULE_EXPORT
void on_tv_notebook_switch_page_after(GtkNotebook
*notebook
, gpointer page
, guint page_num
, gpointer user_data
);
118 G_MODULE_EXPORT
void on_tabs1_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
);
119 G_MODULE_EXPORT
void on_spaces1_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
);
120 G_MODULE_EXPORT
void on_strip_trailing_spaces1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
121 G_MODULE_EXPORT
void on_page_setup1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
122 G_MODULE_EXPORT
void on_search1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
123 G_MODULE_EXPORT
void on_menu_reload_configuration1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
124 G_MODULE_EXPORT
void on_tabs_and_spaces1_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
);
125 G_MODULE_EXPORT
void on_debug_messages1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
126 G_MODULE_EXPORT
void on_menu_show_white_space1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
);
127 G_MODULE_EXPORT
void on_menu_show_line_endings1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
);
128 G_MODULE_EXPORT
void on_menu_show_indentation_guides1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
);
129 G_MODULE_EXPORT gboolean
on_window_state_event(GtkWidget
*widget
, GdkEventWindowState
*event
, gpointer user_data
);
130 G_MODULE_EXPORT
void on_customize_toolbar1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
131 G_MODULE_EXPORT
void on_button_customize_toolbar_clicked(GtkButton
*button
, gpointer user_data
);
132 G_MODULE_EXPORT
void on_cut_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
133 G_MODULE_EXPORT
void on_copy_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
134 G_MODULE_EXPORT
void on_delete_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
135 G_MODULE_EXPORT
void on_duplicate_line_or_selection1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
136 G_MODULE_EXPORT
void on_select_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
137 G_MODULE_EXPORT
void on_select_current_paragraph1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
138 G_MODULE_EXPORT
void on_insert_alternative_white_space1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
139 G_MODULE_EXPORT
void on_go_to_next_marker1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
140 G_MODULE_EXPORT
void on_go_to_previous_marker1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
141 G_MODULE_EXPORT
void on_reflow_lines_block1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
142 G_MODULE_EXPORT
void on_smart_line_indent1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
143 G_MODULE_EXPORT
void on_move_lines_up1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
144 G_MODULE_EXPORT
void on_move_lines_down1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
145 G_MODULE_EXPORT
void on_goto_tag_definition1(GtkMenuItem
*menuitem
, gpointer user_data
);
146 G_MODULE_EXPORT
void on_goto_tag_declaration1(GtkMenuItem
*menuitem
, gpointer user_data
);
147 G_MODULE_EXPORT
void on_indent_width_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
148 G_MODULE_EXPORT
void on_reset_indentation1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
149 G_MODULE_EXPORT
void on_mark_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
150 G_MODULE_EXPORT
void on_detect_type_from_file_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
151 G_MODULE_EXPORT
void on_detect_width_from_file_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
152 G_MODULE_EXPORT
void on_clone1_activate(GtkMenuItem
*menuitem
, gpointer user_data
);
155 /* represents the state at switching a notebook page(in the left treeviews widget), to not emit
156 * the selection-changed signal from tv.tree_openfiles */
157 /*static gboolean switch_tv_notebook_page = FALSE; */
161 /* wrapper function to abort exit process if cancel button is pressed */
162 G_MODULE_EXPORT gboolean
on_window_delete_event(GtkWidget
*widget
, GdkEvent
*event
, gpointer gdata
)
172 G_MODULE_EXPORT
void on_new1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
174 document_new_file(NULL
, NULL
, NULL
);
178 /* create a new file and copy file content and properties */
179 G_MODULE_EXPORT
void on_clone1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
181 GeanyDocument
*old_doc
= document_get_current();
184 document_clone(old_doc
);
188 G_MODULE_EXPORT
void on_save1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
190 GeanyDocument
*doc
= document_get_current();
194 document_save_file(doc
, ui_prefs
.allow_always_save
);
199 G_MODULE_EXPORT
void on_save_as1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
201 dialogs_show_save_as();
205 G_MODULE_EXPORT
void on_save_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
207 guint i
, max
= (guint
) gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets
.notebook
));
208 GeanyDocument
*doc
, *cur_doc
= document_get_current();
211 /* iterate over documents in tabs order */
212 for (i
= 0; i
< max
; i
++)
214 doc
= document_get_from_page(i
);
218 if (document_save_file(doc
, FALSE
))
224 ui_set_statusbar(FALSE
, ngettext("%d file saved.", "%d files saved.", count
), count
);
225 /* saving may have changed window title, sidebar for another doc, so update */
226 document_show_tab(cur_doc
);
227 sidebar_update_tag_list(cur_doc
, TRUE
);
228 ui_set_window_title(cur_doc
);
232 G_MODULE_EXPORT
void on_close_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
234 document_close_all();
238 G_MODULE_EXPORT
void on_close1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
240 GeanyDocument
*doc
= document_get_current();
247 G_MODULE_EXPORT
void on_quit1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
253 G_MODULE_EXPORT
void on_file1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
255 gtk_widget_set_sensitive(ui_widgets
.recent_files_menuitem
,
256 g_queue_get_length(ui_prefs
.recent_queue
) > 0);
257 /* hide Page setup when GTK printing is not used */
258 ui_widget_show_hide(ui_widgets
.print_page_setup
, printing_prefs
.use_gtk_printing
);
262 /* edit actions, c&p & co, from menu bar and from popup menu */
263 G_MODULE_EXPORT
void on_edit1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
266 GeanyDocument
*doc
= document_get_current();
268 ui_update_menu_copy_items(doc
);
269 ui_update_insert_include_item(doc
, 1);
271 item
= ui_lookup_widget(main_widgets
.window
, "plugin_preferences1");
273 gtk_widget_hide(item
);
275 gtk_widget_set_sensitive(item
, plugins_have_preferences());
280 G_MODULE_EXPORT
void on_undo1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
282 GeanyDocument
*doc
= document_get_current();
284 g_return_if_fail(doc
!= NULL
);
286 if (document_can_undo(doc
))
288 sci_cancel(doc
->editor
->sci
);
294 G_MODULE_EXPORT
void on_redo1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
296 GeanyDocument
*doc
= document_get_current();
298 g_return_if_fail(doc
!= NULL
);
300 if (document_can_redo(doc
))
302 sci_cancel(doc
->editor
->sci
);
308 G_MODULE_EXPORT
void on_cut1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
310 GeanyDocument
*doc
= document_get_current();
311 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
313 if (GTK_IS_EDITABLE(focusw
))
314 gtk_editable_cut_clipboard(GTK_EDITABLE(focusw
));
316 if (IS_SCINTILLA(focusw
) && doc
!= NULL
)
317 sci_cut(doc
->editor
->sci
);
319 if (GTK_IS_TEXT_VIEW(focusw
))
321 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(
322 GTK_TEXT_VIEW(focusw
));
323 gtk_text_buffer_cut_clipboard(buffer
, gtk_clipboard_get(GDK_NONE
), TRUE
);
328 G_MODULE_EXPORT
void on_copy1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
330 GeanyDocument
*doc
= document_get_current();
331 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
333 if (GTK_IS_EDITABLE(focusw
))
334 gtk_editable_copy_clipboard(GTK_EDITABLE(focusw
));
336 if (IS_SCINTILLA(focusw
) && doc
!= NULL
)
337 sci_copy(doc
->editor
->sci
);
339 if (GTK_IS_TEXT_VIEW(focusw
))
341 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(
342 GTK_TEXT_VIEW(focusw
));
343 gtk_text_buffer_copy_clipboard(buffer
, gtk_clipboard_get(GDK_NONE
));
348 G_MODULE_EXPORT
void on_paste1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
350 GeanyDocument
*doc
= document_get_current();
351 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
353 if (GTK_IS_EDITABLE(focusw
))
354 gtk_editable_paste_clipboard(GTK_EDITABLE(focusw
));
356 if (IS_SCINTILLA(focusw
) && doc
!= NULL
)
358 sci_paste(doc
->editor
->sci
);
361 if (GTK_IS_TEXT_VIEW(focusw
))
363 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(
364 GTK_TEXT_VIEW(focusw
));
365 gtk_text_buffer_paste_clipboard(buffer
, gtk_clipboard_get(GDK_NONE
), NULL
,
371 G_MODULE_EXPORT
void on_delete1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
373 GeanyDocument
*doc
= document_get_current();
374 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
376 if (GTK_IS_EDITABLE(focusw
))
377 gtk_editable_delete_selection(GTK_EDITABLE(focusw
));
379 if (IS_SCINTILLA(focusw
) && doc
!= NULL
&& sci_has_selection(doc
->editor
->sci
))
380 sci_clear(doc
->editor
->sci
);
382 if (GTK_IS_TEXT_VIEW(focusw
))
384 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(
385 GTK_TEXT_VIEW(focusw
));
386 gtk_text_buffer_delete_selection(buffer
, TRUE
, TRUE
);
391 G_MODULE_EXPORT
void on_preferences1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
397 /* about menu item */
398 G_MODULE_EXPORT
void on_info1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
405 G_MODULE_EXPORT
void on_open1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
407 dialogs_show_open_file();
412 G_MODULE_EXPORT
void on_toolbutton_reload_clicked(GtkAction
*action
, gpointer user_data
)
414 GeanyDocument
*doc
= document_get_current();
416 g_return_if_fail(doc
!= NULL
);
418 document_reload_prompt(doc
, NULL
);
422 G_MODULE_EXPORT
void on_change_font1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
424 dialogs_show_open_font();
428 /* store text, clear search flags so we can use Search->Find Next/Previous */
429 static void setup_find(const gchar
*text
, gboolean backwards
)
431 SETPTR(search_data
.text
, g_strdup(text
));
432 SETPTR(search_data
.original_text
, g_strdup(text
));
433 search_data
.flags
= 0;
434 search_data
.backwards
= backwards
;
435 search_data
.search_bar
= TRUE
;
439 static void do_toolbar_search(const gchar
*text
, gboolean incremental
, gboolean backwards
)
441 GeanyDocument
*doc
= document_get_current();
444 setup_find(text
, backwards
);
445 result
= document_search_bar_find(doc
, search_data
.text
, incremental
, backwards
);
446 if (search_data
.search_bar
)
447 ui_set_search_entry_background(toolbar_get_widget_child_by_name("SearchEntry"), result
);
452 void on_toolbar_search_entry_changed(GtkAction
*action
, const gchar
*text
, gpointer user_data
)
454 do_toolbar_search(text
, TRUE
, FALSE
);
459 void on_toolbar_search_entry_activate(GtkAction
*action
, const gchar
*text
, gpointer user_data
)
461 do_toolbar_search(text
, FALSE
, GPOINTER_TO_INT(user_data
));
466 void on_toolbutton_search_clicked(GtkAction
*action
, gpointer user_data
)
468 GeanyDocument
*doc
= document_get_current();
470 GtkWidget
*entry
= toolbar_get_widget_child_by_name("SearchEntry");
474 const gchar
*text
= gtk_entry_get_text(GTK_ENTRY(entry
));
476 setup_find(text
, FALSE
);
477 result
= document_search_bar_find(doc
, search_data
.text
, FALSE
, FALSE
);
478 if (search_data
.search_bar
)
479 ui_set_search_entry_background(entry
, result
);
482 on_find1_activate(NULL
, NULL
);
486 /* hides toolbar from toolbar popup menu */
487 G_MODULE_EXPORT
void on_hide_toolbar1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
489 GtkWidget
*tool_item
= ui_lookup_widget(GTK_WIDGET(main_widgets
.window
), "menu_show_toolbar1");
490 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(tool_item
), FALSE
);
494 /* zoom in from menu bar and popup menu */
495 G_MODULE_EXPORT
void on_zoom_in1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
497 GeanyDocument
*doc
= document_get_current();
499 g_return_if_fail(doc
!= NULL
);
501 sci_zoom_in(doc
->editor
->sci
);
505 /* zoom out from menu bar and popup menu */
506 G_MODULE_EXPORT
void on_zoom_out1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
508 GeanyDocument
*doc
= document_get_current();
510 g_return_if_fail(doc
!= NULL
);
512 sci_zoom_out(doc
->editor
->sci
);
516 G_MODULE_EXPORT
void on_normal_size1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
518 GeanyDocument
*doc
= document_get_current();
520 g_return_if_fail(doc
!= NULL
);
522 sci_zoom_off(doc
->editor
->sci
);
526 static gboolean
delayed_check_disk_status(gpointer data
)
528 document_check_disk_status(data
, FALSE
);
533 /* Changes window-title after switching tabs and lots of other things.
534 * note: using 'after' makes Scintilla redraw before the UI, appearing more responsive */
535 G_MODULE_EXPORT
void on_notebook1_switch_page_after(GtkNotebook
*notebook
, gpointer page
,
536 guint page_num
, gpointer user_data
)
540 if (G_UNLIKELY(main_status
.opening_session_files
|| main_status
.closing_all
))
543 if (page_num
== (guint
) -1 && page
!= NULL
)
544 doc
= document_find_by_sci(SCINTILLA(page
));
546 doc
= document_get_from_page(page_num
);
550 sidebar_select_openfiles_item(doc
);
551 ui_save_buttons_toggle(doc
->changed
);
552 ui_set_window_title(doc
);
553 ui_update_statusbar(doc
, -1);
554 ui_update_popup_reundo_items(doc
);
555 ui_document_show_hide(doc
); /* update the document menu */
556 build_menu_update(doc
);
557 sidebar_update_tag_list(doc
, FALSE
);
558 document_highlight_tags(doc
);
560 /* We delay the check to avoid weird fast, unintended switching of notebook pages when
561 * the 'file has changed' dialog is shown while the switch event is not yet completely
562 * finished. So, we check after the switch has been performed to be safe. */
563 g_idle_add(delayed_check_disk_status
, doc
);
566 vte_cwd((doc
->real_path
!= NULL
) ? doc
->real_path
: doc
->file_name
, FALSE
);
569 g_signal_emit_by_name(geany_object
, "document-activate", doc
);
574 G_MODULE_EXPORT
void on_tv_notebook_switch_page(GtkNotebook
*notebook
, gpointer page
,
575 guint page_num
, gpointer user_data
)
577 /* suppress selection changed signal when switching to the open files list */
578 ignore_callback
= TRUE
;
582 G_MODULE_EXPORT
void on_tv_notebook_switch_page_after(GtkNotebook
*notebook
, gpointer page
,
583 guint page_num
, gpointer user_data
)
585 ignore_callback
= FALSE
;
589 static void convert_eol(gint mode
)
591 GeanyDocument
*doc
= document_get_current();
593 g_return_if_fail(doc
!= NULL
);
595 sci_convert_eols(doc
->editor
->sci
, mode
);
596 sci_set_eol_mode(doc
->editor
->sci
, mode
);
597 ui_update_statusbar(doc
, -1);
601 G_MODULE_EXPORT
void on_crlf_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
603 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
606 convert_eol(SC_EOL_CRLF
);
610 G_MODULE_EXPORT
void on_lf_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
612 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
615 convert_eol(SC_EOL_LF
);
619 G_MODULE_EXPORT
void on_cr_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
621 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
624 convert_eol(SC_EOL_CR
);
628 G_MODULE_EXPORT
void on_replace_tabs_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
630 GeanyDocument
*doc
= document_get_current();
632 g_return_if_fail(doc
!= NULL
);
634 editor_replace_tabs(doc
->editor
);
638 gboolean
toolbar_popup_menu(GtkWidget
*widget
, GdkEventButton
*event
, gpointer user_data
)
640 if (event
->button
== 3)
642 gtk_menu_popup(GTK_MENU(ui_widgets
.toolbar_menu
), NULL
, NULL
, NULL
, NULL
, event
->button
, event
->time
);
649 G_MODULE_EXPORT
void on_toggle_case1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
651 GeanyDocument
*doc
= document_get_current();
652 ScintillaObject
*sci
;
654 gboolean keep_sel
= TRUE
;
656 g_return_if_fail(doc
!= NULL
);
658 sci
= doc
->editor
->sci
;
659 if (! sci_has_selection(sci
))
661 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_WORD
);
665 /* either we already had a selection or we created one for current word */
666 if (sci_has_selection(sci
))
668 gchar
*result
= NULL
;
669 gint cmd
= SCI_LOWERCASE
;
670 gboolean rectsel
= (gboolean
) scintilla_send_message(sci
, SCI_SELECTIONISRECTANGLE
, 0, 0);
672 text
= sci_get_selection_contents(sci
);
674 if (utils_str_has_upper(text
))
679 result
= g_utf8_strdown(text
, -1);
686 result
= g_utf8_strup(text
, -1);
691 sci_replace_sel(sci
, result
);
694 sci_set_selection_start(sci
, sci_get_current_position(sci
) - strlen(text
));
697 sci_send_command(sci
, cmd
);
705 G_MODULE_EXPORT
void on_show_toolbar1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
707 if (ignore_callback
) return;
709 toolbar_prefs
.visible
= (toolbar_prefs
.visible
) ? FALSE
: TRUE
;;
710 ui_widget_show_hide(GTK_WIDGET(main_widgets
.toolbar
), toolbar_prefs
.visible
);
714 G_MODULE_EXPORT
void on_fullscreen1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
719 ui_prefs
.fullscreen
= (ui_prefs
.fullscreen
) ? FALSE
: TRUE
;
724 G_MODULE_EXPORT
void on_show_messages_window1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
729 ui_prefs
.msgwindow_visible
= (ui_prefs
.msgwindow_visible
) ? FALSE
: TRUE
;
730 msgwin_show_hide(ui_prefs
.msgwindow_visible
);
734 G_MODULE_EXPORT
void on_menu_color_schemes_activate(GtkImageMenuItem
*imagemenuitem
, gpointer user_data
)
736 highlighting_show_color_scheme_dialog();
740 G_MODULE_EXPORT
void on_markers_margin1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
745 editor_prefs
.show_markers_margin
= ! editor_prefs
.show_markers_margin
;
746 ui_toggle_editor_features(GEANY_EDITOR_SHOW_MARKERS_MARGIN
);
750 G_MODULE_EXPORT
void on_show_line_numbers1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
755 editor_prefs
.show_linenumber_margin
= ! editor_prefs
.show_linenumber_margin
;
756 ui_toggle_editor_features(GEANY_EDITOR_SHOW_LINE_NUMBERS
);
760 G_MODULE_EXPORT
void on_menu_show_white_space1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
765 editor_prefs
.show_white_space
= ! editor_prefs
.show_white_space
;
766 ui_toggle_editor_features(GEANY_EDITOR_SHOW_WHITE_SPACE
);
770 G_MODULE_EXPORT
void on_menu_show_line_endings1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
775 editor_prefs
.show_line_endings
= ! editor_prefs
.show_line_endings
;
776 ui_toggle_editor_features(GEANY_EDITOR_SHOW_LINE_ENDINGS
);
780 G_MODULE_EXPORT
void on_menu_show_indentation_guides1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
785 editor_prefs
.show_indent_guide
= ! editor_prefs
.show_indent_guide
;
786 ui_toggle_editor_features(GEANY_EDITOR_SHOW_INDENTATION_GUIDES
);
790 G_MODULE_EXPORT
void on_line_wrapping1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
792 if (! ignore_callback
)
794 GeanyDocument
*doc
= document_get_current();
795 g_return_if_fail(doc
!= NULL
);
797 editor_set_line_wrapping(doc
->editor
, ! doc
->editor
->line_wrapping
);
802 G_MODULE_EXPORT
void on_set_file_readonly1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
804 if (! ignore_callback
)
806 GeanyDocument
*doc
= document_get_current();
807 g_return_if_fail(doc
!= NULL
);
809 doc
->readonly
= ! doc
->readonly
;
810 sci_set_readonly(doc
->editor
->sci
, doc
->readonly
);
811 ui_update_tab_status(doc
);
812 ui_update_statusbar(doc
, -1);
817 G_MODULE_EXPORT
void on_use_auto_indentation1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
819 if (! ignore_callback
)
821 GeanyDocument
*doc
= document_get_current();
822 g_return_if_fail(doc
!= NULL
);
824 doc
->editor
->auto_indent
= ! doc
->editor
->auto_indent
;
829 static void find_usage(gboolean in_session
)
831 GeanyFindFlags flags
;
833 GeanyDocument
*doc
= document_get_current();
835 g_return_if_fail(doc
!= NULL
);
837 if (sci_has_selection(doc
->editor
->sci
))
838 { /* take selected text if there is a selection */
839 search_text
= sci_get_selection_contents(doc
->editor
->sci
);
840 flags
= GEANY_FIND_MATCHCASE
;
844 editor_find_current_word_sciwc(doc
->editor
, -1,
845 editor_info
.current_word
, GEANY_MAX_WORD_LENGTH
);
846 search_text
= g_strdup(editor_info
.current_word
);
847 flags
= GEANY_FIND_MATCHCASE
| GEANY_FIND_WHOLEWORD
;
850 search_find_usage(search_text
, search_text
, flags
, in_session
);
855 G_MODULE_EXPORT
void on_find_document_usage1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
861 G_MODULE_EXPORT
void on_find_usage1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
867 static void goto_tag(gboolean definition
)
869 GeanyDocument
*doc
= document_get_current();
871 g_return_if_fail(doc
!= NULL
);
873 /* update cursor pos for navigating back afterwards */
874 if (!sci_has_selection(doc
->editor
->sci
))
875 sci_set_current_position(doc
->editor
->sci
, editor_info
.click_pos
, FALSE
);
877 /* use the keybinding callback as it checks for selections as well as current word */
879 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_TAGDEFINITION
);
881 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_TAGDECLARATION
);
885 G_MODULE_EXPORT
void on_goto_tag_definition1(GtkMenuItem
*menuitem
, gpointer user_data
)
891 G_MODULE_EXPORT
void on_goto_tag_declaration1(GtkMenuItem
*menuitem
, gpointer user_data
)
897 G_MODULE_EXPORT
void on_count_words1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
903 G_MODULE_EXPORT
void on_show_color_chooser1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
906 GeanyDocument
*doc
= document_get_current();
909 g_return_if_fail(doc
!= NULL
);
911 pos
= sci_get_current_position(doc
->editor
->sci
);
912 editor_find_current_word(doc
->editor
, pos
, colour
, sizeof colour
, GEANY_WORDCHARS
"#");
913 tools_color_chooser(colour
);
917 void on_toolbutton_compile_clicked(GtkAction
*action
, gpointer user_data
)
919 keybindings_send_command(GEANY_KEY_GROUP_BUILD
, GEANY_KEYS_BUILD_COMPILE
);
923 G_MODULE_EXPORT
void on_find1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
925 search_show_find_dialog();
929 G_MODULE_EXPORT
void on_find_next1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
931 search_find_again(FALSE
);
935 G_MODULE_EXPORT
void on_find_previous1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
937 if (search_data
.flags
& GEANY_FIND_REGEXP
)
938 /* Can't reverse search order for a regex (find next ignores search backwards) */
941 search_find_again(TRUE
);
945 G_MODULE_EXPORT
void on_find_nextsel1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
947 search_find_selection(document_get_current(), FALSE
);
951 G_MODULE_EXPORT
void on_find_prevsel1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
953 search_find_selection(document_get_current(), TRUE
);
957 G_MODULE_EXPORT
void on_replace1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
959 search_show_replace_dialog();
963 G_MODULE_EXPORT
void on_find_in_files1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
965 search_show_find_in_files_dialog(NULL
);
969 static void get_line_and_offset_from_text(const gchar
*text
, gint
*line_no
, gint
*offset
)
971 if (*text
== '+' || *text
== '-')
973 *line_no
= atoi(text
+ 1);
974 *offset
= (*text
== '+') ? 1 : -1;
978 *line_no
= atoi(text
) - 1;
984 G_MODULE_EXPORT
void on_go_to_line_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
986 static gchar value
[16] = "";
989 result
= dialogs_show_input_goto_line(
990 _("Go to Line"), GTK_WINDOW(main_widgets
.window
),
991 _("Enter the line you want to go to:"), value
);
994 GeanyDocument
*doc
= document_get_current();
998 g_return_if_fail(doc
!= NULL
);
1000 get_line_and_offset_from_text(result
, &line_no
, &offset
);
1001 if (! editor_goto_line(doc
->editor
, line_no
, offset
))
1003 /* remember value for future calls */
1004 g_snprintf(value
, sizeof(value
), "%s", result
);
1011 void on_toolbutton_goto_entry_activate(GtkAction
*action
, const gchar
*text
, gpointer user_data
)
1013 GeanyDocument
*doc
= document_get_current();
1017 g_return_if_fail(doc
!= NULL
);
1019 get_line_and_offset_from_text(text
, &line_no
, &offset
);
1020 if (! editor_goto_line(doc
->editor
, line_no
, offset
))
1023 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
1027 void on_toolbutton_goto_clicked(GtkAction
*action
, gpointer user_data
)
1029 GtkWidget
*entry
= toolbar_get_widget_child_by_name("GotoEntry");
1033 const gchar
*text
= gtk_entry_get_text(GTK_ENTRY(entry
));
1035 on_toolbutton_goto_entry_activate(NULL
, text
, NULL
);
1038 on_go_to_line_activate(NULL
, NULL
);
1042 G_MODULE_EXPORT
void on_help1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1046 uri
= utils_get_help_url(NULL
);
1047 utils_open_browser(uri
);
1052 G_MODULE_EXPORT
void on_help_shortcuts1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1054 keybindings_show_shortcuts();
1058 G_MODULE_EXPORT
void on_website1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1060 utils_open_browser(GEANY_HOMEPAGE
);
1064 G_MODULE_EXPORT
void on_help_menu_item_donate_activate(GtkMenuItem
*item
, gpointer user_data
)
1066 utils_open_browser(GEANY_DONATE
);
1070 G_MODULE_EXPORT
void on_help_menu_item_wiki_activate(GtkMenuItem
*item
, gpointer user_data
)
1072 utils_open_browser(GEANY_WIKI
);
1076 G_MODULE_EXPORT
void on_help_menu_item_bug_report_activate(GtkMenuItem
*item
, gpointer user_data
)
1078 utils_open_browser(GEANY_BUG_REPORT
);
1082 G_MODULE_EXPORT
void on_comments_function_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1084 GeanyDocument
*doc
= document_get_current();
1086 const gchar
*cur_tag
= NULL
;
1087 gint line
= -1, pos
= 0;
1089 if (doc
== NULL
|| doc
->file_type
== NULL
)
1091 ui_set_statusbar(FALSE
,
1092 _("Please set the filetype for the current file before using this function."));
1096 /* symbols_get_current_function returns -1 on failure, so sci_get_position_from_line
1097 * returns the current position, so it should be safe */
1098 line
= symbols_get_current_function(doc
, &cur_tag
);
1099 pos
= sci_get_position_from_line(doc
->editor
->sci
, line
);
1101 text
= templates_get_template_function(doc
, cur_tag
);
1103 sci_start_undo_action(doc
->editor
->sci
);
1104 sci_insert_text(doc
->editor
->sci
, pos
, text
);
1105 sci_end_undo_action(doc
->editor
->sci
);
1110 static void insert_multiline_comment(GeanyDocument
*doc
, gint pos
)
1112 g_return_if_fail(doc
!= NULL
);
1113 g_return_if_fail(pos
== -1 || pos
>= 0);
1115 if (doc
->file_type
== NULL
)
1117 ui_set_statusbar(FALSE
,
1118 _("Please set the filetype for the current file before using this function."));
1122 if (doc
->file_type
->comment_open
|| doc
->file_type
->comment_single
)
1124 /* editor_insert_multiline_comment() uses editor_info.click_pos */
1126 editor_info
.click_pos
= sci_get_current_position(doc
->editor
->sci
);
1128 editor_info
.click_pos
= pos
;
1129 editor_insert_multiline_comment(doc
->editor
);
1136 G_MODULE_EXPORT
void on_comments_multiline_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1138 insert_multiline_comment(document_get_current(), editor_info
.click_pos
);
1142 G_MODULE_EXPORT
void on_menu_comments_multiline_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1144 insert_multiline_comment(document_get_current(), -1);
1148 static void insert_comment_template(GeanyDocument
*doc
, gint pos
, guint
template)
1152 g_return_if_fail(doc
!= NULL
);
1153 g_return_if_fail(pos
== -1 || pos
>= 0);
1154 g_return_if_fail(template < GEANY_MAX_TEMPLATES
);
1157 pos
= sci_get_current_position(doc
->editor
->sci
);
1159 text
= templates_get_template_licence(doc
, template);
1161 sci_start_undo_action(doc
->editor
->sci
);
1162 sci_insert_text(doc
->editor
->sci
, pos
, text
);
1163 sci_end_undo_action(doc
->editor
->sci
);
1168 G_MODULE_EXPORT
void on_comments_gpl_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1170 insert_comment_template(document_get_current(), editor_info
.click_pos
, GEANY_TEMPLATE_GPL
);
1174 G_MODULE_EXPORT
void on_menu_comments_gpl_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1176 insert_comment_template(document_get_current(), -1, GEANY_TEMPLATE_GPL
);
1180 G_MODULE_EXPORT
void on_comments_bsd_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1182 insert_comment_template(document_get_current(), editor_info
.click_pos
, GEANY_TEMPLATE_BSD
);
1186 G_MODULE_EXPORT
void on_menu_comments_bsd_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1188 insert_comment_template(document_get_current(), -1, GEANY_TEMPLATE_BSD
);
1192 G_MODULE_EXPORT
void on_comments_changelog_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1194 GeanyDocument
*doc
= document_get_current();
1197 g_return_if_fail(doc
!= NULL
);
1199 text
= templates_get_template_changelog(doc
);
1200 sci_start_undo_action(doc
->editor
->sci
);
1201 sci_insert_text(doc
->editor
->sci
, 0, text
);
1202 /* sets the cursor to the right position to type the changelog text,
1203 * the template has 21 chars + length of name and email */
1204 sci_goto_pos(doc
->editor
->sci
, 21 + strlen(template_prefs
.developer
) + strlen(template_prefs
.mail
), TRUE
);
1205 sci_end_undo_action(doc
->editor
->sci
);
1211 G_MODULE_EXPORT
void on_comments_fileheader_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1213 GeanyDocument
*doc
= document_get_current();
1218 g_return_if_fail(doc
!= NULL
);
1220 ft
= doc
->file_type
;
1221 fname
= doc
->file_name
;
1222 text
= templates_get_template_fileheader(FILETYPE_ID(ft
), fname
);
1224 sci_start_undo_action(doc
->editor
->sci
);
1225 sci_insert_text(doc
->editor
->sci
, 0, text
);
1226 sci_goto_pos(doc
->editor
->sci
, 0, FALSE
);
1227 sci_end_undo_action(doc
->editor
->sci
);
1232 G_MODULE_EXPORT
void on_file_properties_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1234 GeanyDocument
*doc
= document_get_current();
1235 g_return_if_fail(doc
!= NULL
);
1237 dialogs_show_file_properties(doc
);
1241 G_MODULE_EXPORT
void on_menu_fold_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1243 GeanyDocument
*doc
= document_get_current();
1244 g_return_if_fail(doc
!= NULL
);
1246 editor_fold_all(doc
->editor
);
1250 G_MODULE_EXPORT
void on_menu_unfold_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1252 GeanyDocument
*doc
= document_get_current();
1253 g_return_if_fail(doc
!= NULL
);
1255 editor_unfold_all(doc
->editor
);
1259 void on_toolbutton_run_clicked(GtkAction
*action
, gpointer user_data
)
1261 keybindings_send_command(GEANY_KEY_GROUP_BUILD
, GEANY_KEYS_BUILD_RUN
);
1265 G_MODULE_EXPORT
void on_menu_remove_indicators1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1267 GeanyDocument
*doc
= document_get_current();
1268 g_return_if_fail(doc
!= NULL
);
1270 editor_indicator_clear(doc
->editor
, GEANY_INDICATOR_ERROR
);
1274 G_MODULE_EXPORT
void on_print1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1276 GeanyDocument
*doc
= document_get_current();
1277 g_return_if_fail(doc
!= NULL
);
1279 printing_print_doc(doc
);
1283 G_MODULE_EXPORT
void on_menu_select_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1285 GeanyDocument
*doc
= document_get_current();
1286 g_return_if_fail(doc
!= NULL
);
1288 sci_select_all(doc
->editor
->sci
);
1292 G_MODULE_EXPORT
void on_menu_show_sidebar1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
1294 if (ignore_callback
)
1297 ui_prefs
.sidebar_visible
= ! ui_prefs
.sidebar_visible
;
1299 /* show built-in tabs if no tabs visible */
1300 if (ui_prefs
.sidebar_visible
&&
1301 ! interface_prefs
.sidebar_openfiles_visible
&& ! interface_prefs
.sidebar_symbol_visible
&&
1302 gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets
.sidebar_notebook
)) <= 2)
1304 interface_prefs
.sidebar_openfiles_visible
= TRUE
;
1305 interface_prefs
.sidebar_symbol_visible
= TRUE
;
1308 /* if window has input focus, set it back to the editor before toggling off */
1309 if (! ui_prefs
.sidebar_visible
&&
1310 gtk_container_get_focus_child(GTK_CONTAINER(main_widgets
.sidebar_notebook
)) != NULL
)
1312 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
1315 ui_sidebar_show_hide();
1319 G_MODULE_EXPORT
void on_menu_write_unicode_bom1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
1321 if (! ignore_callback
)
1323 GeanyDocument
*doc
= document_get_current();
1325 g_return_if_fail(doc
!= NULL
);
1332 document_undo_add(doc
, UNDO_BOM
, GINT_TO_POINTER(doc
->has_bom
));
1334 doc
->has_bom
= ! doc
->has_bom
;
1336 ui_update_statusbar(doc
, -1);
1341 G_MODULE_EXPORT
void on_menu_comment_line1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1343 GeanyDocument
*doc
= document_get_current();
1344 g_return_if_fail(doc
!= NULL
);
1346 editor_do_comment(doc
->editor
, -1, FALSE
, FALSE
, TRUE
);
1350 G_MODULE_EXPORT
void on_menu_uncomment_line1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1352 GeanyDocument
*doc
= document_get_current();
1353 g_return_if_fail(doc
!= NULL
);
1355 editor_do_uncomment(doc
->editor
, -1, FALSE
);
1359 G_MODULE_EXPORT
void on_menu_toggle_line_commentation1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1361 GeanyDocument
*doc
= document_get_current();
1362 g_return_if_fail(doc
!= NULL
);
1364 editor_do_comment_toggle(doc
->editor
);
1368 G_MODULE_EXPORT
void on_menu_increase_indent1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1370 GeanyDocument
*doc
= document_get_current();
1371 g_return_if_fail(doc
!= NULL
);
1373 editor_indent(doc
->editor
, TRUE
);
1377 G_MODULE_EXPORT
void on_menu_decrease_indent1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1379 GeanyDocument
*doc
= document_get_current();
1380 g_return_if_fail(doc
!= NULL
);
1382 editor_indent(doc
->editor
, FALSE
);
1386 G_MODULE_EXPORT
void on_next_message1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1388 if (! ui_tree_view_find_next(GTK_TREE_VIEW(msgwindow
.tree_msg
),
1389 msgwin_goto_messages_file_line
))
1390 ui_set_statusbar(FALSE
, _("No more message items."));
1394 G_MODULE_EXPORT
void on_previous_message1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1396 if (! ui_tree_view_find_previous(GTK_TREE_VIEW(msgwindow
.tree_msg
),
1397 msgwin_goto_messages_file_line
))
1398 ui_set_statusbar(FALSE
, _("No more message items."));
1402 G_MODULE_EXPORT
void on_project_new1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1408 G_MODULE_EXPORT
void on_project_open1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1414 G_MODULE_EXPORT
void on_project_close1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1416 project_close(TRUE
);
1420 G_MODULE_EXPORT
void on_project_properties1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1422 project_properties();
1426 G_MODULE_EXPORT
void on_menu_project1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1428 static GtkWidget
*item_close
= NULL
;
1429 static GtkWidget
*item_properties
= NULL
;
1431 if (item_close
== NULL
)
1433 item_close
= ui_lookup_widget(main_widgets
.window
, "project_close1");
1434 item_properties
= ui_lookup_widget(main_widgets
.window
, "project_properties1");
1437 gtk_widget_set_sensitive(item_close
, (app
->project
!= NULL
));
1438 gtk_widget_set_sensitive(item_properties
, (app
->project
!= NULL
));
1439 gtk_widget_set_sensitive(ui_widgets
.recent_projects_menuitem
,
1440 g_queue_get_length(ui_prefs
.recent_projects_queue
) > 0);
1444 G_MODULE_EXPORT
void on_menu_open_selected_file1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1446 GeanyDocument
*doc
= document_get_current();
1451 wc
= GEANY_WORDCHARS
"./-" "\\";
1453 wc
= GEANY_WORDCHARS
"./-";
1456 g_return_if_fail(doc
!= NULL
);
1458 sel
= editor_get_default_selection(doc
->editor
, TRUE
, wc
);
1459 SETPTR(sel
, utils_get_locale_from_utf8(sel
));
1463 gchar
*filename
= NULL
;
1465 if (g_path_is_absolute(sel
))
1466 filename
= g_strdup(sel
);
1468 { /* relative filename, add the path of the current file */
1471 path
= utils_get_current_file_dir_utf8();
1472 SETPTR(path
, utils_get_locale_from_utf8(path
));
1474 path
= g_get_current_dir();
1476 filename
= g_build_path(G_DIR_SEPARATOR_S
, path
, sel
, NULL
);
1478 if (! g_file_test(filename
, G_FILE_TEST_EXISTS
) &&
1479 app
->project
!= NULL
&& !EMPTY(app
->project
->base_path
))
1481 /* try the project's base path */
1482 SETPTR(path
, project_get_base_path());
1483 SETPTR(path
, utils_get_locale_from_utf8(path
));
1484 SETPTR(filename
, g_build_path(G_DIR_SEPARATOR_S
, path
, sel
, NULL
));
1488 if (! g_file_test(filename
, G_FILE_TEST_EXISTS
))
1489 SETPTR(filename
, g_build_path(G_DIR_SEPARATOR_S
, "/usr/local/include", sel
, NULL
));
1491 if (! g_file_test(filename
, G_FILE_TEST_EXISTS
))
1492 SETPTR(filename
, g_build_path(G_DIR_SEPARATOR_S
, "/usr/include", sel
, NULL
));
1496 if (g_file_test(filename
, G_FILE_TEST_EXISTS
))
1497 document_open_file(filename
, FALSE
, NULL
, NULL
);
1500 SETPTR(sel
, utils_get_utf8_from_locale(sel
));
1501 ui_set_statusbar(TRUE
, _("Could not open file %s (File not found)"), sel
);
1510 G_MODULE_EXPORT
void on_remove_markers1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1512 GeanyDocument
*doc
= document_get_current();
1513 g_return_if_fail(doc
!= NULL
);
1515 sci_marker_delete_all(doc
->editor
->sci
, 0); /* delete the yellow tag marker */
1516 sci_marker_delete_all(doc
->editor
->sci
, 1); /* delete user markers */
1517 editor_indicator_clear(doc
->editor
, GEANY_INDICATOR_SEARCH
);
1521 G_MODULE_EXPORT
void on_load_tags1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1523 symbols_show_load_tags_dialog();
1527 G_MODULE_EXPORT
void on_context_action1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1529 gchar
*word
, *command
;
1530 GError
*error
= NULL
;
1531 GeanyDocument
*doc
= document_get_current();
1533 g_return_if_fail(doc
!= NULL
);
1535 if (sci_has_selection(doc
->editor
->sci
))
1536 { /* take selected text if there is a selection */
1537 word
= sci_get_selection_contents(doc
->editor
->sci
);
1541 word
= g_strdup(editor_info
.current_word
);
1544 /* use the filetype specific command if available, fallback to global command otherwise */
1545 if (doc
->file_type
!= NULL
&&
1546 !EMPTY(doc
->file_type
->context_action_cmd
))
1548 command
= g_strdup(doc
->file_type
->context_action_cmd
);
1552 command
= g_strdup(tool_prefs
.context_action_cmd
);
1555 /* substitute the wildcard %s and run the command if it is non empty */
1556 if (G_LIKELY(!EMPTY(command
)))
1558 utils_str_replace_all(&command
, "%s", word
);
1560 if (! g_spawn_command_line_async(command
, &error
))
1562 ui_set_statusbar(TRUE
, "Context action command failed: %s", error
->message
);
1563 g_error_free(error
);
1571 G_MODULE_EXPORT
void on_menu_toggle_all_additional_widgets1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1573 static gint hide_all
= -1;
1574 GtkCheckMenuItem
*msgw
= GTK_CHECK_MENU_ITEM(
1575 ui_lookup_widget(main_widgets
.window
, "menu_show_messages_window1"));
1576 GtkCheckMenuItem
*toolbari
= GTK_CHECK_MENU_ITEM(
1577 ui_lookup_widget(main_widgets
.window
, "menu_show_toolbar1"));
1579 /* get the initial state (necessary if Geany was closed with hide_all = TRUE) */
1580 if (G_UNLIKELY(hide_all
== -1))
1582 if (! gtk_check_menu_item_get_active(msgw
) &&
1583 ! interface_prefs
.show_notebook_tabs
&&
1584 ! gtk_check_menu_item_get_active(toolbari
))
1592 hide_all
= ! hide_all
; /* toggle */
1596 if (gtk_check_menu_item_get_active(msgw
))
1597 gtk_check_menu_item_set_active(msgw
, ! gtk_check_menu_item_get_active(msgw
));
1599 interface_prefs
.show_notebook_tabs
= FALSE
;
1600 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets
.notebook
), interface_prefs
.show_notebook_tabs
);
1602 ui_statusbar_showhide(FALSE
);
1604 if (gtk_check_menu_item_get_active(toolbari
))
1605 gtk_check_menu_item_set_active(toolbari
, ! gtk_check_menu_item_get_active(toolbari
));
1610 if (! gtk_check_menu_item_get_active(msgw
))
1611 gtk_check_menu_item_set_active(msgw
, ! gtk_check_menu_item_get_active(msgw
));
1613 interface_prefs
.show_notebook_tabs
= TRUE
;
1614 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets
.notebook
), interface_prefs
.show_notebook_tabs
);
1616 ui_statusbar_showhide(TRUE
);
1618 if (! gtk_check_menu_item_get_active(toolbari
))
1619 gtk_check_menu_item_set_active(toolbari
, ! gtk_check_menu_item_get_active(toolbari
));
1624 void on_toolbutton_forward_activate(GtkAction
*menuitem
, gpointer user_data
)
1626 navqueue_go_forward();
1630 void on_toolbutton_back_activate(GtkAction
*menuitem
, gpointer user_data
)
1636 gboolean
on_motion_event(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
)
1638 if (prefs
.auto_focus
&& ! gtk_widget_has_focus(widget
))
1639 gtk_widget_grab_focus(widget
);
1645 static void set_indent_type(GtkCheckMenuItem
*menuitem
, GeanyIndentType type
)
1649 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
1652 doc
= document_get_current();
1653 g_return_if_fail(doc
!= NULL
);
1655 editor_set_indent(doc
->editor
, type
, doc
->editor
->indent_width
);
1656 ui_update_statusbar(doc
, -1);
1660 G_MODULE_EXPORT
void on_tabs1_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
1662 set_indent_type(menuitem
, GEANY_INDENT_TYPE_TABS
);
1666 G_MODULE_EXPORT
void on_spaces1_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
1668 set_indent_type(menuitem
, GEANY_INDENT_TYPE_SPACES
);
1672 G_MODULE_EXPORT
void on_tabs_and_spaces1_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
1674 set_indent_type(menuitem
, GEANY_INDENT_TYPE_BOTH
);
1678 G_MODULE_EXPORT
void on_strip_trailing_spaces1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1682 if (ignore_callback
)
1685 doc
= document_get_current();
1686 g_return_if_fail(doc
!= NULL
);
1688 editor_strip_trailing_spaces(doc
->editor
);
1692 G_MODULE_EXPORT
void on_page_setup1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1694 printing_page_setup_gtk();
1698 G_MODULE_EXPORT gboolean
on_escape_key_press_event(GtkWidget
*widget
, GdkEventKey
*event
, gpointer user_data
)
1700 guint state
= event
->state
& gtk_accelerator_get_default_mod_mask();
1702 /* make pressing escape in the sidebar and toolbar focus the editor */
1703 if (event
->keyval
== GDK_Escape
&& state
== 0)
1705 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
1712 G_MODULE_EXPORT
void on_line_breaking1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1716 if (ignore_callback
)
1719 doc
= document_get_current();
1720 g_return_if_fail(doc
!= NULL
);
1722 doc
->editor
->line_breaking
= !doc
->editor
->line_breaking
;
1726 G_MODULE_EXPORT
void on_replace_spaces_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1728 GeanyDocument
*doc
= document_get_current();
1730 g_return_if_fail(doc
!= NULL
);
1732 editor_replace_spaces(doc
->editor
);
1736 G_MODULE_EXPORT
void on_search1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1738 GtkWidget
*next_message
= ui_lookup_widget(main_widgets
.window
, "next_message1");
1739 GtkWidget
*previous_message
= ui_lookup_widget(main_widgets
.window
, "previous_message1");
1740 gboolean have_messages
;
1742 /* enable commands if the messages window has any items */
1743 have_messages
= gtk_tree_model_iter_n_children(GTK_TREE_MODEL(msgwindow
.store_msg
),
1746 gtk_widget_set_sensitive(next_message
, have_messages
);
1747 gtk_widget_set_sensitive(previous_message
, have_messages
);
1751 /* simple implementation (vs. close all which doesn't close documents if cancelled),
1752 * if user_data is set, it is the GeanyDocument to keep */
1753 G_MODULE_EXPORT
void on_close_other_documents1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1756 GeanyDocument
*cur_doc
= user_data
;
1758 if (cur_doc
== NULL
)
1759 cur_doc
= document_get_current();
1761 for (i
= 0; i
< documents_array
->len
; i
++)
1763 GeanyDocument
*doc
= documents
[i
];
1765 if (doc
== cur_doc
|| ! doc
->is_valid
)
1768 if (! document_close(doc
))
1774 G_MODULE_EXPORT
void on_menu_reload_configuration1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1776 main_reload_configuration();
1780 G_MODULE_EXPORT
void on_debug_messages1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1782 log_show_debug_messages_dialog();
1786 G_MODULE_EXPORT
void on_send_selection_to_vte1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1789 if (vte_info
.have_vte
)
1790 vte_send_selection_to_vte();
1795 G_MODULE_EXPORT gboolean
on_window_state_event(GtkWidget
*widget
, GdkEventWindowState
*event
, gpointer user_data
)
1798 if (event
->changed_mask
& GDK_WINDOW_STATE_FULLSCREEN
)
1800 static GtkWidget
*menuitem
= NULL
;
1802 if (menuitem
== NULL
)
1803 menuitem
= ui_lookup_widget(widget
, "menu_fullscreen1");
1805 ignore_callback
= TRUE
;
1807 ui_prefs
.fullscreen
= (event
->new_window_state
& GDK_WINDOW_STATE_FULLSCREEN
) ? TRUE
: FALSE
;
1808 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem
), ui_prefs
.fullscreen
);
1810 ignore_callback
= FALSE
;
1816 static void show_notebook_page(const gchar
*notebook_name
, const gchar
*page_name
)
1819 GtkNotebook
*notebook
;
1821 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, page_name
);
1822 notebook
= GTK_NOTEBOOK(ui_lookup_widget(ui_widgets
.prefs_dialog
, notebook_name
));
1824 if (notebook
!= NULL
&& widget
!= NULL
)
1825 gtk_notebook_set_current_page(notebook
, gtk_notebook_page_num(notebook
, widget
));
1829 G_MODULE_EXPORT
void on_customize_toolbar1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1831 prefs_show_dialog();
1833 /* select the Interface page */
1834 show_notebook_page("notebook2", "notebook6");
1835 /* select the Toolbar subpage */
1836 show_notebook_page("notebook6", "vbox15");
1840 G_MODULE_EXPORT
void on_button_customize_toolbar_clicked(GtkButton
*button
, gpointer user_data
)
1842 toolbar_configure(GTK_WINDOW(ui_widgets
.prefs_dialog
));
1846 G_MODULE_EXPORT
void on_cut_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1848 keybindings_send_command(GEANY_KEY_GROUP_CLIPBOARD
, GEANY_KEYS_CLIPBOARD_CUTLINE
);
1852 G_MODULE_EXPORT
void on_copy_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1854 keybindings_send_command(GEANY_KEY_GROUP_CLIPBOARD
, GEANY_KEYS_CLIPBOARD_COPYLINE
);
1858 G_MODULE_EXPORT
void on_delete_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1860 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_DELETELINE
);
1864 G_MODULE_EXPORT
void on_duplicate_line_or_selection1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1866 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_DUPLICATELINE
);
1870 G_MODULE_EXPORT
void on_select_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1872 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_LINE
);
1876 G_MODULE_EXPORT
void on_select_current_paragraph1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1878 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_PARAGRAPH
);
1882 G_MODULE_EXPORT
void on_insert_alternative_white_space1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1884 keybindings_send_command(GEANY_KEY_GROUP_INSERT
, GEANY_KEYS_INSERT_ALTWHITESPACE
);
1888 G_MODULE_EXPORT
void on_go_to_next_marker1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1890 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_NEXTMARKER
);
1894 G_MODULE_EXPORT
void on_go_to_previous_marker1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1896 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_PREVIOUSMARKER
);
1900 G_MODULE_EXPORT
void on_reflow_lines_block1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1902 keybindings_send_command(GEANY_KEY_GROUP_FORMAT
, GEANY_KEYS_FORMAT_REFLOWPARAGRAPH
);
1906 G_MODULE_EXPORT
void on_move_lines_up1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1908 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_MOVELINEUP
);
1912 G_MODULE_EXPORT
void on_move_lines_down1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1914 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_MOVELINEDOWN
);
1918 G_MODULE_EXPORT
void on_smart_line_indent1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1920 keybindings_send_command(GEANY_KEY_GROUP_FORMAT
, GEANY_KEYS_FORMAT_AUTOINDENT
);
1924 G_MODULE_EXPORT
void on_plugin_preferences1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1927 plugin_show_configure(NULL
);
1932 G_MODULE_EXPORT
void on_indent_width_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1938 if (ignore_callback
)
1941 label
= ui_menu_item_get_text(menuitem
);
1942 width
= atoi(label
);
1945 doc
= document_get_current();
1946 if (doc
!= NULL
&& width
> 0)
1947 editor_set_indent_width(doc
->editor
, width
);
1951 G_MODULE_EXPORT
void on_reset_indentation1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1956 document_apply_indent_settings(documents
[i
]);
1958 ui_update_statusbar(NULL
, -1);
1959 ui_document_show_hide(NULL
);
1963 G_MODULE_EXPORT
void on_mark_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1965 keybindings_send_command(GEANY_KEY_GROUP_SEARCH
, GEANY_KEYS_SEARCH_MARKALL
);
1969 G_MODULE_EXPORT
void on_detect_type_from_file_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1971 GeanyDocument
*doc
= document_get_current();
1972 GeanyIndentType type
;
1974 if (doc
!= NULL
&& document_detect_indent_type(doc
, &type
))
1976 editor_set_indent_type(doc
->editor
, type
);
1977 ui_document_show_hide(doc
);
1982 G_MODULE_EXPORT
void on_detect_width_from_file_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1984 GeanyDocument
*doc
= document_get_current();
1987 if (doc
!= NULL
&& document_detect_indent_width(doc
, &width
))
1989 editor_set_indent_width(doc
->editor
, width
);
1990 ui_document_show_hide(doc
);