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; */
160 static gboolean
check_no_unsaved(void)
164 for (i
= 0; i
< documents_array
->len
; i
++)
166 if (documents
[i
]->is_valid
&& documents
[i
]->changed
)
171 return TRUE
; /* no unsaved edits */
175 /* should only be called from on_window_delete_event */
176 static void quit_app(void)
178 configuration_save();
180 if (app
->project
!= NULL
)
181 project_close(FALSE
); /* save project session files */
183 document_close_all();
185 main_status
.quitting
= TRUE
;
191 /* wrapper function to abort exit process if cancel button is pressed */
192 G_MODULE_EXPORT gboolean
on_window_delete_event(GtkWidget
*widget
, GdkEvent
*event
, gpointer gdata
)
194 main_status
.quitting
= TRUE
;
196 if (! check_no_unsaved())
198 if (document_account_for_unsaved())
205 if (! prefs
.confirm_exit
||
206 dialogs_show_question_full(NULL
, GTK_STOCK_QUIT
, GTK_STOCK_CANCEL
, NULL
,
207 _("Do you really want to quit?")))
213 main_status
.quitting
= FALSE
;
222 G_MODULE_EXPORT
void on_new1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
224 document_new_file(NULL
, NULL
, NULL
);
228 /* create a new file and copy file content and properties */
229 G_MODULE_EXPORT
void on_clone1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
231 GeanyDocument
*old_doc
= document_get_current();
234 document_clone(old_doc
);
238 G_MODULE_EXPORT
void on_save1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
240 GeanyDocument
*doc
= document_get_current();
244 document_save_file(doc
, ui_prefs
.allow_always_save
);
249 G_MODULE_EXPORT
void on_save_as1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
251 dialogs_show_save_as();
255 G_MODULE_EXPORT
void on_save_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
257 guint i
, max
= (guint
) gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets
.notebook
));
258 GeanyDocument
*doc
, *cur_doc
= document_get_current();
261 /* iterate over documents in tabs order */
262 for (i
= 0; i
< max
; i
++)
264 doc
= document_get_from_page(i
);
268 if (document_save_file(doc
, FALSE
))
274 ui_set_statusbar(FALSE
, ngettext("%d file saved.", "%d files saved.", count
), count
);
275 /* saving may have changed window title, sidebar for another doc, so update */
276 document_show_tab(cur_doc
);
277 sidebar_update_tag_list(cur_doc
, TRUE
);
278 ui_set_window_title(cur_doc
);
282 G_MODULE_EXPORT
void on_close_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
284 document_close_all();
288 G_MODULE_EXPORT
void on_close1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
290 GeanyDocument
*doc
= document_get_current();
297 G_MODULE_EXPORT
void on_quit1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
299 on_window_delete_event(NULL
, NULL
, NULL
);
303 G_MODULE_EXPORT
void on_file1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
305 gtk_widget_set_sensitive(ui_widgets
.recent_files_menuitem
,
306 g_queue_get_length(ui_prefs
.recent_queue
) > 0);
307 /* hide Page setup when GTK printing is not used */
308 ui_widget_show_hide(ui_widgets
.print_page_setup
, printing_prefs
.use_gtk_printing
);
312 /* edit actions, c&p & co, from menu bar and from popup menu */
313 G_MODULE_EXPORT
void on_edit1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
316 GeanyDocument
*doc
= document_get_current();
318 ui_update_menu_copy_items(doc
);
319 ui_update_insert_include_item(doc
, 1);
321 item
= ui_lookup_widget(main_widgets
.window
, "plugin_preferences1");
323 gtk_widget_hide(item
);
325 gtk_widget_set_sensitive(item
, plugins_have_preferences());
330 G_MODULE_EXPORT
void on_undo1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
332 GeanyDocument
*doc
= document_get_current();
334 g_return_if_fail(doc
!= NULL
);
336 if (document_can_undo(doc
))
338 sci_cancel(doc
->editor
->sci
);
344 G_MODULE_EXPORT
void on_redo1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
346 GeanyDocument
*doc
= document_get_current();
348 g_return_if_fail(doc
!= NULL
);
350 if (document_can_redo(doc
))
352 sci_cancel(doc
->editor
->sci
);
358 G_MODULE_EXPORT
void on_cut1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
360 GeanyDocument
*doc
= document_get_current();
361 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
363 if (GTK_IS_EDITABLE(focusw
))
364 gtk_editable_cut_clipboard(GTK_EDITABLE(focusw
));
366 if (IS_SCINTILLA(focusw
) && doc
!= NULL
)
367 sci_cut(doc
->editor
->sci
);
369 if (GTK_IS_TEXT_VIEW(focusw
))
371 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(
372 GTK_TEXT_VIEW(focusw
));
373 gtk_text_buffer_cut_clipboard(buffer
, gtk_clipboard_get(GDK_NONE
), TRUE
);
378 G_MODULE_EXPORT
void on_copy1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
380 GeanyDocument
*doc
= document_get_current();
381 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
383 if (GTK_IS_EDITABLE(focusw
))
384 gtk_editable_copy_clipboard(GTK_EDITABLE(focusw
));
386 if (IS_SCINTILLA(focusw
) && doc
!= NULL
)
387 sci_copy(doc
->editor
->sci
);
389 if (GTK_IS_TEXT_VIEW(focusw
))
391 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(
392 GTK_TEXT_VIEW(focusw
));
393 gtk_text_buffer_copy_clipboard(buffer
, gtk_clipboard_get(GDK_NONE
));
398 G_MODULE_EXPORT
void on_paste1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
400 GeanyDocument
*doc
= document_get_current();
401 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
403 if (GTK_IS_EDITABLE(focusw
))
404 gtk_editable_paste_clipboard(GTK_EDITABLE(focusw
));
406 if (IS_SCINTILLA(focusw
) && doc
!= NULL
)
408 sci_paste(doc
->editor
->sci
);
411 if (GTK_IS_TEXT_VIEW(focusw
))
413 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(
414 GTK_TEXT_VIEW(focusw
));
415 gtk_text_buffer_paste_clipboard(buffer
, gtk_clipboard_get(GDK_NONE
), NULL
,
421 G_MODULE_EXPORT
void on_delete1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
423 GeanyDocument
*doc
= document_get_current();
424 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
426 if (GTK_IS_EDITABLE(focusw
))
427 gtk_editable_delete_selection(GTK_EDITABLE(focusw
));
429 if (IS_SCINTILLA(focusw
) && doc
!= NULL
&& sci_has_selection(doc
->editor
->sci
))
430 sci_clear(doc
->editor
->sci
);
432 if (GTK_IS_TEXT_VIEW(focusw
))
434 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(
435 GTK_TEXT_VIEW(focusw
));
436 gtk_text_buffer_delete_selection(buffer
, TRUE
, TRUE
);
441 G_MODULE_EXPORT
void on_preferences1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
447 /* about menu item */
448 G_MODULE_EXPORT
void on_info1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
455 G_MODULE_EXPORT
void on_open1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
457 dialogs_show_open_file();
462 G_MODULE_EXPORT
void on_toolbutton_reload_clicked(GtkAction
*action
, gpointer user_data
)
464 GeanyDocument
*doc
= document_get_current();
466 g_return_if_fail(doc
!= NULL
);
468 document_reload_prompt(doc
, NULL
);
472 G_MODULE_EXPORT
void on_change_font1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
474 dialogs_show_open_font();
478 /* store text, clear search flags so we can use Search->Find Next/Previous */
479 static void setup_find(const gchar
*text
, gboolean backwards
)
481 SETPTR(search_data
.text
, g_strdup(text
));
482 SETPTR(search_data
.original_text
, g_strdup(text
));
483 search_data
.flags
= 0;
484 search_data
.backwards
= backwards
;
485 search_data
.search_bar
= TRUE
;
489 static void do_toolbar_search(const gchar
*text
, gboolean incremental
, gboolean backwards
)
491 GeanyDocument
*doc
= document_get_current();
494 setup_find(text
, backwards
);
495 result
= document_search_bar_find(doc
, search_data
.text
, 0, incremental
, backwards
);
496 if (search_data
.search_bar
)
497 ui_set_search_entry_background(toolbar_get_widget_child_by_name("SearchEntry"), result
);
502 void on_toolbar_search_entry_changed(GtkAction
*action
, const gchar
*text
, gpointer user_data
)
504 do_toolbar_search(text
, TRUE
, FALSE
);
509 void on_toolbar_search_entry_activate(GtkAction
*action
, const gchar
*text
, gpointer user_data
)
511 do_toolbar_search(text
, FALSE
, GPOINTER_TO_INT(user_data
));
516 void on_toolbutton_search_clicked(GtkAction
*action
, gpointer user_data
)
518 GeanyDocument
*doc
= document_get_current();
520 GtkWidget
*entry
= toolbar_get_widget_child_by_name("SearchEntry");
524 const gchar
*text
= gtk_entry_get_text(GTK_ENTRY(entry
));
526 setup_find(text
, FALSE
);
527 result
= document_search_bar_find(doc
, search_data
.text
, 0, FALSE
, FALSE
);
528 if (search_data
.search_bar
)
529 ui_set_search_entry_background(entry
, result
);
532 on_find1_activate(NULL
, NULL
);
536 /* hides toolbar from toolbar popup menu */
537 G_MODULE_EXPORT
void on_hide_toolbar1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
539 GtkWidget
*tool_item
= ui_lookup_widget(GTK_WIDGET(main_widgets
.window
), "menu_show_toolbar1");
540 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(tool_item
), FALSE
);
544 /* zoom in from menu bar and popup menu */
545 G_MODULE_EXPORT
void on_zoom_in1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
547 GeanyDocument
*doc
= document_get_current();
549 g_return_if_fail(doc
!= NULL
);
551 sci_zoom_in(doc
->editor
->sci
);
555 /* zoom out from menu bar and popup menu */
556 G_MODULE_EXPORT
void on_zoom_out1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
558 GeanyDocument
*doc
= document_get_current();
560 g_return_if_fail(doc
!= NULL
);
562 sci_zoom_out(doc
->editor
->sci
);
566 G_MODULE_EXPORT
void on_normal_size1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
568 GeanyDocument
*doc
= document_get_current();
570 g_return_if_fail(doc
!= NULL
);
572 sci_zoom_off(doc
->editor
->sci
);
576 static gboolean
delayed_check_disk_status(gpointer data
)
578 document_check_disk_status(data
, FALSE
);
583 /* Changes window-title after switching tabs and lots of other things.
584 * note: using 'after' makes Scintilla redraw before the UI, appearing more responsive */
585 G_MODULE_EXPORT
void on_notebook1_switch_page_after(GtkNotebook
*notebook
, gpointer page
,
586 guint page_num
, gpointer user_data
)
590 if (G_UNLIKELY(main_status
.opening_session_files
|| main_status
.closing_all
))
593 if (page_num
== (guint
) -1 && page
!= NULL
)
594 doc
= document_find_by_sci(SCINTILLA(page
));
596 doc
= document_get_from_page(page_num
);
600 sidebar_select_openfiles_item(doc
);
601 ui_save_buttons_toggle(doc
->changed
);
602 ui_set_window_title(doc
);
603 ui_update_statusbar(doc
, -1);
604 ui_update_popup_reundo_items(doc
);
605 ui_document_show_hide(doc
); /* update the document menu */
606 build_menu_update(doc
);
607 sidebar_update_tag_list(doc
, FALSE
);
608 document_highlight_tags(doc
);
610 /* We delay the check to avoid weird fast, unintended switching of notebook pages when
611 * the 'file has changed' dialog is shown while the switch event is not yet completely
612 * finished. So, we check after the switch has been performed to be safe. */
613 g_idle_add(delayed_check_disk_status
, doc
);
616 vte_cwd((doc
->real_path
!= NULL
) ? doc
->real_path
: doc
->file_name
, FALSE
);
619 g_signal_emit_by_name(geany_object
, "document-activate", doc
);
624 G_MODULE_EXPORT
void on_tv_notebook_switch_page(GtkNotebook
*notebook
, gpointer page
,
625 guint page_num
, gpointer user_data
)
627 /* suppress selection changed signal when switching to the open files list */
628 ignore_callback
= TRUE
;
632 G_MODULE_EXPORT
void on_tv_notebook_switch_page_after(GtkNotebook
*notebook
, gpointer page
,
633 guint page_num
, gpointer user_data
)
635 ignore_callback
= FALSE
;
639 static void convert_eol(gint mode
)
641 GeanyDocument
*doc
= document_get_current();
643 g_return_if_fail(doc
!= NULL
);
645 sci_convert_eols(doc
->editor
->sci
, mode
);
646 sci_set_eol_mode(doc
->editor
->sci
, mode
);
647 ui_update_statusbar(doc
, -1);
651 G_MODULE_EXPORT
void on_crlf_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
653 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
656 convert_eol(SC_EOL_CRLF
);
660 G_MODULE_EXPORT
void on_lf_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
662 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
665 convert_eol(SC_EOL_LF
);
669 G_MODULE_EXPORT
void on_cr_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
671 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
674 convert_eol(SC_EOL_CR
);
678 G_MODULE_EXPORT
void on_replace_tabs_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
680 GeanyDocument
*doc
= document_get_current();
682 g_return_if_fail(doc
!= NULL
);
684 editor_replace_tabs(doc
->editor
);
688 gboolean
toolbar_popup_menu(GtkWidget
*widget
, GdkEventButton
*event
, gpointer user_data
)
690 if (event
->button
== 3)
692 gtk_menu_popup(GTK_MENU(ui_widgets
.toolbar_menu
), NULL
, NULL
, NULL
, NULL
, event
->button
, event
->time
);
699 G_MODULE_EXPORT
void on_toggle_case1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
701 GeanyDocument
*doc
= document_get_current();
702 ScintillaObject
*sci
;
704 gboolean keep_sel
= TRUE
;
706 g_return_if_fail(doc
!= NULL
);
708 sci
= doc
->editor
->sci
;
709 if (! sci_has_selection(sci
))
711 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_WORD
);
715 /* either we already had a selection or we created one for current word */
716 if (sci_has_selection(sci
))
718 gchar
*result
= NULL
;
719 gint cmd
= SCI_LOWERCASE
;
720 gboolean rectsel
= (gboolean
) scintilla_send_message(sci
, SCI_SELECTIONISRECTANGLE
, 0, 0);
722 text
= sci_get_selection_contents(sci
);
724 if (utils_str_has_upper(text
))
729 result
= g_utf8_strdown(text
, -1);
736 result
= g_utf8_strup(text
, -1);
741 sci_replace_sel(sci
, result
);
744 sci_set_selection_start(sci
, sci_get_current_position(sci
) - strlen(text
));
747 sci_send_command(sci
, cmd
);
755 G_MODULE_EXPORT
void on_show_toolbar1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
757 if (ignore_callback
) return;
759 toolbar_prefs
.visible
= (toolbar_prefs
.visible
) ? FALSE
: TRUE
;;
760 ui_widget_show_hide(GTK_WIDGET(main_widgets
.toolbar
), toolbar_prefs
.visible
);
764 G_MODULE_EXPORT
void on_fullscreen1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
769 ui_prefs
.fullscreen
= (ui_prefs
.fullscreen
) ? FALSE
: TRUE
;
774 G_MODULE_EXPORT
void on_show_messages_window1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
779 ui_prefs
.msgwindow_visible
= (ui_prefs
.msgwindow_visible
) ? FALSE
: TRUE
;
780 msgwin_show_hide(ui_prefs
.msgwindow_visible
);
784 G_MODULE_EXPORT
void on_menu_color_schemes_activate(GtkImageMenuItem
*imagemenuitem
, gpointer user_data
)
786 highlighting_show_color_scheme_dialog();
790 G_MODULE_EXPORT
void on_markers_margin1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
795 editor_prefs
.show_markers_margin
= ! editor_prefs
.show_markers_margin
;
796 ui_toggle_editor_features(GEANY_EDITOR_SHOW_MARKERS_MARGIN
);
800 G_MODULE_EXPORT
void on_show_line_numbers1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
805 editor_prefs
.show_linenumber_margin
= ! editor_prefs
.show_linenumber_margin
;
806 ui_toggle_editor_features(GEANY_EDITOR_SHOW_LINE_NUMBERS
);
810 G_MODULE_EXPORT
void on_menu_show_white_space1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
815 editor_prefs
.show_white_space
= ! editor_prefs
.show_white_space
;
816 ui_toggle_editor_features(GEANY_EDITOR_SHOW_WHITE_SPACE
);
820 G_MODULE_EXPORT
void on_menu_show_line_endings1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
825 editor_prefs
.show_line_endings
= ! editor_prefs
.show_line_endings
;
826 ui_toggle_editor_features(GEANY_EDITOR_SHOW_LINE_ENDINGS
);
830 G_MODULE_EXPORT
void on_menu_show_indentation_guides1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
835 editor_prefs
.show_indent_guide
= ! editor_prefs
.show_indent_guide
;
836 ui_toggle_editor_features(GEANY_EDITOR_SHOW_INDENTATION_GUIDES
);
840 G_MODULE_EXPORT
void on_line_wrapping1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
842 if (! ignore_callback
)
844 GeanyDocument
*doc
= document_get_current();
845 g_return_if_fail(doc
!= NULL
);
847 editor_set_line_wrapping(doc
->editor
, ! doc
->editor
->line_wrapping
);
852 G_MODULE_EXPORT
void on_set_file_readonly1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
854 if (! ignore_callback
)
856 GeanyDocument
*doc
= document_get_current();
857 g_return_if_fail(doc
!= NULL
);
859 doc
->readonly
= ! doc
->readonly
;
860 sci_set_readonly(doc
->editor
->sci
, doc
->readonly
);
861 ui_update_tab_status(doc
);
862 ui_update_statusbar(doc
, -1);
867 G_MODULE_EXPORT
void on_use_auto_indentation1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
869 if (! ignore_callback
)
871 GeanyDocument
*doc
= document_get_current();
872 g_return_if_fail(doc
!= NULL
);
874 doc
->editor
->auto_indent
= ! doc
->editor
->auto_indent
;
879 static void find_usage(gboolean in_session
)
883 GeanyDocument
*doc
= document_get_current();
885 g_return_if_fail(doc
!= NULL
);
887 if (sci_has_selection(doc
->editor
->sci
))
888 { /* take selected text if there is a selection */
889 search_text
= sci_get_selection_contents(doc
->editor
->sci
);
890 flags
= SCFIND_MATCHCASE
;
894 editor_find_current_word_sciwc(doc
->editor
, -1,
895 editor_info
.current_word
, GEANY_MAX_WORD_LENGTH
);
896 search_text
= g_strdup(editor_info
.current_word
);
897 flags
= SCFIND_MATCHCASE
| SCFIND_WHOLEWORD
;
900 search_find_usage(search_text
, search_text
, flags
, in_session
);
905 G_MODULE_EXPORT
void on_find_document_usage1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
911 G_MODULE_EXPORT
void on_find_usage1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
917 static void goto_tag(gboolean definition
)
919 GeanyDocument
*doc
= document_get_current();
921 g_return_if_fail(doc
!= NULL
);
923 /* update cursor pos for navigating back afterwards */
924 if (!sci_has_selection(doc
->editor
->sci
))
925 sci_set_current_position(doc
->editor
->sci
, editor_info
.click_pos
, FALSE
);
927 /* use the keybinding callback as it checks for selections as well as current word */
929 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_TAGDEFINITION
);
931 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_TAGDECLARATION
);
935 G_MODULE_EXPORT
void on_goto_tag_definition1(GtkMenuItem
*menuitem
, gpointer user_data
)
941 G_MODULE_EXPORT
void on_goto_tag_declaration1(GtkMenuItem
*menuitem
, gpointer user_data
)
947 G_MODULE_EXPORT
void on_count_words1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
953 G_MODULE_EXPORT
void on_show_color_chooser1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
956 GeanyDocument
*doc
= document_get_current();
959 g_return_if_fail(doc
!= NULL
);
961 pos
= sci_get_current_position(doc
->editor
->sci
);
962 editor_find_current_word(doc
->editor
, pos
, colour
, sizeof colour
, GEANY_WORDCHARS
"#");
963 tools_color_chooser(colour
);
967 void on_toolbutton_compile_clicked(GtkAction
*action
, gpointer user_data
)
969 keybindings_send_command(GEANY_KEY_GROUP_BUILD
, GEANY_KEYS_BUILD_COMPILE
);
973 G_MODULE_EXPORT
void on_find1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
975 search_show_find_dialog();
979 G_MODULE_EXPORT
void on_find_next1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
981 search_find_again(FALSE
);
985 G_MODULE_EXPORT
void on_find_previous1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
987 if (search_data
.flags
& SCFIND_REGEXP
)
988 /* Can't reverse search order for a regex (find next ignores search backwards) */
991 search_find_again(TRUE
);
995 G_MODULE_EXPORT
void on_find_nextsel1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
997 search_find_selection(document_get_current(), FALSE
);
1001 G_MODULE_EXPORT
void on_find_prevsel1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1003 search_find_selection(document_get_current(), TRUE
);
1007 G_MODULE_EXPORT
void on_replace1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1009 search_show_replace_dialog();
1013 G_MODULE_EXPORT
void on_find_in_files1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1015 search_show_find_in_files_dialog(NULL
);
1019 static void get_line_and_offset_from_text(const gchar
*text
, gint
*line_no
, gint
*offset
)
1021 if (*text
== '+' || *text
== '-')
1023 *line_no
= atoi(text
+ 1);
1024 *offset
= (*text
== '+') ? 1 : -1;
1028 *line_no
= atoi(text
) - 1;
1034 G_MODULE_EXPORT
void on_go_to_line_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1036 static gchar value
[16] = "";
1039 result
= dialogs_show_input_goto_line(
1040 _("Go to Line"), GTK_WINDOW(main_widgets
.window
),
1041 _("Enter the line you want to go to:"), value
);
1044 GeanyDocument
*doc
= document_get_current();
1048 g_return_if_fail(doc
!= NULL
);
1050 get_line_and_offset_from_text(result
, &line_no
, &offset
);
1051 if (! editor_goto_line(doc
->editor
, line_no
, offset
))
1053 /* remember value for future calls */
1054 g_snprintf(value
, sizeof(value
), "%s", result
);
1061 void on_toolbutton_goto_entry_activate(GtkAction
*action
, const gchar
*text
, gpointer user_data
)
1063 GeanyDocument
*doc
= document_get_current();
1067 g_return_if_fail(doc
!= NULL
);
1069 get_line_and_offset_from_text(text
, &line_no
, &offset
);
1070 if (! editor_goto_line(doc
->editor
, line_no
, offset
))
1073 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
1077 void on_toolbutton_goto_clicked(GtkAction
*action
, gpointer user_data
)
1079 GtkWidget
*entry
= toolbar_get_widget_child_by_name("GotoEntry");
1083 const gchar
*text
= gtk_entry_get_text(GTK_ENTRY(entry
));
1085 on_toolbutton_goto_entry_activate(NULL
, text
, NULL
);
1088 on_go_to_line_activate(NULL
, NULL
);
1092 G_MODULE_EXPORT
void on_help1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1096 uri
= utils_get_help_url(NULL
);
1097 utils_open_browser(uri
);
1102 G_MODULE_EXPORT
void on_help_shortcuts1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1104 keybindings_show_shortcuts();
1108 G_MODULE_EXPORT
void on_website1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1110 utils_open_browser(GEANY_HOMEPAGE
);
1114 G_MODULE_EXPORT
void on_help_menu_item_donate_activate(GtkMenuItem
*item
, gpointer user_data
)
1116 utils_open_browser(GEANY_DONATE
);
1120 G_MODULE_EXPORT
void on_help_menu_item_wiki_activate(GtkMenuItem
*item
, gpointer user_data
)
1122 utils_open_browser(GEANY_WIKI
);
1126 G_MODULE_EXPORT
void on_help_menu_item_bug_report_activate(GtkMenuItem
*item
, gpointer user_data
)
1128 utils_open_browser(GEANY_BUG_REPORT
);
1132 G_MODULE_EXPORT
void on_comments_function_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1134 GeanyDocument
*doc
= document_get_current();
1136 const gchar
*cur_tag
= NULL
;
1137 gint line
= -1, pos
= 0;
1139 if (doc
== NULL
|| doc
->file_type
== NULL
)
1141 ui_set_statusbar(FALSE
,
1142 _("Please set the filetype for the current file before using this function."));
1146 /* symbols_get_current_function returns -1 on failure, so sci_get_position_from_line
1147 * returns the current position, so it should be safe */
1148 line
= symbols_get_current_function(doc
, &cur_tag
);
1149 pos
= sci_get_position_from_line(doc
->editor
->sci
, line
);
1151 text
= templates_get_template_function(doc
, cur_tag
);
1153 sci_start_undo_action(doc
->editor
->sci
);
1154 sci_insert_text(doc
->editor
->sci
, pos
, text
);
1155 sci_end_undo_action(doc
->editor
->sci
);
1160 static void insert_multiline_comment(GeanyDocument
*doc
, gint pos
)
1162 g_return_if_fail(doc
!= NULL
);
1163 g_return_if_fail(pos
== -1 || pos
>= 0);
1165 if (doc
->file_type
== NULL
)
1167 ui_set_statusbar(FALSE
,
1168 _("Please set the filetype for the current file before using this function."));
1172 if (doc
->file_type
->comment_open
|| doc
->file_type
->comment_single
)
1174 /* editor_insert_multiline_comment() uses editor_info.click_pos */
1176 editor_info
.click_pos
= sci_get_current_position(doc
->editor
->sci
);
1178 editor_info
.click_pos
= pos
;
1179 editor_insert_multiline_comment(doc
->editor
);
1186 G_MODULE_EXPORT
void on_comments_multiline_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1188 insert_multiline_comment(document_get_current(), editor_info
.click_pos
);
1192 G_MODULE_EXPORT
void on_menu_comments_multiline_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1194 insert_multiline_comment(document_get_current(), -1);
1198 static void insert_comment_template(GeanyDocument
*doc
, gint pos
, guint
template)
1202 g_return_if_fail(doc
!= NULL
);
1203 g_return_if_fail(pos
== -1 || pos
>= 0);
1204 g_return_if_fail(template < GEANY_MAX_TEMPLATES
);
1207 pos
= sci_get_current_position(doc
->editor
->sci
);
1209 text
= templates_get_template_licence(doc
, template);
1211 sci_start_undo_action(doc
->editor
->sci
);
1212 sci_insert_text(doc
->editor
->sci
, pos
, text
);
1213 sci_end_undo_action(doc
->editor
->sci
);
1218 G_MODULE_EXPORT
void on_comments_gpl_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1220 insert_comment_template(document_get_current(), editor_info
.click_pos
, GEANY_TEMPLATE_GPL
);
1224 G_MODULE_EXPORT
void on_menu_comments_gpl_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1226 insert_comment_template(document_get_current(), -1, GEANY_TEMPLATE_GPL
);
1230 G_MODULE_EXPORT
void on_comments_bsd_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1232 insert_comment_template(document_get_current(), editor_info
.click_pos
, GEANY_TEMPLATE_BSD
);
1236 G_MODULE_EXPORT
void on_menu_comments_bsd_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1238 insert_comment_template(document_get_current(), -1, GEANY_TEMPLATE_BSD
);
1242 G_MODULE_EXPORT
void on_comments_changelog_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1244 GeanyDocument
*doc
= document_get_current();
1247 g_return_if_fail(doc
!= NULL
);
1249 text
= templates_get_template_changelog(doc
);
1250 sci_start_undo_action(doc
->editor
->sci
);
1251 sci_insert_text(doc
->editor
->sci
, 0, text
);
1252 /* sets the cursor to the right position to type the changelog text,
1253 * the template has 21 chars + length of name and email */
1254 sci_goto_pos(doc
->editor
->sci
, 21 + strlen(template_prefs
.developer
) + strlen(template_prefs
.mail
), TRUE
);
1255 sci_end_undo_action(doc
->editor
->sci
);
1261 G_MODULE_EXPORT
void on_comments_fileheader_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1263 GeanyDocument
*doc
= document_get_current();
1268 g_return_if_fail(doc
!= NULL
);
1270 ft
= doc
->file_type
;
1271 fname
= doc
->file_name
;
1272 text
= templates_get_template_fileheader(FILETYPE_ID(ft
), fname
);
1274 sci_start_undo_action(doc
->editor
->sci
);
1275 sci_insert_text(doc
->editor
->sci
, 0, text
);
1276 sci_goto_pos(doc
->editor
->sci
, 0, FALSE
);
1277 sci_end_undo_action(doc
->editor
->sci
);
1282 G_MODULE_EXPORT
void on_file_properties_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1284 GeanyDocument
*doc
= document_get_current();
1285 g_return_if_fail(doc
!= NULL
);
1287 dialogs_show_file_properties(doc
);
1291 G_MODULE_EXPORT
void on_menu_fold_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1293 GeanyDocument
*doc
= document_get_current();
1294 g_return_if_fail(doc
!= NULL
);
1296 editor_fold_all(doc
->editor
);
1300 G_MODULE_EXPORT
void on_menu_unfold_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1302 GeanyDocument
*doc
= document_get_current();
1303 g_return_if_fail(doc
!= NULL
);
1305 editor_unfold_all(doc
->editor
);
1309 void on_toolbutton_run_clicked(GtkAction
*action
, gpointer user_data
)
1311 keybindings_send_command(GEANY_KEY_GROUP_BUILD
, GEANY_KEYS_BUILD_RUN
);
1315 G_MODULE_EXPORT
void on_menu_remove_indicators1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1317 GeanyDocument
*doc
= document_get_current();
1318 g_return_if_fail(doc
!= NULL
);
1320 editor_indicator_clear(doc
->editor
, GEANY_INDICATOR_ERROR
);
1324 G_MODULE_EXPORT
void on_print1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1326 GeanyDocument
*doc
= document_get_current();
1327 g_return_if_fail(doc
!= NULL
);
1329 printing_print_doc(doc
);
1333 G_MODULE_EXPORT
void on_menu_select_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1335 GeanyDocument
*doc
= document_get_current();
1336 g_return_if_fail(doc
!= NULL
);
1338 sci_select_all(doc
->editor
->sci
);
1342 G_MODULE_EXPORT
void on_menu_show_sidebar1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
1344 if (ignore_callback
)
1347 ui_prefs
.sidebar_visible
= ! ui_prefs
.sidebar_visible
;
1349 /* show built-in tabs if no tabs visible */
1350 if (ui_prefs
.sidebar_visible
&&
1351 ! interface_prefs
.sidebar_openfiles_visible
&& ! interface_prefs
.sidebar_symbol_visible
&&
1352 gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets
.sidebar_notebook
)) <= 2)
1354 interface_prefs
.sidebar_openfiles_visible
= TRUE
;
1355 interface_prefs
.sidebar_symbol_visible
= TRUE
;
1358 /* if window has input focus, set it back to the editor before toggling off */
1359 if (! ui_prefs
.sidebar_visible
&&
1360 gtk_container_get_focus_child(GTK_CONTAINER(main_widgets
.sidebar_notebook
)) != NULL
)
1362 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
1365 ui_sidebar_show_hide();
1369 G_MODULE_EXPORT
void on_menu_write_unicode_bom1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
1371 if (! ignore_callback
)
1373 GeanyDocument
*doc
= document_get_current();
1375 g_return_if_fail(doc
!= NULL
);
1382 document_undo_add(doc
, UNDO_BOM
, GINT_TO_POINTER(doc
->has_bom
));
1384 doc
->has_bom
= ! doc
->has_bom
;
1386 ui_update_statusbar(doc
, -1);
1391 G_MODULE_EXPORT
void on_menu_comment_line1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1393 GeanyDocument
*doc
= document_get_current();
1394 g_return_if_fail(doc
!= NULL
);
1396 editor_do_comment(doc
->editor
, -1, FALSE
, FALSE
, TRUE
);
1400 G_MODULE_EXPORT
void on_menu_uncomment_line1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1402 GeanyDocument
*doc
= document_get_current();
1403 g_return_if_fail(doc
!= NULL
);
1405 editor_do_uncomment(doc
->editor
, -1, FALSE
);
1409 G_MODULE_EXPORT
void on_menu_toggle_line_commentation1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1411 GeanyDocument
*doc
= document_get_current();
1412 g_return_if_fail(doc
!= NULL
);
1414 editor_do_comment_toggle(doc
->editor
);
1418 G_MODULE_EXPORT
void on_menu_increase_indent1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1420 GeanyDocument
*doc
= document_get_current();
1421 g_return_if_fail(doc
!= NULL
);
1423 editor_indent(doc
->editor
, TRUE
);
1427 G_MODULE_EXPORT
void on_menu_decrease_indent1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1429 GeanyDocument
*doc
= document_get_current();
1430 g_return_if_fail(doc
!= NULL
);
1432 editor_indent(doc
->editor
, FALSE
);
1436 G_MODULE_EXPORT
void on_next_message1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1438 if (! ui_tree_view_find_next(GTK_TREE_VIEW(msgwindow
.tree_msg
),
1439 msgwin_goto_messages_file_line
))
1440 ui_set_statusbar(FALSE
, _("No more message items."));
1444 G_MODULE_EXPORT
void on_previous_message1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1446 if (! ui_tree_view_find_previous(GTK_TREE_VIEW(msgwindow
.tree_msg
),
1447 msgwin_goto_messages_file_line
))
1448 ui_set_statusbar(FALSE
, _("No more message items."));
1452 G_MODULE_EXPORT
void on_project_new1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1458 G_MODULE_EXPORT
void on_project_open1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1464 G_MODULE_EXPORT
void on_project_close1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1466 project_close(TRUE
);
1470 G_MODULE_EXPORT
void on_project_properties1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1472 project_properties();
1476 G_MODULE_EXPORT
void on_menu_project1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1478 static GtkWidget
*item_close
= NULL
;
1479 static GtkWidget
*item_properties
= NULL
;
1481 if (item_close
== NULL
)
1483 item_close
= ui_lookup_widget(main_widgets
.window
, "project_close1");
1484 item_properties
= ui_lookup_widget(main_widgets
.window
, "project_properties1");
1487 gtk_widget_set_sensitive(item_close
, (app
->project
!= NULL
));
1488 gtk_widget_set_sensitive(item_properties
, (app
->project
!= NULL
));
1489 gtk_widget_set_sensitive(ui_widgets
.recent_projects_menuitem
,
1490 g_queue_get_length(ui_prefs
.recent_projects_queue
) > 0);
1494 G_MODULE_EXPORT
void on_menu_open_selected_file1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1496 GeanyDocument
*doc
= document_get_current();
1501 wc
= GEANY_WORDCHARS
"./-" "\\";
1503 wc
= GEANY_WORDCHARS
"./-";
1506 g_return_if_fail(doc
!= NULL
);
1508 sel
= editor_get_default_selection(doc
->editor
, TRUE
, wc
);
1509 SETPTR(sel
, utils_get_locale_from_utf8(sel
));
1513 gchar
*filename
= NULL
;
1515 if (g_path_is_absolute(sel
))
1516 filename
= g_strdup(sel
);
1518 { /* relative filename, add the path of the current file */
1521 path
= utils_get_current_file_dir_utf8();
1522 SETPTR(path
, utils_get_locale_from_utf8(path
));
1524 path
= g_get_current_dir();
1526 filename
= g_build_path(G_DIR_SEPARATOR_S
, path
, sel
, NULL
);
1528 if (! g_file_test(filename
, G_FILE_TEST_EXISTS
) &&
1529 app
->project
!= NULL
&& !EMPTY(app
->project
->base_path
))
1531 /* try the project's base path */
1532 SETPTR(path
, project_get_base_path());
1533 SETPTR(path
, utils_get_locale_from_utf8(path
));
1534 SETPTR(filename
, g_build_path(G_DIR_SEPARATOR_S
, path
, sel
, NULL
));
1538 if (! g_file_test(filename
, G_FILE_TEST_EXISTS
))
1539 SETPTR(filename
, g_build_path(G_DIR_SEPARATOR_S
, "/usr/local/include", sel
, NULL
));
1541 if (! g_file_test(filename
, G_FILE_TEST_EXISTS
))
1542 SETPTR(filename
, g_build_path(G_DIR_SEPARATOR_S
, "/usr/include", sel
, NULL
));
1546 if (g_file_test(filename
, G_FILE_TEST_EXISTS
))
1547 document_open_file(filename
, FALSE
, NULL
, NULL
);
1550 SETPTR(sel
, utils_get_utf8_from_locale(sel
));
1551 ui_set_statusbar(TRUE
, _("Could not open file %s (File not found)"), sel
);
1560 G_MODULE_EXPORT
void on_remove_markers1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1562 GeanyDocument
*doc
= document_get_current();
1563 g_return_if_fail(doc
!= NULL
);
1565 sci_marker_delete_all(doc
->editor
->sci
, 0); /* delete the yellow tag marker */
1566 sci_marker_delete_all(doc
->editor
->sci
, 1); /* delete user markers */
1567 editor_indicator_clear(doc
->editor
, GEANY_INDICATOR_SEARCH
);
1571 G_MODULE_EXPORT
void on_load_tags1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1573 symbols_show_load_tags_dialog();
1577 G_MODULE_EXPORT
void on_context_action1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1579 gchar
*word
, *command
;
1580 GError
*error
= NULL
;
1581 GeanyDocument
*doc
= document_get_current();
1583 g_return_if_fail(doc
!= NULL
);
1585 if (sci_has_selection(doc
->editor
->sci
))
1586 { /* take selected text if there is a selection */
1587 word
= sci_get_selection_contents(doc
->editor
->sci
);
1591 word
= g_strdup(editor_info
.current_word
);
1594 /* use the filetype specific command if available, fallback to global command otherwise */
1595 if (doc
->file_type
!= NULL
&&
1596 !EMPTY(doc
->file_type
->context_action_cmd
))
1598 command
= g_strdup(doc
->file_type
->context_action_cmd
);
1602 command
= g_strdup(tool_prefs
.context_action_cmd
);
1605 /* substitute the wildcard %s and run the command if it is non empty */
1606 if (G_LIKELY(!EMPTY(command
)))
1608 utils_str_replace_all(&command
, "%s", word
);
1610 if (! g_spawn_command_line_async(command
, &error
))
1612 ui_set_statusbar(TRUE
, "Context action command failed: %s", error
->message
);
1613 g_error_free(error
);
1621 G_MODULE_EXPORT
void on_menu_toggle_all_additional_widgets1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1623 static gint hide_all
= -1;
1624 GtkCheckMenuItem
*msgw
= GTK_CHECK_MENU_ITEM(
1625 ui_lookup_widget(main_widgets
.window
, "menu_show_messages_window1"));
1626 GtkCheckMenuItem
*toolbari
= GTK_CHECK_MENU_ITEM(
1627 ui_lookup_widget(main_widgets
.window
, "menu_show_toolbar1"));
1629 /* get the initial state (necessary if Geany was closed with hide_all = TRUE) */
1630 if (G_UNLIKELY(hide_all
== -1))
1632 if (! gtk_check_menu_item_get_active(msgw
) &&
1633 ! interface_prefs
.show_notebook_tabs
&&
1634 ! gtk_check_menu_item_get_active(toolbari
))
1642 hide_all
= ! hide_all
; /* toggle */
1646 if (gtk_check_menu_item_get_active(msgw
))
1647 gtk_check_menu_item_set_active(msgw
, ! gtk_check_menu_item_get_active(msgw
));
1649 interface_prefs
.show_notebook_tabs
= FALSE
;
1650 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets
.notebook
), interface_prefs
.show_notebook_tabs
);
1652 ui_statusbar_showhide(FALSE
);
1654 if (gtk_check_menu_item_get_active(toolbari
))
1655 gtk_check_menu_item_set_active(toolbari
, ! gtk_check_menu_item_get_active(toolbari
));
1660 if (! gtk_check_menu_item_get_active(msgw
))
1661 gtk_check_menu_item_set_active(msgw
, ! gtk_check_menu_item_get_active(msgw
));
1663 interface_prefs
.show_notebook_tabs
= TRUE
;
1664 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets
.notebook
), interface_prefs
.show_notebook_tabs
);
1666 ui_statusbar_showhide(TRUE
);
1668 if (! gtk_check_menu_item_get_active(toolbari
))
1669 gtk_check_menu_item_set_active(toolbari
, ! gtk_check_menu_item_get_active(toolbari
));
1674 void on_toolbutton_forward_activate(GtkAction
*menuitem
, gpointer user_data
)
1676 navqueue_go_forward();
1680 void on_toolbutton_back_activate(GtkAction
*menuitem
, gpointer user_data
)
1686 gboolean
on_motion_event(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
)
1688 if (prefs
.auto_focus
&& ! gtk_widget_has_focus(widget
))
1689 gtk_widget_grab_focus(widget
);
1695 static void set_indent_type(GtkCheckMenuItem
*menuitem
, GeanyIndentType type
)
1699 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
1702 doc
= document_get_current();
1703 g_return_if_fail(doc
!= NULL
);
1705 editor_set_indent(doc
->editor
, type
, doc
->editor
->indent_width
);
1706 ui_update_statusbar(doc
, -1);
1710 G_MODULE_EXPORT
void on_tabs1_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
1712 set_indent_type(menuitem
, GEANY_INDENT_TYPE_TABS
);
1716 G_MODULE_EXPORT
void on_spaces1_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
1718 set_indent_type(menuitem
, GEANY_INDENT_TYPE_SPACES
);
1722 G_MODULE_EXPORT
void on_tabs_and_spaces1_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
1724 set_indent_type(menuitem
, GEANY_INDENT_TYPE_BOTH
);
1728 G_MODULE_EXPORT
void on_strip_trailing_spaces1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1732 if (ignore_callback
)
1735 doc
= document_get_current();
1736 g_return_if_fail(doc
!= NULL
);
1738 editor_strip_trailing_spaces(doc
->editor
);
1742 G_MODULE_EXPORT
void on_page_setup1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1744 printing_page_setup_gtk();
1748 G_MODULE_EXPORT gboolean
on_escape_key_press_event(GtkWidget
*widget
, GdkEventKey
*event
, gpointer user_data
)
1750 guint state
= event
->state
& gtk_accelerator_get_default_mod_mask();
1752 /* make pressing escape in the sidebar and toolbar focus the editor */
1753 if (event
->keyval
== GDK_Escape
&& state
== 0)
1755 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
1762 G_MODULE_EXPORT
void on_line_breaking1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1766 if (ignore_callback
)
1769 doc
= document_get_current();
1770 g_return_if_fail(doc
!= NULL
);
1772 doc
->editor
->line_breaking
= !doc
->editor
->line_breaking
;
1776 G_MODULE_EXPORT
void on_replace_spaces_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1778 GeanyDocument
*doc
= document_get_current();
1780 g_return_if_fail(doc
!= NULL
);
1782 editor_replace_spaces(doc
->editor
);
1786 G_MODULE_EXPORT
void on_search1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1788 GtkWidget
*next_message
= ui_lookup_widget(main_widgets
.window
, "next_message1");
1789 GtkWidget
*previous_message
= ui_lookup_widget(main_widgets
.window
, "previous_message1");
1790 gboolean have_messages
;
1792 /* enable commands if the messages window has any items */
1793 have_messages
= gtk_tree_model_iter_n_children(GTK_TREE_MODEL(msgwindow
.store_msg
),
1796 gtk_widget_set_sensitive(next_message
, have_messages
);
1797 gtk_widget_set_sensitive(previous_message
, have_messages
);
1801 /* simple implementation (vs. close all which doesn't close documents if cancelled),
1802 * if user_data is set, it is the GeanyDocument to keep */
1803 G_MODULE_EXPORT
void on_close_other_documents1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1806 GeanyDocument
*cur_doc
= user_data
;
1808 if (cur_doc
== NULL
)
1809 cur_doc
= document_get_current();
1811 for (i
= 0; i
< documents_array
->len
; i
++)
1813 GeanyDocument
*doc
= documents
[i
];
1815 if (doc
== cur_doc
|| ! doc
->is_valid
)
1818 if (! document_close(doc
))
1824 G_MODULE_EXPORT
void on_menu_reload_configuration1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1826 main_reload_configuration();
1830 G_MODULE_EXPORT
void on_debug_messages1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1832 log_show_debug_messages_dialog();
1836 G_MODULE_EXPORT
void on_send_selection_to_vte1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1839 if (vte_info
.have_vte
)
1840 vte_send_selection_to_vte();
1845 G_MODULE_EXPORT gboolean
on_window_state_event(GtkWidget
*widget
, GdkEventWindowState
*event
, gpointer user_data
)
1848 if (event
->changed_mask
& GDK_WINDOW_STATE_FULLSCREEN
)
1850 static GtkWidget
*menuitem
= NULL
;
1852 if (menuitem
== NULL
)
1853 menuitem
= ui_lookup_widget(widget
, "menu_fullscreen1");
1855 ignore_callback
= TRUE
;
1857 ui_prefs
.fullscreen
= (event
->new_window_state
& GDK_WINDOW_STATE_FULLSCREEN
) ? TRUE
: FALSE
;
1858 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem
), ui_prefs
.fullscreen
);
1860 ignore_callback
= FALSE
;
1866 static void show_notebook_page(const gchar
*notebook_name
, const gchar
*page_name
)
1869 GtkNotebook
*notebook
;
1871 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, page_name
);
1872 notebook
= GTK_NOTEBOOK(ui_lookup_widget(ui_widgets
.prefs_dialog
, notebook_name
));
1874 if (notebook
!= NULL
&& widget
!= NULL
)
1875 gtk_notebook_set_current_page(notebook
, gtk_notebook_page_num(notebook
, widget
));
1879 G_MODULE_EXPORT
void on_customize_toolbar1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1881 prefs_show_dialog();
1883 /* select the Interface page */
1884 show_notebook_page("notebook2", "notebook6");
1885 /* select the Toolbar subpage */
1886 show_notebook_page("notebook6", "vbox15");
1890 G_MODULE_EXPORT
void on_button_customize_toolbar_clicked(GtkButton
*button
, gpointer user_data
)
1892 toolbar_configure(GTK_WINDOW(ui_widgets
.prefs_dialog
));
1896 G_MODULE_EXPORT
void on_cut_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1898 keybindings_send_command(GEANY_KEY_GROUP_CLIPBOARD
, GEANY_KEYS_CLIPBOARD_CUTLINE
);
1902 G_MODULE_EXPORT
void on_copy_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1904 keybindings_send_command(GEANY_KEY_GROUP_CLIPBOARD
, GEANY_KEYS_CLIPBOARD_COPYLINE
);
1908 G_MODULE_EXPORT
void on_delete_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1910 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_DELETELINE
);
1914 G_MODULE_EXPORT
void on_duplicate_line_or_selection1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1916 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_DUPLICATELINE
);
1920 G_MODULE_EXPORT
void on_select_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1922 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_LINE
);
1926 G_MODULE_EXPORT
void on_select_current_paragraph1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1928 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_PARAGRAPH
);
1932 G_MODULE_EXPORT
void on_insert_alternative_white_space1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1934 keybindings_send_command(GEANY_KEY_GROUP_INSERT
, GEANY_KEYS_INSERT_ALTWHITESPACE
);
1938 G_MODULE_EXPORT
void on_go_to_next_marker1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1940 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_NEXTMARKER
);
1944 G_MODULE_EXPORT
void on_go_to_previous_marker1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1946 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_PREVIOUSMARKER
);
1950 G_MODULE_EXPORT
void on_reflow_lines_block1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1952 keybindings_send_command(GEANY_KEY_GROUP_FORMAT
, GEANY_KEYS_FORMAT_REFLOWPARAGRAPH
);
1956 G_MODULE_EXPORT
void on_move_lines_up1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1958 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_MOVELINEUP
);
1962 G_MODULE_EXPORT
void on_move_lines_down1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1964 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_MOVELINEDOWN
);
1968 G_MODULE_EXPORT
void on_smart_line_indent1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1970 keybindings_send_command(GEANY_KEY_GROUP_FORMAT
, GEANY_KEYS_FORMAT_AUTOINDENT
);
1974 G_MODULE_EXPORT
void on_plugin_preferences1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1977 plugin_show_configure(NULL
);
1982 G_MODULE_EXPORT
void on_indent_width_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1988 if (ignore_callback
)
1991 label
= ui_menu_item_get_text(menuitem
);
1992 width
= atoi(label
);
1995 doc
= document_get_current();
1996 if (doc
!= NULL
&& width
> 0)
1997 editor_set_indent_width(doc
->editor
, width
);
2001 G_MODULE_EXPORT
void on_reset_indentation1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2006 document_apply_indent_settings(documents
[i
]);
2008 ui_update_statusbar(NULL
, -1);
2009 ui_document_show_hide(NULL
);
2013 G_MODULE_EXPORT
void on_mark_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2015 keybindings_send_command(GEANY_KEY_GROUP_SEARCH
, GEANY_KEYS_SEARCH_MARKALL
);
2019 G_MODULE_EXPORT
void on_detect_type_from_file_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2021 GeanyDocument
*doc
= document_get_current();
2022 GeanyIndentType type
;
2024 if (doc
!= NULL
&& document_detect_indent_type(doc
, &type
))
2026 editor_set_indent_type(doc
->editor
, type
);
2027 ui_document_show_hide(doc
);
2032 G_MODULE_EXPORT
void on_detect_width_from_file_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2034 GeanyDocument
*doc
= document_get_current();
2037 if (doc
!= NULL
&& document_detect_indent_width(doc
, &width
))
2039 editor_set_indent_width(doc
->editor
, width
);
2040 ui_document_show_hide(doc
);