2 * callbacks.c - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2005-2012 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5 * Copyright 2006-2012 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 * Callbacks used by Glade. These are mainly in response to menu item and button events in the
24 * main window. Callbacks not used by Glade should go elsewhere.
31 #include "callbacks.h"
37 #include "documentprivate.h"
38 #include "encodings.h"
39 #include "filetypes.h"
40 #include "geanyobject.h"
41 #include "highlighting.h"
42 #include "keybindings.h"
46 #include "msgwindow.h"
49 #include "pluginutils.h"
52 #include "sciwrappers.h"
60 #include "templates.h"
67 #include "gtkcompat.h"
72 #include <gdk/gdkkeysyms.h>
73 #include <glib/gstdio.h>
77 /* represents the state at switching a notebook page(in the left treeviews widget), to not emit
78 * the selection-changed signal from tv.tree_openfiles */
79 /*static gboolean switch_tv_notebook_page = FALSE; */
83 /* wrapper function to abort exit process if cancel button is pressed */
84 static gboolean
on_window_delete_event(GtkWidget
*widget
, GdkEvent
*event
, gpointer gdata
)
94 void on_new1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
96 document_new_file(NULL
, NULL
, NULL
);
100 /* create a new file and copy file content and properties */
101 static void on_clone1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
103 GeanyDocument
*old_doc
= document_get_current();
106 document_clone(old_doc
);
110 void on_save1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
112 GeanyDocument
*doc
= document_get_current();
116 document_save_file(doc
, ui_prefs
.allow_always_save
);
121 void on_save_as1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
123 dialogs_show_save_as();
127 void on_save_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
129 guint i
, max
= (guint
) gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets
.notebook
));
130 GeanyDocument
*cur_doc
= document_get_current();
133 /* iterate over documents in tabs order */
134 for (i
= 0; i
< max
; i
++)
136 GeanyDocument
*doc
= document_get_from_page(i
);
141 if (document_save_file(doc
, FALSE
))
147 ui_set_statusbar(FALSE
, ngettext("%d file saved.", "%d files saved.", count
), count
);
148 /* saving may have changed window title, sidebar for another doc, so update */
149 document_show_tab(cur_doc
);
150 sidebar_update_tag_list(cur_doc
, TRUE
);
151 ui_set_window_title(cur_doc
);
155 void on_close_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
157 document_close_all();
161 void on_close1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
163 GeanyDocument
*doc
= document_get_current();
170 void on_quit1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
176 static void on_file1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
178 gtk_widget_set_sensitive(ui_widgets
.recent_files_menuitem
,
179 g_queue_get_length(ui_prefs
.recent_queue
) > 0);
180 /* hide Page setup when GTK printing is not used */
181 ui_widget_show_hide(ui_widgets
.print_page_setup
, printing_prefs
.use_gtk_printing
);
185 /* edit actions, c&p & co, from menu bar and from popup menu */
186 static void on_edit1_select(GtkMenuItem
*menuitem
, gpointer user_data
)
189 GeanyDocument
*doc
= document_get_current();
191 ui_update_menu_copy_items(doc
);
192 ui_update_insert_include_item(doc
, 1);
194 item
= ui_lookup_widget(main_widgets
.window
, "plugin_preferences1");
196 gtk_widget_hide(item
);
198 gtk_widget_set_sensitive(item
, plugins_have_preferences());
203 static void on_edit1_deselect(GtkMenuShell
*menushell
, gpointer user_data
)
205 /* we re-enable items that were disabled in on_edit1_select() on menu popdown to
206 * workaround mutli-layout keyboard issues in our keybinding handling code, so that
207 * GTK's accelerator handling can catch them.
208 * See https://github.com/geany/geany/issues/1368#issuecomment-273678207 */
209 ui_menu_copy_items_set_sensitive(TRUE
);
213 void on_undo1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
215 GeanyDocument
*doc
= document_get_current();
217 g_return_if_fail(doc
!= NULL
);
219 if (document_can_undo(doc
))
221 sci_cancel(doc
->editor
->sci
);
227 void on_redo1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
229 GeanyDocument
*doc
= document_get_current();
231 g_return_if_fail(doc
!= NULL
);
233 if (document_can_redo(doc
))
235 sci_cancel(doc
->editor
->sci
);
241 void on_cut1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
243 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
245 if (GTK_IS_EDITABLE(focusw
))
246 gtk_editable_cut_clipboard(GTK_EDITABLE(focusw
));
247 else if (IS_SCINTILLA(focusw
))
248 sci_cut(SCINTILLA(focusw
));
249 else if (GTK_IS_TEXT_VIEW(focusw
))
251 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(
252 GTK_TEXT_VIEW(focusw
));
253 gtk_text_buffer_cut_clipboard(buffer
, gtk_clipboard_get(GDK_NONE
), TRUE
);
258 void on_copy1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
260 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
262 if (GTK_IS_EDITABLE(focusw
))
263 gtk_editable_copy_clipboard(GTK_EDITABLE(focusw
));
264 else if (IS_SCINTILLA(focusw
))
265 sci_copy(SCINTILLA(focusw
));
266 else if (GTK_IS_TEXT_VIEW(focusw
))
268 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(
269 GTK_TEXT_VIEW(focusw
));
270 gtk_text_buffer_copy_clipboard(buffer
, gtk_clipboard_get(GDK_NONE
));
275 void on_paste1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
277 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
279 if (GTK_IS_EDITABLE(focusw
))
280 gtk_editable_paste_clipboard(GTK_EDITABLE(focusw
));
281 else if (IS_SCINTILLA(focusw
))
282 sci_paste(SCINTILLA(focusw
));
283 else if (GTK_IS_TEXT_VIEW(focusw
))
285 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(
286 GTK_TEXT_VIEW(focusw
));
287 gtk_text_buffer_paste_clipboard(buffer
, gtk_clipboard_get(GDK_NONE
), NULL
,
293 void on_delete1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
295 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
297 if (GTK_IS_EDITABLE(focusw
))
298 gtk_editable_delete_selection(GTK_EDITABLE(focusw
));
299 else if (IS_SCINTILLA(focusw
) && sci_has_selection(SCINTILLA(focusw
)))
300 sci_clear(SCINTILLA(focusw
));
301 else if (GTK_IS_TEXT_VIEW(focusw
))
303 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(
304 GTK_TEXT_VIEW(focusw
));
305 gtk_text_buffer_delete_selection(buffer
, TRUE
, TRUE
);
310 void on_preferences1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
316 /* about menu item */
317 static void on_info1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
324 void on_open1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
326 dialogs_show_open_file();
331 void on_toolbutton_reload_clicked(GtkAction
*action
, gpointer user_data
)
333 GeanyDocument
*doc
= document_get_current();
335 g_return_if_fail(doc
!= NULL
);
337 document_reload_prompt(doc
, NULL
);
341 static void on_change_font1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
343 dialogs_show_open_font();
347 /* store text, clear search flags so we can use Search->Find Next/Previous */
348 static void setup_find(const gchar
*text
, gboolean backwards
)
350 SETPTR(search_data
.text
, g_strdup(text
));
351 SETPTR(search_data
.original_text
, g_strdup(text
));
352 search_data
.flags
= 0;
353 search_data
.backwards
= backwards
;
354 search_data
.search_bar
= TRUE
;
358 static void do_toolbar_search(const gchar
*text
, gboolean incremental
, gboolean backwards
)
360 GeanyDocument
*doc
= document_get_current();
363 setup_find(text
, backwards
);
364 result
= document_search_bar_find(doc
, search_data
.text
, incremental
, backwards
);
365 if (search_data
.search_bar
)
366 ui_set_search_entry_background(toolbar_get_widget_child_by_name("SearchEntry"), result
);
371 void on_toolbar_search_entry_changed(GtkAction
*action
, const gchar
*text
, gpointer user_data
)
373 do_toolbar_search(text
, TRUE
, FALSE
);
378 void on_toolbar_search_entry_activate(GtkAction
*action
, const gchar
*text
, gpointer user_data
)
380 do_toolbar_search(text
, FALSE
, GPOINTER_TO_INT(user_data
));
385 void on_toolbutton_search_clicked(GtkAction
*action
, gpointer user_data
)
387 GeanyDocument
*doc
= document_get_current();
389 GtkWidget
*entry
= toolbar_get_widget_child_by_name("SearchEntry");
393 const gchar
*text
= gtk_entry_get_text(GTK_ENTRY(entry
));
395 setup_find(text
, FALSE
);
396 result
= document_search_bar_find(doc
, search_data
.text
, FALSE
, FALSE
);
397 if (search_data
.search_bar
)
398 ui_set_search_entry_background(entry
, result
);
401 on_find1_activate(NULL
, NULL
);
405 /* hides toolbar from toolbar popup menu */
406 static void on_hide_toolbar1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
408 GtkWidget
*tool_item
= ui_lookup_widget(GTK_WIDGET(main_widgets
.window
), "menu_show_toolbar1");
409 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(tool_item
), FALSE
);
413 /* zoom in from menu bar and popup menu */
414 void on_zoom_in1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
416 GeanyDocument
*doc
= document_get_current();
418 g_return_if_fail(doc
!= NULL
);
420 sci_zoom_in(doc
->editor
->sci
);
424 /* zoom out from menu bar and popup menu */
425 void on_zoom_out1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
427 GeanyDocument
*doc
= document_get_current();
429 g_return_if_fail(doc
!= NULL
);
431 sci_zoom_out(doc
->editor
->sci
);
435 void on_normal_size1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
437 GeanyDocument
*doc
= document_get_current();
439 g_return_if_fail(doc
!= NULL
);
441 sci_zoom_off(doc
->editor
->sci
);
445 /* Changes window-title after switching tabs and lots of other things.
446 * note: using 'after' makes Scintilla redraw before the UI, appearing more responsive */
447 static void on_notebook1_switch_page_after(GtkNotebook
*notebook
, gpointer page
,
448 guint page_num
, gpointer user_data
)
452 if (G_UNLIKELY(main_status
.opening_session_files
|| main_status
.closing_all
))
455 doc
= document_get_from_notebook_child(page
);
459 sidebar_select_openfiles_item(doc
);
460 ui_save_buttons_toggle(doc
->changed
);
461 ui_set_window_title(doc
);
462 ui_update_statusbar(doc
, -1);
463 ui_update_popup_reundo_items(doc
);
464 ui_document_show_hide(doc
); /* update the document menu */
465 build_menu_update(doc
);
466 sidebar_update_tag_list(doc
, FALSE
);
467 document_highlight_tags(doc
);
469 document_check_disk_status(doc
, TRUE
);
472 vte_cwd((doc
->real_path
!= NULL
) ? doc
->real_path
: doc
->file_name
, FALSE
);
475 g_signal_emit_by_name(geany_object
, "document-activate", doc
);
480 static void on_tv_notebook_switch_page(GtkNotebook
*notebook
, gpointer page
,
481 guint page_num
, gpointer user_data
)
483 /* suppress selection changed signal when switching to the open files list */
484 ignore_callback
= TRUE
;
488 static void on_tv_notebook_switch_page_after(GtkNotebook
*notebook
, gpointer page
,
489 guint page_num
, gpointer user_data
)
491 ignore_callback
= FALSE
;
495 static void convert_eol(gint mode
)
497 GeanyDocument
*doc
= document_get_current();
499 g_return_if_fail(doc
!= NULL
);
501 /* sci_convert_eols() adds UNDO_SCINTILLA action in on_editor_notify().
502 * It is added to the undo stack before sci_convert_eols() finishes
503 * so after adding UNDO_EOL, UNDO_EOL will be at the top of the stack
504 * and UNDO_SCINTILLA below it. */
505 sci_convert_eols(doc
->editor
->sci
, mode
);
506 document_undo_add(doc
, UNDO_EOL
, GINT_TO_POINTER(sci_get_eol_mode(doc
->editor
->sci
)));
508 sci_set_eol_mode(doc
->editor
->sci
, mode
);
510 ui_update_statusbar(doc
, -1);
514 static void on_crlf_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
516 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
519 convert_eol(SC_EOL_CRLF
);
523 static void on_lf_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
525 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
528 convert_eol(SC_EOL_LF
);
532 static void on_cr_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
534 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
537 convert_eol(SC_EOL_CR
);
541 void on_replace_tabs_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
543 GeanyDocument
*doc
= document_get_current();
545 g_return_if_fail(doc
!= NULL
);
547 editor_replace_tabs(doc
->editor
, FALSE
);
551 gboolean
toolbar_popup_menu(GtkWidget
*widget
, GdkEventButton
*event
, gpointer user_data
)
553 if (event
->button
== 3)
555 gtk_menu_popup(GTK_MENU(ui_widgets
.toolbar_menu
), NULL
, NULL
, NULL
, NULL
, event
->button
, event
->time
);
562 void on_toggle_case1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
564 GeanyDocument
*doc
= document_get_current();
565 ScintillaObject
*sci
;
566 gboolean keep_sel
= TRUE
;
568 g_return_if_fail(doc
!= NULL
);
570 sci
= doc
->editor
->sci
;
571 if (! sci_has_selection(sci
))
573 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_WORD
);
577 /* either we already had a selection or we created one for current word */
578 if (sci_has_selection(sci
))
580 gchar
*result
= NULL
;
581 gint cmd
= SCI_LOWERCASE
;
582 gboolean rectsel
= (gboolean
) SSM(sci
, SCI_SELECTIONISRECTANGLE
, 0, 0);
583 gchar
*text
= sci_get_selection_contents(sci
);
585 if (utils_str_has_upper(text
))
590 result
= g_utf8_strdown(text
, -1);
597 result
= g_utf8_strup(text
, -1);
602 sci_replace_sel(sci
, result
);
605 sci_set_selection_start(sci
, sci_get_current_position(sci
) - strlen(text
));
608 sci_send_command(sci
, cmd
);
615 static void on_show_toolbar1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
617 if (ignore_callback
) return;
619 toolbar_prefs
.visible
= (toolbar_prefs
.visible
) ? FALSE
: TRUE
;;
620 ui_widget_show_hide(GTK_WIDGET(main_widgets
.toolbar
), toolbar_prefs
.visible
);
624 static void on_fullscreen1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
629 ui_prefs
.fullscreen
= (ui_prefs
.fullscreen
) ? FALSE
: TRUE
;
634 static void on_show_messages_window1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
639 ui_prefs
.msgwindow_visible
= (ui_prefs
.msgwindow_visible
) ? FALSE
: TRUE
;
640 msgwin_show_hide(ui_prefs
.msgwindow_visible
);
644 static void on_menu_color_schemes_activate(GtkImageMenuItem
*imagemenuitem
, gpointer user_data
)
646 highlighting_show_color_scheme_dialog();
650 static void on_markers_margin1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
655 editor_prefs
.show_markers_margin
= ! editor_prefs
.show_markers_margin
;
656 ui_toggle_editor_features(GEANY_EDITOR_SHOW_MARKERS_MARGIN
);
660 static void on_show_line_numbers1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
665 editor_prefs
.show_linenumber_margin
= ! editor_prefs
.show_linenumber_margin
;
666 ui_toggle_editor_features(GEANY_EDITOR_SHOW_LINE_NUMBERS
);
670 static void on_menu_show_white_space1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
675 editor_prefs
.show_white_space
= ! editor_prefs
.show_white_space
;
676 ui_toggle_editor_features(GEANY_EDITOR_SHOW_WHITE_SPACE
);
680 static void on_menu_show_line_endings1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
685 editor_prefs
.show_line_endings
= ! editor_prefs
.show_line_endings
;
686 ui_toggle_editor_features(GEANY_EDITOR_SHOW_LINE_ENDINGS
);
690 static void on_menu_show_indentation_guides1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
695 editor_prefs
.show_indent_guide
= ! editor_prefs
.show_indent_guide
;
696 ui_toggle_editor_features(GEANY_EDITOR_SHOW_INDENTATION_GUIDES
);
700 void on_line_wrapping1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
702 if (! ignore_callback
)
704 GeanyDocument
*doc
= document_get_current();
705 g_return_if_fail(doc
!= NULL
);
707 editor_set_line_wrapping(doc
->editor
, ! doc
->editor
->line_wrapping
);
712 static void on_set_file_readonly1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
714 if (! ignore_callback
)
716 GeanyDocument
*doc
= document_get_current();
717 g_return_if_fail(doc
!= NULL
);
719 doc
->readonly
= ! doc
->readonly
;
720 sci_set_readonly(doc
->editor
->sci
, doc
->readonly
);
721 ui_update_tab_status(doc
);
722 ui_update_statusbar(doc
, -1);
727 static void on_use_auto_indentation1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
729 if (! ignore_callback
)
731 GeanyDocument
*doc
= document_get_current();
732 g_return_if_fail(doc
!= NULL
);
734 doc
->editor
->auto_indent
= ! doc
->editor
->auto_indent
;
739 static void find_usage(gboolean in_session
)
741 GeanyFindFlags flags
;
743 GeanyDocument
*doc
= document_get_current();
745 g_return_if_fail(doc
!= NULL
);
747 if (sci_has_selection(doc
->editor
->sci
))
748 { /* take selected text if there is a selection */
749 search_text
= sci_get_selection_contents(doc
->editor
->sci
);
750 flags
= GEANY_FIND_MATCHCASE
;
754 editor_find_current_word_sciwc(doc
->editor
, -1,
755 editor_info
.current_word
, GEANY_MAX_WORD_LENGTH
);
756 search_text
= g_strdup(editor_info
.current_word
);
757 flags
= GEANY_FIND_MATCHCASE
| GEANY_FIND_WHOLEWORD
;
760 search_find_usage(search_text
, search_text
, flags
, in_session
);
765 void on_find_document_usage1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
771 void on_find_usage1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
777 static void goto_tag(gboolean definition
)
779 GeanyDocument
*doc
= document_get_current();
781 g_return_if_fail(doc
!= NULL
);
783 /* update cursor pos for navigating back afterwards */
784 if (!sci_has_selection(doc
->editor
->sci
))
785 sci_set_current_position(doc
->editor
->sci
, editor_info
.click_pos
, FALSE
);
787 /* use the keybinding callback as it checks for selections as well as current word */
789 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_TAGDEFINITION
);
791 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_TAGDECLARATION
);
795 static void on_goto_tag_definition1(GtkMenuItem
*menuitem
, gpointer user_data
)
801 static void on_goto_tag_declaration1(GtkMenuItem
*menuitem
, gpointer user_data
)
807 static void on_count_words1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
813 void on_show_color_chooser1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
816 GeanyDocument
*doc
= document_get_current();
819 g_return_if_fail(doc
!= NULL
);
821 pos
= sci_get_current_position(doc
->editor
->sci
);
822 editor_find_current_word(doc
->editor
, pos
, colour
, sizeof colour
, GEANY_WORDCHARS
"#");
823 tools_color_chooser(colour
);
827 void on_toolbutton_compile_clicked(GtkAction
*action
, gpointer user_data
)
829 keybindings_send_command(GEANY_KEY_GROUP_BUILD
, GEANY_KEYS_BUILD_COMPILE
);
833 void on_find1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
835 search_show_find_dialog();
839 void on_find_next1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
841 search_find_again(FALSE
);
845 void on_find_previous1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
847 if (search_data
.flags
& GEANY_FIND_REGEXP
)
848 /* Can't reverse search order for a regex (find next ignores search backwards) */
851 search_find_again(TRUE
);
855 void on_find_nextsel1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
857 search_find_selection(document_get_current(), FALSE
);
861 void on_find_prevsel1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
863 search_find_selection(document_get_current(), TRUE
);
867 void on_replace1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
869 search_show_replace_dialog();
873 void on_find_in_files1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
875 search_show_find_in_files_dialog(NULL
);
879 static void get_line_and_offset_from_text(const gchar
*text
, gint
*line_no
, gint
*offset
)
881 if (*text
== '+' || *text
== '-')
883 *line_no
= atoi(text
+ 1);
884 *offset
= (*text
== '+') ? 1 : -1;
888 *line_no
= atoi(text
) - 1;
894 void on_go_to_line_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
896 static gchar value
[16] = "";
899 result
= dialogs_show_input_goto_line(
900 _("Go to Line"), GTK_WINDOW(main_widgets
.window
),
901 _("Enter the line you want to go to:"), value
);
904 GeanyDocument
*doc
= document_get_current();
908 g_return_if_fail(doc
!= NULL
);
910 get_line_and_offset_from_text(result
, &line_no
, &offset
);
911 if (! editor_goto_line(doc
->editor
, line_no
, offset
))
913 /* remember value for future calls */
914 g_snprintf(value
, sizeof(value
), "%s", result
);
921 void on_toolbutton_goto_entry_activate(GtkAction
*action
, const gchar
*text
, gpointer user_data
)
923 GeanyDocument
*doc
= document_get_current();
927 g_return_if_fail(doc
!= NULL
);
929 get_line_and_offset_from_text(text
, &line_no
, &offset
);
930 if (! editor_goto_line(doc
->editor
, line_no
, offset
))
933 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
937 void on_toolbutton_goto_clicked(GtkAction
*action
, gpointer user_data
)
939 GtkWidget
*entry
= toolbar_get_widget_child_by_name("GotoEntry");
943 const gchar
*text
= gtk_entry_get_text(GTK_ENTRY(entry
));
945 on_toolbutton_goto_entry_activate(NULL
, text
, NULL
);
948 on_go_to_line_activate(NULL
, NULL
);
952 void on_help1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
956 uri
= utils_get_help_url(NULL
);
957 utils_open_browser(uri
);
962 static void on_help_shortcuts1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
964 keybindings_show_shortcuts();
968 static void on_website1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
970 utils_open_browser(GEANY_HOMEPAGE
);
974 static void on_help_menu_item_donate_activate(GtkMenuItem
*item
, gpointer user_data
)
976 utils_open_browser(GEANY_DONATE
);
980 static void on_help_menu_item_wiki_activate(GtkMenuItem
*item
, gpointer user_data
)
982 utils_open_browser(GEANY_WIKI
);
986 static void on_help_menu_item_bug_report_activate(GtkMenuItem
*item
, gpointer user_data
)
988 utils_open_browser(GEANY_BUG_REPORT
);
992 static void on_comments_function_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
994 GeanyDocument
*doc
= document_get_current();
996 const gchar
*cur_tag
= NULL
;
997 gint line
= -1, pos
= 0;
999 if (doc
== NULL
|| doc
->file_type
== NULL
)
1001 ui_set_statusbar(FALSE
,
1002 _("Please set the filetype for the current file before using this function."));
1006 /* symbols_get_current_function returns -1 on failure, so sci_get_position_from_line
1007 * returns the current position, so it should be safe */
1008 line
= symbols_get_current_function(doc
, &cur_tag
);
1009 pos
= sci_get_position_from_line(doc
->editor
->sci
, line
);
1011 text
= templates_get_template_function(doc
, cur_tag
);
1013 sci_start_undo_action(doc
->editor
->sci
);
1014 sci_insert_text(doc
->editor
->sci
, pos
, text
);
1015 sci_end_undo_action(doc
->editor
->sci
);
1020 static void insert_multiline_comment(GeanyDocument
*doc
, gint pos
)
1022 g_return_if_fail(doc
!= NULL
);
1023 g_return_if_fail(pos
== -1 || pos
>= 0);
1025 if (doc
->file_type
== NULL
)
1027 ui_set_statusbar(FALSE
,
1028 _("Please set the filetype for the current file before using this function."));
1032 if (doc
->file_type
->comment_open
|| doc
->file_type
->comment_single
)
1034 /* editor_insert_multiline_comment() uses editor_info.click_pos */
1036 editor_info
.click_pos
= sci_get_current_position(doc
->editor
->sci
);
1038 editor_info
.click_pos
= pos
;
1039 editor_insert_multiline_comment(doc
->editor
);
1046 static void on_comments_multiline_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1048 insert_multiline_comment(document_get_current(), editor_info
.click_pos
);
1052 static void on_menu_comments_multiline_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1054 insert_multiline_comment(document_get_current(), -1);
1058 static void insert_comment_template(GeanyDocument
*doc
, gint pos
, guint
template)
1062 g_return_if_fail(doc
!= NULL
);
1063 g_return_if_fail(pos
== -1 || pos
>= 0);
1064 g_return_if_fail(template < GEANY_MAX_TEMPLATES
);
1067 pos
= sci_get_current_position(doc
->editor
->sci
);
1069 text
= templates_get_template_licence(doc
, template);
1071 sci_start_undo_action(doc
->editor
->sci
);
1072 sci_insert_text(doc
->editor
->sci
, pos
, text
);
1073 sci_end_undo_action(doc
->editor
->sci
);
1078 static void on_comments_gpl_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1080 insert_comment_template(document_get_current(), editor_info
.click_pos
, GEANY_TEMPLATE_GPL
);
1084 static void on_menu_comments_gpl_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1086 insert_comment_template(document_get_current(), -1, GEANY_TEMPLATE_GPL
);
1090 static void on_comments_bsd_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1092 insert_comment_template(document_get_current(), editor_info
.click_pos
, GEANY_TEMPLATE_BSD
);
1096 static void on_menu_comments_bsd_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1098 insert_comment_template(document_get_current(), -1, GEANY_TEMPLATE_BSD
);
1102 static void on_comments_changelog_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1104 GeanyDocument
*doc
= document_get_current();
1107 g_return_if_fail(doc
!= NULL
);
1109 text
= templates_get_template_changelog(doc
);
1110 sci_start_undo_action(doc
->editor
->sci
);
1111 sci_insert_text(doc
->editor
->sci
, 0, text
);
1112 /* sets the cursor to the right position to type the changelog text,
1113 * the template has 21 chars + length of name and email */
1114 sci_goto_pos(doc
->editor
->sci
, 21 + strlen(template_prefs
.developer
) + strlen(template_prefs
.mail
), TRUE
);
1115 sci_end_undo_action(doc
->editor
->sci
);
1121 static void on_comments_fileheader_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1123 GeanyDocument
*doc
= document_get_current();
1128 g_return_if_fail(doc
!= NULL
);
1130 ft
= doc
->file_type
;
1131 fname
= doc
->file_name
;
1132 text
= templates_get_template_fileheader(FILETYPE_ID(ft
), fname
);
1134 sci_start_undo_action(doc
->editor
->sci
);
1135 sci_insert_text(doc
->editor
->sci
, 0, text
);
1136 sci_goto_pos(doc
->editor
->sci
, 0, FALSE
);
1137 sci_end_undo_action(doc
->editor
->sci
);
1142 void on_file_properties_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1144 GeanyDocument
*doc
= document_get_current();
1145 g_return_if_fail(doc
!= NULL
);
1147 dialogs_show_file_properties(doc
);
1151 static void on_menu_fold_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1153 GeanyDocument
*doc
= document_get_current();
1154 g_return_if_fail(doc
!= NULL
);
1156 editor_fold_all(doc
->editor
);
1160 static void on_menu_unfold_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1162 GeanyDocument
*doc
= document_get_current();
1163 g_return_if_fail(doc
!= NULL
);
1165 editor_unfold_all(doc
->editor
);
1169 void on_toolbutton_run_clicked(GtkAction
*action
, gpointer user_data
)
1171 keybindings_send_command(GEANY_KEY_GROUP_BUILD
, GEANY_KEYS_BUILD_RUN
);
1175 void on_menu_remove_indicators1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1177 GeanyDocument
*doc
= document_get_current();
1178 g_return_if_fail(doc
!= NULL
);
1180 editor_indicator_clear(doc
->editor
, GEANY_INDICATOR_ERROR
);
1184 void on_print1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1186 GeanyDocument
*doc
= document_get_current();
1187 g_return_if_fail(doc
!= NULL
);
1189 printing_print_doc(doc
);
1193 void on_menu_select_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1195 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
1197 /* special case for Select All in the scribble widget */
1198 if (GTK_IS_TEXT_VIEW(focusw
))
1200 g_signal_emit_by_name(focusw
, "select-all", TRUE
);
1202 /* special case for Select All in the VTE widget */
1204 else if (vte_info
.have_vte
&& focusw
== vc
->vte
)
1209 else if (GTK_IS_EDITABLE(focusw
))
1211 gtk_editable_select_region(GTK_EDITABLE(focusw
), 0, -1);
1213 else if (IS_SCINTILLA(focusw
))
1215 sci_select_all(SCINTILLA(focusw
));
1220 void on_menu_show_sidebar1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
1222 if (ignore_callback
)
1225 ui_prefs
.sidebar_visible
= ! ui_prefs
.sidebar_visible
;
1227 /* show built-in tabs if no tabs visible */
1228 if (ui_prefs
.sidebar_visible
&&
1229 ! interface_prefs
.sidebar_openfiles_visible
&& ! interface_prefs
.sidebar_symbol_visible
&&
1230 gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets
.sidebar_notebook
)) <= 2)
1232 interface_prefs
.sidebar_openfiles_visible
= TRUE
;
1233 interface_prefs
.sidebar_symbol_visible
= TRUE
;
1236 /* if window has input focus, set it back to the editor before toggling off */
1237 if (! ui_prefs
.sidebar_visible
&&
1238 gtk_container_get_focus_child(GTK_CONTAINER(main_widgets
.sidebar_notebook
)) != NULL
)
1240 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
1243 ui_sidebar_show_hide();
1247 static void on_menu_write_unicode_bom1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
1249 if (! ignore_callback
)
1251 GeanyDocument
*doc
= document_get_current();
1253 g_return_if_fail(doc
!= NULL
);
1260 document_undo_add(doc
, UNDO_BOM
, GINT_TO_POINTER(doc
->has_bom
));
1262 doc
->has_bom
= ! doc
->has_bom
;
1264 ui_update_statusbar(doc
, -1);
1269 void on_menu_comment_line1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1271 GeanyDocument
*doc
= document_get_current();
1272 g_return_if_fail(doc
!= NULL
);
1274 editor_do_comment(doc
->editor
, -1, FALSE
, FALSE
, TRUE
);
1278 void on_menu_uncomment_line1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1280 GeanyDocument
*doc
= document_get_current();
1281 g_return_if_fail(doc
!= NULL
);
1283 editor_do_uncomment(doc
->editor
, -1, FALSE
);
1287 void on_menu_toggle_line_commentation1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1289 GeanyDocument
*doc
= document_get_current();
1290 g_return_if_fail(doc
!= NULL
);
1292 editor_do_comment_toggle(doc
->editor
);
1296 void on_menu_increase_indent1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1298 GeanyDocument
*doc
= document_get_current();
1299 g_return_if_fail(doc
!= NULL
);
1301 editor_indent(doc
->editor
, TRUE
);
1305 void on_menu_decrease_indent1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1307 GeanyDocument
*doc
= document_get_current();
1308 g_return_if_fail(doc
!= NULL
);
1310 editor_indent(doc
->editor
, FALSE
);
1314 void on_next_message1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1316 if (! ui_tree_view_find_next(GTK_TREE_VIEW(msgwindow
.tree_msg
),
1317 msgwin_goto_messages_file_line
))
1318 ui_set_statusbar(FALSE
, _("No more message items."));
1322 void on_previous_message1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1324 if (! ui_tree_view_find_previous(GTK_TREE_VIEW(msgwindow
.tree_msg
),
1325 msgwin_goto_messages_file_line
))
1326 ui_set_statusbar(FALSE
, _("No more message items."));
1330 void on_project_new1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1336 void on_project_open1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1342 void on_project_close1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1344 project_close(TRUE
);
1348 void on_project_properties1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1350 project_properties();
1354 static void on_menu_project1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1356 static GtkWidget
*item_close
= NULL
;
1357 static GtkWidget
*item_properties
= NULL
;
1359 if (item_close
== NULL
)
1361 item_close
= ui_lookup_widget(main_widgets
.window
, "project_close1");
1362 item_properties
= ui_lookup_widget(main_widgets
.window
, "project_properties1");
1365 gtk_widget_set_sensitive(item_close
, (app
->project
!= NULL
));
1366 gtk_widget_set_sensitive(item_properties
, (app
->project
!= NULL
));
1367 gtk_widget_set_sensitive(ui_widgets
.recent_projects_menuitem
,
1368 g_queue_get_length(ui_prefs
.recent_projects_queue
) > 0);
1372 void on_menu_open_selected_file1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1374 GeanyDocument
*doc
= document_get_current();
1379 wc
= GEANY_WORDCHARS
"./-" "\\";
1381 wc
= GEANY_WORDCHARS
"./-";
1384 g_return_if_fail(doc
!= NULL
);
1386 sel
= editor_get_default_selection(doc
->editor
, TRUE
, wc
);
1387 SETPTR(sel
, utils_get_locale_from_utf8(sel
));
1391 gchar
*filename
= NULL
;
1393 if (g_path_is_absolute(sel
))
1394 filename
= g_strdup(sel
);
1396 { /* relative filename, add the path of the current file */
1399 path
= utils_get_current_file_dir_utf8();
1400 SETPTR(path
, utils_get_locale_from_utf8(path
));
1402 path
= g_get_current_dir();
1404 filename
= g_build_path(G_DIR_SEPARATOR_S
, path
, sel
, NULL
);
1406 if (! g_file_test(filename
, G_FILE_TEST_EXISTS
) &&
1407 app
->project
!= NULL
&& !EMPTY(app
->project
->base_path
))
1409 /* try the project's base path */
1410 SETPTR(path
, project_get_base_path());
1411 SETPTR(path
, utils_get_locale_from_utf8(path
));
1412 SETPTR(filename
, g_build_path(G_DIR_SEPARATOR_S
, path
, sel
, NULL
));
1416 if (! g_file_test(filename
, G_FILE_TEST_EXISTS
))
1417 SETPTR(filename
, g_build_path(G_DIR_SEPARATOR_S
, "/usr/local/include", sel
, NULL
));
1419 if (! g_file_test(filename
, G_FILE_TEST_EXISTS
))
1420 SETPTR(filename
, g_build_path(G_DIR_SEPARATOR_S
, "/usr/include", sel
, NULL
));
1424 if (g_file_test(filename
, G_FILE_TEST_EXISTS
))
1425 document_open_file(filename
, FALSE
, NULL
, NULL
);
1428 SETPTR(sel
, utils_get_utf8_from_locale(sel
));
1429 ui_set_statusbar(TRUE
, _("Could not open file %s (File not found)"), sel
);
1438 void on_remove_markers1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1440 GeanyDocument
*doc
= document_get_current();
1441 g_return_if_fail(doc
!= NULL
);
1443 sci_marker_delete_all(doc
->editor
->sci
, 0); /* delete the yellow tag marker */
1444 sci_marker_delete_all(doc
->editor
->sci
, 1); /* delete user markers */
1445 editor_indicator_clear(doc
->editor
, GEANY_INDICATOR_SEARCH
);
1449 static void on_load_tags1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1451 symbols_show_load_tags_dialog();
1455 void on_context_action1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1457 gchar
*word
, *command
;
1458 GError
*error
= NULL
;
1459 GeanyDocument
*doc
= document_get_current();
1460 const gchar
*check_msg
;
1462 g_return_if_fail(doc
!= NULL
);
1464 if (sci_has_selection(doc
->editor
->sci
))
1465 { /* take selected text if there is a selection */
1466 word
= sci_get_selection_contents(doc
->editor
->sci
);
1470 word
= g_strdup(editor_info
.current_word
);
1473 /* use the filetype specific command if available, fallback to global command otherwise */
1474 if (doc
->file_type
!= NULL
&&
1475 !EMPTY(doc
->file_type
->context_action_cmd
))
1477 command
= g_strdup(doc
->file_type
->context_action_cmd
);
1478 check_msg
= _("Check the path setting in Filetype configuration.");
1482 command
= g_strdup(tool_prefs
.context_action_cmd
);
1483 check_msg
= _("Check the path setting in Preferences.");
1486 /* substitute the wildcard %s and run the command if it is non empty */
1487 if (G_LIKELY(!EMPTY(command
)))
1489 gchar
*command_line
= g_strdup(command
);
1491 utils_str_replace_all(&command_line
, "%s", word
);
1493 if (!spawn_async(NULL
, command_line
, NULL
, NULL
, NULL
, &error
))
1495 /* G_SHELL_ERROR is parsing error, it may be caused by %s word with quotes */
1496 ui_set_statusbar(TRUE
, _("Cannot execute context action command \"%s\": %s. %s"),
1497 error
->domain
== G_SHELL_ERROR
? command_line
: command
, error
->message
,
1499 g_error_free(error
);
1501 g_free(command_line
);
1505 ui_set_statusbar(TRUE
, _("No context action set."));
1512 void on_menu_toggle_all_additional_widgets1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1514 static gint hide_all
= -1;
1515 GtkCheckMenuItem
*msgw
= GTK_CHECK_MENU_ITEM(
1516 ui_lookup_widget(main_widgets
.window
, "menu_show_messages_window1"));
1517 GtkCheckMenuItem
*toolbari
= GTK_CHECK_MENU_ITEM(
1518 ui_lookup_widget(main_widgets
.window
, "menu_show_toolbar1"));
1520 /* get the initial state (necessary if Geany was closed with hide_all = TRUE) */
1521 if (G_UNLIKELY(hide_all
== -1))
1523 if (! gtk_check_menu_item_get_active(msgw
) &&
1524 ! interface_prefs
.show_notebook_tabs
&&
1525 ! gtk_check_menu_item_get_active(toolbari
))
1533 hide_all
= ! hide_all
; /* toggle */
1537 if (gtk_check_menu_item_get_active(msgw
))
1538 gtk_check_menu_item_set_active(msgw
, ! gtk_check_menu_item_get_active(msgw
));
1540 interface_prefs
.show_notebook_tabs
= FALSE
;
1541 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets
.notebook
), interface_prefs
.show_notebook_tabs
);
1543 ui_statusbar_showhide(FALSE
);
1545 if (gtk_check_menu_item_get_active(toolbari
))
1546 gtk_check_menu_item_set_active(toolbari
, ! gtk_check_menu_item_get_active(toolbari
));
1551 if (! gtk_check_menu_item_get_active(msgw
))
1552 gtk_check_menu_item_set_active(msgw
, ! gtk_check_menu_item_get_active(msgw
));
1554 interface_prefs
.show_notebook_tabs
= TRUE
;
1555 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets
.notebook
), interface_prefs
.show_notebook_tabs
);
1557 ui_statusbar_showhide(TRUE
);
1559 if (! gtk_check_menu_item_get_active(toolbari
))
1560 gtk_check_menu_item_set_active(toolbari
, ! gtk_check_menu_item_get_active(toolbari
));
1565 void on_toolbutton_forward_activate(GtkAction
*menuitem
, gpointer user_data
)
1567 navqueue_go_forward();
1571 void on_toolbutton_back_activate(GtkAction
*menuitem
, gpointer user_data
)
1577 gboolean
on_motion_event(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
)
1579 if (prefs
.auto_focus
&& ! gtk_widget_has_focus(widget
))
1580 gtk_widget_grab_focus(widget
);
1586 static void set_indent_type(GtkCheckMenuItem
*menuitem
, GeanyIndentType type
)
1590 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
1593 doc
= document_get_current();
1594 g_return_if_fail(doc
!= NULL
);
1596 editor_set_indent(doc
->editor
, type
, doc
->editor
->indent_width
);
1597 ui_update_statusbar(doc
, -1);
1601 static void on_tabs1_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
1603 set_indent_type(menuitem
, GEANY_INDENT_TYPE_TABS
);
1607 static void on_spaces1_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
1609 set_indent_type(menuitem
, GEANY_INDENT_TYPE_SPACES
);
1613 static void on_tabs_and_spaces1_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
1615 set_indent_type(menuitem
, GEANY_INDENT_TYPE_BOTH
);
1619 static void on_strip_trailing_spaces1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1623 if (ignore_callback
)
1626 doc
= document_get_current();
1627 g_return_if_fail(doc
!= NULL
);
1629 editor_strip_trailing_spaces(doc
->editor
, FALSE
);
1633 static void on_page_setup1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1635 printing_page_setup_gtk();
1639 gboolean
on_escape_key_press_event(GtkWidget
*widget
, GdkEventKey
*event
, gpointer user_data
)
1641 guint state
= keybindings_get_modifiers(event
->state
);
1643 /* make pressing escape in the sidebar and toolbar focus the editor */
1644 if (event
->keyval
== GDK_Escape
&& state
== 0)
1646 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
1653 void on_line_breaking1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1657 if (ignore_callback
)
1660 doc
= document_get_current();
1661 g_return_if_fail(doc
!= NULL
);
1663 doc
->editor
->line_breaking
= !doc
->editor
->line_breaking
;
1667 void on_replace_spaces_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1669 GeanyDocument
*doc
= document_get_current();
1671 g_return_if_fail(doc
!= NULL
);
1673 editor_replace_spaces(doc
->editor
, FALSE
);
1677 static void on_search1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1679 GtkWidget
*next_message
= ui_lookup_widget(main_widgets
.window
, "next_message1");
1680 GtkWidget
*previous_message
= ui_lookup_widget(main_widgets
.window
, "previous_message1");
1681 gboolean have_messages
;
1683 /* enable commands if the messages window has any items */
1684 have_messages
= gtk_tree_model_iter_n_children(GTK_TREE_MODEL(msgwindow
.store_msg
),
1687 gtk_widget_set_sensitive(next_message
, have_messages
);
1688 gtk_widget_set_sensitive(previous_message
, have_messages
);
1692 /* simple implementation (vs. close all which doesn't close documents if cancelled),
1693 * if user_data is set, it is the GeanyDocument to keep */
1694 void on_close_other_documents1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1697 GeanyDocument
*cur_doc
= user_data
;
1699 if (cur_doc
== NULL
)
1700 cur_doc
= document_get_current();
1702 for (i
= 0; i
< documents_array
->len
; i
++)
1704 GeanyDocument
*doc
= documents
[i
];
1706 if (doc
== cur_doc
|| ! doc
->is_valid
)
1709 if (! document_close(doc
))
1715 static void on_menu_reload_configuration1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1717 main_reload_configuration();
1721 static void on_debug_messages1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1723 log_show_debug_messages_dialog();
1727 void on_send_selection_to_vte1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1730 if (vte_info
.have_vte
)
1731 vte_send_selection_to_vte();
1736 static gboolean
on_window_state_event(GtkWidget
*widget
, GdkEventWindowState
*event
, gpointer user_data
)
1739 if (event
->changed_mask
& GDK_WINDOW_STATE_FULLSCREEN
)
1741 static GtkWidget
*menuitem
= NULL
;
1743 if (menuitem
== NULL
)
1744 menuitem
= ui_lookup_widget(widget
, "menu_fullscreen1");
1746 ignore_callback
= TRUE
;
1748 ui_prefs
.fullscreen
= (event
->new_window_state
& GDK_WINDOW_STATE_FULLSCREEN
) ? TRUE
: FALSE
;
1749 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem
), ui_prefs
.fullscreen
);
1751 ignore_callback
= FALSE
;
1757 static void show_notebook_page(const gchar
*notebook_name
, const gchar
*page_name
)
1760 GtkNotebook
*notebook
;
1762 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, page_name
);
1763 notebook
= GTK_NOTEBOOK(ui_lookup_widget(ui_widgets
.prefs_dialog
, notebook_name
));
1765 if (notebook
!= NULL
&& widget
!= NULL
)
1766 gtk_notebook_set_current_page(notebook
, gtk_notebook_page_num(notebook
, widget
));
1770 static void on_customize_toolbar1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1772 prefs_show_dialog();
1774 /* select the Interface page */
1775 show_notebook_page("notebook2", "notebook6");
1776 /* select the Toolbar subpage */
1777 show_notebook_page("notebook6", "vbox15");
1781 static void on_button_customize_toolbar_clicked(GtkButton
*button
, gpointer user_data
)
1783 toolbar_configure(GTK_WINDOW(ui_widgets
.prefs_dialog
));
1787 static void on_cut_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1789 keybindings_send_command(GEANY_KEY_GROUP_CLIPBOARD
, GEANY_KEYS_CLIPBOARD_CUTLINE
);
1793 static void on_copy_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1795 keybindings_send_command(GEANY_KEY_GROUP_CLIPBOARD
, GEANY_KEYS_CLIPBOARD_COPYLINE
);
1799 static void on_delete_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1801 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_DELETELINE
);
1805 static void on_duplicate_line_or_selection1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1807 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_DUPLICATELINE
);
1811 static void on_select_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1813 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_LINE
);
1817 static void on_select_current_paragraph1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1819 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_PARAGRAPH
);
1823 static void on_insert_alternative_white_space1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1825 keybindings_send_command(GEANY_KEY_GROUP_INSERT
, GEANY_KEYS_INSERT_ALTWHITESPACE
);
1829 static void on_go_to_next_marker1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1831 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_NEXTMARKER
);
1835 static void on_go_to_previous_marker1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1837 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_PREVIOUSMARKER
);
1841 static void on_reflow_lines_block1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1843 keybindings_send_command(GEANY_KEY_GROUP_FORMAT
, GEANY_KEYS_FORMAT_REFLOWPARAGRAPH
);
1847 static void on_move_lines_up1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1849 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_MOVELINEUP
);
1853 static void on_move_lines_down1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1855 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_MOVELINEDOWN
);
1859 static void on_smart_line_indent1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1861 keybindings_send_command(GEANY_KEY_GROUP_FORMAT
, GEANY_KEYS_FORMAT_AUTOINDENT
);
1865 void on_plugin_preferences1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1868 plugin_show_configure(NULL
);
1873 static void on_indent_width_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1879 if (ignore_callback
)
1882 label
= ui_menu_item_get_text(menuitem
);
1883 width
= atoi(label
);
1886 doc
= document_get_current();
1887 if (doc
!= NULL
&& width
> 0)
1888 editor_set_indent_width(doc
->editor
, width
);
1892 static void on_reset_indentation1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1897 document_apply_indent_settings(documents
[i
]);
1899 ui_update_statusbar(NULL
, -1);
1900 ui_document_show_hide(NULL
);
1904 static void on_mark_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1906 keybindings_send_command(GEANY_KEY_GROUP_SEARCH
, GEANY_KEYS_SEARCH_MARKALL
);
1910 static void on_detect_type_from_file_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1912 GeanyDocument
*doc
= document_get_current();
1913 GeanyIndentType type
;
1915 if (doc
!= NULL
&& document_detect_indent_type(doc
, &type
))
1917 editor_set_indent_type(doc
->editor
, type
);
1918 ui_document_show_hide(doc
);
1919 ui_update_statusbar(doc
, -1);
1924 static void on_show_symbol_list_toggled(GtkToggleButton
*button
, gpointer user_data
)
1926 GtkWidget
*widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "box_show_symbol_list_children");
1928 gtk_widget_set_sensitive(widget
, gtk_toggle_button_get_active(button
));
1932 static void on_detect_width_from_file_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1934 GeanyDocument
*doc
= document_get_current();
1937 if (doc
!= NULL
&& document_detect_indent_width(doc
, &width
))
1939 editor_set_indent_width(doc
->editor
, width
);
1940 ui_document_show_hide(doc
);
1945 static void builder_connect_func(GtkBuilder
*builder
, GObject
*object
,
1946 const gchar
*signal_name
, const gchar
*handler_name
, GObject
*connect_obj
,
1947 GConnectFlags flags
, gpointer user_data
)
1949 GHashTable
*hash
= user_data
;
1952 callback
= g_hash_table_lookup(hash
, handler_name
);
1953 g_return_if_fail(callback
);
1955 if (connect_obj
== NULL
)
1956 g_signal_connect_data(object
, signal_name
, callback
, NULL
, NULL
, flags
);
1958 g_signal_connect_object(object
, signal_name
, callback
, connect_obj
, flags
);
1962 void callbacks_connect(GtkBuilder
*builder
)
1966 g_return_if_fail(GTK_IS_BUILDER(builder
));
1968 hash
= g_hash_table_new(g_str_hash
, g_str_equal
);
1970 #define ITEM(n) g_hash_table_insert(hash, (gpointer) #n, G_CALLBACK(n));
1971 # include "signallist.i"
1974 gtk_builder_connect_signals_full(builder
, builder_connect_func
, hash
);
1975 g_hash_table_destroy(hash
);