sidebar_openfiles_remove_iter() should be static
[geany-mirror.git] / src / prefs.c
blob4489acb3ae91ad508b9578e6253dccb9280acc50
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));
968 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_tab_label_len");
969 interface_prefs.tab_label_len = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
971 /* Toolbar settings */
972 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_toolbar_show");
973 toolbar_prefs.visible = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
974 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_toolbar_in_menu");
975 toolbar_prefs.append_to_menu = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
977 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_style_default");
978 toolbar_prefs.use_gtk_default_style = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
979 if (! toolbar_prefs.use_gtk_default_style)
981 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_imagetext");
982 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
983 toolbar_prefs.icon_style = 2;
984 else
986 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_image");
987 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
988 toolbar_prefs.icon_style = 0;
989 else
990 /* now only the text only radio remains, so set text only */
991 toolbar_prefs.icon_style = 1;
995 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_icon_default");
996 toolbar_prefs.use_gtk_default_icon = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
997 if (! toolbar_prefs.use_gtk_default_icon)
998 { toolbar_prefs.icon_size = GTK_ICON_SIZE_LARGE_TOOLBAR;
999 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_large");
1000 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
1001 toolbar_prefs.icon_size = GTK_ICON_SIZE_LARGE_TOOLBAR;
1002 else
1004 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_toolbar_small");
1005 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
1006 toolbar_prefs.icon_size = GTK_ICON_SIZE_SMALL_TOOLBAR;
1007 else
1008 toolbar_prefs.icon_size = GTK_ICON_SIZE_MENU;
1012 /* Files settings */
1013 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_tab_right");
1014 file_prefs.tab_order_ltr = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1016 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_tab_beside");
1017 file_prefs.tab_order_beside = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1019 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_new_encoding");
1020 file_prefs.default_new_encoding = ui_encodings_combo_box_get_active_encoding(GTK_COMBO_BOX(widget));
1022 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_open_encoding");
1023 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
1025 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_open_encoding");
1026 file_prefs.default_open_encoding = ui_encodings_combo_box_get_active_encoding(GTK_COMBO_BOX(widget));
1028 else
1029 file_prefs.default_open_encoding = -1;
1031 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_eol");
1032 file_prefs.default_eol_character = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
1034 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_trailing_spaces");
1035 file_prefs.strip_trailing_spaces = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1037 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_new_line");
1038 file_prefs.final_new_line = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1040 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_ensure_convert_new_lines");
1041 file_prefs.ensure_convert_new_lines = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1043 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_replace_tabs");
1044 file_prefs.replace_tabs = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1047 /* Editor settings */
1048 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_toggle_mark");
1049 SETPTR(editor_prefs.comment_toggle_mark,
1050 gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1));
1052 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_long_line");
1053 /* note: use stash for new code - it updates spin buttons itself */
1054 gtk_spin_button_update(GTK_SPIN_BUTTON(widget));
1055 editor_prefs.long_line_column = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
1057 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_folding");
1058 editor_prefs.folding = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1059 ui_update_fold_items();
1061 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_unfold_children");
1062 editor_prefs.unfold_all_children = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1064 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_indent");
1065 editor_prefs.show_indent_guide = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1067 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_white_space");
1068 editor_prefs.show_white_space = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1070 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_line_end");
1071 editor_prefs.show_line_endings = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1073 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_line_endings_only_when_differ");
1074 editor_prefs.show_line_endings_only_when_differ = gtk_toggle_button_get_active(
1075 GTK_TOGGLE_BUTTON(widget));
1077 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_line_numbers");
1078 editor_prefs.show_linenumber_margin = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1080 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_markers_margin");
1081 editor_prefs.show_markers_margin = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1083 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_scroll_stop_at_last_line");
1084 editor_prefs.scroll_stop_at_last_line = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1086 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_line_wrapping");
1087 editor_prefs.line_wrapping = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1089 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_complete_snippets");
1090 editor_prefs.complete_snippets = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1092 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_xmltag");
1093 editor_prefs.auto_close_xml_tags = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1095 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_indicators");
1096 editor_prefs.use_indicators = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1098 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_disable_dnd");
1099 editor_prefs.disable_dnd = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1101 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_smart_home");
1102 editor_prefs.smart_home_key = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1104 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_newline_strip");
1105 editor_prefs.newline_strip = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1107 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_auto_multiline");
1108 editor_prefs.auto_continue_multiline = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1110 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_symbol_auto_completion");
1111 editor_prefs.auto_complete_symbols = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1113 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_symbol_complete_chars");
1114 gtk_spin_button_update(GTK_SPIN_BUTTON(widget));
1115 editor_prefs.symbolcompletion_min_chars = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
1117 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_symbollistheight");
1118 gtk_spin_button_update(GTK_SPIN_BUTTON(widget));
1119 editor_prefs.symbolcompletion_max_height = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
1121 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_line_break");
1122 gtk_spin_button_update(GTK_SPIN_BUTTON(widget));
1123 editor_prefs.line_break_column = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
1125 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_autoclose_parenthesis");
1126 autoclose_brackets[0] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1128 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_autoclose_cbracket");
1129 autoclose_brackets[1] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1131 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_autoclose_sbracket");
1132 autoclose_brackets[2] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1134 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_autoclose_squote");
1135 autoclose_brackets[3] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1137 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_autoclose_dquote");
1138 autoclose_brackets[4] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1140 editor_prefs.autoclose_chars =
1141 (autoclose_brackets[0] ? GEANY_AC_PARENTHESIS : 0u)
1142 | (autoclose_brackets[1] ? GEANY_AC_CBRACKET : 0u)
1143 | (autoclose_brackets[2] ? GEANY_AC_SBRACKET : 0u)
1144 | (autoclose_brackets[3] ? GEANY_AC_SQUOTE : 0u)
1145 | (autoclose_brackets[4] ? GEANY_AC_DQUOTE : 0u);
1147 /* Tools Settings */
1149 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_com_term");
1150 g_free(tool_prefs.term_cmd);
1151 tool_prefs.term_cmd = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1153 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_browser");
1154 g_free(tool_prefs.browser_cmd);
1155 tool_prefs.browser_cmd = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1157 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_grep");
1158 g_free(tool_prefs.grep_cmd);
1159 tool_prefs.grep_cmd = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1162 /* Template settings */
1163 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_developer");
1164 g_free(template_prefs.developer);
1165 template_prefs.developer = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1167 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_company");
1168 g_free(template_prefs.company);
1169 template_prefs.company = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1171 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_mail");
1172 g_free(template_prefs.mail);
1173 template_prefs.mail = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1175 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_initial");
1176 g_free(template_prefs.initials);
1177 template_prefs.initials = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1179 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_version");
1180 g_free(template_prefs.version);
1181 template_prefs.version = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1183 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_year");
1184 g_free(template_prefs.year_format);
1185 template_prefs.year_format = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1187 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_date");
1188 g_free(template_prefs.date_format);
1189 template_prefs.date_format = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1191 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_template_datetime");
1192 g_free(template_prefs.datetime_format);
1193 template_prefs.datetime_format = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1196 /* Keybindings */
1197 if (global_kb_data.edited)
1199 kb_update(&global_kb_data);
1200 tools_create_insert_custom_command_menu_items();
1201 keybindings_write_to_file();
1202 #ifdef MAC_INTEGRATION
1203 /* Force re-syncing the menubar to update displayed keybindings. */
1204 gtkosx_application_sync_menubar(gtkosx_application_get());
1205 #endif
1208 /* Printing */
1209 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_print_gtk");
1210 printing_prefs.use_gtk_printing = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1212 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_print_external_cmd");
1213 g_free(printing_prefs.external_print_cmd);
1214 printing_prefs.external_print_cmd = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1216 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_print_linenumbers");
1217 printing_prefs.print_line_numbers = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1219 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_print_pagenumbers");
1220 printing_prefs.print_page_numbers = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1222 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_print_pageheader");
1223 printing_prefs.print_page_header = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1225 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_print_basename");
1226 printing_prefs.page_header_basename = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1228 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_print_dateformat");
1229 g_free(printing_prefs.page_header_datefmt);
1230 printing_prefs.page_header_datefmt = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1233 #ifdef HAVE_VTE
1234 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_vte");
1235 vte_info.load_vte = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1237 /* VTE settings */
1238 if (vte_info.have_vte)
1240 VteConfig *vc = &vte_config;
1242 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_scrollback");
1243 gtk_spin_button_update(GTK_SPIN_BUTTON(widget));
1244 vc->scrollback_lines = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
1246 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_shell");
1247 g_free(vc->shell);
1248 vc->shell = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
1250 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_scroll_key");
1251 vc->scroll_on_key = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1253 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_scroll_out");
1254 vc->scroll_on_out = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1256 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_enable_bash_keys");
1257 vc->enable_bash_keys = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1259 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_ignore_menu_key");
1260 vc->ignore_menu_bar_accel = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1262 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_follow_path");
1263 vc->follow_path = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1265 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_run_in_vte");
1266 vc->run_in_vte = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1268 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_skip_script");
1269 vc->skip_run_script = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1271 widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_cursor_blinks");
1272 vc->cursor_blinks = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1274 vte_apply_user_settings();
1276 #endif
1278 /* apply the changes made */
1279 ui_statusbar_showhide(interface_prefs.statusbar_visible);
1280 sidebar_openfiles_update_all(); /* to update if full path setting has changed */
1281 toolbar_apply_settings();
1282 toolbar_update_ui();
1283 toolbar_show_hide();
1284 ui_sidebar_show_hide();
1285 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets.notebook), interface_prefs.show_notebook_tabs);
1287 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(main_widgets.notebook), interface_prefs.tab_pos_editor);
1288 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(msgwindow.notebook), interface_prefs.tab_pos_msgwin);
1289 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(main_widgets.sidebar_notebook), interface_prefs.tab_pos_sidebar);
1291 /* re-colourise all open documents, if tab width or long line settings have changed */
1292 for (i = 0; i < documents_array->len; i++)
1294 if (documents[i]->is_valid)
1296 editor_apply_update_prefs(documents[i]->editor);
1297 if (! editor_prefs.folding)
1298 editor_unfold_all(documents[i]->editor);
1300 document_update_tab_label(documents[i]);
1303 ui_document_show_hide(NULL);
1304 ui_update_view_editor_menu_items();
1306 /* various preferences */
1307 ui_save_buttons_toggle((doc != NULL) ? doc->changed : FALSE);
1308 msgwin_show_hide_tabs();
1309 ui_update_statusbar(doc, -1);
1310 ui_set_window_title(doc);
1312 /* store all settings */
1313 configuration_save();
1316 if (response == GTK_RESPONSE_HELP)
1318 open_preferences_help();
1320 else if (response != GTK_RESPONSE_APPLY)
1322 gtk_tree_store_clear(global_kb_data.store);
1323 gtk_widget_hide(GTK_WIDGET(dialog));
1328 static void on_color_button_choose_cb(GtkColorButton *widget, gpointer user_data)
1330 GdkColor color;
1332 gtk_color_button_get_color(widget, &color);
1333 SETPTR(editor_prefs.long_line_color, utils_get_hex_from_color(&color));
1337 static void on_prefs_font_choosed(GtkFontButton *widget, gpointer user_data)
1339 const gchar *fontbtn = gtk_font_button_get_font_name(widget);
1340 guint i;
1342 switch (GPOINTER_TO_INT(user_data))
1344 case 1:
1346 if (strcmp(fontbtn, interface_prefs.tagbar_font) == 0)
1347 break;
1349 SETPTR(interface_prefs.tagbar_font, g_strdup(fontbtn));
1350 for (i = 0; i < documents_array->len; i++)
1352 GeanyDocument *doc = documents[i];
1354 if (documents[i]->is_valid && GTK_IS_WIDGET(doc->priv->tag_tree))
1355 ui_widget_modify_font_from_string(doc->priv->tag_tree,
1356 interface_prefs.tagbar_font);
1358 if (GTK_IS_WIDGET(tv.default_tag_tree))
1359 ui_widget_modify_font_from_string(tv.default_tag_tree, interface_prefs.tagbar_font);
1360 ui_widget_modify_font_from_string(tv.tree_openfiles, interface_prefs.tagbar_font);
1361 break;
1363 case 2:
1365 if (strcmp(fontbtn, interface_prefs.msgwin_font) == 0)
1366 break;
1367 SETPTR(interface_prefs.msgwin_font, g_strdup(fontbtn));
1368 ui_widget_modify_font_from_string(msgwindow.tree_compiler, interface_prefs.msgwin_font);
1369 ui_widget_modify_font_from_string(msgwindow.tree_msg, interface_prefs.msgwin_font);
1370 ui_widget_modify_font_from_string(msgwindow.tree_status, interface_prefs.msgwin_font);
1371 ui_widget_modify_font_from_string(msgwindow.scribble, interface_prefs.msgwin_font);
1372 break;
1374 case 3:
1376 ui_set_editor_font(fontbtn);
1377 break;
1383 static void kb_change_iter_shortcut(KbData *kbdata, GtkTreeIter *iter, const gchar *new_text)
1385 guint lkey;
1386 GdkModifierType lmods;
1388 gtk_accelerator_parse(new_text, &lkey, &lmods);
1390 if (kb_find_duplicate(kbdata->store, ui_widgets.prefs_dialog, iter, lkey, lmods, new_text))
1391 return;
1393 /* set the values here, because of the above check, setting it in
1394 * gtk_accelerator_parse would return a wrong key combination if it is duplicate */
1395 kb_set_shortcut(kbdata->store, iter, lkey, lmods);
1397 kbdata->edited = TRUE;
1401 static void kb_cell_edited_cb(GtkCellRendererText *cellrenderertext,
1402 gchar *path, gchar *new_text, KbData *kbdata)
1404 if (path != NULL && new_text != NULL)
1406 GtkTreeIter iter;
1408 gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(kbdata->store), &iter, path);
1409 if (gtk_tree_model_iter_has_child(GTK_TREE_MODEL(kbdata->store), &iter))
1410 return; /* ignore group items */
1412 kb_change_iter_shortcut(kbdata, &iter, new_text);
1417 static gboolean kb_grab_key_dialog_key_press_cb(GtkWidget *dialog, GdkEventKey *event, GtkLabel *label)
1419 gchar *str;
1420 guint state;
1422 g_return_val_if_fail(GTK_IS_LABEL(label), FALSE);
1424 state = keybindings_get_modifiers(event->state);
1426 if (event->keyval == GDK_KEY_Escape)
1427 return FALSE; /* close the dialog, don't allow escape when detecting keybindings. */
1429 str = gtk_accelerator_name(event->keyval, state);
1431 gtk_label_set_text(label, str);
1432 g_free(str);
1434 return TRUE;
1438 /* test if the entered key combination is already used
1439 * returns true if cancelling duplicate */
1440 static gboolean kb_find_duplicate(GtkTreeStore *store, GtkWidget *parent, GtkTreeIter *old_iter,
1441 guint key, GdkModifierType mods, const gchar *shortcut)
1443 GtkTreeModel *model = GTK_TREE_MODEL(store);
1444 GtkTreeIter parent_iter;
1445 gchar *kb_str;
1446 guint kb_key;
1447 GdkModifierType kb_mods;
1449 /* allow duplicate if there is no key combination */
1450 if (key == 0 && mods == 0)
1451 return FALSE;
1453 /* don't check if the new keybinding is the same as the old one */
1454 gtk_tree_model_get(model, old_iter, KB_TREE_SHORTCUT, &kb_str, -1);
1455 if (kb_str)
1457 gtk_accelerator_parse(kb_str, &kb_key, &kb_mods);
1458 g_free(kb_str);
1459 if (key == kb_key && mods == kb_mods)
1460 return FALSE;
1463 if (! gtk_tree_model_get_iter_first(model, &parent_iter))
1464 return FALSE;
1465 do /* foreach top level */
1467 GtkTreeIter iter;
1469 if (! gtk_tree_model_iter_children(model, &iter, &parent_iter))
1470 continue;
1471 do /* foreach children */
1473 gtk_tree_model_get(model, &iter, KB_TREE_SHORTCUT, &kb_str, -1);
1474 if (! kb_str)
1475 continue;
1477 gtk_accelerator_parse(kb_str, &kb_key, &kb_mods);
1478 g_free(kb_str);
1479 /* search another item with the same key and modifiers */
1480 if (kb_key == key && kb_mods == mods)
1482 gchar *label;
1483 gint ret;
1485 gtk_tree_model_get(model, &iter, KB_TREE_ACTION, &label, -1);
1486 ret = dialogs_show_prompt(parent,
1487 _("_Allow"), GTK_RESPONSE_APPLY,
1488 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1489 _("_Override"), GTK_RESPONSE_YES,
1490 _("Override that keybinding?"),
1491 _("The combination '%s' is already used for \"%s\"."),
1492 shortcut, label);
1494 g_free(label);
1496 if (ret == GTK_RESPONSE_YES)
1498 kb_set_shortcut(store, &iter, 0, 0); /* clear shortcut */
1499 /* carry on looking for other duplicates if overriding */
1500 continue;
1502 return ret != GTK_RESPONSE_APPLY;
1505 while (gtk_tree_model_iter_next(model, &iter));
1507 while (gtk_tree_model_iter_next(model, &parent_iter));
1509 return FALSE;
1513 static void on_toolbar_show_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1515 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1517 gtk_widget_set_sensitive(
1518 ui_lookup_widget(ui_widgets.prefs_dialog, "frame_toolbar_style"), sens);
1519 gtk_widget_set_sensitive(
1520 ui_lookup_widget(ui_widgets.prefs_dialog, "frame_toolbar_icon"), sens);
1521 gtk_widget_set_sensitive(
1522 ui_lookup_widget(ui_widgets.prefs_dialog, "button_customize_toolbar"), sens);
1523 gtk_widget_set_sensitive(
1524 ui_lookup_widget(ui_widgets.prefs_dialog, "check_toolbar_in_menu"), sens);
1528 static void on_show_notebook_tabs_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1530 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1532 /* tab placement only enabled when tabs are visible */
1533 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "combo_tab_editor"), sens);
1534 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "check_show_tab_cross"), sens);
1538 static void on_use_folding_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1540 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1542 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "check_unfold_children"), sens);
1546 static void on_check_line_end_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1548 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1550 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "check_line_endings_only_when_differ"), sens);
1554 static void on_enable_plugins_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1556 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1558 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "extra_plugin_path_entry"), sens);
1559 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "extra_plugin_path_button"), sens);
1563 static void on_open_encoding_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1565 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1567 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "eventbox3"), sens);
1568 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "label_open_encoding"), sens);
1572 static void on_sidebar_visible_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1574 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1576 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "box_sidebar_visible_children"), sens);
1580 static void on_prefs_print_radio_button_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1582 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1584 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "vbox29"), sens);
1585 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "hbox9"), ! sens);
1589 static void on_prefs_print_page_header_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1591 gboolean sens = gtk_toggle_button_get_active(togglebutton);
1593 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "check_print_basename"), sens);
1594 gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_print_dateformat"), sens);
1598 static void open_preferences_help(void)
1600 gchar *uri;
1601 const gchar *label, *suffix = NULL;
1602 GtkNotebook *notebook = GTK_NOTEBOOK(
1603 ui_lookup_widget(ui_widgets.prefs_dialog, "notebook2"));
1604 gint page_nr = gtk_notebook_get_current_page(notebook);
1605 GtkWidget *page = gtk_notebook_get_nth_page(notebook, page_nr);
1607 label = gtk_notebook_get_tab_label_text(notebook, page);
1609 /* TODO Find a better way to map the current notebook page to the
1610 * corresponding chapter in the documentation, comparing translatable
1611 * strings is easy to break. Maybe attach an identifying string to the
1612 * tab label object. */
1613 if (utils_str_equal(label, _("General")))
1614 suffix = "#general-startup-preferences";
1615 else if (utils_str_equal(label, _("Interface")))
1616 suffix = "#interface-preferences";
1617 else if (utils_str_equal(label, _("Toolbar")))
1618 suffix = "#toolbar-preferences";
1619 else if (utils_str_equal(label, _("Editor")))
1620 suffix = "#editor-features-preferences";
1621 else if (utils_str_equal(label, _("Files")))
1622 suffix = "#files-preferences";
1623 else if (utils_str_equal(label, _("Tools")))
1624 suffix = "#tools-preferences";
1625 else if (utils_str_equal(label, _("Templates")))
1626 suffix = "#template-preferences";
1627 else if (utils_str_equal(label, _("Keybindings")))
1628 suffix = "#keybinding-preferences";
1629 else if (utils_str_equal(label, _("Printing")))
1630 suffix = "#printing-preferences";
1631 else if (utils_str_equal(label, _("Various")))
1632 suffix = "#various-preferences";
1633 else if (utils_str_equal(label, _("Terminal")))
1634 suffix = "#terminal-vte-preferences";
1636 uri = utils_get_help_url(suffix);
1637 utils_open_browser(uri);
1638 g_free(uri);
1642 static gboolean prefs_dialog_key_press_response_cb(GtkWidget *dialog, GdkEventKey *event,
1643 gpointer data)
1645 GeanyKeyBinding *kb = keybindings_lookup_item(GEANY_KEY_GROUP_HELP, GEANY_KEYS_HELP_HELP);
1647 if (keybindings_check_event(event, kb))
1649 open_preferences_help();
1650 return TRUE;
1652 return FALSE;
1656 static void list_store_append_text(GtkListStore *list, const gchar *text)
1658 GtkTreeIter iter;
1660 gtk_list_store_append(list, &iter);
1661 gtk_list_store_set(list, &iter, 0, text, -1);
1665 void prefs_show_dialog(void)
1667 if (ui_widgets.prefs_dialog == NULL)
1669 GtkListStore *eol_list;
1670 GtkWidget *label;
1672 ui_widgets.prefs_dialog = create_prefs_dialog();
1673 gtk_widget_set_name(ui_widgets.prefs_dialog, "GeanyPrefsDialog");
1674 gtk_window_set_transient_for(GTK_WINDOW(ui_widgets.prefs_dialog), GTK_WINDOW(main_widgets.window));
1676 /* init the file encoding combo boxes */
1678 struct {
1679 const gchar *combo, *renderer;
1680 } names[] = {
1681 { "combo_new_encoding", "combo_new_encoding_renderer" },
1682 { "combo_open_encoding", "combo_open_encoding_renderer" }
1684 guint i;
1685 GtkTreeStore *encoding_list = encodings_encoding_store_new(FALSE);
1687 for (i = 0; i < G_N_ELEMENTS(names); i++)
1689 GtkWidget *combo = ui_lookup_widget(ui_widgets.prefs_dialog, names[i].combo);
1691 gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(combo),
1692 ui_builder_get_object(names[i].renderer),
1693 encodings_encoding_store_cell_data_func, NULL, NULL);
1694 gtk_combo_box_set_model(GTK_COMBO_BOX(combo), GTK_TREE_MODEL(encoding_list));
1696 g_object_unref(encoding_list);
1699 /* init the eol character combo box */
1700 eol_list = ui_builder_get_object("eol_list");
1701 list_store_append_text(eol_list, utils_get_eol_name(SC_EOL_CRLF));
1702 list_store_append_text(eol_list, utils_get_eol_name(SC_EOL_CR));
1703 list_store_append_text(eol_list, utils_get_eol_name(SC_EOL_LF));
1706 /* add manually GeanyWrapLabels because they can't be added with Glade */
1707 /* page Tools */
1708 label = geany_wrap_label_new(_("Enter tool paths below. Tools you do not need can be left blank."));
1709 gtk_widget_show(label);
1710 gtk_box_pack_start(GTK_BOX(ui_lookup_widget(ui_widgets.prefs_dialog, "vbox33")),
1711 label, FALSE, TRUE, 5);
1712 /* page Templates */
1713 label = geany_wrap_label_new(_("Set the information to be used in templates. See the documentation for details."));
1714 gtk_widget_show(label);
1715 gtk_box_pack_start(GTK_BOX(ui_lookup_widget(ui_widgets.prefs_dialog, "vbox31")),
1716 label, FALSE, TRUE, 5);
1717 /* page Keybindings */
1718 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."));
1719 gtk_widget_show(label);
1720 gtk_box_pack_start(GTK_BOX(ui_lookup_widget(ui_widgets.prefs_dialog, "vbox32")),
1721 label, FALSE, TRUE, 5);
1722 /* page Editor->Indentation */
1723 label = geany_wrap_label_new(_("<i>Warning: these settings are overridden by the current project. See <b>Project->Properties</b>.</i>"));
1724 gtk_widget_show(label);
1725 gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
1726 gtk_misc_set_padding(GTK_MISC(label), 6, 0);
1727 gtk_box_pack_start(GTK_BOX(ui_lookup_widget(ui_widgets.prefs_dialog,
1728 "label_project_indent_warning")), label, FALSE, TRUE, 5);
1730 /* add the clear icon to GtkEntry widgets in the dialog */
1732 const gchar *names[] = {
1733 "startup_path_entry",
1734 "project_file_path_entry",
1735 "extra_plugin_path_entry",
1736 "entry_toggle_mark",
1737 /* "entry_com_make", */
1738 "entry_com_term",
1739 "entry_browser",
1740 "entry_grep",
1741 "entry_contextaction",
1742 "entry_template_developer",
1743 "entry_template_initial",
1744 "entry_template_mail",
1745 "entry_template_company",
1746 "entry_template_version",
1747 "entry_template_year",
1748 "entry_template_date",
1749 "entry_template_datetime",
1750 "entry_print_external_cmd",
1751 "entry_print_dateformat"};
1752 const gchar **name;
1754 foreach_c_array(name, names, G_N_ELEMENTS(names))
1755 ui_entry_add_clear_icon(GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, *name)));
1758 /* page Various */
1759 various_treeview = GTK_TREE_VIEW(ui_lookup_widget(ui_widgets.prefs_dialog,
1760 "various_treeview"));
1761 stash_tree_setup(pref_groups, various_treeview);
1763 #ifdef HAVE_VTE
1764 vte_append_preferences_tab();
1765 #endif
1767 #ifndef G_OS_WIN32
1768 gtk_widget_hide(ui_lookup_widget(ui_widgets.prefs_dialog, "check_native_windows_dialogs"));
1769 #endif
1770 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets.prefs_dialog, "startup_path_button"), NULL,
1771 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "startup_path_entry")));
1772 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets.prefs_dialog, "extra_plugin_path_button"), NULL,
1773 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "extra_plugin_path_entry")));
1775 g_signal_connect(ui_widgets.prefs_dialog, "response",
1776 G_CALLBACK(on_prefs_dialog_response), NULL);
1777 g_signal_connect(ui_widgets.prefs_dialog, "delete-event",
1778 G_CALLBACK(gtk_widget_hide_on_delete), NULL);
1780 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "tagbar_font"),
1781 "font-set", G_CALLBACK(on_prefs_font_choosed), GINT_TO_POINTER(1));
1782 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "msgwin_font"),
1783 "font-set", G_CALLBACK(on_prefs_font_choosed), GINT_TO_POINTER(2));
1784 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "editor_font"),
1785 "font-set", G_CALLBACK(on_prefs_font_choosed), GINT_TO_POINTER(3));
1786 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "long_line_color"),
1787 "color-set", G_CALLBACK(on_color_button_choose_cb), NULL);
1788 /* file chooser buttons in the tools tab */
1789 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets.prefs_dialog, "button_term"),
1790 NULL,
1791 GTK_FILE_CHOOSER_ACTION_OPEN,
1792 GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_com_term")));
1793 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets.prefs_dialog, "button_browser"),
1794 NULL,
1795 GTK_FILE_CHOOSER_ACTION_OPEN,
1796 GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_browser")));
1797 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets.prefs_dialog, "button_grep"),
1798 NULL,
1799 GTK_FILE_CHOOSER_ACTION_OPEN,
1800 GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_grep")));
1802 /* tools commands */
1803 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets.prefs_dialog, "button_contextaction"),
1804 NULL,
1805 GTK_FILE_CHOOSER_ACTION_OPEN,
1806 GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_contextaction")));
1808 /* printing */
1809 ui_setup_open_button_callback(ui_lookup_widget(ui_widgets.prefs_dialog, "button_print_external_cmd"),
1810 NULL,
1811 GTK_FILE_CHOOSER_ACTION_OPEN,
1812 GTK_ENTRY(ui_lookup_widget(ui_widgets.prefs_dialog, "entry_print_external_cmd")));
1814 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "radio_print_gtk"),
1815 "toggled", G_CALLBACK(on_prefs_print_radio_button_toggled), NULL);
1816 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_print_pageheader"),
1817 "toggled", G_CALLBACK(on_prefs_print_page_header_toggled), NULL);
1819 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_plugins"),
1820 "toggled", G_CALLBACK(on_enable_plugins_toggled), NULL);
1821 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_toolbar_show"),
1822 "toggled", G_CALLBACK(on_toolbar_show_toggled), NULL);
1823 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_show_notebook_tabs"),
1824 "toggled", G_CALLBACK(on_show_notebook_tabs_toggled), NULL);
1825 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_folding"),
1826 "toggled", G_CALLBACK(on_use_folding_toggled), NULL);
1827 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_line_end"),
1828 "toggled", G_CALLBACK(on_check_line_end_toggled), NULL);
1829 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_open_encoding"),
1830 "toggled", G_CALLBACK(on_open_encoding_toggled), NULL);
1831 g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_sidebar_visible"),
1832 "toggled", G_CALLBACK(on_sidebar_visible_toggled), NULL);
1834 g_signal_connect(ui_widgets.prefs_dialog,
1835 "key-press-event", G_CALLBACK(prefs_dialog_key_press_response_cb), NULL);
1838 prefs_init_dialog();
1839 gtk_window_present(GTK_WINDOW(ui_widgets.prefs_dialog));