2 * callbacks.c - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2005 The Geany contributors
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 * Callbacks used by Glade. These are mainly in response to menu item and button events in the
23 * main window. Callbacks not used by Glade should go elsewhere.
30 #include "callbacks.h"
36 #include "documentprivate.h"
37 #include "encodings.h"
38 #include "filetypes.h"
39 #include "geanyobject.h"
40 #include "highlighting.h"
41 #include "keybindings.h"
45 #include "msgwindow.h"
48 #include "pluginutils.h"
51 #include "sciwrappers.h"
59 #include "templates.h"
70 #include <gdk/gdkkeysyms.h>
71 #include <glib/gstdio.h>
75 /* represents the state at switching a notebook page(in the left treeviews widget), to not emit
76 * the selection-changed signal from tv.tree_openfiles */
77 /*static gboolean switch_tv_notebook_page = FALSE; */
81 /* wrapper function to abort exit process if cancel button is pressed */
82 static gboolean
on_window_delete_event(GtkWidget
*widget
, GdkEvent
*event
, gpointer gdata
)
92 void on_new1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
94 keybindings_send_command(GEANY_KEY_GROUP_FILE
, GEANY_KEYS_FILE_NEW
);
98 /* create a new file and copy file content and properties */
99 static void on_clone1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
101 GeanyDocument
*old_doc
= document_get_current();
104 document_clone(old_doc
);
108 void on_save1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
110 GeanyDocument
*doc
= document_get_current();
114 document_save_file(doc
, ui_prefs
.allow_always_save
);
119 void on_save_as1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
121 dialogs_show_save_as();
125 void on_save_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
127 guint i
, max
= (guint
) gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets
.notebook
));
128 GeanyDocument
*cur_doc
= document_get_current();
131 /* iterate over documents in tabs order */
132 for (i
= 0; i
< max
; i
++)
134 GeanyDocument
*doc
= document_get_from_page(i
);
139 if (document_save_file(doc
, FALSE
))
145 ui_set_statusbar(FALSE
, ngettext("%d file saved.", "%d files saved.", count
), count
);
146 /* saving may have changed window title, sidebar for another doc, so update */
147 document_show_tab(cur_doc
);
148 sidebar_update_tag_list(cur_doc
, TRUE
);
149 ui_set_window_title(cur_doc
);
153 void on_close_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
155 document_close_all();
159 void on_close1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
161 GeanyDocument
*doc
= document_get_current();
168 void on_quit1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
174 static void on_file1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
176 gtk_widget_set_sensitive(ui_widgets
.recent_files_menuitem
,
177 g_queue_get_length(ui_prefs
.recent_queue
) > 0);
178 /* hide Page setup when GTK printing is not used */
179 ui_widget_show_hide(ui_widgets
.print_page_setup
, printing_prefs
.use_gtk_printing
);
183 /* edit actions, c&p & co, from menu bar and from popup menu */
184 static void on_edit1_select(GtkMenuItem
*menuitem
, gpointer user_data
)
187 GeanyDocument
*doc
= document_get_current();
189 ui_update_menu_copy_items(doc
);
190 ui_update_insert_include_item(doc
, 1);
192 item
= ui_lookup_widget(main_widgets
.window
, "plugin_preferences1");
194 gtk_widget_hide(item
);
196 gtk_widget_set_sensitive(item
, plugins_have_preferences());
201 static void on_edit1_deselect(GtkMenuShell
*menushell
, gpointer user_data
)
203 /* we re-enable items that were disabled in on_edit1_select() on menu popdown to
204 * workaround mutli-layout keyboard issues in our keybinding handling code, so that
205 * GTK's accelerator handling can catch them.
206 * See https://github.com/geany/geany/issues/1368#issuecomment-273678207 */
207 ui_menu_copy_items_set_sensitive(TRUE
);
211 void on_undo1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
213 GeanyDocument
*doc
= document_get_current();
215 g_return_if_fail(doc
!= NULL
);
217 if (document_can_undo(doc
))
219 sci_cancel(doc
->editor
->sci
);
225 void on_redo1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
227 GeanyDocument
*doc
= document_get_current();
229 g_return_if_fail(doc
!= NULL
);
231 if (document_can_redo(doc
))
233 sci_cancel(doc
->editor
->sci
);
239 void on_cut1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
241 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
243 if (GTK_IS_EDITABLE(focusw
))
244 gtk_editable_cut_clipboard(GTK_EDITABLE(focusw
));
245 else if (IS_SCINTILLA(focusw
))
246 sci_cut(SCINTILLA(focusw
));
247 else if (GTK_IS_TEXT_VIEW(focusw
))
249 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(
250 GTK_TEXT_VIEW(focusw
));
251 gtk_text_buffer_cut_clipboard(buffer
, gtk_clipboard_get(GDK_NONE
), TRUE
);
256 void on_copy1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
258 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
260 if (GTK_IS_EDITABLE(focusw
))
261 gtk_editable_copy_clipboard(GTK_EDITABLE(focusw
));
262 else if (IS_SCINTILLA(focusw
))
263 sci_copy(SCINTILLA(focusw
));
264 else if (GTK_IS_TEXT_VIEW(focusw
))
266 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(
267 GTK_TEXT_VIEW(focusw
));
268 gtk_text_buffer_copy_clipboard(buffer
, gtk_clipboard_get(GDK_NONE
));
273 void on_paste1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
275 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
277 if (GTK_IS_EDITABLE(focusw
))
278 gtk_editable_paste_clipboard(GTK_EDITABLE(focusw
));
279 else if (IS_SCINTILLA(focusw
))
280 sci_paste(SCINTILLA(focusw
));
281 else if (GTK_IS_TEXT_VIEW(focusw
))
283 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(
284 GTK_TEXT_VIEW(focusw
));
285 gtk_text_buffer_paste_clipboard(buffer
, gtk_clipboard_get(GDK_NONE
), NULL
,
291 void on_delete1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
293 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
295 if (GTK_IS_EDITABLE(focusw
))
296 gtk_editable_delete_selection(GTK_EDITABLE(focusw
));
297 else if (IS_SCINTILLA(focusw
) && sci_has_selection(SCINTILLA(focusw
)))
298 sci_clear(SCINTILLA(focusw
));
299 else if (GTK_IS_TEXT_VIEW(focusw
))
301 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(
302 GTK_TEXT_VIEW(focusw
));
303 gtk_text_buffer_delete_selection(buffer
, TRUE
, TRUE
);
308 void on_preferences1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
314 /* about menu item */
315 static void on_info1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
322 void on_open1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
324 dialogs_show_open_file();
329 void on_toolbutton_reload_clicked(GtkAction
*action
, gpointer user_data
)
331 GeanyDocument
*doc
= document_get_current();
333 g_return_if_fail(doc
!= NULL
);
335 document_reload_prompt(doc
, NULL
);
338 /* reload all files */
339 void on_reload_all(GtkAction
*action
, gpointer user_data
)
342 gint cur_page
= gtk_notebook_get_current_page(GTK_NOTEBOOK(main_widgets
.notebook
));
344 if (!file_prefs
.keep_edit_history_on_reload
)
350 if (doc
->changed
|| document_can_undo(doc
) || document_can_redo(doc
))
352 if (dialogs_show_question_full(NULL
, _("_Reload"), GTK_STOCK_CANCEL
,
353 _("Changes detected, reloading all will lose any changes and history."),
354 _("Are you sure you want to reload all files?")))
356 break; // break the loop and continue with reloading below
360 return; // cancel reloading
368 if (! (documents
[i
]->file_name
== NULL
))
369 document_reload_force(documents
[i
], documents
[i
]->encoding
);
372 gtk_notebook_set_current_page(GTK_NOTEBOOK(main_widgets
.notebook
), cur_page
);
376 static void on_change_font1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
378 dialogs_show_open_font();
382 /* store text, clear search flags so we can use Search->Find Next/Previous */
383 static void setup_find(const gchar
*text
, gboolean backwards
)
385 SETPTR(search_data
.text
, g_strdup(text
));
386 SETPTR(search_data
.original_text
, g_strdup(text
));
387 search_data
.flags
= 0;
388 search_data
.backwards
= backwards
;
389 search_data
.search_bar
= TRUE
;
393 static void do_toolbar_search(const gchar
*text
, gboolean incremental
, gboolean backwards
)
395 GeanyDocument
*doc
= document_get_current();
398 setup_find(text
, backwards
);
399 result
= document_search_bar_find(doc
, search_data
.text
, incremental
, backwards
);
400 if (search_data
.search_bar
)
401 ui_set_search_entry_background(toolbar_get_widget_child_by_name("SearchEntry"), result
);
406 void on_toolbar_search_entry_changed(GtkAction
*action
, const gchar
*text
, gpointer user_data
)
408 do_toolbar_search(text
, TRUE
, FALSE
);
413 void on_toolbar_search_entry_activate(GtkAction
*action
, const gchar
*text
, gpointer user_data
)
415 do_toolbar_search(text
, FALSE
, GPOINTER_TO_INT(user_data
));
420 void on_toolbutton_search_clicked(GtkAction
*action
, gpointer user_data
)
422 GeanyDocument
*doc
= document_get_current();
424 GtkWidget
*entry
= toolbar_get_widget_child_by_name("SearchEntry");
428 const gchar
*text
= gtk_entry_get_text(GTK_ENTRY(entry
));
430 setup_find(text
, FALSE
);
431 result
= document_search_bar_find(doc
, search_data
.text
, FALSE
, FALSE
);
432 if (search_data
.search_bar
)
433 ui_set_search_entry_background(entry
, result
);
436 on_find1_activate(NULL
, NULL
);
440 void on_entry_tagfilter_changed(GtkAction
*action
, gpointer user_data
)
442 GeanyDocument
*doc
= document_get_current();
443 GtkEntry
*filter_entry
;
448 filter_entry
= GTK_ENTRY(ui_lookup_widget(main_widgets
.window
, "entry_tagfilter"));
449 g_free(doc
->priv
->tag_filter
);
450 doc
->priv
->tag_filter
= g_strdup(gtk_entry_get_text(filter_entry
));
452 /* make sure the tree is fully re-created so it appears correctly
453 * after applying filter */
454 if (doc
->priv
->tag_store
)
455 gtk_tree_store_clear(doc
->priv
->tag_store
);
456 sidebar_update_tag_list(doc
, TRUE
);
460 void on_entry_tagfilter_icon_press(GtkEntry
*entry
, GtkEntryIconPosition icon_pos
, GdkEvent
*event
, gpointer user_data
)
462 if (event
->button
.button
== 1)
463 gtk_entry_set_text(entry
, "");
467 void on_entry_tagfilter_activate(GtkEntry
*entry
, gpointer user_data
)
469 GeanyDocument
*doc
= document_get_current();
474 gtk_widget_grab_focus(doc
->priv
->tag_tree
);
478 /* hides toolbar from toolbar popup menu */
479 static void on_hide_toolbar1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
481 GtkWidget
*tool_item
= ui_lookup_widget(GTK_WIDGET(main_widgets
.window
), "menu_show_toolbar1");
482 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(tool_item
), FALSE
);
486 /* zoom in from menu bar and popup menu */
487 void on_zoom_in1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
489 GeanyDocument
*doc
= document_get_current();
491 g_return_if_fail(doc
!= NULL
);
493 sci_zoom_in(doc
->editor
->sci
);
497 /* zoom out from menu bar and popup menu */
498 void on_zoom_out1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
500 GeanyDocument
*doc
= document_get_current();
502 g_return_if_fail(doc
!= NULL
);
504 sci_zoom_out(doc
->editor
->sci
);
508 void on_normal_size1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
510 GeanyDocument
*doc
= document_get_current();
512 g_return_if_fail(doc
!= NULL
);
514 sci_zoom_off(doc
->editor
->sci
);
518 /* Changes window-title after switching tabs and lots of other things.
519 * note: using 'after' makes Scintilla redraw before the UI, appearing more responsive */
520 static void on_notebook1_switch_page_after(GtkNotebook
*notebook
, gpointer page
,
521 guint page_num
, gpointer user_data
)
525 if (G_UNLIKELY(main_status
.opening_session_files
|| main_status
.closing_all
))
528 doc
= document_get_from_notebook_child(page
);
532 GtkEntry
*filter_entry
= GTK_ENTRY(ui_lookup_widget(main_widgets
.window
, "entry_tagfilter"));
533 const gchar
*entry_text
= gtk_entry_get_text(filter_entry
);
535 sidebar_select_openfiles_item(doc
);
536 ui_save_buttons_toggle(doc
->changed
);
537 ui_set_window_title(doc
);
538 ui_update_statusbar(doc
, -1);
539 ui_update_popup_reundo_items(doc
);
540 ui_document_show_hide(doc
); /* update the document menu */
541 build_menu_update(doc
);
542 if (g_strcmp0(entry_text
, doc
->priv
->tag_filter
) != 0)
544 /* calls sidebar_update_tag_list() in on_entry_tagfilter_changed() */
545 gtk_entry_set_text(filter_entry
, doc
->priv
->tag_filter
);
548 sidebar_update_tag_list(doc
, TRUE
);
549 document_highlight_tags(doc
);
551 document_check_disk_status(doc
, TRUE
);
554 vte_cwd((doc
->real_path
!= NULL
) ? doc
->real_path
: doc
->file_name
, FALSE
);
557 g_signal_emit_by_name(geany_object
, "document-activate", doc
);
562 static void on_tv_notebook_switch_page(GtkNotebook
*notebook
, gpointer page
,
563 guint page_num
, gpointer user_data
)
565 /* suppress selection changed signal when switching to the open files list */
566 ignore_callback
= TRUE
;
570 static void on_tv_notebook_switch_page_after(GtkNotebook
*notebook
, gpointer page
,
571 guint page_num
, gpointer user_data
)
573 ignore_callback
= FALSE
;
577 static void convert_eol(gint mode
)
579 GeanyDocument
*doc
= document_get_current();
581 g_return_if_fail(doc
!= NULL
);
583 /* sci_convert_eols() adds UNDO_SCINTILLA action in on_editor_notify().
584 * It is added to the undo stack before sci_convert_eols() finishes
585 * so after adding UNDO_EOL, UNDO_EOL will be at the top of the stack
586 * and UNDO_SCINTILLA below it. */
587 sci_convert_eols(doc
->editor
->sci
, mode
);
588 document_undo_add(doc
, UNDO_EOL
, GINT_TO_POINTER(sci_get_eol_mode(doc
->editor
->sci
)));
590 sci_set_eol_mode(doc
->editor
->sci
, mode
);
592 ui_update_statusbar(doc
, -1);
596 static void on_crlf_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
598 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
601 convert_eol(SC_EOL_CRLF
);
605 static void on_lf_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
607 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
610 convert_eol(SC_EOL_LF
);
614 static void on_cr_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
616 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
619 convert_eol(SC_EOL_CR
);
623 void on_replace_tabs_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
625 GeanyDocument
*doc
= document_get_current();
627 g_return_if_fail(doc
!= NULL
);
629 editor_replace_tabs(doc
->editor
, FALSE
);
633 gboolean
toolbar_popup_menu(GtkWidget
*widget
, GdkEventButton
*event
, gpointer user_data
)
635 if (event
->button
== 3)
637 ui_menu_popup(GTK_MENU(ui_widgets
.toolbar_menu
), NULL
, NULL
, event
->button
, event
->time
);
644 void on_toggle_case1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
646 GeanyDocument
*doc
= document_get_current();
647 ScintillaObject
*sci
;
648 gboolean keep_sel
= TRUE
;
650 g_return_if_fail(doc
!= NULL
);
652 sci
= doc
->editor
->sci
;
653 if (! sci_has_selection(sci
))
655 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_WORD
);
659 /* either we already had a selection or we created one for current word */
660 if (sci_has_selection(sci
))
662 gchar
*result
= NULL
;
663 gint cmd
= SCI_LOWERCASE
;
664 gboolean rectsel
= (gboolean
) SSM(sci
, SCI_SELECTIONISRECTANGLE
, 0, 0);
665 gchar
*text
= sci_get_selection_contents(sci
);
667 if (utils_str_has_upper(text
))
672 result
= g_utf8_strdown(text
, -1);
679 result
= g_utf8_strup(text
, -1);
684 sci_replace_sel(sci
, result
);
687 sci_set_selection_start(sci
, sci_get_current_position(sci
) - strlen(text
));
690 sci_send_command(sci
, cmd
);
697 static void on_show_toolbar1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
699 if (ignore_callback
) return;
701 toolbar_prefs
.visible
= (toolbar_prefs
.visible
) ? FALSE
: TRUE
;;
702 ui_widget_show_hide(GTK_WIDGET(main_widgets
.toolbar
), toolbar_prefs
.visible
);
706 static void on_fullscreen1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
711 ui_prefs
.fullscreen
= (ui_prefs
.fullscreen
) ? FALSE
: TRUE
;
716 static void on_show_messages_window1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
721 ui_prefs
.msgwindow_visible
= (ui_prefs
.msgwindow_visible
) ? FALSE
: TRUE
;
722 msgwin_show_hide(ui_prefs
.msgwindow_visible
);
726 static void on_menu_color_schemes_activate(GtkImageMenuItem
*imagemenuitem
, gpointer user_data
)
728 highlighting_show_color_scheme_dialog();
732 static void on_markers_margin1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
737 editor_prefs
.show_markers_margin
= ! editor_prefs
.show_markers_margin
;
738 ui_toggle_editor_features(GEANY_EDITOR_SHOW_MARKERS_MARGIN
);
742 static void on_show_line_numbers1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
747 editor_prefs
.show_linenumber_margin
= ! editor_prefs
.show_linenumber_margin
;
748 ui_toggle_editor_features(GEANY_EDITOR_SHOW_LINE_NUMBERS
);
752 static void on_menu_show_white_space1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
757 editor_prefs
.show_white_space
= ! editor_prefs
.show_white_space
;
758 ui_toggle_editor_features(GEANY_EDITOR_SHOW_WHITE_SPACE
);
762 static void on_menu_show_line_endings1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
767 editor_prefs
.show_line_endings
= ! editor_prefs
.show_line_endings
;
768 ui_toggle_editor_features(GEANY_EDITOR_SHOW_LINE_ENDINGS
);
772 static void on_menu_show_indentation_guides1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
777 editor_prefs
.show_indent_guide
= ! editor_prefs
.show_indent_guide
;
778 ui_toggle_editor_features(GEANY_EDITOR_SHOW_INDENTATION_GUIDES
);
782 void on_line_wrapping1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
784 if (! ignore_callback
)
786 GeanyDocument
*doc
= document_get_current();
787 g_return_if_fail(doc
!= NULL
);
789 editor_set_line_wrapping(doc
->editor
, ! doc
->editor
->line_wrapping
);
794 static void on_set_file_readonly1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
796 if (! ignore_callback
)
798 GeanyDocument
*doc
= document_get_current();
799 g_return_if_fail(doc
!= NULL
);
801 doc
->readonly
= ! doc
->readonly
;
802 sci_set_readonly(doc
->editor
->sci
, doc
->readonly
);
803 ui_update_tab_status(doc
);
804 ui_update_statusbar(doc
, -1);
809 static void on_use_auto_indentation1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
811 if (! ignore_callback
)
813 GeanyDocument
*doc
= document_get_current();
814 g_return_if_fail(doc
!= NULL
);
816 doc
->editor
->auto_indent
= ! doc
->editor
->auto_indent
;
821 static void find_usage(gboolean in_session
)
823 GeanyFindFlags flags
;
825 GeanyDocument
*doc
= document_get_current();
827 g_return_if_fail(doc
!= NULL
);
829 if (sci_has_selection(doc
->editor
->sci
))
830 { /* take selected text if there is a selection */
831 search_text
= sci_get_selection_contents(doc
->editor
->sci
);
832 flags
= GEANY_FIND_MATCHCASE
;
836 editor_find_current_word_sciwc(doc
->editor
, -1,
837 editor_info
.current_word
, GEANY_MAX_WORD_LENGTH
);
838 search_text
= g_strdup(editor_info
.current_word
);
839 flags
= GEANY_FIND_MATCHCASE
| GEANY_FIND_WHOLEWORD
;
842 search_find_usage(search_text
, search_text
, flags
, in_session
);
847 void on_find_document_usage1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
853 void on_find_usage1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
859 static void goto_tag(gboolean definition
)
861 GeanyDocument
*doc
= document_get_current();
863 g_return_if_fail(doc
!= NULL
);
865 /* update cursor pos for navigating back afterwards */
866 if (!sci_has_selection(doc
->editor
->sci
))
867 sci_set_current_position(doc
->editor
->sci
, editor_info
.click_pos
, FALSE
);
869 /* use the keybinding callback as it checks for selections as well as current word */
871 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_TAGDEFINITION
);
873 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_TAGDECLARATION
);
877 static void on_goto_tag_definition1(GtkMenuItem
*menuitem
, gpointer user_data
)
883 static void on_goto_tag_declaration1(GtkMenuItem
*menuitem
, gpointer user_data
)
889 static void on_count_words1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
895 void on_show_color_chooser1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
898 GeanyDocument
*doc
= document_get_current();
901 g_return_if_fail(doc
!= NULL
);
903 pos
= sci_get_current_position(doc
->editor
->sci
);
904 editor_find_current_word(doc
->editor
, pos
, colour
, sizeof colour
, GEANY_WORDCHARS
"#");
905 tools_color_chooser(colour
);
909 void on_toolbutton_compile_clicked(GtkAction
*action
, gpointer user_data
)
911 keybindings_send_command(GEANY_KEY_GROUP_BUILD
, GEANY_KEYS_BUILD_COMPILE
);
915 void on_find1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
917 search_show_find_dialog();
921 void on_find_next1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
923 search_find_again(FALSE
);
927 void on_find_previous1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
929 if (search_data
.flags
& GEANY_FIND_REGEXP
)
930 /* Can't reverse search order for a regex (find next ignores search backwards) */
933 search_find_again(TRUE
);
937 void on_find_nextsel1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
939 search_find_selection(document_get_current(), FALSE
);
943 void on_find_prevsel1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
945 search_find_selection(document_get_current(), TRUE
);
949 void on_replace1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
951 search_show_replace_dialog();
955 void on_find_in_files1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
957 search_show_find_in_files_dialog(NULL
);
961 void on_go_to_line_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
963 static gchar value
[16] = "";
966 result
= dialogs_show_input_goto_line(
967 _("Go to Line"), GTK_WINDOW(main_widgets
.window
),
968 _("Enter the line you want to go to:"), value
);
971 on_toolbutton_goto_entry_activate(NULL
, result
, NULL
);
973 /* remember value for future calls */
974 g_snprintf(value
, sizeof(value
), "%s", result
);
980 void on_toolbutton_goto_entry_activate(GtkAction
*action
, const gchar
*text
, gpointer user_data
)
982 GeanyDocument
*doc
= document_get_current();
983 g_return_if_fail(doc
!= NULL
);
985 gint line_no
= atoi(text
);
986 gboolean offset
= (*text
== '+' || *text
== '-');
988 if (! editor_goto_line(doc
->editor
, line_no
, offset
))
991 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
995 void on_toolbutton_goto_clicked(GtkAction
*action
, gpointer user_data
)
997 GtkWidget
*entry
= toolbar_get_widget_child_by_name("GotoEntry");
1001 const gchar
*text
= gtk_entry_get_text(GTK_ENTRY(entry
));
1003 on_toolbutton_goto_entry_activate(NULL
, text
, NULL
);
1006 on_go_to_line_activate(NULL
, NULL
);
1010 void on_help1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1014 uri
= utils_get_help_url(NULL
);
1015 utils_open_browser(uri
);
1020 static void on_help_shortcuts1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1022 keybindings_show_shortcuts();
1026 static void on_website1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1028 utils_open_browser(GEANY_HOMEPAGE
);
1032 static void on_help_menu_item_donate_activate(GtkMenuItem
*item
, gpointer user_data
)
1034 utils_open_browser(GEANY_DONATE
);
1038 static void on_help_menu_item_wiki_activate(GtkMenuItem
*item
, gpointer user_data
)
1040 utils_open_browser(GEANY_WIKI
);
1044 static void on_help_menu_item_bug_report_activate(GtkMenuItem
*item
, gpointer user_data
)
1046 utils_open_browser(GEANY_BUG_REPORT
);
1050 static void on_comments_function_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1052 GeanyDocument
*doc
= document_get_current();
1054 const gchar
*cur_tag
= NULL
;
1055 gint line
= -1, pos
= 0;
1057 if (doc
== NULL
|| doc
->file_type
== NULL
)
1059 ui_set_statusbar(FALSE
,
1060 _("Please set the filetype for the current file before using this function."));
1064 /* symbols_get_current_function returns -1 on failure, so sci_get_position_from_line
1065 * returns the current position, so it should be safe */
1066 line
= symbols_get_current_function(doc
, &cur_tag
);
1067 pos
= sci_get_position_from_line(doc
->editor
->sci
, line
);
1069 text
= templates_get_template_function(doc
, cur_tag
);
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 insert_multiline_comment(GeanyDocument
*doc
, gint pos
)
1080 g_return_if_fail(doc
!= NULL
);
1081 g_return_if_fail(pos
== -1 || pos
>= 0);
1083 if (doc
->file_type
== NULL
)
1085 ui_set_statusbar(FALSE
,
1086 _("Please set the filetype for the current file before using this function."));
1090 if (doc
->file_type
->comment_open
|| doc
->file_type
->comment_single
)
1092 /* editor_insert_multiline_comment() uses editor_info.click_pos */
1094 editor_info
.click_pos
= sci_get_current_position(doc
->editor
->sci
);
1096 editor_info
.click_pos
= pos
;
1097 editor_insert_multiline_comment(doc
->editor
);
1104 static void on_comments_multiline_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1106 insert_multiline_comment(document_get_current(), editor_info
.click_pos
);
1110 static void on_menu_comments_multiline_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1112 insert_multiline_comment(document_get_current(), -1);
1116 static void insert_comment_template(GeanyDocument
*doc
, gint pos
, guint
template)
1120 g_return_if_fail(doc
!= NULL
);
1121 g_return_if_fail(pos
== -1 || pos
>= 0);
1122 g_return_if_fail(template < GEANY_MAX_TEMPLATES
);
1125 pos
= sci_get_current_position(doc
->editor
->sci
);
1127 text
= templates_get_template_licence(doc
, template);
1129 sci_start_undo_action(doc
->editor
->sci
);
1130 sci_insert_text(doc
->editor
->sci
, pos
, text
);
1131 sci_end_undo_action(doc
->editor
->sci
);
1136 static void on_comments_gpl_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1138 insert_comment_template(document_get_current(), editor_info
.click_pos
, GEANY_TEMPLATE_GPL
);
1142 static void on_menu_comments_gpl_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1144 insert_comment_template(document_get_current(), -1, GEANY_TEMPLATE_GPL
);
1148 static void on_comments_bsd_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1150 insert_comment_template(document_get_current(), editor_info
.click_pos
, GEANY_TEMPLATE_BSD
);
1154 static void on_menu_comments_bsd_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1156 insert_comment_template(document_get_current(), -1, GEANY_TEMPLATE_BSD
);
1160 static void on_comments_changelog_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1162 GeanyDocument
*doc
= document_get_current();
1165 g_return_if_fail(doc
!= NULL
);
1167 text
= templates_get_template_changelog(doc
);
1168 sci_start_undo_action(doc
->editor
->sci
);
1169 sci_insert_text(doc
->editor
->sci
, 0, text
);
1170 /* sets the cursor to the right position to type the changelog text,
1171 * the template has 21 chars + length of name and email */
1172 sci_goto_pos(doc
->editor
->sci
, 21 + strlen(template_prefs
.developer
) + strlen(template_prefs
.mail
), TRUE
);
1173 sci_end_undo_action(doc
->editor
->sci
);
1179 static void on_comments_fileheader_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1181 GeanyDocument
*doc
= document_get_current();
1186 g_return_if_fail(doc
!= NULL
);
1188 ft
= doc
->file_type
;
1189 fname
= doc
->file_name
;
1190 text
= templates_get_template_fileheader(FILETYPE_ID(ft
), fname
);
1192 sci_start_undo_action(doc
->editor
->sci
);
1193 sci_insert_text(doc
->editor
->sci
, 0, text
);
1194 sci_goto_pos(doc
->editor
->sci
, 0, FALSE
);
1195 sci_end_undo_action(doc
->editor
->sci
);
1200 void on_file_properties_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1202 GeanyDocument
*doc
= document_get_current();
1203 g_return_if_fail(doc
!= NULL
);
1205 dialogs_show_file_properties(doc
);
1209 static void on_menu_fold_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1211 GeanyDocument
*doc
= document_get_current();
1212 g_return_if_fail(doc
!= NULL
);
1214 editor_fold_all(doc
->editor
);
1218 static void on_menu_unfold_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1220 GeanyDocument
*doc
= document_get_current();
1221 g_return_if_fail(doc
!= NULL
);
1223 editor_unfold_all(doc
->editor
);
1227 void on_toolbutton_run_clicked(GtkAction
*action
, gpointer user_data
)
1229 keybindings_send_command(GEANY_KEY_GROUP_BUILD
, GEANY_KEYS_BUILD_RUN
);
1233 void on_menu_remove_indicators1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1235 GeanyDocument
*doc
= document_get_current();
1236 g_return_if_fail(doc
!= NULL
);
1238 editor_indicator_clear(doc
->editor
, GEANY_INDICATOR_ERROR
);
1242 void on_print1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1244 GeanyDocument
*doc
= document_get_current();
1245 g_return_if_fail(doc
!= NULL
);
1247 printing_print_doc(doc
);
1251 void on_menu_select_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1253 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
1255 /* special case for Select All in the scribble widget */
1256 if (GTK_IS_TEXT_VIEW(focusw
))
1258 g_signal_emit_by_name(focusw
, "select-all", TRUE
);
1260 /* special case for Select All in the VTE widget */
1262 else if (vte_info
.have_vte
&& focusw
== vte_config
.vte
)
1267 else if (GTK_IS_EDITABLE(focusw
))
1269 gtk_editable_select_region(GTK_EDITABLE(focusw
), 0, -1);
1271 else if (IS_SCINTILLA(focusw
))
1273 sci_select_all(SCINTILLA(focusw
));
1278 void on_menu_show_sidebar1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
1280 if (ignore_callback
)
1283 ui_prefs
.sidebar_visible
= ! ui_prefs
.sidebar_visible
;
1285 /* show built-in tabs if no tabs visible */
1286 if (ui_prefs
.sidebar_visible
&&
1287 ! interface_prefs
.sidebar_openfiles_visible
&& ! interface_prefs
.sidebar_symbol_visible
&&
1288 gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets
.sidebar_notebook
)) <= 2)
1290 interface_prefs
.sidebar_openfiles_visible
= TRUE
;
1291 interface_prefs
.sidebar_symbol_visible
= TRUE
;
1294 /* if window has input focus, set it back to the editor before toggling off */
1295 if (! ui_prefs
.sidebar_visible
&&
1296 gtk_container_get_focus_child(GTK_CONTAINER(main_widgets
.sidebar_notebook
)) != NULL
)
1298 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
1301 ui_sidebar_show_hide();
1305 static void on_menu_write_unicode_bom1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
1307 if (! ignore_callback
)
1309 GeanyDocument
*doc
= document_get_current();
1311 g_return_if_fail(doc
!= NULL
);
1318 document_undo_add(doc
, UNDO_BOM
, GINT_TO_POINTER(doc
->has_bom
));
1320 doc
->has_bom
= ! doc
->has_bom
;
1322 ui_update_statusbar(doc
, -1);
1327 void on_menu_comment_line1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1329 GeanyDocument
*doc
= document_get_current();
1330 g_return_if_fail(doc
!= NULL
);
1332 editor_do_comment(doc
->editor
, -1, FALSE
, FALSE
, TRUE
);
1336 void on_menu_uncomment_line1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1338 GeanyDocument
*doc
= document_get_current();
1339 g_return_if_fail(doc
!= NULL
);
1341 editor_do_uncomment(doc
->editor
, -1, FALSE
);
1345 void on_menu_toggle_line_commentation1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1347 GeanyDocument
*doc
= document_get_current();
1348 g_return_if_fail(doc
!= NULL
);
1350 editor_do_comment_toggle(doc
->editor
);
1354 void on_menu_increase_indent1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1356 GeanyDocument
*doc
= document_get_current();
1357 g_return_if_fail(doc
!= NULL
);
1359 editor_indent(doc
->editor
, TRUE
);
1363 void on_menu_decrease_indent1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1365 GeanyDocument
*doc
= document_get_current();
1366 g_return_if_fail(doc
!= NULL
);
1368 editor_indent(doc
->editor
, FALSE
);
1372 void on_next_message1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1374 if (! ui_tree_view_find_next(GTK_TREE_VIEW(msgwindow
.tree_msg
),
1375 msgwin_goto_messages_file_line
))
1376 ui_set_statusbar(FALSE
, _("No more message items."));
1380 void on_previous_message1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1382 if (! ui_tree_view_find_previous(GTK_TREE_VIEW(msgwindow
.tree_msg
),
1383 msgwin_goto_messages_file_line
))
1384 ui_set_statusbar(FALSE
, _("No more message items."));
1388 void on_project_new1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1394 void on_project_new_from_folder1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1400 void on_project_open1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1406 void on_project_close1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1408 project_close(TRUE
);
1412 void on_project_properties1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1414 project_properties();
1418 static void on_menu_project1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1420 static GtkWidget
*item_close
= NULL
;
1421 static GtkWidget
*item_properties
= NULL
;
1423 if (item_close
== NULL
)
1425 item_close
= ui_lookup_widget(main_widgets
.window
, "project_close1");
1426 item_properties
= ui_lookup_widget(main_widgets
.window
, "project_properties1");
1429 gtk_widget_set_sensitive(item_close
, (app
->project
!= NULL
));
1430 gtk_widget_set_sensitive(item_properties
, (app
->project
!= NULL
));
1431 gtk_widget_set_sensitive(ui_widgets
.recent_projects_menuitem
,
1432 g_queue_get_length(ui_prefs
.recent_projects_queue
) > 0);
1436 void on_menu_open_selected_file1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1438 GeanyDocument
*doc
= document_get_current();
1443 wc
= GEANY_WORDCHARS
"./-" "\\";
1445 wc
= GEANY_WORDCHARS
"./-";
1448 g_return_if_fail(doc
!= NULL
);
1450 sel
= editor_get_default_selection(doc
->editor
, TRUE
, wc
);
1451 SETPTR(sel
, utils_get_locale_from_utf8(sel
));
1455 gchar
*filename
= NULL
;
1457 if (g_path_is_absolute(sel
))
1458 filename
= g_strdup(sel
);
1460 { /* relative filename, add the path of the current file */
1463 path
= utils_get_current_file_dir_utf8();
1464 SETPTR(path
, utils_get_locale_from_utf8(path
));
1466 path
= g_get_current_dir();
1468 filename
= g_build_path(G_DIR_SEPARATOR_S
, path
, sel
, NULL
);
1470 if (! g_file_test(filename
, G_FILE_TEST_EXISTS
) &&
1471 app
->project
!= NULL
&& !EMPTY(app
->project
->base_path
))
1473 /* try the project's base path */
1474 SETPTR(path
, project_get_base_path());
1475 SETPTR(path
, utils_get_locale_from_utf8(path
));
1476 SETPTR(filename
, g_build_path(G_DIR_SEPARATOR_S
, path
, sel
, NULL
));
1480 if (! g_file_test(filename
, G_FILE_TEST_EXISTS
))
1481 SETPTR(filename
, g_build_path(G_DIR_SEPARATOR_S
, "/usr/local/include", sel
, NULL
));
1483 if (! g_file_test(filename
, G_FILE_TEST_EXISTS
))
1484 SETPTR(filename
, g_build_path(G_DIR_SEPARATOR_S
, "/usr/include", sel
, NULL
));
1488 if (g_file_test(filename
, G_FILE_TEST_EXISTS
))
1489 document_open_file(filename
, FALSE
, NULL
, NULL
);
1492 SETPTR(sel
, utils_get_utf8_from_locale(sel
));
1493 ui_set_statusbar(TRUE
, _("Could not open file %s (File not found)"), sel
);
1502 void on_remove_markers1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1504 GeanyDocument
*doc
= document_get_current();
1505 g_return_if_fail(doc
!= NULL
);
1507 sci_marker_delete_all(doc
->editor
->sci
, 0); /* delete the yellow tag marker */
1508 sci_marker_delete_all(doc
->editor
->sci
, 1); /* delete user markers */
1509 editor_indicator_clear(doc
->editor
, GEANY_INDICATOR_SEARCH
);
1513 static void on_load_tags1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1515 symbols_show_load_tags_dialog();
1519 void on_context_action1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1521 gchar
*word
, *command
;
1522 GError
*error
= NULL
;
1523 GeanyDocument
*doc
= document_get_current();
1524 const gchar
*check_msg
;
1526 g_return_if_fail(doc
!= NULL
);
1528 if (sci_has_selection(doc
->editor
->sci
))
1529 { /* take selected text if there is a selection */
1530 word
= sci_get_selection_contents(doc
->editor
->sci
);
1534 word
= g_strdup(editor_info
.current_word
);
1537 /* use the filetype specific command if available, fallback to global command otherwise */
1538 if (doc
->file_type
!= NULL
&&
1539 !EMPTY(doc
->file_type
->context_action_cmd
))
1541 command
= g_strdup(doc
->file_type
->context_action_cmd
);
1542 check_msg
= _("Check the path setting in Filetype configuration.");
1546 command
= g_strdup(tool_prefs
.context_action_cmd
);
1547 check_msg
= _("Check the path setting in Preferences.");
1550 /* substitute the wildcard %s and run the command if it is non empty */
1551 if (G_LIKELY(!EMPTY(command
)))
1553 gchar
*command_line
= g_strdup(command
);
1555 utils_str_replace_all(&command_line
, "%s", word
);
1557 if (!spawn_async(NULL
, command_line
, NULL
, NULL
, NULL
, &error
))
1559 /* G_SHELL_ERROR is parsing error, it may be caused by %s word with quotes */
1560 ui_set_statusbar(TRUE
, _("Cannot execute context action command \"%s\": %s. %s"),
1561 error
->domain
== G_SHELL_ERROR
? command_line
: command
, error
->message
,
1563 g_error_free(error
);
1565 g_free(command_line
);
1569 ui_set_statusbar(TRUE
, _("No context action set."));
1576 void on_menu_toggle_all_additional_widgets1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1578 static gint hide_all
= -1;
1579 GtkCheckMenuItem
*msgw
= GTK_CHECK_MENU_ITEM(
1580 ui_lookup_widget(main_widgets
.window
, "menu_show_messages_window1"));
1581 GtkCheckMenuItem
*toolbari
= GTK_CHECK_MENU_ITEM(
1582 ui_lookup_widget(main_widgets
.window
, "menu_show_toolbar1"));
1584 /* get the initial state (necessary if Geany was closed with hide_all = TRUE) */
1585 if (G_UNLIKELY(hide_all
== -1))
1587 if (! gtk_check_menu_item_get_active(msgw
) &&
1588 ! interface_prefs
.show_notebook_tabs
&&
1589 ! gtk_check_menu_item_get_active(toolbari
))
1597 hide_all
= ! hide_all
; /* toggle */
1601 if (gtk_check_menu_item_get_active(msgw
))
1602 gtk_check_menu_item_set_active(msgw
, ! gtk_check_menu_item_get_active(msgw
));
1604 interface_prefs
.show_notebook_tabs
= FALSE
;
1605 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets
.notebook
), interface_prefs
.show_notebook_tabs
);
1607 ui_statusbar_showhide(FALSE
);
1609 if (gtk_check_menu_item_get_active(toolbari
))
1610 gtk_check_menu_item_set_active(toolbari
, ! gtk_check_menu_item_get_active(toolbari
));
1615 if (! gtk_check_menu_item_get_active(msgw
))
1616 gtk_check_menu_item_set_active(msgw
, ! gtk_check_menu_item_get_active(msgw
));
1618 interface_prefs
.show_notebook_tabs
= TRUE
;
1619 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets
.notebook
), interface_prefs
.show_notebook_tabs
);
1621 ui_statusbar_showhide(TRUE
);
1623 if (! gtk_check_menu_item_get_active(toolbari
))
1624 gtk_check_menu_item_set_active(toolbari
, ! gtk_check_menu_item_get_active(toolbari
));
1629 void on_toolbutton_forward_activate(GtkAction
*menuitem
, gpointer user_data
)
1631 navqueue_go_forward();
1635 void on_toolbutton_back_activate(GtkAction
*menuitem
, gpointer user_data
)
1641 gboolean
on_motion_event(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
)
1643 if (prefs
.auto_focus
&& ! gtk_widget_has_focus(widget
))
1644 gtk_widget_grab_focus(widget
);
1650 static void set_indent_type(GtkCheckMenuItem
*menuitem
, GeanyIndentType type
)
1654 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
1657 doc
= document_get_current();
1658 g_return_if_fail(doc
!= NULL
);
1660 editor_set_indent(doc
->editor
, type
, doc
->editor
->indent_width
);
1661 ui_update_statusbar(doc
, -1);
1665 static void on_tabs1_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
1667 set_indent_type(menuitem
, GEANY_INDENT_TYPE_TABS
);
1671 static void on_spaces1_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
1673 set_indent_type(menuitem
, GEANY_INDENT_TYPE_SPACES
);
1677 static void on_tabs_and_spaces1_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
1679 set_indent_type(menuitem
, GEANY_INDENT_TYPE_BOTH
);
1683 static void on_strip_trailing_spaces1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1687 if (ignore_callback
)
1690 doc
= document_get_current();
1691 g_return_if_fail(doc
!= NULL
);
1693 editor_strip_trailing_spaces(doc
->editor
, FALSE
);
1697 static void on_page_setup1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1699 printing_page_setup_gtk();
1703 gboolean
on_escape_key_press_event(GtkWidget
*widget
, GdkEventKey
*event
, gpointer user_data
)
1705 guint state
= keybindings_get_modifiers(event
->state
);
1707 /* make pressing escape in the sidebar and toolbar focus the editor */
1708 if (event
->keyval
== GDK_KEY_Escape
&& state
== 0)
1710 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
1717 void on_line_breaking1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1721 if (ignore_callback
)
1724 doc
= document_get_current();
1725 g_return_if_fail(doc
!= NULL
);
1727 doc
->editor
->line_breaking
= !doc
->editor
->line_breaking
;
1731 void on_replace_spaces_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1733 GeanyDocument
*doc
= document_get_current();
1735 g_return_if_fail(doc
!= NULL
);
1737 editor_replace_spaces(doc
->editor
, FALSE
);
1741 static void on_search1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1743 GtkWidget
*next_message
= ui_lookup_widget(main_widgets
.window
, "next_message1");
1744 GtkWidget
*previous_message
= ui_lookup_widget(main_widgets
.window
, "previous_message1");
1745 gboolean have_messages
;
1747 /* enable commands if the messages window has any items */
1748 have_messages
= gtk_tree_model_iter_n_children(GTK_TREE_MODEL(msgwindow
.store_msg
),
1751 gtk_widget_set_sensitive(next_message
, have_messages
);
1752 gtk_widget_set_sensitive(previous_message
, have_messages
);
1756 /* simple implementation (vs. close all which doesn't close documents if cancelled),
1757 * if user_data is set, it is the GeanyDocument to keep */
1758 void on_close_other_documents1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1761 GeanyDocument
*cur_doc
= user_data
;
1763 if (cur_doc
== NULL
)
1764 cur_doc
= document_get_current();
1766 for (i
= 0; i
< documents_array
->len
; i
++)
1768 GeanyDocument
*doc
= documents
[i
];
1770 if (doc
== cur_doc
|| ! doc
->is_valid
)
1773 if (! document_close(doc
))
1779 static void on_menu_reload_configuration1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1781 main_reload_configuration();
1785 static void on_debug_messages1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1787 log_show_debug_messages_dialog();
1791 void on_send_selection_to_vte1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1794 if (vte_info
.have_vte
)
1795 vte_send_selection_to_vte();
1800 static gboolean
on_window_state_event(GtkWidget
*widget
, GdkEventWindowState
*event
, gpointer user_data
)
1803 if (event
->changed_mask
& GDK_WINDOW_STATE_FULLSCREEN
)
1805 static GtkWidget
*menuitem
= NULL
;
1807 if (menuitem
== NULL
)
1808 menuitem
= ui_lookup_widget(widget
, "menu_fullscreen1");
1810 ignore_callback
= TRUE
;
1812 ui_prefs
.fullscreen
= (event
->new_window_state
& GDK_WINDOW_STATE_FULLSCREEN
) ? TRUE
: FALSE
;
1813 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem
), ui_prefs
.fullscreen
);
1815 ignore_callback
= FALSE
;
1821 static void show_notebook_page(const gchar
*notebook_name
, const gchar
*page_name
)
1824 GtkNotebook
*notebook
;
1826 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, page_name
);
1827 notebook
= GTK_NOTEBOOK(ui_lookup_widget(ui_widgets
.prefs_dialog
, notebook_name
));
1829 if (notebook
!= NULL
&& widget
!= NULL
)
1830 gtk_notebook_set_current_page(notebook
, gtk_notebook_page_num(notebook
, widget
));
1834 static void on_customize_toolbar1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1836 prefs_show_dialog();
1838 /* select the Interface page */
1839 show_notebook_page("notebook2", "notebook6");
1840 /* select the Toolbar subpage */
1841 show_notebook_page("notebook6", "vbox15");
1845 static void on_button_customize_toolbar_clicked(GtkButton
*button
, gpointer user_data
)
1847 toolbar_configure(GTK_WINDOW(ui_widgets
.prefs_dialog
));
1851 static void on_cut_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1853 keybindings_send_command(GEANY_KEY_GROUP_CLIPBOARD
, GEANY_KEYS_CLIPBOARD_CUTLINE
);
1857 static void on_copy_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1859 keybindings_send_command(GEANY_KEY_GROUP_CLIPBOARD
, GEANY_KEYS_CLIPBOARD_COPYLINE
);
1863 static void on_delete_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1865 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_DELETELINE
);
1869 static void on_duplicate_line_or_selection1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1871 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_DUPLICATELINE
);
1875 static void on_select_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1877 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_LINE
);
1881 static void on_select_current_paragraph1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1883 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_PARAGRAPH
);
1887 static void on_insert_alternative_white_space1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1889 keybindings_send_command(GEANY_KEY_GROUP_INSERT
, GEANY_KEYS_INSERT_ALTWHITESPACE
);
1893 static void on_go_to_next_marker1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1895 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_NEXTMARKER
);
1899 static void on_go_to_previous_marker1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1901 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_PREVIOUSMARKER
);
1905 static void on_join_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1907 keybindings_send_command(GEANY_KEY_GROUP_FORMAT
, GEANY_KEYS_FORMAT_JOINLINES
);
1911 static void on_reflow_lines_block1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1913 keybindings_send_command(GEANY_KEY_GROUP_FORMAT
, GEANY_KEYS_FORMAT_REFLOWPARAGRAPH
);
1917 static void on_move_lines_up1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1919 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_MOVELINEUP
);
1923 static void on_move_lines_down1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1925 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_MOVELINEDOWN
);
1929 static void on_smart_line_indent1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1931 keybindings_send_command(GEANY_KEY_GROUP_FORMAT
, GEANY_KEYS_FORMAT_AUTOINDENT
);
1935 void on_plugin_preferences1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1938 plugin_show_configure(NULL
);
1943 static void on_indent_width_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1949 if (ignore_callback
)
1952 label
= ui_menu_item_get_text(menuitem
);
1953 width
= atoi(label
);
1956 doc
= document_get_current();
1957 if (doc
!= NULL
&& width
> 0)
1958 editor_set_indent_width(doc
->editor
, width
);
1962 static void on_reset_indentation1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1967 document_apply_indent_settings(documents
[i
]);
1969 ui_update_statusbar(NULL
, -1);
1970 ui_document_show_hide(NULL
);
1974 static void on_mark_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1976 keybindings_send_command(GEANY_KEY_GROUP_SEARCH
, GEANY_KEYS_SEARCH_MARKALL
);
1980 static void on_detect_type_from_file_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1982 GeanyDocument
*doc
= document_get_current();
1983 GeanyIndentType type
;
1985 if (doc
!= NULL
&& document_detect_indent_type(doc
, &type
))
1987 editor_set_indent_type(doc
->editor
, type
);
1988 ui_document_show_hide(doc
);
1989 ui_update_statusbar(doc
, -1);
1994 static void on_show_symbol_list_toggled(GtkToggleButton
*button
, gpointer user_data
)
1996 GtkWidget
*widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "box_show_symbol_list_children");
1998 gtk_widget_set_sensitive(widget
, gtk_toggle_button_get_active(button
));
2002 static void on_detect_width_from_file_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2004 GeanyDocument
*doc
= document_get_current();
2007 if (doc
!= NULL
&& document_detect_indent_width(doc
, &width
))
2009 editor_set_indent_width(doc
->editor
, width
);
2010 ui_document_show_hide(doc
);
2015 static void builder_connect_func(GtkBuilder
*builder
, GObject
*object
,
2016 const gchar
*signal_name
, const gchar
*handler_name
, GObject
*connect_obj
,
2017 GConnectFlags flags
, gpointer user_data
)
2019 GHashTable
*hash
= user_data
;
2022 callback
= g_hash_table_lookup(hash
, handler_name
);
2023 g_return_if_fail(callback
);
2025 if (connect_obj
== NULL
)
2026 g_signal_connect_data(object
, signal_name
, callback
, NULL
, NULL
, flags
);
2028 g_signal_connect_object(object
, signal_name
, callback
, connect_obj
, flags
);
2032 void callbacks_connect(GtkBuilder
*builder
)
2036 g_return_if_fail(GTK_IS_BUILDER(builder
));
2038 hash
= g_hash_table_new(g_str_hash
, g_str_equal
);
2040 #define ITEM(n) g_hash_table_insert(hash, (gpointer) #n, G_CALLBACK(n));
2041 # include "signallist.i"
2044 gtk_builder_connect_signals_full(builder
, builder_connect_func
, hash
);
2045 g_hash_table_destroy(hash
);