Update of Russian translation
[geany-mirror.git] / src / prefs.c
blob6b7ad8a1351daa7ed8c40c8537cd683f36cab8e1
1 /*
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.
23 * @file prefs.h
24 * Preferences dialog.
28 * Preferences dialog support functions.
29 * New 'simple' prefs should use Stash code in keyfile.c - init_pref_groups().
32 #include <stdlib.h>
33 #include <string.h>
34 #include <gdk/gdkkeysyms.h>
36 #include "geany.h"
38 #include "prefs.h"
39 #include "support.h"
40 #include "dialogs.h"
41 #include "ui_utils.h"
42 #include "utils.h"
43 #include "sciwrappers.h"
44 #include "document.h"
45 #include "documentprivate.h"
46 #include "msgwindow.h"
47 #include "keyfile.h"
48 #include "keybindings.h"
49 #include "encodings.h"
50 #include "project.h"
51 #include "editor.h"
52 #include "main.h"
53 #include "sidebar.h"
54 #include "printing.h"
55 #include "geanywraplabel.h"
56 #include "templates.h"
57 #include "search.h"
58 #include "toolbar.h"
59 #include "tools.h"
60 #include "stash.h"
61 #include "keyfile.h"
62 #include "filetypes.h"
63 #include "win32.h"
65 #ifdef HAVE_VTE
66 # include "vte.h"
67 #endif
70 GeanyPrefs prefs;
71 GeanyToolPrefs tool_prefs;
74 /* keybinding globals, should be put in a struct */
75 static GtkTreeIter g_iter;
76 static GtkTreeStore *store = NULL;
77 static GtkTreeView *tree = NULL;
78 static GtkWidget *dialog_label;
79 static gboolean edited = FALSE;
81 static GtkTreeView *various_treeview = NULL;
83 static GeanyKeyBinding *kb_index(guint gidx, guint kid);
84 static void kb_cell_edited_cb(GtkCellRendererText *cellrenderertext, gchar *path, gchar *new_text, gpointer user_data);
85 static gboolean kb_grab_key_dialog_key_press_cb(GtkWidget *dialog, GdkEventKey *event, gpointer user_data);
86 static void kb_grab_key_dialog_response_cb(GtkWidget *dialog, gint response, gpointer user_data);
87 static gboolean kb_find_duplicate(GtkWidget *parent, GtkTreeIter *old_iter,
88 guint key, GdkModifierType mods, const gchar *shortcut);
89 static void on_toolbar_show_toggled(GtkToggleButton *togglebutton, gpointer user_data);
90 static void on_show_notebook_tabs_toggled(GtkToggleButton *togglebutton, gpointer user_data);
91 static void on_enable_plugins_toggled(GtkToggleButton *togglebutton, gpointer user_data);
92 static void on_use_folding_toggled(GtkToggleButton *togglebutton, gpointer user_data);
93 static void on_open_encoding_toggled(GtkToggleButton *togglebutton, gpointer user_data);
94 static void on_sidebar_visible_toggled(GtkToggleButton *togglebutton, gpointer user_data);
95 static void on_prefs_print_radio_button_toggled(GtkToggleButton *togglebutton, gpointer user_data);
96 static void on_prefs_print_page_header_toggled(GtkToggleButton *togglebutton, gpointer user_data);
97 static void open_preferences_help(void);
100 typedef enum PrefCallbackAction
102 PREF_DISPLAY,
103 PREF_UPDATE
105 PrefCallbackAction;
108 /* Synchronize Stash settings with widgets (see keyfile.c - init_pref_groups()). */
109 static void prefs_action(PrefCallbackAction action)
111 StashGroup *group;
112 guint i;
114 foreach_ptr_array(group, i, pref_groups)
116 switch (action)
118 case PREF_DISPLAY:
119 stash_group_display(group, ui_widgets.prefs_dialog);
120 break;
121 case PREF_UPDATE:
122 stash_group_update(group, ui_widgets.prefs_dialog);
123 break;
127 switch (action)
129 case PREF_DISPLAY:
130 stash_tree_display(various_treeview);
131 break;
132 case PREF_UPDATE:
133 stash_tree_update(various_treeview);
134 break;
139 enum
141 KB_TREE_ACTION,
142 KB_TREE_SHORTCUT,
143 KB_TREE_INDEX,
144 KB_TREE_EDITABLE,
145 KB_TREE_WEIGHT,
146 KB_TREE_COLUMNS
150 static void kb_tree_view_change_button_clicked_cb(GtkWidget *button, gpointer data)
152 GtkTreeModel *model;
153 GtkTreeSelection *selection;
154 gchar *name;
156 selection = gtk_tree_view_get_selection(tree);
157 if (gtk_tree_selection_get_selected(selection, &model, &g_iter))
159 if (gtk_tree_model_iter_has_child(model, &g_iter))
160 { /* double click on a section to expand or collapse it */
161 GtkTreePath *path = gtk_tree_model_get_path(model, &g_iter);
163 if (gtk_tree_view_row_expanded(tree, path))
164 gtk_tree_view_collapse_row(tree, path);
165 else
166 gtk_tree_view_expand_row(tree, path, FALSE);
168 gtk_tree_path_free(path);
169 return;
172 gtk_tree_model_get(model, &g_iter, KB_TREE_ACTION, &name, -1);
173 if (name != NULL)
175 GtkWidget *dialog;
176 GtkWidget *label;
177 gchar *str;
179 dialog = gtk_dialog_new_with_buttons(_("Grab Key"), GTK_WINDOW(ui_widgets.prefs_dialog),
180 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
181 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
182 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL);
184 str = g_strdup_printf(
185 _("Press the combination of the keys you want to use for \"%s\"."), name);
186 label = gtk_label_new(str);
187 gtk_misc_set_padding(GTK_MISC(label), 5, 10);
188 gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), label);
190 dialog_label = gtk_label_new("");
191 gtk_misc_set_padding(GTK_MISC(dialog_label), 5, 10);
192 gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), dialog_label);
194 g_signal_connect(dialog, "key-press-event",
195 G_CALLBACK(kb_grab_key_dialog_key_press_cb), NULL);
196 g_signal_connect(dialog, "response", G_CALLBACK(kb_grab_key_dialog_response_cb), NULL);
198 gtk_widget_show_all(dialog);
199 g_free(str);
200 g_free(name);
206 static void kb_expand_collapse_cb(GtkWidget *item, gpointer user_data)
208 if (user_data != NULL)
209 gtk_tree_view_expand_all(tree);
210 else
211 gtk_tree_view_collapse_all(tree);
215 static void kb_show_popup_menu(GtkWidget *widget, GdkEventButton *event)
217 GtkWidget *item;
218 static GtkWidget *menu = NULL;
219 guint button;
220 guint32 event_time;
222 if (menu == NULL)
224 menu = gtk_menu_new();
226 item = ui_image_menu_item_new(GTK_STOCK_ADD, _("_Expand All"));
227 gtk_widget_show(item);
228 gtk_container_add(GTK_CONTAINER(menu), item);
229 g_signal_connect(item, "activate", G_CALLBACK(kb_expand_collapse_cb), GINT_TO_POINTER(TRUE));
231 item = ui_image_menu_item_new(GTK_STOCK_REMOVE, _("_Collapse All"));
232 gtk_widget_show(item);
233 gtk_container_add(GTK_CONTAINER(menu), item);
234 g_signal_connect(item, "activate", G_CALLBACK(kb_expand_collapse_cb), NULL);
236 gtk_menu_attach_to_widget(GTK_MENU(menu), widget, NULL);
239 if (event != NULL)
241 button = event->button;
242 event_time = event->time;
244 else
246 button = 0;
247 event_time = gtk_get_current_event_time();
250 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, button, event_time);
254 static gboolean kb_popup_menu_cb(GtkWidget *widget, gpointer data)
256 kb_show_popup_menu(widget, NULL);
257 return TRUE;
261 static gboolean kb_tree_view_button_press_event_cb(GtkWidget *widget, GdkEventButton *event,
262 gpointer user_data)
264 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
266 kb_show_popup_menu(widget, event);
267 return TRUE;
269 else if (event->type == GDK_2BUTTON_PRESS)
271 kb_tree_view_change_button_clicked_cb(NULL, NULL);
272 return TRUE;
274 return FALSE;
278 static void kb_init_tree(void)
280 GtkCellRenderer *renderer;
281 GtkTreeViewColumn *column;
283 tree = GTK_TREE_VIEW(ui_lookup_widget(ui_widgets.prefs_dialog, "treeview7"));
285 store = gtk_tree_store_new(KB_TREE_COLUMNS,
286 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT, G_TYPE_BOOLEAN, G_TYPE_INT);
287 gtk_tree_view_set_model(GTK_TREE_VIEW(tree), GTK_TREE_MODEL(store));
288 g_object_unref(store);
290 renderer = gtk_cell_renderer_text_new();
291 column = gtk_tree_view_column_new_with_attributes(_("Action"), renderer,
292 "text", KB_TREE_ACTION, "weight", KB_TREE_WEIGHT, NULL);
293 gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
295 renderer = gtk_cell_renderer_text_new();
296 column = gtk_tree_view_column_new_with_attributes(_("Shortcut"), renderer,
297 "text", KB_TREE_SHORTCUT, "editable", KB_TREE_EDITABLE,
298 "weight", KB_TREE_WEIGHT, NULL);
299 gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
301 /* set policy settings for the scrolled window around the treeview again, because glade
302 * doesn't keep the settings */
303 gtk_scrolled_window_set_policy(
304 GTK_SCROLLED_WINDOW(ui_lookup_widget(ui_widgets.prefs_dialog, "scrolledwindow8")),
305 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
307 g_signal_connect(renderer, "edited", G_CALLBACK(kb_cell_edited_cb), NULL);
308 g_signal_connect(tree, "button-press-event", G_CALLBACK(kb_tree_view_button_press_event_cb), NULL);
309 g_signal_connect(tree, "popup-menu", G_CALLBACK(kb_popup_menu_cb), NULL);
310 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "button2"), "clicked",
311 G_CALLBACK(kb_tree_view_change_button_clicked_cb), NULL);
315 static void kb_set_shortcut(GtkTreeStore *store, GtkTreeIter *iter,
316 guint key, GdkModifierType mods)
318 gchar *key_string = gtk_accelerator_name(key, mods);
319 GtkTreeIter parent;
320 guint kid, gid;
321 GeanyKeyBinding *kb;
322 gboolean bold;
324 gtk_tree_store_set(store, iter, KB_TREE_SHORTCUT, key_string, -1);
325 g_free(key_string);
327 gtk_tree_model_get(GTK_TREE_MODEL(store), iter, KB_TREE_INDEX, &kid, -1);
328 gtk_tree_model_iter_parent(GTK_TREE_MODEL(store), &parent, iter);
329 gtk_tree_model_get(GTK_TREE_MODEL(store), &parent, KB_TREE_INDEX, &gid, -1);
330 kb = kb_index(gid, kid);
331 bold = key != kb->default_key || mods != kb->default_mods;
332 gtk_tree_store_set(store, iter, KB_TREE_WEIGHT,
333 bold ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL, -1);
337 void prefs_kb_search_name(const gchar *search)
339 GtkTreeIter iter;
340 gboolean valid;
341 GtkTreeModel *model;
343 model = gtk_tree_view_get_model(tree);
344 valid = gtk_tree_model_get_iter_first(model, &iter);
345 while (valid)
347 gchar *name;
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(tree, path, NULL, TRUE, .0f, .0f);
354 gtk_tree_path_free(path);
355 g_free(name);
356 break;
358 g_free(name);
359 valid = gtk_tree_model_iter_next(model, &iter);
364 static void kb_init(void)
366 GtkTreeIter parent, iter;
367 gsize g, i;
368 gchar *label;
369 GeanyKeyGroup *group;
370 GeanyKeyBinding *kb;
372 if (store == NULL)
373 kb_init_tree();
375 foreach_ptr_array(group, g, keybinding_groups)
377 gtk_tree_store_append(store, &parent, NULL);
378 gtk_tree_store_set(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(store, &iter, &parent);
385 gtk_tree_store_set(store, &iter, KB_TREE_ACTION, label,
386 KB_TREE_EDITABLE, TRUE, KB_TREE_INDEX, kb->id, -1);
387 kb_set_shortcut(store, &iter, kb->key, kb->mods);
388 g_free(label);
391 gtk_tree_view_expand_all(GTK_TREE_VIEW(tree));
395 /* note: new 'simple' prefs should use Stash code in keyfile.c */
396 static void prefs_init_dialog(void)
398 GtkWidget *widget;
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 */
408 /* startup */
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);
424 /* behaviour */
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);
539 /* Files settings */
540 if (file_prefs.tab_order_ltr)
541 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_tab_right");
542 else
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 /* luckily the index of the combo box items match the index of the encodings array */
551 gtk_combo_box_set_active(GTK_COMBO_BOX(widget), file_prefs.default_new_encoding);
553 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_open_encoding");
554 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),
555 (file_prefs.default_open_encoding >= 0) ? TRUE : FALSE);
556 on_open_encoding_toggled(GTK_TOGGLE_BUTTON(widget), NULL);
558 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_open_encoding");
559 if (file_prefs.default_open_encoding >= 0)
561 gtk_combo_box_set_active(GTK_COMBO_BOX(widget), file_prefs.default_open_encoding);
563 else
564 gtk_combo_box_set_active(GTK_COMBO_BOX(widget), GEANY_ENCODING_UTF_8);
566 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_eol");
567 if (file_prefs.default_eol_character >= 0 && file_prefs.default_eol_character < 3)
569 gtk_combo_box_set_active(GTK_COMBO_BOX(widget), file_prefs.default_eol_character);
571 else
572 gtk_combo_box_set_active(GTK_COMBO_BOX(widget), GEANY_DEFAULT_EOL_CHARACTER);
574 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_trailing_spaces");
575 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), file_prefs.strip_trailing_spaces);
577 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_new_line");
578 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), file_prefs.final_new_line);
580 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_ensure_convert_new_lines");
581 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), file_prefs.ensure_convert_new_lines);
583 /* Editor settings */
584 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_toggle_mark");
585 gtk_entry_set_text(GTK_ENTRY(widget), editor_prefs.comment_toggle_mark);
587 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_replace_tabs");
588 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), file_prefs.replace_tabs);
590 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_indent");
591 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.show_indent_guide);
593 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_white_space");
594 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.show_white_space);
596 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_line_end");
597 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.show_line_endings);
599 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_line_numbers");
600 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.show_linenumber_margin);
602 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_markers_margin");
603 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.show_markers_margin);
605 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_scroll_stop_at_last_line");
606 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.scroll_stop_at_last_line);
608 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_line_wrapping");
609 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.line_wrapping);
611 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_complete_snippets");
612 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.complete_snippets);
614 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_xmltag");
615 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.auto_close_xml_tags);
617 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_folding");
618 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.folding);
620 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_unfold_children");
621 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.unfold_all_children);
622 on_use_folding_toggled(GTK_TOGGLE_BUTTON(
623 ui_lookup_widget(ui_widgets.prefs_dialog, "check_folding")), NULL);
625 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_disable_dnd");
626 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.disable_dnd);
628 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_smart_home");
629 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.smart_home_key);
631 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_newline_strip");
632 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.newline_strip);
634 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_indicators");
635 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.use_indicators);
637 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_auto_multiline");
638 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.auto_continue_multiline);
640 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_symbol_auto_completion");
641 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.auto_complete_symbols);
643 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_symbollistheight");
644 gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), editor_prefs.symbolcompletion_max_height);
646 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_symbol_complete_chars");
647 gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), editor_prefs.symbolcompletion_min_chars);
649 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_line_break");
650 gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), editor_prefs.line_break_column);
652 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_autoclose_parenthesis");
653 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),
654 (editor_prefs.autoclose_chars & GEANY_AC_PARENTHESIS));
656 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_autoclose_cbracket");
657 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),
658 (editor_prefs.autoclose_chars & GEANY_AC_CBRACKET));
660 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_autoclose_sbracket");
661 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),
662 (editor_prefs.autoclose_chars & GEANY_AC_SBRACKET));
664 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_autoclose_squote");
665 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),
666 (editor_prefs.autoclose_chars & GEANY_AC_SQUOTE));
668 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_autoclose_dquote");
669 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),
670 (editor_prefs.autoclose_chars & GEANY_AC_DQUOTE));
672 /* Tools Settings */
674 if (tool_prefs.term_cmd)
675 gtk_entry_set_text(GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_com_term")), tool_prefs.term_cmd);
677 if (tool_prefs.browser_cmd)
678 gtk_entry_set_text(GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_browser")), tool_prefs.browser_cmd);
680 if (tool_prefs.grep_cmd)
681 gtk_entry_set_text(GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_grep")), tool_prefs.grep_cmd);
684 /* Template settings */
685 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_developer");
686 gtk_entry_set_text(GTK_ENTRY(widget), template_prefs.developer);
688 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_company");
689 gtk_entry_set_text(GTK_ENTRY(widget), template_prefs.company);
691 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_mail");
692 gtk_entry_set_text(GTK_ENTRY(widget), template_prefs.mail);
694 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_initial");
695 gtk_entry_set_text(GTK_ENTRY(widget), template_prefs.initials);
697 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_version");
698 gtk_entry_set_text(GTK_ENTRY(widget), template_prefs.version);
700 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_year");
701 gtk_entry_set_text(GTK_ENTRY(widget), template_prefs.year_format);
703 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_date");
704 gtk_entry_set_text(GTK_ENTRY(widget), template_prefs.date_format);
706 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_datetime");
707 gtk_entry_set_text(GTK_ENTRY(widget), template_prefs.datetime_format);
710 /* Keybindings */
711 kb_init();
713 /* Printing */
715 GtkWidget *widget_gtk = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_print_gtk");
716 if (printing_prefs.use_gtk_printing)
717 widget = widget_gtk;
718 else
719 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_print_external");
721 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
723 on_prefs_print_radio_button_toggled(GTK_TOGGLE_BUTTON(widget_gtk), NULL);
725 if (printing_prefs.external_print_cmd)
726 gtk_entry_set_text(
727 GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_print_external_cmd")),
728 printing_prefs.external_print_cmd);
730 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_print_linenumbers");
731 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), printing_prefs.print_line_numbers);
733 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_print_pagenumbers");
734 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), printing_prefs.print_page_numbers);
736 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_print_pageheader");
737 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), printing_prefs.print_page_header);
738 on_prefs_print_page_header_toggled(GTK_TOGGLE_BUTTON(widget), NULL);
740 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_print_basename");
741 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), printing_prefs.page_header_basename);
743 if (printing_prefs.page_header_datefmt)
744 gtk_entry_set_text(
745 GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_print_dateformat")),
746 printing_prefs.page_header_datefmt);
749 #ifndef HAVE_PLUGINS
750 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "check_plugins"), FALSE);
751 #endif
752 on_enable_plugins_toggled(GTK_TOGGLE_BUTTON( ui_lookup_widget(ui_widgets.prefs_dialog, "check_plugins")), NULL);
754 #ifdef HAVE_VTE
755 /* make VTE switch visible only when VTE is compiled in, it is hidden by default */
756 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_vte");
757 gtk_widget_show(widget);
758 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), vte_info.load_vte);
760 /* VTE settings */
761 if (vte_info.have_vte)
763 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "font_term");
764 gtk_font_button_set_font_name(GTK_FONT_BUTTON(widget), vc->font);
766 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "color_fore");
767 gtk_color_button_set_color(GTK_COLOR_BUTTON(widget), &vc->colour_fore);
769 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "color_back");
770 gtk_color_button_set_color(GTK_COLOR_BUTTON(widget), &vc->colour_back);
772 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_image");
773 gtk_entry_set_text(GTK_ENTRY(widget), vc->image);
775 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_scrollback");
776 gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), vc->scrollback_lines);
778 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_shell");
779 gtk_entry_set_text(GTK_ENTRY(widget), vc->shell);
781 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_scroll_key");
782 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), vc->scroll_on_key);
784 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_scroll_out");
785 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), vc->scroll_on_out);
787 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_enable_bash_keys");
788 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), vc->enable_bash_keys);
790 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_ignore_menu_key");
791 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), vc->ignore_menu_bar_accel);
793 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_follow_path");
794 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), vc->follow_path);
796 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_run_in_vte");
797 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), vc->run_in_vte);
799 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_skip_script");
800 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), vc->skip_run_script);
802 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_cursor_blinks");
803 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), vc->cursor_blinks);
805 #endif
809 /* note: uses group index, not group id, unlike keybindings_lookup_item(). */
810 static GeanyKeyBinding *kb_index(guint gidx, guint kid)
812 GeanyKeyGroup *group;
814 group = g_ptr_array_index(keybinding_groups, gidx);
815 return keybindings_get_item(group, kid);
819 /* read the treeview shortcut fields into keybindings */
820 static void kb_update(void)
822 GtkTreeModel *model = GTK_TREE_MODEL(store);
823 GtkTreeIter child, parent;
824 guint gid = 0;
826 /* get first parent */
827 if (! gtk_tree_model_iter_children(model, &parent, NULL))
828 return;
830 /* foreach parent */
831 while (TRUE)
833 /* get first child */
834 if (! gtk_tree_model_iter_children(model, &child, &parent))
835 return;
837 /* foreach child */
838 while (TRUE)
840 guint kid;
841 gchar *str;
842 guint key;
843 GdkModifierType mods;
844 GeanyKeyBinding *kb;
846 gtk_tree_model_get(model, &child, KB_TREE_INDEX, &kid, KB_TREE_SHORTCUT, &str, -1);
847 gtk_accelerator_parse(str, &key, &mods);
848 g_free(str);
849 kb = kb_index(gid, kid);
850 if (kb->key != key || kb->mods != mods)
851 keybindings_update_combo(kb, key, mods);
853 if (! gtk_tree_model_iter_next(model, &child))
854 break;
856 if (! gtk_tree_model_iter_next(model, &parent))
857 return;
858 gid++;
864 * callbacks
866 /* note: new 'simple' prefs should use Stash code in keyfile.c */
867 static void
868 on_prefs_dialog_response(GtkDialog *dialog, gint response, gpointer user_data)
870 if (response == GTK_RESPONSE_OK || response == GTK_RESPONSE_APPLY)
872 GtkWidget *widget;
873 guint i;
874 gboolean autoclose_brackets[5];
875 gboolean old_invert_all = interface_prefs.highlighting_invert_all;
876 gboolean old_sidebar_pos = interface_prefs.sidebar_pos;
877 GeanyDocument *doc = document_get_current();
879 /* Synchronize Stash settings */
880 prefs_action(PREF_UPDATE);
882 if (interface_prefs.highlighting_invert_all != old_invert_all)
883 filetypes_reload();
885 if (interface_prefs.sidebar_pos != old_sidebar_pos)
886 ui_swap_sidebar_pos();
888 widget = ui_lookup_widget(main_widgets.window, "vpaned1");
889 gtk_orientable_set_orientation(GTK_ORIENTABLE(widget), interface_prefs.msgwin_orientation);
891 /* General settings */
892 /* startup */
893 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_load_session");
894 prefs.load_session = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
896 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_project_session");
897 project_prefs.project_session = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
899 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_project_file_in_basedir");
900 project_prefs.project_file_in_basedir = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
902 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_save_win_pos");
903 prefs.save_winpos = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
905 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_ask_for_quit");
906 prefs.confirm_exit = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
908 /* behaviour */
909 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_beep");
910 prefs.beep_on_errors = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
912 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_switch_pages");
913 prefs.switch_to_status = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
915 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_suppress_status_msgs");
916 prefs.suppress_status_messages = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
918 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_auto_focus");
919 prefs.auto_focus = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
921 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_native_windows_dialogs");
922 interface_prefs.use_native_windows_dialogs =
923 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
925 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_contextaction");
926 g_free(tool_prefs.context_action_cmd);
927 tool_prefs.context_action_cmd = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
929 project_apply_prefs(); /* project file path */
932 /* Interface settings */
933 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_sidebar_visible");
934 ui_prefs.sidebar_visible = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
936 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_list_symbol");
937 interface_prefs.sidebar_symbol_visible = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
939 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_list_openfiles");
940 interface_prefs.sidebar_openfiles_visible = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
942 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_long_line");
943 editor_prefs.long_line_enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
945 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_long_line_line");
946 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
947 editor_prefs.long_line_type = 0;
948 else
949 /* now only the "background" radio remains */
950 editor_prefs.long_line_type = 1;
952 if (editor_prefs.long_line_column == 0)
953 editor_prefs.long_line_enabled = FALSE;
955 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_show_notebook_tabs");
956 interface_prefs.show_notebook_tabs = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
958 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_show_tab_cross");
959 file_prefs.show_tab_cross = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
961 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_tab_editor");
962 interface_prefs.tab_pos_editor = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
964 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_tab_msgwin");
965 interface_prefs.tab_pos_msgwin = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
967 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_tab_sidebar");
968 interface_prefs.tab_pos_sidebar = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
970 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_statusbar_visible");
971 interface_prefs.statusbar_visible = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
974 /* Toolbar settings */
975 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_toolbar_show");
976 toolbar_prefs.visible = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
977 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_toolbar_in_menu");
978 toolbar_prefs.append_to_menu = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
980 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_style_default");
981 toolbar_prefs.use_gtk_default_style = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
982 if (! toolbar_prefs.use_gtk_default_style)
984 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_imagetext");
985 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
986 toolbar_prefs.icon_style = 2;
987 else
989 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_image");
990 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
991 toolbar_prefs.icon_style = 0;
992 else
993 /* now only the text only radio remains, so set text only */
994 toolbar_prefs.icon_style = 1;
998 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_icon_default");
999 toolbar_prefs.use_gtk_default_icon = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1000 if (! toolbar_prefs.use_gtk_default_icon)
1001 { toolbar_prefs.icon_size = GTK_ICON_SIZE_LARGE_TOOLBAR;
1002 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_large");
1003 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
1004 toolbar_prefs.icon_size = GTK_ICON_SIZE_LARGE_TOOLBAR;
1005 else
1007 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_small");
1008 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
1009 toolbar_prefs.icon_size = GTK_ICON_SIZE_SMALL_TOOLBAR;
1010 else
1011 toolbar_prefs.icon_size = GTK_ICON_SIZE_MENU;
1015 /* Files settings */
1016 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_tab_right");
1017 file_prefs.tab_order_ltr = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1019 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_tab_beside");
1020 file_prefs.tab_order_beside = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1022 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_new_encoding");
1023 file_prefs.default_new_encoding = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
1025 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_open_encoding");
1026 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
1028 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_open_encoding");
1029 file_prefs.default_open_encoding = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
1031 else
1032 file_prefs.default_open_encoding = -1;
1034 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_eol");
1035 file_prefs.default_eol_character = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
1037 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_trailing_spaces");
1038 file_prefs.strip_trailing_spaces = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1040 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_new_line");
1041 file_prefs.final_new_line = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1043 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_ensure_convert_new_lines");
1044 file_prefs.ensure_convert_new_lines = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1046 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_replace_tabs");
1047 file_prefs.replace_tabs = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1050 /* Editor settings */
1051 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_toggle_mark");
1052 SETPTR(editor_prefs.comment_toggle_mark,
1053 gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1));
1055 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_long_line");
1056 /* note: use stash for new code - it updates spin buttons itself */
1057 gtk_spin_button_update(GTK_SPIN_BUTTON(widget));
1058 editor_prefs.long_line_column = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
1060 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_folding");
1061 editor_prefs.folding = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1062 ui_update_fold_items();
1064 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_unfold_children");
1065 editor_prefs.unfold_all_children = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1067 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_indent");
1068 editor_prefs.show_indent_guide = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1070 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_white_space");
1071 editor_prefs.show_white_space = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1073 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_line_end");
1074 editor_prefs.show_line_endings = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1076 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_line_numbers");
1077 editor_prefs.show_linenumber_margin = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1079 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_markers_margin");
1080 editor_prefs.show_markers_margin = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1082 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_scroll_stop_at_last_line");
1083 editor_prefs.scroll_stop_at_last_line = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1085 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_line_wrapping");
1086 editor_prefs.line_wrapping = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1088 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_complete_snippets");
1089 editor_prefs.complete_snippets = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1091 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_xmltag");
1092 editor_prefs.auto_close_xml_tags = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1094 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_indicators");
1095 editor_prefs.use_indicators = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1097 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_disable_dnd");
1098 editor_prefs.disable_dnd = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1100 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_smart_home");
1101 editor_prefs.smart_home_key = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1103 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_newline_strip");
1104 editor_prefs.newline_strip = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1106 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_auto_multiline");
1107 editor_prefs.auto_continue_multiline = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1109 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_symbol_auto_completion");
1110 editor_prefs.auto_complete_symbols = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1112 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_symbol_complete_chars");
1113 gtk_spin_button_update(GTK_SPIN_BUTTON(widget));
1114 editor_prefs.symbolcompletion_min_chars = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
1116 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_symbollistheight");
1117 gtk_spin_button_update(GTK_SPIN_BUTTON(widget));
1118 editor_prefs.symbolcompletion_max_height = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
1120 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_line_break");
1121 gtk_spin_button_update(GTK_SPIN_BUTTON(widget));
1122 editor_prefs.line_break_column = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
1124 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_autoclose_parenthesis");
1125 autoclose_brackets[0] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1127 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_autoclose_cbracket");
1128 autoclose_brackets[1] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1130 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_autoclose_sbracket");
1131 autoclose_brackets[2] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1133 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_autoclose_squote");
1134 autoclose_brackets[3] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1136 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_autoclose_dquote");
1137 autoclose_brackets[4] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1139 editor_prefs.autoclose_chars =
1140 (autoclose_brackets[0] ? GEANY_AC_PARENTHESIS : 0u)
1141 | (autoclose_brackets[1] ? GEANY_AC_CBRACKET : 0u)
1142 | (autoclose_brackets[2] ? GEANY_AC_SBRACKET : 0u)
1143 | (autoclose_brackets[3] ? GEANY_AC_SQUOTE : 0u)
1144 | (autoclose_brackets[4] ? GEANY_AC_DQUOTE : 0u);
1146 /* Tools Settings */
1148 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_com_term");
1149 g_free(tool_prefs.term_cmd);
1150 tool_prefs.term_cmd = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1152 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_browser");
1153 g_free(tool_prefs.browser_cmd);
1154 tool_prefs.browser_cmd = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1156 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_grep");
1157 g_free(tool_prefs.grep_cmd);
1158 tool_prefs.grep_cmd = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1161 /* Template settings */
1162 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_developer");
1163 g_free(template_prefs.developer);
1164 template_prefs.developer = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1166 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_company");
1167 g_free(template_prefs.company);
1168 template_prefs.company = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1170 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_mail");
1171 g_free(template_prefs.mail);
1172 template_prefs.mail = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1174 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_initial");
1175 g_free(template_prefs.initials);
1176 template_prefs.initials = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1178 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_version");
1179 g_free(template_prefs.version);
1180 template_prefs.version = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1182 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_year");
1183 g_free(template_prefs.year_format);
1184 template_prefs.year_format = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1186 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_date");
1187 g_free(template_prefs.date_format);
1188 template_prefs.date_format = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1190 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_datetime");
1191 g_free(template_prefs.datetime_format);
1192 template_prefs.datetime_format = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1195 /* Keybindings */
1196 if (edited)
1198 kb_update();
1199 tools_create_insert_custom_command_menu_items();
1200 keybindings_write_to_file();
1203 /* Printing */
1204 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_print_gtk");
1205 printing_prefs.use_gtk_printing = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1207 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_print_external_cmd");
1208 g_free(printing_prefs.external_print_cmd);
1209 printing_prefs.external_print_cmd = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1211 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_print_linenumbers");
1212 printing_prefs.print_line_numbers = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1214 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_print_pagenumbers");
1215 printing_prefs.print_page_numbers = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1217 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_print_pageheader");
1218 printing_prefs.print_page_header = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1220 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_print_basename");
1221 printing_prefs.page_header_basename = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1223 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_print_dateformat");
1224 g_free(printing_prefs.page_header_datefmt);
1225 printing_prefs.page_header_datefmt = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1228 #ifdef HAVE_VTE
1229 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_vte");
1230 vte_info.load_vte = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1232 /* VTE settings */
1233 if (vte_info.have_vte)
1235 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_scrollback");
1236 gtk_spin_button_update(GTK_SPIN_BUTTON(widget));
1237 vc->scrollback_lines = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
1239 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_image");
1240 g_free(vc->image);
1241 vc->image = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1243 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_shell");
1244 g_free(vc->shell);
1245 vc->shell = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1247 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_scroll_key");
1248 vc->scroll_on_key = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1250 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_scroll_out");
1251 vc->scroll_on_out = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1253 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_enable_bash_keys");
1254 vc->enable_bash_keys = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1256 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_ignore_menu_key");
1257 vc->ignore_menu_bar_accel = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1259 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_follow_path");
1260 vc->follow_path = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1262 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_run_in_vte");
1263 vc->run_in_vte = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1265 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_skip_script");
1266 vc->skip_run_script = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1268 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_cursor_blinks");
1269 vc->cursor_blinks = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1271 vte_apply_user_settings();
1273 #endif
1275 /* apply the changes made */
1276 ui_statusbar_showhide(interface_prefs.statusbar_visible);
1277 sidebar_openfiles_update_all(); /* to update if full path setting has changed */
1278 toolbar_apply_settings();
1279 toolbar_update_ui();
1280 toolbar_show_hide();
1281 ui_sidebar_show_hide();
1282 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets.notebook), interface_prefs.show_notebook_tabs);
1284 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(main_widgets.notebook), interface_prefs.tab_pos_editor);
1285 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(msgwindow.notebook), interface_prefs.tab_pos_msgwin);
1286 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(main_widgets.sidebar_notebook), interface_prefs.tab_pos_sidebar);
1288 /* re-colourise all open documents, if tab width or long line settings have changed */
1289 for (i = 0; i < documents_array->len; i++)
1291 if (documents[i]->is_valid)
1293 editor_apply_update_prefs(documents[i]->editor);
1294 if (! editor_prefs.folding)
1295 editor_unfold_all(documents[i]->editor);
1298 ui_document_show_hide(NULL);
1299 ui_update_view_editor_menu_items();
1301 /* various preferences */
1302 ui_save_buttons_toggle((doc != NULL) ? doc->changed : FALSE);
1303 msgwin_show_hide_tabs();
1304 ui_update_statusbar(doc, -1);
1306 /* store all settings */
1307 configuration_save();
1310 if (response == GTK_RESPONSE_HELP)
1312 open_preferences_help();
1314 else if (response != GTK_RESPONSE_APPLY)
1316 gtk_tree_store_clear(store);
1317 gtk_widget_hide(GTK_WIDGET(dialog));
1322 static void on_color_button_choose_cb(GtkColorButton *widget, gpointer user_data)
1324 GdkColor color;
1326 gtk_color_button_get_color(widget, &color);
1327 SETPTR(editor_prefs.long_line_color, utils_get_hex_from_color(&color));
1331 static void on_prefs_font_choosed(GtkFontButton *widget, gpointer user_data)
1333 const gchar *fontbtn = gtk_font_button_get_font_name(widget);
1334 guint i;
1336 switch (GPOINTER_TO_INT(user_data))
1338 case 1:
1340 if (strcmp(fontbtn, interface_prefs.tagbar_font) == 0)
1341 break;
1343 SETPTR(interface_prefs.tagbar_font, g_strdup(fontbtn));
1344 for (i = 0; i < documents_array->len; i++)
1346 GeanyDocument *doc = documents[i];
1348 if (documents[i]->is_valid && GTK_IS_WIDGET(doc->priv->tag_tree))
1349 ui_widget_modify_font_from_string(doc->priv->tag_tree,
1350 interface_prefs.tagbar_font);
1352 if (GTK_IS_WIDGET(tv.default_tag_tree))
1353 ui_widget_modify_font_from_string(tv.default_tag_tree, interface_prefs.tagbar_font);
1354 ui_widget_modify_font_from_string(tv.tree_openfiles, interface_prefs.tagbar_font);
1355 break;
1357 case 2:
1359 if (strcmp(fontbtn, interface_prefs.msgwin_font) == 0)
1360 break;
1361 SETPTR(interface_prefs.msgwin_font, g_strdup(fontbtn));
1362 ui_widget_modify_font_from_string(msgwindow.tree_compiler, interface_prefs.msgwin_font);
1363 ui_widget_modify_font_from_string(msgwindow.tree_msg, interface_prefs.msgwin_font);
1364 ui_widget_modify_font_from_string(msgwindow.tree_status, interface_prefs.msgwin_font);
1365 ui_widget_modify_font_from_string(msgwindow.scribble, interface_prefs.msgwin_font);
1366 break;
1368 case 3:
1370 ui_set_editor_font(fontbtn);
1371 break;
1377 static void kb_change_iter_shortcut(GtkTreeIter *iter, const gchar *new_text)
1379 guint lkey;
1380 GdkModifierType lmods;
1382 gtk_accelerator_parse(new_text, &lkey, &lmods);
1384 if (kb_find_duplicate(ui_widgets.prefs_dialog, iter, lkey, lmods, new_text))
1385 return;
1387 /* set the values here, because of the above check, setting it in
1388 * gtk_accelerator_parse would return a wrong key combination if it is duplicate */
1389 kb_set_shortcut(store, iter, lkey, lmods);
1391 edited = TRUE;
1395 static void kb_cell_edited_cb(GtkCellRendererText *cellrenderertext,
1396 gchar *path, gchar *new_text, gpointer user_data)
1398 if (path != NULL && new_text != NULL)
1400 GtkTreeIter iter;
1402 gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(store), &iter, path);
1403 if (gtk_tree_model_iter_has_child(GTK_TREE_MODEL(store), &iter))
1404 return; /* ignore group items */
1406 kb_change_iter_shortcut(&iter, new_text);
1411 static gboolean kb_grab_key_dialog_key_press_cb(GtkWidget *dialog, GdkEventKey *event, gpointer user_data)
1413 gchar *str;
1414 guint state;
1416 state = event->state & gtk_accelerator_get_default_mod_mask();
1418 if (event->keyval == GDK_Escape)
1419 return FALSE; /* close the dialog, don't allow escape when detecting keybindings. */
1421 str = gtk_accelerator_name(event->keyval, state);
1423 gtk_label_set_text(GTK_LABEL(dialog_label), str);
1424 g_free(str);
1426 return TRUE;
1430 static void kb_grab_key_dialog_response_cb(GtkWidget *dialog, gint response, G_GNUC_UNUSED gpointer iter)
1432 if (response == GTK_RESPONSE_ACCEPT)
1434 const gchar *new_text = gtk_label_get_text(GTK_LABEL(dialog_label));
1436 kb_change_iter_shortcut(&g_iter, new_text);
1438 gtk_widget_destroy(dialog);
1442 /* test if the entered key combination is already used
1443 * returns true if cancelling duplicate */
1444 static gboolean kb_find_duplicate(GtkWidget *parent, GtkTreeIter *old_iter,
1445 guint key, GdkModifierType mods, const gchar *shortcut)
1447 GtkTreeModel *model = GTK_TREE_MODEL(store);
1448 GtkTreeIter parent_iter;
1449 gchar *kb_str;
1450 guint kb_key;
1451 GdkModifierType kb_mods;
1453 /* allow duplicate if there is no key combination */
1454 if (key == 0 && mods == 0)
1455 return FALSE;
1457 /* don't check if the new keybinding is the same as the old one */
1458 gtk_tree_model_get(model, old_iter, KB_TREE_SHORTCUT, &kb_str, -1);
1459 if (kb_str)
1461 gtk_accelerator_parse(kb_str, &kb_key, &kb_mods);
1462 g_free(kb_str);
1463 if (key == kb_key && mods == kb_mods)
1464 return FALSE;
1467 if (! gtk_tree_model_get_iter_first(model, &parent_iter))
1468 return FALSE;
1469 do /* foreach top level */
1471 GtkTreeIter iter;
1473 if (! gtk_tree_model_iter_children(model, &iter, &parent_iter))
1474 continue;
1475 do /* foreach children */
1477 gtk_tree_model_get(model, &iter, KB_TREE_SHORTCUT, &kb_str, -1);
1478 if (! kb_str)
1479 continue;
1481 gtk_accelerator_parse(kb_str, &kb_key, &kb_mods);
1482 g_free(kb_str);
1483 /* search another item with the same key and modifiers */
1484 if (kb_key == key && kb_mods == mods)
1486 gchar *label;
1487 gint ret;
1489 gtk_tree_model_get(model, &iter, KB_TREE_ACTION, &label, -1);
1490 ret = dialogs_show_prompt(parent,
1491 _("_Allow"), GTK_RESPONSE_APPLY,
1492 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1493 _("_Override"), GTK_RESPONSE_YES,
1494 _("Override that keybinding?"),
1495 _("The combination '%s' is already used for \"%s\"."),
1496 shortcut, label);
1498 g_free(label);
1500 if (ret == GTK_RESPONSE_YES)
1502 kb_set_shortcut(store, &iter, 0, 0); /* clear shortcut */
1503 /* carry on looking for other duplicates if overriding */
1504 continue;
1506 return ret == GTK_RESPONSE_NO;
1509 while (gtk_tree_model_iter_next(model, &iter));
1511 while (gtk_tree_model_iter_next(model, &parent_iter));
1513 return FALSE;
1517 static void on_toolbar_show_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1519 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1521 gtk_widget_set_sensitive(
1522 ui_lookup_widget(ui_widgets.prefs_dialog, "frame_toolbar_style"), sens);
1523 gtk_widget_set_sensitive(
1524 ui_lookup_widget(ui_widgets.prefs_dialog, "frame_toolbar_icon"), sens);
1525 gtk_widget_set_sensitive(
1526 ui_lookup_widget(ui_widgets.prefs_dialog, "button_customize_toolbar"), sens);
1527 gtk_widget_set_sensitive(
1528 ui_lookup_widget(ui_widgets.prefs_dialog, "check_toolbar_in_menu"), sens);
1532 static void on_show_notebook_tabs_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1534 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1536 /* tab placement only enabled when tabs are visible */
1537 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "combo_tab_editor"), sens);
1538 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "check_show_tab_cross"), sens);
1542 static void on_use_folding_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1544 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1546 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "check_unfold_children"), sens);
1550 static void on_enable_plugins_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1552 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1554 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "extra_plugin_path_entry"), sens);
1555 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "extra_plugin_path_button"), sens);
1559 static void on_open_encoding_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1561 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1563 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "eventbox3"), sens);
1564 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "label_open_encoding"), sens);
1568 static void on_sidebar_visible_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1570 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1572 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "check_list_openfiles"), sens);
1573 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "check_list_symbol"), sens);
1577 static void on_prefs_print_radio_button_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1579 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1581 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "vbox29"), sens);
1582 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "hbox9"), ! sens);
1586 static void on_prefs_print_page_header_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1588 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1590 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "check_print_basename"), sens);
1591 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_print_dateformat"), sens);
1595 static void open_preferences_help(void)
1597 gchar *uri;
1598 const gchar *label, *suffix = NULL;
1599 GtkNotebook *notebook = GTK_NOTEBOOK(
1600 ui_lookup_widget(ui_widgets.prefs_dialog, "notebook2"));
1601 gint page_nr = gtk_notebook_get_current_page(notebook);
1602 GtkWidget *page = gtk_notebook_get_nth_page(notebook, page_nr);
1604 label = gtk_notebook_get_tab_label_text(notebook, page);
1606 /* TODO Find a better way to map the current notebook page to the
1607 * corresponding chapter in the documentation, comparing translatable
1608 * strings is easy to break. Maybe attach an identifying string to the
1609 * tab label object. */
1610 if (utils_str_equal(label, _("General")))
1611 suffix = "#general-startup-preferences";
1612 else if (utils_str_equal(label, _("Interface")))
1613 suffix = "#interface-preferences";
1614 else if (utils_str_equal(label, _("Toolbar")))
1615 suffix = "#toolbar-preferences";
1616 else if (utils_str_equal(label, _("Editor")))
1617 suffix = "#editor-features-preferences";
1618 else if (utils_str_equal(label, _("Files")))
1619 suffix = "#files-preferences";
1620 else if (utils_str_equal(label, _("Tools")))
1621 suffix = "#tools-preferences";
1622 else if (utils_str_equal(label, _("Templates")))
1623 suffix = "#template-preferences";
1624 else if (utils_str_equal(label, _("Keybindings")))
1625 suffix = "#keybinding-preferences";
1626 else if (utils_str_equal(label, _("Printing")))
1627 suffix = "#printing-preferences";
1628 else if (utils_str_equal(label, _("Various")))
1629 suffix = "#various-preferences";
1630 else if (utils_str_equal(label, _("Terminal")))
1631 suffix = "#terminal-vte-preferences";
1633 uri = utils_get_help_url(suffix);
1634 utils_open_browser(uri);
1635 g_free(uri);
1639 static gboolean prefs_dialog_key_press_response_cb(GtkWidget *dialog, GdkEventKey *event,
1640 gpointer data)
1642 GeanyKeyBinding *kb = keybindings_lookup_item(GEANY_KEY_GROUP_HELP, GEANY_KEYS_HELP_HELP);
1644 if (keybindings_check_event(event, kb))
1646 open_preferences_help();
1647 return TRUE;
1649 return FALSE;
1653 static void list_store_append_text(GtkListStore *list, const gchar *text)
1655 GtkTreeIter iter;
1657 gtk_list_store_append(list, &iter);
1658 gtk_list_store_set(list, &iter, 0, text, -1);
1662 void prefs_show_dialog(void)
1664 if (ui_widgets.prefs_dialog == NULL)
1666 GtkListStore *encoding_list, *eol_list;
1667 GtkWidget *label, *widget;
1668 guint i;
1669 gchar *encoding_string;
1671 ui_widgets.prefs_dialog = create_prefs_dialog();
1672 gtk_widget_set_name(ui_widgets.prefs_dialog, "GeanyPrefsDialog");
1673 gtk_window_set_transient_for(GTK_WINDOW(ui_widgets.prefs_dialog), GTK_WINDOW(main_widgets.window));
1675 /* init the file encoding combo boxes */
1676 encoding_list = ui_builder_get_object("encoding_list");
1677 for (i = 0; i < GEANY_ENCODINGS_MAX; i++)
1679 encoding_string = encodings_to_string(&encodings[i]);
1680 list_store_append_text(encoding_list, encoding_string);
1681 g_free(encoding_string);
1684 /* init the eol character combo box */
1685 eol_list = ui_builder_get_object("eol_list");
1686 list_store_append_text(eol_list, utils_get_eol_name(SC_EOL_CRLF));
1687 list_store_append_text(eol_list, utils_get_eol_name(SC_EOL_CR));
1688 list_store_append_text(eol_list, utils_get_eol_name(SC_EOL_LF));
1690 /* wet combo box wrap width after having filled the encoding to workaround
1691 * GTK bug https://bugzilla.gnome.org/show_bug.cgi?id=722388 */
1692 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_new_encoding");
1693 gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(widget), 3);
1694 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_open_encoding");
1695 gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(widget), 3);
1697 /* add manually GeanyWrapLabels because they can't be added with Glade */
1698 /* page Tools */
1699 label = geany_wrap_label_new(_("Enter tool paths below. Tools you do not need can be left blank."));
1700 gtk_widget_show(label);
1701 gtk_box_pack_start(GTK_BOX(ui_lookup_widget(ui_widgets.prefs_dialog, "vbox33")),
1702 label, FALSE, TRUE, 5);
1703 /* page Templates */
1704 label = geany_wrap_label_new(_("Set the information to be used in templates. See the documentation for details."));
1705 gtk_widget_show(label);
1706 gtk_box_pack_start(GTK_BOX(ui_lookup_widget(ui_widgets.prefs_dialog, "vbox31")),
1707 label, FALSE, TRUE, 5);
1708 /* page Keybindings */
1709 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."));
1710 gtk_widget_show(label);
1711 gtk_box_pack_start(GTK_BOX(ui_lookup_widget(ui_widgets.prefs_dialog, "vbox32")),
1712 label, FALSE, TRUE, 5);
1713 /* page Editor->Indentation */
1714 label = geany_wrap_label_new(_("<i>Warning: these settings are overridden by the current project. See <b>Project->Properties</b>.</i>"));
1715 gtk_widget_show(label);
1716 gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
1717 gtk_misc_set_padding(GTK_MISC(label), 6, 0);
1718 gtk_box_pack_start(GTK_BOX(ui_lookup_widget(ui_widgets.prefs_dialog,
1719 "label_project_indent_warning")), label, FALSE, TRUE, 5);
1721 /* add the clear icon to GtkEntry widgets in the dialog */
1723 const gchar *names[] = {
1724 "startup_path_entry",
1725 "project_file_path_entry",
1726 "extra_plugin_path_entry",
1727 "entry_toggle_mark",
1728 /* "entry_com_make", */
1729 "entry_com_term",
1730 "entry_browser",
1731 "entry_grep",
1732 "entry_contextaction",
1733 "entry_template_developer",
1734 "entry_template_initial",
1735 "entry_template_mail",
1736 "entry_template_company",
1737 "entry_template_version",
1738 "entry_template_year",
1739 "entry_template_date",
1740 "entry_template_datetime",
1741 "entry_print_external_cmd",
1742 "entry_print_dateformat"};
1743 const gchar **name;
1745 foreach_c_array(name, names, G_N_ELEMENTS(names))
1746 ui_entry_add_clear_icon(GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, *name)));
1749 /* page Various */
1750 various_treeview = GTK_TREE_VIEW(ui_lookup_widget(ui_widgets.prefs_dialog,
1751 "various_treeview"));
1752 stash_tree_setup(pref_groups, various_treeview);
1754 #ifdef HAVE_VTE
1755 vte_append_preferences_tab();
1756 #endif
1758 #ifndef G_OS_WIN32
1759 gtk_widget_hide(ui_lookup_widget(ui_widgets.prefs_dialog, "check_native_windows_dialogs"));
1760 #endif
1761 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets.prefs_dialog, "startup_path_button"), NULL,
1762 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "startup_path_entry")));
1763 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets.prefs_dialog, "extra_plugin_path_button"), NULL,
1764 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "extra_plugin_path_entry")));
1766 g_signal_connect(ui_widgets.prefs_dialog, "response",
1767 G_CALLBACK(on_prefs_dialog_response), NULL);
1768 g_signal_connect(ui_widgets.prefs_dialog, "delete-event",
1769 G_CALLBACK(gtk_widget_hide_on_delete), NULL);
1771 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "tagbar_font"),
1772 "font-set", G_CALLBACK(on_prefs_font_choosed), GINT_TO_POINTER(1));
1773 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "msgwin_font"),
1774 "font-set", G_CALLBACK(on_prefs_font_choosed), GINT_TO_POINTER(2));
1775 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "editor_font"),
1776 "font-set", G_CALLBACK(on_prefs_font_choosed), GINT_TO_POINTER(3));
1777 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "long_line_color"),
1778 "color-set", G_CALLBACK(on_color_button_choose_cb), NULL);
1779 /* file chooser buttons in the tools tab */
1780 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets.prefs_dialog, "button_term"),
1781 NULL,
1782 GTK_FILE_CHOOSER_ACTION_OPEN,
1783 GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_com_term")));
1784 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets.prefs_dialog, "button_browser"),
1785 NULL,
1786 GTK_FILE_CHOOSER_ACTION_OPEN,
1787 GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_browser")));
1788 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets.prefs_dialog, "button_grep"),
1789 NULL,
1790 GTK_FILE_CHOOSER_ACTION_OPEN,
1791 GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_grep")));
1793 /* tools commands */
1794 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets.prefs_dialog, "button_contextaction"),
1795 NULL,
1796 GTK_FILE_CHOOSER_ACTION_OPEN,
1797 GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_contextaction")));
1799 /* printing */
1800 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets.prefs_dialog, "button_print_external_cmd"),
1801 NULL,
1802 GTK_FILE_CHOOSER_ACTION_OPEN,
1803 GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_print_external_cmd")));
1805 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "radio_print_gtk"),
1806 "toggled", G_CALLBACK(on_prefs_print_radio_button_toggled), NULL);
1807 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_print_pageheader"),
1808 "toggled", G_CALLBACK(on_prefs_print_page_header_toggled), NULL);
1810 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_plugins"),
1811 "toggled", G_CALLBACK(on_enable_plugins_toggled), NULL);
1812 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_toolbar_show"),
1813 "toggled", G_CALLBACK(on_toolbar_show_toggled), NULL);
1814 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_show_notebook_tabs"),
1815 "toggled", G_CALLBACK(on_show_notebook_tabs_toggled), NULL);
1816 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_folding"),
1817 "toggled", G_CALLBACK(on_use_folding_toggled), NULL);
1818 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_open_encoding"),
1819 "toggled", G_CALLBACK(on_open_encoding_toggled), NULL);
1820 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_sidebar_visible"),
1821 "toggled", G_CALLBACK(on_sidebar_visible_toggled), NULL);
1823 g_signal_connect(ui_widgets.prefs_dialog,
1824 "key-press-event", G_CALLBACK(prefs_dialog_key_press_response_cb), NULL);
1827 prefs_init_dialog();
1828 gtk_window_present(GTK_WINDOW(ui_widgets.prefs_dialog));