2 * prefs.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.
28 * Preferences dialog support functions.
29 * New 'simple' prefs should use Stash code in keyfile.c - init_pref_groups().
40 #include "documentprivate.h"
42 #include "encodings.h"
43 #include "filetypes.h"
44 #include "geanywraplabel.h"
45 #include "keybindingsprivate.h"
47 #include "msgwindow.h"
53 #include "templates.h"
60 #include "gtkcompat.h"
64 #include <gdk/gdkkeysyms.h>
68 GeanyToolPrefs tool_prefs
;
79 static KbData global_kb_data
= { NULL
, NULL
, FALSE
};
80 static GtkTreeView
*various_treeview
= NULL
;
82 static GeanyKeyBinding
*kb_index(guint gidx
, guint kid
);
83 static void kb_cell_edited_cb(GtkCellRendererText
*cellrenderertext
, gchar
*path
, gchar
*new_text
, KbData
*kbdata
);
84 static gboolean
kb_grab_key_dialog_key_press_cb(GtkWidget
*dialog
, GdkEventKey
*event
, GtkLabel
*label
);
85 static void kb_change_iter_shortcut(KbData
*kbdata
, GtkTreeIter
*iter
, const gchar
*new_text
);
86 static gboolean
kb_find_duplicate(GtkTreeStore
*store
, GtkWidget
*parent
, GtkTreeIter
*old_iter
,
87 guint key
, GdkModifierType mods
, const gchar
*shortcut
);
88 static void on_toolbar_show_toggled(GtkToggleButton
*togglebutton
, gpointer user_data
);
89 static void on_show_notebook_tabs_toggled(GtkToggleButton
*togglebutton
, gpointer user_data
);
90 static void on_enable_plugins_toggled(GtkToggleButton
*togglebutton
, gpointer user_data
);
91 static void on_use_folding_toggled(GtkToggleButton
*togglebutton
, gpointer user_data
);
92 static void on_open_encoding_toggled(GtkToggleButton
*togglebutton
, gpointer user_data
);
93 static void on_sidebar_visible_toggled(GtkToggleButton
*togglebutton
, gpointer user_data
);
94 static void on_prefs_print_radio_button_toggled(GtkToggleButton
*togglebutton
, gpointer user_data
);
95 static void on_prefs_print_page_header_toggled(GtkToggleButton
*togglebutton
, gpointer user_data
);
96 static void open_preferences_help(void);
99 typedef enum PrefCallbackAction
107 /* Synchronize Stash settings with widgets (see keyfile.c - init_pref_groups()). */
108 static void prefs_action(PrefCallbackAction action
)
113 foreach_ptr_array(group
, i
, pref_groups
)
118 stash_group_display(group
, ui_widgets
.prefs_dialog
);
121 stash_group_update(group
, ui_widgets
.prefs_dialog
);
129 stash_tree_display(various_treeview
);
132 stash_tree_update(various_treeview
);
149 static void kb_tree_view_change_button_clicked_cb(GtkWidget
*button
, KbData
*kbdata
)
153 GtkTreeSelection
*selection
;
156 selection
= gtk_tree_view_get_selection(kbdata
->tree
);
157 if (gtk_tree_selection_get_selected(selection
, &model
, &iter
))
159 if (gtk_tree_model_iter_has_child(model
, &iter
))
160 { /* double click on a section to expand or collapse it */
161 GtkTreePath
*path
= gtk_tree_model_get_path(model
, &iter
);
163 if (gtk_tree_view_row_expanded(kbdata
->tree
, path
))
164 gtk_tree_view_collapse_row(kbdata
->tree
, path
);
166 gtk_tree_view_expand_row(kbdata
->tree
, path
, FALSE
);
168 gtk_tree_path_free(path
);
172 gtk_tree_model_get(model
, &iter
, KB_TREE_ACTION
, &name
, -1);
177 GtkWidget
*accel_label
;
180 dialog
= gtk_dialog_new_with_buttons(_("Grab Key"), GTK_WINDOW(ui_widgets
.prefs_dialog
),
181 GTK_DIALOG_MODAL
| GTK_DIALOG_DESTROY_WITH_PARENT
,
182 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
183 GTK_STOCK_OK
, GTK_RESPONSE_ACCEPT
, NULL
);
185 str
= g_strdup_printf(
186 _("Press the combination of the keys you want to use for \"%s\"."), name
);
187 label
= gtk_label_new(str
);
188 gtk_misc_set_padding(GTK_MISC(label
), 5, 10);
189 gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog
))), label
);
191 accel_label
= gtk_label_new("");
192 gtk_misc_set_padding(GTK_MISC(accel_label
), 5, 10);
193 gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog
))), accel_label
);
195 g_signal_connect(dialog
, "key-press-event",
196 G_CALLBACK(kb_grab_key_dialog_key_press_cb
), accel_label
);
198 gtk_widget_show_all(dialog
);
199 if (gtk_dialog_run(GTK_DIALOG(dialog
)) == GTK_RESPONSE_ACCEPT
)
201 const gchar
*new_text
= gtk_label_get_text(GTK_LABEL(accel_label
));
203 kb_change_iter_shortcut(kbdata
, &iter
, new_text
);
205 gtk_widget_destroy(dialog
);
214 static void kb_show_popup_menu(KbData
*kbdata
, GtkWidget
*widget
, GdkEventButton
*event
)
217 static GtkWidget
*menu
= NULL
;
223 menu
= gtk_menu_new();
225 item
= ui_image_menu_item_new(GTK_STOCK_ADD
, _("_Expand All"));
226 gtk_widget_show(item
);
227 gtk_container_add(GTK_CONTAINER(menu
), item
);
228 g_signal_connect_swapped(item
, "activate", G_CALLBACK(gtk_tree_view_expand_all
), kbdata
->tree
);
230 item
= ui_image_menu_item_new(GTK_STOCK_REMOVE
, _("_Collapse All"));
231 gtk_widget_show(item
);
232 gtk_container_add(GTK_CONTAINER(menu
), item
);
233 g_signal_connect_swapped(item
, "activate", G_CALLBACK(gtk_tree_view_collapse_all
), kbdata
->tree
);
235 gtk_menu_attach_to_widget(GTK_MENU(menu
), widget
, NULL
);
240 button
= event
->button
;
241 event_time
= event
->time
;
246 event_time
= gtk_get_current_event_time();
249 gtk_menu_popup(GTK_MENU(menu
), NULL
, NULL
, NULL
, NULL
, button
, event_time
);
253 static gboolean
kb_popup_menu_cb(GtkWidget
*widget
, KbData
*kbdata
)
255 kb_show_popup_menu(kbdata
, widget
, NULL
);
260 static gboolean
kb_tree_view_button_press_event_cb(GtkWidget
*widget
, GdkEventButton
*event
,
263 if (event
->button
== 3 && event
->type
== GDK_BUTTON_PRESS
)
265 kb_show_popup_menu(kbdata
, widget
, event
);
268 else if (event
->type
== GDK_2BUTTON_PRESS
)
270 kb_tree_view_change_button_clicked_cb(NULL
, kbdata
);
277 static void kb_init_tree(KbData
*kbdata
)
279 GtkCellRenderer
*renderer
;
280 GtkTreeViewColumn
*column
;
282 kbdata
->tree
= GTK_TREE_VIEW(ui_lookup_widget(ui_widgets
.prefs_dialog
, "treeview7"));
284 kbdata
->store
= gtk_tree_store_new(KB_TREE_COLUMNS
,
285 G_TYPE_STRING
, G_TYPE_STRING
, G_TYPE_INT
, G_TYPE_BOOLEAN
, G_TYPE_INT
);
286 gtk_tree_view_set_model(GTK_TREE_VIEW(kbdata
->tree
), GTK_TREE_MODEL(kbdata
->store
));
287 g_object_unref(kbdata
->store
);
289 renderer
= gtk_cell_renderer_text_new();
290 column
= gtk_tree_view_column_new_with_attributes(_("Action"), renderer
,
291 "text", KB_TREE_ACTION
, "weight", KB_TREE_WEIGHT
, NULL
);
292 gtk_tree_view_append_column(GTK_TREE_VIEW(kbdata
->tree
), column
);
294 renderer
= gtk_cell_renderer_text_new();
295 column
= gtk_tree_view_column_new_with_attributes(_("Shortcut"), renderer
,
296 "text", KB_TREE_SHORTCUT
, "editable", KB_TREE_EDITABLE
,
297 "weight", KB_TREE_WEIGHT
, NULL
);
298 gtk_tree_view_append_column(GTK_TREE_VIEW(kbdata
->tree
), column
);
300 /* set policy settings for the scrolled window around the treeview again, because glade
301 * doesn't keep the settings */
302 gtk_scrolled_window_set_policy(
303 GTK_SCROLLED_WINDOW(ui_lookup_widget(ui_widgets
.prefs_dialog
, "scrolledwindow8")),
304 GTK_POLICY_NEVER
, GTK_POLICY_AUTOMATIC
);
306 g_signal_connect(renderer
, "edited", G_CALLBACK(kb_cell_edited_cb
), kbdata
);
307 g_signal_connect(kbdata
->tree
, "button-press-event", G_CALLBACK(kb_tree_view_button_press_event_cb
), kbdata
);
308 g_signal_connect(kbdata
->tree
, "popup-menu", G_CALLBACK(kb_popup_menu_cb
), kbdata
);
309 g_signal_connect(ui_lookup_widget(ui_widgets
.prefs_dialog
, "button2"), "clicked",
310 G_CALLBACK(kb_tree_view_change_button_clicked_cb
), kbdata
);
314 static void kb_set_shortcut(GtkTreeStore
*store
, GtkTreeIter
*iter
,
315 guint key
, GdkModifierType mods
)
317 gchar
*key_string
= gtk_accelerator_name(key
, mods
);
323 gtk_tree_store_set(store
, iter
, KB_TREE_SHORTCUT
, key_string
, -1);
326 gtk_tree_model_get(GTK_TREE_MODEL(store
), iter
, KB_TREE_INDEX
, &kid
, -1);
327 gtk_tree_model_iter_parent(GTK_TREE_MODEL(store
), &parent
, iter
);
328 gtk_tree_model_get(GTK_TREE_MODEL(store
), &parent
, KB_TREE_INDEX
, &gid
, -1);
329 kb
= kb_index(gid
, kid
);
330 bold
= key
!= kb
->default_key
|| mods
!= kb
->default_mods
;
331 gtk_tree_store_set(store
, iter
, KB_TREE_WEIGHT
,
332 bold
? PANGO_WEIGHT_BOLD
: PANGO_WEIGHT_NORMAL
, -1);
336 void prefs_kb_search_name(const gchar
*search
)
341 KbData
*kbdata
= &global_kb_data
;
343 model
= gtk_tree_view_get_model(kbdata
->tree
);
344 valid
= gtk_tree_model_get_iter_first(model
, &iter
);
349 gtk_tree_model_get(model
, &iter
, KB_TREE_ACTION
, &name
, -1);
350 if (g_strcmp0(name
, search
) == 0)
352 GtkTreePath
*path
= gtk_tree_model_get_path(model
, &iter
);
353 gtk_tree_view_scroll_to_cell(kbdata
->tree
, path
, NULL
, TRUE
, .0f
, .0f
);
354 gtk_tree_path_free(path
);
359 valid
= gtk_tree_model_iter_next(model
, &iter
);
364 static void kb_init(KbData
*kbdata
)
366 GtkTreeIter parent
, iter
;
369 GeanyKeyGroup
*group
;
372 if (kbdata
->store
== NULL
)
373 kb_init_tree(kbdata
);
375 foreach_ptr_array(group
, g
, keybinding_groups
)
377 gtk_tree_store_append(kbdata
->store
, &parent
, NULL
);
378 gtk_tree_store_set(kbdata
->store
, &parent
, KB_TREE_ACTION
, group
->label
,
379 KB_TREE_INDEX
, g
, -1);
381 foreach_ptr_array(kb
, i
, group
->key_items
)
383 label
= keybindings_get_label(kb
);
384 gtk_tree_store_append(kbdata
->store
, &iter
, &parent
);
385 gtk_tree_store_set(kbdata
->store
, &iter
, KB_TREE_ACTION
, label
,
386 KB_TREE_EDITABLE
, TRUE
, KB_TREE_INDEX
, kb
->id
, -1);
387 kb_set_shortcut(kbdata
->store
, &iter
, kb
->key
, kb
->mods
);
391 gtk_tree_view_expand_all(GTK_TREE_VIEW(kbdata
->tree
));
395 /* note: new 'simple' prefs should use Stash code in keyfile.c */
396 static void prefs_init_dialog(void)
399 GdkColor color
= {0};
401 /* Synchronize with Stash settings */
402 prefs_action(PREF_DISPLAY
);
404 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "label_project_indent_warning");
405 ui_widget_show_hide(widget
, app
->project
!= NULL
);
407 /* General settings */
409 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_load_session");
410 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), prefs
.load_session
);
412 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_project_session");
413 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), project_prefs
.project_session
);
415 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_project_file_in_basedir");
416 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), project_prefs
.project_file_in_basedir
);
418 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_save_win_pos");
419 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), prefs
.save_winpos
);
421 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_ask_for_quit");
422 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), prefs
.confirm_exit
);
425 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_beep");
426 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), prefs
.beep_on_errors
);
428 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_switch_pages");
429 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), prefs
.switch_to_status
);
431 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_suppress_status_msgs");
432 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), prefs
.suppress_status_messages
);
434 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_auto_focus");
435 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), prefs
.auto_focus
);
437 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_native_windows_dialogs");
438 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
),
439 interface_prefs
.use_native_windows_dialogs
);
441 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_contextaction");
442 gtk_entry_set_text(GTK_ENTRY(widget
), tool_prefs
.context_action_cmd
);
444 project_setup_prefs(); /* project files path */
447 /* Interface settings */
448 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_sidebar_visible");
449 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), ui_prefs
.sidebar_visible
);
450 on_sidebar_visible_toggled(GTK_TOGGLE_BUTTON(widget
), NULL
);
452 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_list_symbol");
453 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), interface_prefs
.sidebar_symbol_visible
);
455 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_list_openfiles");
456 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), interface_prefs
.sidebar_openfiles_visible
);
458 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "tagbar_font");
459 gtk_font_button_set_font_name(GTK_FONT_BUTTON(widget
), interface_prefs
.tagbar_font
);
461 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "msgwin_font");
462 gtk_font_button_set_font_name(GTK_FONT_BUTTON(widget
), interface_prefs
.msgwin_font
);
464 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "editor_font");
465 gtk_font_button_set_font_name(GTK_FONT_BUTTON(widget
), interface_prefs
.editor_font
);
467 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "spin_long_line");
468 gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget
), editor_prefs
.long_line_column
);
470 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_long_line");
471 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), editor_prefs
.long_line_enabled
);
473 switch (editor_prefs
.long_line_type
)
475 case 0: widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "radio_long_line_line"); break;
476 case 1: widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "radio_long_line_background"); break;
478 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), TRUE
);
480 utils_parse_color(editor_prefs
.long_line_color
, &color
);
481 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "long_line_color");
482 gtk_color_button_set_color(GTK_COLOR_BUTTON(widget
), &color
);
484 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_show_notebook_tabs");
485 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), interface_prefs
.show_notebook_tabs
);
486 /* disable following setting if notebook tabs are hidden */
487 on_show_notebook_tabs_toggled(GTK_TOGGLE_BUTTON(
488 ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_show_notebook_tabs")), NULL
);
490 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_show_tab_cross");
491 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), file_prefs
.show_tab_cross
);
493 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "combo_tab_editor");
494 gtk_combo_box_set_active(GTK_COMBO_BOX(widget
), interface_prefs
.tab_pos_editor
);
496 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "combo_tab_msgwin");
497 gtk_combo_box_set_active(GTK_COMBO_BOX(widget
), interface_prefs
.tab_pos_msgwin
);
499 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "combo_tab_sidebar");
500 gtk_combo_box_set_active(GTK_COMBO_BOX(widget
), interface_prefs
.tab_pos_sidebar
);
502 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_statusbar_visible");
503 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), interface_prefs
.statusbar_visible
);
506 /* Toolbar settings */
507 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_toolbar_show");
508 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), toolbar_prefs
.visible
);
509 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_toolbar_in_menu");
510 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), toolbar_prefs
.append_to_menu
);
512 switch (toolbar_prefs
.icon_style
)
514 case 0: widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "radio_toolbar_image"); break;
515 case 1: widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "radio_toolbar_text"); break;
516 default: widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "radio_toolbar_imagetext"); break;
518 if (toolbar_prefs
.use_gtk_default_style
)
519 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "radio_toolbar_style_default");
520 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), TRUE
);
522 switch (toolbar_prefs
.icon_size
)
524 case GTK_ICON_SIZE_LARGE_TOOLBAR
:
525 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "radio_toolbar_large"); break;
526 case GTK_ICON_SIZE_SMALL_TOOLBAR
:
527 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "radio_toolbar_small"); break;
528 default: widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "radio_toolbar_verysmall"); break;
530 if (toolbar_prefs
.use_gtk_default_icon
)
531 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "radio_toolbar_icon_default");
532 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), TRUE
);
534 /* disable elements if toolbar is hidden */
535 on_toolbar_show_toggled(GTK_TOGGLE_BUTTON(
536 ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_toolbar_show")), NULL
);
540 if (file_prefs
.tab_order_ltr
)
541 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "radio_tab_right");
543 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "radio_tab_left");
544 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), TRUE
);
546 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_tab_beside");
547 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), file_prefs
.tab_order_beside
);
549 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "combo_new_encoding");
550 ui_encodings_combo_box_set_active_encoding(GTK_COMBO_BOX(widget
), file_prefs
.default_new_encoding
);
552 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_open_encoding");
553 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
),
554 (file_prefs
.default_open_encoding
>= 0) ? TRUE
: FALSE
);
555 on_open_encoding_toggled(GTK_TOGGLE_BUTTON(widget
), NULL
);
557 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "combo_open_encoding");
558 if (file_prefs
.default_open_encoding
>= 0)
560 ui_encodings_combo_box_set_active_encoding(GTK_COMBO_BOX(widget
), file_prefs
.default_open_encoding
);
563 ui_encodings_combo_box_set_active_encoding(GTK_COMBO_BOX(widget
), GEANY_ENCODING_UTF_8
);
565 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "combo_eol");
566 if (file_prefs
.default_eol_character
>= 0 && file_prefs
.default_eol_character
< 3)
568 gtk_combo_box_set_active(GTK_COMBO_BOX(widget
), file_prefs
.default_eol_character
);
571 gtk_combo_box_set_active(GTK_COMBO_BOX(widget
), GEANY_DEFAULT_EOL_CHARACTER
);
573 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_trailing_spaces");
574 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), file_prefs
.strip_trailing_spaces
);
576 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_new_line");
577 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), file_prefs
.final_new_line
);
579 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_ensure_convert_new_lines");
580 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), file_prefs
.ensure_convert_new_lines
);
582 /* Editor settings */
583 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_toggle_mark");
584 gtk_entry_set_text(GTK_ENTRY(widget
), editor_prefs
.comment_toggle_mark
);
586 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_replace_tabs");
587 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), file_prefs
.replace_tabs
);
589 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_indent");
590 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), editor_prefs
.show_indent_guide
);
592 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_white_space");
593 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), editor_prefs
.show_white_space
);
595 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_line_end");
596 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), editor_prefs
.show_line_endings
);
598 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_line_numbers");
599 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), editor_prefs
.show_linenumber_margin
);
601 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_markers_margin");
602 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), editor_prefs
.show_markers_margin
);
604 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_scroll_stop_at_last_line");
605 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), editor_prefs
.scroll_stop_at_last_line
);
607 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_line_wrapping");
608 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), editor_prefs
.line_wrapping
);
610 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_complete_snippets");
611 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), editor_prefs
.complete_snippets
);
613 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_xmltag");
614 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), editor_prefs
.auto_close_xml_tags
);
616 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_folding");
617 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), editor_prefs
.folding
);
619 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_unfold_children");
620 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), editor_prefs
.unfold_all_children
);
621 on_use_folding_toggled(GTK_TOGGLE_BUTTON(
622 ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_folding")), NULL
);
624 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_disable_dnd");
625 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), editor_prefs
.disable_dnd
);
627 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_smart_home");
628 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), editor_prefs
.smart_home_key
);
630 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_newline_strip");
631 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), editor_prefs
.newline_strip
);
633 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_indicators");
634 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), editor_prefs
.use_indicators
);
636 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_auto_multiline");
637 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), editor_prefs
.auto_continue_multiline
);
639 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_symbol_auto_completion");
640 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), editor_prefs
.auto_complete_symbols
);
642 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "spin_symbollistheight");
643 gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget
), editor_prefs
.symbolcompletion_max_height
);
645 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "spin_symbol_complete_chars");
646 gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget
), editor_prefs
.symbolcompletion_min_chars
);
648 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "spin_line_break");
649 gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget
), editor_prefs
.line_break_column
);
651 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_autoclose_parenthesis");
652 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
),
653 (editor_prefs
.autoclose_chars
& GEANY_AC_PARENTHESIS
));
655 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_autoclose_cbracket");
656 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
),
657 (editor_prefs
.autoclose_chars
& GEANY_AC_CBRACKET
));
659 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_autoclose_sbracket");
660 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
),
661 (editor_prefs
.autoclose_chars
& GEANY_AC_SBRACKET
));
663 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_autoclose_squote");
664 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
),
665 (editor_prefs
.autoclose_chars
& GEANY_AC_SQUOTE
));
667 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_autoclose_dquote");
668 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
),
669 (editor_prefs
.autoclose_chars
& GEANY_AC_DQUOTE
));
673 if (tool_prefs
.term_cmd
)
674 gtk_entry_set_text(GTK_ENTRY(ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_com_term")), tool_prefs
.term_cmd
);
676 if (tool_prefs
.browser_cmd
)
677 gtk_entry_set_text(GTK_ENTRY(ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_browser")), tool_prefs
.browser_cmd
);
679 if (tool_prefs
.grep_cmd
)
680 gtk_entry_set_text(GTK_ENTRY(ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_grep")), tool_prefs
.grep_cmd
);
683 /* Template settings */
684 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_template_developer");
685 gtk_entry_set_text(GTK_ENTRY(widget
), template_prefs
.developer
);
687 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_template_company");
688 gtk_entry_set_text(GTK_ENTRY(widget
), template_prefs
.company
);
690 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_template_mail");
691 gtk_entry_set_text(GTK_ENTRY(widget
), template_prefs
.mail
);
693 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_template_initial");
694 gtk_entry_set_text(GTK_ENTRY(widget
), template_prefs
.initials
);
696 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_template_version");
697 gtk_entry_set_text(GTK_ENTRY(widget
), template_prefs
.version
);
699 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_template_year");
700 gtk_entry_set_text(GTK_ENTRY(widget
), template_prefs
.year_format
);
702 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_template_date");
703 gtk_entry_set_text(GTK_ENTRY(widget
), template_prefs
.date_format
);
705 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_template_datetime");
706 gtk_entry_set_text(GTK_ENTRY(widget
), template_prefs
.datetime_format
);
710 kb_init(&global_kb_data
);
714 GtkWidget
*widget_gtk
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "radio_print_gtk");
715 if (printing_prefs
.use_gtk_printing
)
718 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "radio_print_external");
720 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), TRUE
);
722 on_prefs_print_radio_button_toggled(GTK_TOGGLE_BUTTON(widget_gtk
), NULL
);
724 if (printing_prefs
.external_print_cmd
)
726 GTK_ENTRY(ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_print_external_cmd")),
727 printing_prefs
.external_print_cmd
);
729 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_print_linenumbers");
730 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), printing_prefs
.print_line_numbers
);
732 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_print_pagenumbers");
733 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), printing_prefs
.print_page_numbers
);
735 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_print_pageheader");
736 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), printing_prefs
.print_page_header
);
737 on_prefs_print_page_header_toggled(GTK_TOGGLE_BUTTON(widget
), NULL
);
739 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_print_basename");
740 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), printing_prefs
.page_header_basename
);
742 if (printing_prefs
.page_header_datefmt
)
744 GTK_ENTRY(ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_print_dateformat")),
745 printing_prefs
.page_header_datefmt
);
749 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_plugins"), FALSE
);
751 on_enable_plugins_toggled(GTK_TOGGLE_BUTTON( ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_plugins")), NULL
);
754 /* make VTE switch visible only when VTE is compiled in, it is hidden by default */
755 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_vte");
756 gtk_widget_show(widget
);
757 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), vte_info
.load_vte
);
760 if (vte_info
.have_vte
)
762 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "font_term");
763 gtk_font_button_set_font_name(GTK_FONT_BUTTON(widget
), vc
->font
);
765 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "color_fore");
766 gtk_color_button_set_color(GTK_COLOR_BUTTON(widget
), &vc
->colour_fore
);
768 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "color_back");
769 gtk_color_button_set_color(GTK_COLOR_BUTTON(widget
), &vc
->colour_back
);
771 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_image");
772 gtk_entry_set_text(GTK_ENTRY(widget
), vc
->image
);
774 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "spin_scrollback");
775 gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget
), vc
->scrollback_lines
);
777 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_shell");
778 gtk_entry_set_text(GTK_ENTRY(widget
), vc
->shell
);
780 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_scroll_key");
781 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), vc
->scroll_on_key
);
783 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_scroll_out");
784 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), vc
->scroll_on_out
);
786 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_enable_bash_keys");
787 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), vc
->enable_bash_keys
);
789 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_ignore_menu_key");
790 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), vc
->ignore_menu_bar_accel
);
792 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_follow_path");
793 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), vc
->follow_path
);
795 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_run_in_vte");
796 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), vc
->run_in_vte
);
798 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_skip_script");
799 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), vc
->skip_run_script
);
801 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_cursor_blinks");
802 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
), vc
->cursor_blinks
);
808 /* note: uses group index, not group id, unlike keybindings_lookup_item(). */
809 static GeanyKeyBinding
*kb_index(guint gidx
, guint kid
)
811 GeanyKeyGroup
*group
;
813 group
= g_ptr_array_index(keybinding_groups
, gidx
);
814 return keybindings_get_item(group
, kid
);
818 /* read the treeview shortcut fields into keybindings */
819 static void kb_update(KbData
*kbdata
)
821 GtkTreeModel
*model
= GTK_TREE_MODEL(kbdata
->store
);
822 GtkTreeIter child
, parent
;
825 /* get first parent */
826 if (! gtk_tree_model_iter_children(model
, &parent
, NULL
))
832 /* get first child */
833 if (! gtk_tree_model_iter_children(model
, &child
, &parent
))
842 GdkModifierType mods
;
845 gtk_tree_model_get(model
, &child
, KB_TREE_INDEX
, &kid
, KB_TREE_SHORTCUT
, &str
, -1);
846 gtk_accelerator_parse(str
, &key
, &mods
);
848 kb
= kb_index(gid
, kid
);
849 if (kb
->key
!= key
|| kb
->mods
!= mods
)
850 keybindings_update_combo(kb
, key
, mods
);
852 if (! gtk_tree_model_iter_next(model
, &child
))
855 if (! gtk_tree_model_iter_next(model
, &parent
))
865 /* note: new 'simple' prefs should use Stash code in keyfile.c */
867 on_prefs_dialog_response(GtkDialog
*dialog
, gint response
, gpointer user_data
)
869 if (response
== GTK_RESPONSE_OK
|| response
== GTK_RESPONSE_APPLY
)
873 gboolean autoclose_brackets
[5];
874 gboolean old_invert_all
= interface_prefs
.highlighting_invert_all
;
875 gboolean old_sidebar_pos
= interface_prefs
.sidebar_pos
;
876 GeanyDocument
*doc
= document_get_current();
878 /* Synchronize Stash settings */
879 prefs_action(PREF_UPDATE
);
881 if (interface_prefs
.highlighting_invert_all
!= old_invert_all
)
884 if (interface_prefs
.sidebar_pos
!= old_sidebar_pos
)
885 ui_swap_sidebar_pos();
887 widget
= ui_lookup_widget(main_widgets
.window
, "vpaned1");
888 gtk_orientable_set_orientation(GTK_ORIENTABLE(widget
), interface_prefs
.msgwin_orientation
);
890 /* General settings */
892 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_load_session");
893 prefs
.load_session
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
895 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_project_session");
896 project_prefs
.project_session
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
898 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_project_file_in_basedir");
899 project_prefs
.project_file_in_basedir
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
901 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_save_win_pos");
902 prefs
.save_winpos
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
904 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_ask_for_quit");
905 prefs
.confirm_exit
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
908 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_beep");
909 prefs
.beep_on_errors
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
911 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_switch_pages");
912 prefs
.switch_to_status
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
914 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_suppress_status_msgs");
915 prefs
.suppress_status_messages
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
917 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_auto_focus");
918 prefs
.auto_focus
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
920 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_native_windows_dialogs");
921 interface_prefs
.use_native_windows_dialogs
=
922 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
924 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_contextaction");
925 g_free(tool_prefs
.context_action_cmd
);
926 tool_prefs
.context_action_cmd
= g_strdup(gtk_entry_get_text(GTK_ENTRY(widget
)));
928 project_apply_prefs(); /* project file path */
931 /* Interface settings */
932 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_sidebar_visible");
933 ui_prefs
.sidebar_visible
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
935 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_list_symbol");
936 interface_prefs
.sidebar_symbol_visible
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
938 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_list_openfiles");
939 interface_prefs
.sidebar_openfiles_visible
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
941 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_long_line");
942 editor_prefs
.long_line_enabled
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
944 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "radio_long_line_line");
945 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
)))
946 editor_prefs
.long_line_type
= 0;
948 /* now only the "background" radio remains */
949 editor_prefs
.long_line_type
= 1;
951 if (editor_prefs
.long_line_column
== 0)
952 editor_prefs
.long_line_enabled
= FALSE
;
954 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_show_notebook_tabs");
955 interface_prefs
.show_notebook_tabs
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
957 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_show_tab_cross");
958 file_prefs
.show_tab_cross
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
960 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "combo_tab_editor");
961 interface_prefs
.tab_pos_editor
= gtk_combo_box_get_active(GTK_COMBO_BOX(widget
));
963 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "combo_tab_msgwin");
964 interface_prefs
.tab_pos_msgwin
= gtk_combo_box_get_active(GTK_COMBO_BOX(widget
));
966 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "combo_tab_sidebar");
967 interface_prefs
.tab_pos_sidebar
= gtk_combo_box_get_active(GTK_COMBO_BOX(widget
));
969 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_statusbar_visible");
970 interface_prefs
.statusbar_visible
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
973 /* Toolbar settings */
974 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_toolbar_show");
975 toolbar_prefs
.visible
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
976 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_toolbar_in_menu");
977 toolbar_prefs
.append_to_menu
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
979 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "radio_toolbar_style_default");
980 toolbar_prefs
.use_gtk_default_style
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
981 if (! toolbar_prefs
.use_gtk_default_style
)
983 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "radio_toolbar_imagetext");
984 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
)))
985 toolbar_prefs
.icon_style
= 2;
988 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "radio_toolbar_image");
989 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
)))
990 toolbar_prefs
.icon_style
= 0;
992 /* now only the text only radio remains, so set text only */
993 toolbar_prefs
.icon_style
= 1;
997 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "radio_toolbar_icon_default");
998 toolbar_prefs
.use_gtk_default_icon
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
999 if (! toolbar_prefs
.use_gtk_default_icon
)
1000 { toolbar_prefs
.icon_size
= GTK_ICON_SIZE_LARGE_TOOLBAR
;
1001 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "radio_toolbar_large");
1002 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
)))
1003 toolbar_prefs
.icon_size
= GTK_ICON_SIZE_LARGE_TOOLBAR
;
1006 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "radio_toolbar_small");
1007 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
)))
1008 toolbar_prefs
.icon_size
= GTK_ICON_SIZE_SMALL_TOOLBAR
;
1010 toolbar_prefs
.icon_size
= GTK_ICON_SIZE_MENU
;
1014 /* Files settings */
1015 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "radio_tab_right");
1016 file_prefs
.tab_order_ltr
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1018 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_tab_beside");
1019 file_prefs
.tab_order_beside
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1021 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "combo_new_encoding");
1022 file_prefs
.default_new_encoding
= ui_encodings_combo_box_get_active_encoding(GTK_COMBO_BOX(widget
));
1024 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_open_encoding");
1025 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
)))
1027 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "combo_open_encoding");
1028 file_prefs
.default_open_encoding
= ui_encodings_combo_box_get_active_encoding(GTK_COMBO_BOX(widget
));
1031 file_prefs
.default_open_encoding
= -1;
1033 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "combo_eol");
1034 file_prefs
.default_eol_character
= gtk_combo_box_get_active(GTK_COMBO_BOX(widget
));
1036 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_trailing_spaces");
1037 file_prefs
.strip_trailing_spaces
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1039 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_new_line");
1040 file_prefs
.final_new_line
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1042 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_ensure_convert_new_lines");
1043 file_prefs
.ensure_convert_new_lines
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1045 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_replace_tabs");
1046 file_prefs
.replace_tabs
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1049 /* Editor settings */
1050 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_toggle_mark");
1051 SETPTR(editor_prefs
.comment_toggle_mark
,
1052 gtk_editable_get_chars(GTK_EDITABLE(widget
), 0, -1));
1054 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "spin_long_line");
1055 /* note: use stash for new code - it updates spin buttons itself */
1056 gtk_spin_button_update(GTK_SPIN_BUTTON(widget
));
1057 editor_prefs
.long_line_column
= gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget
));
1059 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_folding");
1060 editor_prefs
.folding
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1061 ui_update_fold_items();
1063 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_unfold_children");
1064 editor_prefs
.unfold_all_children
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1066 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_indent");
1067 editor_prefs
.show_indent_guide
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1069 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_white_space");
1070 editor_prefs
.show_white_space
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1072 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_line_end");
1073 editor_prefs
.show_line_endings
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1075 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_line_numbers");
1076 editor_prefs
.show_linenumber_margin
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1078 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_markers_margin");
1079 editor_prefs
.show_markers_margin
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1081 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_scroll_stop_at_last_line");
1082 editor_prefs
.scroll_stop_at_last_line
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1084 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_line_wrapping");
1085 editor_prefs
.line_wrapping
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1087 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_complete_snippets");
1088 editor_prefs
.complete_snippets
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1090 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_xmltag");
1091 editor_prefs
.auto_close_xml_tags
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1093 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_indicators");
1094 editor_prefs
.use_indicators
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1096 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_disable_dnd");
1097 editor_prefs
.disable_dnd
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1099 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_smart_home");
1100 editor_prefs
.smart_home_key
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1102 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_newline_strip");
1103 editor_prefs
.newline_strip
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1105 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_auto_multiline");
1106 editor_prefs
.auto_continue_multiline
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1108 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_symbol_auto_completion");
1109 editor_prefs
.auto_complete_symbols
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1111 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "spin_symbol_complete_chars");
1112 gtk_spin_button_update(GTK_SPIN_BUTTON(widget
));
1113 editor_prefs
.symbolcompletion_min_chars
= gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget
));
1115 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "spin_symbollistheight");
1116 gtk_spin_button_update(GTK_SPIN_BUTTON(widget
));
1117 editor_prefs
.symbolcompletion_max_height
= gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget
));
1119 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "spin_line_break");
1120 gtk_spin_button_update(GTK_SPIN_BUTTON(widget
));
1121 editor_prefs
.line_break_column
= gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget
));
1123 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_autoclose_parenthesis");
1124 autoclose_brackets
[0] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1126 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_autoclose_cbracket");
1127 autoclose_brackets
[1] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1129 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_autoclose_sbracket");
1130 autoclose_brackets
[2] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1132 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_autoclose_squote");
1133 autoclose_brackets
[3] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1135 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_autoclose_dquote");
1136 autoclose_brackets
[4] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1138 editor_prefs
.autoclose_chars
=
1139 (autoclose_brackets
[0] ? GEANY_AC_PARENTHESIS
: 0u)
1140 | (autoclose_brackets
[1] ? GEANY_AC_CBRACKET
: 0u)
1141 | (autoclose_brackets
[2] ? GEANY_AC_SBRACKET
: 0u)
1142 | (autoclose_brackets
[3] ? GEANY_AC_SQUOTE
: 0u)
1143 | (autoclose_brackets
[4] ? GEANY_AC_DQUOTE
: 0u);
1145 /* Tools Settings */
1147 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_com_term");
1148 g_free(tool_prefs
.term_cmd
);
1149 tool_prefs
.term_cmd
= g_strdup(gtk_entry_get_text(GTK_ENTRY(widget
)));
1151 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_browser");
1152 g_free(tool_prefs
.browser_cmd
);
1153 tool_prefs
.browser_cmd
= g_strdup(gtk_entry_get_text(GTK_ENTRY(widget
)));
1155 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_grep");
1156 g_free(tool_prefs
.grep_cmd
);
1157 tool_prefs
.grep_cmd
= g_strdup(gtk_entry_get_text(GTK_ENTRY(widget
)));
1160 /* Template settings */
1161 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_template_developer");
1162 g_free(template_prefs
.developer
);
1163 template_prefs
.developer
= g_strdup(gtk_entry_get_text(GTK_ENTRY(widget
)));
1165 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_template_company");
1166 g_free(template_prefs
.company
);
1167 template_prefs
.company
= g_strdup(gtk_entry_get_text(GTK_ENTRY(widget
)));
1169 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_template_mail");
1170 g_free(template_prefs
.mail
);
1171 template_prefs
.mail
= g_strdup(gtk_entry_get_text(GTK_ENTRY(widget
)));
1173 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_template_initial");
1174 g_free(template_prefs
.initials
);
1175 template_prefs
.initials
= g_strdup(gtk_entry_get_text(GTK_ENTRY(widget
)));
1177 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_template_version");
1178 g_free(template_prefs
.version
);
1179 template_prefs
.version
= g_strdup(gtk_entry_get_text(GTK_ENTRY(widget
)));
1181 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_template_year");
1182 g_free(template_prefs
.year_format
);
1183 template_prefs
.year_format
= g_strdup(gtk_entry_get_text(GTK_ENTRY(widget
)));
1185 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_template_date");
1186 g_free(template_prefs
.date_format
);
1187 template_prefs
.date_format
= g_strdup(gtk_entry_get_text(GTK_ENTRY(widget
)));
1189 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_template_datetime");
1190 g_free(template_prefs
.datetime_format
);
1191 template_prefs
.datetime_format
= g_strdup(gtk_entry_get_text(GTK_ENTRY(widget
)));
1195 if (global_kb_data
.edited
)
1197 kb_update(&global_kb_data
);
1198 tools_create_insert_custom_command_menu_items();
1199 keybindings_write_to_file();
1203 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "radio_print_gtk");
1204 printing_prefs
.use_gtk_printing
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1206 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_print_external_cmd");
1207 g_free(printing_prefs
.external_print_cmd
);
1208 printing_prefs
.external_print_cmd
= g_strdup(gtk_entry_get_text(GTK_ENTRY(widget
)));
1210 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_print_linenumbers");
1211 printing_prefs
.print_line_numbers
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1213 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_print_pagenumbers");
1214 printing_prefs
.print_page_numbers
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1216 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_print_pageheader");
1217 printing_prefs
.print_page_header
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1219 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_print_basename");
1220 printing_prefs
.page_header_basename
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1222 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_print_dateformat");
1223 g_free(printing_prefs
.page_header_datefmt
);
1224 printing_prefs
.page_header_datefmt
= g_strdup(gtk_entry_get_text(GTK_ENTRY(widget
)));
1228 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_vte");
1229 vte_info
.load_vte
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1232 if (vte_info
.have_vte
)
1234 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "spin_scrollback");
1235 gtk_spin_button_update(GTK_SPIN_BUTTON(widget
));
1236 vc
->scrollback_lines
= gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget
));
1238 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_image");
1240 vc
->image
= g_strdup(gtk_entry_get_text(GTK_ENTRY(widget
)));
1242 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_shell");
1244 vc
->shell
= g_strdup(gtk_entry_get_text(GTK_ENTRY(widget
)));
1246 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_scroll_key");
1247 vc
->scroll_on_key
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1249 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_scroll_out");
1250 vc
->scroll_on_out
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1252 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_enable_bash_keys");
1253 vc
->enable_bash_keys
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1255 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_ignore_menu_key");
1256 vc
->ignore_menu_bar_accel
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1258 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_follow_path");
1259 vc
->follow_path
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1261 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_run_in_vte");
1262 vc
->run_in_vte
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1264 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_skip_script");
1265 vc
->skip_run_script
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1267 widget
= ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_cursor_blinks");
1268 vc
->cursor_blinks
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1270 vte_apply_user_settings();
1274 /* apply the changes made */
1275 ui_statusbar_showhide(interface_prefs
.statusbar_visible
);
1276 sidebar_openfiles_update_all(); /* to update if full path setting has changed */
1277 toolbar_apply_settings();
1278 toolbar_update_ui();
1279 toolbar_show_hide();
1280 ui_sidebar_show_hide();
1281 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets
.notebook
), interface_prefs
.show_notebook_tabs
);
1283 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(main_widgets
.notebook
), interface_prefs
.tab_pos_editor
);
1284 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(msgwindow
.notebook
), interface_prefs
.tab_pos_msgwin
);
1285 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(main_widgets
.sidebar_notebook
), interface_prefs
.tab_pos_sidebar
);
1287 /* re-colourise all open documents, if tab width or long line settings have changed */
1288 for (i
= 0; i
< documents_array
->len
; i
++)
1290 if (documents
[i
]->is_valid
)
1292 editor_apply_update_prefs(documents
[i
]->editor
);
1293 if (! editor_prefs
.folding
)
1294 editor_unfold_all(documents
[i
]->editor
);
1297 ui_document_show_hide(NULL
);
1298 ui_update_view_editor_menu_items();
1300 /* various preferences */
1301 ui_save_buttons_toggle((doc
!= NULL
) ? doc
->changed
: FALSE
);
1302 msgwin_show_hide_tabs();
1303 ui_update_statusbar(doc
, -1);
1305 /* store all settings */
1306 configuration_save();
1309 if (response
== GTK_RESPONSE_HELP
)
1311 open_preferences_help();
1313 else if (response
!= GTK_RESPONSE_APPLY
)
1315 gtk_tree_store_clear(global_kb_data
.store
);
1316 gtk_widget_hide(GTK_WIDGET(dialog
));
1321 static void on_color_button_choose_cb(GtkColorButton
*widget
, gpointer user_data
)
1325 gtk_color_button_get_color(widget
, &color
);
1326 SETPTR(editor_prefs
.long_line_color
, utils_get_hex_from_color(&color
));
1330 static void on_prefs_font_choosed(GtkFontButton
*widget
, gpointer user_data
)
1332 const gchar
*fontbtn
= gtk_font_button_get_font_name(widget
);
1335 switch (GPOINTER_TO_INT(user_data
))
1339 if (strcmp(fontbtn
, interface_prefs
.tagbar_font
) == 0)
1342 SETPTR(interface_prefs
.tagbar_font
, g_strdup(fontbtn
));
1343 for (i
= 0; i
< documents_array
->len
; i
++)
1345 GeanyDocument
*doc
= documents
[i
];
1347 if (documents
[i
]->is_valid
&& GTK_IS_WIDGET(doc
->priv
->tag_tree
))
1348 ui_widget_modify_font_from_string(doc
->priv
->tag_tree
,
1349 interface_prefs
.tagbar_font
);
1351 if (GTK_IS_WIDGET(tv
.default_tag_tree
))
1352 ui_widget_modify_font_from_string(tv
.default_tag_tree
, interface_prefs
.tagbar_font
);
1353 ui_widget_modify_font_from_string(tv
.tree_openfiles
, interface_prefs
.tagbar_font
);
1358 if (strcmp(fontbtn
, interface_prefs
.msgwin_font
) == 0)
1360 SETPTR(interface_prefs
.msgwin_font
, g_strdup(fontbtn
));
1361 ui_widget_modify_font_from_string(msgwindow
.tree_compiler
, interface_prefs
.msgwin_font
);
1362 ui_widget_modify_font_from_string(msgwindow
.tree_msg
, interface_prefs
.msgwin_font
);
1363 ui_widget_modify_font_from_string(msgwindow
.tree_status
, interface_prefs
.msgwin_font
);
1364 ui_widget_modify_font_from_string(msgwindow
.scribble
, interface_prefs
.msgwin_font
);
1369 ui_set_editor_font(fontbtn
);
1376 static void kb_change_iter_shortcut(KbData
*kbdata
, GtkTreeIter
*iter
, const gchar
*new_text
)
1379 GdkModifierType lmods
;
1381 gtk_accelerator_parse(new_text
, &lkey
, &lmods
);
1383 if (kb_find_duplicate(kbdata
->store
, ui_widgets
.prefs_dialog
, iter
, lkey
, lmods
, new_text
))
1386 /* set the values here, because of the above check, setting it in
1387 * gtk_accelerator_parse would return a wrong key combination if it is duplicate */
1388 kb_set_shortcut(kbdata
->store
, iter
, lkey
, lmods
);
1390 kbdata
->edited
= TRUE
;
1394 static void kb_cell_edited_cb(GtkCellRendererText
*cellrenderertext
,
1395 gchar
*path
, gchar
*new_text
, KbData
*kbdata
)
1397 if (path
!= NULL
&& new_text
!= NULL
)
1401 gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(kbdata
->store
), &iter
, path
);
1402 if (gtk_tree_model_iter_has_child(GTK_TREE_MODEL(kbdata
->store
), &iter
))
1403 return; /* ignore group items */
1405 kb_change_iter_shortcut(kbdata
, &iter
, new_text
);
1410 static gboolean
kb_grab_key_dialog_key_press_cb(GtkWidget
*dialog
, GdkEventKey
*event
, GtkLabel
*label
)
1415 g_return_val_if_fail(GTK_IS_LABEL(label
), FALSE
);
1417 state
= keybindings_get_modifiers(event
->state
);
1419 if (event
->keyval
== GDK_Escape
)
1420 return FALSE
; /* close the dialog, don't allow escape when detecting keybindings. */
1422 str
= gtk_accelerator_name(event
->keyval
, state
);
1424 gtk_label_set_text(label
, str
);
1431 /* test if the entered key combination is already used
1432 * returns true if cancelling duplicate */
1433 static gboolean
kb_find_duplicate(GtkTreeStore
*store
, GtkWidget
*parent
, GtkTreeIter
*old_iter
,
1434 guint key
, GdkModifierType mods
, const gchar
*shortcut
)
1436 GtkTreeModel
*model
= GTK_TREE_MODEL(store
);
1437 GtkTreeIter parent_iter
;
1440 GdkModifierType kb_mods
;
1442 /* allow duplicate if there is no key combination */
1443 if (key
== 0 && mods
== 0)
1446 /* don't check if the new keybinding is the same as the old one */
1447 gtk_tree_model_get(model
, old_iter
, KB_TREE_SHORTCUT
, &kb_str
, -1);
1450 gtk_accelerator_parse(kb_str
, &kb_key
, &kb_mods
);
1452 if (key
== kb_key
&& mods
== kb_mods
)
1456 if (! gtk_tree_model_get_iter_first(model
, &parent_iter
))
1458 do /* foreach top level */
1462 if (! gtk_tree_model_iter_children(model
, &iter
, &parent_iter
))
1464 do /* foreach children */
1466 gtk_tree_model_get(model
, &iter
, KB_TREE_SHORTCUT
, &kb_str
, -1);
1470 gtk_accelerator_parse(kb_str
, &kb_key
, &kb_mods
);
1472 /* search another item with the same key and modifiers */
1473 if (kb_key
== key
&& kb_mods
== mods
)
1478 gtk_tree_model_get(model
, &iter
, KB_TREE_ACTION
, &label
, -1);
1479 ret
= dialogs_show_prompt(parent
,
1480 _("_Allow"), GTK_RESPONSE_APPLY
,
1481 GTK_STOCK_CANCEL
, GTK_RESPONSE_NO
,
1482 _("_Override"), GTK_RESPONSE_YES
,
1483 _("Override that keybinding?"),
1484 _("The combination '%s' is already used for \"%s\"."),
1489 if (ret
== GTK_RESPONSE_YES
)
1491 kb_set_shortcut(store
, &iter
, 0, 0); /* clear shortcut */
1492 /* carry on looking for other duplicates if overriding */
1495 return ret
== GTK_RESPONSE_NO
;
1498 while (gtk_tree_model_iter_next(model
, &iter
));
1500 while (gtk_tree_model_iter_next(model
, &parent_iter
));
1506 static void on_toolbar_show_toggled(GtkToggleButton
*togglebutton
, gpointer user_data
)
1508 gboolean sens
= gtk_toggle_button_get_active(togglebutton
);
1510 gtk_widget_set_sensitive(
1511 ui_lookup_widget(ui_widgets
.prefs_dialog
, "frame_toolbar_style"), sens
);
1512 gtk_widget_set_sensitive(
1513 ui_lookup_widget(ui_widgets
.prefs_dialog
, "frame_toolbar_icon"), sens
);
1514 gtk_widget_set_sensitive(
1515 ui_lookup_widget(ui_widgets
.prefs_dialog
, "button_customize_toolbar"), sens
);
1516 gtk_widget_set_sensitive(
1517 ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_toolbar_in_menu"), sens
);
1521 static void on_show_notebook_tabs_toggled(GtkToggleButton
*togglebutton
, gpointer user_data
)
1523 gboolean sens
= gtk_toggle_button_get_active(togglebutton
);
1525 /* tab placement only enabled when tabs are visible */
1526 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets
.prefs_dialog
, "combo_tab_editor"), sens
);
1527 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_show_tab_cross"), sens
);
1531 static void on_use_folding_toggled(GtkToggleButton
*togglebutton
, gpointer user_data
)
1533 gboolean sens
= gtk_toggle_button_get_active(togglebutton
);
1535 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_unfold_children"), sens
);
1539 static void on_enable_plugins_toggled(GtkToggleButton
*togglebutton
, gpointer user_data
)
1541 gboolean sens
= gtk_toggle_button_get_active(togglebutton
);
1543 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets
.prefs_dialog
, "extra_plugin_path_entry"), sens
);
1544 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets
.prefs_dialog
, "extra_plugin_path_button"), sens
);
1548 static void on_open_encoding_toggled(GtkToggleButton
*togglebutton
, gpointer user_data
)
1550 gboolean sens
= gtk_toggle_button_get_active(togglebutton
);
1552 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets
.prefs_dialog
, "eventbox3"), sens
);
1553 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets
.prefs_dialog
, "label_open_encoding"), sens
);
1557 static void on_sidebar_visible_toggled(GtkToggleButton
*togglebutton
, gpointer user_data
)
1559 gboolean sens
= gtk_toggle_button_get_active(togglebutton
);
1561 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_list_openfiles"), sens
);
1562 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_list_symbol"), sens
);
1566 static void on_prefs_print_radio_button_toggled(GtkToggleButton
*togglebutton
, gpointer user_data
)
1568 gboolean sens
= gtk_toggle_button_get_active(togglebutton
);
1570 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets
.prefs_dialog
, "vbox29"), sens
);
1571 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets
.prefs_dialog
, "hbox9"), ! sens
);
1575 static void on_prefs_print_page_header_toggled(GtkToggleButton
*togglebutton
, gpointer user_data
)
1577 gboolean sens
= gtk_toggle_button_get_active(togglebutton
);
1579 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_print_basename"), sens
);
1580 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_print_dateformat"), sens
);
1584 static void open_preferences_help(void)
1587 const gchar
*label
, *suffix
= NULL
;
1588 GtkNotebook
*notebook
= GTK_NOTEBOOK(
1589 ui_lookup_widget(ui_widgets
.prefs_dialog
, "notebook2"));
1590 gint page_nr
= gtk_notebook_get_current_page(notebook
);
1591 GtkWidget
*page
= gtk_notebook_get_nth_page(notebook
, page_nr
);
1593 label
= gtk_notebook_get_tab_label_text(notebook
, page
);
1595 /* TODO Find a better way to map the current notebook page to the
1596 * corresponding chapter in the documentation, comparing translatable
1597 * strings is easy to break. Maybe attach an identifying string to the
1598 * tab label object. */
1599 if (utils_str_equal(label
, _("General")))
1600 suffix
= "#general-startup-preferences";
1601 else if (utils_str_equal(label
, _("Interface")))
1602 suffix
= "#interface-preferences";
1603 else if (utils_str_equal(label
, _("Toolbar")))
1604 suffix
= "#toolbar-preferences";
1605 else if (utils_str_equal(label
, _("Editor")))
1606 suffix
= "#editor-features-preferences";
1607 else if (utils_str_equal(label
, _("Files")))
1608 suffix
= "#files-preferences";
1609 else if (utils_str_equal(label
, _("Tools")))
1610 suffix
= "#tools-preferences";
1611 else if (utils_str_equal(label
, _("Templates")))
1612 suffix
= "#template-preferences";
1613 else if (utils_str_equal(label
, _("Keybindings")))
1614 suffix
= "#keybinding-preferences";
1615 else if (utils_str_equal(label
, _("Printing")))
1616 suffix
= "#printing-preferences";
1617 else if (utils_str_equal(label
, _("Various")))
1618 suffix
= "#various-preferences";
1619 else if (utils_str_equal(label
, _("Terminal")))
1620 suffix
= "#terminal-vte-preferences";
1622 uri
= utils_get_help_url(suffix
);
1623 utils_open_browser(uri
);
1628 static gboolean
prefs_dialog_key_press_response_cb(GtkWidget
*dialog
, GdkEventKey
*event
,
1631 GeanyKeyBinding
*kb
= keybindings_lookup_item(GEANY_KEY_GROUP_HELP
, GEANY_KEYS_HELP_HELP
);
1633 if (keybindings_check_event(event
, kb
))
1635 open_preferences_help();
1642 static void list_store_append_text(GtkListStore
*list
, const gchar
*text
)
1646 gtk_list_store_append(list
, &iter
);
1647 gtk_list_store_set(list
, &iter
, 0, text
, -1);
1651 void prefs_show_dialog(void)
1653 if (ui_widgets
.prefs_dialog
== NULL
)
1655 GtkListStore
*eol_list
;
1658 ui_widgets
.prefs_dialog
= create_prefs_dialog();
1659 gtk_widget_set_name(ui_widgets
.prefs_dialog
, "GeanyPrefsDialog");
1660 gtk_window_set_transient_for(GTK_WINDOW(ui_widgets
.prefs_dialog
), GTK_WINDOW(main_widgets
.window
));
1662 /* init the file encoding combo boxes */
1665 const gchar
*combo
, *renderer
;
1667 { "combo_new_encoding", "combo_new_encoding_renderer" },
1668 { "combo_open_encoding", "combo_open_encoding_renderer" }
1671 GtkTreeStore
*encoding_list
= encodings_encoding_store_new(FALSE
);
1673 for (i
= 0; i
< G_N_ELEMENTS(names
); i
++)
1675 GtkWidget
*combo
= ui_lookup_widget(ui_widgets
.prefs_dialog
, names
[i
].combo
);
1677 gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(combo
),
1678 ui_builder_get_object(names
[i
].renderer
),
1679 encodings_encoding_store_cell_data_func
, NULL
, NULL
);
1680 gtk_combo_box_set_model(GTK_COMBO_BOX(combo
), GTK_TREE_MODEL(encoding_list
));
1682 g_object_unref(encoding_list
);
1685 /* init the eol character combo box */
1686 eol_list
= ui_builder_get_object("eol_list");
1687 list_store_append_text(eol_list
, utils_get_eol_name(SC_EOL_CRLF
));
1688 list_store_append_text(eol_list
, utils_get_eol_name(SC_EOL_CR
));
1689 list_store_append_text(eol_list
, utils_get_eol_name(SC_EOL_LF
));
1692 /* add manually GeanyWrapLabels because they can't be added with Glade */
1694 label
= geany_wrap_label_new(_("Enter tool paths below. Tools you do not need can be left blank."));
1695 gtk_widget_show(label
);
1696 gtk_box_pack_start(GTK_BOX(ui_lookup_widget(ui_widgets
.prefs_dialog
, "vbox33")),
1697 label
, FALSE
, TRUE
, 5);
1698 /* page Templates */
1699 label
= geany_wrap_label_new(_("Set the information to be used in templates. See the documentation for details."));
1700 gtk_widget_show(label
);
1701 gtk_box_pack_start(GTK_BOX(ui_lookup_widget(ui_widgets
.prefs_dialog
, "vbox31")),
1702 label
, FALSE
, TRUE
, 5);
1703 /* page Keybindings */
1704 label
= geany_wrap_label_new(_("Here you can change keyboard shortcuts for various actions. Select one and press the Change button to enter a new shortcut, or double click on an action to edit the string representation of the shortcut directly."));
1705 gtk_widget_show(label
);
1706 gtk_box_pack_start(GTK_BOX(ui_lookup_widget(ui_widgets
.prefs_dialog
, "vbox32")),
1707 label
, FALSE
, TRUE
, 5);
1708 /* page Editor->Indentation */
1709 label
= geany_wrap_label_new(_("<i>Warning: these settings are overridden by the current project. See <b>Project->Properties</b>.</i>"));
1710 gtk_widget_show(label
);
1711 gtk_label_set_use_markup(GTK_LABEL(label
), TRUE
);
1712 gtk_misc_set_padding(GTK_MISC(label
), 6, 0);
1713 gtk_box_pack_start(GTK_BOX(ui_lookup_widget(ui_widgets
.prefs_dialog
,
1714 "label_project_indent_warning")), label
, FALSE
, TRUE
, 5);
1716 /* add the clear icon to GtkEntry widgets in the dialog */
1718 const gchar
*names
[] = {
1719 "startup_path_entry",
1720 "project_file_path_entry",
1721 "extra_plugin_path_entry",
1722 "entry_toggle_mark",
1723 /* "entry_com_make", */
1727 "entry_contextaction",
1728 "entry_template_developer",
1729 "entry_template_initial",
1730 "entry_template_mail",
1731 "entry_template_company",
1732 "entry_template_version",
1733 "entry_template_year",
1734 "entry_template_date",
1735 "entry_template_datetime",
1736 "entry_print_external_cmd",
1737 "entry_print_dateformat"};
1740 foreach_c_array(name
, names
, G_N_ELEMENTS(names
))
1741 ui_entry_add_clear_icon(GTK_ENTRY(ui_lookup_widget(ui_widgets
.prefs_dialog
, *name
)));
1745 various_treeview
= GTK_TREE_VIEW(ui_lookup_widget(ui_widgets
.prefs_dialog
,
1746 "various_treeview"));
1747 stash_tree_setup(pref_groups
, various_treeview
);
1750 vte_append_preferences_tab();
1754 gtk_widget_hide(ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_native_windows_dialogs"));
1756 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets
.prefs_dialog
, "startup_path_button"), NULL
,
1757 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER
, GTK_ENTRY(ui_lookup_widget(ui_widgets
.prefs_dialog
, "startup_path_entry")));
1758 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets
.prefs_dialog
, "extra_plugin_path_button"), NULL
,
1759 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER
, GTK_ENTRY(ui_lookup_widget(ui_widgets
.prefs_dialog
, "extra_plugin_path_entry")));
1761 g_signal_connect(ui_widgets
.prefs_dialog
, "response",
1762 G_CALLBACK(on_prefs_dialog_response
), NULL
);
1763 g_signal_connect(ui_widgets
.prefs_dialog
, "delete-event",
1764 G_CALLBACK(gtk_widget_hide_on_delete
), NULL
);
1766 g_signal_connect(ui_lookup_widget(ui_widgets
.prefs_dialog
, "tagbar_font"),
1767 "font-set", G_CALLBACK(on_prefs_font_choosed
), GINT_TO_POINTER(1));
1768 g_signal_connect(ui_lookup_widget(ui_widgets
.prefs_dialog
, "msgwin_font"),
1769 "font-set", G_CALLBACK(on_prefs_font_choosed
), GINT_TO_POINTER(2));
1770 g_signal_connect(ui_lookup_widget(ui_widgets
.prefs_dialog
, "editor_font"),
1771 "font-set", G_CALLBACK(on_prefs_font_choosed
), GINT_TO_POINTER(3));
1772 g_signal_connect(ui_lookup_widget(ui_widgets
.prefs_dialog
, "long_line_color"),
1773 "color-set", G_CALLBACK(on_color_button_choose_cb
), NULL
);
1774 /* file chooser buttons in the tools tab */
1775 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets
.prefs_dialog
, "button_term"),
1777 GTK_FILE_CHOOSER_ACTION_OPEN
,
1778 GTK_ENTRY(ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_com_term")));
1779 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets
.prefs_dialog
, "button_browser"),
1781 GTK_FILE_CHOOSER_ACTION_OPEN
,
1782 GTK_ENTRY(ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_browser")));
1783 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets
.prefs_dialog
, "button_grep"),
1785 GTK_FILE_CHOOSER_ACTION_OPEN
,
1786 GTK_ENTRY(ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_grep")));
1788 /* tools commands */
1789 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets
.prefs_dialog
, "button_contextaction"),
1791 GTK_FILE_CHOOSER_ACTION_OPEN
,
1792 GTK_ENTRY(ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_contextaction")));
1795 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets
.prefs_dialog
, "button_print_external_cmd"),
1797 GTK_FILE_CHOOSER_ACTION_OPEN
,
1798 GTK_ENTRY(ui_lookup_widget(ui_widgets
.prefs_dialog
, "entry_print_external_cmd")));
1800 g_signal_connect(ui_lookup_widget(ui_widgets
.prefs_dialog
, "radio_print_gtk"),
1801 "toggled", G_CALLBACK(on_prefs_print_radio_button_toggled
), NULL
);
1802 g_signal_connect(ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_print_pageheader"),
1803 "toggled", G_CALLBACK(on_prefs_print_page_header_toggled
), NULL
);
1805 g_signal_connect(ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_plugins"),
1806 "toggled", G_CALLBACK(on_enable_plugins_toggled
), NULL
);
1807 g_signal_connect(ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_toolbar_show"),
1808 "toggled", G_CALLBACK(on_toolbar_show_toggled
), NULL
);
1809 g_signal_connect(ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_show_notebook_tabs"),
1810 "toggled", G_CALLBACK(on_show_notebook_tabs_toggled
), NULL
);
1811 g_signal_connect(ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_folding"),
1812 "toggled", G_CALLBACK(on_use_folding_toggled
), NULL
);
1813 g_signal_connect(ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_open_encoding"),
1814 "toggled", G_CALLBACK(on_open_encoding_toggled
), NULL
);
1815 g_signal_connect(ui_lookup_widget(ui_widgets
.prefs_dialog
, "check_sidebar_visible"),
1816 "toggled", G_CALLBACK(on_sidebar_visible_toggled
), NULL
);
1818 g_signal_connect(ui_widgets
.prefs_dialog
,
1819 "key-press-event", G_CALLBACK(prefs_dialog_key_press_response_cb
), NULL
);
1822 prefs_init_dialog();
1823 gtk_window_present(GTK_WINDOW(ui_widgets
.prefs_dialog
));