Add last minute update of Italian translation
[geany-mirror.git] / src / prefs.c
blob469cecdfed24c42b60157452ed29dad075c5c9cb
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 #ifdef HAVE_CONFIG_H
33 # include "config.h"
34 #endif
36 #include "prefs.h"
38 #include "app.h"
39 #include "dialogs.h"
40 #include "documentprivate.h"
41 #include "editor.h"
42 #include "encodingsprivate.h"
43 #include "filetypes.h"
44 #include "geanywraplabel.h"
45 #include "keybindingsprivate.h"
46 #include "keyfile.h"
47 #include "msgwindow.h"
48 #include "prefs.h"
49 #include "printing.h"
50 #include "sidebar.h"
51 #include "stash.h"
52 #include "support.h"
53 #include "templates.h"
54 #include "toolbar.h"
55 #include "tools.h"
56 #include "ui_utils.h"
57 #include "utils.h"
58 #include "vte.h"
59 #include "osx.h"
61 #include "gtkcompat.h"
63 #include <stdlib.h>
64 #include <string.h>
65 #include <gdk/gdkkeysyms.h>
68 GeanyPrefs prefs;
69 GeanyToolPrefs tool_prefs;
72 typedef struct
74 GtkTreeStore *store;
75 GtkTreeView *tree;
76 gboolean edited;
78 KbData;
80 static KbData global_kb_data = { NULL, NULL, 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, KbData *kbdata);
85 static gboolean kb_grab_key_dialog_key_press_cb(GtkWidget *dialog, GdkEventKey *event, GtkLabel *label);
86 static void kb_change_iter_shortcut(KbData *kbdata, GtkTreeIter *iter, const gchar *new_text);
87 static gboolean kb_find_duplicate(GtkTreeStore *store, 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, KbData *kbdata)
152 GtkTreeModel *model;
153 GtkTreeIter iter;
154 GtkTreeSelection *selection;
155 gchar *name;
157 selection = gtk_tree_view_get_selection(kbdata->tree);
158 if (gtk_tree_selection_get_selected(selection, &model, &iter))
160 if (gtk_tree_model_iter_has_child(model, &iter))
161 { /* double click on a section to expand or collapse it */
162 GtkTreePath *path = gtk_tree_model_get_path(model, &iter);
164 if (gtk_tree_view_row_expanded(kbdata->tree, path))
165 gtk_tree_view_collapse_row(kbdata->tree, path);
166 else
167 gtk_tree_view_expand_row(kbdata->tree, path, FALSE);
169 gtk_tree_path_free(path);
170 return;
173 gtk_tree_model_get(model, &iter, KB_TREE_ACTION, &name, -1);
174 if (name != NULL)
176 GtkWidget *dialog;
177 GtkWidget *label;
178 GtkWidget *accel_label;
179 gchar *str;
181 dialog = gtk_dialog_new_with_buttons(_("Grab Key"), GTK_WINDOW(ui_widgets.prefs_dialog),
182 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
183 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
184 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL);
186 str = g_strdup_printf(
187 _("Press the combination of the keys you want to use for \"%s\"."), name);
188 label = gtk_label_new(str);
189 gtk_misc_set_padding(GTK_MISC(label), 5, 10);
190 gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), label);
192 accel_label = gtk_label_new("");
193 gtk_misc_set_padding(GTK_MISC(accel_label), 5, 10);
194 gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), accel_label);
196 g_signal_connect(dialog, "key-press-event",
197 G_CALLBACK(kb_grab_key_dialog_key_press_cb), accel_label);
199 gtk_widget_show_all(dialog);
200 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
202 const gchar *new_text = gtk_label_get_text(GTK_LABEL(accel_label));
204 kb_change_iter_shortcut(kbdata, &iter, new_text);
206 gtk_widget_destroy(dialog);
208 g_free(str);
209 g_free(name);
215 static void kb_show_popup_menu(KbData *kbdata, GtkWidget *widget, GdkEventButton *event)
217 static GtkWidget *menu = NULL;
218 guint button;
219 guint32 event_time;
221 if (menu == NULL)
223 GtkWidget *item;
225 menu = gtk_menu_new();
227 item = ui_image_menu_item_new(GTK_STOCK_ADD, _("_Expand All"));
228 gtk_widget_show(item);
229 gtk_container_add(GTK_CONTAINER(menu), item);
230 g_signal_connect_swapped(item, "activate", G_CALLBACK(gtk_tree_view_expand_all), kbdata->tree);
232 item = ui_image_menu_item_new(GTK_STOCK_REMOVE, _("_Collapse All"));
233 gtk_widget_show(item);
234 gtk_container_add(GTK_CONTAINER(menu), item);
235 g_signal_connect_swapped(item, "activate", G_CALLBACK(gtk_tree_view_collapse_all), kbdata->tree);
237 gtk_menu_attach_to_widget(GTK_MENU(menu), widget, NULL);
240 if (event != NULL)
242 button = event->button;
243 event_time = event->time;
245 else
247 button = 0;
248 event_time = gtk_get_current_event_time();
251 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, button, event_time);
255 static gboolean kb_popup_menu_cb(GtkWidget *widget, KbData *kbdata)
257 kb_show_popup_menu(kbdata, widget, NULL);
258 return TRUE;
262 static gboolean kb_tree_view_button_press_event_cb(GtkWidget *widget, GdkEventButton *event,
263 KbData *kbdata)
265 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
267 kb_show_popup_menu(kbdata, widget, event);
268 return TRUE;
270 else if (event->type == GDK_2BUTTON_PRESS)
272 kb_tree_view_change_button_clicked_cb(NULL, kbdata);
273 return TRUE;
275 return FALSE;
279 static void kb_init_tree(KbData *kbdata)
281 GtkCellRenderer *renderer;
282 GtkTreeViewColumn *column;
284 kbdata->tree = GTK_TREE_VIEW(ui_lookup_widget(ui_widgets.prefs_dialog, "treeview7"));
286 kbdata->store = gtk_tree_store_new(KB_TREE_COLUMNS,
287 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT, G_TYPE_BOOLEAN, G_TYPE_INT);
288 gtk_tree_view_set_model(GTK_TREE_VIEW(kbdata->tree), GTK_TREE_MODEL(kbdata->store));
289 g_object_unref(kbdata->store);
291 renderer = gtk_cell_renderer_text_new();
292 column = gtk_tree_view_column_new_with_attributes(_("Action"), renderer,
293 "text", KB_TREE_ACTION, "weight", KB_TREE_WEIGHT, NULL);
294 gtk_tree_view_append_column(GTK_TREE_VIEW(kbdata->tree), column);
296 renderer = gtk_cell_renderer_text_new();
297 column = gtk_tree_view_column_new_with_attributes(_("Shortcut"), renderer,
298 "text", KB_TREE_SHORTCUT, "editable", KB_TREE_EDITABLE,
299 "weight", KB_TREE_WEIGHT, NULL);
300 gtk_tree_view_append_column(GTK_TREE_VIEW(kbdata->tree), column);
302 /* set policy settings for the scrolled window around the treeview again, because glade
303 * doesn't keep the settings */
304 gtk_scrolled_window_set_policy(
305 GTK_SCROLLED_WINDOW(ui_lookup_widget(ui_widgets.prefs_dialog, "scrolledwindow8")),
306 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
308 g_signal_connect(renderer, "edited", G_CALLBACK(kb_cell_edited_cb), kbdata);
309 g_signal_connect(kbdata->tree, "button-press-event", G_CALLBACK(kb_tree_view_button_press_event_cb), kbdata);
310 g_signal_connect(kbdata->tree, "popup-menu", G_CALLBACK(kb_popup_menu_cb), kbdata);
311 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "button2"), "clicked",
312 G_CALLBACK(kb_tree_view_change_button_clicked_cb), kbdata);
316 static void kb_set_shortcut(GtkTreeStore *store, GtkTreeIter *iter,
317 guint key, GdkModifierType mods)
319 gchar *key_string = gtk_accelerator_name(key, mods);
320 GtkTreeIter parent;
321 guint kid, gid;
322 GeanyKeyBinding *kb;
323 gboolean bold;
325 gtk_tree_store_set(store, iter, KB_TREE_SHORTCUT, key_string, -1);
326 g_free(key_string);
328 gtk_tree_model_get(GTK_TREE_MODEL(store), iter, KB_TREE_INDEX, &kid, -1);
329 gtk_tree_model_iter_parent(GTK_TREE_MODEL(store), &parent, iter);
330 gtk_tree_model_get(GTK_TREE_MODEL(store), &parent, KB_TREE_INDEX, &gid, -1);
331 kb = kb_index(gid, kid);
332 bold = key != kb->default_key || mods != kb->default_mods;
333 gtk_tree_store_set(store, iter, KB_TREE_WEIGHT,
334 bold ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL, -1);
338 void prefs_kb_search_name(const gchar *search)
340 GtkTreeIter iter;
341 gboolean valid;
342 GtkTreeModel *model;
343 KbData *kbdata = &global_kb_data;
345 model = gtk_tree_view_get_model(kbdata->tree);
346 valid = gtk_tree_model_get_iter_first(model, &iter);
347 while (valid)
349 gchar *name;
351 gtk_tree_model_get(model, &iter, KB_TREE_ACTION, &name, -1);
352 if (g_strcmp0(name, search) == 0)
354 GtkTreePath *path = gtk_tree_model_get_path(model, &iter);
355 gtk_tree_view_scroll_to_cell(kbdata->tree, path, NULL, TRUE, .0f, .0f);
356 gtk_tree_path_free(path);
357 g_free(name);
358 break;
360 g_free(name);
361 valid = gtk_tree_model_iter_next(model, &iter);
366 static void kb_init(KbData *kbdata)
368 GtkTreeIter parent, iter;
369 gsize g, i;
370 gchar *label;
371 GeanyKeyGroup *group;
372 GeanyKeyBinding *kb;
374 if (kbdata->store == NULL)
375 kb_init_tree(kbdata);
377 foreach_ptr_array(group, g, keybinding_groups)
379 gtk_tree_store_append(kbdata->store, &parent, NULL);
380 gtk_tree_store_set(kbdata->store, &parent, KB_TREE_ACTION, group->label,
381 KB_TREE_INDEX, g, -1);
383 foreach_ptr_array(kb, i, group->key_items)
385 label = keybindings_get_label(kb);
386 gtk_tree_store_append(kbdata->store, &iter, &parent);
387 gtk_tree_store_set(kbdata->store, &iter, KB_TREE_ACTION, label,
388 KB_TREE_EDITABLE, TRUE, KB_TREE_INDEX, kb->id, -1);
389 kb_set_shortcut(kbdata->store, &iter, kb->key, kb->mods);
390 g_free(label);
393 gtk_tree_view_expand_all(GTK_TREE_VIEW(kbdata->tree));
397 /* note: new 'simple' prefs should use Stash code in keyfile.c */
398 static void prefs_init_dialog(void)
400 GtkWidget *widget;
401 GdkColor color = {0};
403 /* Synchronize with Stash settings */
404 prefs_action(PREF_DISPLAY);
406 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "label_project_indent_warning");
407 ui_widget_show_hide(widget, app->project != NULL);
409 /* General settings */
410 /* startup */
411 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_load_session");
412 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), prefs.load_session);
414 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_project_session");
415 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), project_prefs.project_session);
417 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_project_file_in_basedir");
418 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), project_prefs.project_file_in_basedir);
420 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_save_win_pos");
421 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), prefs.save_winpos);
423 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_save_win_geom");
424 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), prefs.save_wingeom);
426 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_ask_for_quit");
427 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), prefs.confirm_exit);
429 /* behaviour */
430 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_beep");
431 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), prefs.beep_on_errors);
433 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_switch_pages");
434 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), prefs.switch_to_status);
436 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_suppress_status_msgs");
437 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), prefs.suppress_status_messages);
439 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_auto_focus");
440 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), prefs.auto_focus);
442 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_native_windows_dialogs");
443 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),
444 interface_prefs.use_native_windows_dialogs);
446 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_contextaction");
447 gtk_entry_set_text(GTK_ENTRY(widget), tool_prefs.context_action_cmd);
449 project_setup_prefs(); /* project files path */
452 /* Interface settings */
453 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_sidebar_visible");
454 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), ui_prefs.sidebar_visible);
455 on_sidebar_visible_toggled(GTK_TOGGLE_BUTTON(widget), NULL);
457 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_list_symbol");
458 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), interface_prefs.sidebar_symbol_visible);
460 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_list_openfiles");
461 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), interface_prefs.sidebar_openfiles_visible);
463 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "tagbar_font");
464 gtk_font_button_set_font_name(GTK_FONT_BUTTON(widget), interface_prefs.tagbar_font);
466 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "msgwin_font");
467 gtk_font_button_set_font_name(GTK_FONT_BUTTON(widget), interface_prefs.msgwin_font);
469 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "editor_font");
470 gtk_font_button_set_font_name(GTK_FONT_BUTTON(widget), interface_prefs.editor_font);
472 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_long_line");
473 gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), editor_prefs.long_line_column);
475 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_long_line");
476 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.long_line_enabled);
478 switch (editor_prefs.long_line_type)
480 case 0: widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_long_line_line"); break;
481 case 1: widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_long_line_background"); break;
483 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
485 utils_parse_color(editor_prefs.long_line_color, &color);
486 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "long_line_color");
487 gtk_color_button_set_color(GTK_COLOR_BUTTON(widget), &color);
489 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_show_notebook_tabs");
490 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), interface_prefs.show_notebook_tabs);
491 /* disable following setting if notebook tabs are hidden */
492 on_show_notebook_tabs_toggled(GTK_TOGGLE_BUTTON(
493 ui_lookup_widget(ui_widgets.prefs_dialog, "check_show_notebook_tabs")), NULL);
495 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_show_tab_cross");
496 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), file_prefs.show_tab_cross);
498 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_tab_editor");
499 gtk_combo_box_set_active(GTK_COMBO_BOX(widget), interface_prefs.tab_pos_editor);
501 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_tab_msgwin");
502 gtk_combo_box_set_active(GTK_COMBO_BOX(widget), interface_prefs.tab_pos_msgwin);
504 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_tab_sidebar");
505 gtk_combo_box_set_active(GTK_COMBO_BOX(widget), interface_prefs.tab_pos_sidebar);
507 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_statusbar_visible");
508 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), interface_prefs.statusbar_visible);
511 /* Toolbar settings */
512 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_toolbar_show");
513 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), toolbar_prefs.visible);
514 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_toolbar_in_menu");
515 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), toolbar_prefs.append_to_menu);
517 switch (toolbar_prefs.icon_style)
519 case 0: widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_image"); break;
520 case 1: widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_text"); break;
521 default: widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_imagetext"); break;
523 if (toolbar_prefs.use_gtk_default_style)
524 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_style_default");
525 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
527 switch (toolbar_prefs.icon_size)
529 case GTK_ICON_SIZE_LARGE_TOOLBAR:
530 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_large"); break;
531 case GTK_ICON_SIZE_SMALL_TOOLBAR:
532 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_small"); break;
533 default: widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_verysmall"); break;
535 if (toolbar_prefs.use_gtk_default_icon)
536 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_icon_default");
537 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
539 /* disable elements if toolbar is hidden */
540 on_toolbar_show_toggled(GTK_TOGGLE_BUTTON(
541 ui_lookup_widget(ui_widgets.prefs_dialog, "check_toolbar_show")), NULL);
544 /* Files settings */
545 if (file_prefs.tab_order_ltr)
546 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_tab_right");
547 else
548 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_tab_left");
549 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
551 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_tab_beside");
552 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), file_prefs.tab_order_beside);
554 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_new_encoding");
555 ui_encodings_combo_box_set_active_encoding(GTK_COMBO_BOX(widget), file_prefs.default_new_encoding);
557 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_open_encoding");
558 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),
559 (file_prefs.default_open_encoding >= 0) ? TRUE : FALSE);
560 on_open_encoding_toggled(GTK_TOGGLE_BUTTON(widget), NULL);
562 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_open_encoding");
563 if (file_prefs.default_open_encoding >= 0)
565 ui_encodings_combo_box_set_active_encoding(GTK_COMBO_BOX(widget), file_prefs.default_open_encoding);
567 else
568 ui_encodings_combo_box_set_active_encoding(GTK_COMBO_BOX(widget), GEANY_ENCODING_UTF_8);
570 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_eol");
571 if (file_prefs.default_eol_character >= 0 && file_prefs.default_eol_character < 3)
573 gtk_combo_box_set_active(GTK_COMBO_BOX(widget), file_prefs.default_eol_character);
575 else
576 gtk_combo_box_set_active(GTK_COMBO_BOX(widget), GEANY_DEFAULT_EOL_CHARACTER);
578 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_trailing_spaces");
579 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), file_prefs.strip_trailing_spaces);
581 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_new_line");
582 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), file_prefs.final_new_line);
584 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_ensure_convert_new_lines");
585 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), file_prefs.ensure_convert_new_lines);
587 /* Editor settings */
588 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_toggle_mark");
589 gtk_entry_set_text(GTK_ENTRY(widget), editor_prefs.comment_toggle_mark);
591 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_replace_tabs");
592 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), file_prefs.replace_tabs);
594 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_indent");
595 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.show_indent_guide);
597 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_white_space");
598 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.show_white_space);
600 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_line_end");
601 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.show_line_endings);
603 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_line_numbers");
604 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.show_linenumber_margin);
606 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_markers_margin");
607 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.show_markers_margin);
609 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_scroll_stop_at_last_line");
610 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.scroll_stop_at_last_line);
612 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_line_wrapping");
613 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.line_wrapping);
615 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_complete_snippets");
616 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.complete_snippets);
618 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_xmltag");
619 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.auto_close_xml_tags);
621 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_folding");
622 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.folding);
624 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_unfold_children");
625 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.unfold_all_children);
626 on_use_folding_toggled(GTK_TOGGLE_BUTTON(
627 ui_lookup_widget(ui_widgets.prefs_dialog, "check_folding")), NULL);
629 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_disable_dnd");
630 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.disable_dnd);
632 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_smart_home");
633 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.smart_home_key);
635 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_newline_strip");
636 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.newline_strip);
638 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_indicators");
639 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.use_indicators);
641 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_auto_multiline");
642 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.auto_continue_multiline);
644 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_symbol_auto_completion");
645 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.auto_complete_symbols);
647 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_symbollistheight");
648 gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), editor_prefs.symbolcompletion_max_height);
650 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_symbol_complete_chars");
651 gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), editor_prefs.symbolcompletion_min_chars);
653 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_line_break");
654 gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), editor_prefs.line_break_column);
656 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_autoclose_parenthesis");
657 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),
658 (editor_prefs.autoclose_chars & GEANY_AC_PARENTHESIS));
660 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_autoclose_cbracket");
661 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),
662 (editor_prefs.autoclose_chars & GEANY_AC_CBRACKET));
664 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_autoclose_sbracket");
665 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),
666 (editor_prefs.autoclose_chars & GEANY_AC_SBRACKET));
668 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_autoclose_squote");
669 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),
670 (editor_prefs.autoclose_chars & GEANY_AC_SQUOTE));
672 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_autoclose_dquote");
673 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),
674 (editor_prefs.autoclose_chars & GEANY_AC_DQUOTE));
676 /* Tools Settings */
678 if (tool_prefs.term_cmd)
679 gtk_entry_set_text(GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_com_term")), tool_prefs.term_cmd);
681 if (tool_prefs.browser_cmd)
682 gtk_entry_set_text(GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_browser")), tool_prefs.browser_cmd);
684 if (tool_prefs.grep_cmd)
685 gtk_entry_set_text(GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_grep")), tool_prefs.grep_cmd);
688 /* Template settings */
689 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_developer");
690 gtk_entry_set_text(GTK_ENTRY(widget), template_prefs.developer);
692 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_company");
693 gtk_entry_set_text(GTK_ENTRY(widget), template_prefs.company);
695 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_mail");
696 gtk_entry_set_text(GTK_ENTRY(widget), template_prefs.mail);
698 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_initial");
699 gtk_entry_set_text(GTK_ENTRY(widget), template_prefs.initials);
701 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_version");
702 gtk_entry_set_text(GTK_ENTRY(widget), template_prefs.version);
704 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_year");
705 gtk_entry_set_text(GTK_ENTRY(widget), template_prefs.year_format);
707 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_date");
708 gtk_entry_set_text(GTK_ENTRY(widget), template_prefs.date_format);
710 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_datetime");
711 gtk_entry_set_text(GTK_ENTRY(widget), template_prefs.datetime_format);
714 /* Keybindings */
715 kb_init(&global_kb_data);
717 /* Printing */
719 GtkWidget *widget_gtk = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_print_gtk");
720 if (printing_prefs.use_gtk_printing)
721 widget = widget_gtk;
722 else
723 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_print_external");
725 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
727 on_prefs_print_radio_button_toggled(GTK_TOGGLE_BUTTON(widget_gtk), NULL);
729 if (printing_prefs.external_print_cmd)
730 gtk_entry_set_text(
731 GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_print_external_cmd")),
732 printing_prefs.external_print_cmd);
734 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_print_linenumbers");
735 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), printing_prefs.print_line_numbers);
737 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_print_pagenumbers");
738 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), printing_prefs.print_page_numbers);
740 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_print_pageheader");
741 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), printing_prefs.print_page_header);
742 on_prefs_print_page_header_toggled(GTK_TOGGLE_BUTTON(widget), NULL);
744 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_print_basename");
745 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), printing_prefs.page_header_basename);
747 if (printing_prefs.page_header_datefmt)
748 gtk_entry_set_text(
749 GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_print_dateformat")),
750 printing_prefs.page_header_datefmt);
753 #ifndef HAVE_PLUGINS
754 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "check_plugins"), FALSE);
755 #endif
756 on_enable_plugins_toggled(GTK_TOGGLE_BUTTON( ui_lookup_widget(ui_widgets.prefs_dialog, "check_plugins")), NULL);
758 #ifdef HAVE_VTE
759 /* make VTE switch visible only when VTE is compiled in, it is hidden by default */
760 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_vte");
761 gtk_widget_show(widget);
762 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), vte_info.load_vte);
764 /* VTE settings */
765 if (vte_info.have_vte)
767 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "font_term");
768 gtk_font_button_set_font_name(GTK_FONT_BUTTON(widget), vc->font);
770 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "color_fore");
771 gtk_color_button_set_color(GTK_COLOR_BUTTON(widget), &vc->colour_fore);
773 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "color_back");
774 gtk_color_button_set_color(GTK_COLOR_BUTTON(widget), &vc->colour_back);
776 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_scrollback");
777 gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), vc->scrollback_lines);
779 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_shell");
780 gtk_entry_set_text(GTK_ENTRY(widget), vc->shell);
782 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_scroll_key");
783 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), vc->scroll_on_key);
785 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_scroll_out");
786 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), vc->scroll_on_out);
788 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_enable_bash_keys");
789 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), vc->enable_bash_keys);
791 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_ignore_menu_key");
792 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), vc->ignore_menu_bar_accel);
794 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_follow_path");
795 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), vc->follow_path);
797 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_run_in_vte");
798 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), vc->run_in_vte);
800 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_skip_script");
801 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), vc->skip_run_script);
803 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_cursor_blinks");
804 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), vc->cursor_blinks);
806 #endif
810 /* note: uses group index, not group id, unlike keybindings_lookup_item(). */
811 static GeanyKeyBinding *kb_index(guint gidx, guint kid)
813 GeanyKeyGroup *group;
815 group = g_ptr_array_index(keybinding_groups, gidx);
816 return keybindings_get_item(group, kid);
820 /* read the treeview shortcut fields into keybindings */
821 static void kb_update(KbData *kbdata)
823 GtkTreeModel *model = GTK_TREE_MODEL(kbdata->store);
824 GtkTreeIter child, parent;
825 guint gid = 0;
827 /* get first parent */
828 if (! gtk_tree_model_iter_children(model, &parent, NULL))
829 return;
831 /* foreach parent */
832 while (TRUE)
834 /* get first child */
835 if (! gtk_tree_model_iter_children(model, &child, &parent))
836 return;
838 /* foreach child */
839 while (TRUE)
841 guint kid;
842 gchar *str;
843 guint key;
844 GdkModifierType mods;
845 GeanyKeyBinding *kb;
847 gtk_tree_model_get(model, &child, KB_TREE_INDEX, &kid, KB_TREE_SHORTCUT, &str, -1);
848 gtk_accelerator_parse(str, &key, &mods);
849 g_free(str);
850 kb = kb_index(gid, kid);
851 if (kb->key != key || kb->mods != mods)
852 keybindings_update_combo(kb, key, mods);
854 if (! gtk_tree_model_iter_next(model, &child))
855 break;
857 if (! gtk_tree_model_iter_next(model, &parent))
858 return;
859 gid++;
865 * callbacks
867 /* note: new 'simple' prefs should use Stash code in keyfile.c */
868 static void
869 on_prefs_dialog_response(GtkDialog *dialog, gint response, gpointer user_data)
871 if (response == GTK_RESPONSE_OK || response == GTK_RESPONSE_APPLY)
873 GtkWidget *widget;
874 guint i;
875 gboolean autoclose_brackets[5];
876 gboolean old_invert_all = interface_prefs.highlighting_invert_all;
877 gboolean old_sidebar_pos = interface_prefs.sidebar_pos;
878 GeanyDocument *doc = document_get_current();
880 /* Synchronize Stash settings */
881 prefs_action(PREF_UPDATE);
883 if (interface_prefs.highlighting_invert_all != old_invert_all)
884 filetypes_reload();
886 if (interface_prefs.sidebar_pos != old_sidebar_pos)
887 ui_swap_sidebar_pos();
889 widget = ui_lookup_widget(main_widgets.window, "vpaned1");
890 gtk_orientable_set_orientation(GTK_ORIENTABLE(widget), interface_prefs.msgwin_orientation);
892 /* General settings */
893 /* startup */
894 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_load_session");
895 prefs.load_session = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
897 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_project_session");
898 project_prefs.project_session = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
900 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_project_file_in_basedir");
901 project_prefs.project_file_in_basedir = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
903 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_save_win_pos");
904 prefs.save_winpos = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
906 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_save_win_geom");
907 prefs.save_wingeom = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
909 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_ask_for_quit");
910 prefs.confirm_exit = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
912 /* behaviour */
913 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_beep");
914 prefs.beep_on_errors = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
916 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_switch_pages");
917 prefs.switch_to_status = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
919 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_suppress_status_msgs");
920 prefs.suppress_status_messages = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
922 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_auto_focus");
923 prefs.auto_focus = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
925 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_native_windows_dialogs");
926 interface_prefs.use_native_windows_dialogs =
927 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
929 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_contextaction");
930 g_free(tool_prefs.context_action_cmd);
931 tool_prefs.context_action_cmd = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
933 project_apply_prefs(); /* project file path */
936 /* Interface settings */
937 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_sidebar_visible");
938 ui_prefs.sidebar_visible = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
940 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_list_symbol");
941 interface_prefs.sidebar_symbol_visible = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
943 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_list_openfiles");
944 interface_prefs.sidebar_openfiles_visible = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
946 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_long_line");
947 editor_prefs.long_line_enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
949 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_long_line_line");
950 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
951 editor_prefs.long_line_type = 0;
952 else
953 /* now only the "background" radio remains */
954 editor_prefs.long_line_type = 1;
956 if (editor_prefs.long_line_column == 0)
957 editor_prefs.long_line_enabled = FALSE;
959 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_show_notebook_tabs");
960 interface_prefs.show_notebook_tabs = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
962 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_show_tab_cross");
963 file_prefs.show_tab_cross = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
965 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_tab_editor");
966 interface_prefs.tab_pos_editor = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
968 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_tab_msgwin");
969 interface_prefs.tab_pos_msgwin = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
971 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_tab_sidebar");
972 interface_prefs.tab_pos_sidebar = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
974 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_statusbar_visible");
975 interface_prefs.statusbar_visible = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
978 /* Toolbar settings */
979 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_toolbar_show");
980 toolbar_prefs.visible = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
981 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_toolbar_in_menu");
982 toolbar_prefs.append_to_menu = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
984 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_style_default");
985 toolbar_prefs.use_gtk_default_style = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
986 if (! toolbar_prefs.use_gtk_default_style)
988 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_imagetext");
989 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
990 toolbar_prefs.icon_style = 2;
991 else
993 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_image");
994 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
995 toolbar_prefs.icon_style = 0;
996 else
997 /* now only the text only radio remains, so set text only */
998 toolbar_prefs.icon_style = 1;
1002 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_icon_default");
1003 toolbar_prefs.use_gtk_default_icon = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1004 if (! toolbar_prefs.use_gtk_default_icon)
1005 { toolbar_prefs.icon_size = GTK_ICON_SIZE_LARGE_TOOLBAR;
1006 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_large");
1007 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
1008 toolbar_prefs.icon_size = GTK_ICON_SIZE_LARGE_TOOLBAR;
1009 else
1011 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_small");
1012 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
1013 toolbar_prefs.icon_size = GTK_ICON_SIZE_SMALL_TOOLBAR;
1014 else
1015 toolbar_prefs.icon_size = GTK_ICON_SIZE_MENU;
1019 /* Files settings */
1020 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_tab_right");
1021 file_prefs.tab_order_ltr = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1023 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_tab_beside");
1024 file_prefs.tab_order_beside = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1026 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_new_encoding");
1027 file_prefs.default_new_encoding = ui_encodings_combo_box_get_active_encoding(GTK_COMBO_BOX(widget));
1029 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_open_encoding");
1030 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
1032 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_open_encoding");
1033 file_prefs.default_open_encoding = ui_encodings_combo_box_get_active_encoding(GTK_COMBO_BOX(widget));
1035 else
1036 file_prefs.default_open_encoding = -1;
1038 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_eol");
1039 file_prefs.default_eol_character = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
1041 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_trailing_spaces");
1042 file_prefs.strip_trailing_spaces = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1044 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_new_line");
1045 file_prefs.final_new_line = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1047 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_ensure_convert_new_lines");
1048 file_prefs.ensure_convert_new_lines = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1050 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_replace_tabs");
1051 file_prefs.replace_tabs = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1054 /* Editor settings */
1055 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_toggle_mark");
1056 SETPTR(editor_prefs.comment_toggle_mark,
1057 gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1));
1059 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_long_line");
1060 /* note: use stash for new code - it updates spin buttons itself */
1061 gtk_spin_button_update(GTK_SPIN_BUTTON(widget));
1062 editor_prefs.long_line_column = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
1064 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_folding");
1065 editor_prefs.folding = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1066 ui_update_fold_items();
1068 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_unfold_children");
1069 editor_prefs.unfold_all_children = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1071 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_indent");
1072 editor_prefs.show_indent_guide = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1074 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_white_space");
1075 editor_prefs.show_white_space = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1077 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_line_end");
1078 editor_prefs.show_line_endings = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1080 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_line_numbers");
1081 editor_prefs.show_linenumber_margin = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1083 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_markers_margin");
1084 editor_prefs.show_markers_margin = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1086 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_scroll_stop_at_last_line");
1087 editor_prefs.scroll_stop_at_last_line = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1089 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_line_wrapping");
1090 editor_prefs.line_wrapping = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1092 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_complete_snippets");
1093 editor_prefs.complete_snippets = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1095 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_xmltag");
1096 editor_prefs.auto_close_xml_tags = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1098 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_indicators");
1099 editor_prefs.use_indicators = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1101 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_disable_dnd");
1102 editor_prefs.disable_dnd = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1104 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_smart_home");
1105 editor_prefs.smart_home_key = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1107 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_newline_strip");
1108 editor_prefs.newline_strip = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1110 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_auto_multiline");
1111 editor_prefs.auto_continue_multiline = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1113 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_symbol_auto_completion");
1114 editor_prefs.auto_complete_symbols = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1116 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_symbol_complete_chars");
1117 gtk_spin_button_update(GTK_SPIN_BUTTON(widget));
1118 editor_prefs.symbolcompletion_min_chars = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
1120 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_symbollistheight");
1121 gtk_spin_button_update(GTK_SPIN_BUTTON(widget));
1122 editor_prefs.symbolcompletion_max_height = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
1124 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_line_break");
1125 gtk_spin_button_update(GTK_SPIN_BUTTON(widget));
1126 editor_prefs.line_break_column = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
1128 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_autoclose_parenthesis");
1129 autoclose_brackets[0] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1131 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_autoclose_cbracket");
1132 autoclose_brackets[1] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1134 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_autoclose_sbracket");
1135 autoclose_brackets[2] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1137 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_autoclose_squote");
1138 autoclose_brackets[3] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1140 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_autoclose_dquote");
1141 autoclose_brackets[4] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1143 editor_prefs.autoclose_chars =
1144 (autoclose_brackets[0] ? GEANY_AC_PARENTHESIS : 0u)
1145 | (autoclose_brackets[1] ? GEANY_AC_CBRACKET : 0u)
1146 | (autoclose_brackets[2] ? GEANY_AC_SBRACKET : 0u)
1147 | (autoclose_brackets[3] ? GEANY_AC_SQUOTE : 0u)
1148 | (autoclose_brackets[4] ? GEANY_AC_DQUOTE : 0u);
1150 /* Tools Settings */
1152 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_com_term");
1153 g_free(tool_prefs.term_cmd);
1154 tool_prefs.term_cmd = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1156 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_browser");
1157 g_free(tool_prefs.browser_cmd);
1158 tool_prefs.browser_cmd = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1160 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_grep");
1161 g_free(tool_prefs.grep_cmd);
1162 tool_prefs.grep_cmd = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1165 /* Template settings */
1166 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_developer");
1167 g_free(template_prefs.developer);
1168 template_prefs.developer = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1170 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_company");
1171 g_free(template_prefs.company);
1172 template_prefs.company = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1174 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_mail");
1175 g_free(template_prefs.mail);
1176 template_prefs.mail = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1178 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_initial");
1179 g_free(template_prefs.initials);
1180 template_prefs.initials = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1182 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_version");
1183 g_free(template_prefs.version);
1184 template_prefs.version = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1186 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_year");
1187 g_free(template_prefs.year_format);
1188 template_prefs.year_format = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1190 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_date");
1191 g_free(template_prefs.date_format);
1192 template_prefs.date_format = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1194 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_datetime");
1195 g_free(template_prefs.datetime_format);
1196 template_prefs.datetime_format = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1199 /* Keybindings */
1200 if (global_kb_data.edited)
1202 kb_update(&global_kb_data);
1203 tools_create_insert_custom_command_menu_items();
1204 keybindings_write_to_file();
1205 #ifdef MAC_INTEGRATION
1206 /* Force re-syncing the menubar to update displayed keybindings. */
1207 gtkosx_application_sync_menubar(gtkosx_application_get());
1208 #endif
1211 /* Printing */
1212 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_print_gtk");
1213 printing_prefs.use_gtk_printing = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1215 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_print_external_cmd");
1216 g_free(printing_prefs.external_print_cmd);
1217 printing_prefs.external_print_cmd = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1219 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_print_linenumbers");
1220 printing_prefs.print_line_numbers = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1222 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_print_pagenumbers");
1223 printing_prefs.print_page_numbers = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1225 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_print_pageheader");
1226 printing_prefs.print_page_header = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1228 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_print_basename");
1229 printing_prefs.page_header_basename = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1231 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_print_dateformat");
1232 g_free(printing_prefs.page_header_datefmt);
1233 printing_prefs.page_header_datefmt = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1236 #ifdef HAVE_VTE
1237 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_vte");
1238 vte_info.load_vte = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1240 /* VTE settings */
1241 if (vte_info.have_vte)
1243 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_scrollback");
1244 gtk_spin_button_update(GTK_SPIN_BUTTON(widget));
1245 vc->scrollback_lines = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
1247 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_shell");
1248 g_free(vc->shell);
1249 vc->shell = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1251 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_scroll_key");
1252 vc->scroll_on_key = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1254 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_scroll_out");
1255 vc->scroll_on_out = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1257 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_enable_bash_keys");
1258 vc->enable_bash_keys = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1260 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_ignore_menu_key");
1261 vc->ignore_menu_bar_accel = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1263 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_follow_path");
1264 vc->follow_path = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1266 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_run_in_vte");
1267 vc->run_in_vte = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1269 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_skip_script");
1270 vc->skip_run_script = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1272 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_cursor_blinks");
1273 vc->cursor_blinks = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1275 vte_apply_user_settings();
1277 #endif
1279 /* apply the changes made */
1280 ui_statusbar_showhide(interface_prefs.statusbar_visible);
1281 sidebar_openfiles_update_all(); /* to update if full path setting has changed */
1282 toolbar_apply_settings();
1283 toolbar_update_ui();
1284 toolbar_show_hide();
1285 ui_sidebar_show_hide();
1286 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets.notebook), interface_prefs.show_notebook_tabs);
1288 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(main_widgets.notebook), interface_prefs.tab_pos_editor);
1289 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(msgwindow.notebook), interface_prefs.tab_pos_msgwin);
1290 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(main_widgets.sidebar_notebook), interface_prefs.tab_pos_sidebar);
1292 /* re-colourise all open documents, if tab width or long line settings have changed */
1293 for (i = 0; i < documents_array->len; i++)
1295 if (documents[i]->is_valid)
1297 editor_apply_update_prefs(documents[i]->editor);
1298 if (! editor_prefs.folding)
1299 editor_unfold_all(documents[i]->editor);
1302 ui_document_show_hide(NULL);
1303 ui_update_view_editor_menu_items();
1305 /* various preferences */
1306 ui_save_buttons_toggle((doc != NULL) ? doc->changed : FALSE);
1307 msgwin_show_hide_tabs();
1308 ui_update_statusbar(doc, -1);
1310 /* store all settings */
1311 configuration_save();
1314 if (response == GTK_RESPONSE_HELP)
1316 open_preferences_help();
1318 else if (response != GTK_RESPONSE_APPLY)
1320 gtk_tree_store_clear(global_kb_data.store);
1321 gtk_widget_hide(GTK_WIDGET(dialog));
1326 static void on_color_button_choose_cb(GtkColorButton *widget, gpointer user_data)
1328 GdkColor color;
1330 gtk_color_button_get_color(widget, &color);
1331 SETPTR(editor_prefs.long_line_color, utils_get_hex_from_color(&color));
1335 static void on_prefs_font_choosed(GtkFontButton *widget, gpointer user_data)
1337 const gchar *fontbtn = gtk_font_button_get_font_name(widget);
1338 guint i;
1340 switch (GPOINTER_TO_INT(user_data))
1342 case 1:
1344 if (strcmp(fontbtn, interface_prefs.tagbar_font) == 0)
1345 break;
1347 SETPTR(interface_prefs.tagbar_font, g_strdup(fontbtn));
1348 for (i = 0; i < documents_array->len; i++)
1350 GeanyDocument *doc = documents[i];
1352 if (documents[i]->is_valid && GTK_IS_WIDGET(doc->priv->tag_tree))
1353 ui_widget_modify_font_from_string(doc->priv->tag_tree,
1354 interface_prefs.tagbar_font);
1356 if (GTK_IS_WIDGET(tv.default_tag_tree))
1357 ui_widget_modify_font_from_string(tv.default_tag_tree, interface_prefs.tagbar_font);
1358 ui_widget_modify_font_from_string(tv.tree_openfiles, interface_prefs.tagbar_font);
1359 break;
1361 case 2:
1363 if (strcmp(fontbtn, interface_prefs.msgwin_font) == 0)
1364 break;
1365 SETPTR(interface_prefs.msgwin_font, g_strdup(fontbtn));
1366 ui_widget_modify_font_from_string(msgwindow.tree_compiler, interface_prefs.msgwin_font);
1367 ui_widget_modify_font_from_string(msgwindow.tree_msg, interface_prefs.msgwin_font);
1368 ui_widget_modify_font_from_string(msgwindow.tree_status, interface_prefs.msgwin_font);
1369 ui_widget_modify_font_from_string(msgwindow.scribble, interface_prefs.msgwin_font);
1370 break;
1372 case 3:
1374 ui_set_editor_font(fontbtn);
1375 break;
1381 static void kb_change_iter_shortcut(KbData *kbdata, GtkTreeIter *iter, const gchar *new_text)
1383 guint lkey;
1384 GdkModifierType lmods;
1386 gtk_accelerator_parse(new_text, &lkey, &lmods);
1388 if (kb_find_duplicate(kbdata->store, ui_widgets.prefs_dialog, iter, lkey, lmods, new_text))
1389 return;
1391 /* set the values here, because of the above check, setting it in
1392 * gtk_accelerator_parse would return a wrong key combination if it is duplicate */
1393 kb_set_shortcut(kbdata->store, iter, lkey, lmods);
1395 kbdata->edited = TRUE;
1399 static void kb_cell_edited_cb(GtkCellRendererText *cellrenderertext,
1400 gchar *path, gchar *new_text, KbData *kbdata)
1402 if (path != NULL && new_text != NULL)
1404 GtkTreeIter iter;
1406 gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(kbdata->store), &iter, path);
1407 if (gtk_tree_model_iter_has_child(GTK_TREE_MODEL(kbdata->store), &iter))
1408 return; /* ignore group items */
1410 kb_change_iter_shortcut(kbdata, &iter, new_text);
1415 static gboolean kb_grab_key_dialog_key_press_cb(GtkWidget *dialog, GdkEventKey *event, GtkLabel *label)
1417 gchar *str;
1418 guint state;
1420 g_return_val_if_fail(GTK_IS_LABEL(label), FALSE);
1422 state = keybindings_get_modifiers(event->state);
1424 if (event->keyval == GDK_Escape)
1425 return FALSE; /* close the dialog, don't allow escape when detecting keybindings. */
1427 str = gtk_accelerator_name(event->keyval, state);
1429 gtk_label_set_text(label, str);
1430 g_free(str);
1432 return TRUE;
1436 /* test if the entered key combination is already used
1437 * returns true if cancelling duplicate */
1438 static gboolean kb_find_duplicate(GtkTreeStore *store, GtkWidget *parent, GtkTreeIter *old_iter,
1439 guint key, GdkModifierType mods, const gchar *shortcut)
1441 GtkTreeModel *model = GTK_TREE_MODEL(store);
1442 GtkTreeIter parent_iter;
1443 gchar *kb_str;
1444 guint kb_key;
1445 GdkModifierType kb_mods;
1447 /* allow duplicate if there is no key combination */
1448 if (key == 0 && mods == 0)
1449 return FALSE;
1451 /* don't check if the new keybinding is the same as the old one */
1452 gtk_tree_model_get(model, old_iter, KB_TREE_SHORTCUT, &kb_str, -1);
1453 if (kb_str)
1455 gtk_accelerator_parse(kb_str, &kb_key, &kb_mods);
1456 g_free(kb_str);
1457 if (key == kb_key && mods == kb_mods)
1458 return FALSE;
1461 if (! gtk_tree_model_get_iter_first(model, &parent_iter))
1462 return FALSE;
1463 do /* foreach top level */
1465 GtkTreeIter iter;
1467 if (! gtk_tree_model_iter_children(model, &iter, &parent_iter))
1468 continue;
1469 do /* foreach children */
1471 gtk_tree_model_get(model, &iter, KB_TREE_SHORTCUT, &kb_str, -1);
1472 if (! kb_str)
1473 continue;
1475 gtk_accelerator_parse(kb_str, &kb_key, &kb_mods);
1476 g_free(kb_str);
1477 /* search another item with the same key and modifiers */
1478 if (kb_key == key && kb_mods == mods)
1480 gchar *label;
1481 gint ret;
1483 gtk_tree_model_get(model, &iter, KB_TREE_ACTION, &label, -1);
1484 ret = dialogs_show_prompt(parent,
1485 _("_Allow"), GTK_RESPONSE_APPLY,
1486 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1487 _("_Override"), GTK_RESPONSE_YES,
1488 _("Override that keybinding?"),
1489 _("The combination '%s' is already used for \"%s\"."),
1490 shortcut, label);
1492 g_free(label);
1494 if (ret == GTK_RESPONSE_YES)
1496 kb_set_shortcut(store, &iter, 0, 0); /* clear shortcut */
1497 /* carry on looking for other duplicates if overriding */
1498 continue;
1500 return ret != GTK_RESPONSE_APPLY;
1503 while (gtk_tree_model_iter_next(model, &iter));
1505 while (gtk_tree_model_iter_next(model, &parent_iter));
1507 return FALSE;
1511 static void on_toolbar_show_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1513 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1515 gtk_widget_set_sensitive(
1516 ui_lookup_widget(ui_widgets.prefs_dialog, "frame_toolbar_style"), sens);
1517 gtk_widget_set_sensitive(
1518 ui_lookup_widget(ui_widgets.prefs_dialog, "frame_toolbar_icon"), sens);
1519 gtk_widget_set_sensitive(
1520 ui_lookup_widget(ui_widgets.prefs_dialog, "button_customize_toolbar"), sens);
1521 gtk_widget_set_sensitive(
1522 ui_lookup_widget(ui_widgets.prefs_dialog, "check_toolbar_in_menu"), sens);
1526 static void on_show_notebook_tabs_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1528 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1530 /* tab placement only enabled when tabs are visible */
1531 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "combo_tab_editor"), sens);
1532 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "check_show_tab_cross"), sens);
1536 static void on_use_folding_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1538 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1540 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "check_unfold_children"), sens);
1544 static void on_enable_plugins_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1546 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1548 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "extra_plugin_path_entry"), sens);
1549 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "extra_plugin_path_button"), sens);
1553 static void on_open_encoding_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1555 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1557 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "eventbox3"), sens);
1558 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "label_open_encoding"), sens);
1562 static void on_sidebar_visible_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1564 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1566 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "box_sidebar_visible_children"), sens);
1570 static void on_prefs_print_radio_button_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1572 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1574 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "vbox29"), sens);
1575 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "hbox9"), ! sens);
1579 static void on_prefs_print_page_header_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1581 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1583 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "check_print_basename"), sens);
1584 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_print_dateformat"), sens);
1588 static void open_preferences_help(void)
1590 gchar *uri;
1591 const gchar *label, *suffix = NULL;
1592 GtkNotebook *notebook = GTK_NOTEBOOK(
1593 ui_lookup_widget(ui_widgets.prefs_dialog, "notebook2"));
1594 gint page_nr = gtk_notebook_get_current_page(notebook);
1595 GtkWidget *page = gtk_notebook_get_nth_page(notebook, page_nr);
1597 label = gtk_notebook_get_tab_label_text(notebook, page);
1599 /* TODO Find a better way to map the current notebook page to the
1600 * corresponding chapter in the documentation, comparing translatable
1601 * strings is easy to break. Maybe attach an identifying string to the
1602 * tab label object. */
1603 if (utils_str_equal(label, _("General")))
1604 suffix = "#general-startup-preferences";
1605 else if (utils_str_equal(label, _("Interface")))
1606 suffix = "#interface-preferences";
1607 else if (utils_str_equal(label, _("Toolbar")))
1608 suffix = "#toolbar-preferences";
1609 else if (utils_str_equal(label, _("Editor")))
1610 suffix = "#editor-features-preferences";
1611 else if (utils_str_equal(label, _("Files")))
1612 suffix = "#files-preferences";
1613 else if (utils_str_equal(label, _("Tools")))
1614 suffix = "#tools-preferences";
1615 else if (utils_str_equal(label, _("Templates")))
1616 suffix = "#template-preferences";
1617 else if (utils_str_equal(label, _("Keybindings")))
1618 suffix = "#keybinding-preferences";
1619 else if (utils_str_equal(label, _("Printing")))
1620 suffix = "#printing-preferences";
1621 else if (utils_str_equal(label, _("Various")))
1622 suffix = "#various-preferences";
1623 else if (utils_str_equal(label, _("Terminal")))
1624 suffix = "#terminal-vte-preferences";
1626 uri = utils_get_help_url(suffix);
1627 utils_open_browser(uri);
1628 g_free(uri);
1632 static gboolean prefs_dialog_key_press_response_cb(GtkWidget *dialog, GdkEventKey *event,
1633 gpointer data)
1635 GeanyKeyBinding *kb = keybindings_lookup_item(GEANY_KEY_GROUP_HELP, GEANY_KEYS_HELP_HELP);
1637 if (keybindings_check_event(event, kb))
1639 open_preferences_help();
1640 return TRUE;
1642 return FALSE;
1646 static void list_store_append_text(GtkListStore *list, const gchar *text)
1648 GtkTreeIter iter;
1650 gtk_list_store_append(list, &iter);
1651 gtk_list_store_set(list, &iter, 0, text, -1);
1655 void prefs_show_dialog(void)
1657 if (ui_widgets.prefs_dialog == NULL)
1659 GtkListStore *eol_list;
1660 GtkWidget *label;
1662 ui_widgets.prefs_dialog = create_prefs_dialog();
1663 gtk_widget_set_name(ui_widgets.prefs_dialog, "GeanyPrefsDialog");
1664 gtk_window_set_transient_for(GTK_WINDOW(ui_widgets.prefs_dialog), GTK_WINDOW(main_widgets.window));
1666 /* init the file encoding combo boxes */
1668 struct {
1669 const gchar *combo, *renderer;
1670 } names[] = {
1671 { "combo_new_encoding", "combo_new_encoding_renderer" },
1672 { "combo_open_encoding", "combo_open_encoding_renderer" }
1674 guint i;
1675 GtkTreeStore *encoding_list = encodings_encoding_store_new(FALSE);
1677 for (i = 0; i < G_N_ELEMENTS(names); i++)
1679 GtkWidget *combo = ui_lookup_widget(ui_widgets.prefs_dialog, names[i].combo);
1681 gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(combo),
1682 ui_builder_get_object(names[i].renderer),
1683 encodings_encoding_store_cell_data_func, NULL, NULL);
1684 gtk_combo_box_set_model(GTK_COMBO_BOX(combo), GTK_TREE_MODEL(encoding_list));
1686 g_object_unref(encoding_list);
1689 /* init the eol character combo box */
1690 eol_list = ui_builder_get_object("eol_list");
1691 list_store_append_text(eol_list, utils_get_eol_name(SC_EOL_CRLF));
1692 list_store_append_text(eol_list, utils_get_eol_name(SC_EOL_CR));
1693 list_store_append_text(eol_list, utils_get_eol_name(SC_EOL_LF));
1696 /* add manually GeanyWrapLabels because they can't be added with Glade */
1697 /* page Tools */
1698 label = geany_wrap_label_new(_("Enter tool paths below. Tools you do not need can be left blank."));
1699 gtk_widget_show(label);
1700 gtk_box_pack_start(GTK_BOX(ui_lookup_widget(ui_widgets.prefs_dialog, "vbox33")),
1701 label, FALSE, TRUE, 5);
1702 /* page Templates */
1703 label = geany_wrap_label_new(_("Set the information to be used in templates. See the documentation for details."));
1704 gtk_widget_show(label);
1705 gtk_box_pack_start(GTK_BOX(ui_lookup_widget(ui_widgets.prefs_dialog, "vbox31")),
1706 label, FALSE, TRUE, 5);
1707 /* page Keybindings */
1708 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."));
1709 gtk_widget_show(label);
1710 gtk_box_pack_start(GTK_BOX(ui_lookup_widget(ui_widgets.prefs_dialog, "vbox32")),
1711 label, FALSE, TRUE, 5);
1712 /* page Editor->Indentation */
1713 label = geany_wrap_label_new(_("<i>Warning: these settings are overridden by the current project. See <b>Project->Properties</b>.</i>"));
1714 gtk_widget_show(label);
1715 gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
1716 gtk_misc_set_padding(GTK_MISC(label), 6, 0);
1717 gtk_box_pack_start(GTK_BOX(ui_lookup_widget(ui_widgets.prefs_dialog,
1718 "label_project_indent_warning")), label, FALSE, TRUE, 5);
1720 /* add the clear icon to GtkEntry widgets in the dialog */
1722 const gchar *names[] = {
1723 "startup_path_entry",
1724 "project_file_path_entry",
1725 "extra_plugin_path_entry",
1726 "entry_toggle_mark",
1727 /* "entry_com_make", */
1728 "entry_com_term",
1729 "entry_browser",
1730 "entry_grep",
1731 "entry_contextaction",
1732 "entry_template_developer",
1733 "entry_template_initial",
1734 "entry_template_mail",
1735 "entry_template_company",
1736 "entry_template_version",
1737 "entry_template_year",
1738 "entry_template_date",
1739 "entry_template_datetime",
1740 "entry_print_external_cmd",
1741 "entry_print_dateformat"};
1742 const gchar **name;
1744 foreach_c_array(name, names, G_N_ELEMENTS(names))
1745 ui_entry_add_clear_icon(GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, *name)));
1748 /* page Various */
1749 various_treeview = GTK_TREE_VIEW(ui_lookup_widget(ui_widgets.prefs_dialog,
1750 "various_treeview"));
1751 stash_tree_setup(pref_groups, various_treeview);
1753 #ifdef HAVE_VTE
1754 vte_append_preferences_tab();
1755 #endif
1757 #ifndef G_OS_WIN32
1758 gtk_widget_hide(ui_lookup_widget(ui_widgets.prefs_dialog, "check_native_windows_dialogs"));
1759 #endif
1760 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets.prefs_dialog, "startup_path_button"), NULL,
1761 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "startup_path_entry")));
1762 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets.prefs_dialog, "extra_plugin_path_button"), NULL,
1763 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "extra_plugin_path_entry")));
1765 g_signal_connect(ui_widgets.prefs_dialog, "response",
1766 G_CALLBACK(on_prefs_dialog_response), NULL);
1767 g_signal_connect(ui_widgets.prefs_dialog, "delete-event",
1768 G_CALLBACK(gtk_widget_hide_on_delete), NULL);
1770 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "tagbar_font"),
1771 "font-set", G_CALLBACK(on_prefs_font_choosed), GINT_TO_POINTER(1));
1772 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "msgwin_font"),
1773 "font-set", G_CALLBACK(on_prefs_font_choosed), GINT_TO_POINTER(2));
1774 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "editor_font"),
1775 "font-set", G_CALLBACK(on_prefs_font_choosed), GINT_TO_POINTER(3));
1776 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "long_line_color"),
1777 "color-set", G_CALLBACK(on_color_button_choose_cb), NULL);
1778 /* file chooser buttons in the tools tab */
1779 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets.prefs_dialog, "button_term"),
1780 NULL,
1781 GTK_FILE_CHOOSER_ACTION_OPEN,
1782 GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_com_term")));
1783 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets.prefs_dialog, "button_browser"),
1784 NULL,
1785 GTK_FILE_CHOOSER_ACTION_OPEN,
1786 GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_browser")));
1787 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets.prefs_dialog, "button_grep"),
1788 NULL,
1789 GTK_FILE_CHOOSER_ACTION_OPEN,
1790 GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_grep")));
1792 /* tools commands */
1793 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets.prefs_dialog, "button_contextaction"),
1794 NULL,
1795 GTK_FILE_CHOOSER_ACTION_OPEN,
1796 GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_contextaction")));
1798 /* printing */
1799 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets.prefs_dialog, "button_print_external_cmd"),
1800 NULL,
1801 GTK_FILE_CHOOSER_ACTION_OPEN,
1802 GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_print_external_cmd")));
1804 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "radio_print_gtk"),
1805 "toggled", G_CALLBACK(on_prefs_print_radio_button_toggled), NULL);
1806 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_print_pageheader"),
1807 "toggled", G_CALLBACK(on_prefs_print_page_header_toggled), NULL);
1809 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_plugins"),
1810 "toggled", G_CALLBACK(on_enable_plugins_toggled), NULL);
1811 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_toolbar_show"),
1812 "toggled", G_CALLBACK(on_toolbar_show_toggled), NULL);
1813 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_show_notebook_tabs"),
1814 "toggled", G_CALLBACK(on_show_notebook_tabs_toggled), NULL);
1815 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_folding"),
1816 "toggled", G_CALLBACK(on_use_folding_toggled), NULL);
1817 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_open_encoding"),
1818 "toggled", G_CALLBACK(on_open_encoding_toggled), NULL);
1819 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_sidebar_visible"),
1820 "toggled", G_CALLBACK(on_sidebar_visible_toggled), NULL);
1822 g_signal_connect(ui_widgets.prefs_dialog,
1823 "key-press-event", G_CALLBACK(prefs_dialog_key_press_response_cb), NULL);
1826 prefs_init_dialog();
1827 gtk_window_present(GTK_WINDOW(ui_widgets.prefs_dialog));