2 * keyfile.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 * geany.conf preferences file loading and saving.
26 * Session file format:
27 * filename_xx=pos;filetype UID;read only;Eencoding;use_tabs;auto_indent;line_wrapping;filename
39 #include "encodings.h"
40 #include "encodingsprivate.h"
41 #include "filetypes.h"
42 #include "geanyobject.h"
44 #include "msgwindow.h"
48 #include "sciwrappers.h"
54 #include "templates.h"
66 #include <sys/types.h>
70 /* define the configuration filenames */
71 #define PREFS_FILE "geany.conf"
72 #define SESSION_FILE "session.conf"
74 /* some default settings which are used at the very first start of Geany to fill
75 * the configuration file */
76 #define GEANY_MAX_SYMBOLLIST_HEIGHT 10
77 #define GEANY_MIN_SYMBOLLIST_CHARS 4
78 #define GEANY_MSGWIN_HEIGHT 208
79 #define GEANY_DISK_CHECK_TIMEOUT 30
80 #define GEANY_DEFAULT_TOOLS_MAKE "make"
82 #define GEANY_DEFAULT_TOOLS_TERMINAL "cmd.exe /Q /C %c"
83 #elif defined(__APPLE__)
84 #define GEANY_DEFAULT_TOOLS_TERMINAL "open -a terminal %c"
86 #define GEANY_DEFAULT_TOOLS_TERMINAL "xterm -e \"/bin/sh %c\""
89 #define GEANY_DEFAULT_TOOLS_BROWSER "open -a safari"
90 #define GEANY_DEFAULT_FONT_SYMBOL_LIST "Helvetica Medium 12"
91 #define GEANY_DEFAULT_FONT_MSG_WINDOW "Menlo Medium 12"
92 #define GEANY_DEFAULT_FONT_EDITOR "Menlo Medium 12"
94 #define GEANY_DEFAULT_TOOLS_BROWSER "firefox"
95 #define GEANY_DEFAULT_FONT_SYMBOL_LIST "Sans 9"
96 #define GEANY_DEFAULT_FONT_MSG_WINDOW "Monospace 9"
97 #define GEANY_DEFAULT_FONT_EDITOR "Monospace 10"
99 #define GEANY_DEFAULT_TOOLS_PRINTCMD "lpr"
100 #define GEANY_DEFAULT_TOOLS_GREP "grep"
101 #define GEANY_DEFAULT_MRU_LENGTH 10
102 #define GEANY_TOGGLE_MARK "~ "
103 #define GEANY_MAX_AUTOCOMPLETE_WORDS 30
104 #define GEANY_MAX_SYMBOLS_UPDATE_FREQ 250
105 #define GEANY_DEFAULT_FILETYPE_REGEX "-\\*-\\s*([^\\s]+)\\s*-\\*-"
108 static gchar
*scribble_text
= NULL
;
109 static gint scribble_pos
= -1;
110 static GPtrArray
*default_session_files
= NULL
;
111 static gint session_notebook_page
;
112 static gint hpan_position
;
113 static gint vpan_position
;
114 static const gchar atomic_file_saving_key
[] = "use_atomic_file_saving";
124 /* Fallback only used when loading config. Saving config should always write the real file. */
125 static gchar
*get_keyfile_for_payload(ConfigPayload payload
)
127 static gboolean logged
;
133 file
= g_build_filename(app
->configdir
, PREFS_FILE
, NULL
);
134 if (! g_file_test(file
, G_FILE_TEST_IS_REGULAR
))
135 { /* config file does not (yet) exist, so try to load a global config
136 * file which may be created by distributors */
137 g_message("No user config file found, trying to use global configuration.");
139 file
= g_build_filename(app
->datadir
, PREFS_FILE
, NULL
);
143 file
= g_build_filename(app
->configdir
, SESSION_FILE
, NULL
);
144 if (! g_file_test(file
, G_FILE_TEST_IS_REGULAR
))
148 g_message("No user session file found, trying to use configuration file.");
152 file
= g_build_filename(app
->configdir
, PREFS_FILE
, NULL
);
156 g_assert_not_reached();
161 static GPtrArray
*keyfile_groups
[MAX_PAYLOAD
];
162 GPtrArray
*pref_groups
;
166 gint number_ft_menu_items
;
167 gint number_non_ft_menu_items
;
168 gint number_exec_menu_items
;
172 /* The group will be free'd on quitting.
173 * @param for_prefs_dialog is whether the group also has Prefs dialog items. */
174 void configuration_add_pref_group(struct StashGroup
*group
, gboolean for_prefs_dialog
)
176 g_ptr_array_add(keyfile_groups
[PREFS
], group
);
178 if (for_prefs_dialog
)
179 g_ptr_array_add(pref_groups
, group
);
183 /* The group will be free'd on quitting.
184 * prefix can be NULL to use group name */
185 void configuration_add_various_pref_group(struct StashGroup
*group
,
188 configuration_add_pref_group(group
, TRUE
);
189 stash_group_set_various(group
, TRUE
, prefix
);
193 /* The group will be free'd on quitting.
195 * @a for_prefs_dialog is typically @c FALSE as session configuration is not
196 * well suited for the Preferences dialog. Probably only existing prefs that
197 * migrated to session data should set this to @c TRUE.
199 * @param for_prefs_dialog is whether the group also has Prefs dialog items.
201 void configuration_add_session_group(struct StashGroup
*group
, gboolean for_prefs_dialog
)
203 g_ptr_array_add(keyfile_groups
[SESSION
], group
);
205 if (for_prefs_dialog
)
206 g_ptr_array_add(pref_groups
, group
);
210 static void init_pref_groups(void)
214 group
= stash_group_new(PACKAGE
);
215 configuration_add_pref_group(group
, TRUE
);
216 stash_group_add_entry(group
, &prefs
.default_open_path
,
217 "default_open_path", "", "startup_path_entry");
219 stash_group_add_toggle_button(group
, &file_prefs
.cmdline_new_files
,
220 "cmdline_new_files", TRUE
, "check_cmdline_new_files");
222 stash_group_add_toggle_button(group
, &interface_prefs
.notebook_double_click_hides_widgets
,
223 "notebook_double_click_hides_widgets", FALSE
, "check_double_click_hides_widgets");
224 stash_group_add_toggle_button(group
, &file_prefs
.tab_close_switch_to_mru
,
225 "tab_close_switch_to_mru", FALSE
, "check_tab_close_switch_to_mru");
226 stash_group_add_integer(group
, &interface_prefs
.tab_pos_sidebar
, "tab_pos_sidebar", GTK_POS_TOP
);
227 stash_group_add_integer(group
, &interface_prefs
.openfiles_path_mode
, "openfiles_path_mode", -1);
228 stash_group_add_radio_buttons(group
, &interface_prefs
.sidebar_pos
,
229 "sidebar_pos", GTK_POS_LEFT
,
230 "radio_sidebar_left", GTK_POS_LEFT
,
231 "radio_sidebar_right", GTK_POS_RIGHT
,
233 stash_group_add_radio_buttons(group
, &interface_prefs
.symbols_sort_mode
,
234 "symbols_sort_mode", SYMBOLS_SORT_BY_NAME
,
235 "radio_symbols_sort_by_name", SYMBOLS_SORT_BY_NAME
,
236 "radio_symbols_sort_by_appearance", SYMBOLS_SORT_BY_APPEARANCE
,
238 stash_group_add_radio_buttons(group
, &interface_prefs
.msgwin_orientation
,
239 "msgwin_orientation", GTK_ORIENTATION_VERTICAL
,
240 "radio_msgwin_vertical", GTK_ORIENTATION_VERTICAL
,
241 "radio_msgwin_horizontal", GTK_ORIENTATION_HORIZONTAL
,
245 stash_group_add_toggle_button(group
, &interface_prefs
.highlighting_invert_all
,
246 "highlighting_invert_all", FALSE
, "check_highlighting_invert");
248 stash_group_add_toggle_button(group
, &search_prefs
.use_current_word
,
249 "pref_main_search_use_current_word", TRUE
, "check_search_use_current_word");
252 stash_group_add_toggle_button(group
, &editor_prefs
.indentation
->detect_type
,
253 "check_detect_indent", FALSE
, "check_detect_indent_type");
254 stash_group_add_toggle_button(group
, &editor_prefs
.indentation
->detect_width
,
255 "detect_indent_width", FALSE
, "check_detect_indent_width");
256 stash_group_add_toggle_button(group
, &editor_prefs
.use_tab_to_indent
,
257 "use_tab_to_indent", TRUE
, "check_tab_key_indents");
258 stash_group_add_toggle_button(group
, &editor_prefs
.backspace_unindent
,
259 "backspace_unindent", TRUE
, "check_backspace_unindent");
260 stash_group_add_spin_button_integer(group
, &editor_prefs
.indentation
->width
,
261 "pref_editor_tab_width", 4, "spin_indent_width");
262 stash_group_add_combo_box(group
, (gint
*)(void*)&editor_prefs
.indentation
->auto_indent_mode
,
263 "indent_mode", GEANY_AUTOINDENT_CURRENTCHARS
, "combo_auto_indent_mode");
264 stash_group_add_radio_buttons(group
, (gint
*)(void*)&editor_prefs
.indentation
->type
,
265 "indent_type", GEANY_INDENT_TYPE_TABS
,
266 "radio_indent_spaces", GEANY_INDENT_TYPE_SPACES
,
267 "radio_indent_tabs", GEANY_INDENT_TYPE_TABS
,
268 "radio_indent_both", GEANY_INDENT_TYPE_BOTH
,
270 stash_group_add_radio_buttons(group
, (gint
*)(void*)&editor_prefs
.show_virtual_space
,
271 "virtualspace", GEANY_VIRTUAL_SPACE_SELECTION
,
272 "radio_virtualspace_disabled", GEANY_VIRTUAL_SPACE_DISABLED
,
273 "radio_virtualspace_selection", GEANY_VIRTUAL_SPACE_SELECTION
,
274 "radio_virtualspace_always", GEANY_VIRTUAL_SPACE_ALWAYS
,
276 stash_group_add_toggle_button(group
, &editor_prefs
.autocomplete_doc_words
,
277 "autocomplete_doc_words", FALSE
, "check_autocomplete_doc_words");
278 stash_group_add_toggle_button(group
, &editor_prefs
.completion_drops_rest_of_word
,
279 "completion_drops_rest_of_word", FALSE
, "check_completion_drops_rest_of_word");
280 stash_group_add_spin_button_integer(group
, (gint
*)&editor_prefs
.autocompletion_max_entries
,
281 "autocompletion_max_entries", GEANY_MAX_AUTOCOMPLETE_WORDS
,
282 "spin_autocompletion_max_entries");
283 stash_group_add_spin_button_integer(group
, (gint
*)&editor_prefs
.autocompletion_update_freq
,
284 "autocompletion_update_freq", GEANY_MAX_SYMBOLS_UPDATE_FREQ
, "spin_symbol_update_freq");
285 stash_group_add_string(group
, &editor_prefs
.color_scheme
,
286 "color_scheme", NULL
);
287 stash_group_add_spin_button_integer(group
, &editor_prefs
.scroll_lines_around_cursor
,
288 "scroll_lines_around_cursor", 0, "spin_scroll_lines_around_cursor");
291 stash_group_add_spin_button_integer(group
, (gint
*)&file_prefs
.mru_length
,
292 "mru_length", GEANY_DEFAULT_MRU_LENGTH
, "spin_mru");
293 stash_group_add_spin_button_integer(group
, &file_prefs
.disk_check_timeout
,
294 "disk_check_timeout", GEANY_DISK_CHECK_TIMEOUT
, "spin_disk_check");
296 /* various geany prefs */
297 group
= stash_group_new(PACKAGE
);
298 configuration_add_various_pref_group(group
, "editor");
300 stash_group_add_boolean(group
, &editor_prefs
.show_scrollbars
,
301 "show_editor_scrollbars", TRUE
);
302 stash_group_add_boolean(group
, &editor_prefs
.brace_match_ltgt
,
303 "brace_match_ltgt", FALSE
);
304 stash_group_add_boolean(group
, &editor_prefs
.use_gtk_word_boundaries
,
305 "use_gtk_word_boundaries", TRUE
);
306 stash_group_add_boolean(group
, &editor_prefs
.complete_snippets_whilst_editing
,
307 "complete_snippets_whilst_editing", FALSE
);
308 /* for backwards-compatibility */
309 stash_group_add_integer(group
, &editor_prefs
.indentation
->hard_tab_width
,
310 "indent_hard_tab_width", 8);
311 stash_group_add_integer(group
, &editor_prefs
.ime_interaction
,
312 "editor_ime_interaction", SC_IME_WINDOWED
);
314 group
= stash_group_new(PACKAGE
);
315 configuration_add_various_pref_group(group
, "files");
317 stash_group_add_boolean(group
, &file_prefs
.use_safe_file_saving
,
318 atomic_file_saving_key
, FALSE
);
319 stash_group_add_boolean(group
, &file_prefs
.gio_unsafe_save_backup
,
320 "gio_unsafe_save_backup", FALSE
);
321 stash_group_add_boolean(group
, &file_prefs
.use_gio_unsafe_file_saving
,
322 "use_gio_unsafe_file_saving", TRUE
);
323 stash_group_add_boolean(group
, &file_prefs
.keep_edit_history_on_reload
,
324 "keep_edit_history_on_reload", TRUE
);
325 stash_group_add_boolean(group
, &file_prefs
.show_keep_edit_history_on_reload_msg
,
326 "show_keep_edit_history_on_reload_msg", TRUE
);
327 stash_group_add_boolean(group
, &file_prefs
.reload_clean_doc_on_file_change
,
328 "reload_clean_doc_on_file_change", FALSE
);
329 stash_group_add_boolean(group
, &file_prefs
.save_config_on_file_change
,
330 "save_config_on_file_change", TRUE
);
331 stash_group_add_string(group
, &file_prefs
.extract_filetype_regex
,
332 "extract_filetype_regex", GEANY_DEFAULT_FILETYPE_REGEX
);
333 stash_group_add_boolean(group
, &ui_prefs
.allow_always_save
,
334 "allow_always_save", FALSE
);
336 group
= stash_group_new(PACKAGE
);
337 configuration_add_various_pref_group(group
, "search");
339 stash_group_add_integer(group
, (gint
*)&search_prefs
.find_selection_type
,
340 "find_selection_type", GEANY_FIND_SEL_CURRENT_WORD
);
341 stash_group_add_boolean(group
, &search_prefs
.replace_and_find_by_default
,
342 "replace_and_find_by_default", TRUE
);
344 group
= stash_group_new(PACKAGE
);
345 configuration_add_various_pref_group(group
, "socket");
348 stash_group_add_integer(group
, (gint
*)&prefs
.socket_remote_cmd_port
,
349 "socket_remote_cmd_port", SOCKET_WINDOWS_REMOTE_CMD_PORT
);
353 /* various VTE prefs. */
354 group
= stash_group_new("VTE");
355 configuration_add_various_pref_group(group
, "terminal");
357 stash_group_add_string(group
, &vte_config
.send_cmd_prefix
,
358 "send_cmd_prefix", "");
359 stash_group_add_boolean(group
, &vte_config
.send_selection_unsafe
,
360 "send_selection_unsafe", FALSE
);
363 /* Note: Interface-related various prefs are in ui_init_prefs() */
365 /* various build-menu prefs */
366 // Warning: don't move PACKAGE group name items here
367 group
= stash_group_new("build-menu");
368 configuration_add_various_pref_group(group
, "build");
370 stash_group_add_integer(group
, &build_menu_prefs
.number_ft_menu_items
,
371 "number_ft_menu_items", 0);
372 stash_group_add_integer(group
, &build_menu_prefs
.number_non_ft_menu_items
,
373 "number_non_ft_menu_items", 0);
374 stash_group_add_integer(group
, &build_menu_prefs
.number_exec_menu_items
,
375 "number_exec_menu_items", 0);
379 typedef enum SettingAction
386 static void settings_action(GKeyFile
*config
, SettingAction action
, ConfigPayload payload
)
391 foreach_ptr_array(group
, i
, keyfile_groups
[payload
])
396 stash_group_load_from_key_file(group
, config
); break;
398 stash_group_save_to_key_file(group
, config
); break;
404 static void save_recent_files(GKeyFile
*config
, GQueue
*queue
, gchar
const *key
)
406 gchar
**recent_files
= g_new0(gchar
*, file_prefs
.mru_length
+ 1);
409 for (i
= 0; i
< file_prefs
.mru_length
; i
++)
411 if (! g_queue_is_empty(queue
))
413 /* copy the values, this is necessary when this function is called from the
414 * preferences dialog or when quitting is canceled to keep the queue intact */
415 recent_files
[i
] = g_strdup(g_queue_peek_nth(queue
, i
));
419 recent_files
[i
] = NULL
;
423 /* There is a bug in GTK 2.6 g_key_file_set_string_list, we must NULL terminate. */
424 recent_files
[file_prefs
.mru_length
] = NULL
;
425 g_key_file_set_string_list(config
, "files", key
,
426 (const gchar
**)recent_files
, file_prefs
.mru_length
);
427 g_strfreev(recent_files
);
431 static gchar
*get_session_file_string(GeanyDocument
*doc
)
434 gchar
*locale_filename
;
435 gchar
*escaped_filename
;
436 GeanyFiletype
*ft
= doc
->file_type
;
438 if (ft
== NULL
) /* can happen when saving a new file when quitting */
439 ft
= filetypes
[GEANY_FILETYPES_NONE
];
441 locale_filename
= utils_get_locale_from_utf8(doc
->file_name
);
442 escaped_filename
= g_uri_escape_string(locale_filename
, NULL
, TRUE
);
444 fname
= g_strdup_printf("%d;%s;%d;E%s;%d;%d;%d;%s;%d;%d",
445 sci_get_current_position(doc
->editor
->sci
),
449 doc
->editor
->indent_type
,
450 doc
->editor
->auto_indent
,
451 doc
->editor
->line_wrapping
,
453 doc
->editor
->line_breaking
,
454 doc
->editor
->indent_width
);
455 g_free(escaped_filename
);
456 g_free(locale_filename
);
461 static void remove_session_files(GKeyFile
*config
)
464 gchar
**keys
= g_key_file_get_keys(config
, "files", NULL
, NULL
);
466 foreach_strv(ptr
, keys
)
468 if (g_str_has_prefix(*ptr
, "FILE_NAME_"))
469 g_key_file_remove_key(config
, "files", *ptr
, NULL
);
475 void configuration_save_session_files(GKeyFile
*config
)
479 guint i
= 0, j
= 0, max
;
481 npage
= gtk_notebook_get_current_page(GTK_NOTEBOOK(main_widgets
.notebook
));
482 g_key_file_set_integer(config
, "files", "current_page", npage
);
484 // clear existing entries first as they might not all be overwritten
485 remove_session_files(config
);
487 /* store the filenames in the notebook tab order to reopen them the next time */
488 max
= gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets
.notebook
));
489 for (i
= 0; i
< max
; i
++)
491 GeanyDocument
*doc
= document_get_from_page(i
);
493 if (doc
!= NULL
&& doc
->real_path
!= NULL
)
497 g_snprintf(entry
, sizeof(entry
), "FILE_NAME_%d", j
);
498 fname
= get_session_file_string(doc
);
499 g_key_file_set_string(config
, "files", entry
, fname
);
506 if (vte_info
.have_vte
)
508 vte_get_working_directory(); /* refresh vte_info.dir */
509 g_key_file_set_string(config
, "VTE", "last_dir", vte_info
.dir
);
515 static void save_dialog_prefs(GKeyFile
*config
)
517 /* Some of the key names are not consistent, but this is for backwards compatibility */
520 g_key_file_set_boolean(config
, PACKAGE
, "pref_main_load_session", prefs
.load_session
);
521 g_key_file_set_boolean(config
, PACKAGE
, "pref_main_project_file_in_basedir", project_prefs
.project_file_in_basedir
);
522 g_key_file_set_boolean(config
, PACKAGE
, "pref_main_save_winpos", prefs
.save_winpos
);
523 g_key_file_set_boolean(config
, PACKAGE
, "pref_main_save_wingeom", prefs
.save_wingeom
);
524 g_key_file_set_boolean(config
, PACKAGE
, "pref_main_confirm_exit", prefs
.confirm_exit
);
525 g_key_file_set_boolean(config
, PACKAGE
, "pref_main_suppress_status_messages", prefs
.suppress_status_messages
);
526 g_key_file_set_boolean(config
, PACKAGE
, "switch_msgwin_pages", prefs
.switch_to_status
);
527 g_key_file_set_boolean(config
, PACKAGE
, "beep_on_errors", prefs
.beep_on_errors
);
528 g_key_file_set_boolean(config
, PACKAGE
, "auto_focus", prefs
.auto_focus
);
531 g_key_file_set_boolean(config
, PACKAGE
, "sidebar_symbol_visible", interface_prefs
.sidebar_symbol_visible
);
532 g_key_file_set_boolean(config
, PACKAGE
, "sidebar_openfiles_visible", interface_prefs
.sidebar_openfiles_visible
);
533 g_key_file_set_string(config
, PACKAGE
, "editor_font", interface_prefs
.editor_font
);
534 g_key_file_set_string(config
, PACKAGE
, "tagbar_font", interface_prefs
.tagbar_font
);
535 g_key_file_set_string(config
, PACKAGE
, "msgwin_font", interface_prefs
.msgwin_font
);
536 g_key_file_set_boolean(config
, PACKAGE
, "show_notebook_tabs", interface_prefs
.show_notebook_tabs
);
537 g_key_file_set_boolean(config
, PACKAGE
, "show_tab_cross", file_prefs
.show_tab_cross
);
538 g_key_file_set_boolean(config
, PACKAGE
, "tab_order_ltr", file_prefs
.tab_order_ltr
);
539 g_key_file_set_boolean(config
, PACKAGE
, "tab_order_beside", file_prefs
.tab_order_beside
);
540 g_key_file_set_integer(config
, PACKAGE
, "tab_pos_editor", interface_prefs
.tab_pos_editor
);
541 g_key_file_set_integer(config
, PACKAGE
, "tab_pos_msgwin", interface_prefs
.tab_pos_msgwin
);
542 g_key_file_set_integer(config
, PACKAGE
, "tab_label_length", interface_prefs
.tab_label_len
);
545 g_key_file_set_boolean(config
, PACKAGE
, "show_indent_guide", editor_prefs
.show_indent_guide
);
546 g_key_file_set_boolean(config
, PACKAGE
, "show_white_space", editor_prefs
.show_white_space
);
547 g_key_file_set_boolean(config
, PACKAGE
, "show_line_endings", editor_prefs
.show_line_endings
);
548 g_key_file_set_boolean(config
, PACKAGE
, "show_line_endings_only_when_differ", editor_prefs
.show_line_endings_only_when_differ
);
549 g_key_file_set_boolean(config
, PACKAGE
, "show_markers_margin", editor_prefs
.show_markers_margin
);
550 g_key_file_set_boolean(config
, PACKAGE
, "show_linenumber_margin", editor_prefs
.show_linenumber_margin
);
551 g_key_file_set_boolean(config
, PACKAGE
, "long_line_enabled", editor_prefs
.long_line_enabled
);
552 g_key_file_set_integer(config
, PACKAGE
, "long_line_type", editor_prefs
.long_line_type
);
553 g_key_file_set_integer(config
, PACKAGE
, "long_line_column", editor_prefs
.long_line_column
);
554 g_key_file_set_string(config
, PACKAGE
, "long_line_color", editor_prefs
.long_line_color
);
557 g_key_file_set_integer(config
, PACKAGE
, "symbolcompletion_max_height", editor_prefs
.symbolcompletion_max_height
);
558 g_key_file_set_integer(config
, PACKAGE
, "symbolcompletion_min_chars", editor_prefs
.symbolcompletion_min_chars
);
559 g_key_file_set_boolean(config
, PACKAGE
, "use_folding", editor_prefs
.folding
);
560 g_key_file_set_boolean(config
, PACKAGE
, "unfold_all_children", editor_prefs
.unfold_all_children
);
561 g_key_file_set_boolean(config
, PACKAGE
, "use_indicators", editor_prefs
.use_indicators
);
562 g_key_file_set_boolean(config
, PACKAGE
, "line_wrapping", editor_prefs
.line_wrapping
);
563 g_key_file_set_boolean(config
, PACKAGE
, "auto_close_xml_tags", editor_prefs
.auto_close_xml_tags
);
564 g_key_file_set_boolean(config
, PACKAGE
, "complete_snippets", editor_prefs
.complete_snippets
);
565 g_key_file_set_boolean(config
, PACKAGE
, "auto_complete_symbols", editor_prefs
.auto_complete_symbols
);
566 g_key_file_set_boolean(config
, PACKAGE
, "pref_editor_disable_dnd", editor_prefs
.disable_dnd
);
567 g_key_file_set_boolean(config
, PACKAGE
, "pref_editor_smart_home_key", editor_prefs
.smart_home_key
);
568 g_key_file_set_boolean(config
, PACKAGE
, "pref_editor_newline_strip", editor_prefs
.newline_strip
);
569 g_key_file_set_integer(config
, PACKAGE
, "line_break_column", editor_prefs
.line_break_column
);
570 g_key_file_set_boolean(config
, PACKAGE
, "auto_continue_multiline", editor_prefs
.auto_continue_multiline
);
571 g_key_file_set_string(config
, PACKAGE
, "comment_toggle_mark", editor_prefs
.comment_toggle_mark
);
572 g_key_file_set_boolean(config
, PACKAGE
, "scroll_stop_at_last_line", editor_prefs
.scroll_stop_at_last_line
);
573 g_key_file_set_integer(config
, PACKAGE
, "autoclose_chars", editor_prefs
.autoclose_chars
);
576 g_key_file_set_string(config
, PACKAGE
, "pref_editor_default_new_encoding", encodings
[file_prefs
.default_new_encoding
].charset
);
577 if (file_prefs
.default_open_encoding
== -1)
578 g_key_file_set_string(config
, PACKAGE
, "pref_editor_default_open_encoding", "none");
580 g_key_file_set_string(config
, PACKAGE
, "pref_editor_default_open_encoding", encodings
[file_prefs
.default_open_encoding
].charset
);
581 g_key_file_set_integer(config
, PACKAGE
, "default_eol_character", file_prefs
.default_eol_character
);
582 g_key_file_set_boolean(config
, PACKAGE
, "pref_editor_new_line", file_prefs
.final_new_line
);
583 g_key_file_set_boolean(config
, PACKAGE
, "pref_editor_ensure_convert_line_endings", file_prefs
.ensure_convert_new_lines
);
584 g_key_file_set_boolean(config
, PACKAGE
, "pref_editor_replace_tabs", file_prefs
.replace_tabs
);
585 g_key_file_set_boolean(config
, PACKAGE
, "pref_editor_trail_space", file_prefs
.strip_trailing_spaces
);
588 g_key_file_set_boolean(config
, PACKAGE
, "pref_toolbar_show", toolbar_prefs
.visible
);
589 g_key_file_set_boolean(config
, PACKAGE
, "pref_toolbar_append_to_menu", toolbar_prefs
.append_to_menu
);
590 g_key_file_set_boolean(config
, PACKAGE
, "pref_toolbar_use_gtk_default_style", toolbar_prefs
.use_gtk_default_style
);
591 g_key_file_set_boolean(config
, PACKAGE
, "pref_toolbar_use_gtk_default_icon", toolbar_prefs
.use_gtk_default_icon
);
592 g_key_file_set_integer(config
, PACKAGE
, "pref_toolbar_icon_style", toolbar_prefs
.icon_style
);
593 g_key_file_set_integer(config
, PACKAGE
, "pref_toolbar_icon_size", toolbar_prefs
.icon_size
);
596 g_key_file_set_string(config
, PACKAGE
, "pref_template_developer", template_prefs
.developer
);
597 g_key_file_set_string(config
, PACKAGE
, "pref_template_company", template_prefs
.company
);
598 g_key_file_set_string(config
, PACKAGE
, "pref_template_mail", template_prefs
.mail
);
599 g_key_file_set_string(config
, PACKAGE
, "pref_template_initial", template_prefs
.initials
);
600 g_key_file_set_string(config
, PACKAGE
, "pref_template_version", template_prefs
.version
);
601 g_key_file_set_string(config
, PACKAGE
, "pref_template_year", template_prefs
.year_format
);
602 g_key_file_set_string(config
, PACKAGE
, "pref_template_date", template_prefs
.date_format
);
603 g_key_file_set_string(config
, PACKAGE
, "pref_template_datetime", template_prefs
.datetime_format
);
606 g_key_file_set_string(config
, "tools", "terminal_cmd", tool_prefs
.term_cmd
? tool_prefs
.term_cmd
: "");
607 g_key_file_set_string(config
, "tools", "browser_cmd", tool_prefs
.browser_cmd
? tool_prefs
.browser_cmd
: "");
608 g_key_file_set_string(config
, "tools", "grep_cmd", tool_prefs
.grep_cmd
? tool_prefs
.grep_cmd
: "");
609 g_key_file_set_string(config
, PACKAGE
, "context_action_cmd", tool_prefs
.context_action_cmd
);
612 build_save_menu(config
, NULL
, GEANY_BCS_PREF
);
615 g_key_file_set_string(config
, "printing", "print_cmd", printing_prefs
.external_print_cmd
? printing_prefs
.external_print_cmd
: "");
616 g_key_file_set_boolean(config
, "printing", "use_gtk_printing", printing_prefs
.use_gtk_printing
);
617 g_key_file_set_boolean(config
, "printing", "print_line_numbers", printing_prefs
.print_line_numbers
);
618 g_key_file_set_boolean(config
, "printing", "print_page_numbers", printing_prefs
.print_page_numbers
);
619 g_key_file_set_boolean(config
, "printing", "print_page_header", printing_prefs
.print_page_header
);
620 g_key_file_set_boolean(config
, "printing", "page_header_basename", printing_prefs
.page_header_basename
);
621 g_key_file_set_string(config
, "printing", "page_header_datefmt", printing_prefs
.page_header_datefmt
);
625 g_key_file_set_boolean(config
, "VTE", "load_vte", vte_info
.load_vte
);
626 if (vte_info
.have_vte
)
628 VteConfig
*vc
= &vte_config
;
631 g_key_file_set_string(config
, "VTE", "font", vc
->font
);
632 g_key_file_set_boolean(config
, "VTE", "scroll_on_key", vc
->scroll_on_key
);
633 g_key_file_set_boolean(config
, "VTE", "scroll_on_out", vc
->scroll_on_out
);
634 g_key_file_set_boolean(config
, "VTE", "enable_bash_keys", vc
->enable_bash_keys
);
635 g_key_file_set_boolean(config
, "VTE", "ignore_menu_bar_accel", vc
->ignore_menu_bar_accel
);
636 g_key_file_set_boolean(config
, "VTE", "follow_path", vc
->follow_path
);
637 g_key_file_set_boolean(config
, "VTE", "run_in_vte", vc
->run_in_vte
);
638 g_key_file_set_boolean(config
, "VTE", "skip_run_script", vc
->skip_run_script
);
639 g_key_file_set_boolean(config
, "VTE", "cursor_blinks", vc
->cursor_blinks
);
640 g_key_file_set_integer(config
, "VTE", "scrollback_lines", vc
->scrollback_lines
);
641 g_key_file_set_string(config
, "VTE", "font", vc
->font
);
642 g_key_file_set_string(config
, "VTE", "shell", vc
->shell
);
643 tmp_string
= utils_get_hex_from_color(&vc
->colour_fore
);
644 g_key_file_set_string(config
, "VTE", "colour_fore", tmp_string
);
646 tmp_string
= utils_get_hex_from_color(&vc
->colour_back
);
647 g_key_file_set_string(config
, "VTE", "colour_back", tmp_string
);
654 static void save_ui_prefs(GKeyFile
*config
)
656 g_key_file_set_boolean(config
, PACKAGE
, "sidebar_visible", ui_prefs
.sidebar_visible
);
657 g_key_file_set_boolean(config
, PACKAGE
, "statusbar_visible", interface_prefs
.statusbar_visible
);
658 g_key_file_set_boolean(config
, PACKAGE
, "msgwindow_visible", ui_prefs
.msgwindow_visible
);
659 g_key_file_set_boolean(config
, PACKAGE
, "fullscreen", ui_prefs
.fullscreen
);
660 g_key_file_set_boolean(config
, PACKAGE
, "symbols_group_by_type", ui_prefs
.symbols_group_by_type
);
661 g_key_file_set_string(config
, PACKAGE
, "color_picker_palette", ui_prefs
.color_picker_palette
);
663 /* get the text from the scribble textview */
665 GtkTextBuffer
*buffer
;
666 GtkTextIter start
, end
, iter
;
669 buffer
= gtk_text_view_get_buffer(GTK_TEXT_VIEW(msgwindow
.scribble
));
670 gtk_text_buffer_get_bounds(buffer
, &start
, &end
);
671 scribble_text
= gtk_text_buffer_get_text(buffer
, &start
, &end
, FALSE
);
672 g_key_file_set_string(config
, PACKAGE
, "scribble_text", scribble_text
);
673 g_free(scribble_text
);
675 mark
= gtk_text_buffer_get_insert(buffer
);
676 gtk_text_buffer_get_iter_at_mark(buffer
, &iter
, mark
);
677 scribble_pos
= gtk_text_iter_get_offset(&iter
);
678 g_key_file_set_integer(config
, PACKAGE
, "scribble_pos", scribble_pos
);
681 g_key_file_set_string(config
, PACKAGE
, "custom_date_format", ui_prefs
.custom_date_format
);
682 if (ui_prefs
.custom_commands
!= NULL
)
684 g_key_file_set_string_list(config
, PACKAGE
, "custom_commands",
685 (const gchar
**) ui_prefs
.custom_commands
, g_strv_length(ui_prefs
.custom_commands
));
686 g_key_file_set_string_list(config
, PACKAGE
, "custom_commands_labels",
687 (const gchar
**) ui_prefs
.custom_commands_labels
, g_strv_length(ui_prefs
.custom_commands_labels
));
691 static void save_ui_session(GKeyFile
*config
)
693 if (prefs
.save_winpos
|| prefs
.save_wingeom
)
695 GdkWindowState wstate
;
697 g_key_file_set_integer(config
, PACKAGE
, "treeview_position",
698 gtk_paned_get_position(GTK_PANED(ui_lookup_widget(main_widgets
.window
, "hpaned1"))));
699 g_key_file_set_integer(config
, PACKAGE
, "msgwindow_position",
700 gtk_paned_get_position(GTK_PANED(ui_lookup_widget(main_widgets
.window
, "vpaned1"))));
702 gtk_window_get_position(GTK_WINDOW(main_widgets
.window
), &ui_prefs
.geometry
[0], &ui_prefs
.geometry
[1]);
703 gtk_window_get_size(GTK_WINDOW(main_widgets
.window
), &ui_prefs
.geometry
[2], &ui_prefs
.geometry
[3]);
704 wstate
= gdk_window_get_state(gtk_widget_get_window(main_widgets
.window
));
705 ui_prefs
.geometry
[4] = (wstate
& GDK_WINDOW_STATE_MAXIMIZED
) ? 1 : 0;
706 g_key_file_set_integer_list(config
, PACKAGE
, "geometry", ui_prefs
.geometry
, 5);
710 static void write_config_file(ConfigPayload payload
)
712 GKeyFile
*config
= g_key_file_new();
713 const gchar
*filename
;
717 filename
= payload
== SESSION
? SESSION_FILE
: PREFS_FILE
;
718 configfile
= g_build_filename(app
->configdir
, filename
, NULL
);
719 g_key_file_load_from_file(config
, configfile
, G_KEY_FILE_NONE
, NULL
);
724 /* this signal can be used e.g. to prepare any settings before Stash code reads them below */
725 g_signal_emit_by_name(geany_object
, "save-settings", config
);
726 save_dialog_prefs(config
);
727 save_ui_prefs(config
);
730 save_recent_files(config
, ui_prefs
.recent_queue
, "recent_files");
731 save_recent_files(config
, ui_prefs
.recent_projects_queue
, "recent_projects");
732 project_save_prefs(config
); /* save project filename, etc. */
733 save_ui_session(config
);
734 if (cl_options
.load_session
&& app
->project
== NULL
)
735 configuration_save_session_files(config
);
737 else if (vte_info
.have_vte
)
739 vte_get_working_directory(); /* refresh vte_info.dir */
740 g_key_file_set_string(config
, "VTE", "last_dir", vte_info
.dir
);
745 g_assert_not_reached();
748 /* new settings should be added in init_pref_groups() */
749 settings_action(config
, SETTING_WRITE
, payload
);
752 data
= g_key_file_to_data(config
, NULL
, NULL
);
753 utils_write_file(configfile
, data
);
756 g_key_file_free(config
);
760 void configuration_save(void)
762 /* save all configuration files
763 * it is probably not very efficient to write both files every time
764 * could be more selective about which file is saved when */
765 write_config_file(PREFS
);
766 write_config_file(SESSION
);
769 static void load_recent_files(GKeyFile
*config
, GQueue
*queue
, const gchar
*key
)
771 gchar
**recent_files
;
774 recent_files
= g_key_file_get_string_list(config
, "files", key
, &len
, NULL
);
775 if (recent_files
!= NULL
)
777 for (i
= 0; (i
< len
) && (i
< file_prefs
.mru_length
); i
++)
779 gchar
*filename
= g_strdup(recent_files
[i
]);
780 g_queue_push_tail(queue
, filename
);
782 g_strfreev(recent_files
);
788 * Load session list from the given keyfile and return an array containg the file names
790 GPtrArray
*configuration_load_session_files(GKeyFile
*config
)
793 gboolean have_session_files
;
796 GError
*error
= NULL
;
799 session_notebook_page
= utils_get_setting_integer(config
, "files", "current_page", -1);
801 files
= g_ptr_array_new();
802 have_session_files
= TRUE
;
804 while (have_session_files
)
806 g_snprintf(entry
, sizeof(entry
), "FILE_NAME_%d", i
);
807 tmp_array
= g_key_file_get_string_list(config
, "files", entry
, NULL
, &error
);
808 if (! tmp_array
|| error
)
812 have_session_files
= FALSE
;
814 g_ptr_array_add(files
, tmp_array
);
819 /* BUG: after loading project at startup, closing project doesn't restore old VTE path */
820 if (vte_info
.have_vte
)
822 gchar
*tmp_string
= utils_get_setting_string(config
, "VTE", "last_dir", NULL
);
823 vte_cwd(tmp_string
,TRUE
);
833 static void get_setting_color(GKeyFile
*config
, const gchar
*section
, const gchar
*key
,
834 GdkColor
*color
, const gchar
*default_color
)
836 gchar
*str
= utils_get_setting_string(config
, section
, key
, NULL
);
837 if (str
== NULL
|| ! utils_parse_color(str
, color
))
838 utils_parse_color(default_color
, color
);
844 /* note: new settings should be added in init_pref_groups() */
845 static void load_dialog_prefs(GKeyFile
*config
)
847 gchar
*tmp_string
, *tmp_string2
;
848 const gchar
*default_charset
= NULL
;
851 /* compatibility with Geany 0.20 */
852 if (!g_key_file_has_key(config
, PACKAGE
, atomic_file_saving_key
, NULL
))
854 g_key_file_set_boolean(config
, PACKAGE
, atomic_file_saving_key
,
855 utils_get_setting_boolean(config
, PACKAGE
, "use_safe_file_saving", FALSE
));
858 /* compatibility with Geany 0.21 */
860 gboolean suppress_search_dialogs
= utils_get_setting_boolean(config
, PACKAGE
, "pref_main_suppress_search_dialogs", FALSE
);
862 if (!g_key_file_has_key(config
, "search", "pref_search_always_wrap", NULL
))
863 g_key_file_set_boolean(config
, "search", "pref_search_always_wrap", suppress_search_dialogs
);
865 if (!g_key_file_has_key(config
, "search", "pref_search_hide_find_dialog", NULL
))
866 g_key_file_set_boolean(config
, "search", "pref_search_hide_find_dialog", suppress_search_dialogs
);
870 prefs
.confirm_exit
= utils_get_setting_boolean(config
, PACKAGE
, "pref_main_confirm_exit", FALSE
);
871 prefs
.suppress_status_messages
= utils_get_setting_boolean(config
, PACKAGE
, "pref_main_suppress_status_messages", FALSE
);
872 prefs
.load_session
= utils_get_setting_boolean(config
, PACKAGE
, "pref_main_load_session", TRUE
);
873 project_prefs
.project_file_in_basedir
= utils_get_setting_boolean(config
, PACKAGE
, "pref_main_project_file_in_basedir", TRUE
);
874 prefs
.save_winpos
= utils_get_setting_boolean(config
, PACKAGE
, "pref_main_save_winpos", TRUE
);
875 prefs
.save_wingeom
= utils_get_setting_boolean(config
, PACKAGE
, "pref_main_save_wingeom", prefs
.save_winpos
);
876 prefs
.beep_on_errors
= utils_get_setting_boolean(config
, PACKAGE
, "beep_on_errors", TRUE
);
877 prefs
.switch_to_status
= utils_get_setting_boolean(config
, PACKAGE
, "switch_msgwin_pages", FALSE
);
878 prefs
.auto_focus
= utils_get_setting_boolean(config
, PACKAGE
, "auto_focus", FALSE
);
881 interface_prefs
.tab_pos_editor
= utils_get_setting_integer(config
, PACKAGE
, "tab_pos_editor", GTK_POS_TOP
);
882 interface_prefs
.tab_pos_msgwin
= utils_get_setting_integer(config
, PACKAGE
, "tab_pos_msgwin",GTK_POS_LEFT
);
883 interface_prefs
.sidebar_symbol_visible
= utils_get_setting_boolean(config
, PACKAGE
, "sidebar_symbol_visible", TRUE
);
884 interface_prefs
.sidebar_openfiles_visible
= utils_get_setting_boolean(config
, PACKAGE
, "sidebar_openfiles_visible", TRUE
);
885 interface_prefs
.statusbar_visible
= utils_get_setting_boolean(config
, PACKAGE
, "statusbar_visible", TRUE
);
886 file_prefs
.tab_order_ltr
= utils_get_setting_boolean(config
, PACKAGE
, "tab_order_ltr", TRUE
);
887 file_prefs
.tab_order_beside
= utils_get_setting_boolean(config
, PACKAGE
, "tab_order_beside", FALSE
);
888 interface_prefs
.show_notebook_tabs
= utils_get_setting_boolean(config
, PACKAGE
, "show_notebook_tabs", TRUE
);
889 file_prefs
.show_tab_cross
= utils_get_setting_boolean(config
, PACKAGE
, "show_tab_cross", TRUE
);
890 interface_prefs
.editor_font
= utils_get_setting_string(config
, PACKAGE
, "editor_font", GEANY_DEFAULT_FONT_EDITOR
);
891 interface_prefs
.tagbar_font
= utils_get_setting_string(config
, PACKAGE
, "tagbar_font", GEANY_DEFAULT_FONT_SYMBOL_LIST
);
892 interface_prefs
.msgwin_font
= utils_get_setting_string(config
, PACKAGE
, "msgwin_font", GEANY_DEFAULT_FONT_MSG_WINDOW
);
894 /* display, editor */
895 editor_prefs
.long_line_enabled
= utils_get_setting_boolean(config
, PACKAGE
, "long_line_enabled", TRUE
);
896 editor_prefs
.long_line_type
= utils_get_setting_integer(config
, PACKAGE
, "long_line_type", 0);
897 if (editor_prefs
.long_line_type
== 2) /* backward compatibility */
899 editor_prefs
.long_line_type
= 0;
900 editor_prefs
.long_line_enabled
= FALSE
;
902 editor_prefs
.long_line_color
= utils_get_setting_string(config
, PACKAGE
, "long_line_color", "#C2EBC2");
903 editor_prefs
.long_line_column
= utils_get_setting_integer(config
, PACKAGE
, "long_line_column", 72);
904 editor_prefs
.symbolcompletion_min_chars
= utils_get_setting_integer(config
, PACKAGE
, "symbolcompletion_min_chars", GEANY_MIN_SYMBOLLIST_CHARS
);
905 editor_prefs
.symbolcompletion_max_height
= utils_get_setting_integer(config
, PACKAGE
, "symbolcompletion_max_height", GEANY_MAX_SYMBOLLIST_HEIGHT
);
906 editor_prefs
.line_wrapping
= utils_get_setting_boolean(config
, PACKAGE
, "line_wrapping", FALSE
); /* default is off for better performance */
907 editor_prefs
.use_indicators
= utils_get_setting_boolean(config
, PACKAGE
, "use_indicators", TRUE
);
908 editor_prefs
.show_indent_guide
= utils_get_setting_boolean(config
, PACKAGE
, "show_indent_guide", FALSE
);
909 editor_prefs
.show_white_space
= utils_get_setting_boolean(config
, PACKAGE
, "show_white_space", FALSE
);
910 editor_prefs
.show_line_endings
= utils_get_setting_boolean(config
, PACKAGE
, "show_line_endings", FALSE
);
911 editor_prefs
.show_line_endings_only_when_differ
= utils_get_setting_boolean(config
, PACKAGE
, "show_line_endings_only_when_differ", FALSE
);
912 editor_prefs
.scroll_stop_at_last_line
= utils_get_setting_boolean(config
, PACKAGE
, "scroll_stop_at_last_line", TRUE
);
913 editor_prefs
.auto_close_xml_tags
= utils_get_setting_boolean(config
, PACKAGE
, "auto_close_xml_tags", TRUE
);
914 editor_prefs
.complete_snippets
= utils_get_setting_boolean(config
, PACKAGE
, "complete_snippets", TRUE
);
915 editor_prefs
.auto_complete_symbols
= utils_get_setting_boolean(config
, PACKAGE
, "auto_complete_symbols", TRUE
);
916 editor_prefs
.folding
= utils_get_setting_boolean(config
, PACKAGE
, "use_folding", TRUE
);
917 editor_prefs
.unfold_all_children
= utils_get_setting_boolean(config
, PACKAGE
, "unfold_all_children", FALSE
);
918 editor_prefs
.show_markers_margin
= utils_get_setting_boolean(config
, PACKAGE
, "show_markers_margin", TRUE
);
919 editor_prefs
.show_linenumber_margin
= utils_get_setting_boolean(config
, PACKAGE
, "show_linenumber_margin", TRUE
);
920 editor_prefs
.disable_dnd
= utils_get_setting_boolean(config
, PACKAGE
, "pref_editor_disable_dnd", FALSE
);
921 editor_prefs
.smart_home_key
= utils_get_setting_boolean(config
, PACKAGE
, "pref_editor_smart_home_key", TRUE
);
922 editor_prefs
.newline_strip
= utils_get_setting_boolean(config
, PACKAGE
, "pref_editor_newline_strip", FALSE
);
923 editor_prefs
.line_break_column
= utils_get_setting_integer(config
, PACKAGE
, "line_break_column", 72);
924 editor_prefs
.auto_continue_multiline
= utils_get_setting_boolean(config
, PACKAGE
, "auto_continue_multiline", TRUE
);
925 editor_prefs
.comment_toggle_mark
= utils_get_setting_string(config
, PACKAGE
, "comment_toggle_mark", GEANY_TOGGLE_MARK
);
926 editor_prefs
.autoclose_chars
= utils_get_setting_integer(config
, PACKAGE
, "autoclose_chars", 0);
929 * use current locale encoding as default for new files (should be UTF-8 in most cases) */
930 g_get_charset(&default_charset
);
931 tmp_string
= utils_get_setting_string(config
, PACKAGE
, "pref_editor_default_new_encoding",
935 const GeanyEncoding
*enc
= encodings_get_from_charset(tmp_string
);
937 file_prefs
.default_new_encoding
= enc
->idx
;
939 file_prefs
.default_new_encoding
= GEANY_ENCODING_UTF_8
;
943 tmp_string
= utils_get_setting_string(config
, PACKAGE
, "pref_editor_default_open_encoding",
947 const GeanyEncoding
*enc
= NULL
;
948 if (strcmp(tmp_string
, "none") != 0)
949 enc
= encodings_get_from_charset(tmp_string
);
951 file_prefs
.default_open_encoding
= enc
->idx
;
953 file_prefs
.default_open_encoding
= -1;
957 file_prefs
.default_eol_character
= utils_get_setting_integer(config
, PACKAGE
, "default_eol_character", GEANY_DEFAULT_EOL_CHARACTER
);
958 file_prefs
.replace_tabs
= utils_get_setting_boolean(config
, PACKAGE
, "pref_editor_replace_tabs", FALSE
);
959 file_prefs
.ensure_convert_new_lines
= utils_get_setting_boolean(config
, PACKAGE
, "pref_editor_ensure_convert_line_endings", FALSE
);
960 file_prefs
.final_new_line
= utils_get_setting_boolean(config
, PACKAGE
, "pref_editor_new_line", TRUE
);
961 file_prefs
.strip_trailing_spaces
= utils_get_setting_boolean(config
, PACKAGE
, "pref_editor_trail_space", FALSE
);
964 toolbar_prefs
.visible
= utils_get_setting_boolean(config
, PACKAGE
, "pref_toolbar_show", TRUE
);
965 toolbar_prefs
.append_to_menu
= utils_get_setting_boolean(config
, PACKAGE
, "pref_toolbar_append_to_menu", FALSE
);
967 toolbar_prefs
.use_gtk_default_style
= utils_get_setting_boolean(config
, PACKAGE
, "pref_toolbar_use_gtk_default_style", TRUE
);
968 if (! toolbar_prefs
.use_gtk_default_style
)
969 toolbar_prefs
.icon_style
= utils_get_setting_integer(config
, PACKAGE
, "pref_toolbar_icon_style", GTK_TOOLBAR_ICONS
);
971 toolbar_prefs
.use_gtk_default_icon
= utils_get_setting_boolean(config
, PACKAGE
, "pref_toolbar_use_gtk_default_icon", TRUE
);
972 if (! toolbar_prefs
.use_gtk_default_icon
)
973 toolbar_prefs
.icon_size
= utils_get_setting_integer(config
, PACKAGE
, "pref_toolbar_icon_size", GTK_ICON_SIZE_LARGE_TOOLBAR
);
978 vte_info
.load_vte
= utils_get_setting_boolean(config
, "VTE", "load_vte", TRUE
);
979 if (vte_info
.load_vte
&& vte_info
.load_vte_cmdline
/* not disabled on the cmdline */)
981 VteConfig
*vc
= &vte_config
;
982 struct passwd
*pw
= getpwuid(getuid());
983 const gchar
*shell
= (pw
!= NULL
) ? pw
->pw_shell
: "/bin/sh";
986 /* Geany is started using launchd on OS X and we don't get any environment variables
987 * so PS1 isn't defined. Start as a login shell to read the corresponding config files. */
988 if (strcmp(shell
, "/bin/bash") == 0)
989 shell
= "/bin/bash -l";
992 vte_info
.dir
= utils_get_setting_string(config
, "VTE", "last_dir", NULL
);
993 if ((vte_info
.dir
== NULL
|| utils_str_equal(vte_info
.dir
, "")) && pw
!= NULL
)
994 /* last dir is not set, fallback to user's home directory */
995 SETPTR(vte_info
.dir
, g_strdup(pw
->pw_dir
));
996 else if (vte_info
.dir
== NULL
&& pw
== NULL
)
997 /* fallback to root */
998 vte_info
.dir
= g_strdup("/");
1000 vc
->shell
= utils_get_setting_string(config
, "VTE", "shell", shell
);
1001 vc
->font
= utils_get_setting_string(config
, "VTE", "font", GEANY_DEFAULT_FONT_EDITOR
);
1002 vc
->scroll_on_key
= utils_get_setting_boolean(config
, "VTE", "scroll_on_key", TRUE
);
1003 vc
->scroll_on_out
= utils_get_setting_boolean(config
, "VTE", "scroll_on_out", TRUE
);
1004 vc
->enable_bash_keys
= utils_get_setting_boolean(config
, "VTE", "enable_bash_keys", TRUE
);
1005 vc
->ignore_menu_bar_accel
= utils_get_setting_boolean(config
, "VTE", "ignore_menu_bar_accel", FALSE
);
1006 vc
->follow_path
= utils_get_setting_boolean(config
, "VTE", "follow_path", FALSE
);
1007 vc
->run_in_vte
= utils_get_setting_boolean(config
, "VTE", "run_in_vte", FALSE
);
1008 vc
->skip_run_script
= utils_get_setting_boolean(config
, "VTE", "skip_run_script", FALSE
);
1009 vc
->cursor_blinks
= utils_get_setting_boolean(config
, "VTE", "cursor_blinks", FALSE
);
1010 vc
->scrollback_lines
= utils_get_setting_integer(config
, "VTE", "scrollback_lines", 500);
1011 get_setting_color(config
, "VTE", "colour_fore", &vc
->colour_fore
, "#ffffff");
1012 get_setting_color(config
, "VTE", "colour_back", &vc
->colour_back
, "#000000");
1016 template_prefs
.developer
= utils_get_setting_string(config
, PACKAGE
, "pref_template_developer", g_get_real_name());
1017 template_prefs
.company
= utils_get_setting_string(config
, PACKAGE
, "pref_template_company", "");
1018 tmp_string
= utils_get_initials(template_prefs
.developer
);
1019 template_prefs
.initials
= utils_get_setting_string(config
, PACKAGE
, "pref_template_initial", tmp_string
);
1022 template_prefs
.version
= utils_get_setting_string(config
, PACKAGE
, "pref_template_version", "1.0");
1024 tmp_string
= g_strdup_printf("%s@%s", g_get_user_name(), g_get_host_name());
1025 template_prefs
.mail
= utils_get_setting_string(config
, PACKAGE
, "pref_template_mail", tmp_string
);
1027 template_prefs
.year_format
= utils_get_setting_string(config
, PACKAGE
, "pref_template_year", GEANY_TEMPLATES_FORMAT_YEAR
);
1028 template_prefs
.date_format
= utils_get_setting_string(config
, PACKAGE
, "pref_template_date", GEANY_TEMPLATES_FORMAT_DATE
);
1029 template_prefs
.datetime_format
= utils_get_setting_string(config
, PACKAGE
, "pref_template_datetime", GEANY_TEMPLATES_FORMAT_DATETIME
);
1032 cmd
= utils_get_setting_string(config
, "tools", "terminal_cmd", "");
1035 SETPTR(cmd
, utils_get_setting_string(config
, "tools", "term_cmd", ""));
1040 if (strstr(cmd
, "cmd.exe"))
1041 cmd
= g_strconcat(cmd
, " /Q /C %c", NULL
);
1043 cmd
= g_strconcat(cmd
, " %c", NULL
);
1045 cmd
= g_strconcat(cmd
, " -e \"/bin/sh %c\"", NULL
);
1050 SETPTR(cmd
, g_strdup(GEANY_DEFAULT_TOOLS_TERMINAL
));
1052 tool_prefs
.term_cmd
= cmd
;
1053 tool_prefs
.browser_cmd
= utils_get_setting_string(config
, "tools", "browser_cmd", GEANY_DEFAULT_TOOLS_BROWSER
);
1054 tool_prefs
.grep_cmd
= utils_get_setting_string(config
, "tools", "grep_cmd", GEANY_DEFAULT_TOOLS_GREP
);
1056 tool_prefs
.context_action_cmd
= utils_get_setting_string(config
, PACKAGE
, "context_action_cmd", "");
1059 tmp_string2
= g_find_program_in_path(GEANY_DEFAULT_TOOLS_PRINTCMD
);
1061 if (!EMPTY(tmp_string2
))
1064 tmp_string
= g_strconcat(GEANY_DEFAULT_TOOLS_PRINTCMD
, " \"%f\"", NULL
);
1066 tmp_string
= g_strconcat(GEANY_DEFAULT_TOOLS_PRINTCMD
, " '%f'", NULL
);
1071 tmp_string
= g_strdup("");
1074 printing_prefs
.external_print_cmd
= utils_get_setting_string(config
, "printing", "print_cmd", tmp_string
);
1076 g_free(tmp_string2
);
1078 printing_prefs
.use_gtk_printing
= utils_get_setting_boolean(config
, "printing", "use_gtk_printing", TRUE
);
1079 printing_prefs
.print_line_numbers
= utils_get_setting_boolean(config
, "printing", "print_line_numbers", TRUE
);
1080 printing_prefs
.print_page_numbers
= utils_get_setting_boolean(config
, "printing", "print_page_numbers", TRUE
);
1081 printing_prefs
.print_page_header
= utils_get_setting_boolean(config
, "printing", "print_page_header", TRUE
);
1082 printing_prefs
.page_header_basename
= utils_get_setting_boolean(config
, "printing", "page_header_basename", FALSE
);
1083 printing_prefs
.page_header_datefmt
= utils_get_setting_string(config
, "printing", "page_header_datefmt", "%c");
1087 static void load_ui_prefs(GKeyFile
*config
)
1089 ui_prefs
.sidebar_visible
= utils_get_setting_boolean(config
, PACKAGE
, "sidebar_visible", TRUE
);
1090 ui_prefs
.msgwindow_visible
= utils_get_setting_boolean(config
, PACKAGE
, "msgwindow_visible", TRUE
);
1091 ui_prefs
.fullscreen
= utils_get_setting_boolean(config
, PACKAGE
, "fullscreen", FALSE
);
1092 ui_prefs
.symbols_group_by_type
= utils_get_setting_boolean(config
, PACKAGE
, "symbols_group_by_type", TRUE
);
1093 ui_prefs
.custom_date_format
= utils_get_setting_string(config
, PACKAGE
, "custom_date_format", "");
1094 ui_prefs
.custom_commands
= g_key_file_get_string_list(config
, PACKAGE
, "custom_commands", NULL
, NULL
);
1095 ui_prefs
.custom_commands_labels
= g_key_file_get_string_list(config
, PACKAGE
, "custom_commands_labels", NULL
, NULL
);
1096 ui_prefs
.color_picker_palette
= utils_get_setting_string(config
, PACKAGE
, "color_picker_palette", "");
1098 /* Load the saved color picker palette */
1099 if (!EMPTY(ui_prefs
.color_picker_palette
))
1101 GtkSettings
*settings
;
1102 settings
= gtk_settings_get_for_screen(gtk_window_get_screen(GTK_WINDOW(main_widgets
.window
)));
1103 g_object_set(G_OBJECT(settings
), "gtk-color-palette", ui_prefs
.color_picker_palette
, NULL
);
1106 /* sanitize custom commands labels */
1107 if (ui_prefs
.custom_commands
|| ui_prefs
.custom_commands_labels
)
1110 guint cc_len
= ui_prefs
.custom_commands
? g_strv_length(ui_prefs
.custom_commands
) : 0;
1111 guint cc_labels_len
= ui_prefs
.custom_commands_labels
? g_strv_length(ui_prefs
.custom_commands_labels
) : 0;
1113 /* not enough items, resize and fill */
1114 if (cc_labels_len
< cc_len
)
1116 ui_prefs
.custom_commands_labels
= g_realloc(ui_prefs
.custom_commands_labels
,
1117 (cc_len
+ 1) * sizeof *ui_prefs
.custom_commands_labels
);
1118 for (i
= cc_labels_len
; i
< cc_len
; i
++)
1119 ui_prefs
.custom_commands_labels
[i
] = g_strdup("");
1120 ui_prefs
.custom_commands_labels
[cc_len
] = NULL
;
1122 /* too many items, cut off */
1123 else if (cc_labels_len
> cc_len
)
1125 for (i
= cc_len
; i
< cc_labels_len
; i
++)
1127 g_free(ui_prefs
.custom_commands_labels
[i
]);
1128 ui_prefs
.custom_commands_labels
[i
] = NULL
;
1133 scribble_text
= utils_get_setting_string(config
, PACKAGE
, "scribble_text",
1134 _("Type here what you want, use it as a notice/scratch board"));
1135 scribble_pos
= utils_get_setting_integer(config
, PACKAGE
, "scribble_pos", -1);
1138 static void load_ui_session(GKeyFile
*config
)
1143 geo
= g_key_file_get_integer_list(config
, PACKAGE
, "geometry", &geo_len
, NULL
);
1144 if (! geo
|| geo_len
< 5)
1146 ui_prefs
.geometry
[0] = -1;
1147 ui_prefs
.geometry
[1] = -1;
1148 ui_prefs
.geometry
[2] = -1;
1149 ui_prefs
.geometry
[3] = -1;
1150 ui_prefs
.geometry
[4] = 0;
1154 /* don't use insane values but when main windows was maximized last time, pos might be
1155 * negative (due to differences in root window and window decorations) */
1156 /* quitting when minimized can make pos -32000, -32000 on Windows! */
1157 ui_prefs
.geometry
[0] = MAX(-1, geo
[0]);
1158 ui_prefs
.geometry
[1] = MAX(-1, geo
[1]);
1159 ui_prefs
.geometry
[2] = MAX(-1, geo
[2]);
1160 ui_prefs
.geometry
[3] = MAX(-1, geo
[3]);
1161 ui_prefs
.geometry
[4] = geo
[4] != 0;
1163 hpan_position
= utils_get_setting_integer(config
, PACKAGE
, "treeview_position", 156);
1164 vpan_position
= utils_get_setting_integer(config
, PACKAGE
, "msgwindow_position", (geo
) ?
1165 (GEANY_MSGWIN_HEIGHT
+ geo
[3] - 440) :
1166 (GEANY_MSGWIN_HEIGHT
+ GEANY_WINDOW_DEFAULT_HEIGHT
- 440));
1173 * Save current session in default configuration file
1175 void configuration_save_default_session(void)
1177 gchar
*configfile
= g_build_filename(app
->configdir
, SESSION_FILE
, NULL
);
1179 GKeyFile
*config
= g_key_file_new();
1181 g_key_file_load_from_file(config
, configfile
, G_KEY_FILE_NONE
, NULL
);
1183 if (cl_options
.load_session
)
1184 configuration_save_session_files(config
);
1186 /* write the file */
1187 data
= g_key_file_to_data(config
, NULL
, NULL
);
1188 utils_write_file(configfile
, data
);
1191 g_key_file_free(config
);
1196 void configuration_clear_default_session(void)
1198 gchar
*configfile
= g_build_filename(app
->configdir
, SESSION_FILE
, NULL
);
1200 GKeyFile
*config
= g_key_file_new();
1202 g_key_file_load_from_file(config
, configfile
, G_KEY_FILE_NONE
, NULL
);
1204 if (cl_options
.load_session
)
1205 remove_session_files(config
);
1207 /* write the file */
1208 data
= g_key_file_to_data(config
, NULL
, NULL
);
1209 utils_write_file(configfile
, data
);
1212 g_key_file_free(config
);
1218 * Only reload the session part of the default configuration
1220 void configuration_load_default_session(void)
1222 gchar
*configfile
= get_keyfile_for_payload(SESSION
);
1223 GKeyFile
*config
= g_key_file_new();
1225 g_return_if_fail(default_session_files
== NULL
);
1227 g_key_file_load_from_file(config
, configfile
, G_KEY_FILE_NONE
, NULL
);
1230 default_session_files
= configuration_load_session_files(config
);
1232 g_key_file_free(config
);
1235 static gboolean
read_config_file(ConfigPayload payload
)
1237 GKeyFile
*config
= g_key_file_new();
1240 configfile
= get_keyfile_for_payload(payload
);
1241 g_key_file_load_from_file(config
, configfile
, G_KEY_FILE_NONE
, NULL
);
1244 /* read stash prefs */
1245 settings_action(config
, SETTING_READ
, payload
);
1250 load_dialog_prefs(config
);
1251 load_ui_prefs(config
);
1253 /* build menu, after stash prefs as it uses some of them */
1254 build_set_group_count(GEANY_GBG_FT
, build_menu_prefs
.number_ft_menu_items
);
1255 build_set_group_count(GEANY_GBG_NON_FT
, build_menu_prefs
.number_non_ft_menu_items
);
1256 build_set_group_count(GEANY_GBG_EXEC
, build_menu_prefs
.number_exec_menu_items
);
1257 build_load_menu(config
, GEANY_BCS_PREF
, NULL
);
1258 /* this signal can be used e.g. to delay building UI elements until settings have been read */
1259 g_signal_emit_by_name(geany_object
, "load-settings", config
);
1262 project_load_prefs(config
);
1263 load_ui_session(config
);
1264 load_recent_files(config
, ui_prefs
.recent_queue
, "recent_files");
1265 load_recent_files(config
, ui_prefs
.recent_projects_queue
, "recent_projects");
1268 g_assert_not_reached();
1271 g_key_file_free(config
);
1276 gboolean
configuration_load(void)
1278 gboolean prefs_loaded
= read_config_file(PREFS
);
1279 gboolean sess_loaded
= read_config_file(SESSION
);
1281 return prefs_loaded
&& sess_loaded
;
1285 static gboolean
open_session_file(gchar
**tmp
, guint len
)
1288 const gchar
*ft_name
;
1289 gchar
*locale_filename
;
1290 gchar
*unescaped_filename
;
1291 const gchar
*encoding
;
1293 gboolean ro
, auto_indent
, line_wrapping
;
1294 /** TODO when we have a global pref for line breaking, use its value */
1295 gboolean line_breaking
= FALSE
;
1296 gboolean ret
= FALSE
;
1301 if (isdigit(tmp
[3][0]))
1303 encoding
= encodings_get_charset_from_index(atoi(tmp
[3]));
1307 encoding
= &(tmp
[3][1]);
1309 indent_type
= atoi(tmp
[4]);
1310 auto_indent
= atoi(tmp
[5]);
1311 line_wrapping
= atoi(tmp
[6]);
1312 /* try to get the locale equivalent for the filename */
1313 unescaped_filename
= g_uri_unescape_string(tmp
[7], NULL
);
1314 locale_filename
= utils_get_locale_from_utf8(unescaped_filename
);
1317 line_breaking
= atoi(tmp
[8]);
1319 if (g_file_test(locale_filename
, G_FILE_TEST_IS_REGULAR
))
1321 GeanyFiletype
*ft
= filetypes_lookup_by_name(ft_name
);
1322 GeanyDocument
*doc
= document_open_file_full(
1323 NULL
, locale_filename
, pos
, ro
, ft
, encoding
);
1327 gint indent_width
= doc
->editor
->indent_width
;
1330 indent_width
= atoi(tmp
[9]);
1331 editor_set_indent(doc
->editor
, indent_type
, indent_width
);
1332 editor_set_line_wrapping(doc
->editor
, line_wrapping
);
1333 doc
->editor
->line_breaking
= line_breaking
;
1334 doc
->editor
->auto_indent
= auto_indent
;
1340 geany_debug("Could not find file '%s'.", unescaped_filename
);
1343 g_free(locale_filename
);
1344 g_free(unescaped_filename
);
1349 /* Open session files
1350 * Note: notebook page switch handler and adding to recent files list is always disabled
1351 * for all files opened within this function */
1352 void configuration_open_files(GPtrArray
*session_files
)
1355 gboolean failure
= FALSE
;
1357 /* necessary to set it to TRUE for project session support */
1358 main_status
.opening_session_files
++;
1360 i
= file_prefs
.tab_order_ltr
? 0 : (session_files
->len
- 1);
1363 gchar
**tmp
= g_ptr_array_index(session_files
, i
);
1366 if (tmp
!= NULL
&& (len
= g_strv_length(tmp
)) >= 8)
1368 if (! open_session_file(tmp
, len
))
1373 if (file_prefs
.tab_order_ltr
)
1376 if (i
>= (gint
)session_files
->len
)
1387 g_ptr_array_free(session_files
, TRUE
);
1390 ui_set_statusbar(TRUE
, _("Failed to load one or more session files."));
1392 document_show_tab_idle(session_notebook_page
>= 0 ? document_get_from_page(session_notebook_page
) : document_get_current());
1394 session_notebook_page
= -1;
1395 main_status
.opening_session_files
--;
1399 /* Open session files
1400 * Note: notebook page switch handler and adding to recent files list is always disabled
1401 * for all files opened within this function */
1402 void configuration_open_default_session(void)
1404 g_return_if_fail(default_session_files
!= NULL
);
1406 configuration_open_files(default_session_files
);
1407 default_session_files
= NULL
;
1411 /* set some settings which are already read from the config file, but need other things, like the
1412 * realisation of the main window */
1413 void configuration_apply_settings(void)
1416 { /* update the scribble widget, because now it's realized */
1418 GtkTextBuffer
*buffer
=
1419 gtk_text_view_get_buffer(GTK_TEXT_VIEW(msgwindow
.scribble
));
1421 gtk_text_buffer_set_text(buffer
, scribble_text
, -1);
1422 gtk_text_buffer_get_iter_at_offset(buffer
, &iter
, scribble_pos
);
1423 gtk_text_buffer_place_cursor(buffer
, &iter
);
1425 g_free(scribble_text
);
1427 /* set the position of the hpaned and vpaned */
1428 if (prefs
.save_winpos
)
1430 gtk_paned_set_position(GTK_PANED(ui_lookup_widget(main_widgets
.window
, "hpaned1")), hpan_position
);
1431 gtk_paned_set_position(GTK_PANED(ui_lookup_widget(main_widgets
.window
, "vpaned1")), vpan_position
);
1434 /* set fullscreen after initial draw so that returning to normal view is the right size.
1435 * fullscreen mode is disabled by default, so act only if it is true */
1436 if (ui_prefs
.fullscreen
)
1438 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ui_lookup_widget(main_widgets
.window
, "menu_fullscreen1")), TRUE
);
1439 ui_prefs
.fullscreen
= TRUE
;
1440 ui_set_fullscreen();
1443 msgwin_show_hide_tabs();
1447 static gboolean
save_configuration_cb(gpointer data
)
1449 if (app
->project
!= NULL
)
1450 project_write_config();
1452 configuration_save_default_session();
1453 return G_SOURCE_REMOVE
;
1457 static void document_list_changed_cb(GObject
*obj
, GeanyDocument
*doc
, gpointer data
)
1459 g_return_if_fail(doc
!= NULL
&& doc
->is_valid
);
1461 /* save configuration, especially session file list, but only if we are not just starting
1462 * and not about to quit */
1463 if (file_prefs
.save_config_on_file_change
&&
1464 main_status
.main_window_realized
&&
1465 !main_status
.opening_session_files
&&
1466 !main_status
.quitting
)
1468 g_idle_remove_by_data(save_configuration_cb
);
1469 g_idle_add(save_configuration_cb
, save_configuration_cb
);
1474 void configuration_init(void)
1476 keyfile_groups
[PREFS
] = g_ptr_array_new_with_free_func((GDestroyNotify
) stash_group_free
);
1477 keyfile_groups
[SESSION
] = g_ptr_array_new_with_free_func((GDestroyNotify
) stash_group_free
);
1478 pref_groups
= g_ptr_array_new();
1481 g_signal_connect(geany_object
, "document-open", G_CALLBACK(document_list_changed_cb
), NULL
);
1482 g_signal_connect(geany_object
, "document-save", G_CALLBACK(document_list_changed_cb
), NULL
);
1483 g_signal_connect(geany_object
, "document-close", G_CALLBACK(document_list_changed_cb
), NULL
);
1487 void configuration_finalize(void)
1489 g_signal_handlers_disconnect_by_func(geany_object
, G_CALLBACK(document_list_changed_cb
), NULL
);
1491 g_ptr_array_free(pref_groups
, TRUE
);
1492 g_ptr_array_free(keyfile_groups
[SESSION
], TRUE
);
1493 g_ptr_array_free(keyfile_groups
[PREFS
], TRUE
);