2 * callbacks.c - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2005-2012 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5 * Copyright 2006-2012 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 * Callbacks used by Glade. These are mainly in response to menu item and button events in the
24 * main window. Callbacks not used by Glade should go elsewhere.
31 #include "callbacks.h"
37 #include "documentprivate.h"
38 #include "encodings.h"
39 #include "filetypes.h"
40 #include "geanyobject.h"
41 #include "highlighting.h"
42 #include "keybindings.h"
46 #include "msgwindow.h"
49 #include "pluginutils.h"
52 #include "sciwrappers.h"
59 #include "templates.h"
66 #include "gtkcompat.h"
71 #include <gdk/gdkkeysyms.h>
72 #include <glib/gstdio.h>
76 /* flag to indicate that an insert callback was triggered from the file menu,
77 * so we need to store the current cursor position in editor_info.click_pos. */
78 static gboolean insert_callback_from_menu
= FALSE
;
80 /* represents the state at switching a notebook page(in the left treeviews widget), to not emit
81 * the selection-changed signal from tv.tree_openfiles */
82 /*static gboolean switch_tv_notebook_page = FALSE; */
85 static gboolean
check_no_unsaved(void)
89 for (i
= 0; i
< documents_array
->len
; i
++)
91 if (documents
[i
]->is_valid
&& documents
[i
]->changed
)
96 return TRUE
; /* no unsaved edits */
100 /* set editor_info.click_pos to the current cursor position if insert_callback_from_menu is TRUE
101 * to prevent invalid cursor positions which can cause segfaults */
102 static void verify_click_pos(GeanyDocument
*doc
)
104 if (insert_callback_from_menu
)
106 editor_info
.click_pos
= sci_get_current_position(doc
->editor
->sci
);
107 insert_callback_from_menu
= FALSE
;
112 /* should only be called from on_exit_clicked */
113 static void quit_app(void)
115 configuration_save();
117 if (app
->project
!= NULL
)
118 project_close(FALSE
); /* save project session files */
120 document_close_all();
122 main_status
.quitting
= TRUE
;
128 /* wrapper function to abort exit process if cancel button is pressed */
129 G_MODULE_EXPORT gboolean
on_exit_clicked(GtkWidget
*widget
, gpointer gdata
)
131 main_status
.quitting
= TRUE
;
133 if (! check_no_unsaved())
135 if (document_account_for_unsaved())
142 if (! prefs
.confirm_exit
||
143 dialogs_show_question_full(NULL
, GTK_STOCK_QUIT
, GTK_STOCK_CANCEL
, NULL
,
144 _("Do you really want to quit?")))
150 main_status
.quitting
= FALSE
;
159 G_MODULE_EXPORT
void on_new1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
161 document_new_file(NULL
, NULL
, NULL
);
165 G_MODULE_EXPORT
void on_save1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
167 GeanyDocument
*doc
= document_get_current();
171 document_save_file(doc
, ui_prefs
.allow_always_save
);
176 G_MODULE_EXPORT
void on_save_as1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
178 dialogs_show_save_as();
182 G_MODULE_EXPORT
void on_save_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
184 guint i
, max
= (guint
) gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets
.notebook
));
185 GeanyDocument
*doc
, *cur_doc
= document_get_current();
188 /* iterate over documents in tabs order */
189 for (i
= 0; i
< max
; i
++)
191 doc
= document_get_from_page(i
);
195 if (document_save_file(doc
, FALSE
))
201 ui_set_statusbar(FALSE
, ngettext("%d file saved.", "%d files saved.", count
), count
);
202 /* saving may have changed window title, sidebar for another doc, so update */
203 document_show_tab(cur_doc
);
204 sidebar_update_tag_list(cur_doc
, TRUE
);
205 ui_set_window_title(cur_doc
);
209 G_MODULE_EXPORT
void on_close_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
211 document_close_all();
215 G_MODULE_EXPORT
void on_close1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
217 GeanyDocument
*doc
= document_get_current();
224 G_MODULE_EXPORT
void on_quit1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
226 on_exit_clicked(NULL
, NULL
);
230 G_MODULE_EXPORT
void on_file1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
232 gtk_widget_set_sensitive(ui_widgets
.recent_files_menuitem
,
233 g_queue_get_length(ui_prefs
.recent_queue
) > 0);
234 /* hide Page setup when GTK printing is not used */
235 ui_widget_show_hide(ui_widgets
.print_page_setup
, printing_prefs
.use_gtk_printing
);
239 /* edit actions, c&p & co, from menu bar and from popup menu */
240 G_MODULE_EXPORT
void on_edit1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
243 GeanyDocument
*doc
= document_get_current();
245 ui_update_menu_copy_items(doc
);
246 ui_update_insert_include_item(doc
, 1);
248 item
= ui_lookup_widget(main_widgets
.window
, "plugin_preferences1");
250 gtk_widget_hide(item
);
252 gtk_widget_set_sensitive(item
, plugins_have_preferences());
257 G_MODULE_EXPORT
void on_undo1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
259 GeanyDocument
*doc
= document_get_current();
261 g_return_if_fail(doc
!= NULL
);
263 if (document_can_undo(doc
))
265 sci_cancel(doc
->editor
->sci
);
271 G_MODULE_EXPORT
void on_redo1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
273 GeanyDocument
*doc
= document_get_current();
275 g_return_if_fail(doc
!= NULL
);
277 if (document_can_redo(doc
))
279 sci_cancel(doc
->editor
->sci
);
285 G_MODULE_EXPORT
void on_cut1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
287 GeanyDocument
*doc
= document_get_current();
288 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
290 if (GTK_IS_EDITABLE(focusw
))
291 gtk_editable_cut_clipboard(GTK_EDITABLE(focusw
));
293 if (IS_SCINTILLA(focusw
) && doc
!= NULL
)
294 sci_cut(doc
->editor
->sci
);
296 if (GTK_IS_TEXT_VIEW(focusw
))
298 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(
299 GTK_TEXT_VIEW(focusw
));
300 gtk_text_buffer_cut_clipboard(buffer
, gtk_clipboard_get(GDK_NONE
), TRUE
);
305 G_MODULE_EXPORT
void on_copy1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
307 GeanyDocument
*doc
= document_get_current();
308 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
310 if (GTK_IS_EDITABLE(focusw
))
311 gtk_editable_copy_clipboard(GTK_EDITABLE(focusw
));
313 if (IS_SCINTILLA(focusw
) && doc
!= NULL
)
314 sci_copy(doc
->editor
->sci
);
316 if (GTK_IS_TEXT_VIEW(focusw
))
318 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(
319 GTK_TEXT_VIEW(focusw
));
320 gtk_text_buffer_copy_clipboard(buffer
, gtk_clipboard_get(GDK_NONE
));
325 G_MODULE_EXPORT
void on_paste1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
327 GeanyDocument
*doc
= document_get_current();
328 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
330 if (GTK_IS_EDITABLE(focusw
))
331 gtk_editable_paste_clipboard(GTK_EDITABLE(focusw
));
333 if (IS_SCINTILLA(focusw
) && doc
!= NULL
)
335 sci_paste(doc
->editor
->sci
);
338 if (GTK_IS_TEXT_VIEW(focusw
))
340 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(
341 GTK_TEXT_VIEW(focusw
));
342 gtk_text_buffer_paste_clipboard(buffer
, gtk_clipboard_get(GDK_NONE
), NULL
,
348 G_MODULE_EXPORT
void on_delete1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
350 GeanyDocument
*doc
= document_get_current();
351 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
353 if (GTK_IS_EDITABLE(focusw
))
354 gtk_editable_delete_selection(GTK_EDITABLE(focusw
));
356 if (IS_SCINTILLA(focusw
) && doc
!= NULL
&& sci_has_selection(doc
->editor
->sci
))
357 sci_clear(doc
->editor
->sci
);
359 if (GTK_IS_TEXT_VIEW(focusw
))
361 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(
362 GTK_TEXT_VIEW(focusw
));
363 gtk_text_buffer_delete_selection(buffer
, TRUE
, TRUE
);
368 G_MODULE_EXPORT
void on_preferences1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
374 /* about menu item */
375 G_MODULE_EXPORT
void on_info1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
382 G_MODULE_EXPORT
void on_open1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
384 dialogs_show_open_file();
388 /* quit toolbar button */
389 G_MODULE_EXPORT
void on_toolbutton_quit_clicked(GtkAction
*action
, gpointer user_data
)
391 on_exit_clicked(NULL
, NULL
);
396 G_MODULE_EXPORT
void on_toolbutton_reload_clicked(GtkAction
*action
, gpointer user_data
)
398 GeanyDocument
*doc
= document_get_current();
400 g_return_if_fail(doc
!= NULL
);
402 document_reload_prompt(doc
, NULL
);
406 G_MODULE_EXPORT
void on_change_font1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
408 dialogs_show_open_font();
413 G_MODULE_EXPORT
void on_toolbutton_new_clicked(GtkAction
*action
, gpointer user_data
)
415 document_new_file(NULL
, NULL
, NULL
);
420 G_MODULE_EXPORT
void on_toolbutton_open_clicked(GtkAction
*action
, gpointer user_data
)
422 dialogs_show_open_file();
427 G_MODULE_EXPORT
void on_toolbutton_save_clicked(GtkAction
*action
, gpointer user_data
)
429 on_save1_activate(NULL
, user_data
);
433 /* store text, clear search flags so we can use Search->Find Next/Previous */
434 static void setup_find(const gchar
*text
, gboolean backwards
)
436 SETPTR(search_data
.text
, g_strdup(text
));
437 SETPTR(search_data
.original_text
, g_strdup(text
));
438 search_data
.flags
= 0;
439 search_data
.backwards
= backwards
;
440 search_data
.search_bar
= TRUE
;
444 static void do_toolbar_search(const gchar
*text
, gboolean incremental
, gboolean backwards
)
446 GeanyDocument
*doc
= document_get_current();
449 setup_find(text
, backwards
);
450 result
= document_search_bar_find(doc
, search_data
.text
, 0, incremental
, backwards
);
451 if (search_data
.search_bar
)
452 ui_set_search_entry_background(toolbar_get_widget_child_by_name("SearchEntry"), result
);
457 G_MODULE_EXPORT
void on_toolbar_search_entry_changed(GtkAction
*action
, const gchar
*text
, gpointer user_data
)
459 do_toolbar_search(text
, TRUE
, FALSE
);
464 G_MODULE_EXPORT
void on_toolbar_search_entry_activate(GtkAction
*action
, const gchar
*text
, gpointer user_data
)
466 do_toolbar_search(text
, FALSE
, GPOINTER_TO_INT(user_data
));
471 G_MODULE_EXPORT
void on_toolbutton_search_clicked(GtkAction
*action
, gpointer user_data
)
473 GeanyDocument
*doc
= document_get_current();
475 GtkWidget
*entry
= toolbar_get_widget_child_by_name("SearchEntry");
479 const gchar
*text
= gtk_entry_get_text(GTK_ENTRY(entry
));
481 setup_find(text
, FALSE
);
482 result
= document_search_bar_find(doc
, search_data
.text
, 0, FALSE
, FALSE
);
483 if (search_data
.search_bar
)
484 ui_set_search_entry_background(entry
, result
);
487 on_find1_activate(NULL
, NULL
);
491 /* hides toolbar from toolbar popup menu */
492 G_MODULE_EXPORT
void on_hide_toolbar1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
494 GtkWidget
*tool_item
= ui_lookup_widget(GTK_WIDGET(main_widgets
.window
), "menu_show_toolbar1");
495 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(tool_item
), FALSE
);
499 /* zoom in from menu bar and popup menu */
500 G_MODULE_EXPORT
void on_zoom_in1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
502 GeanyDocument
*doc
= document_get_current();
504 g_return_if_fail(doc
!= NULL
);
506 sci_zoom_in(doc
->editor
->sci
);
510 /* zoom out from menu bar and popup menu */
511 G_MODULE_EXPORT
void on_zoom_out1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
513 GeanyDocument
*doc
= document_get_current();
515 g_return_if_fail(doc
!= NULL
);
517 sci_zoom_out(doc
->editor
->sci
);
521 G_MODULE_EXPORT
void on_normal_size1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
523 GeanyDocument
*doc
= document_get_current();
525 g_return_if_fail(doc
!= NULL
);
527 sci_zoom_off(doc
->editor
->sci
);
532 G_MODULE_EXPORT
void on_toolbutton_close_clicked(GtkAction
*action
, gpointer user_data
)
534 on_close1_activate(NULL
, NULL
);
538 G_MODULE_EXPORT
void on_toolbutton_close_all_clicked(GtkAction
*action
, gpointer user_data
)
540 on_close_all1_activate(NULL
, NULL
);
544 G_MODULE_EXPORT
void on_toolbutton_preferences_clicked(GtkAction
*action
, gpointer user_data
)
546 on_preferences1_activate(NULL
, NULL
);
550 static gboolean
delayed_check_disk_status(gpointer data
)
552 document_check_disk_status(data
, FALSE
);
557 /* Changes window-title after switching tabs and lots of other things.
558 * note: using 'after' makes Scintilla redraw before the UI, appearing more responsive */
559 G_MODULE_EXPORT
void on_notebook1_switch_page_after(GtkNotebook
*notebook
, gpointer page
,
560 guint page_num
, gpointer user_data
)
564 if (G_UNLIKELY(main_status
.opening_session_files
|| main_status
.closing_all
))
567 if (page_num
== (guint
) -1 && page
!= NULL
)
568 doc
= document_find_by_sci(SCINTILLA(page
));
570 doc
= document_get_from_page(page_num
);
574 sidebar_select_openfiles_item(doc
);
575 ui_save_buttons_toggle(doc
->changed
);
576 ui_set_window_title(doc
);
577 ui_update_statusbar(doc
, -1);
578 ui_update_popup_reundo_items(doc
);
579 ui_document_show_hide(doc
); /* update the document menu */
580 build_menu_update(doc
);
581 sidebar_update_tag_list(doc
, FALSE
);
582 document_highlight_tags(doc
);
584 /* We delay the check to avoid weird fast, unintended switching of notebook pages when
585 * the 'file has changed' dialog is shown while the switch event is not yet completely
586 * finished. So, we check after the switch has been performed to be safe. */
587 g_idle_add(delayed_check_disk_status
, doc
);
590 vte_cwd((doc
->real_path
!= NULL
) ? doc
->real_path
: doc
->file_name
, FALSE
);
593 g_signal_emit_by_name(geany_object
, "document-activate", doc
);
598 G_MODULE_EXPORT
void on_tv_notebook_switch_page(GtkNotebook
*notebook
, gpointer page
,
599 guint page_num
, gpointer user_data
)
601 /* suppress selection changed signal when switching to the open files list */
602 ignore_callback
= TRUE
;
606 G_MODULE_EXPORT
void on_tv_notebook_switch_page_after(GtkNotebook
*notebook
, gpointer page
,
607 guint page_num
, gpointer user_data
)
609 ignore_callback
= FALSE
;
613 static void convert_eol(gint mode
)
615 GeanyDocument
*doc
= document_get_current();
617 g_return_if_fail(doc
!= NULL
);
619 sci_convert_eols(doc
->editor
->sci
, mode
);
620 sci_set_eol_mode(doc
->editor
->sci
, mode
);
621 ui_update_statusbar(doc
, -1);
625 G_MODULE_EXPORT
void on_crlf_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
627 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
630 convert_eol(SC_EOL_CRLF
);
634 G_MODULE_EXPORT
void on_lf_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
636 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
639 convert_eol(SC_EOL_LF
);
643 G_MODULE_EXPORT
void on_cr_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
645 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
648 convert_eol(SC_EOL_CR
);
652 G_MODULE_EXPORT
void on_replace_tabs_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
654 GeanyDocument
*doc
= document_get_current();
656 g_return_if_fail(doc
!= NULL
);
658 editor_replace_tabs(doc
->editor
);
662 gboolean
toolbar_popup_menu(GtkWidget
*widget
, GdkEventButton
*event
, gpointer user_data
)
664 if (event
->button
== 3)
666 gtk_menu_popup(GTK_MENU(ui_widgets
.toolbar_menu
), NULL
, NULL
, NULL
, NULL
, event
->button
, event
->time
);
673 G_MODULE_EXPORT
void on_toggle_case1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
675 GeanyDocument
*doc
= document_get_current();
676 ScintillaObject
*sci
;
678 gboolean keep_sel
= TRUE
;
680 g_return_if_fail(doc
!= NULL
);
682 sci
= doc
->editor
->sci
;
683 if (! sci_has_selection(sci
))
685 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_WORD
);
689 /* either we already had a selection or we created one for current word */
690 if (sci_has_selection(sci
))
692 gchar
*result
= NULL
;
693 gint cmd
= SCI_LOWERCASE
;
694 gboolean rectsel
= (gboolean
) scintilla_send_message(sci
, SCI_SELECTIONISRECTANGLE
, 0, 0);
696 text
= sci_get_selection_contents(sci
);
698 if (utils_str_has_upper(text
))
703 result
= g_utf8_strdown(text
, -1);
710 result
= g_utf8_strup(text
, -1);
715 sci_replace_sel(sci
, result
);
718 sci_set_selection_start(sci
, sci_get_current_position(sci
) - strlen(text
));
721 sci_send_command(sci
, cmd
);
729 G_MODULE_EXPORT
void on_show_toolbar1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
731 if (ignore_callback
) return;
733 toolbar_prefs
.visible
= (toolbar_prefs
.visible
) ? FALSE
: TRUE
;;
734 ui_widget_show_hide(GTK_WIDGET(main_widgets
.toolbar
), toolbar_prefs
.visible
);
738 G_MODULE_EXPORT
void on_fullscreen1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
743 ui_prefs
.fullscreen
= (ui_prefs
.fullscreen
) ? FALSE
: TRUE
;
748 G_MODULE_EXPORT
void on_show_messages_window1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
753 ui_prefs
.msgwindow_visible
= (ui_prefs
.msgwindow_visible
) ? FALSE
: TRUE
;
754 msgwin_show_hide(ui_prefs
.msgwindow_visible
);
758 G_MODULE_EXPORT
void on_menu_color_schemes_activate(GtkImageMenuItem
*imagemenuitem
, gpointer user_data
)
760 highlighting_show_color_scheme_dialog();
764 G_MODULE_EXPORT
void on_markers_margin1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
769 editor_prefs
.show_markers_margin
= ! editor_prefs
.show_markers_margin
;
770 ui_toggle_editor_features(GEANY_EDITOR_SHOW_MARKERS_MARGIN
);
774 G_MODULE_EXPORT
void on_show_line_numbers1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
779 editor_prefs
.show_linenumber_margin
= ! editor_prefs
.show_linenumber_margin
;
780 ui_toggle_editor_features(GEANY_EDITOR_SHOW_LINE_NUMBERS
);
784 G_MODULE_EXPORT
void on_menu_show_white_space1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
789 editor_prefs
.show_white_space
= ! editor_prefs
.show_white_space
;
790 ui_toggle_editor_features(GEANY_EDITOR_SHOW_WHITE_SPACE
);
794 G_MODULE_EXPORT
void on_menu_show_line_endings1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
799 editor_prefs
.show_line_endings
= ! editor_prefs
.show_line_endings
;
800 ui_toggle_editor_features(GEANY_EDITOR_SHOW_LINE_ENDINGS
);
804 G_MODULE_EXPORT
void on_menu_show_indentation_guides1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
809 editor_prefs
.show_indent_guide
= ! editor_prefs
.show_indent_guide
;
810 ui_toggle_editor_features(GEANY_EDITOR_SHOW_INDENTATION_GUIDES
);
814 G_MODULE_EXPORT
void on_line_wrapping1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
816 if (! ignore_callback
)
818 GeanyDocument
*doc
= document_get_current();
819 g_return_if_fail(doc
!= NULL
);
821 editor_set_line_wrapping(doc
->editor
, ! doc
->editor
->line_wrapping
);
826 G_MODULE_EXPORT
void on_set_file_readonly1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
828 if (! ignore_callback
)
830 GeanyDocument
*doc
= document_get_current();
831 g_return_if_fail(doc
!= NULL
);
833 doc
->readonly
= ! doc
->readonly
;
834 sci_set_readonly(doc
->editor
->sci
, doc
->readonly
);
835 ui_update_tab_status(doc
);
836 ui_update_statusbar(doc
, -1);
841 G_MODULE_EXPORT
void on_use_auto_indentation1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
843 if (! ignore_callback
)
845 GeanyDocument
*doc
= document_get_current();
846 g_return_if_fail(doc
!= NULL
);
848 doc
->editor
->auto_indent
= ! doc
->editor
->auto_indent
;
853 static void find_usage(gboolean in_session
)
857 GeanyDocument
*doc
= document_get_current();
859 g_return_if_fail(doc
!= NULL
);
861 if (sci_has_selection(doc
->editor
->sci
))
862 { /* take selected text if there is a selection */
863 search_text
= sci_get_selection_contents(doc
->editor
->sci
);
864 flags
= SCFIND_MATCHCASE
;
868 editor_find_current_word_sciwc(doc
->editor
, -1,
869 editor_info
.current_word
, GEANY_MAX_WORD_LENGTH
);
870 search_text
= g_strdup(editor_info
.current_word
);
871 flags
= SCFIND_MATCHCASE
| SCFIND_WHOLEWORD
;
874 search_find_usage(search_text
, search_text
, flags
, in_session
);
879 G_MODULE_EXPORT
void on_find_document_usage1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
885 G_MODULE_EXPORT
void on_find_usage1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
891 static void goto_tag(gboolean definition
)
893 GeanyDocument
*doc
= document_get_current();
895 g_return_if_fail(doc
!= NULL
);
897 /* update cursor pos for navigating back afterwards */
898 if (!sci_has_selection(doc
->editor
->sci
))
899 sci_set_current_position(doc
->editor
->sci
, editor_info
.click_pos
, FALSE
);
901 /* use the keybinding callback as it checks for selections as well as current word */
903 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_TAGDEFINITION
);
905 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_TAGDECLARATION
);
909 G_MODULE_EXPORT
void on_goto_tag_definition1(GtkMenuItem
*menuitem
, gpointer user_data
)
915 G_MODULE_EXPORT
void on_goto_tag_declaration1(GtkMenuItem
*menuitem
, gpointer user_data
)
921 G_MODULE_EXPORT
void on_count_words1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
927 G_MODULE_EXPORT
void on_show_color_chooser1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
930 GeanyDocument
*doc
= document_get_current();
933 g_return_if_fail(doc
!= NULL
);
935 pos
= sci_get_current_position(doc
->editor
->sci
);
936 editor_find_current_word(doc
->editor
, pos
, colour
, sizeof colour
, GEANY_WORDCHARS
"#");
937 tools_color_chooser(colour
);
941 G_MODULE_EXPORT
void on_toolbutton_compile_clicked(GtkAction
*action
, gpointer user_data
)
943 keybindings_send_command(GEANY_KEY_GROUP_BUILD
, GEANY_KEYS_BUILD_COMPILE
);
947 G_MODULE_EXPORT
void on_find1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
949 search_show_find_dialog();
953 G_MODULE_EXPORT
void on_find_next1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
955 search_find_again(FALSE
);
959 G_MODULE_EXPORT
void on_find_previous1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
961 if (search_data
.flags
& SCFIND_REGEXP
)
962 /* Can't reverse search order for a regex (find next ignores search backwards) */
965 search_find_again(TRUE
);
969 G_MODULE_EXPORT
void on_find_nextsel1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
971 search_find_selection(document_get_current(), FALSE
);
975 G_MODULE_EXPORT
void on_find_prevsel1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
977 search_find_selection(document_get_current(), TRUE
);
981 G_MODULE_EXPORT
void on_replace1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
983 search_show_replace_dialog();
987 G_MODULE_EXPORT
void on_find_in_files1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
989 search_show_find_in_files_dialog(NULL
);
993 static void get_line_and_offset_from_text(const gchar
*text
, gint
*line_no
, gint
*offset
)
995 if (*text
== '+' || *text
== '-')
997 *line_no
= atoi(text
+ 1);
998 *offset
= (*text
== '+') ? 1 : -1;
1002 *line_no
= atoi(text
) - 1;
1008 G_MODULE_EXPORT
void on_go_to_line_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1010 static gchar value
[16] = "";
1013 result
= dialogs_show_input_goto_line(
1014 _("Go to Line"), GTK_WINDOW(main_widgets
.window
),
1015 _("Enter the line you want to go to:"), value
);
1018 GeanyDocument
*doc
= document_get_current();
1022 g_return_if_fail(doc
!= NULL
);
1024 get_line_and_offset_from_text(result
, &line_no
, &offset
);
1025 if (! editor_goto_line(doc
->editor
, line_no
, offset
))
1027 /* remember value for future calls */
1028 g_snprintf(value
, sizeof(value
), "%s", result
);
1035 G_MODULE_EXPORT
void on_toolbutton_goto_entry_activate(GtkAction
*action
, const gchar
*text
, gpointer user_data
)
1037 GeanyDocument
*doc
= document_get_current();
1041 g_return_if_fail(doc
!= NULL
);
1043 get_line_and_offset_from_text(text
, &line_no
, &offset
);
1044 if (! editor_goto_line(doc
->editor
, line_no
, offset
))
1047 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
1051 G_MODULE_EXPORT
void on_toolbutton_goto_clicked(GtkAction
*action
, gpointer user_data
)
1053 GtkWidget
*entry
= toolbar_get_widget_child_by_name("GotoEntry");
1057 const gchar
*text
= gtk_entry_get_text(GTK_ENTRY(entry
));
1059 on_toolbutton_goto_entry_activate(NULL
, text
, NULL
);
1062 on_go_to_line_activate(NULL
, NULL
);
1066 G_MODULE_EXPORT
void on_help1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1070 uri
= utils_get_help_url(NULL
);
1071 utils_open_browser(uri
);
1076 G_MODULE_EXPORT
void on_help_shortcuts1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1078 keybindings_show_shortcuts();
1082 G_MODULE_EXPORT
void on_website1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1084 utils_open_browser(GEANY_HOMEPAGE
);
1088 G_MODULE_EXPORT
void on_help_menu_item_donate_activate(GtkMenuItem
*item
, gpointer user_data
)
1090 utils_open_browser(GEANY_DONATE
);
1094 G_MODULE_EXPORT
void on_help_menu_item_wiki_activate(GtkMenuItem
*item
, gpointer user_data
)
1096 utils_open_browser(GEANY_WIKI
);
1100 G_MODULE_EXPORT
void on_help_menu_item_bug_report_activate(GtkMenuItem
*item
, gpointer user_data
)
1102 utils_open_browser(GEANY_BUG_REPORT
);
1106 G_MODULE_EXPORT
void on_comments_function_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1108 GeanyDocument
*doc
= document_get_current();
1110 const gchar
*cur_tag
= NULL
;
1111 gint line
= -1, pos
= 0;
1113 if (doc
== NULL
|| doc
->file_type
== NULL
)
1115 ui_set_statusbar(FALSE
,
1116 _("Please set the filetype for the current file before using this function."));
1120 /* symbols_get_current_function returns -1 on failure, so sci_get_position_from_line
1121 * returns the current position, so it should be safe */
1122 line
= symbols_get_current_function(doc
, &cur_tag
);
1123 pos
= sci_get_position_from_line(doc
->editor
->sci
, line
);
1125 text
= templates_get_template_function(doc
, cur_tag
);
1127 sci_start_undo_action(doc
->editor
->sci
);
1128 sci_insert_text(doc
->editor
->sci
, pos
, text
);
1129 sci_end_undo_action(doc
->editor
->sci
);
1134 G_MODULE_EXPORT
void on_comments_multiline_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1136 GeanyDocument
*doc
= document_get_current();
1138 if (doc
== NULL
|| doc
->file_type
== NULL
)
1140 ui_set_statusbar(FALSE
,
1141 _("Please set the filetype for the current file before using this function."));
1145 verify_click_pos(doc
); /* make sure that the click_pos is valid */
1147 if (doc
->file_type
->comment_open
|| doc
->file_type
->comment_single
)
1148 editor_insert_multiline_comment(doc
->editor
);
1154 G_MODULE_EXPORT
void on_comments_gpl_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1156 GeanyDocument
*doc
= document_get_current();
1159 g_return_if_fail(doc
!= NULL
);
1161 text
= templates_get_template_licence(doc
, GEANY_TEMPLATE_GPL
);
1163 verify_click_pos(doc
); /* make sure that the click_pos is valid */
1165 sci_start_undo_action(doc
->editor
->sci
);
1166 sci_insert_text(doc
->editor
->sci
, editor_info
.click_pos
, text
);
1167 sci_end_undo_action(doc
->editor
->sci
);
1172 G_MODULE_EXPORT
void on_comments_bsd_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1174 GeanyDocument
*doc
= document_get_current();
1177 g_return_if_fail(doc
!= NULL
);
1179 text
= templates_get_template_licence(doc
, GEANY_TEMPLATE_BSD
);
1181 verify_click_pos(doc
); /* make sure that the click_pos is valid */
1183 sci_start_undo_action(doc
->editor
->sci
);
1184 sci_insert_text(doc
->editor
->sci
, editor_info
.click_pos
, text
);
1185 sci_end_undo_action(doc
->editor
->sci
);
1191 G_MODULE_EXPORT
void on_comments_changelog_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1193 GeanyDocument
*doc
= document_get_current();
1196 g_return_if_fail(doc
!= NULL
);
1198 text
= templates_get_template_changelog(doc
);
1199 sci_start_undo_action(doc
->editor
->sci
);
1200 sci_insert_text(doc
->editor
->sci
, 0, text
);
1201 /* sets the cursor to the right position to type the changelog text,
1202 * the template has 21 chars + length of name and email */
1203 sci_goto_pos(doc
->editor
->sci
, 21 + strlen(template_prefs
.developer
) + strlen(template_prefs
.mail
), TRUE
);
1204 sci_end_undo_action(doc
->editor
->sci
);
1210 G_MODULE_EXPORT
void on_comments_fileheader_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1212 GeanyDocument
*doc
= document_get_current();
1217 g_return_if_fail(doc
!= NULL
);
1219 ft
= doc
->file_type
;
1220 fname
= doc
->file_name
;
1221 text
= templates_get_template_fileheader(FILETYPE_ID(ft
), fname
);
1223 sci_start_undo_action(doc
->editor
->sci
);
1224 sci_insert_text(doc
->editor
->sci
, 0, text
);
1225 sci_goto_pos(doc
->editor
->sci
, 0, FALSE
);
1226 sci_end_undo_action(doc
->editor
->sci
);
1231 G_MODULE_EXPORT
void on_insert_date_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1233 GeanyDocument
*doc
= document_get_current();
1234 const gchar
*format
= NULL
;
1237 g_return_if_fail(doc
!= NULL
);
1239 /* set default value */
1240 if (utils_str_equal("", ui_prefs
.custom_date_format
))
1242 g_free(ui_prefs
.custom_date_format
);
1243 ui_prefs
.custom_date_format
= g_strdup("%d.%m.%Y");
1246 if (utils_str_equal(_("dd.mm.yyyy"), (gchar
*) user_data
))
1247 format
= "%d.%m.%Y";
1248 else if (utils_str_equal(_("mm.dd.yyyy"), (gchar
*) user_data
))
1249 format
= "%m.%d.%Y";
1250 else if (utils_str_equal(_("yyyy/mm/dd"), (gchar
*) user_data
))
1251 format
= "%Y/%m/%d";
1252 else if (utils_str_equal(_("dd.mm.yyyy hh:mm:ss"), (gchar
*) user_data
))
1253 format
= "%d.%m.%Y %H:%M:%S";
1254 else if (utils_str_equal(_("mm.dd.yyyy hh:mm:ss"), (gchar
*) user_data
))
1255 format
= "%m.%d.%Y %H:%M:%S";
1256 else if (utils_str_equal(_("yyyy/mm/dd hh:mm:ss"), (gchar
*) user_data
))
1257 format
= "%Y/%m/%d %H:%M:%S";
1258 else if (utils_str_equal(_("_Use Custom Date Format"), (gchar
*) user_data
))
1259 format
= ui_prefs
.custom_date_format
;
1262 gchar
*str
= dialogs_show_input(_("Custom Date Format"), GTK_WINDOW(main_widgets
.window
),
1263 _("Enter here a custom date and time format. "
1264 "You can use any conversion specifiers which can be used with the ANSI C strftime function."),
1265 ui_prefs
.custom_date_format
);
1267 SETPTR(ui_prefs
.custom_date_format
, str
);
1271 time_str
= utils_get_date_time(format
, NULL
);
1272 if (time_str
!= NULL
)
1274 verify_click_pos(doc
); /* make sure that the click_pos is valid */
1276 sci_start_undo_action(doc
->editor
->sci
);
1277 sci_insert_text(doc
->editor
->sci
, editor_info
.click_pos
, time_str
);
1278 sci_goto_pos(doc
->editor
->sci
, editor_info
.click_pos
+ strlen(time_str
), FALSE
);
1279 sci_end_undo_action(doc
->editor
->sci
);
1285 ui_set_statusbar(TRUE
,
1286 _("Date format string could not be converted (possibly too long)."));
1291 G_MODULE_EXPORT
void on_insert_include_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1293 GeanyDocument
*doc
= document_get_current();
1297 g_return_if_fail(doc
!= NULL
);
1298 g_return_if_fail(user_data
!= NULL
);
1300 verify_click_pos(doc
); /* make sure that the click_pos is valid */
1302 if (utils_str_equal(user_data
, "blank"))
1304 text
= g_strdup("#include \"\"\n");
1305 pos
= editor_info
.click_pos
+ 10;
1309 text
= g_strconcat("#include <", user_data
, ">\n", NULL
);
1312 sci_start_undo_action(doc
->editor
->sci
);
1313 sci_insert_text(doc
->editor
->sci
, editor_info
.click_pos
, text
);
1314 sci_end_undo_action(doc
->editor
->sci
);
1317 sci_goto_pos(doc
->editor
->sci
, pos
, FALSE
);
1321 G_MODULE_EXPORT
void on_file_properties_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1323 GeanyDocument
*doc
= document_get_current();
1324 g_return_if_fail(doc
!= NULL
);
1326 dialogs_show_file_properties(doc
);
1330 G_MODULE_EXPORT
void on_menu_fold_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1332 GeanyDocument
*doc
= document_get_current();
1333 g_return_if_fail(doc
!= NULL
);
1335 editor_fold_all(doc
->editor
);
1339 G_MODULE_EXPORT
void on_menu_unfold_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1341 GeanyDocument
*doc
= document_get_current();
1342 g_return_if_fail(doc
!= NULL
);
1344 editor_unfold_all(doc
->editor
);
1348 G_MODULE_EXPORT
void on_toolbutton_run_clicked(GtkAction
*action
, gpointer user_data
)
1350 keybindings_send_command(GEANY_KEY_GROUP_BUILD
, GEANY_KEYS_BUILD_RUN
);
1354 G_MODULE_EXPORT
void on_menu_remove_indicators1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1356 GeanyDocument
*doc
= document_get_current();
1357 g_return_if_fail(doc
!= NULL
);
1359 editor_indicator_clear(doc
->editor
, GEANY_INDICATOR_ERROR
);
1363 G_MODULE_EXPORT
void on_print1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1365 GeanyDocument
*doc
= document_get_current();
1366 g_return_if_fail(doc
!= NULL
);
1368 printing_print_doc(doc
);
1372 G_MODULE_EXPORT
void on_menu_select_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1374 GeanyDocument
*doc
= document_get_current();
1375 g_return_if_fail(doc
!= NULL
);
1377 sci_select_all(doc
->editor
->sci
);
1381 G_MODULE_EXPORT
void on_menu_show_sidebar1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
1383 if (ignore_callback
)
1386 ui_prefs
.sidebar_visible
= ! ui_prefs
.sidebar_visible
;
1388 /* show built-in tabs if no tabs visible */
1389 if (ui_prefs
.sidebar_visible
&&
1390 ! interface_prefs
.sidebar_openfiles_visible
&& ! interface_prefs
.sidebar_symbol_visible
&&
1391 gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets
.sidebar_notebook
)) <= 2)
1393 interface_prefs
.sidebar_openfiles_visible
= TRUE
;
1394 interface_prefs
.sidebar_symbol_visible
= TRUE
;
1397 /* if window has input focus, set it back to the editor before toggling off */
1398 if (! ui_prefs
.sidebar_visible
&&
1399 gtk_container_get_focus_child(GTK_CONTAINER(main_widgets
.sidebar_notebook
)) != NULL
)
1401 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
1404 ui_sidebar_show_hide();
1408 G_MODULE_EXPORT
void on_menu_write_unicode_bom1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
1410 if (! ignore_callback
)
1412 GeanyDocument
*doc
= document_get_current();
1414 g_return_if_fail(doc
!= NULL
);
1421 document_undo_add(doc
, UNDO_BOM
, GINT_TO_POINTER(doc
->has_bom
));
1423 doc
->has_bom
= ! doc
->has_bom
;
1425 ui_update_statusbar(doc
, -1);
1430 G_MODULE_EXPORT
void on_menu_comment_line1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1432 GeanyDocument
*doc
= document_get_current();
1433 g_return_if_fail(doc
!= NULL
);
1435 editor_do_comment(doc
->editor
, -1, FALSE
, FALSE
, TRUE
);
1439 G_MODULE_EXPORT
void on_menu_uncomment_line1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1441 GeanyDocument
*doc
= document_get_current();
1442 g_return_if_fail(doc
!= NULL
);
1444 editor_do_uncomment(doc
->editor
, -1, FALSE
);
1448 G_MODULE_EXPORT
void on_menu_toggle_line_commentation1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1450 GeanyDocument
*doc
= document_get_current();
1451 g_return_if_fail(doc
!= NULL
);
1453 editor_do_comment_toggle(doc
->editor
);
1457 G_MODULE_EXPORT
void on_menu_increase_indent1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1459 GeanyDocument
*doc
= document_get_current();
1460 g_return_if_fail(doc
!= NULL
);
1462 editor_indent(doc
->editor
, TRUE
);
1466 G_MODULE_EXPORT
void on_menu_decrease_indent1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1468 GeanyDocument
*doc
= document_get_current();
1469 g_return_if_fail(doc
!= NULL
);
1471 editor_indent(doc
->editor
, FALSE
);
1475 G_MODULE_EXPORT
void on_next_message1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1477 if (! ui_tree_view_find_next(GTK_TREE_VIEW(msgwindow
.tree_msg
),
1478 msgwin_goto_messages_file_line
))
1479 ui_set_statusbar(FALSE
, _("No more message items."));
1483 G_MODULE_EXPORT
void on_previous_message1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1485 if (! ui_tree_view_find_previous(GTK_TREE_VIEW(msgwindow
.tree_msg
),
1486 msgwin_goto_messages_file_line
))
1487 ui_set_statusbar(FALSE
, _("No more message items."));
1491 G_MODULE_EXPORT
void on_menu_comments_multiline_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1493 insert_callback_from_menu
= TRUE
;
1494 on_comments_multiline_activate(menuitem
, user_data
);
1498 G_MODULE_EXPORT
void on_menu_comments_gpl_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1500 insert_callback_from_menu
= TRUE
;
1501 on_comments_gpl_activate(menuitem
, user_data
);
1505 G_MODULE_EXPORT
void on_menu_comments_bsd_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1507 insert_callback_from_menu
= TRUE
;
1508 on_comments_bsd_activate(menuitem
, user_data
);
1512 G_MODULE_EXPORT
void on_menu_insert_include_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1514 insert_callback_from_menu
= TRUE
;
1515 on_insert_include_activate(menuitem
, user_data
);
1519 G_MODULE_EXPORT
void on_menu_insert_date_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1521 insert_callback_from_menu
= TRUE
;
1522 on_insert_date_activate(menuitem
, user_data
);
1526 G_MODULE_EXPORT
void on_project_new1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1532 G_MODULE_EXPORT
void on_project_open1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1538 G_MODULE_EXPORT
void on_project_close1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1540 project_close(TRUE
);
1544 G_MODULE_EXPORT
void on_project_properties1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1546 project_properties();
1550 G_MODULE_EXPORT
void on_menu_project1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1552 static GtkWidget
*item_close
= NULL
;
1553 static GtkWidget
*item_properties
= NULL
;
1555 if (item_close
== NULL
)
1557 item_close
= ui_lookup_widget(main_widgets
.window
, "project_close1");
1558 item_properties
= ui_lookup_widget(main_widgets
.window
, "project_properties1");
1561 gtk_widget_set_sensitive(item_close
, (app
->project
!= NULL
));
1562 gtk_widget_set_sensitive(item_properties
, (app
->project
!= NULL
));
1563 gtk_widget_set_sensitive(ui_widgets
.recent_projects_menuitem
,
1564 g_queue_get_length(ui_prefs
.recent_projects_queue
) > 0);
1568 G_MODULE_EXPORT
void on_menu_open_selected_file1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1570 GeanyDocument
*doc
= document_get_current();
1575 wc
= GEANY_WORDCHARS
"./-" "\\";
1577 wc
= GEANY_WORDCHARS
"./-";
1580 g_return_if_fail(doc
!= NULL
);
1582 sel
= editor_get_default_selection(doc
->editor
, TRUE
, wc
);
1583 SETPTR(sel
, utils_get_locale_from_utf8(sel
));
1587 gchar
*filename
= NULL
;
1589 if (g_path_is_absolute(sel
))
1590 filename
= g_strdup(sel
);
1592 { /* relative filename, add the path of the current file */
1595 path
= utils_get_current_file_dir_utf8();
1596 SETPTR(path
, utils_get_locale_from_utf8(path
));
1598 path
= g_get_current_dir();
1600 filename
= g_build_path(G_DIR_SEPARATOR_S
, path
, sel
, NULL
);
1602 if (! g_file_test(filename
, G_FILE_TEST_EXISTS
) &&
1603 app
->project
!= NULL
&& !EMPTY(app
->project
->base_path
))
1605 /* try the project's base path */
1606 SETPTR(path
, project_get_base_path());
1607 SETPTR(path
, utils_get_locale_from_utf8(path
));
1608 SETPTR(filename
, g_build_path(G_DIR_SEPARATOR_S
, path
, sel
, NULL
));
1612 if (! g_file_test(filename
, G_FILE_TEST_EXISTS
))
1613 SETPTR(filename
, g_build_path(G_DIR_SEPARATOR_S
, "/usr/local/include", sel
, NULL
));
1615 if (! g_file_test(filename
, G_FILE_TEST_EXISTS
))
1616 SETPTR(filename
, g_build_path(G_DIR_SEPARATOR_S
, "/usr/include", sel
, NULL
));
1620 if (g_file_test(filename
, G_FILE_TEST_EXISTS
))
1621 document_open_file(filename
, FALSE
, NULL
, NULL
);
1624 SETPTR(sel
, utils_get_utf8_from_locale(sel
));
1625 ui_set_statusbar(TRUE
, _("Could not open file %s (File not found)"), sel
);
1634 G_MODULE_EXPORT
void on_remove_markers1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1636 GeanyDocument
*doc
= document_get_current();
1637 g_return_if_fail(doc
!= NULL
);
1639 sci_marker_delete_all(doc
->editor
->sci
, 0); /* delete the yellow tag marker */
1640 sci_marker_delete_all(doc
->editor
->sci
, 1); /* delete user markers */
1641 editor_indicator_clear(doc
->editor
, GEANY_INDICATOR_SEARCH
);
1645 G_MODULE_EXPORT
void on_load_tags1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1647 symbols_show_load_tags_dialog();
1651 G_MODULE_EXPORT
void on_context_action1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1653 gchar
*word
, *command
;
1654 GError
*error
= NULL
;
1655 GeanyDocument
*doc
= document_get_current();
1657 g_return_if_fail(doc
!= NULL
);
1659 if (sci_has_selection(doc
->editor
->sci
))
1660 { /* take selected text if there is a selection */
1661 word
= sci_get_selection_contents(doc
->editor
->sci
);
1665 word
= g_strdup(editor_info
.current_word
);
1668 /* use the filetype specific command if available, fallback to global command otherwise */
1669 if (doc
->file_type
!= NULL
&&
1670 !EMPTY(doc
->file_type
->context_action_cmd
))
1672 command
= g_strdup(doc
->file_type
->context_action_cmd
);
1676 command
= g_strdup(tool_prefs
.context_action_cmd
);
1679 /* substitute the wildcard %s and run the command if it is non empty */
1680 if (G_LIKELY(!EMPTY(command
)))
1682 utils_str_replace_all(&command
, "%s", word
);
1684 if (! g_spawn_command_line_async(command
, &error
))
1686 ui_set_statusbar(TRUE
, "Context action command failed: %s", error
->message
);
1687 g_error_free(error
);
1695 G_MODULE_EXPORT
void on_menu_toggle_all_additional_widgets1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1697 static gint hide_all
= -1;
1698 GtkCheckMenuItem
*msgw
= GTK_CHECK_MENU_ITEM(
1699 ui_lookup_widget(main_widgets
.window
, "menu_show_messages_window1"));
1700 GtkCheckMenuItem
*toolbari
= GTK_CHECK_MENU_ITEM(
1701 ui_lookup_widget(main_widgets
.window
, "menu_show_toolbar1"));
1703 /* get the initial state (necessary if Geany was closed with hide_all = TRUE) */
1704 if (G_UNLIKELY(hide_all
== -1))
1706 if (! gtk_check_menu_item_get_active(msgw
) &&
1707 ! interface_prefs
.show_notebook_tabs
&&
1708 ! gtk_check_menu_item_get_active(toolbari
))
1716 hide_all
= ! hide_all
; /* toggle */
1720 if (gtk_check_menu_item_get_active(msgw
))
1721 gtk_check_menu_item_set_active(msgw
, ! gtk_check_menu_item_get_active(msgw
));
1723 interface_prefs
.show_notebook_tabs
= FALSE
;
1724 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets
.notebook
), interface_prefs
.show_notebook_tabs
);
1726 ui_statusbar_showhide(FALSE
);
1728 if (gtk_check_menu_item_get_active(toolbari
))
1729 gtk_check_menu_item_set_active(toolbari
, ! gtk_check_menu_item_get_active(toolbari
));
1734 if (! gtk_check_menu_item_get_active(msgw
))
1735 gtk_check_menu_item_set_active(msgw
, ! gtk_check_menu_item_get_active(msgw
));
1737 interface_prefs
.show_notebook_tabs
= TRUE
;
1738 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets
.notebook
), interface_prefs
.show_notebook_tabs
);
1740 ui_statusbar_showhide(TRUE
);
1742 if (! gtk_check_menu_item_get_active(toolbari
))
1743 gtk_check_menu_item_set_active(toolbari
, ! gtk_check_menu_item_get_active(toolbari
));
1748 G_MODULE_EXPORT
void on_forward_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1750 navqueue_go_forward();
1754 G_MODULE_EXPORT
void on_back_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1760 G_MODULE_EXPORT gboolean
on_motion_event(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
)
1762 if (prefs
.auto_focus
&& ! gtk_widget_has_focus(widget
))
1763 gtk_widget_grab_focus(widget
);
1769 static void set_indent_type(GtkCheckMenuItem
*menuitem
, GeanyIndentType type
)
1773 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
1776 doc
= document_get_current();
1777 g_return_if_fail(doc
!= NULL
);
1779 editor_set_indent(doc
->editor
, type
, doc
->editor
->indent_width
);
1780 ui_update_statusbar(doc
, -1);
1784 G_MODULE_EXPORT
void on_tabs1_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
1786 set_indent_type(menuitem
, GEANY_INDENT_TYPE_TABS
);
1790 G_MODULE_EXPORT
void on_spaces1_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
1792 set_indent_type(menuitem
, GEANY_INDENT_TYPE_SPACES
);
1796 G_MODULE_EXPORT
void on_tabs_and_spaces1_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
1798 set_indent_type(menuitem
, GEANY_INDENT_TYPE_BOTH
);
1802 G_MODULE_EXPORT
void on_strip_trailing_spaces1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1806 if (ignore_callback
)
1809 doc
= document_get_current();
1810 g_return_if_fail(doc
!= NULL
);
1812 editor_strip_trailing_spaces(doc
->editor
);
1816 G_MODULE_EXPORT
void on_page_setup1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1818 printing_page_setup_gtk();
1822 G_MODULE_EXPORT gboolean
on_escape_key_press_event(GtkWidget
*widget
, GdkEventKey
*event
, gpointer user_data
)
1824 guint state
= event
->state
& gtk_accelerator_get_default_mod_mask();
1826 /* make pressing escape in the sidebar and toolbar focus the editor */
1827 if (event
->keyval
== GDK_Escape
&& state
== 0)
1829 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
1836 G_MODULE_EXPORT
void on_line_breaking1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1840 if (ignore_callback
)
1843 doc
= document_get_current();
1844 g_return_if_fail(doc
!= NULL
);
1846 doc
->editor
->line_breaking
= !doc
->editor
->line_breaking
;
1850 G_MODULE_EXPORT
void on_replace_spaces_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1852 GeanyDocument
*doc
= document_get_current();
1854 g_return_if_fail(doc
!= NULL
);
1856 editor_replace_spaces(doc
->editor
);
1860 G_MODULE_EXPORT
void on_search1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1862 GtkWidget
*next_message
= ui_lookup_widget(main_widgets
.window
, "next_message1");
1863 GtkWidget
*previous_message
= ui_lookup_widget(main_widgets
.window
, "previous_message1");
1864 gboolean have_messages
;
1866 /* enable commands if the messages window has any items */
1867 have_messages
= gtk_tree_model_iter_n_children(GTK_TREE_MODEL(msgwindow
.store_msg
),
1870 gtk_widget_set_sensitive(next_message
, have_messages
);
1871 gtk_widget_set_sensitive(previous_message
, have_messages
);
1875 /* simple implementation (vs. close all which doesn't close documents if cancelled),
1876 * if user_data is set, it is the GeanyDocument to keep */
1877 G_MODULE_EXPORT
void on_close_other_documents1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1880 GeanyDocument
*cur_doc
= user_data
;
1882 if (cur_doc
== NULL
)
1883 cur_doc
= document_get_current();
1885 for (i
= 0; i
< documents_array
->len
; i
++)
1887 GeanyDocument
*doc
= documents
[i
];
1889 if (doc
== cur_doc
|| ! doc
->is_valid
)
1892 if (! document_close(doc
))
1898 G_MODULE_EXPORT
void on_menu_reload_configuration1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1900 main_reload_configuration();
1904 G_MODULE_EXPORT
void on_debug_messages1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1906 log_show_debug_messages_dialog();
1910 G_MODULE_EXPORT
void on_send_selection_to_vte1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1913 if (vte_info
.have_vte
)
1914 vte_send_selection_to_vte();
1919 G_MODULE_EXPORT gboolean
on_window_state_event(GtkWidget
*widget
, GdkEventWindowState
*event
, gpointer user_data
)
1922 if (event
->changed_mask
& GDK_WINDOW_STATE_FULLSCREEN
)
1924 static GtkWidget
*menuitem
= NULL
;
1926 if (menuitem
== NULL
)
1927 menuitem
= ui_lookup_widget(widget
, "menu_fullscreen1");
1929 ignore_callback
= TRUE
;
1931 ui_prefs
.fullscreen
= (event
->new_window_state
& GDK_WINDOW_STATE_FULLSCREEN
) ? TRUE
: FALSE
;
1932 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem
), ui_prefs
.fullscreen
);
1934 ignore_callback
= FALSE
;
1940 static void show_notebook_page(const gchar
*notebook_name
, const gchar
*page_name
)
1943 GtkNotebook
*notebook
;
1945 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, page_name
);
1946 notebook
= GTK_NOTEBOOK(ui_lookup_widget(ui_widgets
.prefs_dialog
, notebook_name
));
1948 if (notebook
!= NULL
&& widget
!= NULL
)
1949 gtk_notebook_set_current_page(notebook
, gtk_notebook_page_num(notebook
, widget
));
1953 G_MODULE_EXPORT
void on_customize_toolbar1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1955 prefs_show_dialog();
1957 /* select the Interface page */
1958 show_notebook_page("notebook2", "notebook6");
1959 /* select the Toolbar subpage */
1960 show_notebook_page("notebook6", "vbox15");
1964 G_MODULE_EXPORT
void on_button_customize_toolbar_clicked(GtkButton
*button
, gpointer user_data
)
1966 toolbar_configure(GTK_WINDOW(ui_widgets
.prefs_dialog
));
1970 G_MODULE_EXPORT
void on_cut_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1972 keybindings_send_command(GEANY_KEY_GROUP_CLIPBOARD
, GEANY_KEYS_CLIPBOARD_CUTLINE
);
1976 G_MODULE_EXPORT
void on_copy_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1978 keybindings_send_command(GEANY_KEY_GROUP_CLIPBOARD
, GEANY_KEYS_CLIPBOARD_COPYLINE
);
1982 G_MODULE_EXPORT
void on_delete_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1984 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_DELETELINE
);
1988 G_MODULE_EXPORT
void on_duplicate_line_or_selection1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1990 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_DUPLICATELINE
);
1994 G_MODULE_EXPORT
void on_select_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1996 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_LINE
);
2000 G_MODULE_EXPORT
void on_select_current_paragraph1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2002 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_PARAGRAPH
);
2006 G_MODULE_EXPORT
void on_insert_alternative_white_space1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2008 keybindings_send_command(GEANY_KEY_GROUP_INSERT
, GEANY_KEYS_INSERT_ALTWHITESPACE
);
2012 G_MODULE_EXPORT
void on_go_to_next_marker1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2014 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_NEXTMARKER
);
2018 G_MODULE_EXPORT
void on_go_to_previous_marker1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2020 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_PREVIOUSMARKER
);
2024 G_MODULE_EXPORT
void on_reflow_lines_block1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2026 keybindings_send_command(GEANY_KEY_GROUP_FORMAT
, GEANY_KEYS_FORMAT_REFLOWPARAGRAPH
);
2030 G_MODULE_EXPORT
void on_move_lines_up1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2032 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_MOVELINEUP
);
2036 G_MODULE_EXPORT
void on_move_lines_down1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2038 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_MOVELINEDOWN
);
2042 G_MODULE_EXPORT
void on_smart_line_indent1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2044 keybindings_send_command(GEANY_KEY_GROUP_FORMAT
, GEANY_KEYS_FORMAT_AUTOINDENT
);
2048 G_MODULE_EXPORT
void on_plugin_preferences1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2051 plugin_show_configure(NULL
);
2056 G_MODULE_EXPORT
void on_indent_width_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2062 if (ignore_callback
)
2065 label
= ui_menu_item_get_text(menuitem
);
2066 width
= atoi(label
);
2069 doc
= document_get_current();
2070 if (doc
!= NULL
&& width
> 0)
2071 editor_set_indent_width(doc
->editor
, width
);
2075 G_MODULE_EXPORT
void on_reset_indentation1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2080 document_apply_indent_settings(documents
[i
]);
2082 ui_update_statusbar(NULL
, -1);
2083 ui_document_show_hide(NULL
);
2087 G_MODULE_EXPORT
void on_mark_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2089 keybindings_send_command(GEANY_KEY_GROUP_SEARCH
, GEANY_KEYS_SEARCH_MARKALL
);
2093 G_MODULE_EXPORT
void on_detect_type_from_file_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2095 GeanyDocument
*doc
= document_get_current();
2096 GeanyIndentType type
;
2098 if (doc
!= NULL
&& document_detect_indent_type(doc
, &type
))
2100 editor_set_indent_type(doc
->editor
, type
);
2101 ui_document_show_hide(doc
);
2106 G_MODULE_EXPORT
void on_detect_width_from_file_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2108 GeanyDocument
*doc
= document_get_current();
2111 if (doc
!= NULL
&& document_detect_indent_width(doc
, &width
))
2113 editor_set_indent_width(doc
->editor
, width
);
2114 ui_document_show_hide(doc
);