Merge pull request #3334 from eht16/show_d_python_global_class_calltips
[geany-mirror.git] / src / prefs.c
blob9d8306c2e76f3f96fa8b20ba5c2a3e6f8421dec1
1 /*
2 * prefs.c - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2005 The Geany contributors
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 * @file prefs.h
23 * Preferences dialog.
27 * Preferences dialog support functions.
28 * New 'simple' prefs should use Stash code in keyfile.c - init_pref_groups().
31 #ifdef HAVE_CONFIG_H
32 # include "config.h"
33 #endif
35 #include "prefs.h"
37 #include "app.h"
38 #include "dialogs.h"
39 #include "documentprivate.h"
40 #include "editor.h"
41 #include "encodingsprivate.h"
42 #include "filetypes.h"
43 #include "geanywraplabel.h"
44 #include "keybindingsprivate.h"
45 #include "keyfile.h"
46 #include "msgwindow.h"
47 #include "prefs.h"
48 #include "printing.h"
49 #include "sidebar.h"
50 #include "stash.h"
51 #include "support.h"
52 #include "templates.h"
53 #include "toolbar.h"
54 #include "tools.h"
55 #include "ui_utils.h"
56 #include "utils.h"
57 #include "vte.h"
58 #include "osx.h"
60 #include <stdlib.h>
61 #include <string.h>
62 #include <gtk/gtk.h>
63 #include <gdk/gdkkeysyms.h>
66 GeanyPrefs prefs;
67 GeanyToolPrefs tool_prefs;
70 typedef struct
72 GtkTreeStore *store;
73 GtkTreeView *tree;
74 gboolean edited;
76 KbData;
78 static KbData global_kb_data = { NULL, NULL, FALSE };
79 static GtkTreeView *various_treeview = NULL;
81 static GeanyKeyBinding *kb_index(guint gidx, guint kid);
82 static void kb_cell_edited_cb(GtkCellRendererText *cellrenderertext, gchar *path, gchar *new_text, KbData *kbdata);
83 static gboolean kb_grab_key_dialog_key_press_cb(GtkWidget *dialog, GdkEventKey *event, GtkLabel *label);
84 static void kb_change_iter_shortcut(KbData *kbdata, GtkTreeIter *iter, const gchar *new_text);
85 static gboolean kb_find_duplicate(GtkTreeStore *store, GtkWidget *parent, GtkTreeIter *old_iter,
86 guint key, GdkModifierType mods, const gchar *shortcut);
87 static void on_toolbar_show_toggled(GtkToggleButton *togglebutton, gpointer user_data);
88 static void on_show_notebook_tabs_toggled(GtkToggleButton *togglebutton, gpointer user_data);
89 static void on_enable_plugins_toggled(GtkToggleButton *togglebutton, gpointer user_data);
90 static void on_use_folding_toggled(GtkToggleButton *togglebutton, gpointer user_data);
91 static void on_check_line_end_toggled(GtkToggleButton *togglebutton, gpointer user_data);
92 static void on_open_encoding_toggled(GtkToggleButton *togglebutton, gpointer user_data);
93 static void on_sidebar_visible_toggled(GtkToggleButton *togglebutton, gpointer user_data);
94 static void on_prefs_print_radio_button_toggled(GtkToggleButton *togglebutton, gpointer user_data);
95 static void on_prefs_print_page_header_toggled(GtkToggleButton *togglebutton, gpointer user_data);
96 static void open_preferences_help(void);
99 typedef enum PrefCallbackAction
101 PREF_DISPLAY,
102 PREF_UPDATE
104 PrefCallbackAction;
107 /* Synchronize Stash settings with widgets (see keyfile.c - init_pref_groups()). */
108 static void prefs_action(PrefCallbackAction action)
110 StashGroup *group;
111 guint i;
113 foreach_ptr_array(group, i, pref_groups)
115 switch (action)
117 case PREF_DISPLAY:
118 stash_group_display(group, ui_widgets.prefs_dialog);
119 break;
120 case PREF_UPDATE:
121 stash_group_update(group, ui_widgets.prefs_dialog);
122 break;
126 switch (action)
128 case PREF_DISPLAY:
129 stash_tree_display(various_treeview);
130 break;
131 case PREF_UPDATE:
132 stash_tree_update(various_treeview);
133 break;
138 enum
140 KB_TREE_ACTION,
141 KB_TREE_SHORTCUT,
142 KB_TREE_INDEX,
143 KB_TREE_EDITABLE,
144 KB_TREE_WEIGHT,
145 KB_TREE_COLUMNS
149 static void kb_tree_view_change_button_clicked_cb(GtkWidget *button, KbData *kbdata)
151 GtkTreeModel *model;
152 GtkTreeIter iter;
153 GtkTreeSelection *selection;
154 gchar *name;
156 selection = gtk_tree_view_get_selection(kbdata->tree);
157 if (gtk_tree_selection_get_selected(selection, &model, &iter))
159 if (gtk_tree_model_iter_has_child(model, &iter))
160 { /* double click on a section to expand or collapse it */
161 GtkTreePath *path = gtk_tree_model_get_path(model, &iter);
163 if (gtk_tree_view_row_expanded(kbdata->tree, path))
164 gtk_tree_view_collapse_row(kbdata->tree, path);
165 else
166 gtk_tree_view_expand_row(kbdata->tree, path, FALSE);
168 gtk_tree_path_free(path);
169 return;
172 gtk_tree_model_get(model, &iter, KB_TREE_ACTION, &name, -1);
173 if (name != NULL)
175 GtkWidget *dialog;
176 GtkWidget *label;
177 GtkWidget *accel_label;
178 gchar *str;
180 dialog = gtk_dialog_new_with_buttons(_("Grab Key"), GTK_WINDOW(ui_widgets.prefs_dialog),
181 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
182 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
183 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL);
185 str = g_strdup_printf(
186 _("Press the combination of the keys you want to use for \"%s\"."), name);
187 label = gtk_label_new(str);
188 gtk_misc_set_padding(GTK_MISC(label), 5, 10);
189 gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), label);
191 accel_label = gtk_label_new("");
192 gtk_misc_set_padding(GTK_MISC(accel_label), 5, 10);
193 gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), accel_label);
195 g_signal_connect(dialog, "key-press-event",
196 G_CALLBACK(kb_grab_key_dialog_key_press_cb), accel_label);
198 gtk_widget_show_all(dialog);
199 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
201 const gchar *new_text = gtk_label_get_text(GTK_LABEL(accel_label));
203 kb_change_iter_shortcut(kbdata, &iter, new_text);
205 gtk_widget_destroy(dialog);
207 g_free(str);
208 g_free(name);
214 static void kb_show_popup_menu(KbData *kbdata, GtkWidget *widget, GdkEventButton *event)
216 static GtkWidget *menu = NULL;
217 guint button;
218 guint32 event_time;
220 if (menu == NULL)
222 GtkWidget *item;
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_swapped(item, "activate", G_CALLBACK(gtk_tree_view_expand_all), kbdata->tree);
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_swapped(item, "activate", G_CALLBACK(gtk_tree_view_collapse_all), kbdata->tree);
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 ui_menu_popup(GTK_MENU(menu), NULL, NULL, button, event_time);
254 static gboolean kb_popup_menu_cb(GtkWidget *widget, KbData *kbdata)
256 kb_show_popup_menu(kbdata, widget, NULL);
257 return TRUE;
261 static gboolean kb_tree_view_button_press_event_cb(GtkWidget *widget, GdkEventButton *event,
262 KbData *kbdata)
264 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
266 kb_show_popup_menu(kbdata, widget, event);
267 return TRUE;
269 else if (event->type == GDK_2BUTTON_PRESS)
271 kb_tree_view_change_button_clicked_cb(NULL, kbdata);
272 return TRUE;
274 return FALSE;
278 static void kb_init_tree(KbData *kbdata)
280 GtkCellRenderer *renderer;
281 GtkTreeViewColumn *column;
283 kbdata->tree = GTK_TREE_VIEW(ui_lookup_widget(ui_widgets.prefs_dialog, "treeview7"));
285 kbdata->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(kbdata->tree), GTK_TREE_MODEL(kbdata->store));
288 g_object_unref(kbdata->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(kbdata->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(kbdata->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), kbdata);
308 g_signal_connect(kbdata->tree, "button-press-event", G_CALLBACK(kb_tree_view_button_press_event_cb), kbdata);
309 g_signal_connect(kbdata->tree, "popup-menu", G_CALLBACK(kb_popup_menu_cb), kbdata);
310 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "button2"), "clicked",
311 G_CALLBACK(kb_tree_view_change_button_clicked_cb), kbdata);
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;
342 KbData *kbdata = &global_kb_data;
344 model = gtk_tree_view_get_model(kbdata->tree);
345 valid = gtk_tree_model_get_iter_first(model, &iter);
346 while (valid)
348 gchar *name;
350 gtk_tree_model_get(model, &iter, KB_TREE_ACTION, &name, -1);
351 if (g_strcmp0(name, search) == 0)
353 GtkTreePath *path = gtk_tree_model_get_path(model, &iter);
354 gtk_tree_view_scroll_to_cell(kbdata->tree, path, NULL, TRUE, .0f, .0f);
355 gtk_tree_path_free(path);
356 g_free(name);
357 break;
359 g_free(name);
360 valid = gtk_tree_model_iter_next(model, &iter);
365 static void kb_init(KbData *kbdata)
367 GtkTreeIter parent, iter;
368 gsize g, i;
369 gchar *label;
370 GeanyKeyGroup *group;
371 GeanyKeyBinding *kb;
373 if (kbdata->store == NULL)
374 kb_init_tree(kbdata);
376 foreach_ptr_array(group, g, keybinding_groups)
378 gtk_tree_store_append(kbdata->store, &parent, NULL);
379 gtk_tree_store_set(kbdata->store, &parent, KB_TREE_ACTION, group->label,
380 KB_TREE_INDEX, g, -1);
382 foreach_ptr_array(kb, i, group->key_items)
384 label = keybindings_get_label(kb);
385 gtk_tree_store_append(kbdata->store, &iter, &parent);
386 gtk_tree_store_set(kbdata->store, &iter, KB_TREE_ACTION, label,
387 KB_TREE_EDITABLE, TRUE, KB_TREE_INDEX, kb->id, -1);
388 kb_set_shortcut(kbdata->store, &iter, kb->key, kb->mods);
389 g_free(label);
392 gtk_tree_view_expand_all(GTK_TREE_VIEW(kbdata->tree));
396 /* note: new 'simple' prefs should use Stash code in keyfile.c */
397 static void prefs_init_dialog(void)
399 GtkWidget *widget;
400 GdkColor color = {0};
402 /* Synchronize with Stash settings */
403 prefs_action(PREF_DISPLAY);
405 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "label_project_indent_warning");
406 ui_widget_show_hide(widget, app->project != NULL);
408 /* General settings */
409 /* startup */
410 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_load_session");
411 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), prefs.load_session);
413 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_project_file_in_basedir");
414 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), project_prefs.project_file_in_basedir);
416 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_save_win_pos");
417 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), prefs.save_winpos);
419 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_save_win_geom");
420 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), prefs.save_wingeom);
422 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_ask_for_quit");
423 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), prefs.confirm_exit);
425 /* behaviour */
426 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_beep");
427 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), prefs.beep_on_errors);
429 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_switch_pages");
430 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), prefs.switch_to_status);
432 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_suppress_status_msgs");
433 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), prefs.suppress_status_messages);
435 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_auto_focus");
436 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), prefs.auto_focus);
438 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_contextaction");
439 gtk_entry_set_text(GTK_ENTRY(widget), tool_prefs.context_action_cmd);
441 project_setup_prefs(); /* project files path */
444 /* Interface settings */
445 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_sidebar_visible");
446 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), ui_prefs.sidebar_visible);
447 on_sidebar_visible_toggled(GTK_TOGGLE_BUTTON(widget), NULL);
449 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_list_symbol");
450 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), interface_prefs.sidebar_symbol_visible);
452 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_list_openfiles");
453 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), interface_prefs.sidebar_openfiles_visible);
455 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "tagbar_font");
456 gtk_font_button_set_font_name(GTK_FONT_BUTTON(widget), interface_prefs.tagbar_font);
458 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "msgwin_font");
459 gtk_font_button_set_font_name(GTK_FONT_BUTTON(widget), interface_prefs.msgwin_font);
461 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "editor_font");
462 gtk_font_button_set_font_name(GTK_FONT_BUTTON(widget), interface_prefs.editor_font);
464 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_long_line");
465 gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), editor_prefs.long_line_column);
467 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_long_line");
468 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.long_line_enabled);
470 switch (editor_prefs.long_line_type)
472 case 0: widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_long_line_line"); break;
473 case 1: widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_long_line_background"); break;
475 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
477 utils_parse_color(editor_prefs.long_line_color, &color);
478 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "long_line_color");
479 gtk_color_button_set_color(GTK_COLOR_BUTTON(widget), &color);
481 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_show_notebook_tabs");
482 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), interface_prefs.show_notebook_tabs);
483 /* disable following setting if notebook tabs are hidden */
484 on_show_notebook_tabs_toggled(GTK_TOGGLE_BUTTON(
485 ui_lookup_widget(ui_widgets.prefs_dialog, "check_show_notebook_tabs")), NULL);
487 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_show_tab_cross");
488 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), file_prefs.show_tab_cross);
490 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_tab_editor");
491 gtk_combo_box_set_active(GTK_COMBO_BOX(widget), interface_prefs.tab_pos_editor);
493 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_tab_msgwin");
494 gtk_combo_box_set_active(GTK_COMBO_BOX(widget), interface_prefs.tab_pos_msgwin);
496 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_tab_sidebar");
497 gtk_combo_box_set_active(GTK_COMBO_BOX(widget), interface_prefs.tab_pos_sidebar);
499 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_statusbar_visible");
500 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), interface_prefs.statusbar_visible);
503 /* Toolbar settings */
504 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_toolbar_show");
505 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), toolbar_prefs.visible);
506 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_toolbar_in_menu");
507 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), toolbar_prefs.append_to_menu);
509 switch (toolbar_prefs.icon_style)
511 case 0: widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_image"); break;
512 case 1: widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_text"); break;
513 default: widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_imagetext"); break;
515 if (toolbar_prefs.use_gtk_default_style)
516 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_style_default");
517 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
519 switch (toolbar_prefs.icon_size)
521 case GTK_ICON_SIZE_LARGE_TOOLBAR:
522 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_large"); break;
523 case GTK_ICON_SIZE_SMALL_TOOLBAR:
524 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_small"); break;
525 default: widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_verysmall"); break;
527 if (toolbar_prefs.use_gtk_default_icon)
528 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_icon_default");
529 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
531 /* disable elements if toolbar is hidden */
532 on_toolbar_show_toggled(GTK_TOGGLE_BUTTON(
533 ui_lookup_widget(ui_widgets.prefs_dialog, "check_toolbar_show")), NULL);
536 /* Files settings */
537 if (file_prefs.tab_order_ltr)
538 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_tab_right");
539 else
540 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_tab_left");
541 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
543 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_tab_beside");
544 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), file_prefs.tab_order_beside);
546 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_new_encoding");
547 ui_encodings_combo_box_set_active_encoding(GTK_COMBO_BOX(widget), file_prefs.default_new_encoding);
549 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_open_encoding");
550 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),
551 (file_prefs.default_open_encoding >= 0) ? TRUE : FALSE);
552 on_open_encoding_toggled(GTK_TOGGLE_BUTTON(widget), NULL);
554 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_open_encoding");
555 if (file_prefs.default_open_encoding >= 0)
557 ui_encodings_combo_box_set_active_encoding(GTK_COMBO_BOX(widget), file_prefs.default_open_encoding);
559 else
560 ui_encodings_combo_box_set_active_encoding(GTK_COMBO_BOX(widget), GEANY_ENCODING_UTF_8);
562 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_eol");
563 if (file_prefs.default_eol_character >= 0 && file_prefs.default_eol_character < 3)
565 gtk_combo_box_set_active(GTK_COMBO_BOX(widget), file_prefs.default_eol_character);
567 else
568 gtk_combo_box_set_active(GTK_COMBO_BOX(widget), GEANY_DEFAULT_EOL_CHARACTER);
570 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_trailing_spaces");
571 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), file_prefs.strip_trailing_spaces);
573 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_new_line");
574 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), file_prefs.final_new_line);
576 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_ensure_convert_new_lines");
577 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), file_prefs.ensure_convert_new_lines);
579 /* Editor settings */
580 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_toggle_mark");
581 gtk_entry_set_text(GTK_ENTRY(widget), editor_prefs.comment_toggle_mark);
583 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_replace_tabs");
584 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), file_prefs.replace_tabs);
586 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_indent");
587 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.show_indent_guide);
589 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_white_space");
590 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.show_white_space);
592 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_line_end");
593 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.show_line_endings);
595 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_line_endings_only_when_differ");
596 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),
597 editor_prefs.show_line_endings_only_when_differ);
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(&global_kb_data);
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 VteConfig *vc = &vte_config;
765 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "font_term");
766 gtk_font_button_set_font_name(GTK_FONT_BUTTON(widget), vc->font);
768 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "color_fore");
769 gtk_color_button_set_color(GTK_COLOR_BUTTON(widget), &vc->colour_fore);
771 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "color_back");
772 gtk_color_button_set_color(GTK_COLOR_BUTTON(widget), &vc->colour_back);
774 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_scrollback");
775 gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), vc->scrollback_lines);
777 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_shell");
778 gtk_entry_set_text(GTK_ENTRY(widget), vc->shell);
780 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_scroll_key");
781 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), vc->scroll_on_key);
783 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_scroll_out");
784 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), vc->scroll_on_out);
786 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_enable_bash_keys");
787 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), vc->enable_bash_keys);
789 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_ignore_menu_key");
790 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), vc->ignore_menu_bar_accel);
792 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_follow_path");
793 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), vc->follow_path);
795 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_run_in_vte");
796 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), vc->run_in_vte);
798 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_skip_script");
799 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), vc->skip_run_script);
801 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_cursor_blinks");
802 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), vc->cursor_blinks);
804 #endif
808 /* note: uses group index, not group id, unlike keybindings_lookup_item(). */
809 static GeanyKeyBinding *kb_index(guint gidx, guint kid)
811 GeanyKeyGroup *group;
813 group = g_ptr_array_index(keybinding_groups, gidx);
814 return keybindings_get_item(group, kid);
818 /* read the treeview shortcut fields into keybindings */
819 static void kb_update(KbData *kbdata)
821 GtkTreeModel *model = GTK_TREE_MODEL(kbdata->store);
822 GtkTreeIter child, parent;
823 guint gid = 0;
825 /* get first parent */
826 if (! gtk_tree_model_iter_children(model, &parent, NULL))
827 return;
829 /* foreach parent */
830 while (TRUE)
832 /* get first child */
833 if (! gtk_tree_model_iter_children(model, &child, &parent))
834 return;
836 /* foreach child */
837 while (TRUE)
839 guint kid;
840 gchar *str;
841 guint key;
842 GdkModifierType mods;
843 GeanyKeyBinding *kb;
845 gtk_tree_model_get(model, &child, KB_TREE_INDEX, &kid, KB_TREE_SHORTCUT, &str, -1);
846 gtk_accelerator_parse(str, &key, &mods);
847 g_free(str);
848 kb = kb_index(gid, kid);
849 if (kb->key != key || kb->mods != mods)
850 keybindings_update_combo(kb, key, mods);
852 if (! gtk_tree_model_iter_next(model, &child))
853 break;
855 if (! gtk_tree_model_iter_next(model, &parent))
856 return;
857 gid++;
863 * callbacks
865 /* note: new 'simple' prefs should use Stash code in keyfile.c */
866 static void
867 on_prefs_dialog_response(GtkDialog *dialog, gint response, gpointer user_data)
869 if (response == GTK_RESPONSE_OK || response == GTK_RESPONSE_APPLY)
871 GtkWidget *widget;
872 guint i;
873 gboolean autoclose_brackets[5];
874 gboolean old_invert_all = interface_prefs.highlighting_invert_all;
875 gboolean old_sidebar_pos = interface_prefs.sidebar_pos;
876 GeanyDocument *doc = document_get_current();
878 /* Synchronize Stash settings */
879 prefs_action(PREF_UPDATE);
881 if (interface_prefs.highlighting_invert_all != old_invert_all)
882 filetypes_reload();
884 if (interface_prefs.sidebar_pos != old_sidebar_pos)
885 ui_swap_sidebar_pos();
887 widget = ui_lookup_widget(main_widgets.window, "vpaned1");
888 gtk_orientable_set_orientation(GTK_ORIENTABLE(widget), interface_prefs.msgwin_orientation);
890 /* General settings */
891 /* startup */
892 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_load_session");
893 prefs.load_session = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
895 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_project_file_in_basedir");
896 project_prefs.project_file_in_basedir = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
898 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_save_win_pos");
899 prefs.save_winpos = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
901 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_save_win_geom");
902 prefs.save_wingeom = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
904 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_ask_for_quit");
905 prefs.confirm_exit = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
907 /* behaviour */
908 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_beep");
909 prefs.beep_on_errors = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
911 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_switch_pages");
912 prefs.switch_to_status = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
914 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_suppress_status_msgs");
915 prefs.suppress_status_messages = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
917 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_auto_focus");
918 prefs.auto_focus = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
920 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_contextaction");
921 g_free(tool_prefs.context_action_cmd);
922 tool_prefs.context_action_cmd = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
924 project_apply_prefs(); /* project file path */
927 /* Interface settings */
928 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_sidebar_visible");
929 ui_prefs.sidebar_visible = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
931 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_list_symbol");
932 interface_prefs.sidebar_symbol_visible = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
934 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_list_openfiles");
935 interface_prefs.sidebar_openfiles_visible = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
937 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_long_line");
938 editor_prefs.long_line_enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
940 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_long_line_line");
941 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
942 editor_prefs.long_line_type = 0;
943 else
944 /* now only the "background" radio remains */
945 editor_prefs.long_line_type = 1;
947 if (editor_prefs.long_line_column == 0)
948 editor_prefs.long_line_enabled = FALSE;
950 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_show_notebook_tabs");
951 interface_prefs.show_notebook_tabs = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
953 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_show_tab_cross");
954 file_prefs.show_tab_cross = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
956 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_tab_editor");
957 interface_prefs.tab_pos_editor = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
959 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_tab_msgwin");
960 interface_prefs.tab_pos_msgwin = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
962 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_tab_sidebar");
963 interface_prefs.tab_pos_sidebar = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
965 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_statusbar_visible");
966 interface_prefs.statusbar_visible = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
969 /* Toolbar settings */
970 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_toolbar_show");
971 toolbar_prefs.visible = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
972 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_toolbar_in_menu");
973 toolbar_prefs.append_to_menu = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
975 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_style_default");
976 toolbar_prefs.use_gtk_default_style = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
977 if (! toolbar_prefs.use_gtk_default_style)
979 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_imagetext");
980 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
981 toolbar_prefs.icon_style = 2;
982 else
984 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_image");
985 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
986 toolbar_prefs.icon_style = 0;
987 else
988 /* now only the text only radio remains, so set text only */
989 toolbar_prefs.icon_style = 1;
993 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_icon_default");
994 toolbar_prefs.use_gtk_default_icon = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
995 if (! toolbar_prefs.use_gtk_default_icon)
996 { toolbar_prefs.icon_size = GTK_ICON_SIZE_LARGE_TOOLBAR;
997 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_large");
998 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
999 toolbar_prefs.icon_size = GTK_ICON_SIZE_LARGE_TOOLBAR;
1000 else
1002 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_small");
1003 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
1004 toolbar_prefs.icon_size = GTK_ICON_SIZE_SMALL_TOOLBAR;
1005 else
1006 toolbar_prefs.icon_size = GTK_ICON_SIZE_MENU;
1010 /* Files settings */
1011 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_tab_right");
1012 file_prefs.tab_order_ltr = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1014 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_tab_beside");
1015 file_prefs.tab_order_beside = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1017 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_new_encoding");
1018 file_prefs.default_new_encoding = ui_encodings_combo_box_get_active_encoding(GTK_COMBO_BOX(widget));
1020 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_open_encoding");
1021 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
1023 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_open_encoding");
1024 file_prefs.default_open_encoding = ui_encodings_combo_box_get_active_encoding(GTK_COMBO_BOX(widget));
1026 else
1027 file_prefs.default_open_encoding = -1;
1029 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_eol");
1030 file_prefs.default_eol_character = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
1032 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_trailing_spaces");
1033 file_prefs.strip_trailing_spaces = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1035 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_new_line");
1036 file_prefs.final_new_line = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1038 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_ensure_convert_new_lines");
1039 file_prefs.ensure_convert_new_lines = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1041 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_replace_tabs");
1042 file_prefs.replace_tabs = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1045 /* Editor settings */
1046 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_toggle_mark");
1047 SETPTR(editor_prefs.comment_toggle_mark,
1048 gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1));
1050 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_long_line");
1051 /* note: use stash for new code - it updates spin buttons itself */
1052 gtk_spin_button_update(GTK_SPIN_BUTTON(widget));
1053 editor_prefs.long_line_column = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
1055 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_folding");
1056 editor_prefs.folding = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1057 ui_update_fold_items();
1059 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_unfold_children");
1060 editor_prefs.unfold_all_children = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1062 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_indent");
1063 editor_prefs.show_indent_guide = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1065 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_white_space");
1066 editor_prefs.show_white_space = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1068 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_line_end");
1069 editor_prefs.show_line_endings = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1071 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_line_endings_only_when_differ");
1072 editor_prefs.show_line_endings_only_when_differ = gtk_toggle_button_get_active(
1073 GTK_TOGGLE_BUTTON(widget));
1075 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_line_numbers");
1076 editor_prefs.show_linenumber_margin = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1078 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_markers_margin");
1079 editor_prefs.show_markers_margin = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1081 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_scroll_stop_at_last_line");
1082 editor_prefs.scroll_stop_at_last_line = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1084 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_line_wrapping");
1085 editor_prefs.line_wrapping = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1087 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_complete_snippets");
1088 editor_prefs.complete_snippets = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1090 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_xmltag");
1091 editor_prefs.auto_close_xml_tags = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1093 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_indicators");
1094 editor_prefs.use_indicators = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1096 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_disable_dnd");
1097 editor_prefs.disable_dnd = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1099 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_smart_home");
1100 editor_prefs.smart_home_key = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1102 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_newline_strip");
1103 editor_prefs.newline_strip = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1105 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_auto_multiline");
1106 editor_prefs.auto_continue_multiline = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1108 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_symbol_auto_completion");
1109 editor_prefs.auto_complete_symbols = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1111 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_symbol_complete_chars");
1112 gtk_spin_button_update(GTK_SPIN_BUTTON(widget));
1113 editor_prefs.symbolcompletion_min_chars = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
1115 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_symbollistheight");
1116 gtk_spin_button_update(GTK_SPIN_BUTTON(widget));
1117 editor_prefs.symbolcompletion_max_height = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
1119 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_line_break");
1120 gtk_spin_button_update(GTK_SPIN_BUTTON(widget));
1121 editor_prefs.line_break_column = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
1123 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_autoclose_parenthesis");
1124 autoclose_brackets[0] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1126 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_autoclose_cbracket");
1127 autoclose_brackets[1] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1129 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_autoclose_sbracket");
1130 autoclose_brackets[2] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1132 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_autoclose_squote");
1133 autoclose_brackets[3] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1135 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_autoclose_dquote");
1136 autoclose_brackets[4] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1138 editor_prefs.autoclose_chars =
1139 (autoclose_brackets[0] ? GEANY_AC_PARENTHESIS : 0u)
1140 | (autoclose_brackets[1] ? GEANY_AC_CBRACKET : 0u)
1141 | (autoclose_brackets[2] ? GEANY_AC_SBRACKET : 0u)
1142 | (autoclose_brackets[3] ? GEANY_AC_SQUOTE : 0u)
1143 | (autoclose_brackets[4] ? GEANY_AC_DQUOTE : 0u);
1145 /* Tools Settings */
1147 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_com_term");
1148 g_free(tool_prefs.term_cmd);
1149 tool_prefs.term_cmd = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1151 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_browser");
1152 g_free(tool_prefs.browser_cmd);
1153 tool_prefs.browser_cmd = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1155 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_grep");
1156 g_free(tool_prefs.grep_cmd);
1157 tool_prefs.grep_cmd = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1160 /* Template settings */
1161 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_developer");
1162 g_free(template_prefs.developer);
1163 template_prefs.developer = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1165 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_company");
1166 g_free(template_prefs.company);
1167 template_prefs.company = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1169 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_mail");
1170 g_free(template_prefs.mail);
1171 template_prefs.mail = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1173 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_initial");
1174 g_free(template_prefs.initials);
1175 template_prefs.initials = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1177 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_version");
1178 g_free(template_prefs.version);
1179 template_prefs.version = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1181 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_year");
1182 g_free(template_prefs.year_format);
1183 template_prefs.year_format = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1185 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_date");
1186 g_free(template_prefs.date_format);
1187 template_prefs.date_format = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1189 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_datetime");
1190 g_free(template_prefs.datetime_format);
1191 template_prefs.datetime_format = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1194 /* Keybindings */
1195 if (global_kb_data.edited)
1197 kb_update(&global_kb_data);
1198 tools_create_insert_custom_command_menu_items();
1199 keybindings_write_to_file();
1200 #ifdef MAC_INTEGRATION
1201 /* Force re-syncing the menubar to update displayed keybindings. */
1202 gtkosx_application_sync_menubar(gtkosx_application_get());
1203 #endif
1206 /* Printing */
1207 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_print_gtk");
1208 printing_prefs.use_gtk_printing = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1210 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_print_external_cmd");
1211 g_free(printing_prefs.external_print_cmd);
1212 printing_prefs.external_print_cmd = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1214 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_print_linenumbers");
1215 printing_prefs.print_line_numbers = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1217 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_print_pagenumbers");
1218 printing_prefs.print_page_numbers = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1220 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_print_pageheader");
1221 printing_prefs.print_page_header = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1223 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_print_basename");
1224 printing_prefs.page_header_basename = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1226 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_print_dateformat");
1227 g_free(printing_prefs.page_header_datefmt);
1228 printing_prefs.page_header_datefmt = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1231 #ifdef HAVE_VTE
1232 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_vte");
1233 vte_info.load_vte = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1235 /* VTE settings */
1236 if (vte_info.have_vte)
1238 VteConfig *vc = &vte_config;
1240 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_scrollback");
1241 gtk_spin_button_update(GTK_SPIN_BUTTON(widget));
1242 vc->scrollback_lines = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
1244 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_shell");
1245 g_free(vc->shell);
1246 vc->shell = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1248 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_scroll_key");
1249 vc->scroll_on_key = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1251 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_scroll_out");
1252 vc->scroll_on_out = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1254 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_enable_bash_keys");
1255 vc->enable_bash_keys = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1257 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_ignore_menu_key");
1258 vc->ignore_menu_bar_accel = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1260 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_follow_path");
1261 vc->follow_path = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1263 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_run_in_vte");
1264 vc->run_in_vte = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1266 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_skip_script");
1267 vc->skip_run_script = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1269 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_cursor_blinks");
1270 vc->cursor_blinks = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1272 vte_apply_user_settings();
1274 #endif
1276 /* apply the changes made */
1277 ui_statusbar_showhide(interface_prefs.statusbar_visible);
1278 sidebar_openfiles_update_all(); /* to update if full path setting has changed */
1279 toolbar_apply_settings();
1280 toolbar_update_ui();
1281 toolbar_show_hide();
1282 ui_sidebar_show_hide();
1283 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets.notebook), interface_prefs.show_notebook_tabs);
1285 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(main_widgets.notebook), interface_prefs.tab_pos_editor);
1286 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(msgwindow.notebook), interface_prefs.tab_pos_msgwin);
1287 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(main_widgets.sidebar_notebook), interface_prefs.tab_pos_sidebar);
1289 /* re-colourise all open documents, if tab width or long line settings have changed */
1290 for (i = 0; i < documents_array->len; i++)
1292 if (documents[i]->is_valid)
1294 editor_apply_update_prefs(documents[i]->editor);
1295 if (! editor_prefs.folding)
1296 editor_unfold_all(documents[i]->editor);
1299 ui_document_show_hide(NULL);
1300 ui_update_view_editor_menu_items();
1302 /* various preferences */
1303 ui_save_buttons_toggle((doc != NULL) ? doc->changed : FALSE);
1304 msgwin_show_hide_tabs();
1305 ui_update_statusbar(doc, -1);
1307 /* store all settings */
1308 configuration_save();
1311 if (response == GTK_RESPONSE_HELP)
1313 open_preferences_help();
1315 else if (response != GTK_RESPONSE_APPLY)
1317 gtk_tree_store_clear(global_kb_data.store);
1318 gtk_widget_hide(GTK_WIDGET(dialog));
1323 static void on_color_button_choose_cb(GtkColorButton *widget, gpointer user_data)
1325 GdkColor color;
1327 gtk_color_button_get_color(widget, &color);
1328 SETPTR(editor_prefs.long_line_color, utils_get_hex_from_color(&color));
1332 static void on_prefs_font_choosed(GtkFontButton *widget, gpointer user_data)
1334 const gchar *fontbtn = gtk_font_button_get_font_name(widget);
1335 guint i;
1337 switch (GPOINTER_TO_INT(user_data))
1339 case 1:
1341 if (strcmp(fontbtn, interface_prefs.tagbar_font) == 0)
1342 break;
1344 SETPTR(interface_prefs.tagbar_font, g_strdup(fontbtn));
1345 for (i = 0; i < documents_array->len; i++)
1347 GeanyDocument *doc = documents[i];
1349 if (documents[i]->is_valid && GTK_IS_WIDGET(doc->priv->tag_tree))
1350 ui_widget_modify_font_from_string(doc->priv->tag_tree,
1351 interface_prefs.tagbar_font);
1353 if (GTK_IS_WIDGET(tv.default_tag_tree))
1354 ui_widget_modify_font_from_string(tv.default_tag_tree, interface_prefs.tagbar_font);
1355 ui_widget_modify_font_from_string(tv.tree_openfiles, interface_prefs.tagbar_font);
1356 break;
1358 case 2:
1360 if (strcmp(fontbtn, interface_prefs.msgwin_font) == 0)
1361 break;
1362 SETPTR(interface_prefs.msgwin_font, g_strdup(fontbtn));
1363 ui_widget_modify_font_from_string(msgwindow.tree_compiler, interface_prefs.msgwin_font);
1364 ui_widget_modify_font_from_string(msgwindow.tree_msg, interface_prefs.msgwin_font);
1365 ui_widget_modify_font_from_string(msgwindow.tree_status, interface_prefs.msgwin_font);
1366 ui_widget_modify_font_from_string(msgwindow.scribble, interface_prefs.msgwin_font);
1367 break;
1369 case 3:
1371 ui_set_editor_font(fontbtn);
1372 break;
1378 static void kb_change_iter_shortcut(KbData *kbdata, GtkTreeIter *iter, const gchar *new_text)
1380 guint lkey;
1381 GdkModifierType lmods;
1383 gtk_accelerator_parse(new_text, &lkey, &lmods);
1385 if (kb_find_duplicate(kbdata->store, ui_widgets.prefs_dialog, iter, lkey, lmods, new_text))
1386 return;
1388 /* set the values here, because of the above check, setting it in
1389 * gtk_accelerator_parse would return a wrong key combination if it is duplicate */
1390 kb_set_shortcut(kbdata->store, iter, lkey, lmods);
1392 kbdata->edited = TRUE;
1396 static void kb_cell_edited_cb(GtkCellRendererText *cellrenderertext,
1397 gchar *path, gchar *new_text, KbData *kbdata)
1399 if (path != NULL && new_text != NULL)
1401 GtkTreeIter iter;
1403 gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(kbdata->store), &iter, path);
1404 if (gtk_tree_model_iter_has_child(GTK_TREE_MODEL(kbdata->store), &iter))
1405 return; /* ignore group items */
1407 kb_change_iter_shortcut(kbdata, &iter, new_text);
1412 static gboolean kb_grab_key_dialog_key_press_cb(GtkWidget *dialog, GdkEventKey *event, GtkLabel *label)
1414 gchar *str;
1415 guint state;
1417 g_return_val_if_fail(GTK_IS_LABEL(label), FALSE);
1419 state = keybindings_get_modifiers(event->state);
1421 if (event->keyval == GDK_KEY_Escape)
1422 return FALSE; /* close the dialog, don't allow escape when detecting keybindings. */
1424 str = gtk_accelerator_name(event->keyval, state);
1426 gtk_label_set_text(label, str);
1427 g_free(str);
1429 return TRUE;
1433 /* test if the entered key combination is already used
1434 * returns true if cancelling duplicate */
1435 static gboolean kb_find_duplicate(GtkTreeStore *store, GtkWidget *parent, GtkTreeIter *old_iter,
1436 guint key, GdkModifierType mods, const gchar *shortcut)
1438 GtkTreeModel *model = GTK_TREE_MODEL(store);
1439 GtkTreeIter parent_iter;
1440 gchar *kb_str;
1441 guint kb_key;
1442 GdkModifierType kb_mods;
1444 /* allow duplicate if there is no key combination */
1445 if (key == 0 && mods == 0)
1446 return FALSE;
1448 /* don't check if the new keybinding is the same as the old one */
1449 gtk_tree_model_get(model, old_iter, KB_TREE_SHORTCUT, &kb_str, -1);
1450 if (kb_str)
1452 gtk_accelerator_parse(kb_str, &kb_key, &kb_mods);
1453 g_free(kb_str);
1454 if (key == kb_key && mods == kb_mods)
1455 return FALSE;
1458 if (! gtk_tree_model_get_iter_first(model, &parent_iter))
1459 return FALSE;
1460 do /* foreach top level */
1462 GtkTreeIter iter;
1464 if (! gtk_tree_model_iter_children(model, &iter, &parent_iter))
1465 continue;
1466 do /* foreach children */
1468 gtk_tree_model_get(model, &iter, KB_TREE_SHORTCUT, &kb_str, -1);
1469 if (! kb_str)
1470 continue;
1472 gtk_accelerator_parse(kb_str, &kb_key, &kb_mods);
1473 g_free(kb_str);
1474 /* search another item with the same key and modifiers */
1475 if (kb_key == key && kb_mods == mods)
1477 gchar *label;
1478 gint ret;
1480 gtk_tree_model_get(model, &iter, KB_TREE_ACTION, &label, -1);
1481 ret = dialogs_show_prompt(parent,
1482 _("_Allow"), GTK_RESPONSE_APPLY,
1483 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1484 _("_Override"), GTK_RESPONSE_YES,
1485 _("Override that keybinding?"),
1486 _("The combination '%s' is already used for \"%s\"."),
1487 shortcut, label);
1489 g_free(label);
1491 if (ret == GTK_RESPONSE_YES)
1493 kb_set_shortcut(store, &iter, 0, 0); /* clear shortcut */
1494 /* carry on looking for other duplicates if overriding */
1495 continue;
1497 return ret != GTK_RESPONSE_APPLY;
1500 while (gtk_tree_model_iter_next(model, &iter));
1502 while (gtk_tree_model_iter_next(model, &parent_iter));
1504 return FALSE;
1508 static void on_toolbar_show_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1510 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1512 gtk_widget_set_sensitive(
1513 ui_lookup_widget(ui_widgets.prefs_dialog, "frame_toolbar_style"), sens);
1514 gtk_widget_set_sensitive(
1515 ui_lookup_widget(ui_widgets.prefs_dialog, "frame_toolbar_icon"), sens);
1516 gtk_widget_set_sensitive(
1517 ui_lookup_widget(ui_widgets.prefs_dialog, "button_customize_toolbar"), sens);
1518 gtk_widget_set_sensitive(
1519 ui_lookup_widget(ui_widgets.prefs_dialog, "check_toolbar_in_menu"), sens);
1523 static void on_show_notebook_tabs_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1525 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1527 /* tab placement only enabled when tabs are visible */
1528 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "combo_tab_editor"), sens);
1529 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "check_show_tab_cross"), sens);
1533 static void on_use_folding_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1535 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1537 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "check_unfold_children"), sens);
1541 static void on_check_line_end_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1543 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1545 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "check_line_endings_only_when_differ"), sens);
1549 static void on_enable_plugins_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1551 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1553 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "extra_plugin_path_entry"), sens);
1554 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "extra_plugin_path_button"), sens);
1558 static void on_open_encoding_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1560 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1562 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "eventbox3"), sens);
1563 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "label_open_encoding"), sens);
1567 static void on_sidebar_visible_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1569 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1571 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "box_sidebar_visible_children"), sens);
1575 static void on_prefs_print_radio_button_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1577 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1579 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "vbox29"), sens);
1580 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "hbox9"), ! sens);
1584 static void on_prefs_print_page_header_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1586 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1588 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "check_print_basename"), sens);
1589 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_print_dateformat"), sens);
1593 static void open_preferences_help(void)
1595 gchar *uri;
1596 const gchar *label, *suffix = NULL;
1597 GtkNotebook *notebook = GTK_NOTEBOOK(
1598 ui_lookup_widget(ui_widgets.prefs_dialog, "notebook2"));
1599 gint page_nr = gtk_notebook_get_current_page(notebook);
1600 GtkWidget *page = gtk_notebook_get_nth_page(notebook, page_nr);
1602 label = gtk_notebook_get_tab_label_text(notebook, page);
1604 /* TODO Find a better way to map the current notebook page to the
1605 * corresponding chapter in the documentation, comparing translatable
1606 * strings is easy to break. Maybe attach an identifying string to the
1607 * tab label object. */
1608 if (utils_str_equal(label, _("General")))
1609 suffix = "#general-startup-preferences";
1610 else if (utils_str_equal(label, _("Interface")))
1611 suffix = "#interface-preferences";
1612 else if (utils_str_equal(label, _("Toolbar")))
1613 suffix = "#toolbar-preferences";
1614 else if (utils_str_equal(label, _("Editor")))
1615 suffix = "#editor-features-preferences";
1616 else if (utils_str_equal(label, _("Files")))
1617 suffix = "#files-preferences";
1618 else if (utils_str_equal(label, _("Tools")))
1619 suffix = "#tools-preferences";
1620 else if (utils_str_equal(label, _("Templates")))
1621 suffix = "#template-preferences";
1622 else if (utils_str_equal(label, _("Keybindings")))
1623 suffix = "#keybinding-preferences";
1624 else if (utils_str_equal(label, _("Printing")))
1625 suffix = "#printing-preferences";
1626 else if (utils_str_equal(label, _("Various")))
1627 suffix = "#various-preferences";
1628 else if (utils_str_equal(label, _("Terminal")))
1629 suffix = "#terminal-vte-preferences";
1631 uri = utils_get_help_url(suffix);
1632 utils_open_browser(uri);
1633 g_free(uri);
1637 static gboolean prefs_dialog_key_press_response_cb(GtkWidget *dialog, GdkEventKey *event,
1638 gpointer data)
1640 GeanyKeyBinding *kb = keybindings_lookup_item(GEANY_KEY_GROUP_HELP, GEANY_KEYS_HELP_HELP);
1642 if (keybindings_check_event(event, kb))
1644 open_preferences_help();
1645 return TRUE;
1647 return FALSE;
1651 static void list_store_append_text(GtkListStore *list, const gchar *text)
1653 GtkTreeIter iter;
1655 gtk_list_store_append(list, &iter);
1656 gtk_list_store_set(list, &iter, 0, text, -1);
1660 void prefs_show_dialog(void)
1662 if (ui_widgets.prefs_dialog == NULL)
1664 GtkListStore *eol_list;
1665 GtkWidget *label;
1667 ui_widgets.prefs_dialog = create_prefs_dialog();
1668 gtk_widget_set_name(ui_widgets.prefs_dialog, "GeanyPrefsDialog");
1669 gtk_window_set_transient_for(GTK_WINDOW(ui_widgets.prefs_dialog), GTK_WINDOW(main_widgets.window));
1671 /* init the file encoding combo boxes */
1673 struct {
1674 const gchar *combo, *renderer;
1675 } names[] = {
1676 { "combo_new_encoding", "combo_new_encoding_renderer" },
1677 { "combo_open_encoding", "combo_open_encoding_renderer" }
1679 guint i;
1680 GtkTreeStore *encoding_list = encodings_encoding_store_new(FALSE);
1682 for (i = 0; i < G_N_ELEMENTS(names); i++)
1684 GtkWidget *combo = ui_lookup_widget(ui_widgets.prefs_dialog, names[i].combo);
1686 gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(combo),
1687 ui_builder_get_object(names[i].renderer),
1688 encodings_encoding_store_cell_data_func, NULL, NULL);
1689 gtk_combo_box_set_model(GTK_COMBO_BOX(combo), GTK_TREE_MODEL(encoding_list));
1691 g_object_unref(encoding_list);
1694 /* init the eol character combo box */
1695 eol_list = ui_builder_get_object("eol_list");
1696 list_store_append_text(eol_list, utils_get_eol_name(SC_EOL_CRLF));
1697 list_store_append_text(eol_list, utils_get_eol_name(SC_EOL_CR));
1698 list_store_append_text(eol_list, utils_get_eol_name(SC_EOL_LF));
1701 /* add manually GeanyWrapLabels because they can't be added with Glade */
1702 /* page Tools */
1703 label = geany_wrap_label_new(_("Enter tool paths below. Tools you do not need can be left blank."));
1704 gtk_widget_show(label);
1705 gtk_box_pack_start(GTK_BOX(ui_lookup_widget(ui_widgets.prefs_dialog, "vbox33")),
1706 label, FALSE, TRUE, 5);
1707 /* page Templates */
1708 label = geany_wrap_label_new(_("Set the information to be used in templates. See the documentation for details."));
1709 gtk_widget_show(label);
1710 gtk_box_pack_start(GTK_BOX(ui_lookup_widget(ui_widgets.prefs_dialog, "vbox31")),
1711 label, FALSE, TRUE, 5);
1712 /* page Keybindings */
1713 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."));
1714 gtk_widget_show(label);
1715 gtk_box_pack_start(GTK_BOX(ui_lookup_widget(ui_widgets.prefs_dialog, "vbox32")),
1716 label, FALSE, TRUE, 5);
1717 /* page Editor->Indentation */
1718 label = geany_wrap_label_new(_("<i>Warning: these settings are overridden by the current project. See <b>Project->Properties</b>.</i>"));
1719 gtk_widget_show(label);
1720 gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
1721 gtk_misc_set_padding(GTK_MISC(label), 6, 0);
1722 gtk_box_pack_start(GTK_BOX(ui_lookup_widget(ui_widgets.prefs_dialog,
1723 "label_project_indent_warning")), label, FALSE, TRUE, 5);
1725 /* add the clear icon to GtkEntry widgets in the dialog */
1727 const gchar *names[] = {
1728 "startup_path_entry",
1729 "project_file_path_entry",
1730 "extra_plugin_path_entry",
1731 "entry_toggle_mark",
1732 /* "entry_com_make", */
1733 "entry_com_term",
1734 "entry_browser",
1735 "entry_grep",
1736 "entry_contextaction",
1737 "entry_template_developer",
1738 "entry_template_initial",
1739 "entry_template_mail",
1740 "entry_template_company",
1741 "entry_template_version",
1742 "entry_template_year",
1743 "entry_template_date",
1744 "entry_template_datetime",
1745 "entry_print_external_cmd",
1746 "entry_print_dateformat"};
1747 const gchar **name;
1749 foreach_c_array(name, names, G_N_ELEMENTS(names))
1750 ui_entry_add_clear_icon(GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, *name)));
1753 /* page Various */
1754 various_treeview = GTK_TREE_VIEW(ui_lookup_widget(ui_widgets.prefs_dialog,
1755 "various_treeview"));
1756 stash_tree_setup(pref_groups, various_treeview);
1758 #ifdef HAVE_VTE
1759 vte_append_preferences_tab();
1760 #endif
1762 #ifndef G_OS_WIN32
1763 gtk_widget_hide(ui_lookup_widget(ui_widgets.prefs_dialog, "check_native_windows_dialogs"));
1764 #endif
1765 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets.prefs_dialog, "startup_path_button"), NULL,
1766 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "startup_path_entry")));
1767 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets.prefs_dialog, "extra_plugin_path_button"), NULL,
1768 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "extra_plugin_path_entry")));
1770 g_signal_connect(ui_widgets.prefs_dialog, "response",
1771 G_CALLBACK(on_prefs_dialog_response), NULL);
1772 g_signal_connect(ui_widgets.prefs_dialog, "delete-event",
1773 G_CALLBACK(gtk_widget_hide_on_delete), NULL);
1775 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "tagbar_font"),
1776 "font-set", G_CALLBACK(on_prefs_font_choosed), GINT_TO_POINTER(1));
1777 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "msgwin_font"),
1778 "font-set", G_CALLBACK(on_prefs_font_choosed), GINT_TO_POINTER(2));
1779 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "editor_font"),
1780 "font-set", G_CALLBACK(on_prefs_font_choosed), GINT_TO_POINTER(3));
1781 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "long_line_color"),
1782 "color-set", G_CALLBACK(on_color_button_choose_cb), NULL);
1783 /* file chooser buttons in the tools tab */
1784 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets.prefs_dialog, "button_term"),
1785 NULL,
1786 GTK_FILE_CHOOSER_ACTION_OPEN,
1787 GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_com_term")));
1788 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets.prefs_dialog, "button_browser"),
1789 NULL,
1790 GTK_FILE_CHOOSER_ACTION_OPEN,
1791 GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_browser")));
1792 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets.prefs_dialog, "button_grep"),
1793 NULL,
1794 GTK_FILE_CHOOSER_ACTION_OPEN,
1795 GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_grep")));
1797 /* tools commands */
1798 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets.prefs_dialog, "button_contextaction"),
1799 NULL,
1800 GTK_FILE_CHOOSER_ACTION_OPEN,
1801 GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_contextaction")));
1803 /* printing */
1804 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets.prefs_dialog, "button_print_external_cmd"),
1805 NULL,
1806 GTK_FILE_CHOOSER_ACTION_OPEN,
1807 GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_print_external_cmd")));
1809 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "radio_print_gtk"),
1810 "toggled", G_CALLBACK(on_prefs_print_radio_button_toggled), NULL);
1811 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_print_pageheader"),
1812 "toggled", G_CALLBACK(on_prefs_print_page_header_toggled), NULL);
1814 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_plugins"),
1815 "toggled", G_CALLBACK(on_enable_plugins_toggled), NULL);
1816 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_toolbar_show"),
1817 "toggled", G_CALLBACK(on_toolbar_show_toggled), NULL);
1818 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_show_notebook_tabs"),
1819 "toggled", G_CALLBACK(on_show_notebook_tabs_toggled), NULL);
1820 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_folding"),
1821 "toggled", G_CALLBACK(on_use_folding_toggled), NULL);
1822 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_line_end"),
1823 "toggled", G_CALLBACK(on_check_line_end_toggled), NULL);
1824 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_open_encoding"),
1825 "toggled", G_CALLBACK(on_open_encoding_toggled), NULL);
1826 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_sidebar_visible"),
1827 "toggled", G_CALLBACK(on_sidebar_visible_toggled), NULL);
1829 g_signal_connect(ui_widgets.prefs_dialog,
1830 "key-press-event", G_CALLBACK(prefs_dialog_key_press_response_cb), NULL);
1833 prefs_init_dialog();
1834 gtk_window_present(GTK_WINDOW(ui_widgets.prefs_dialog));