prefs.c 42.8 KB
Newer Older
Enrico Tröger's avatar
Enrico Tröger committed
1 2 3
/*
 *      prefs.c - this file is part of Geany, a fast and lightweight IDE
 *
4
 *      Copyright 2006 Enrico Troeger <enrico.troeger@uvena.de>
Enrico Tröger's avatar
Enrico Tröger committed
5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
18
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Enrico Tröger's avatar
Enrico Tröger committed
19
 *
20
 * $Id$
Enrico Tröger's avatar
Enrico Tröger committed
21 22 23
 */


24
#include <stdlib.h>
25
#include <string.h>
26

Enrico Tröger's avatar
Enrico Tröger committed
27 28 29 30
#include "geany.h"

#include "prefs.h"
#include "support.h"
31
#include "dialogs.h"
Enrico Tröger's avatar
Enrico Tröger committed
32 33 34
#include "utils.h"
#include "msgwindow.h"
#include "sciwrappers.h"
Enrico Tröger's avatar
Enrico Tröger committed
35
#include "document.h"
36
#include "keyfile.h"
37
#include "keybindings.h"
38 39 40
#include "interface.h"
#include "encodings.h"
#include "callbacks.h"
41

42 43 44
#ifdef HAVE_VTE
# include "vte.h"
#endif
Enrico Tröger's avatar
Enrico Tröger committed
45 46 47 48


gint old_tab_width;
gint old_long_line_column;
49
gchar *old_long_line_color;
50 51 52 53 54 55 56 57 58 59 60
gchar *dialog_key_name;
static GtkListStore *store = NULL;
static GtkTreeView *tree = NULL;
GtkWidget *dialog_label;
static gboolean edited = FALSE;

static gboolean on_prefs_tree_view_button_press_event(
						GtkWidget *widget, GdkEventButton *event, gpointer user_data);
static void on_cell_edited(GtkCellRendererText *cellrenderertext, gchar *path, gchar *new_text, gpointer user_data);
static gboolean on_keytype_dialog_response(GtkWidget *dialog, GdkEventKey *event, gpointer user_data);
static void on_dialog_response(GtkWidget *dialog, gint response, gpointer user_data);
61
static gboolean find_duplicate(guint idx, guint key, GdkModifierType mods, const gchar *action);
Enrico Tröger's avatar
Enrico Tröger committed
62 63 64 65 66


void prefs_init_dialog(void)
{
	GtkWidget *widget;
67
	GdkColor *color;
68 69 70
	GtkTreeIter iter;
	guint i;
	gchar *key_string;
Enrico Tröger's avatar
Enrico Tröger committed
71 72

	// General settings
73 74 75
	widget = lookup_widget(app->prefs_dialog, "spin_mru");
	gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), app->mru_length);

Enrico Tröger's avatar
Enrico Tröger committed
76 77 78 79 80 81
	widget = lookup_widget(app->prefs_dialog, "check_load_session");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->pref_main_load_session);

	widget = lookup_widget(app->prefs_dialog, "check_save_win_pos");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->pref_main_save_winpos);

82 83 84
	widget = lookup_widget(app->prefs_dialog, "check_beep");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->beep_on_errors);

85 86 87
	widget = lookup_widget(app->prefs_dialog, "check_switch_pages");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->switch_msgwin_pages);

Enrico Tröger's avatar
Enrico Tröger committed
88 89 90
	widget = lookup_widget(app->prefs_dialog, "check_ask_for_quit");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->pref_main_confirm_exit);

91 92 93 94 95 96 97 98
	if (app->tab_order_ltr)
		widget = lookup_widget(app->prefs_dialog, "radio_tab_right");
	else
		widget = lookup_widget(app->prefs_dialog, "radio_tab_left");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);


	// Interface settings
99
	widget = lookup_widget(app->prefs_dialog, "check_list_symbol");
100
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->sidebar_symbol_visible);
101 102

	widget = lookup_widget(app->prefs_dialog, "check_list_openfiles");
103
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->sidebar_openfiles_visible);
Enrico Tröger's avatar
Enrico Tröger committed
104 105 106 107 108 109 110

	widget = lookup_widget(app->prefs_dialog, "tagbar_font");
	gtk_font_button_set_font_name(GTK_FONT_BUTTON(widget), app->tagbar_font);

	widget = lookup_widget(app->prefs_dialog, "msgwin_font");
	gtk_font_button_set_font_name(GTK_FONT_BUTTON(widget), app->msgwin_font);

111 112 113 114 115 116 117 118 119 120 121 122 123
	widget = lookup_widget(app->prefs_dialog, "editor_font");
	gtk_font_button_set_font_name(GTK_FONT_BUTTON(widget), app->editor_font);

	widget = lookup_widget(app->prefs_dialog, "spin_long_line");
	gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), app->long_line_column);
	old_long_line_column = app->long_line_column;

	switch (app->long_line_type)
	{
		case 0: widget = lookup_widget(app->prefs_dialog, "radio_long_line_line"); break;
		case 1: widget = lookup_widget(app->prefs_dialog, "radio_long_line_background"); break;
		default: widget = lookup_widget(app->prefs_dialog, "radio_long_line_disabled"); break;
	}
Enrico Tröger's avatar
Enrico Tröger committed
124 125
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);

126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
	old_long_line_color = g_strdup(app->long_line_color);

	color = g_new0(GdkColor, 1);
	gdk_color_parse(app->long_line_color, color);
	widget = lookup_widget(app->prefs_dialog, "long_line_color");
	gtk_color_button_set_color(GTK_COLOR_BUTTON(widget), color);
	g_free(color);

	widget = lookup_widget(app->prefs_dialog, "combo_tab_editor");
	gtk_combo_box_set_active(GTK_COMBO_BOX(widget), app->tab_pos_editor);

	widget = lookup_widget(app->prefs_dialog, "combo_tab_msgwin");
	gtk_combo_box_set_active(GTK_COMBO_BOX(widget), app->tab_pos_msgwin);

	widget = lookup_widget(app->prefs_dialog, "combo_tab_sidebar");
	gtk_combo_box_set_active(GTK_COMBO_BOX(widget), app->tab_pos_sidebar);

Enrico Tröger's avatar
Enrico Tröger committed
143

144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
	// Toolbar settings
	widget = lookup_widget(app->prefs_dialog, "check_toolbar_show");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->toolbar_visible);

	widget = lookup_widget(app->prefs_dialog, "check_toolbar_search");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->pref_toolbar_show_search);

	widget = lookup_widget(app->prefs_dialog, "check_toolbar_goto");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->pref_toolbar_show_goto);

	widget = lookup_widget(app->prefs_dialog, "check_toolbar_compile");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->pref_toolbar_show_compile);

	widget = lookup_widget(app->prefs_dialog, "check_toolbar_zoom");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->pref_toolbar_show_zoom);

	widget = lookup_widget(app->prefs_dialog, "check_toolbar_undo");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->pref_toolbar_show_undo);

	widget = lookup_widget(app->prefs_dialog, "check_toolbar_colour");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->pref_toolbar_show_colour);

166 167 168
	widget = lookup_widget(app->prefs_dialog, "check_toolbar_fileops");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->pref_toolbar_show_fileops);

169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190

	switch (app->toolbar_icon_style)
	{
		case 0: widget = lookup_widget(app->prefs_dialog, "radio_toolbar_image"); break;
		case 1: widget = lookup_widget(app->prefs_dialog, "radio_toolbar_text"); break;
		default: widget = lookup_widget(app->prefs_dialog, "radio_toolbar_imagetext"); break;
	}
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);


	switch (app->toolbar_icon_size)
	{
		case GTK_ICON_SIZE_LARGE_TOOLBAR:
				widget = lookup_widget(app->prefs_dialog, "radio_toolbar_large"); break;
		default: widget = lookup_widget(app->prefs_dialog, "radio_toolbar_small"); break;
	}
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
	// disable elements if toolbar is hidden
	on_pref_toolbar_show_toggled(GTK_TOGGLE_BUTTON(
					lookup_widget(app->prefs_dialog, "check_toolbar_show")), NULL);


Enrico Tröger's avatar
Enrico Tröger committed
191 192 193 194 195
	// Editor settings
	widget = lookup_widget(app->prefs_dialog, "spin_tab_width");
	gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), app->pref_editor_tab_width);
	old_tab_width = app->pref_editor_tab_width;

196 197 198 199
	widget = lookup_widget(app->prefs_dialog, "combo_encoding");
	// luckily the index of the combo box items match the index of the encodings array
	gtk_combo_box_set_active(GTK_COMBO_BOX(widget), app->pref_editor_default_encoding);

Enrico Tröger's avatar
Enrico Tröger committed
200 201 202 203 204 205
	widget = lookup_widget(app->prefs_dialog, "check_trailing_spaces");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->pref_editor_trail_space);

	widget = lookup_widget(app->prefs_dialog, "check_new_line");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->pref_editor_new_line);

206 207 208
	widget = lookup_widget(app->prefs_dialog, "check_replace_tabs");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->pref_editor_replace_tabs);

209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
	widget = lookup_widget(app->prefs_dialog, "check_indent");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->pref_editor_show_indent_guide);

	widget = lookup_widget(app->prefs_dialog, "check_white_space");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->pref_editor_show_white_space);

	widget = lookup_widget(app->prefs_dialog, "check_line_end");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->pref_editor_show_line_endings);

	widget = lookup_widget(app->prefs_dialog, "check_xmltag");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->pref_editor_auto_close_xml_tags);

	widget = lookup_widget(app->prefs_dialog, "check_auto_complete");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->pref_editor_auto_complete_constructs);

Enrico Tröger's avatar
Enrico Tröger committed
224 225 226
	widget = lookup_widget(app->prefs_dialog, "check_folding");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->pref_editor_folding);

227 228 229
	widget = lookup_widget(app->prefs_dialog, "check_indicators");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->pref_editor_use_indicators);

Enrico Tröger's avatar
Enrico Tröger committed
230 231

	// Tools Settings
232
#ifdef GEANY_WIN32
233
        // hide related Make path setting
234 235 236 237 238 239 240 241 242
        gtk_widget_set_sensitive(lookup_widget(app->prefs_dialog, "label11"), FALSE);
        gtk_widget_set_sensitive(lookup_widget(app->prefs_dialog, "entry_com_make"), FALSE);
        gtk_widget_set_sensitive(lookup_widget(app->prefs_dialog, "button_make"), FALSE);

        // hide related Terminal path setting
        gtk_widget_set_sensitive(lookup_widget(app->prefs_dialog, "label97"), FALSE);
        gtk_widget_set_sensitive(lookup_widget(app->prefs_dialog, "entry_com_term"), FALSE);
        gtk_widget_set_sensitive(lookup_widget(app->prefs_dialog, "button_term"), FALSE);
#else
243 244
        if (app->tools_make_cmd)
                gtk_entry_set_text(GTK_ENTRY(lookup_widget(app->prefs_dialog, "entry_com_make")), app->tools_make_cmd);
245

246 247
        if (app->tools_term_cmd)
                gtk_entry_set_text(GTK_ENTRY(lookup_widget(app->prefs_dialog, "entry_com_term")), app->tools_term_cmd);
248
#endif
249 250
	if (app->tools_browser_cmd)
		gtk_entry_set_text(GTK_ENTRY(lookup_widget(app->prefs_dialog, "entry_browser")), app->tools_browser_cmd);
Enrico Tröger's avatar
Enrico Tröger committed
251

252
	if (app->tools_print_cmd)
253 254
		gtk_entry_set_text(GTK_ENTRY(lookup_widget(app->prefs_dialog, "entry_print")), app->tools_print_cmd);

255 256 257
	if (app->tools_grep_cmd)
		gtk_entry_set_text(GTK_ENTRY(lookup_widget(app->prefs_dialog, "entry_grep")), app->tools_grep_cmd);

Enrico Tröger's avatar
Enrico Tröger committed
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273

	// Template settings
	widget = lookup_widget(app->prefs_dialog, "entry_template_developer");
	gtk_entry_set_text(GTK_ENTRY(widget), app->pref_template_developer);

	widget = lookup_widget(app->prefs_dialog, "entry_template_company");
	gtk_entry_set_text(GTK_ENTRY(widget), app->pref_template_company);

	widget = lookup_widget(app->prefs_dialog, "entry_template_mail");
	gtk_entry_set_text(GTK_ENTRY(widget), app->pref_template_mail);

	widget = lookup_widget(app->prefs_dialog, "entry_template_initial");
	gtk_entry_set_text(GTK_ENTRY(widget), app->pref_template_initial);

	widget = lookup_widget(app->prefs_dialog, "entry_template_version");
	gtk_entry_set_text(GTK_ENTRY(widget), app->pref_template_version);
274 275


276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
	// Keybindings
	if (store == NULL)
	{
		GtkCellRenderer *renderer;
		GtkTreeViewColumn *column;

		tree = GTK_TREE_VIEW(lookup_widget(app->prefs_dialog, "treeview7"));
		//g_object_set(tree, "vertical-separator", 6, NULL);

		store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
		gtk_tree_view_set_model(GTK_TREE_VIEW(tree), GTK_TREE_MODEL(store));

		renderer = gtk_cell_renderer_text_new();
		column = gtk_tree_view_column_new_with_attributes(_("Action"), renderer, "text", 0, NULL);
		gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);

		renderer = gtk_cell_renderer_text_new();
		g_object_set(renderer, "editable", TRUE, NULL);
		column = gtk_tree_view_column_new_with_attributes(_("Shortcut"), renderer, "text", 1, NULL);
		gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);

297 298 299 300
		// set policy settings for the scollwedwindow around the treeview again, because glade
		// doesn't keep the settings
		gtk_scrolled_window_set_policy(
				GTK_SCROLLED_WINDOW(lookup_widget(app->prefs_dialog, "scrolledwindow8")),
301
				GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
302

303 304 305 306 307 308 309 310 311 312 313
		g_signal_connect(G_OBJECT(renderer), "edited", G_CALLBACK(on_cell_edited), NULL);
		g_signal_connect(G_OBJECT(tree), "button-press-event",
					G_CALLBACK(on_prefs_tree_view_button_press_event), NULL);
		g_signal_connect(G_OBJECT(lookup_widget(app->prefs_dialog, "button2")), "button-press-event",
					G_CALLBACK(on_prefs_tree_view_button_press_event), NULL);
	}

	for (i = 0; i < GEANY_MAX_KEYS; i++)
	{
		key_string = gtk_accelerator_name(keys[i]->key, keys[i]->mods);
		gtk_list_store_append(store, &iter);
314
		gtk_list_store_set(store, &iter, 0, keys[i]->label, 1, key_string, -1);
315 316 317 318
		g_free(key_string);
	}


319
#ifdef HAVE_VTE
320 321 322 323 324
	// make VTE switch visible only when VTE is compiled in, it is hidden by default
	widget = lookup_widget(app->prefs_dialog, "check_vte");
	gtk_widget_show(widget);
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->load_vte);

325
	// VTE settings
326 327 328 329
	if (app->have_vte)
	{
		widget = lookup_widget(app->prefs_dialog, "font_term");
		gtk_font_button_set_font_name(GTK_FONT_BUTTON(widget), vc->font);
330

331 332
		widget = lookup_widget(app->prefs_dialog, "color_fore");
		gtk_color_button_set_color(GTK_COLOR_BUTTON(widget), vc->color_fore);
333

334 335
		widget = lookup_widget(app->prefs_dialog, "color_back");
		gtk_color_button_set_color(GTK_COLOR_BUTTON(widget), vc->color_back);
336

337 338
		widget = lookup_widget(app->prefs_dialog, "spin_scrollback");
		gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), vc->scrollback_lines);
339

340 341
		widget = lookup_widget(app->prefs_dialog, "entry_emulation");
		gtk_entry_set_text(GTK_ENTRY(widget), vc->emulation);
342

343 344
		widget = lookup_widget(app->prefs_dialog, "check_scroll_key");
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), vc->scroll_on_key);
345

346 347
		widget = lookup_widget(app->prefs_dialog, "check_scroll_out");
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), vc->scroll_on_out);
348 349 350

		widget = lookup_widget(app->prefs_dialog, "check_follow_path");
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), vc->follow_path);
351
	}
352
#endif
Enrico Tröger's avatar
Enrico Tröger committed
353 354
}

355
//gtk_notebook_set_tab_pos
Enrico Tröger's avatar
Enrico Tröger committed
356 357 358 359 360 361 362 363 364

/*
 * callbacks
 */
void on_prefs_button_clicked(GtkDialog *dialog, gint response, gpointer user_data)
{
	if (response == GTK_RESPONSE_OK)
	{
		GtkWidget *widget;
365
		gint i;
Enrico Tröger's avatar
Enrico Tröger committed
366 367

		// General settings
368 369 370
		widget = lookup_widget(app->prefs_dialog, "spin_mru");
		app->mru_length = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));

Enrico Tröger's avatar
Enrico Tröger committed
371 372 373 374 375 376
		widget = lookup_widget(app->prefs_dialog, "check_load_session");
		app->pref_main_load_session = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));

		widget = lookup_widget(app->prefs_dialog, "check_save_win_pos");
		app->pref_main_save_winpos = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));

377 378 379
		widget = lookup_widget(app->prefs_dialog, "check_beep");
		app->beep_on_errors = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));

Enrico Tröger's avatar
Enrico Tröger committed
380 381 382
		widget = lookup_widget(app->prefs_dialog, "check_ask_for_quit");
		app->pref_main_confirm_exit = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));

383 384 385
		widget = lookup_widget(app->prefs_dialog, "check_switch_pages");
		app->switch_msgwin_pages = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));

386 387 388 389 390
		widget = lookup_widget(app->prefs_dialog, "radio_tab_right");
		app->tab_order_ltr = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));


		// Interface settings
391
		widget = lookup_widget(app->prefs_dialog, "check_list_symbol");
392
		app->sidebar_symbol_visible = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
393 394

		widget = lookup_widget(app->prefs_dialog, "check_list_openfiles");
395
		app->sidebar_openfiles_visible = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
Enrico Tröger's avatar
Enrico Tröger committed
396

397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
		widget = lookup_widget(app->prefs_dialog, "radio_long_line_line");
		if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) app->long_line_type = 0;
		else
		{
			widget = lookup_widget(app->prefs_dialog, "radio_long_line_background");
			if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) app->long_line_type = 1;
			else
			{	// now only the disabled radio remains, so disable it
				app->long_line_type = 2;
			}
		}
		if (app->long_line_column == 0) app->long_line_type = 2;

		widget = lookup_widget(app->prefs_dialog, "combo_tab_editor");
		app->tab_pos_editor = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));

		widget = lookup_widget(app->prefs_dialog, "combo_tab_msgwin");
		app->tab_pos_msgwin = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));

		widget = lookup_widget(app->prefs_dialog, "combo_tab_sidebar");
		app->tab_pos_sidebar = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
418

419

420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441
		// Toolbar settings
		widget = lookup_widget(app->prefs_dialog, "check_toolbar_show");
		app->toolbar_visible = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));

		widget = lookup_widget(app->prefs_dialog, "check_toolbar_search");
		app->pref_toolbar_show_search = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));

		widget = lookup_widget(app->prefs_dialog, "check_toolbar_goto");
		app->pref_toolbar_show_goto = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));

		widget = lookup_widget(app->prefs_dialog, "check_toolbar_zoom");
		app->pref_toolbar_show_zoom = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));

		widget = lookup_widget(app->prefs_dialog, "check_toolbar_undo");
		app->pref_toolbar_show_undo = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));

		widget = lookup_widget(app->prefs_dialog, "check_toolbar_compile");
		app->pref_toolbar_show_compile = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));

		widget = lookup_widget(app->prefs_dialog, "check_toolbar_colour");
		app->pref_toolbar_show_colour = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));

442 443 444
		widget = lookup_widget(app->prefs_dialog, "check_toolbar_fileops");
		app->pref_toolbar_show_fileops = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));

445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
		widget = lookup_widget(app->prefs_dialog, "radio_toolbar_imagetext");
		if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) app->toolbar_icon_style = 2;
		else
		{
			widget = lookup_widget(app->prefs_dialog, "radio_toolbar_image");
			if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
				app->toolbar_icon_style = 0;
			else
				// now only the text only radio remains, so set text only
				app->toolbar_icon_style = 1;
		}


		widget = lookup_widget(app->prefs_dialog, "radio_toolbar_large");
		if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
			app->toolbar_icon_size = GTK_ICON_SIZE_LARGE_TOOLBAR;
		else
			app->toolbar_icon_size = GTK_ICON_SIZE_SMALL_TOOLBAR;


Enrico Tröger's avatar
Enrico Tröger committed
465 466 467 468
		// Editor settings
		widget = lookup_widget(app->prefs_dialog, "spin_tab_width");
		app->pref_editor_tab_width = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));

469 470 471
		widget = lookup_widget(app->prefs_dialog, "combo_encoding");
		app->pref_editor_default_encoding = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));

Enrico Tröger's avatar
Enrico Tröger committed
472 473 474 475 476 477
		widget = lookup_widget(app->prefs_dialog, "check_trailing_spaces");
		app->pref_editor_trail_space = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));

		widget = lookup_widget(app->prefs_dialog, "check_new_line");
		app->pref_editor_new_line = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));

478 479 480
		widget = lookup_widget(app->prefs_dialog, "check_replace_tabs");
		app->pref_editor_replace_tabs = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));

Enrico Tröger's avatar
Enrico Tröger committed
481 482 483
		widget = lookup_widget(app->prefs_dialog, "spin_long_line");
		app->long_line_column = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));

Enrico Tröger's avatar
Enrico Tröger committed
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
		widget = lookup_widget(app->prefs_dialog, "check_folding");
		app->pref_editor_folding = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
		utils_update_fold_items();

		widget = lookup_widget(app->prefs_dialog, "check_indent");
		app->pref_editor_show_indent_guide = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));

		widget = lookup_widget(app->prefs_dialog, "check_white_space");
		app->pref_editor_show_white_space = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));

		widget = lookup_widget(app->prefs_dialog, "check_line_end");
		app->pref_editor_show_line_endings = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));

		widget = lookup_widget(app->prefs_dialog, "check_xmltag");
		app->pref_editor_auto_close_xml_tags = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));

		widget = lookup_widget(app->prefs_dialog, "check_auto_complete");
		app->pref_editor_auto_complete_constructs = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));

503 504 505
		widget = lookup_widget(app->prefs_dialog, "check_indicators");
		app->pref_editor_use_indicators = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));

Enrico Tröger's avatar
Enrico Tröger committed
506 507 508

		// Tools Settings
		widget = lookup_widget(app->prefs_dialog, "entry_com_make");
509 510
		g_free(app->tools_make_cmd);
		app->tools_make_cmd = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
Enrico Tröger's avatar
Enrico Tröger committed
511 512

		widget = lookup_widget(app->prefs_dialog, "entry_com_term");
513 514
		g_free(app->tools_term_cmd);
		app->tools_term_cmd = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
Enrico Tröger's avatar
Enrico Tröger committed
515 516

		widget = lookup_widget(app->prefs_dialog, "entry_browser");
517 518
		g_free(app->tools_browser_cmd);
		app->tools_browser_cmd = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
Enrico Tröger's avatar
Enrico Tröger committed
519

520 521 522 523
		widget = lookup_widget(app->prefs_dialog, "entry_print");
		g_free(app->tools_print_cmd);
		app->tools_print_cmd = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));

524 525 526 527
		widget = lookup_widget(app->prefs_dialog, "entry_grep");
		g_free(app->tools_grep_cmd);
		app->tools_grep_cmd = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));

528

Enrico Tröger's avatar
Enrico Tröger committed
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
		// Template settings
		widget = lookup_widget(app->prefs_dialog, "entry_template_developer");
		g_free(app->pref_template_developer);
		app->pref_template_developer = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));

		widget = lookup_widget(app->prefs_dialog, "entry_template_company");
		g_free(app->pref_template_company);
		app->pref_template_company = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));

		widget = lookup_widget(app->prefs_dialog, "entry_template_mail");
		g_free(app->pref_template_mail);
		app->pref_template_mail = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));

		widget = lookup_widget(app->prefs_dialog, "entry_template_initial");
		g_free(app->pref_template_initial);
		app->pref_template_initial = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));

		widget = lookup_widget(app->prefs_dialog, "entry_template_version");
		g_free(app->pref_template_version);
		app->pref_template_version = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));


551 552 553
		// Keybindings
		if (edited) keybindings_write_to_file();

554
#ifdef HAVE_VTE
555 556 557
		widget = lookup_widget(app->prefs_dialog, "check_vte");
		app->load_vte = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));

558
		// VTE settings
559 560 561
		if (app->have_vte)
		{
			gchar *hex_color_back, *hex_color_fore;
562

563 564
			widget = lookup_widget(app->prefs_dialog, "spin_scrollback");
			vc->scrollback_lines = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
565

566 567 568
			widget = lookup_widget(app->prefs_dialog, "entry_emulation");
			g_free(vc->emulation);
			vc->emulation = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
569

570 571
			widget = lookup_widget(app->prefs_dialog, "check_scroll_key");
			vc->scroll_on_key = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
572

573 574 575
			widget = lookup_widget(app->prefs_dialog, "check_scroll_out");
			vc->scroll_on_out = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));

576 577 578
			widget = lookup_widget(app->prefs_dialog, "check_follow_path");
			vc->follow_path = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));

579 580 581
			g_free(app->terminal_settings);
			hex_color_fore = utils_get_hex_from_color(vc->color_fore);
			hex_color_back = utils_get_hex_from_color(vc->color_back);
582
			app->terminal_settings = g_strdup_printf("%s;%s;%s;%d;%s;%s;%s;%s", vc->font,
583 584
					hex_color_fore, hex_color_back,
					vc->scrollback_lines, vc->emulation,
585 586
					utils_btoa(vc->scroll_on_key), utils_btoa(vc->scroll_on_out),
					utils_btoa(vc->follow_path));
587 588 589 590 591

			vte_apply_user_settings();
			g_free(hex_color_fore);
			g_free(hex_color_back);
		}
592 593
#endif

Enrico Tröger's avatar
Enrico Tröger committed
594
		// apply the changes made
595 596 597
		utils_update_toolbar_items();
		utils_update_toolbar_icons(app->toolbar_icon_size);
		gtk_toolbar_set_style(GTK_TOOLBAR(app->toolbar), app->toolbar_icon_style);
598
		utils_treeviews_showhide();
Enrico Tröger's avatar
Enrico Tröger committed
599

600 601 602 603
		gtk_notebook_set_tab_pos(GTK_NOTEBOOK(app->notebook), app->tab_pos_editor);
		gtk_notebook_set_tab_pos(GTK_NOTEBOOK(msgwindow.notebook), app->tab_pos_msgwin);
		gtk_notebook_set_tab_pos(GTK_NOTEBOOK(app->treeview_notebook), app->tab_pos_sidebar);

604 605
		// re-colourise all open documents, if tab width or long line settings have changed
		for (i = 0; i < GEANY_MAX_OPEN_FILES; i++)
Enrico Tröger's avatar
Enrico Tröger committed
606
		{
607
			if (doc_list[i].is_valid)
Enrico Tröger's avatar
Enrico Tröger committed
608
			{
609 610 611 612 613 614 615 616 617
				sci_set_tab_width(doc_list[i].sci, app->pref_editor_tab_width);
				sci_set_mark_long_lines(doc_list[i].sci, app->long_line_type,
										app->long_line_column, app->long_line_color);
				sci_set_visible_eols(doc_list[i].sci, app->pref_editor_show_line_endings);
				sci_set_indentionguides(doc_list[i].sci, app->pref_editor_show_indent_guide);
				sci_set_visible_white_spaces(doc_list[i].sci, app->pref_editor_show_white_space);
				sci_set_folding_margin_visible(doc_list[i].sci, app->pref_editor_folding);
				if (! app->pref_editor_folding) document_unfold_all(i);
			}
Enrico Tröger's avatar
Enrico Tröger committed
618
		}
619 620 621 622
		old_tab_width = app->pref_editor_tab_width;
		old_long_line_column = app->long_line_column;
		g_free(old_long_line_color);
		old_long_line_color = g_strdup(app->long_line_color);
Enrico Tröger's avatar
Enrico Tröger committed
623

624 625
		// store all settings
		configuration_save();
Enrico Tröger's avatar
Enrico Tröger committed
626
	}
627
	gtk_list_store_clear(store);
Enrico Tröger's avatar
Enrico Tröger committed
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643
	gtk_widget_hide(GTK_WIDGET(dialog));
}


gboolean on_prefs_delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data)
{
	gtk_widget_hide(widget);

	return TRUE;
}


void on_prefs_color_choosed(GtkColorButton *widget, gpointer user_data)
{
	GdkColor color;

644 645 646 647 648 649 650 651
	switch (GPOINTER_TO_INT(user_data))
	{
		case 1:
		{
			gtk_color_button_get_color(widget, &color);
			app->long_line_color = utils_get_hex_from_color(&color);
			break;
		}
652
#ifdef HAVE_VTE
653 654 655
		case 2:
		{
			g_free(vc->color_fore);
Enrico Tröger's avatar
Enrico Tröger committed
656
			vc->color_fore = g_new0(GdkColor, 1);
657 658 659 660 661 662
			gtk_color_button_get_color(widget, vc->color_fore);
			break;
		}
		case 3:
		{
			g_free(vc->color_back);
Enrico Tröger's avatar
Enrico Tröger committed
663
			vc->color_back = g_new0(GdkColor, 1);
664 665 666
			gtk_color_button_get_color(widget, vc->color_back);
			break;
		}
667
#endif
668
	}
Enrico Tröger's avatar
Enrico Tröger committed
669 670 671 672 673
}


void on_prefs_font_choosed(GtkFontButton *widget, gpointer user_data)
{
674 675 676
	const gchar *fontbtn = gtk_font_button_get_font_name(widget);
	gint i;

677
	switch (GPOINTER_TO_INT(user_data))
Enrico Tröger's avatar
Enrico Tröger committed
678
	{
679 680
		case 1:
		{
681
			if (strcmp(fontbtn, app->tagbar_font) == 0) break;
682
			g_free(app->tagbar_font);
683 684 685 686 687 688 689 690 691 692 693 694
			app->tagbar_font = g_strdup(fontbtn);
			for (i = 0; i < GEANY_MAX_OPEN_FILES; i++)
			{
				if (doc_list[i].is_valid && GTK_IS_WIDGET(doc_list[i].tag_tree))
					gtk_widget_modify_font(doc_list[i].tag_tree,
						pango_font_description_from_string(app->tagbar_font));
			}
			if (GTK_IS_WIDGET(app->default_tag_tree))
				gtk_widget_modify_font(app->default_tag_tree,
					pango_font_description_from_string(app->tagbar_font));
			gtk_widget_modify_font(lookup_widget(app->window, "entry1"),
				pango_font_description_from_string(app->tagbar_font));
695 696 697 698
			break;
		}
		case 2:
		{
699
			if (strcmp(fontbtn, app->msgwin_font) == 0) break;
700
			g_free(app->msgwin_font);
701 702 703 704 705 706 707
			app->msgwin_font = g_strdup(fontbtn);
			gtk_widget_modify_font(msgwindow.tree_compiler,
				pango_font_description_from_string(app->msgwin_font));
			gtk_widget_modify_font(msgwindow.tree_msg,
				pango_font_description_from_string(app->msgwin_font));
			gtk_widget_modify_font(msgwindow.tree_status,
				pango_font_description_from_string(app->msgwin_font));
708 709 710 711
			break;
		}
		case 3:
		{
712
			utils_set_editor_font(fontbtn);
713 714
			break;
		}
715
#ifdef HAVE_VTE
716 717 718
		case 4:
		{
			// VTE settings
719
			if (strcmp(fontbtn, vc->font) == 0) break;
720 721
			g_free(vc->font);
			vc->font = g_strdup(gtk_font_button_get_font_name(widget));
722
			vte_apply_user_settings();
723 724
			break;
		}
725
#endif
Enrico Tröger's avatar
Enrico Tröger committed
726 727 728
	}
}

729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785


static gboolean on_prefs_tree_view_button_press_event(
						GtkWidget *widget, GdkEventButton *event, gpointer user_data)
{
	GtkTreeIter iter;
	GtkTreeModel *model;
	GtkTreeSelection *selection;
	gchar *name;

	// discard click events in the tree unless it is a double click
	if (widget == (GtkWidget*)tree && event->type != GDK_2BUTTON_PRESS) return FALSE;

	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree));
	if (gtk_tree_selection_get_selected(selection, &model, &iter))
	{
		gtk_tree_model_get(model, &iter, 0, &name, -1);
		if (name != NULL)
		{
			GtkWidget *dialog;
			GtkWidget *label;
			gchar *str;

			dialog = gtk_dialog_new_with_buttons(_("Grab key"), GTK_WINDOW(app->prefs_dialog),
					GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
					GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL);

			str = g_strdup_printf(_("Type the combination of the keys you want to use for \"%s\""), name);
			label = gtk_label_new(str);
			gtk_misc_set_padding(GTK_MISC(label), 5, 10);
			gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), label);

			dialog_label = gtk_label_new("");
			gtk_misc_set_padding(GTK_MISC(dialog_label), 5, 10);
			gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), dialog_label);

			g_signal_connect(G_OBJECT(dialog), "key-press-event", G_CALLBACK(on_keytype_dialog_response), NULL);
			g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(on_dialog_response), NULL);
			g_signal_connect(G_OBJECT(dialog), "close", G_CALLBACK(gtk_widget_destroy), NULL);

			// copy name to global variable to hold it, will be freed in on_dialog_response()
			dialog_key_name = g_strdup(name);

			gtk_widget_show_all(dialog);
			g_free(str);
			g_free(name);
		}
	}
	return TRUE;
}


static void on_cell_edited(GtkCellRendererText *cellrenderertext, gchar *path, gchar *new_text, gpointer user_data)
{
	if (path != NULL && new_text != NULL)
	{
		guint idx;
786 787
		guint lkey;
		GdkModifierType lmods;
788 789 790 791 792 793 794
		gchar *test;
		GtkTreeIter iter;

		// get the index of the shortcut
		idx = strtol(path, &test, 10);
		if (test == path) return;

795 796 797 798 799 800 801 802
		gtk_accelerator_parse(new_text, &lkey, &lmods);

		if (find_duplicate(idx, lkey, lmods, new_text)) return;

		// set the values here, because of the above check, setting it in gtk_accelerator_parse would
		// return a wrong key combination if it is duplicate
		keys[idx]->key = lkey;
		keys[idx]->mods = lmods;
803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833

		gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(store), &iter, path);
		gtk_list_store_set(store, &iter, 1, new_text, -1);

		edited = TRUE;
	}
}


static gboolean on_keytype_dialog_response(GtkWidget *dialog, GdkEventKey *event, gpointer user_data)
{
	gchar *str;

	// ignore numlock key, not necessary but nice
	if (event->state & GDK_MOD2_MASK) event->state -= GDK_MOD2_MASK;

	str = gtk_accelerator_name(event->keyval, event->state);

	gtk_label_set_text(GTK_LABEL(dialog_label), str);
	g_free(str);

	return TRUE;
}


static void on_dialog_response(GtkWidget *dialog, gint response, gpointer user_data)
{
	if (response == GTK_RESPONSE_ACCEPT)
	{
		GtkTreeIter iter;
		guint idx;
834 835
		guint lkey;
		GdkModifierType lmods;
836 837 838 839
		gchar path[3];

		for (idx = 0; idx < GEANY_MAX_KEYS; idx++)
		{
840
			if (utils_strcmp(dialog_key_name, keys[idx]->label)) break;
841 842
		}

843 844 845 846 847 848 849 850
		gtk_accelerator_parse(gtk_label_get_text(GTK_LABEL(dialog_label)), &lkey, &lmods);

		if (find_duplicate(idx, lkey, lmods, gtk_label_get_text(GTK_LABEL(dialog_label)))) return;

		// set the values here, because of the above check, setting it in gtk_accelerator_parse would
		// return a wrong key combination if it is duplicate
		keys[idx]->key = lkey;
		keys[idx]->mods = lmods;
851 852 853 854 855 856

		// generate the path, it is exactly the index
		g_snprintf(path, 3, "%d", idx);
		gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(store), &iter, path);
		gtk_list_store_set(store, &iter, 1, gtk_label_get_text(GTK_LABEL(dialog_label)), -1);
		g_free(dialog_key_name);
857
		dialog_key_name = NULL;
858 859 860 861 862

		edited = TRUE;
	}
	gtk_widget_destroy(dialog);
}
863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880


// test if the entered key combination is already used
static gboolean find_duplicate(guint idx, guint key, GdkModifierType mods, const gchar *action)
{
	guint i;

	// allow duplicate if there is no key combination
	if (key == 0 && mods == 0) return FALSE;

	for (i = 0; i < GEANY_MAX_KEYS; i++)
	{
		// search another item with the same key, but take not the key we are searching for(-> idx)
		if (keys[i]->key == key && keys[i]->mods == mods
			&& ! (keys[i]->key == keys[idx]->key && keys[i]->mods == keys[idx]->mods))
		{
			dialogs_show_error(
				_("The combination '%s' is already used for \"%s\". Please choose another one."),
881
				action, keys[i]->label);
882 883 884 885 886 887 888
			return TRUE;
		}
	}
	return FALSE;
}


889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085
void on_pref_toolbar_show_toggled(GtkToggleButton *togglebutton, gpointer user_data)
{
	gboolean sens = gtk_toggle_button_get_active(togglebutton);

	gtk_widget_set_sensitive(lookup_widget(app->prefs_dialog, "frame11"), sens);
	gtk_widget_set_sensitive(lookup_widget(app->prefs_dialog, "frame13"), sens);
}


void dialogs_show_prefs_dialog(void)
{
	if (app->prefs_dialog == NULL)
	{
#ifdef HAVE_VTE
		GtkWidget *notebook, *vbox, *label, *alignment, *table;
		GtkWidget *font_term, *color_fore, *color_back, *spin_scrollback, *entry_emulation;
		GtkWidget *check_scroll_key, *check_scroll_out, *check_follow_path;
		GtkTooltips *tooltips;
		GtkObject *spin_scrollback_adj;
#endif
		GtkWidget *combo;
		guint i;
		gchar *encoding_string;

		app->prefs_dialog = create_prefs_dialog();
		gtk_window_set_transient_for(GTK_WINDOW(app->prefs_dialog), GTK_WINDOW(app->window));

		// init the default file encoding combo box
		combo = lookup_widget(app->prefs_dialog, "combo_encoding");
		gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(combo), 3);
		for (i = 0; i < GEANY_ENCODINGS_MAX; i++)
		{
			encoding_string = encodings_to_string(&encodings[i]);
			gtk_combo_box_append_text(GTK_COMBO_BOX(combo), encoding_string);
			g_free(encoding_string);
		}

#ifdef HAVE_VTE
		if (app->have_vte)
		{
			tooltips = GTK_TOOLTIPS(lookup_widget(app->prefs_dialog, "tooltips"));
			notebook = lookup_widget(app->prefs_dialog, "notebook2");
			vbox = gtk_vbox_new(FALSE, 0);
			gtk_container_add(GTK_CONTAINER(notebook), vbox);

			label = gtk_label_new(_("These are settings for the virtual terminal emulator widget (VTE). They only apply, if the VTE library could be loaded."));
			gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
			gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_FILL);
			gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
			gtk_misc_set_alignment(GTK_MISC(label), 0.14, 0.19);
			gtk_misc_set_padding(GTK_MISC(label), 0, 8);

			alignment = gtk_alignment_new(0.5, 0.5, 1, 1);
			gtk_box_pack_start(GTK_BOX(vbox), alignment, FALSE, FALSE, 0);
			gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), 0, 0, 12, 6);

			table = gtk_table_new(8, 2, FALSE);
			gtk_container_add(GTK_CONTAINER(alignment), table);
			gtk_table_set_row_spacings(GTK_TABLE(table), 3);
			gtk_table_set_col_spacings(GTK_TABLE(table), 25);

			label = gtk_label_new(_("Terminal font"));
			gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1,
						(GtkAttachOptions) (GTK_FILL),
						(GtkAttachOptions) (0), 0, 0);
			gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);

			font_term = gtk_font_button_new();
			gtk_table_attach(GTK_TABLE(table), font_term, 1, 2, 0, 1,
						(GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
						(GtkAttachOptions) (0), 0, 0);
			gtk_tooltips_set_tip(tooltips, font_term, _("Sets the font for the terminal widget."), NULL);

			label = gtk_label_new(_("Foreground color"));
			gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
						(GtkAttachOptions) (GTK_FILL),
						(GtkAttachOptions) (0), 0, 0);
			gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);

			label = gtk_label_new(_("Background color"));
			gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3,
						(GtkAttachOptions) (GTK_FILL),
						(GtkAttachOptions) (0), 0, 0);
			gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);

			color_fore = gtk_color_button_new();
			gtk_table_attach(GTK_TABLE(table), color_fore, 1, 2, 1, 2,
						(GtkAttachOptions) (GTK_FILL),
						(GtkAttachOptions) (0), 0, 0);
			gtk_tooltips_set_tip(tooltips, color_fore, _("Sets the foreground color of the text in the terminal widget."), NULL);
			gtk_color_button_set_title(GTK_COLOR_BUTTON(color_fore), _("Color Chooser"));

			color_back = gtk_color_button_new();
			gtk_table_attach(GTK_TABLE(table), color_back, 1, 2, 2, 3,
						(GtkAttachOptions) (GTK_FILL),
						(GtkAttachOptions) (0), 0, 0);
			gtk_tooltips_set_tip(tooltips, color_back, _("Sets the background color of the text in the terminal widget."), NULL);
			gtk_color_button_set_title(GTK_COLOR_BUTTON(color_back), _("Color Chooser"));

			label = gtk_label_new(_("Scrollback lines"));
			gtk_table_attach(GTK_TABLE(table), label, 0, 1, 3, 4,
						(GtkAttachOptions) (GTK_FILL),
						(GtkAttachOptions) (0), 0, 0);
			gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);

			spin_scrollback_adj = gtk_adjustment_new(500, 0, 5000, 1, 10, 10);
			spin_scrollback = gtk_spin_button_new(GTK_ADJUSTMENT(spin_scrollback_adj), 1, 0);
			gtk_table_attach(GTK_TABLE(table), spin_scrollback, 1, 2, 3, 4,
						(GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
						(GtkAttachOptions) (0), 0, 0);
			gtk_tooltips_set_tip(tooltips, spin_scrollback, _("Specifies the history in lines, which you can scroll back in the terminal widget."), NULL);
			gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(spin_scrollback), TRUE);
			gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(spin_scrollback), TRUE);

			label = gtk_label_new(_("Terminal emulation"));
			gtk_table_attach(GTK_TABLE(table), label, 0, 1, 4, 5,
						(GtkAttachOptions) (GTK_FILL),
						(GtkAttachOptions) (0), 0, 0);
			gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);

			entry_emulation = gtk_entry_new();
			gtk_table_attach(GTK_TABLE(table), entry_emulation, 1, 2, 4, 5,
						(GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
						(GtkAttachOptions) (0), 0, 0);
			gtk_tooltips_set_tip(tooltips, entry_emulation, _("Controls how the terminal emulator should behave. xterm is a good start."), NULL);

			check_scroll_key = gtk_check_button_new_with_mnemonic(_("Scroll on keystroke"));
			gtk_table_attach(GTK_TABLE(table), check_scroll_key, 1, 2, 5, 6,
						(GtkAttachOptions) (GTK_FILL),
						(GtkAttachOptions) (0), 0, 0);
			gtk_tooltips_set_tip(tooltips, check_scroll_key, _("Whether to scroll to the bottom if a key was pressed."), NULL);
			gtk_button_set_focus_on_click(GTK_BUTTON(check_scroll_key), FALSE);

			check_scroll_out = gtk_check_button_new_with_mnemonic(_("Scroll on output"));
			gtk_table_attach(GTK_TABLE(table), check_scroll_out, 1, 2, 6, 7,
						(GtkAttachOptions) (GTK_FILL),
						(GtkAttachOptions) (0), 0, 0);
			gtk_tooltips_set_tip(tooltips, check_scroll_out, _("Whether to scroll to the bottom if an output was generated."), NULL);
			gtk_button_set_focus_on_click(GTK_BUTTON(check_scroll_out), FALSE);

			check_follow_path = gtk_check_button_new_with_mnemonic(_("Follow the path of the current file"));
			gtk_table_attach(GTK_TABLE(table), check_follow_path, 1, 2, 7, 8,
						(GtkAttachOptions) (GTK_FILL),
						(GtkAttachOptions) (0), 0, 0);
			gtk_tooltips_set_tip(tooltips, check_follow_path, _("Whether to execute \"cd $path\" when you switch between opened files."), NULL);
			gtk_button_set_focus_on_click(GTK_BUTTON(check_follow_path), FALSE);

			label = gtk_label_new(_("Terminal"));
			gtk_notebook_set_tab_label(GTK_NOTEBOOK(notebook), gtk_notebook_get_nth_page(
						GTK_NOTEBOOK(notebook), 7), label);

			g_object_set_data_full(G_OBJECT(app->prefs_dialog), "font_term",
					gtk_widget_ref(font_term),	(GDestroyNotify) gtk_widget_unref);
			g_object_set_data_full(G_OBJECT(app->prefs_dialog), "color_fore",
					gtk_widget_ref(color_fore),	(GDestroyNotify) gtk_widget_unref);
			g_object_set_data_full(G_OBJECT(app->prefs_dialog), "color_back",
					gtk_widget_ref(color_back),	(GDestroyNotify) gtk_widget_unref);
			g_object_set_data_full(G_OBJECT(app->prefs_dialog), "spin_scrollback",
					gtk_widget_ref(spin_scrollback),	(GDestroyNotify) gtk_widget_unref);
			g_object_set_data_full(G_OBJECT(app->prefs_dialog), "entry_emulation",
					gtk_widget_ref(entry_emulation),	(GDestroyNotify) gtk_widget_unref);
			g_object_set_data_full(G_OBJECT(app->prefs_dialog), "check_scroll_key",
					gtk_widget_ref(check_scroll_key),	(GDestroyNotify) gtk_widget_unref);
			g_object_set_data_full(G_OBJECT(app->prefs_dialog), "check_scroll_out",
					gtk_widget_ref(check_scroll_out),	(GDestroyNotify) gtk_widget_unref);
			g_object_set_data_full(G_OBJECT(app->prefs_dialog), "check_follow_path",
					gtk_widget_ref(check_follow_path),	(GDestroyNotify) gtk_widget_unref);

			gtk_widget_show_all(vbox);

			g_signal_connect((gpointer) lookup_widget(app->prefs_dialog, "font_term"),
					"font-set", G_CALLBACK(on_prefs_font_choosed), GINT_TO_POINTER(4));
			g_signal_connect((gpointer) lookup_widget(app->prefs_dialog, "color_fore"),
					"color-set", G_CALLBACK(on_prefs_color_choosed), GINT_TO_POINTER(2));
			g_signal_connect((gpointer) lookup_widget(app->prefs_dialog, "color_back"),
					"color-set", G_CALLBACK(on_prefs_color_choosed), GINT_TO_POINTER(3));
		}
#endif
		g_signal_connect((gpointer) app->prefs_dialog, "response", G_CALLBACK(on_prefs_button_clicked), NULL);
		g_signal_connect((gpointer) app->prefs_dialog, "delete_event", G_CALLBACK(on_prefs_delete_event), NULL);
		g_signal_connect((gpointer) lookup_widget(app->prefs_dialog, "tagbar_font"),
				"font-set", G_CALLBACK(on_prefs_font_choosed), GINT_TO_POINTER(1));
		g_signal_connect((gpointer) lookup_widget(app->prefs_dialog, "msgwin_font"),
				"font-set", G_CALLBACK(on_prefs_font_choosed), GINT_TO_POINTER(2));
		g_signal_connect((gpointer) lookup_widget(app->prefs_dialog, "editor_font"),
				"font-set", G_CALLBACK(on_prefs_font_choosed), GINT_TO_POINTER(3));
		g_signal_connect((gpointer) lookup_widget(app->prefs_dialog, "long_line_color"),
				"color-set", G_CALLBACK(on_prefs_color_choosed), GINT_TO_POINTER(1));
		// file chooser buttons in the tools tab
		g_signal_connect((gpointer) lookup_widget(app->prefs_dialog, "button_make"),
				"clicked", G_CALLBACK(on_pref_tools_button_clicked), lookup_widget(app->prefs_dialog, "entry_com_make"));
		g_signal_connect((gpointer) lookup_widget(app->prefs_dialog, "button_term"),
				"clicked", G_CALLBACK(on_pref_tools_button_clicked), lookup_widget(app->prefs_dialog, "entry_com_term"));
		g_signal_connect((gpointer) lookup_widget(app->prefs_dialog, "button_browser"),
				"clicked", G_CALLBACK(on_pref_tools_button_clicked), lookup_widget(app->prefs_dialog, "entry_browser"));
		g_signal_connect((gpointer) lookup_widget(app->prefs_dialog, "button_print"),
				"clicked", G_CALLBACK(on_pref_tools_button_clicked), lookup_widget(app->prefs_dialog, "entry_print"));
1086 1087
		g_signal_connect((gpointer) lookup_widget(app->prefs_dialog, "button_grep"),
				"clicked", G_CALLBACK(on_pref_tools_button_clicked), lookup_widget(app->prefs_dialog, "entry_grep"));
1088 1089 1090 1091 1092 1093 1094 1095 1096

		g_signal_connect((gpointer) lookup_widget(app->prefs_dialog, "check_toolbar_show"),
				"toggled", G_CALLBACK(on_pref_toolbar_show_toggled), NULL);

	}

	prefs_init_dialog();
	gtk_widget_show(app->prefs_dialog);
}