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 gint cur_page
= gtk_notebook_get_current_page(GTK_NOTEBOOK(main_widgets
.notebook
));
168 GeanyDocument
*doc
= document_get_current();
170 if (doc
!= NULL
&& cur_page
>= 0)
172 document_save_file(doc
, ui_prefs
.allow_always_save
);
177 G_MODULE_EXPORT
void on_save_as1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
179 dialogs_show_save_as();
183 G_MODULE_EXPORT
void on_save_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
185 guint i
, max
= (guint
) gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets
.notebook
));
186 GeanyDocument
*doc
, *cur_doc
= document_get_current();
189 /* iterate over documents in tabs order */
190 for (i
= 0; i
< max
; i
++)
192 doc
= document_get_from_page(i
);
196 if (document_save_file(doc
, FALSE
))
202 ui_set_statusbar(FALSE
, ngettext("%d file saved.", "%d files saved.", count
), count
);
203 /* saving may have changed window title, sidebar for another doc, so update */
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 on_reload_as_activate(NULL
, GINT_TO_POINTER(-1));
402 /* also used for reloading when user_data is -1 */
403 G_MODULE_EXPORT
void on_reload_as_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
405 GeanyDocument
*doc
= document_get_current();
407 gint i
= GPOINTER_TO_INT(user_data
);
408 const gchar
*charset
= NULL
;
410 g_return_if_fail(doc
!= NULL
);
412 /* No need to reload "untitled" (non-file-backed) documents */
413 if (doc
->file_name
== NULL
)
418 if (i
>= GEANY_ENCODINGS_MAX
|| encodings
[i
].charset
== NULL
)
420 charset
= encodings
[i
].charset
;
423 charset
= doc
->encoding
;
425 base_name
= g_path_get_basename(doc
->file_name
);
426 /* don't prompt if file hasn't been edited at all */
427 if ((!doc
->changed
&& !document_can_undo(doc
) && !document_can_redo(doc
)) ||
428 dialogs_show_question_full(NULL
, _("_Reload"), GTK_STOCK_CANCEL
,
429 _("Any unsaved changes will be lost."),
430 _("Are you sure you want to reload '%s'?"), base_name
))
432 document_reload_file(doc
, charset
);
434 ui_update_statusbar(doc
, -1);
440 G_MODULE_EXPORT
void on_change_font1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
442 dialogs_show_open_font();
447 G_MODULE_EXPORT
void on_toolbutton_new_clicked(GtkAction
*action
, gpointer user_data
)
449 document_new_file(NULL
, NULL
, NULL
);
454 G_MODULE_EXPORT
void on_toolbutton_open_clicked(GtkAction
*action
, gpointer user_data
)
456 dialogs_show_open_file();
461 G_MODULE_EXPORT
void on_toolbutton_save_clicked(GtkAction
*action
, gpointer user_data
)
463 on_save1_activate(NULL
, user_data
);
467 /* store text, clear search flags so we can use Search->Find Next/Previous */
468 static void setup_find(const gchar
*text
, gboolean backwards
)
470 SETPTR(search_data
.text
, g_strdup(text
));
471 SETPTR(search_data
.original_text
, g_strdup(text
));
472 search_data
.flags
= 0;
473 search_data
.backwards
= backwards
;
474 search_data
.search_bar
= TRUE
;
478 static void do_toolbar_search(const gchar
*text
, gboolean incremental
, gboolean backwards
)
480 GeanyDocument
*doc
= document_get_current();
483 setup_find(text
, backwards
);
484 result
= document_search_bar_find(doc
, search_data
.text
, 0, incremental
, backwards
);
485 if (search_data
.search_bar
)
486 ui_set_search_entry_background(toolbar_get_widget_child_by_name("SearchEntry"), result
);
491 G_MODULE_EXPORT
void on_toolbar_search_entry_changed(GtkAction
*action
, const gchar
*text
, gpointer user_data
)
493 do_toolbar_search(text
, TRUE
, FALSE
);
498 G_MODULE_EXPORT
void on_toolbar_search_entry_activate(GtkAction
*action
, const gchar
*text
, gpointer user_data
)
500 do_toolbar_search(text
, FALSE
, GPOINTER_TO_INT(user_data
));
505 G_MODULE_EXPORT
void on_toolbutton_search_clicked(GtkAction
*action
, gpointer user_data
)
507 GeanyDocument
*doc
= document_get_current();
509 GtkWidget
*entry
= toolbar_get_widget_child_by_name("SearchEntry");
513 const gchar
*text
= gtk_entry_get_text(GTK_ENTRY(entry
));
515 setup_find(text
, FALSE
);
516 result
= document_search_bar_find(doc
, search_data
.text
, 0, FALSE
, FALSE
);
517 if (search_data
.search_bar
)
518 ui_set_search_entry_background(entry
, result
);
521 on_find1_activate(NULL
, NULL
);
525 /* hides toolbar from toolbar popup menu */
526 G_MODULE_EXPORT
void on_hide_toolbar1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
528 GtkWidget
*tool_item
= ui_lookup_widget(GTK_WIDGET(main_widgets
.window
), "menu_show_toolbar1");
529 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(tool_item
), FALSE
);
533 /* zoom in from menu bar and popup menu */
534 G_MODULE_EXPORT
void on_zoom_in1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
536 GeanyDocument
*doc
= document_get_current();
537 static gint done
= 1;
539 g_return_if_fail(doc
!= NULL
);
542 sci_set_line_numbers(doc
->editor
->sci
, editor_prefs
.show_linenumber_margin
,
543 (sci_get_zoom(doc
->editor
->sci
) / 2));
544 sci_zoom_in(doc
->editor
->sci
);
548 /* zoom out from menu bar and popup menu */
549 G_MODULE_EXPORT
void on_zoom_out1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
551 GeanyDocument
*doc
= document_get_current();
553 g_return_if_fail(doc
!= NULL
);
555 if (sci_get_zoom(doc
->editor
->sci
) == 0)
556 sci_set_line_numbers(doc
->editor
->sci
, editor_prefs
.show_linenumber_margin
, 0);
557 sci_zoom_out(doc
->editor
->sci
);
561 G_MODULE_EXPORT
void on_normal_size1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
563 GeanyDocument
*doc
= document_get_current();
565 g_return_if_fail(doc
!= NULL
);
567 sci_zoom_off(doc
->editor
->sci
);
568 sci_set_line_numbers(doc
->editor
->sci
, editor_prefs
.show_linenumber_margin
, 0);
573 G_MODULE_EXPORT
void on_toolbutton_close_clicked(GtkAction
*action
, gpointer user_data
)
575 on_close1_activate(NULL
, NULL
);
579 G_MODULE_EXPORT
void on_toolbutton_close_all_clicked(GtkAction
*action
, gpointer user_data
)
581 on_close_all1_activate(NULL
, NULL
);
585 G_MODULE_EXPORT
void on_toolbutton_preferences_clicked(GtkAction
*action
, gpointer user_data
)
587 on_preferences1_activate(NULL
, NULL
);
591 static gboolean
delayed_check_disk_status(gpointer data
)
593 document_check_disk_status(data
, FALSE
);
598 /* Changes window-title after switching tabs and lots of other things.
599 * note: using 'after' makes Scintilla redraw before the UI, appearing more responsive */
600 G_MODULE_EXPORT
void on_notebook1_switch_page_after(GtkNotebook
*notebook
, gpointer page
,
601 guint page_num
, gpointer user_data
)
605 if (G_UNLIKELY(main_status
.opening_session_files
|| main_status
.closing_all
))
608 if (page_num
== (guint
) -1 && page
!= NULL
)
609 doc
= document_find_by_sci(SCINTILLA(page
));
611 doc
= document_get_from_page(page_num
);
615 sidebar_select_openfiles_item(doc
);
616 ui_save_buttons_toggle(doc
->changed
);
617 ui_set_window_title(doc
);
618 ui_update_statusbar(doc
, -1);
619 ui_update_popup_reundo_items(doc
);
620 ui_document_show_hide(doc
); /* update the document menu */
621 build_menu_update(doc
);
622 sidebar_update_tag_list(doc
, FALSE
);
623 document_highlight_tags(doc
);
625 /* We delay the check to avoid weird fast, unintended switching of notebook pages when
626 * the 'file has changed' dialog is shown while the switch event is not yet completely
627 * finished. So, we check after the switch has been performed to be safe. */
628 g_idle_add(delayed_check_disk_status
, doc
);
631 vte_cwd((doc
->real_path
!= NULL
) ? doc
->real_path
: doc
->file_name
, FALSE
);
634 g_signal_emit_by_name(geany_object
, "document-activate", doc
);
639 G_MODULE_EXPORT
void on_tv_notebook_switch_page(GtkNotebook
*notebook
, gpointer page
,
640 guint page_num
, gpointer user_data
)
642 /* suppress selection changed signal when switching to the open files list */
643 ignore_callback
= TRUE
;
647 G_MODULE_EXPORT
void on_tv_notebook_switch_page_after(GtkNotebook
*notebook
, gpointer page
,
648 guint page_num
, gpointer user_data
)
650 ignore_callback
= FALSE
;
654 static void convert_eol(gint mode
)
656 GeanyDocument
*doc
= document_get_current();
658 g_return_if_fail(doc
!= NULL
);
660 sci_convert_eols(doc
->editor
->sci
, mode
);
661 sci_set_eol_mode(doc
->editor
->sci
, mode
);
662 ui_update_statusbar(doc
, -1);
666 G_MODULE_EXPORT
void on_crlf_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
668 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
671 convert_eol(SC_EOL_CRLF
);
675 G_MODULE_EXPORT
void on_lf_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
677 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
680 convert_eol(SC_EOL_LF
);
684 G_MODULE_EXPORT
void on_cr_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
686 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
689 convert_eol(SC_EOL_CR
);
693 G_MODULE_EXPORT
void on_replace_tabs_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
695 GeanyDocument
*doc
= document_get_current();
697 g_return_if_fail(doc
!= NULL
);
699 editor_replace_tabs(doc
->editor
);
703 gboolean
toolbar_popup_menu(GtkWidget
*widget
, GdkEventButton
*event
, gpointer user_data
)
705 if (event
->button
== 3)
707 gtk_menu_popup(GTK_MENU(ui_widgets
.toolbar_menu
), NULL
, NULL
, NULL
, NULL
, event
->button
, event
->time
);
714 G_MODULE_EXPORT
void on_toggle_case1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
716 GeanyDocument
*doc
= document_get_current();
717 ScintillaObject
*sci
;
719 gboolean keep_sel
= TRUE
;
721 g_return_if_fail(doc
!= NULL
);
723 sci
= doc
->editor
->sci
;
724 if (! sci_has_selection(sci
))
726 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_WORD
);
730 /* either we already had a selection or we created one for current word */
731 if (sci_has_selection(sci
))
733 gchar
*result
= NULL
;
734 gint cmd
= SCI_LOWERCASE
;
735 gboolean rectsel
= (gboolean
) scintilla_send_message(sci
, SCI_SELECTIONISRECTANGLE
, 0, 0);
737 text
= sci_get_selection_contents(sci
);
739 if (utils_str_has_upper(text
))
744 result
= g_utf8_strdown(text
, -1);
751 result
= g_utf8_strup(text
, -1);
756 sci_replace_sel(sci
, result
);
759 sci_set_selection_start(sci
, sci_get_current_position(sci
) - strlen(text
));
762 sci_send_command(sci
, cmd
);
770 G_MODULE_EXPORT
void on_show_toolbar1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
772 if (ignore_callback
) return;
774 toolbar_prefs
.visible
= (toolbar_prefs
.visible
) ? FALSE
: TRUE
;;
775 ui_widget_show_hide(GTK_WIDGET(main_widgets
.toolbar
), toolbar_prefs
.visible
);
779 G_MODULE_EXPORT
void on_fullscreen1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
784 ui_prefs
.fullscreen
= (ui_prefs
.fullscreen
) ? FALSE
: TRUE
;
789 G_MODULE_EXPORT
void on_show_messages_window1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
794 ui_prefs
.msgwindow_visible
= (ui_prefs
.msgwindow_visible
) ? FALSE
: TRUE
;
795 msgwin_show_hide(ui_prefs
.msgwindow_visible
);
799 G_MODULE_EXPORT
void on_menu_color_schemes_activate(GtkImageMenuItem
*imagemenuitem
, gpointer user_data
)
801 highlighting_show_color_scheme_dialog();
805 G_MODULE_EXPORT
void on_markers_margin1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
810 editor_prefs
.show_markers_margin
= ! editor_prefs
.show_markers_margin
;
811 ui_toggle_editor_features(GEANY_EDITOR_SHOW_MARKERS_MARGIN
);
815 G_MODULE_EXPORT
void on_show_line_numbers1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
820 editor_prefs
.show_linenumber_margin
= ! editor_prefs
.show_linenumber_margin
;
821 ui_toggle_editor_features(GEANY_EDITOR_SHOW_LINE_NUMBERS
);
825 G_MODULE_EXPORT
void on_menu_show_white_space1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
830 editor_prefs
.show_white_space
= ! editor_prefs
.show_white_space
;
831 ui_toggle_editor_features(GEANY_EDITOR_SHOW_WHITE_SPACE
);
835 G_MODULE_EXPORT
void on_menu_show_line_endings1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
840 editor_prefs
.show_line_endings
= ! editor_prefs
.show_line_endings
;
841 ui_toggle_editor_features(GEANY_EDITOR_SHOW_LINE_ENDINGS
);
845 G_MODULE_EXPORT
void on_menu_show_indentation_guides1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
850 editor_prefs
.show_indent_guide
= ! editor_prefs
.show_indent_guide
;
851 ui_toggle_editor_features(GEANY_EDITOR_SHOW_INDENTATION_GUIDES
);
855 G_MODULE_EXPORT
void on_line_wrapping1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
857 if (! ignore_callback
)
859 GeanyDocument
*doc
= document_get_current();
860 g_return_if_fail(doc
!= NULL
);
862 editor_set_line_wrapping(doc
->editor
, ! doc
->editor
->line_wrapping
);
867 G_MODULE_EXPORT
void on_set_file_readonly1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
869 if (! ignore_callback
)
871 GeanyDocument
*doc
= document_get_current();
872 g_return_if_fail(doc
!= NULL
);
874 doc
->readonly
= ! doc
->readonly
;
875 sci_set_readonly(doc
->editor
->sci
, doc
->readonly
);
876 ui_update_tab_status(doc
);
877 ui_update_statusbar(doc
, -1);
882 G_MODULE_EXPORT
void on_use_auto_indentation1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
884 if (! ignore_callback
)
886 GeanyDocument
*doc
= document_get_current();
887 g_return_if_fail(doc
!= NULL
);
889 doc
->editor
->auto_indent
= ! doc
->editor
->auto_indent
;
894 static void find_usage(gboolean in_session
)
898 GeanyDocument
*doc
= document_get_current();
900 g_return_if_fail(doc
!= NULL
);
902 if (sci_has_selection(doc
->editor
->sci
))
903 { /* take selected text if there is a selection */
904 search_text
= sci_get_selection_contents(doc
->editor
->sci
);
905 flags
= SCFIND_MATCHCASE
;
909 editor_find_current_word_sciwc(doc
->editor
, -1,
910 editor_info
.current_word
, GEANY_MAX_WORD_LENGTH
);
911 search_text
= g_strdup(editor_info
.current_word
);
912 flags
= SCFIND_MATCHCASE
| SCFIND_WHOLEWORD
;
915 search_find_usage(search_text
, search_text
, flags
, in_session
);
920 G_MODULE_EXPORT
void on_find_document_usage1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
926 G_MODULE_EXPORT
void on_find_usage1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
932 static void goto_tag(gboolean definition
)
934 GeanyDocument
*doc
= document_get_current();
936 g_return_if_fail(doc
!= NULL
);
938 /* update cursor pos for navigating back afterwards */
939 if (!sci_has_selection(doc
->editor
->sci
))
940 sci_set_current_position(doc
->editor
->sci
, editor_info
.click_pos
, FALSE
);
942 /* use the keybinding callback as it checks for selections as well as current word */
944 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_TAGDEFINITION
);
946 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_TAGDECLARATION
);
950 G_MODULE_EXPORT
void on_goto_tag_definition1(GtkMenuItem
*menuitem
, gpointer user_data
)
956 G_MODULE_EXPORT
void on_goto_tag_declaration1(GtkMenuItem
*menuitem
, gpointer user_data
)
962 G_MODULE_EXPORT
void on_count_words1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
968 G_MODULE_EXPORT
void on_show_color_chooser1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
971 GeanyDocument
*doc
= document_get_current();
974 g_return_if_fail(doc
!= NULL
);
976 pos
= sci_get_current_position(doc
->editor
->sci
);
977 editor_find_current_word(doc
->editor
, pos
, colour
, sizeof colour
, GEANY_WORDCHARS
"#");
978 tools_color_chooser(colour
);
982 G_MODULE_EXPORT
void on_toolbutton_compile_clicked(GtkAction
*action
, gpointer user_data
)
984 keybindings_send_command(GEANY_KEY_GROUP_BUILD
, GEANY_KEYS_BUILD_COMPILE
);
988 G_MODULE_EXPORT
void on_find1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
990 search_show_find_dialog();
994 G_MODULE_EXPORT
void on_find_next1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
996 search_find_again(FALSE
);
1000 G_MODULE_EXPORT
void on_find_previous1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1002 if (search_data
.flags
& SCFIND_REGEXP
)
1003 /* Can't reverse search order for a regex (find next ignores search backwards) */
1006 search_find_again(TRUE
);
1010 G_MODULE_EXPORT
void on_find_nextsel1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1012 search_find_selection(document_get_current(), FALSE
);
1016 G_MODULE_EXPORT
void on_find_prevsel1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1018 search_find_selection(document_get_current(), TRUE
);
1022 G_MODULE_EXPORT
void on_replace1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1024 search_show_replace_dialog();
1028 G_MODULE_EXPORT
void on_find_in_files1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1030 search_show_find_in_files_dialog(NULL
);
1034 static void get_line_and_offset_from_text(const gchar
*text
, gint
*line_no
, gint
*offset
)
1036 if (*text
== '+' || *text
== '-')
1038 *line_no
= atoi(text
+ 1);
1039 *offset
= (*text
== '+') ? 1 : -1;
1043 *line_no
= atoi(text
) - 1;
1049 G_MODULE_EXPORT
void on_go_to_line_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1051 static gchar value
[16] = "";
1054 result
= dialogs_show_input_goto_line(
1055 _("Go to Line"), GTK_WINDOW(main_widgets
.window
),
1056 _("Enter the line you want to go to:"), value
);
1059 GeanyDocument
*doc
= document_get_current();
1063 g_return_if_fail(doc
!= NULL
);
1065 get_line_and_offset_from_text(result
, &line_no
, &offset
);
1066 if (! editor_goto_line(doc
->editor
, line_no
, offset
))
1068 /* remember value for future calls */
1069 g_snprintf(value
, sizeof(value
), "%s", result
);
1076 G_MODULE_EXPORT
void on_toolbutton_goto_entry_activate(GtkAction
*action
, const gchar
*text
, gpointer user_data
)
1078 GeanyDocument
*doc
= document_get_current();
1082 g_return_if_fail(doc
!= NULL
);
1084 get_line_and_offset_from_text(text
, &line_no
, &offset
);
1085 if (! editor_goto_line(doc
->editor
, line_no
, offset
))
1088 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
1092 G_MODULE_EXPORT
void on_toolbutton_goto_clicked(GtkAction
*action
, gpointer user_data
)
1094 GtkWidget
*entry
= toolbar_get_widget_child_by_name("GotoEntry");
1098 const gchar
*text
= gtk_entry_get_text(GTK_ENTRY(entry
));
1100 on_toolbutton_goto_entry_activate(NULL
, text
, NULL
);
1103 on_go_to_line_activate(NULL
, NULL
);
1107 G_MODULE_EXPORT
void on_help1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1111 uri
= utils_get_help_url(NULL
);
1112 utils_open_browser(uri
);
1117 G_MODULE_EXPORT
void on_help_shortcuts1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1119 keybindings_show_shortcuts();
1123 G_MODULE_EXPORT
void on_website1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1125 utils_open_browser(GEANY_HOMEPAGE
);
1129 G_MODULE_EXPORT
void on_help_menu_item_donate_activate(GtkMenuItem
*item
, gpointer user_data
)
1131 utils_open_browser(GEANY_DONATE
);
1135 G_MODULE_EXPORT
void on_help_menu_item_wiki_activate(GtkMenuItem
*item
, gpointer user_data
)
1137 utils_open_browser(GEANY_WIKI
);
1141 G_MODULE_EXPORT
void on_help_menu_item_bug_report_activate(GtkMenuItem
*item
, gpointer user_data
)
1143 utils_open_browser(GEANY_BUG_REPORT
);
1147 G_MODULE_EXPORT
void on_comments_function_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1149 GeanyDocument
*doc
= document_get_current();
1151 const gchar
*cur_tag
= NULL
;
1152 gint line
= -1, pos
= 0;
1154 if (doc
== NULL
|| doc
->file_type
== NULL
)
1156 ui_set_statusbar(FALSE
,
1157 _("Please set the filetype for the current file before using this function."));
1161 /* symbols_get_current_function returns -1 on failure, so sci_get_position_from_line
1162 * returns the current position, so it should be safe */
1163 line
= symbols_get_current_function(doc
, &cur_tag
);
1164 pos
= sci_get_position_from_line(doc
->editor
->sci
, line
);
1166 text
= templates_get_template_function(doc
, cur_tag
);
1168 sci_start_undo_action(doc
->editor
->sci
);
1169 sci_insert_text(doc
->editor
->sci
, pos
, text
);
1170 sci_end_undo_action(doc
->editor
->sci
);
1175 G_MODULE_EXPORT
void on_comments_multiline_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1177 GeanyDocument
*doc
= document_get_current();
1179 if (doc
== NULL
|| doc
->file_type
== NULL
)
1181 ui_set_statusbar(FALSE
,
1182 _("Please set the filetype for the current file before using this function."));
1186 verify_click_pos(doc
); /* make sure that the click_pos is valid */
1188 if (doc
->file_type
->comment_open
|| doc
->file_type
->comment_single
)
1189 editor_insert_multiline_comment(doc
->editor
);
1195 G_MODULE_EXPORT
void on_comments_gpl_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1197 GeanyDocument
*doc
= document_get_current();
1200 g_return_if_fail(doc
!= NULL
);
1202 text
= templates_get_template_licence(doc
, GEANY_TEMPLATE_GPL
);
1204 verify_click_pos(doc
); /* make sure that the click_pos is valid */
1206 sci_start_undo_action(doc
->editor
->sci
);
1207 sci_insert_text(doc
->editor
->sci
, editor_info
.click_pos
, text
);
1208 sci_end_undo_action(doc
->editor
->sci
);
1213 G_MODULE_EXPORT
void on_comments_bsd_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1215 GeanyDocument
*doc
= document_get_current();
1218 g_return_if_fail(doc
!= NULL
);
1220 text
= templates_get_template_licence(doc
, GEANY_TEMPLATE_BSD
);
1222 verify_click_pos(doc
); /* make sure that the click_pos is valid */
1224 sci_start_undo_action(doc
->editor
->sci
);
1225 sci_insert_text(doc
->editor
->sci
, editor_info
.click_pos
, text
);
1226 sci_end_undo_action(doc
->editor
->sci
);
1232 G_MODULE_EXPORT
void on_comments_changelog_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1234 GeanyDocument
*doc
= document_get_current();
1237 g_return_if_fail(doc
!= NULL
);
1239 text
= templates_get_template_changelog(doc
);
1240 sci_start_undo_action(doc
->editor
->sci
);
1241 sci_insert_text(doc
->editor
->sci
, 0, text
);
1242 /* sets the cursor to the right position to type the changelog text,
1243 * the template has 21 chars + length of name and email */
1244 sci_goto_pos(doc
->editor
->sci
, 21 + strlen(template_prefs
.developer
) + strlen(template_prefs
.mail
), TRUE
);
1245 sci_end_undo_action(doc
->editor
->sci
);
1251 G_MODULE_EXPORT
void on_comments_fileheader_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1253 GeanyDocument
*doc
= document_get_current();
1258 g_return_if_fail(doc
!= NULL
);
1260 ft
= doc
->file_type
;
1261 fname
= doc
->file_name
;
1262 text
= templates_get_template_fileheader(FILETYPE_ID(ft
), fname
);
1264 sci_start_undo_action(doc
->editor
->sci
);
1265 sci_insert_text(doc
->editor
->sci
, 0, text
);
1266 sci_goto_pos(doc
->editor
->sci
, 0, FALSE
);
1267 sci_end_undo_action(doc
->editor
->sci
);
1272 G_MODULE_EXPORT
void on_insert_date_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1274 GeanyDocument
*doc
= document_get_current();
1275 const gchar
*format
= NULL
;
1278 g_return_if_fail(doc
!= NULL
);
1280 /* set default value */
1281 if (utils_str_equal("", ui_prefs
.custom_date_format
))
1283 g_free(ui_prefs
.custom_date_format
);
1284 ui_prefs
.custom_date_format
= g_strdup("%d.%m.%Y");
1287 if (utils_str_equal(_("dd.mm.yyyy"), (gchar
*) user_data
))
1288 format
= "%d.%m.%Y";
1289 else if (utils_str_equal(_("mm.dd.yyyy"), (gchar
*) user_data
))
1290 format
= "%m.%d.%Y";
1291 else if (utils_str_equal(_("yyyy/mm/dd"), (gchar
*) user_data
))
1292 format
= "%Y/%m/%d";
1293 else if (utils_str_equal(_("dd.mm.yyyy hh:mm:ss"), (gchar
*) user_data
))
1294 format
= "%d.%m.%Y %H:%M:%S";
1295 else if (utils_str_equal(_("mm.dd.yyyy hh:mm:ss"), (gchar
*) user_data
))
1296 format
= "%m.%d.%Y %H:%M:%S";
1297 else if (utils_str_equal(_("yyyy/mm/dd hh:mm:ss"), (gchar
*) user_data
))
1298 format
= "%Y/%m/%d %H:%M:%S";
1299 else if (utils_str_equal(_("_Use Custom Date Format"), (gchar
*) user_data
))
1300 format
= ui_prefs
.custom_date_format
;
1303 gchar
*str
= dialogs_show_input(_("Custom Date Format"), GTK_WINDOW(main_widgets
.window
),
1304 _("Enter here a custom date and time format. "
1305 "You can use any conversion specifiers which can be used with the ANSI C strftime function."),
1306 ui_prefs
.custom_date_format
);
1308 SETPTR(ui_prefs
.custom_date_format
, str
);
1312 time_str
= utils_get_date_time(format
, NULL
);
1313 if (time_str
!= NULL
)
1315 verify_click_pos(doc
); /* make sure that the click_pos is valid */
1317 sci_start_undo_action(doc
->editor
->sci
);
1318 sci_insert_text(doc
->editor
->sci
, editor_info
.click_pos
, time_str
);
1319 sci_goto_pos(doc
->editor
->sci
, editor_info
.click_pos
+ strlen(time_str
), FALSE
);
1320 sci_end_undo_action(doc
->editor
->sci
);
1326 ui_set_statusbar(TRUE
,
1327 _("Date format string could not be converted (possibly too long)."));
1332 G_MODULE_EXPORT
void on_insert_include_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1334 GeanyDocument
*doc
= document_get_current();
1338 g_return_if_fail(doc
!= NULL
);
1339 g_return_if_fail(user_data
!= NULL
);
1341 verify_click_pos(doc
); /* make sure that the click_pos is valid */
1343 if (utils_str_equal(user_data
, "blank"))
1345 text
= g_strdup("#include \"\"\n");
1346 pos
= editor_info
.click_pos
+ 10;
1350 text
= g_strconcat("#include <", user_data
, ">\n", NULL
);
1353 sci_start_undo_action(doc
->editor
->sci
);
1354 sci_insert_text(doc
->editor
->sci
, editor_info
.click_pos
, text
);
1355 sci_end_undo_action(doc
->editor
->sci
);
1358 sci_goto_pos(doc
->editor
->sci
, pos
, FALSE
);
1362 G_MODULE_EXPORT
void on_file_properties_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1364 GeanyDocument
*doc
= document_get_current();
1365 g_return_if_fail(doc
!= NULL
);
1367 dialogs_show_file_properties(doc
);
1371 G_MODULE_EXPORT
void on_menu_fold_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1373 GeanyDocument
*doc
= document_get_current();
1374 g_return_if_fail(doc
!= NULL
);
1376 editor_fold_all(doc
->editor
);
1380 G_MODULE_EXPORT
void on_menu_unfold_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1382 GeanyDocument
*doc
= document_get_current();
1383 g_return_if_fail(doc
!= NULL
);
1385 editor_unfold_all(doc
->editor
);
1389 G_MODULE_EXPORT
void on_toolbutton_run_clicked(GtkAction
*action
, gpointer user_data
)
1391 keybindings_send_command(GEANY_KEY_GROUP_BUILD
, GEANY_KEYS_BUILD_RUN
);
1395 G_MODULE_EXPORT
void on_menu_remove_indicators1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1397 GeanyDocument
*doc
= document_get_current();
1398 g_return_if_fail(doc
!= NULL
);
1400 editor_indicator_clear(doc
->editor
, GEANY_INDICATOR_ERROR
);
1404 G_MODULE_EXPORT
void on_print1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1406 GeanyDocument
*doc
= document_get_current();
1407 g_return_if_fail(doc
!= NULL
);
1409 printing_print_doc(doc
);
1413 G_MODULE_EXPORT
void on_menu_select_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1415 GeanyDocument
*doc
= document_get_current();
1416 g_return_if_fail(doc
!= NULL
);
1418 sci_select_all(doc
->editor
->sci
);
1422 G_MODULE_EXPORT
void on_menu_show_sidebar1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
1424 if (ignore_callback
)
1427 ui_prefs
.sidebar_visible
= ! ui_prefs
.sidebar_visible
;
1429 /* show built-in tabs if no tabs visible */
1430 if (ui_prefs
.sidebar_visible
&&
1431 ! interface_prefs
.sidebar_openfiles_visible
&& ! interface_prefs
.sidebar_symbol_visible
&&
1432 gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets
.sidebar_notebook
)) <= 2)
1434 interface_prefs
.sidebar_openfiles_visible
= TRUE
;
1435 interface_prefs
.sidebar_symbol_visible
= TRUE
;
1438 /* if window has input focus, set it back to the editor before toggling off */
1439 if (! ui_prefs
.sidebar_visible
&&
1440 gtk_container_get_focus_child(GTK_CONTAINER(main_widgets
.sidebar_notebook
)) != NULL
)
1442 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
1445 ui_sidebar_show_hide();
1449 G_MODULE_EXPORT
void on_menu_write_unicode_bom1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
1451 if (! ignore_callback
)
1453 GeanyDocument
*doc
= document_get_current();
1455 g_return_if_fail(doc
!= NULL
);
1462 document_undo_add(doc
, UNDO_BOM
, GINT_TO_POINTER(doc
->has_bom
));
1464 doc
->has_bom
= ! doc
->has_bom
;
1466 ui_update_statusbar(doc
, -1);
1471 G_MODULE_EXPORT
void on_menu_comment_line1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1473 GeanyDocument
*doc
= document_get_current();
1474 g_return_if_fail(doc
!= NULL
);
1476 editor_do_comment(doc
->editor
, -1, FALSE
, FALSE
, TRUE
);
1480 G_MODULE_EXPORT
void on_menu_uncomment_line1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1482 GeanyDocument
*doc
= document_get_current();
1483 g_return_if_fail(doc
!= NULL
);
1485 editor_do_uncomment(doc
->editor
, -1, FALSE
);
1489 G_MODULE_EXPORT
void on_menu_toggle_line_commentation1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1491 GeanyDocument
*doc
= document_get_current();
1492 g_return_if_fail(doc
!= NULL
);
1494 editor_do_comment_toggle(doc
->editor
);
1498 G_MODULE_EXPORT
void on_menu_increase_indent1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1500 GeanyDocument
*doc
= document_get_current();
1501 g_return_if_fail(doc
!= NULL
);
1503 editor_indent(doc
->editor
, TRUE
);
1507 G_MODULE_EXPORT
void on_menu_decrease_indent1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1509 GeanyDocument
*doc
= document_get_current();
1510 g_return_if_fail(doc
!= NULL
);
1512 editor_indent(doc
->editor
, FALSE
);
1516 G_MODULE_EXPORT
void on_next_message1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1518 if (! ui_tree_view_find_next(GTK_TREE_VIEW(msgwindow
.tree_msg
),
1519 msgwin_goto_messages_file_line
))
1520 ui_set_statusbar(FALSE
, _("No more message items."));
1524 G_MODULE_EXPORT
void on_previous_message1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1526 if (! ui_tree_view_find_previous(GTK_TREE_VIEW(msgwindow
.tree_msg
),
1527 msgwin_goto_messages_file_line
))
1528 ui_set_statusbar(FALSE
, _("No more message items."));
1532 G_MODULE_EXPORT
void on_menu_comments_multiline_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1534 insert_callback_from_menu
= TRUE
;
1535 on_comments_multiline_activate(menuitem
, user_data
);
1539 G_MODULE_EXPORT
void on_menu_comments_gpl_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1541 insert_callback_from_menu
= TRUE
;
1542 on_comments_gpl_activate(menuitem
, user_data
);
1546 G_MODULE_EXPORT
void on_menu_comments_bsd_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1548 insert_callback_from_menu
= TRUE
;
1549 on_comments_bsd_activate(menuitem
, user_data
);
1553 G_MODULE_EXPORT
void on_menu_insert_include_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1555 insert_callback_from_menu
= TRUE
;
1556 on_insert_include_activate(menuitem
, user_data
);
1560 G_MODULE_EXPORT
void on_menu_insert_date_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1562 insert_callback_from_menu
= TRUE
;
1563 on_insert_date_activate(menuitem
, user_data
);
1567 G_MODULE_EXPORT
void on_project_new1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1573 G_MODULE_EXPORT
void on_project_open1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1579 G_MODULE_EXPORT
void on_project_close1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1581 project_close(TRUE
);
1585 G_MODULE_EXPORT
void on_project_properties1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1587 project_properties();
1591 G_MODULE_EXPORT
void on_menu_project1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1593 static GtkWidget
*item_close
= NULL
;
1594 static GtkWidget
*item_properties
= NULL
;
1596 if (item_close
== NULL
)
1598 item_close
= ui_lookup_widget(main_widgets
.window
, "project_close1");
1599 item_properties
= ui_lookup_widget(main_widgets
.window
, "project_properties1");
1602 gtk_widget_set_sensitive(item_close
, (app
->project
!= NULL
));
1603 gtk_widget_set_sensitive(item_properties
, (app
->project
!= NULL
));
1604 gtk_widget_set_sensitive(ui_widgets
.recent_projects_menuitem
,
1605 g_queue_get_length(ui_prefs
.recent_projects_queue
) > 0);
1609 G_MODULE_EXPORT
void on_menu_open_selected_file1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1611 GeanyDocument
*doc
= document_get_current();
1616 wc
= GEANY_WORDCHARS
"./-" "\\";
1618 wc
= GEANY_WORDCHARS
"./-";
1621 g_return_if_fail(doc
!= NULL
);
1623 sel
= editor_get_default_selection(doc
->editor
, TRUE
, wc
);
1624 SETPTR(sel
, utils_get_locale_from_utf8(sel
));
1628 gchar
*filename
= NULL
;
1630 if (g_path_is_absolute(sel
))
1631 filename
= g_strdup(sel
);
1633 { /* relative filename, add the path of the current file */
1636 path
= utils_get_current_file_dir_utf8();
1637 SETPTR(path
, utils_get_locale_from_utf8(path
));
1639 path
= g_get_current_dir();
1641 filename
= g_build_path(G_DIR_SEPARATOR_S
, path
, sel
, NULL
);
1643 if (! g_file_test(filename
, G_FILE_TEST_EXISTS
) &&
1644 app
->project
!= NULL
&& !EMPTY(app
->project
->base_path
))
1646 /* try the project's base path */
1647 SETPTR(path
, project_get_base_path());
1648 SETPTR(path
, utils_get_locale_from_utf8(path
));
1649 SETPTR(filename
, g_build_path(G_DIR_SEPARATOR_S
, path
, sel
, NULL
));
1653 if (! g_file_test(filename
, G_FILE_TEST_EXISTS
))
1654 SETPTR(filename
, g_build_path(G_DIR_SEPARATOR_S
, "/usr/local/include", sel
, NULL
));
1656 if (! g_file_test(filename
, G_FILE_TEST_EXISTS
))
1657 SETPTR(filename
, g_build_path(G_DIR_SEPARATOR_S
, "/usr/include", sel
, NULL
));
1661 if (g_file_test(filename
, G_FILE_TEST_EXISTS
))
1662 document_open_file(filename
, FALSE
, NULL
, NULL
);
1665 SETPTR(sel
, utils_get_utf8_from_locale(sel
));
1666 ui_set_statusbar(TRUE
, _("Could not open file %s (File not found)"), sel
);
1675 G_MODULE_EXPORT
void on_remove_markers1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1677 GeanyDocument
*doc
= document_get_current();
1678 g_return_if_fail(doc
!= NULL
);
1680 sci_marker_delete_all(doc
->editor
->sci
, 0); /* delete the yellow tag marker */
1681 sci_marker_delete_all(doc
->editor
->sci
, 1); /* delete user markers */
1682 editor_indicator_clear(doc
->editor
, GEANY_INDICATOR_SEARCH
);
1686 G_MODULE_EXPORT
void on_load_tags1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1688 symbols_show_load_tags_dialog();
1692 G_MODULE_EXPORT
void on_context_action1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1694 gchar
*word
, *command
;
1695 GError
*error
= NULL
;
1696 GeanyDocument
*doc
= document_get_current();
1698 g_return_if_fail(doc
!= NULL
);
1700 if (sci_has_selection(doc
->editor
->sci
))
1701 { /* take selected text if there is a selection */
1702 word
= sci_get_selection_contents(doc
->editor
->sci
);
1706 word
= g_strdup(editor_info
.current_word
);
1709 /* use the filetype specific command if available, fallback to global command otherwise */
1710 if (doc
->file_type
!= NULL
&&
1711 !EMPTY(doc
->file_type
->context_action_cmd
))
1713 command
= g_strdup(doc
->file_type
->context_action_cmd
);
1717 command
= g_strdup(tool_prefs
.context_action_cmd
);
1720 /* substitute the wildcard %s and run the command if it is non empty */
1721 if (G_LIKELY(!EMPTY(command
)))
1723 utils_str_replace_all(&command
, "%s", word
);
1725 if (! g_spawn_command_line_async(command
, &error
))
1727 ui_set_statusbar(TRUE
, "Context action command failed: %s", error
->message
);
1728 g_error_free(error
);
1736 G_MODULE_EXPORT
void on_menu_toggle_all_additional_widgets1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1738 static gint hide_all
= -1;
1739 GtkCheckMenuItem
*msgw
= GTK_CHECK_MENU_ITEM(
1740 ui_lookup_widget(main_widgets
.window
, "menu_show_messages_window1"));
1741 GtkCheckMenuItem
*toolbari
= GTK_CHECK_MENU_ITEM(
1742 ui_lookup_widget(main_widgets
.window
, "menu_show_toolbar1"));
1744 /* get the initial state (necessary if Geany was closed with hide_all = TRUE) */
1745 if (G_UNLIKELY(hide_all
== -1))
1747 if (! gtk_check_menu_item_get_active(msgw
) &&
1748 ! interface_prefs
.show_notebook_tabs
&&
1749 ! gtk_check_menu_item_get_active(toolbari
))
1757 hide_all
= ! hide_all
; /* toggle */
1761 if (gtk_check_menu_item_get_active(msgw
))
1762 gtk_check_menu_item_set_active(msgw
, ! gtk_check_menu_item_get_active(msgw
));
1764 interface_prefs
.show_notebook_tabs
= FALSE
;
1765 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets
.notebook
), interface_prefs
.show_notebook_tabs
);
1767 ui_statusbar_showhide(FALSE
);
1769 if (gtk_check_menu_item_get_active(toolbari
))
1770 gtk_check_menu_item_set_active(toolbari
, ! gtk_check_menu_item_get_active(toolbari
));
1775 if (! gtk_check_menu_item_get_active(msgw
))
1776 gtk_check_menu_item_set_active(msgw
, ! gtk_check_menu_item_get_active(msgw
));
1778 interface_prefs
.show_notebook_tabs
= TRUE
;
1779 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets
.notebook
), interface_prefs
.show_notebook_tabs
);
1781 ui_statusbar_showhide(TRUE
);
1783 if (! gtk_check_menu_item_get_active(toolbari
))
1784 gtk_check_menu_item_set_active(toolbari
, ! gtk_check_menu_item_get_active(toolbari
));
1789 G_MODULE_EXPORT
void on_forward_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1791 navqueue_go_forward();
1795 G_MODULE_EXPORT
void on_back_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1801 G_MODULE_EXPORT gboolean
on_motion_event(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
)
1803 if (prefs
.auto_focus
&& ! gtk_widget_has_focus(widget
))
1804 gtk_widget_grab_focus(widget
);
1810 static void set_indent_type(GtkCheckMenuItem
*menuitem
, GeanyIndentType type
)
1814 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
1817 doc
= document_get_current();
1818 g_return_if_fail(doc
!= NULL
);
1820 editor_set_indent(doc
->editor
, type
, doc
->editor
->indent_width
);
1821 ui_update_statusbar(doc
, -1);
1825 G_MODULE_EXPORT
void on_tabs1_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
1827 set_indent_type(menuitem
, GEANY_INDENT_TYPE_TABS
);
1831 G_MODULE_EXPORT
void on_spaces1_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
1833 set_indent_type(menuitem
, GEANY_INDENT_TYPE_SPACES
);
1837 G_MODULE_EXPORT
void on_tabs_and_spaces1_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
1839 set_indent_type(menuitem
, GEANY_INDENT_TYPE_BOTH
);
1843 G_MODULE_EXPORT
void on_strip_trailing_spaces1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1847 if (ignore_callback
)
1850 doc
= document_get_current();
1851 g_return_if_fail(doc
!= NULL
);
1853 editor_strip_trailing_spaces(doc
->editor
);
1857 G_MODULE_EXPORT
void on_page_setup1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1859 printing_page_setup_gtk();
1863 G_MODULE_EXPORT gboolean
on_escape_key_press_event(GtkWidget
*widget
, GdkEventKey
*event
, gpointer user_data
)
1865 guint state
= event
->state
& gtk_accelerator_get_default_mod_mask();
1867 /* make pressing escape in the sidebar and toolbar focus the editor */
1868 if (event
->keyval
== GDK_Escape
&& state
== 0)
1870 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
1877 G_MODULE_EXPORT
void on_line_breaking1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1881 if (ignore_callback
)
1884 doc
= document_get_current();
1885 g_return_if_fail(doc
!= NULL
);
1887 doc
->editor
->line_breaking
= !doc
->editor
->line_breaking
;
1891 G_MODULE_EXPORT
void on_replace_spaces_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1893 GeanyDocument
*doc
= document_get_current();
1895 g_return_if_fail(doc
!= NULL
);
1897 editor_replace_spaces(doc
->editor
);
1901 G_MODULE_EXPORT
void on_search1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1903 GtkWidget
*next_message
= ui_lookup_widget(main_widgets
.window
, "next_message1");
1904 GtkWidget
*previous_message
= ui_lookup_widget(main_widgets
.window
, "previous_message1");
1905 gboolean have_messages
;
1907 /* enable commands if the messages window has any items */
1908 have_messages
= gtk_tree_model_iter_n_children(GTK_TREE_MODEL(msgwindow
.store_msg
),
1911 gtk_widget_set_sensitive(next_message
, have_messages
);
1912 gtk_widget_set_sensitive(previous_message
, have_messages
);
1916 /* simple implementation (vs. close all which doesn't close documents if cancelled),
1917 * if user_data is set, it is the GeanyDocument to keep */
1918 G_MODULE_EXPORT
void on_close_other_documents1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1921 GeanyDocument
*cur_doc
= user_data
;
1923 if (cur_doc
== NULL
)
1924 cur_doc
= document_get_current();
1926 for (i
= 0; i
< documents_array
->len
; i
++)
1928 GeanyDocument
*doc
= documents
[i
];
1930 if (doc
== cur_doc
|| ! doc
->is_valid
)
1933 if (! document_close(doc
))
1939 G_MODULE_EXPORT
void on_menu_reload_configuration1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1941 main_reload_configuration();
1945 G_MODULE_EXPORT
void on_debug_messages1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1947 log_show_debug_messages_dialog();
1951 G_MODULE_EXPORT
void on_send_selection_to_vte1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1954 if (vte_info
.have_vte
)
1955 vte_send_selection_to_vte();
1960 G_MODULE_EXPORT gboolean
on_window_state_event(GtkWidget
*widget
, GdkEventWindowState
*event
, gpointer user_data
)
1963 if (event
->changed_mask
& GDK_WINDOW_STATE_FULLSCREEN
)
1965 static GtkWidget
*menuitem
= NULL
;
1967 if (menuitem
== NULL
)
1968 menuitem
= ui_lookup_widget(widget
, "menu_fullscreen1");
1970 ignore_callback
= TRUE
;
1972 ui_prefs
.fullscreen
= (event
->new_window_state
& GDK_WINDOW_STATE_FULLSCREEN
) ? TRUE
: FALSE
;
1973 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem
), ui_prefs
.fullscreen
);
1975 ignore_callback
= FALSE
;
1981 static void show_notebook_page(const gchar
*notebook_name
, const gchar
*page_name
)
1984 GtkNotebook
*notebook
;
1986 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, page_name
);
1987 notebook
= GTK_NOTEBOOK(ui_lookup_widget(ui_widgets
.prefs_dialog
, notebook_name
));
1989 if (notebook
!= NULL
&& widget
!= NULL
)
1990 gtk_notebook_set_current_page(notebook
, gtk_notebook_page_num(notebook
, widget
));
1994 G_MODULE_EXPORT
void on_customize_toolbar1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1996 prefs_show_dialog();
1998 /* select the Interface page */
1999 show_notebook_page("notebook2", "notebook6");
2000 /* select the Toolbar subpage */
2001 show_notebook_page("notebook6", "vbox15");
2005 G_MODULE_EXPORT
void on_button_customize_toolbar_clicked(GtkButton
*button
, gpointer user_data
)
2007 toolbar_configure(GTK_WINDOW(ui_widgets
.prefs_dialog
));
2011 G_MODULE_EXPORT
void on_cut_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2013 keybindings_send_command(GEANY_KEY_GROUP_CLIPBOARD
, GEANY_KEYS_CLIPBOARD_CUTLINE
);
2017 G_MODULE_EXPORT
void on_copy_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2019 keybindings_send_command(GEANY_KEY_GROUP_CLIPBOARD
, GEANY_KEYS_CLIPBOARD_COPYLINE
);
2023 G_MODULE_EXPORT
void on_delete_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2025 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_DELETELINE
);
2029 G_MODULE_EXPORT
void on_duplicate_line_or_selection1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2031 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_DUPLICATELINE
);
2035 G_MODULE_EXPORT
void on_select_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2037 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_LINE
);
2041 G_MODULE_EXPORT
void on_select_current_paragraph1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2043 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_PARAGRAPH
);
2047 G_MODULE_EXPORT
void on_insert_alternative_white_space1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2049 keybindings_send_command(GEANY_KEY_GROUP_INSERT
, GEANY_KEYS_INSERT_ALTWHITESPACE
);
2053 G_MODULE_EXPORT
void on_go_to_next_marker1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2055 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_NEXTMARKER
);
2059 G_MODULE_EXPORT
void on_go_to_previous_marker1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2061 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_PREVIOUSMARKER
);
2065 G_MODULE_EXPORT
void on_reflow_lines_block1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2067 keybindings_send_command(GEANY_KEY_GROUP_FORMAT
, GEANY_KEYS_FORMAT_REFLOWPARAGRAPH
);
2071 G_MODULE_EXPORT
void on_move_lines_up1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2073 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_MOVELINEUP
);
2077 G_MODULE_EXPORT
void on_move_lines_down1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2079 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_MOVELINEDOWN
);
2083 G_MODULE_EXPORT
void on_smart_line_indent1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2085 keybindings_send_command(GEANY_KEY_GROUP_FORMAT
, GEANY_KEYS_FORMAT_AUTOINDENT
);
2089 G_MODULE_EXPORT
void on_plugin_preferences1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2092 plugin_show_configure(NULL
);
2097 G_MODULE_EXPORT
void on_indent_width_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2103 if (ignore_callback
)
2106 label
= ui_menu_item_get_text(menuitem
);
2107 width
= atoi(label
);
2110 doc
= document_get_current();
2111 if (doc
!= NULL
&& width
> 0)
2112 editor_set_indent_width(doc
->editor
, width
);
2116 G_MODULE_EXPORT
void on_reset_indentation1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2121 document_apply_indent_settings(documents
[i
]);
2123 ui_update_statusbar(NULL
, -1);
2124 ui_document_show_hide(NULL
);
2128 G_MODULE_EXPORT
void on_mark_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2130 keybindings_send_command(GEANY_KEY_GROUP_SEARCH
, GEANY_KEYS_SEARCH_MARKALL
);
2134 G_MODULE_EXPORT
void on_detect_type_from_file_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2136 GeanyDocument
*doc
= document_get_current();
2137 GeanyIndentType type
;
2139 if (doc
!= NULL
&& document_detect_indent_type(doc
, &type
))
2141 editor_set_indent_type(doc
->editor
, type
);
2142 ui_document_show_hide(doc
);
2147 G_MODULE_EXPORT
void on_detect_width_from_file_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
2149 GeanyDocument
*doc
= document_get_current();
2152 if (doc
!= NULL
&& document_detect_indent_width(doc
, &width
))
2154 editor_set_indent_width(doc
->editor
, width
);
2155 ui_document_show_hide(doc
);