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 /* represents the state at switching a notebook page(in the left treeviews widget), to not emit
77 * the selection-changed signal from tv.tree_openfiles */
78 /*static gboolean switch_tv_notebook_page = FALSE; */
82 /* wrapper function to abort exit process if cancel button is pressed */
83 static gboolean
on_window_delete_event(GtkWidget
*widget
, GdkEvent
*event
, gpointer gdata
)
93 void on_new1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
95 document_new_file(NULL
, NULL
, NULL
);
99 /* create a new file and copy file content and properties */
100 static void on_clone1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
102 GeanyDocument
*old_doc
= document_get_current();
105 document_clone(old_doc
);
109 void on_save1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
111 GeanyDocument
*doc
= document_get_current();
115 document_save_file(doc
, ui_prefs
.allow_always_save
);
120 void on_save_as1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
122 dialogs_show_save_as();
126 void on_save_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
128 guint i
, max
= (guint
) gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets
.notebook
));
129 GeanyDocument
*doc
, *cur_doc
= document_get_current();
132 /* iterate over documents in tabs order */
133 for (i
= 0; i
< max
; i
++)
135 doc
= document_get_from_page(i
);
139 if (document_save_file(doc
, FALSE
))
145 ui_set_statusbar(FALSE
, ngettext("%d file saved.", "%d files saved.", count
), count
);
146 /* saving may have changed window title, sidebar for another doc, so update */
147 document_show_tab(cur_doc
);
148 sidebar_update_tag_list(cur_doc
, TRUE
);
149 ui_set_window_title(cur_doc
);
153 void on_close_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
155 document_close_all();
159 void on_close1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
161 GeanyDocument
*doc
= document_get_current();
168 void on_quit1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
174 static void on_file1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
176 gtk_widget_set_sensitive(ui_widgets
.recent_files_menuitem
,
177 g_queue_get_length(ui_prefs
.recent_queue
) > 0);
178 /* hide Page setup when GTK printing is not used */
179 ui_widget_show_hide(ui_widgets
.print_page_setup
, printing_prefs
.use_gtk_printing
);
183 /* edit actions, c&p & co, from menu bar and from popup menu */
184 static void on_edit1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
187 GeanyDocument
*doc
= document_get_current();
189 ui_update_menu_copy_items(doc
);
190 ui_update_insert_include_item(doc
, 1);
192 item
= ui_lookup_widget(main_widgets
.window
, "plugin_preferences1");
194 gtk_widget_hide(item
);
196 gtk_widget_set_sensitive(item
, plugins_have_preferences());
201 void on_undo1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
203 GeanyDocument
*doc
= document_get_current();
205 g_return_if_fail(doc
!= NULL
);
207 if (document_can_undo(doc
))
209 sci_cancel(doc
->editor
->sci
);
215 void on_redo1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
217 GeanyDocument
*doc
= document_get_current();
219 g_return_if_fail(doc
!= NULL
);
221 if (document_can_redo(doc
))
223 sci_cancel(doc
->editor
->sci
);
229 void on_cut1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
231 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
233 if (GTK_IS_EDITABLE(focusw
))
234 gtk_editable_cut_clipboard(GTK_EDITABLE(focusw
));
235 else if (IS_SCINTILLA(focusw
))
236 sci_cut(SCINTILLA(focusw
));
237 else if (GTK_IS_TEXT_VIEW(focusw
))
239 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(
240 GTK_TEXT_VIEW(focusw
));
241 gtk_text_buffer_cut_clipboard(buffer
, gtk_clipboard_get(GDK_NONE
), TRUE
);
246 void on_copy1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
248 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
250 if (GTK_IS_EDITABLE(focusw
))
251 gtk_editable_copy_clipboard(GTK_EDITABLE(focusw
));
252 else if (IS_SCINTILLA(focusw
))
253 sci_copy(SCINTILLA(focusw
));
254 else if (GTK_IS_TEXT_VIEW(focusw
))
256 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(
257 GTK_TEXT_VIEW(focusw
));
258 gtk_text_buffer_copy_clipboard(buffer
, gtk_clipboard_get(GDK_NONE
));
263 void on_paste1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
265 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
267 if (GTK_IS_EDITABLE(focusw
))
268 gtk_editable_paste_clipboard(GTK_EDITABLE(focusw
));
269 else if (IS_SCINTILLA(focusw
))
270 sci_paste(SCINTILLA(focusw
));
271 else if (GTK_IS_TEXT_VIEW(focusw
))
273 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(
274 GTK_TEXT_VIEW(focusw
));
275 gtk_text_buffer_paste_clipboard(buffer
, gtk_clipboard_get(GDK_NONE
), NULL
,
281 void on_delete1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
283 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
285 if (GTK_IS_EDITABLE(focusw
))
286 gtk_editable_delete_selection(GTK_EDITABLE(focusw
));
287 else if (IS_SCINTILLA(focusw
) && sci_has_selection(SCINTILLA(focusw
)))
288 sci_clear(SCINTILLA(focusw
));
289 else if (GTK_IS_TEXT_VIEW(focusw
))
291 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(
292 GTK_TEXT_VIEW(focusw
));
293 gtk_text_buffer_delete_selection(buffer
, TRUE
, TRUE
);
298 void on_preferences1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
304 /* about menu item */
305 static void on_info1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
312 void on_open1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
314 dialogs_show_open_file();
319 void on_toolbutton_reload_clicked(GtkAction
*action
, gpointer user_data
)
321 GeanyDocument
*doc
= document_get_current();
323 g_return_if_fail(doc
!= NULL
);
325 document_reload_prompt(doc
, NULL
);
329 static void on_change_font1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
331 dialogs_show_open_font();
335 /* store text, clear search flags so we can use Search->Find Next/Previous */
336 static void setup_find(const gchar
*text
, gboolean backwards
)
338 SETPTR(search_data
.text
, g_strdup(text
));
339 SETPTR(search_data
.original_text
, g_strdup(text
));
340 search_data
.flags
= 0;
341 search_data
.backwards
= backwards
;
342 search_data
.search_bar
= TRUE
;
346 static void do_toolbar_search(const gchar
*text
, gboolean incremental
, gboolean backwards
)
348 GeanyDocument
*doc
= document_get_current();
351 setup_find(text
, backwards
);
352 result
= document_search_bar_find(doc
, search_data
.text
, incremental
, backwards
);
353 if (search_data
.search_bar
)
354 ui_set_search_entry_background(toolbar_get_widget_child_by_name("SearchEntry"), result
);
359 void on_toolbar_search_entry_changed(GtkAction
*action
, const gchar
*text
, gpointer user_data
)
361 do_toolbar_search(text
, TRUE
, FALSE
);
366 void on_toolbar_search_entry_activate(GtkAction
*action
, const gchar
*text
, gpointer user_data
)
368 do_toolbar_search(text
, FALSE
, GPOINTER_TO_INT(user_data
));
373 void on_toolbutton_search_clicked(GtkAction
*action
, gpointer user_data
)
375 GeanyDocument
*doc
= document_get_current();
377 GtkWidget
*entry
= toolbar_get_widget_child_by_name("SearchEntry");
381 const gchar
*text
= gtk_entry_get_text(GTK_ENTRY(entry
));
383 setup_find(text
, FALSE
);
384 result
= document_search_bar_find(doc
, search_data
.text
, FALSE
, FALSE
);
385 if (search_data
.search_bar
)
386 ui_set_search_entry_background(entry
, result
);
389 on_find1_activate(NULL
, NULL
);
393 /* hides toolbar from toolbar popup menu */
394 static void on_hide_toolbar1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
396 GtkWidget
*tool_item
= ui_lookup_widget(GTK_WIDGET(main_widgets
.window
), "menu_show_toolbar1");
397 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(tool_item
), FALSE
);
401 /* zoom in from menu bar and popup menu */
402 void on_zoom_in1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
404 GeanyDocument
*doc
= document_get_current();
406 g_return_if_fail(doc
!= NULL
);
408 sci_zoom_in(doc
->editor
->sci
);
412 /* zoom out from menu bar and popup menu */
413 void on_zoom_out1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
415 GeanyDocument
*doc
= document_get_current();
417 g_return_if_fail(doc
!= NULL
);
419 sci_zoom_out(doc
->editor
->sci
);
423 void on_normal_size1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
425 GeanyDocument
*doc
= document_get_current();
427 g_return_if_fail(doc
!= NULL
);
429 sci_zoom_off(doc
->editor
->sci
);
433 static gboolean
delayed_check_disk_status(gpointer data
)
435 document_check_disk_status(data
, FALSE
);
440 /* Changes window-title after switching tabs and lots of other things.
441 * note: using 'after' makes Scintilla redraw before the UI, appearing more responsive */
442 static void on_notebook1_switch_page_after(GtkNotebook
*notebook
, gpointer page
,
443 guint page_num
, gpointer user_data
)
447 if (G_UNLIKELY(main_status
.opening_session_files
|| main_status
.closing_all
))
450 doc
= document_get_from_notebook_child(page
);
454 sidebar_select_openfiles_item(doc
);
455 ui_save_buttons_toggle(doc
->changed
);
456 ui_set_window_title(doc
);
457 ui_update_statusbar(doc
, -1);
458 ui_update_popup_reundo_items(doc
);
459 ui_document_show_hide(doc
); /* update the document menu */
460 build_menu_update(doc
);
461 sidebar_update_tag_list(doc
, FALSE
);
462 document_highlight_tags(doc
);
464 /* We delay the check to avoid weird fast, unintended switching of notebook pages when
465 * the 'file has changed' dialog is shown while the switch event is not yet completely
466 * finished. So, we check after the switch has been performed to be safe. */
467 g_idle_add(delayed_check_disk_status
, doc
);
470 vte_cwd((doc
->real_path
!= NULL
) ? doc
->real_path
: doc
->file_name
, FALSE
);
473 g_signal_emit_by_name(geany_object
, "document-activate", doc
);
478 static void on_tv_notebook_switch_page(GtkNotebook
*notebook
, gpointer page
,
479 guint page_num
, gpointer user_data
)
481 /* suppress selection changed signal when switching to the open files list */
482 ignore_callback
= TRUE
;
486 static void on_tv_notebook_switch_page_after(GtkNotebook
*notebook
, gpointer page
,
487 guint page_num
, gpointer user_data
)
489 ignore_callback
= FALSE
;
493 static void convert_eol(gint mode
)
495 GeanyDocument
*doc
= document_get_current();
497 g_return_if_fail(doc
!= NULL
);
499 sci_convert_eols(doc
->editor
->sci
, mode
);
500 sci_set_eol_mode(doc
->editor
->sci
, mode
);
501 ui_update_statusbar(doc
, -1);
505 static void on_crlf_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
507 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
510 convert_eol(SC_EOL_CRLF
);
514 static void on_lf_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
516 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
519 convert_eol(SC_EOL_LF
);
523 static void on_cr_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
525 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
528 convert_eol(SC_EOL_CR
);
532 void on_replace_tabs_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
534 GeanyDocument
*doc
= document_get_current();
536 g_return_if_fail(doc
!= NULL
);
538 editor_replace_tabs(doc
->editor
);
542 gboolean
toolbar_popup_menu(GtkWidget
*widget
, GdkEventButton
*event
, gpointer user_data
)
544 if (event
->button
== 3)
546 gtk_menu_popup(GTK_MENU(ui_widgets
.toolbar_menu
), NULL
, NULL
, NULL
, NULL
, event
->button
, event
->time
);
553 void on_toggle_case1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
555 GeanyDocument
*doc
= document_get_current();
556 ScintillaObject
*sci
;
558 gboolean keep_sel
= TRUE
;
560 g_return_if_fail(doc
!= NULL
);
562 sci
= doc
->editor
->sci
;
563 if (! sci_has_selection(sci
))
565 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_WORD
);
569 /* either we already had a selection or we created one for current word */
570 if (sci_has_selection(sci
))
572 gchar
*result
= NULL
;
573 gint cmd
= SCI_LOWERCASE
;
574 gboolean rectsel
= (gboolean
) scintilla_send_message(sci
, SCI_SELECTIONISRECTANGLE
, 0, 0);
576 text
= sci_get_selection_contents(sci
);
578 if (utils_str_has_upper(text
))
583 result
= g_utf8_strdown(text
, -1);
590 result
= g_utf8_strup(text
, -1);
595 sci_replace_sel(sci
, result
);
598 sci_set_selection_start(sci
, sci_get_current_position(sci
) - strlen(text
));
601 sci_send_command(sci
, cmd
);
609 static void on_show_toolbar1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
611 if (ignore_callback
) return;
613 toolbar_prefs
.visible
= (toolbar_prefs
.visible
) ? FALSE
: TRUE
;;
614 ui_widget_show_hide(GTK_WIDGET(main_widgets
.toolbar
), toolbar_prefs
.visible
);
618 static void on_fullscreen1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
623 ui_prefs
.fullscreen
= (ui_prefs
.fullscreen
) ? FALSE
: TRUE
;
628 static void on_show_messages_window1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
633 ui_prefs
.msgwindow_visible
= (ui_prefs
.msgwindow_visible
) ? FALSE
: TRUE
;
634 msgwin_show_hide(ui_prefs
.msgwindow_visible
);
638 static void on_menu_color_schemes_activate(GtkImageMenuItem
*imagemenuitem
, gpointer user_data
)
640 highlighting_show_color_scheme_dialog();
644 static void on_markers_margin1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
649 editor_prefs
.show_markers_margin
= ! editor_prefs
.show_markers_margin
;
650 ui_toggle_editor_features(GEANY_EDITOR_SHOW_MARKERS_MARGIN
);
654 static void on_show_line_numbers1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
659 editor_prefs
.show_linenumber_margin
= ! editor_prefs
.show_linenumber_margin
;
660 ui_toggle_editor_features(GEANY_EDITOR_SHOW_LINE_NUMBERS
);
664 static void on_menu_show_white_space1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
669 editor_prefs
.show_white_space
= ! editor_prefs
.show_white_space
;
670 ui_toggle_editor_features(GEANY_EDITOR_SHOW_WHITE_SPACE
);
674 static void on_menu_show_line_endings1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
679 editor_prefs
.show_line_endings
= ! editor_prefs
.show_line_endings
;
680 ui_toggle_editor_features(GEANY_EDITOR_SHOW_LINE_ENDINGS
);
684 static void on_menu_show_indentation_guides1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
689 editor_prefs
.show_indent_guide
= ! editor_prefs
.show_indent_guide
;
690 ui_toggle_editor_features(GEANY_EDITOR_SHOW_INDENTATION_GUIDES
);
694 void on_line_wrapping1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
696 if (! ignore_callback
)
698 GeanyDocument
*doc
= document_get_current();
699 g_return_if_fail(doc
!= NULL
);
701 editor_set_line_wrapping(doc
->editor
, ! doc
->editor
->line_wrapping
);
706 static void on_set_file_readonly1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
708 if (! ignore_callback
)
710 GeanyDocument
*doc
= document_get_current();
711 g_return_if_fail(doc
!= NULL
);
713 doc
->readonly
= ! doc
->readonly
;
714 sci_set_readonly(doc
->editor
->sci
, doc
->readonly
);
715 ui_update_tab_status(doc
);
716 ui_update_statusbar(doc
, -1);
721 static void on_use_auto_indentation1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
723 if (! ignore_callback
)
725 GeanyDocument
*doc
= document_get_current();
726 g_return_if_fail(doc
!= NULL
);
728 doc
->editor
->auto_indent
= ! doc
->editor
->auto_indent
;
733 static void find_usage(gboolean in_session
)
735 GeanyFindFlags flags
;
737 GeanyDocument
*doc
= document_get_current();
739 g_return_if_fail(doc
!= NULL
);
741 if (sci_has_selection(doc
->editor
->sci
))
742 { /* take selected text if there is a selection */
743 search_text
= sci_get_selection_contents(doc
->editor
->sci
);
744 flags
= GEANY_FIND_MATCHCASE
;
748 editor_find_current_word_sciwc(doc
->editor
, -1,
749 editor_info
.current_word
, GEANY_MAX_WORD_LENGTH
);
750 search_text
= g_strdup(editor_info
.current_word
);
751 flags
= GEANY_FIND_MATCHCASE
| GEANY_FIND_WHOLEWORD
;
754 search_find_usage(search_text
, search_text
, flags
, in_session
);
759 void on_find_document_usage1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
765 void on_find_usage1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
771 static void goto_tag(gboolean definition
)
773 GeanyDocument
*doc
= document_get_current();
775 g_return_if_fail(doc
!= NULL
);
777 /* update cursor pos for navigating back afterwards */
778 if (!sci_has_selection(doc
->editor
->sci
))
779 sci_set_current_position(doc
->editor
->sci
, editor_info
.click_pos
, FALSE
);
781 /* use the keybinding callback as it checks for selections as well as current word */
783 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_TAGDEFINITION
);
785 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_TAGDECLARATION
);
789 static void on_goto_tag_definition1(GtkMenuItem
*menuitem
, gpointer user_data
)
795 static void on_goto_tag_declaration1(GtkMenuItem
*menuitem
, gpointer user_data
)
801 static void on_count_words1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
807 void on_show_color_chooser1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
810 GeanyDocument
*doc
= document_get_current();
813 g_return_if_fail(doc
!= NULL
);
815 pos
= sci_get_current_position(doc
->editor
->sci
);
816 editor_find_current_word(doc
->editor
, pos
, colour
, sizeof colour
, GEANY_WORDCHARS
"#");
817 tools_color_chooser(colour
);
821 void on_toolbutton_compile_clicked(GtkAction
*action
, gpointer user_data
)
823 keybindings_send_command(GEANY_KEY_GROUP_BUILD
, GEANY_KEYS_BUILD_COMPILE
);
827 void on_find1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
829 search_show_find_dialog();
833 void on_find_next1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
835 search_find_again(FALSE
);
839 void on_find_previous1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
841 if (search_data
.flags
& GEANY_FIND_REGEXP
)
842 /* Can't reverse search order for a regex (find next ignores search backwards) */
845 search_find_again(TRUE
);
849 void on_find_nextsel1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
851 search_find_selection(document_get_current(), FALSE
);
855 void on_find_prevsel1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
857 search_find_selection(document_get_current(), TRUE
);
861 void on_replace1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
863 search_show_replace_dialog();
867 void on_find_in_files1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
869 search_show_find_in_files_dialog(NULL
);
873 static void get_line_and_offset_from_text(const gchar
*text
, gint
*line_no
, gint
*offset
)
875 if (*text
== '+' || *text
== '-')
877 *line_no
= atoi(text
+ 1);
878 *offset
= (*text
== '+') ? 1 : -1;
882 *line_no
= atoi(text
) - 1;
888 void on_go_to_line_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
890 static gchar value
[16] = "";
893 result
= dialogs_show_input_goto_line(
894 _("Go to Line"), GTK_WINDOW(main_widgets
.window
),
895 _("Enter the line you want to go to:"), value
);
898 GeanyDocument
*doc
= document_get_current();
902 g_return_if_fail(doc
!= NULL
);
904 get_line_and_offset_from_text(result
, &line_no
, &offset
);
905 if (! editor_goto_line(doc
->editor
, line_no
, offset
))
907 /* remember value for future calls */
908 g_snprintf(value
, sizeof(value
), "%s", result
);
915 void on_toolbutton_goto_entry_activate(GtkAction
*action
, const gchar
*text
, gpointer user_data
)
917 GeanyDocument
*doc
= document_get_current();
921 g_return_if_fail(doc
!= NULL
);
923 get_line_and_offset_from_text(text
, &line_no
, &offset
);
924 if (! editor_goto_line(doc
->editor
, line_no
, offset
))
927 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
931 void on_toolbutton_goto_clicked(GtkAction
*action
, gpointer user_data
)
933 GtkWidget
*entry
= toolbar_get_widget_child_by_name("GotoEntry");
937 const gchar
*text
= gtk_entry_get_text(GTK_ENTRY(entry
));
939 on_toolbutton_goto_entry_activate(NULL
, text
, NULL
);
942 on_go_to_line_activate(NULL
, NULL
);
946 void on_help1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
950 uri
= utils_get_help_url(NULL
);
951 utils_open_browser(uri
);
956 static void on_help_shortcuts1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
958 keybindings_show_shortcuts();
962 static void on_website1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
964 utils_open_browser(GEANY_HOMEPAGE
);
968 static void on_help_menu_item_donate_activate(GtkMenuItem
*item
, gpointer user_data
)
970 utils_open_browser(GEANY_DONATE
);
974 static void on_help_menu_item_wiki_activate(GtkMenuItem
*item
, gpointer user_data
)
976 utils_open_browser(GEANY_WIKI
);
980 static void on_help_menu_item_bug_report_activate(GtkMenuItem
*item
, gpointer user_data
)
982 utils_open_browser(GEANY_BUG_REPORT
);
986 static void on_comments_function_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
988 GeanyDocument
*doc
= document_get_current();
990 const gchar
*cur_tag
= NULL
;
991 gint line
= -1, pos
= 0;
993 if (doc
== NULL
|| doc
->file_type
== NULL
)
995 ui_set_statusbar(FALSE
,
996 _("Please set the filetype for the current file before using this function."));
1000 /* symbols_get_current_function returns -1 on failure, so sci_get_position_from_line
1001 * returns the current position, so it should be safe */
1002 line
= symbols_get_current_function(doc
, &cur_tag
);
1003 pos
= sci_get_position_from_line(doc
->editor
->sci
, line
);
1005 text
= templates_get_template_function(doc
, cur_tag
);
1007 sci_start_undo_action(doc
->editor
->sci
);
1008 sci_insert_text(doc
->editor
->sci
, pos
, text
);
1009 sci_end_undo_action(doc
->editor
->sci
);
1014 static void insert_multiline_comment(GeanyDocument
*doc
, gint pos
)
1016 g_return_if_fail(doc
!= NULL
);
1017 g_return_if_fail(pos
== -1 || pos
>= 0);
1019 if (doc
->file_type
== NULL
)
1021 ui_set_statusbar(FALSE
,
1022 _("Please set the filetype for the current file before using this function."));
1026 if (doc
->file_type
->comment_open
|| doc
->file_type
->comment_single
)
1028 /* editor_insert_multiline_comment() uses editor_info.click_pos */
1030 editor_info
.click_pos
= sci_get_current_position(doc
->editor
->sci
);
1032 editor_info
.click_pos
= pos
;
1033 editor_insert_multiline_comment(doc
->editor
);
1040 static void on_comments_multiline_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1042 insert_multiline_comment(document_get_current(), editor_info
.click_pos
);
1046 static void on_menu_comments_multiline_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1048 insert_multiline_comment(document_get_current(), -1);
1052 static void insert_comment_template(GeanyDocument
*doc
, gint pos
, guint
template)
1056 g_return_if_fail(doc
!= NULL
);
1057 g_return_if_fail(pos
== -1 || pos
>= 0);
1058 g_return_if_fail(template < GEANY_MAX_TEMPLATES
);
1061 pos
= sci_get_current_position(doc
->editor
->sci
);
1063 text
= templates_get_template_licence(doc
, template);
1065 sci_start_undo_action(doc
->editor
->sci
);
1066 sci_insert_text(doc
->editor
->sci
, pos
, text
);
1067 sci_end_undo_action(doc
->editor
->sci
);
1072 static void on_comments_gpl_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1074 insert_comment_template(document_get_current(), editor_info
.click_pos
, GEANY_TEMPLATE_GPL
);
1078 static void on_menu_comments_gpl_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1080 insert_comment_template(document_get_current(), -1, GEANY_TEMPLATE_GPL
);
1084 static void on_comments_bsd_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1086 insert_comment_template(document_get_current(), editor_info
.click_pos
, GEANY_TEMPLATE_BSD
);
1090 static void on_menu_comments_bsd_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1092 insert_comment_template(document_get_current(), -1, GEANY_TEMPLATE_BSD
);
1096 static void on_comments_changelog_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1098 GeanyDocument
*doc
= document_get_current();
1101 g_return_if_fail(doc
!= NULL
);
1103 text
= templates_get_template_changelog(doc
);
1104 sci_start_undo_action(doc
->editor
->sci
);
1105 sci_insert_text(doc
->editor
->sci
, 0, text
);
1106 /* sets the cursor to the right position to type the changelog text,
1107 * the template has 21 chars + length of name and email */
1108 sci_goto_pos(doc
->editor
->sci
, 21 + strlen(template_prefs
.developer
) + strlen(template_prefs
.mail
), TRUE
);
1109 sci_end_undo_action(doc
->editor
->sci
);
1115 static void on_comments_fileheader_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1117 GeanyDocument
*doc
= document_get_current();
1122 g_return_if_fail(doc
!= NULL
);
1124 ft
= doc
->file_type
;
1125 fname
= doc
->file_name
;
1126 text
= templates_get_template_fileheader(FILETYPE_ID(ft
), fname
);
1128 sci_start_undo_action(doc
->editor
->sci
);
1129 sci_insert_text(doc
->editor
->sci
, 0, text
);
1130 sci_goto_pos(doc
->editor
->sci
, 0, FALSE
);
1131 sci_end_undo_action(doc
->editor
->sci
);
1136 static void on_file_properties_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1138 GeanyDocument
*doc
= document_get_current();
1139 g_return_if_fail(doc
!= NULL
);
1141 dialogs_show_file_properties(doc
);
1145 static void on_menu_fold_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1147 GeanyDocument
*doc
= document_get_current();
1148 g_return_if_fail(doc
!= NULL
);
1150 editor_fold_all(doc
->editor
);
1154 static void on_menu_unfold_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1156 GeanyDocument
*doc
= document_get_current();
1157 g_return_if_fail(doc
!= NULL
);
1159 editor_unfold_all(doc
->editor
);
1163 void on_toolbutton_run_clicked(GtkAction
*action
, gpointer user_data
)
1165 keybindings_send_command(GEANY_KEY_GROUP_BUILD
, GEANY_KEYS_BUILD_RUN
);
1169 void on_menu_remove_indicators1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1171 GeanyDocument
*doc
= document_get_current();
1172 g_return_if_fail(doc
!= NULL
);
1174 editor_indicator_clear(doc
->editor
, GEANY_INDICATOR_ERROR
);
1178 void on_print1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1180 GeanyDocument
*doc
= document_get_current();
1181 g_return_if_fail(doc
!= NULL
);
1183 printing_print_doc(doc
);
1187 void on_menu_select_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1189 GtkWidget
*focusw
= gtk_window_get_focus(GTK_WINDOW(main_widgets
.window
));
1191 /* special case for Select All in the scribble widget */
1192 if (GTK_IS_TEXT_VIEW(focusw
))
1194 g_signal_emit_by_name(focusw
, "select-all", TRUE
);
1196 /* special case for Select All in the VTE widget */
1198 else if (vte_info
.have_vte
&& focusw
== vc
->vte
)
1203 else if (GTK_IS_EDITABLE(focusw
))
1205 gtk_editable_select_region(GTK_EDITABLE(focusw
), 0, -1);
1207 else if (IS_SCINTILLA(focusw
))
1209 sci_select_all(SCINTILLA(focusw
));
1214 void on_menu_show_sidebar1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
1216 if (ignore_callback
)
1219 ui_prefs
.sidebar_visible
= ! ui_prefs
.sidebar_visible
;
1221 /* show built-in tabs if no tabs visible */
1222 if (ui_prefs
.sidebar_visible
&&
1223 ! interface_prefs
.sidebar_openfiles_visible
&& ! interface_prefs
.sidebar_symbol_visible
&&
1224 gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets
.sidebar_notebook
)) <= 2)
1226 interface_prefs
.sidebar_openfiles_visible
= TRUE
;
1227 interface_prefs
.sidebar_symbol_visible
= TRUE
;
1230 /* if window has input focus, set it back to the editor before toggling off */
1231 if (! ui_prefs
.sidebar_visible
&&
1232 gtk_container_get_focus_child(GTK_CONTAINER(main_widgets
.sidebar_notebook
)) != NULL
)
1234 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
1237 ui_sidebar_show_hide();
1241 static void on_menu_write_unicode_bom1_toggled(GtkCheckMenuItem
*checkmenuitem
, gpointer user_data
)
1243 if (! ignore_callback
)
1245 GeanyDocument
*doc
= document_get_current();
1247 g_return_if_fail(doc
!= NULL
);
1254 document_undo_add(doc
, UNDO_BOM
, GINT_TO_POINTER(doc
->has_bom
));
1256 doc
->has_bom
= ! doc
->has_bom
;
1258 ui_update_statusbar(doc
, -1);
1263 void on_menu_comment_line1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1265 GeanyDocument
*doc
= document_get_current();
1266 g_return_if_fail(doc
!= NULL
);
1268 editor_do_comment(doc
->editor
, -1, FALSE
, FALSE
, TRUE
);
1272 void on_menu_uncomment_line1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1274 GeanyDocument
*doc
= document_get_current();
1275 g_return_if_fail(doc
!= NULL
);
1277 editor_do_uncomment(doc
->editor
, -1, FALSE
);
1281 void on_menu_toggle_line_commentation1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1283 GeanyDocument
*doc
= document_get_current();
1284 g_return_if_fail(doc
!= NULL
);
1286 editor_do_comment_toggle(doc
->editor
);
1290 void on_menu_increase_indent1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1292 GeanyDocument
*doc
= document_get_current();
1293 g_return_if_fail(doc
!= NULL
);
1295 editor_indent(doc
->editor
, TRUE
);
1299 void on_menu_decrease_indent1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1301 GeanyDocument
*doc
= document_get_current();
1302 g_return_if_fail(doc
!= NULL
);
1304 editor_indent(doc
->editor
, FALSE
);
1308 void on_next_message1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1310 if (! ui_tree_view_find_next(GTK_TREE_VIEW(msgwindow
.tree_msg
),
1311 msgwin_goto_messages_file_line
))
1312 ui_set_statusbar(FALSE
, _("No more message items."));
1316 void on_previous_message1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1318 if (! ui_tree_view_find_previous(GTK_TREE_VIEW(msgwindow
.tree_msg
),
1319 msgwin_goto_messages_file_line
))
1320 ui_set_statusbar(FALSE
, _("No more message items."));
1324 void on_project_new1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1330 void on_project_open1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1336 void on_project_close1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1338 project_close(TRUE
);
1342 void on_project_properties1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1344 project_properties();
1348 static void on_menu_project1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1350 static GtkWidget
*item_close
= NULL
;
1351 static GtkWidget
*item_properties
= NULL
;
1353 if (item_close
== NULL
)
1355 item_close
= ui_lookup_widget(main_widgets
.window
, "project_close1");
1356 item_properties
= ui_lookup_widget(main_widgets
.window
, "project_properties1");
1359 gtk_widget_set_sensitive(item_close
, (app
->project
!= NULL
));
1360 gtk_widget_set_sensitive(item_properties
, (app
->project
!= NULL
));
1361 gtk_widget_set_sensitive(ui_widgets
.recent_projects_menuitem
,
1362 g_queue_get_length(ui_prefs
.recent_projects_queue
) > 0);
1366 void on_menu_open_selected_file1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1368 GeanyDocument
*doc
= document_get_current();
1373 wc
= GEANY_WORDCHARS
"./-" "\\";
1375 wc
= GEANY_WORDCHARS
"./-";
1378 g_return_if_fail(doc
!= NULL
);
1380 sel
= editor_get_default_selection(doc
->editor
, TRUE
, wc
);
1381 SETPTR(sel
, utils_get_locale_from_utf8(sel
));
1385 gchar
*filename
= NULL
;
1387 if (g_path_is_absolute(sel
))
1388 filename
= g_strdup(sel
);
1390 { /* relative filename, add the path of the current file */
1393 path
= utils_get_current_file_dir_utf8();
1394 SETPTR(path
, utils_get_locale_from_utf8(path
));
1396 path
= g_get_current_dir();
1398 filename
= g_build_path(G_DIR_SEPARATOR_S
, path
, sel
, NULL
);
1400 if (! g_file_test(filename
, G_FILE_TEST_EXISTS
) &&
1401 app
->project
!= NULL
&& !EMPTY(app
->project
->base_path
))
1403 /* try the project's base path */
1404 SETPTR(path
, project_get_base_path());
1405 SETPTR(path
, utils_get_locale_from_utf8(path
));
1406 SETPTR(filename
, g_build_path(G_DIR_SEPARATOR_S
, path
, sel
, NULL
));
1410 if (! g_file_test(filename
, G_FILE_TEST_EXISTS
))
1411 SETPTR(filename
, g_build_path(G_DIR_SEPARATOR_S
, "/usr/local/include", sel
, NULL
));
1413 if (! g_file_test(filename
, G_FILE_TEST_EXISTS
))
1414 SETPTR(filename
, g_build_path(G_DIR_SEPARATOR_S
, "/usr/include", sel
, NULL
));
1418 if (g_file_test(filename
, G_FILE_TEST_EXISTS
))
1419 document_open_file(filename
, FALSE
, NULL
, NULL
);
1422 SETPTR(sel
, utils_get_utf8_from_locale(sel
));
1423 ui_set_statusbar(TRUE
, _("Could not open file %s (File not found)"), sel
);
1432 void on_remove_markers1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1434 GeanyDocument
*doc
= document_get_current();
1435 g_return_if_fail(doc
!= NULL
);
1437 sci_marker_delete_all(doc
->editor
->sci
, 0); /* delete the yellow tag marker */
1438 sci_marker_delete_all(doc
->editor
->sci
, 1); /* delete user markers */
1439 editor_indicator_clear(doc
->editor
, GEANY_INDICATOR_SEARCH
);
1443 static void on_load_tags1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1445 symbols_show_load_tags_dialog();
1449 void on_context_action1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1451 gchar
*word
, *command
;
1452 GError
*error
= NULL
;
1453 GeanyDocument
*doc
= document_get_current();
1455 g_return_if_fail(doc
!= NULL
);
1457 if (sci_has_selection(doc
->editor
->sci
))
1458 { /* take selected text if there is a selection */
1459 word
= sci_get_selection_contents(doc
->editor
->sci
);
1463 word
= g_strdup(editor_info
.current_word
);
1466 /* use the filetype specific command if available, fallback to global command otherwise */
1467 if (doc
->file_type
!= NULL
&&
1468 !EMPTY(doc
->file_type
->context_action_cmd
))
1470 command
= g_strdup(doc
->file_type
->context_action_cmd
);
1474 command
= g_strdup(tool_prefs
.context_action_cmd
);
1477 /* substitute the wildcard %s and run the command if it is non empty */
1478 if (G_LIKELY(!EMPTY(command
)))
1480 utils_str_replace_all(&command
, "%s", word
);
1482 if (! g_spawn_command_line_async(command
, &error
))
1484 ui_set_statusbar(TRUE
, "Context action command failed: %s", error
->message
);
1485 g_error_free(error
);
1493 void on_menu_toggle_all_additional_widgets1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1495 static gint hide_all
= -1;
1496 GtkCheckMenuItem
*msgw
= GTK_CHECK_MENU_ITEM(
1497 ui_lookup_widget(main_widgets
.window
, "menu_show_messages_window1"));
1498 GtkCheckMenuItem
*toolbari
= GTK_CHECK_MENU_ITEM(
1499 ui_lookup_widget(main_widgets
.window
, "menu_show_toolbar1"));
1501 /* get the initial state (necessary if Geany was closed with hide_all = TRUE) */
1502 if (G_UNLIKELY(hide_all
== -1))
1504 if (! gtk_check_menu_item_get_active(msgw
) &&
1505 ! interface_prefs
.show_notebook_tabs
&&
1506 ! gtk_check_menu_item_get_active(toolbari
))
1514 hide_all
= ! hide_all
; /* toggle */
1518 if (gtk_check_menu_item_get_active(msgw
))
1519 gtk_check_menu_item_set_active(msgw
, ! gtk_check_menu_item_get_active(msgw
));
1521 interface_prefs
.show_notebook_tabs
= FALSE
;
1522 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets
.notebook
), interface_prefs
.show_notebook_tabs
);
1524 ui_statusbar_showhide(FALSE
);
1526 if (gtk_check_menu_item_get_active(toolbari
))
1527 gtk_check_menu_item_set_active(toolbari
, ! gtk_check_menu_item_get_active(toolbari
));
1532 if (! gtk_check_menu_item_get_active(msgw
))
1533 gtk_check_menu_item_set_active(msgw
, ! gtk_check_menu_item_get_active(msgw
));
1535 interface_prefs
.show_notebook_tabs
= TRUE
;
1536 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets
.notebook
), interface_prefs
.show_notebook_tabs
);
1538 ui_statusbar_showhide(TRUE
);
1540 if (! gtk_check_menu_item_get_active(toolbari
))
1541 gtk_check_menu_item_set_active(toolbari
, ! gtk_check_menu_item_get_active(toolbari
));
1546 void on_toolbutton_forward_activate(GtkAction
*menuitem
, gpointer user_data
)
1548 navqueue_go_forward();
1552 void on_toolbutton_back_activate(GtkAction
*menuitem
, gpointer user_data
)
1558 gboolean
on_motion_event(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
)
1560 if (prefs
.auto_focus
&& ! gtk_widget_has_focus(widget
))
1561 gtk_widget_grab_focus(widget
);
1567 static void set_indent_type(GtkCheckMenuItem
*menuitem
, GeanyIndentType type
)
1571 if (ignore_callback
|| ! gtk_check_menu_item_get_active(menuitem
))
1574 doc
= document_get_current();
1575 g_return_if_fail(doc
!= NULL
);
1577 editor_set_indent(doc
->editor
, type
, doc
->editor
->indent_width
);
1578 ui_update_statusbar(doc
, -1);
1582 static void on_tabs1_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
1584 set_indent_type(menuitem
, GEANY_INDENT_TYPE_TABS
);
1588 static void on_spaces1_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
1590 set_indent_type(menuitem
, GEANY_INDENT_TYPE_SPACES
);
1594 static void on_tabs_and_spaces1_activate(GtkCheckMenuItem
*menuitem
, gpointer user_data
)
1596 set_indent_type(menuitem
, GEANY_INDENT_TYPE_BOTH
);
1600 static void on_strip_trailing_spaces1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1604 if (ignore_callback
)
1607 doc
= document_get_current();
1608 g_return_if_fail(doc
!= NULL
);
1610 editor_strip_trailing_spaces(doc
->editor
);
1614 static void on_page_setup1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1616 printing_page_setup_gtk();
1620 gboolean
on_escape_key_press_event(GtkWidget
*widget
, GdkEventKey
*event
, gpointer user_data
)
1622 guint state
= keybindings_get_modifiers(event
->state
);
1624 /* make pressing escape in the sidebar and toolbar focus the editor */
1625 if (event
->keyval
== GDK_Escape
&& state
== 0)
1627 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
1634 void on_line_breaking1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1638 if (ignore_callback
)
1641 doc
= document_get_current();
1642 g_return_if_fail(doc
!= NULL
);
1644 doc
->editor
->line_breaking
= !doc
->editor
->line_breaking
;
1648 void on_replace_spaces_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1650 GeanyDocument
*doc
= document_get_current();
1652 g_return_if_fail(doc
!= NULL
);
1654 editor_replace_spaces(doc
->editor
);
1658 static void on_search1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1660 GtkWidget
*next_message
= ui_lookup_widget(main_widgets
.window
, "next_message1");
1661 GtkWidget
*previous_message
= ui_lookup_widget(main_widgets
.window
, "previous_message1");
1662 gboolean have_messages
;
1664 /* enable commands if the messages window has any items */
1665 have_messages
= gtk_tree_model_iter_n_children(GTK_TREE_MODEL(msgwindow
.store_msg
),
1668 gtk_widget_set_sensitive(next_message
, have_messages
);
1669 gtk_widget_set_sensitive(previous_message
, have_messages
);
1673 /* simple implementation (vs. close all which doesn't close documents if cancelled),
1674 * if user_data is set, it is the GeanyDocument to keep */
1675 void on_close_other_documents1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1678 GeanyDocument
*cur_doc
= user_data
;
1680 if (cur_doc
== NULL
)
1681 cur_doc
= document_get_current();
1683 for (i
= 0; i
< documents_array
->len
; i
++)
1685 GeanyDocument
*doc
= documents
[i
];
1687 if (doc
== cur_doc
|| ! doc
->is_valid
)
1690 if (! document_close(doc
))
1696 static void on_menu_reload_configuration1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1698 main_reload_configuration();
1702 static void on_debug_messages1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1704 log_show_debug_messages_dialog();
1708 void on_send_selection_to_vte1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1711 if (vte_info
.have_vte
)
1712 vte_send_selection_to_vte();
1717 static gboolean
on_window_state_event(GtkWidget
*widget
, GdkEventWindowState
*event
, gpointer user_data
)
1720 if (event
->changed_mask
& GDK_WINDOW_STATE_FULLSCREEN
)
1722 static GtkWidget
*menuitem
= NULL
;
1724 if (menuitem
== NULL
)
1725 menuitem
= ui_lookup_widget(widget
, "menu_fullscreen1");
1727 ignore_callback
= TRUE
;
1729 ui_prefs
.fullscreen
= (event
->new_window_state
& GDK_WINDOW_STATE_FULLSCREEN
) ? TRUE
: FALSE
;
1730 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem
), ui_prefs
.fullscreen
);
1732 ignore_callback
= FALSE
;
1738 static void show_notebook_page(const gchar
*notebook_name
, const gchar
*page_name
)
1741 GtkNotebook
*notebook
;
1743 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, page_name
);
1744 notebook
= GTK_NOTEBOOK(ui_lookup_widget(ui_widgets
.prefs_dialog
, notebook_name
));
1746 if (notebook
!= NULL
&& widget
!= NULL
)
1747 gtk_notebook_set_current_page(notebook
, gtk_notebook_page_num(notebook
, widget
));
1751 static void on_customize_toolbar1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1753 prefs_show_dialog();
1755 /* select the Interface page */
1756 show_notebook_page("notebook2", "notebook6");
1757 /* select the Toolbar subpage */
1758 show_notebook_page("notebook6", "vbox15");
1762 static void on_button_customize_toolbar_clicked(GtkButton
*button
, gpointer user_data
)
1764 toolbar_configure(GTK_WINDOW(ui_widgets
.prefs_dialog
));
1768 static void on_cut_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1770 keybindings_send_command(GEANY_KEY_GROUP_CLIPBOARD
, GEANY_KEYS_CLIPBOARD_CUTLINE
);
1774 static void on_copy_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1776 keybindings_send_command(GEANY_KEY_GROUP_CLIPBOARD
, GEANY_KEYS_CLIPBOARD_COPYLINE
);
1780 static void on_delete_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1782 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_DELETELINE
);
1786 static void on_duplicate_line_or_selection1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1788 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_DUPLICATELINE
);
1792 static void on_select_current_lines1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1794 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_LINE
);
1798 static void on_select_current_paragraph1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1800 keybindings_send_command(GEANY_KEY_GROUP_SELECT
, GEANY_KEYS_SELECT_PARAGRAPH
);
1804 static void on_insert_alternative_white_space1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1806 keybindings_send_command(GEANY_KEY_GROUP_INSERT
, GEANY_KEYS_INSERT_ALTWHITESPACE
);
1810 static void on_go_to_next_marker1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1812 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_NEXTMARKER
);
1816 static void on_go_to_previous_marker1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1818 keybindings_send_command(GEANY_KEY_GROUP_GOTO
, GEANY_KEYS_GOTO_PREVIOUSMARKER
);
1822 static void on_reflow_lines_block1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1824 keybindings_send_command(GEANY_KEY_GROUP_FORMAT
, GEANY_KEYS_FORMAT_REFLOWPARAGRAPH
);
1828 static void on_move_lines_up1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1830 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_MOVELINEUP
);
1834 static void on_move_lines_down1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1836 keybindings_send_command(GEANY_KEY_GROUP_EDITOR
, GEANY_KEYS_EDITOR_MOVELINEDOWN
);
1840 static void on_smart_line_indent1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1842 keybindings_send_command(GEANY_KEY_GROUP_FORMAT
, GEANY_KEYS_FORMAT_AUTOINDENT
);
1846 void on_plugin_preferences1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1849 plugin_show_configure(NULL
);
1854 static void on_indent_width_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1860 if (ignore_callback
)
1863 label
= ui_menu_item_get_text(menuitem
);
1864 width
= atoi(label
);
1867 doc
= document_get_current();
1868 if (doc
!= NULL
&& width
> 0)
1869 editor_set_indent_width(doc
->editor
, width
);
1873 static void on_reset_indentation1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1878 document_apply_indent_settings(documents
[i
]);
1880 ui_update_statusbar(NULL
, -1);
1881 ui_document_show_hide(NULL
);
1885 static void on_mark_all1_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1887 keybindings_send_command(GEANY_KEY_GROUP_SEARCH
, GEANY_KEYS_SEARCH_MARKALL
);
1891 static void on_detect_type_from_file_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1893 GeanyDocument
*doc
= document_get_current();
1894 GeanyIndentType type
;
1896 if (doc
!= NULL
&& document_detect_indent_type(doc
, &type
))
1898 editor_set_indent_type(doc
->editor
, type
);
1899 ui_document_show_hide(doc
);
1904 static void on_detect_width_from_file_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
1906 GeanyDocument
*doc
= document_get_current();
1909 if (doc
!= NULL
&& document_detect_indent_width(doc
, &width
))
1911 editor_set_indent_width(doc
->editor
, width
);
1912 ui_document_show_hide(doc
);
1917 static void builder_connect_func(GtkBuilder
*builder
, GObject
*object
,
1918 const gchar
*signal_name
, const gchar
*handler_name
, GObject
*connect_obj
,
1919 GConnectFlags flags
, gpointer user_data
)
1921 GHashTable
*hash
= user_data
;
1924 callback
= g_hash_table_lookup(hash
, handler_name
);
1925 g_return_if_fail(callback
);
1927 if (connect_obj
== NULL
)
1928 g_signal_connect_data(object
, signal_name
, callback
, NULL
, NULL
, flags
);
1930 g_signal_connect_object(object
, signal_name
, callback
, connect_obj
, flags
);
1934 void callbacks_connect(GtkBuilder
*builder
)
1938 g_return_if_fail(GTK_IS_BUILDER(builder
));
1940 hash
= g_hash_table_new(g_str_hash
, g_str_equal
);
1942 #define ITEM(n) g_hash_table_insert(hash, (gpointer) #n, G_CALLBACK(n));
1943 # include "signallist.i"
1946 gtk_builder_connect_signals_full(builder
, builder_connect_func
, hash
);
1947 g_hash_table_destroy(hash
);