2 * keyfile.c - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2005-2012 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5 * Copyright 2006-2012 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 * geany.conf preferences file loading and saving.
27 * Session file format:
28 * filename_xx=pos;filetype UID;read only;Eencoding;use_tabs;auto_indent;line_wrapping;filename
39 #include <sys/types.h>
49 #include "filetypes.h"
50 #include "sciwrappers.h"
51 #include "encodings.h"
54 #include "msgwindow.h"
59 #include "templates.h"
64 /* some default settings which are used at the very first start of Geany to fill
65 * the configuration file */
66 #define GEANY_MAX_SYMBOLLIST_HEIGHT 10
67 #define GEANY_MIN_SYMBOLLIST_CHARS 4
68 #define GEANY_MSGWIN_HEIGHT 208
69 #define GEANY_DISK_CHECK_TIMEOUT 30
70 #define GEANY_DEFAULT_TOOLS_MAKE "make"
72 #define GEANY_DEFAULT_TOOLS_TERMINAL "cmd.exe /Q /C %c"
74 #define GEANY_DEFAULT_TOOLS_TERMINAL "xterm -e \"/bin/sh %c\""
76 #define GEANY_DEFAULT_TOOLS_BROWSER "firefox"
77 #define GEANY_DEFAULT_TOOLS_PRINTCMD "lpr"
78 #define GEANY_DEFAULT_TOOLS_GREP "grep"
79 #define GEANY_DEFAULT_MRU_LENGTH 10
80 #define GEANY_DEFAULT_FONT_SYMBOL_LIST "Sans 9"
81 #define GEANY_DEFAULT_FONT_MSG_WINDOW "Sans 9"
82 #define GEANY_DEFAULT_FONT_EDITOR "Monospace 10"
83 #define GEANY_TOGGLE_MARK "~ "
84 #define GEANY_MAX_AUTOCOMPLETE_WORDS 30
85 #define GEANY_MAX_SYMBOLS_UPDATE_FREQ 250
86 #define GEANY_DEFAULT_FILETYPE_REGEX "-\\*-\\s*([^\\s]+)\\s*-\\*-"
89 static gchar
*scribble_text
= NULL
;
90 static gint scribble_pos
= -1;
91 static GPtrArray
*session_files
= NULL
;
92 static gint session_notebook_page
;
93 static gint hpan_position
;
94 static gint vpan_position
;
95 static const gchar atomic_file_saving_key
[] = "use_atomic_file_saving";
97 static GPtrArray
*keyfile_groups
= NULL
;
99 GPtrArray
*pref_groups
= NULL
;
103 gint number_ft_menu_items
;
104 gint number_non_ft_menu_items
;
105 gint number_exec_menu_items
;
110 /* The group will be free'd on quitting.
111 * @param for_prefs_dialog is whether the group also has Prefs dialog items. */
112 void configuration_add_pref_group(struct StashGroup
*group
, gboolean for_prefs_dialog
)
114 g_ptr_array_add(keyfile_groups
, group
);
116 if (for_prefs_dialog
)
117 g_ptr_array_add(pref_groups
, group
);
121 /* The group will be free'd on quitting. */
122 void configuration_add_various_pref_group(struct StashGroup
*group
)
124 configuration_add_pref_group(group
, TRUE
);
125 stash_group_set_various(group
, TRUE
);
129 static void init_pref_groups(void)
133 group
= stash_group_new(PACKAGE
);
134 configuration_add_pref_group(group
, TRUE
);
135 stash_group_add_entry(group
, &prefs
.default_open_path
,
136 "default_open_path", "", "startup_path_entry");
138 stash_group_add_toggle_button(group
, &file_prefs
.cmdline_new_files
,
139 "cmdline_new_files", TRUE
, "check_cmdline_new_files");
141 stash_group_add_toggle_button(group
, &interface_prefs
.notebook_double_click_hides_widgets
,
142 "notebook_double_click_hides_widgets", FALSE
, "check_double_click_hides_widgets");
143 stash_group_add_toggle_button(group
, &file_prefs
.tab_close_switch_to_mru
,
144 "tab_close_switch_to_mru", FALSE
, "check_tab_close_switch_to_mru");
145 stash_group_add_integer(group
, &interface_prefs
.tab_pos_sidebar
, "tab_pos_sidebar", GTK_POS_TOP
);
146 stash_group_add_radio_buttons(group
, &interface_prefs
.sidebar_pos
,
147 "sidebar_pos", GTK_POS_LEFT
,
148 "radio_sidebar_left", GTK_POS_LEFT
,
149 "radio_sidebar_right", GTK_POS_RIGHT
,
151 stash_group_add_radio_buttons(group
, &interface_prefs
.msgwin_orientation
,
152 "msgwin_orientation", GTK_ORIENTATION_VERTICAL
,
153 "radio_msgwin_vertical", GTK_ORIENTATION_VERTICAL
,
154 "radio_msgwin_horizontal", GTK_ORIENTATION_HORIZONTAL
,
158 stash_group_add_toggle_button(group
, &interface_prefs
.highlighting_invert_all
,
159 "highlighting_invert_all", FALSE
, "check_highlighting_invert");
161 stash_group_add_toggle_button(group
, &search_prefs
.use_current_word
,
162 "pref_main_search_use_current_word", TRUE
, "check_search_use_current_word");
165 stash_group_add_toggle_button(group
, &editor_prefs
.indentation
->detect_type
,
166 "check_detect_indent", FALSE
, "check_detect_indent_type");
167 stash_group_add_toggle_button(group
, &editor_prefs
.indentation
->detect_width
,
168 "detect_indent_width", FALSE
, "check_detect_indent_width");
169 stash_group_add_toggle_button(group
, &editor_prefs
.use_tab_to_indent
,
170 "use_tab_to_indent", TRUE
, "check_tab_key_indents");
171 stash_group_add_spin_button_integer(group
, &editor_prefs
.indentation
->width
,
172 "pref_editor_tab_width", 4, "spin_indent_width");
173 stash_group_add_combo_box(group
, (gint
*)(void*)&editor_prefs
.indentation
->auto_indent_mode
,
174 "indent_mode", GEANY_AUTOINDENT_CURRENTCHARS
, "combo_auto_indent_mode");
175 stash_group_add_radio_buttons(group
, (gint
*)(void*)&editor_prefs
.indentation
->type
,
176 "indent_type", GEANY_INDENT_TYPE_TABS
,
177 "radio_indent_spaces", GEANY_INDENT_TYPE_SPACES
,
178 "radio_indent_tabs", GEANY_INDENT_TYPE_TABS
,
179 "radio_indent_both", GEANY_INDENT_TYPE_BOTH
,
181 stash_group_add_radio_buttons(group
, (gint
*)(void*)&editor_prefs
.show_virtual_space
,
182 "virtualspace", GEANY_VIRTUAL_SPACE_SELECTION
,
183 "radio_virtualspace_disabled", GEANY_VIRTUAL_SPACE_DISABLED
,
184 "radio_virtualspace_selection", GEANY_VIRTUAL_SPACE_SELECTION
,
185 "radio_virtualspace_always", GEANY_VIRTUAL_SPACE_ALWAYS
,
187 stash_group_add_toggle_button(group
, &editor_prefs
.autocomplete_doc_words
,
188 "autocomplete_doc_words", FALSE
, "check_autocomplete_doc_words");
189 stash_group_add_toggle_button(group
, &editor_prefs
.completion_drops_rest_of_word
,
190 "completion_drops_rest_of_word", FALSE
, "check_completion_drops_rest_of_word");
191 stash_group_add_spin_button_integer(group
, (gint
*)&editor_prefs
.autocompletion_max_entries
,
192 "autocompletion_max_entries", GEANY_MAX_AUTOCOMPLETE_WORDS
,
193 "spin_autocompletion_max_entries");
194 stash_group_add_spin_button_integer(group
, (gint
*)&editor_prefs
.autocompletion_update_freq
,
195 "autocompletion_update_freq", GEANY_MAX_SYMBOLS_UPDATE_FREQ
, "spin_symbol_update_freq");
196 stash_group_add_string(group
, &editor_prefs
.color_scheme
,
197 "color_scheme", NULL
);
200 stash_group_add_spin_button_integer(group
, (gint
*)&file_prefs
.mru_length
,
201 "mru_length", GEANY_DEFAULT_MRU_LENGTH
, "spin_mru");
202 stash_group_add_spin_button_integer(group
, &file_prefs
.disk_check_timeout
,
203 "disk_check_timeout", GEANY_DISK_CHECK_TIMEOUT
, "spin_disk_check");
205 /* various geany prefs */
206 group
= stash_group_new(PACKAGE
);
207 configuration_add_various_pref_group(group
);
209 stash_group_add_boolean(group
, &editor_prefs
.show_scrollbars
,
210 "show_editor_scrollbars", TRUE
);
211 stash_group_add_boolean(group
, &editor_prefs
.brace_match_ltgt
,
212 "brace_match_ltgt", FALSE
);
213 stash_group_add_boolean(group
, &editor_prefs
.use_gtk_word_boundaries
,
214 "use_gtk_word_boundaries", TRUE
);
215 stash_group_add_boolean(group
, &editor_prefs
.complete_snippets_whilst_editing
,
216 "complete_snippets_whilst_editing", FALSE
);
217 stash_group_add_boolean(group
, &file_prefs
.use_safe_file_saving
,
218 atomic_file_saving_key
, FALSE
);
219 stash_group_add_boolean(group
, &file_prefs
.gio_unsafe_save_backup
,
220 "gio_unsafe_save_backup", FALSE
);
221 stash_group_add_boolean(group
, &file_prefs
.use_gio_unsafe_file_saving
,
222 "use_gio_unsafe_file_saving", TRUE
);
223 /* for backwards-compatibility */
224 stash_group_add_integer(group
, &editor_prefs
.indentation
->hard_tab_width
,
225 "indent_hard_tab_width", 8);
226 stash_group_add_integer(group
, (gint
*)&search_prefs
.find_selection_type
,
227 "find_selection_type", GEANY_FIND_SEL_CURRENT_WORD
);
228 stash_group_add_string(group
, &file_prefs
.extract_filetype_regex
,
229 "extract_filetype_regex", GEANY_DEFAULT_FILETYPE_REGEX
);
231 /* Note: Interface-related various prefs are in ui_init_prefs() */
233 /* various build-menu prefs */
234 group
= stash_group_new("build-menu");
235 configuration_add_various_pref_group(group
);
237 stash_group_add_integer(group
, &build_menu_prefs
.number_ft_menu_items
,
238 "number_ft_menu_items", 0);
239 stash_group_add_integer(group
, &build_menu_prefs
.number_non_ft_menu_items
,
240 "number_non_ft_menu_items", 0);
241 stash_group_add_integer(group
, &build_menu_prefs
.number_exec_menu_items
,
242 "number_exec_menu_items", 0);
246 typedef enum SettingAction
253 static void settings_action(GKeyFile
*config
, SettingAction action
)
258 foreach_ptr_array(group
, i
, keyfile_groups
)
263 stash_group_load_from_key_file(group
, config
); break;
265 stash_group_save_to_key_file(group
, config
); break;
271 static void save_recent_files(GKeyFile
*config
, GQueue
*queue
, gchar
const *key
)
273 gchar
**recent_files
= g_new0(gchar
*, file_prefs
.mru_length
+ 1);
276 for (i
= 0; i
< file_prefs
.mru_length
; i
++)
278 if (! g_queue_is_empty(queue
))
280 /* copy the values, this is necessary when this function is called from the
281 * preferences dialog or when quitting is canceled to keep the queue intact */
282 recent_files
[i
] = g_strdup(g_queue_peek_nth(queue
, i
));
286 recent_files
[i
] = NULL
;
290 /* There is a bug in GTK 2.6 g_key_file_set_string_list, we must NULL terminate. */
291 recent_files
[file_prefs
.mru_length
] = NULL
;
292 g_key_file_set_string_list(config
, "files", key
,
293 (const gchar
**)recent_files
, file_prefs
.mru_length
);
294 g_strfreev(recent_files
);
298 static gchar
*get_session_file_string(GeanyDocument
*doc
)
301 gchar
*locale_filename
;
302 gchar
*escaped_filename
;
303 GeanyFiletype
*ft
= doc
->file_type
;
305 if (ft
== NULL
) /* can happen when saving a new file when quitting */
306 ft
= filetypes
[GEANY_FILETYPES_NONE
];
308 locale_filename
= utils_get_locale_from_utf8(doc
->file_name
);
309 escaped_filename
= g_uri_escape_string(locale_filename
, NULL
, TRUE
);
311 fname
= g_strdup_printf("%d;%s;%d;E%s;%d;%d;%d;%s;%d;%d",
312 sci_get_current_position(doc
->editor
->sci
),
316 doc
->editor
->indent_type
,
317 doc
->editor
->auto_indent
,
318 doc
->editor
->line_wrapping
,
320 doc
->editor
->line_breaking
,
321 doc
->editor
->indent_width
);
322 g_free(escaped_filename
);
323 g_free(locale_filename
);
328 void configuration_save_session_files(GKeyFile
*config
)
333 guint i
= 0, j
= 0, max
;
336 npage
= gtk_notebook_get_current_page(GTK_NOTEBOOK(main_widgets
.notebook
));
337 g_key_file_set_integer(config
, "files", "current_page", npage
);
339 /* store the filenames in the notebook tab order to reopen them the next time */
340 max
= gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets
.notebook
));
341 for (i
= 0; i
< max
; i
++)
343 doc
= document_get_from_page(i
);
344 if (doc
!= NULL
&& doc
->real_path
!= NULL
)
348 g_snprintf(entry
, sizeof(entry
), "FILE_NAME_%d", j
);
349 fname
= get_session_file_string(doc
);
350 g_key_file_set_string(config
, "files", entry
, fname
);
355 /* if open filenames less than saved session files, delete existing entries in the list */
359 g_snprintf(entry
, sizeof(entry
), "FILE_NAME_%d", i
);
360 tmp
= g_key_file_get_string(config
, "files", entry
, NULL
);
361 if (G_UNLIKELY(tmp
== NULL
))
367 g_key_file_remove_key(config
, "files", entry
, NULL
);
374 if (vte_info
.have_vte
)
376 vte_get_working_directory(); /* refresh vte_info.dir */
377 g_key_file_set_string(config
, "VTE", "last_dir", vte_info
.dir
);
383 static void save_dialog_prefs(GKeyFile
*config
)
385 /* new settings should be added in init_pref_groups() */
386 settings_action(config
, SETTING_WRITE
);
388 /* Some of the key names are not consistent, but this is for backwards compatibility */
391 g_key_file_set_boolean(config
, PACKAGE
, "pref_main_load_session", prefs
.load_session
);
392 g_key_file_set_boolean(config
, PACKAGE
, "pref_main_project_session", project_prefs
.project_session
);
393 g_key_file_set_boolean(config
, PACKAGE
, "pref_main_project_file_in_basedir", project_prefs
.project_file_in_basedir
);
394 g_key_file_set_boolean(config
, PACKAGE
, "pref_main_save_winpos", prefs
.save_winpos
);
395 g_key_file_set_boolean(config
, PACKAGE
, "pref_main_confirm_exit", prefs
.confirm_exit
);
396 g_key_file_set_boolean(config
, PACKAGE
, "pref_main_suppress_status_messages", prefs
.suppress_status_messages
);
397 g_key_file_set_boolean(config
, PACKAGE
, "switch_msgwin_pages", prefs
.switch_to_status
);
398 g_key_file_set_boolean(config
, PACKAGE
, "beep_on_errors", prefs
.beep_on_errors
);
399 g_key_file_set_boolean(config
, PACKAGE
, "auto_focus", prefs
.auto_focus
);
402 g_key_file_set_boolean(config
, PACKAGE
, "sidebar_symbol_visible", interface_prefs
.sidebar_symbol_visible
);
403 g_key_file_set_boolean(config
, PACKAGE
, "sidebar_openfiles_visible", interface_prefs
.sidebar_openfiles_visible
);
404 g_key_file_set_string(config
, PACKAGE
, "editor_font", interface_prefs
.editor_font
);
405 g_key_file_set_string(config
, PACKAGE
, "tagbar_font", interface_prefs
.tagbar_font
);
406 g_key_file_set_string(config
, PACKAGE
, "msgwin_font", interface_prefs
.msgwin_font
);
407 g_key_file_set_boolean(config
, PACKAGE
, "show_notebook_tabs", interface_prefs
.show_notebook_tabs
);
408 g_key_file_set_boolean(config
, PACKAGE
, "show_tab_cross", file_prefs
.show_tab_cross
);
409 g_key_file_set_boolean(config
, PACKAGE
, "tab_order_ltr", file_prefs
.tab_order_ltr
);
410 g_key_file_set_boolean(config
, PACKAGE
, "tab_order_beside", file_prefs
.tab_order_beside
);
411 g_key_file_set_integer(config
, PACKAGE
, "tab_pos_editor", interface_prefs
.tab_pos_editor
);
412 g_key_file_set_integer(config
, PACKAGE
, "tab_pos_msgwin", interface_prefs
.tab_pos_msgwin
);
413 g_key_file_set_boolean(config
, PACKAGE
, "use_native_windows_dialogs", interface_prefs
.use_native_windows_dialogs
);
416 g_key_file_set_boolean(config
, PACKAGE
, "show_indent_guide", editor_prefs
.show_indent_guide
);
417 g_key_file_set_boolean(config
, PACKAGE
, "show_white_space", editor_prefs
.show_white_space
);
418 g_key_file_set_boolean(config
, PACKAGE
, "show_line_endings", editor_prefs
.show_line_endings
);
419 g_key_file_set_boolean(config
, PACKAGE
, "show_markers_margin", editor_prefs
.show_markers_margin
);
420 g_key_file_set_boolean(config
, PACKAGE
, "show_linenumber_margin", editor_prefs
.show_linenumber_margin
);
421 g_key_file_set_boolean(config
, PACKAGE
, "long_line_enabled", editor_prefs
.long_line_enabled
);
422 g_key_file_set_integer(config
, PACKAGE
, "long_line_type", editor_prefs
.long_line_type
);
423 g_key_file_set_integer(config
, PACKAGE
, "long_line_column", editor_prefs
.long_line_column
);
424 g_key_file_set_string(config
, PACKAGE
, "long_line_color", editor_prefs
.long_line_color
);
427 g_key_file_set_integer(config
, PACKAGE
, "symbolcompletion_max_height", editor_prefs
.symbolcompletion_max_height
);
428 g_key_file_set_integer(config
, PACKAGE
, "symbolcompletion_min_chars", editor_prefs
.symbolcompletion_min_chars
);
429 g_key_file_set_boolean(config
, PACKAGE
, "use_folding", editor_prefs
.folding
);
430 g_key_file_set_boolean(config
, PACKAGE
, "unfold_all_children", editor_prefs
.unfold_all_children
);
431 g_key_file_set_boolean(config
, PACKAGE
, "use_indicators", editor_prefs
.use_indicators
);
432 g_key_file_set_boolean(config
, PACKAGE
, "line_wrapping", editor_prefs
.line_wrapping
);
433 g_key_file_set_boolean(config
, PACKAGE
, "auto_close_xml_tags", editor_prefs
.auto_close_xml_tags
);
434 g_key_file_set_boolean(config
, PACKAGE
, "complete_snippets", editor_prefs
.complete_snippets
);
435 g_key_file_set_boolean(config
, PACKAGE
, "auto_complete_symbols", editor_prefs
.auto_complete_symbols
);
436 g_key_file_set_boolean(config
, PACKAGE
, "pref_editor_disable_dnd", editor_prefs
.disable_dnd
);
437 g_key_file_set_boolean(config
, PACKAGE
, "pref_editor_smart_home_key", editor_prefs
.smart_home_key
);
438 g_key_file_set_boolean(config
, PACKAGE
, "pref_editor_newline_strip", editor_prefs
.newline_strip
);
439 g_key_file_set_integer(config
, PACKAGE
, "line_break_column", editor_prefs
.line_break_column
);
440 g_key_file_set_boolean(config
, PACKAGE
, "auto_continue_multiline", editor_prefs
.auto_continue_multiline
);
441 g_key_file_set_string(config
, PACKAGE
, "comment_toggle_mark", editor_prefs
.comment_toggle_mark
);
442 g_key_file_set_boolean(config
, PACKAGE
, "scroll_stop_at_last_line", editor_prefs
.scroll_stop_at_last_line
);
443 g_key_file_set_integer(config
, PACKAGE
, "autoclose_chars", editor_prefs
.autoclose_chars
);
446 g_key_file_set_string(config
, PACKAGE
, "pref_editor_default_new_encoding", encodings
[file_prefs
.default_new_encoding
].charset
);
447 if (file_prefs
.default_open_encoding
== -1)
448 g_key_file_set_string(config
, PACKAGE
, "pref_editor_default_open_encoding", "none");
450 g_key_file_set_string(config
, PACKAGE
, "pref_editor_default_open_encoding", encodings
[file_prefs
.default_open_encoding
].charset
);
451 g_key_file_set_integer(config
, PACKAGE
, "default_eol_character", file_prefs
.default_eol_character
);
452 g_key_file_set_boolean(config
, PACKAGE
, "pref_editor_new_line", file_prefs
.final_new_line
);
453 g_key_file_set_boolean(config
, PACKAGE
, "pref_editor_ensure_convert_line_endings", file_prefs
.ensure_convert_new_lines
);
454 g_key_file_set_boolean(config
, PACKAGE
, "pref_editor_replace_tabs", file_prefs
.replace_tabs
);
455 g_key_file_set_boolean(config
, PACKAGE
, "pref_editor_trail_space", file_prefs
.strip_trailing_spaces
);
458 g_key_file_set_boolean(config
, PACKAGE
, "pref_toolbar_show", toolbar_prefs
.visible
);
459 g_key_file_set_boolean(config
, PACKAGE
, "pref_toolbar_append_to_menu", toolbar_prefs
.append_to_menu
);
460 g_key_file_set_boolean(config
, PACKAGE
, "pref_toolbar_use_gtk_default_style", toolbar_prefs
.use_gtk_default_style
);
461 g_key_file_set_boolean(config
, PACKAGE
, "pref_toolbar_use_gtk_default_icon", toolbar_prefs
.use_gtk_default_icon
);
462 g_key_file_set_integer(config
, PACKAGE
, "pref_toolbar_icon_style", toolbar_prefs
.icon_style
);
463 g_key_file_set_integer(config
, PACKAGE
, "pref_toolbar_icon_size", toolbar_prefs
.icon_size
);
466 g_key_file_set_string(config
, PACKAGE
, "pref_template_developer", template_prefs
.developer
);
467 g_key_file_set_string(config
, PACKAGE
, "pref_template_company", template_prefs
.company
);
468 g_key_file_set_string(config
, PACKAGE
, "pref_template_mail", template_prefs
.mail
);
469 g_key_file_set_string(config
, PACKAGE
, "pref_template_initial", template_prefs
.initials
);
470 g_key_file_set_string(config
, PACKAGE
, "pref_template_version", template_prefs
.version
);
471 g_key_file_set_string(config
, PACKAGE
, "pref_template_year", template_prefs
.year_format
);
472 g_key_file_set_string(config
, PACKAGE
, "pref_template_date", template_prefs
.date_format
);
473 g_key_file_set_string(config
, PACKAGE
, "pref_template_datetime", template_prefs
.datetime_format
);
476 g_key_file_set_string(config
, "tools", "terminal_cmd", tool_prefs
.term_cmd
? tool_prefs
.term_cmd
: "");
477 g_key_file_set_string(config
, "tools", "browser_cmd", tool_prefs
.browser_cmd
? tool_prefs
.browser_cmd
: "");
478 g_key_file_set_string(config
, "tools", "grep_cmd", tool_prefs
.grep_cmd
? tool_prefs
.grep_cmd
: "");
479 g_key_file_set_string(config
, PACKAGE
, "context_action_cmd", tool_prefs
.context_action_cmd
);
482 build_save_menu(config
, NULL
, GEANY_BCS_PREF
);
485 g_key_file_set_string(config
, "printing", "print_cmd", printing_prefs
.external_print_cmd
? printing_prefs
.external_print_cmd
: "");
486 g_key_file_set_boolean(config
, "printing", "use_gtk_printing", printing_prefs
.use_gtk_printing
);
487 g_key_file_set_boolean(config
, "printing", "print_line_numbers", printing_prefs
.print_line_numbers
);
488 g_key_file_set_boolean(config
, "printing", "print_page_numbers", printing_prefs
.print_page_numbers
);
489 g_key_file_set_boolean(config
, "printing", "print_page_header", printing_prefs
.print_page_header
);
490 g_key_file_set_boolean(config
, "printing", "page_header_basename", printing_prefs
.page_header_basename
);
491 g_key_file_set_string(config
, "printing", "page_header_datefmt", printing_prefs
.page_header_datefmt
);
495 g_key_file_set_boolean(config
, "VTE", "load_vte", vte_info
.load_vte
);
496 if (vte_info
.have_vte
)
500 if (!g_key_file_has_key(config
, "VTE", "emulation", NULL
)) /* hidden */
501 g_key_file_set_string(config
, "VTE", "emulation", vc
->emulation
);
502 if (!g_key_file_has_key(config
, "VTE", "send_selection_unsafe", NULL
)) /* hidden */
503 g_key_file_set_boolean(config
, "VTE", "send_selection_unsafe",
504 vc
->send_selection_unsafe
);
505 if (!g_key_file_has_key(config
, "VTE", "send_cmd_prefix", NULL
)) /* hidden */
506 g_key_file_set_string(config
, "VTE", "send_cmd_prefix", vc
->send_cmd_prefix
);
507 g_key_file_set_string(config
, "VTE", "font", vc
->font
);
508 g_key_file_set_boolean(config
, "VTE", "scroll_on_key", vc
->scroll_on_key
);
509 g_key_file_set_boolean(config
, "VTE", "scroll_on_out", vc
->scroll_on_out
);
510 g_key_file_set_boolean(config
, "VTE", "enable_bash_keys", vc
->enable_bash_keys
);
511 g_key_file_set_boolean(config
, "VTE", "ignore_menu_bar_accel", vc
->ignore_menu_bar_accel
);
512 g_key_file_set_boolean(config
, "VTE", "follow_path", vc
->follow_path
);
513 g_key_file_set_boolean(config
, "VTE", "run_in_vte", vc
->run_in_vte
);
514 g_key_file_set_boolean(config
, "VTE", "skip_run_script", vc
->skip_run_script
);
515 g_key_file_set_boolean(config
, "VTE", "cursor_blinks", vc
->cursor_blinks
);
516 g_key_file_set_integer(config
, "VTE", "scrollback_lines", vc
->scrollback_lines
);
517 g_key_file_set_string(config
, "VTE", "font", vc
->font
);
518 g_key_file_set_string(config
, "VTE", "image", vc
->image
);
519 g_key_file_set_string(config
, "VTE", "shell", vc
->shell
);
520 tmp_string
= utils_get_hex_from_color(vc
->colour_fore
);
521 g_key_file_set_string(config
, "VTE", "colour_fore", tmp_string
);
523 tmp_string
= utils_get_hex_from_color(vc
->colour_back
);
524 g_key_file_set_string(config
, "VTE", "colour_back", tmp_string
);
531 static void save_ui_prefs(GKeyFile
*config
)
533 g_key_file_set_boolean(config
, PACKAGE
, "sidebar_visible", ui_prefs
.sidebar_visible
);
534 g_key_file_set_boolean(config
, PACKAGE
, "statusbar_visible", interface_prefs
.statusbar_visible
);
535 g_key_file_set_boolean(config
, PACKAGE
, "msgwindow_visible", ui_prefs
.msgwindow_visible
);
536 g_key_file_set_boolean(config
, PACKAGE
, "fullscreen", ui_prefs
.fullscreen
);
538 /* get the text from the scribble textview */
540 GtkTextBuffer
*buffer
;
541 GtkTextIter start
, end
, iter
;
544 buffer
= gtk_text_view_get_buffer(GTK_TEXT_VIEW(msgwindow
.scribble
));
545 gtk_text_buffer_get_bounds(buffer
, &start
, &end
);
546 scribble_text
= gtk_text_buffer_get_text(buffer
, &start
, &end
, FALSE
);
547 g_key_file_set_string(config
, PACKAGE
, "scribble_text", scribble_text
);
548 g_free(scribble_text
);
550 mark
= gtk_text_buffer_get_insert(buffer
);
551 gtk_text_buffer_get_iter_at_mark(buffer
, &iter
, mark
);
552 scribble_pos
= gtk_text_iter_get_offset(&iter
);
553 g_key_file_set_integer(config
, PACKAGE
, "scribble_pos", scribble_pos
);
556 if (prefs
.save_winpos
)
558 GdkWindowState wstate
;
560 g_key_file_set_integer(config
, PACKAGE
, "treeview_position",
561 gtk_paned_get_position(GTK_PANED(ui_lookup_widget(main_widgets
.window
, "hpaned1"))));
562 g_key_file_set_integer(config
, PACKAGE
, "msgwindow_position",
563 gtk_paned_get_position(GTK_PANED(ui_lookup_widget(main_widgets
.window
, "vpaned1"))));
565 gtk_window_get_position(GTK_WINDOW(main_widgets
.window
), &ui_prefs
.geometry
[0], &ui_prefs
.geometry
[1]);
566 gtk_window_get_size(GTK_WINDOW(main_widgets
.window
), &ui_prefs
.geometry
[2], &ui_prefs
.geometry
[3]);
567 wstate
= gdk_window_get_state(gtk_widget_get_window(main_widgets
.window
));
568 ui_prefs
.geometry
[4] = (wstate
& GDK_WINDOW_STATE_MAXIMIZED
) ? 1 : 0;
569 g_key_file_set_integer_list(config
, PACKAGE
, "geometry", ui_prefs
.geometry
, 5);
572 g_key_file_set_string(config
, PACKAGE
, "custom_date_format", ui_prefs
.custom_date_format
);
573 if (ui_prefs
.custom_commands
!= NULL
)
575 g_key_file_set_string_list(config
, PACKAGE
, "custom_commands",
576 (const gchar
**) ui_prefs
.custom_commands
, g_strv_length(ui_prefs
.custom_commands
));
577 g_key_file_set_string_list(config
, PACKAGE
, "custom_commands_labels",
578 (const gchar
**) ui_prefs
.custom_commands_labels
, g_strv_length(ui_prefs
.custom_commands_labels
));
583 void configuration_save(void)
585 GKeyFile
*config
= g_key_file_new();
586 gchar
*configfile
= g_build_filename(app
->configdir
, "geany.conf", NULL
);
589 g_key_file_load_from_file(config
, configfile
, G_KEY_FILE_NONE
, NULL
);
591 /* this signal can be used e.g. to prepare any settings before Stash code reads them below */
592 g_signal_emit_by_name(geany_object
, "save-settings", config
);
594 save_dialog_prefs(config
);
595 save_ui_prefs(config
);
596 project_save_prefs(config
); /* save project filename, etc. */
597 save_recent_files(config
, ui_prefs
.recent_queue
, "recent_files");
598 save_recent_files(config
, ui_prefs
.recent_projects_queue
, "recent_projects");
600 if (cl_options
.load_session
)
601 configuration_save_session_files(config
);
603 else if (vte_info
.have_vte
)
605 vte_get_working_directory(); /* refresh vte_info.dir */
606 g_key_file_set_string(config
, "VTE", "last_dir", vte_info
.dir
);
611 data
= g_key_file_to_data(config
, NULL
, NULL
);
612 utils_write_file(configfile
, data
);
615 g_key_file_free(config
);
620 static void load_recent_files(GKeyFile
*config
, GQueue
*queue
, const gchar
*key
)
622 gchar
**recent_files
;
625 recent_files
= g_key_file_get_string_list(config
, "files", key
, &len
, NULL
);
626 if (recent_files
!= NULL
)
628 for (i
= 0; (i
< len
) && (i
< file_prefs
.mru_length
); i
++)
630 gchar
*filename
= g_strdup(recent_files
[i
]);
631 g_queue_push_tail(queue
, filename
);
633 g_strfreev(recent_files
);
639 * Load session list from the given keyfile, and store it in the global
640 * session_files variable for later file loading
642 void configuration_load_session_files(GKeyFile
*config
, gboolean read_recent_files
)
645 gboolean have_session_files
;
648 GError
*error
= NULL
;
650 session_notebook_page
= utils_get_setting_integer(config
, "files", "current_page", -1);
652 if (read_recent_files
)
654 load_recent_files(config
, ui_prefs
.recent_queue
, "recent_files");
655 load_recent_files(config
, ui_prefs
.recent_projects_queue
, "recent_projects");
658 /* the project may load another list than the main setting */
659 if (session_files
!= NULL
)
660 g_ptr_array_free(session_files
, TRUE
);
662 session_files
= g_ptr_array_new();
663 have_session_files
= TRUE
;
665 while (have_session_files
)
667 g_snprintf(entry
, sizeof(entry
), "FILE_NAME_%d", i
);
668 tmp_array
= g_key_file_get_string_list(config
, "files", entry
, NULL
, &error
);
669 if (! tmp_array
|| error
)
673 have_session_files
= FALSE
;
675 g_ptr_array_add(session_files
, tmp_array
);
680 /* BUG: after loading project at startup, closing project doesn't restore old VTE path */
681 if (vte_info
.have_vte
)
683 gchar
*tmp_string
= utils_get_setting_string(config
, "VTE", "last_dir", NULL
);
684 vte_cwd(tmp_string
,TRUE
);
691 /* note: new settings should be added in init_pref_groups() */
692 static void load_dialog_prefs(GKeyFile
*config
)
694 gchar
*tmp_string
, *tmp_string2
;
695 const gchar
*default_charset
= NULL
;
698 /* compatibility with Geany 0.20 */
699 if (!g_key_file_has_key(config
, PACKAGE
, atomic_file_saving_key
, NULL
))
701 g_key_file_set_boolean(config
, PACKAGE
, atomic_file_saving_key
,
702 utils_get_setting_boolean(config
, PACKAGE
, "use_safe_file_saving", FALSE
));
705 /* compatibility with Geany 0.21 */
707 gboolean suppress_search_dialogs
= utils_get_setting_boolean(config
, PACKAGE
, "pref_main_suppress_search_dialogs", FALSE
);
709 if (!g_key_file_has_key(config
, "search", "pref_search_always_wrap", NULL
))
710 g_key_file_set_boolean(config
, "search", "pref_search_always_wrap", suppress_search_dialogs
);
712 if (!g_key_file_has_key(config
, "search", "pref_search_hide_find_dialog", NULL
))
713 g_key_file_set_boolean(config
, "search", "pref_search_hide_find_dialog", suppress_search_dialogs
);
716 /* read stash prefs */
717 settings_action(config
, SETTING_READ
);
720 prefs
.confirm_exit
= utils_get_setting_boolean(config
, PACKAGE
, "pref_main_confirm_exit", FALSE
);
721 prefs
.suppress_status_messages
= utils_get_setting_boolean(config
, PACKAGE
, "pref_main_suppress_status_messages", FALSE
);
722 prefs
.load_session
= utils_get_setting_boolean(config
, PACKAGE
, "pref_main_load_session", TRUE
);
723 project_prefs
.project_session
= utils_get_setting_boolean(config
, PACKAGE
, "pref_main_project_session", TRUE
);
724 project_prefs
.project_file_in_basedir
= utils_get_setting_boolean(config
, PACKAGE
, "pref_main_project_file_in_basedir", FALSE
);
725 prefs
.save_winpos
= utils_get_setting_boolean(config
, PACKAGE
, "pref_main_save_winpos", TRUE
);
726 prefs
.beep_on_errors
= utils_get_setting_boolean(config
, PACKAGE
, "beep_on_errors", TRUE
);
727 prefs
.switch_to_status
= utils_get_setting_boolean(config
, PACKAGE
, "switch_msgwin_pages", FALSE
);
728 prefs
.auto_focus
= utils_get_setting_boolean(config
, PACKAGE
, "auto_focus", FALSE
);
731 interface_prefs
.tab_pos_editor
= utils_get_setting_integer(config
, PACKAGE
, "tab_pos_editor", GTK_POS_TOP
);
732 interface_prefs
.tab_pos_msgwin
= utils_get_setting_integer(config
, PACKAGE
, "tab_pos_msgwin",GTK_POS_LEFT
);
733 interface_prefs
.sidebar_symbol_visible
= utils_get_setting_boolean(config
, PACKAGE
, "sidebar_symbol_visible", TRUE
);
734 interface_prefs
.sidebar_openfiles_visible
= utils_get_setting_boolean(config
, PACKAGE
, "sidebar_openfiles_visible", TRUE
);
735 interface_prefs
.statusbar_visible
= utils_get_setting_boolean(config
, PACKAGE
, "statusbar_visible", TRUE
);
736 file_prefs
.tab_order_ltr
= utils_get_setting_boolean(config
, PACKAGE
, "tab_order_ltr", TRUE
);
737 file_prefs
.tab_order_beside
= utils_get_setting_boolean(config
, PACKAGE
, "tab_order_beside", FALSE
);
738 interface_prefs
.show_notebook_tabs
= utils_get_setting_boolean(config
, PACKAGE
, "show_notebook_tabs", TRUE
);
739 file_prefs
.show_tab_cross
= utils_get_setting_boolean(config
, PACKAGE
, "show_tab_cross", TRUE
);
740 interface_prefs
.editor_font
= utils_get_setting_string(config
, PACKAGE
, "editor_font", GEANY_DEFAULT_FONT_EDITOR
);
741 interface_prefs
.tagbar_font
= utils_get_setting_string(config
, PACKAGE
, "tagbar_font", GEANY_DEFAULT_FONT_SYMBOL_LIST
);
742 interface_prefs
.msgwin_font
= utils_get_setting_string(config
, PACKAGE
, "msgwin_font", GEANY_DEFAULT_FONT_MSG_WINDOW
);
743 interface_prefs
.use_native_windows_dialogs
= utils_get_setting_boolean(config
, PACKAGE
, "use_native_windows_dialogs", FALSE
);
745 /* display, editor */
746 editor_prefs
.long_line_enabled
= utils_get_setting_boolean(config
, PACKAGE
, "long_line_enabled", TRUE
);
747 editor_prefs
.long_line_type
= utils_get_setting_integer(config
, PACKAGE
, "long_line_type", 0);
748 if (editor_prefs
.long_line_type
== 2) /* backward compatibility */
750 editor_prefs
.long_line_type
= 0;
751 editor_prefs
.long_line_enabled
= FALSE
;
753 editor_prefs
.long_line_color
= utils_get_setting_string(config
, PACKAGE
, "long_line_color", "#C2EBC2");
754 editor_prefs
.long_line_column
= utils_get_setting_integer(config
, PACKAGE
, "long_line_column", 72);
755 editor_prefs
.symbolcompletion_min_chars
= utils_get_setting_integer(config
, PACKAGE
, "symbolcompletion_min_chars", GEANY_MIN_SYMBOLLIST_CHARS
);
756 editor_prefs
.symbolcompletion_max_height
= utils_get_setting_integer(config
, PACKAGE
, "symbolcompletion_max_height", GEANY_MAX_SYMBOLLIST_HEIGHT
);
757 editor_prefs
.line_wrapping
= utils_get_setting_boolean(config
, PACKAGE
, "line_wrapping", FALSE
); /* default is off for better performance */
758 editor_prefs
.use_indicators
= utils_get_setting_boolean(config
, PACKAGE
, "use_indicators", TRUE
);
759 editor_prefs
.show_indent_guide
= utils_get_setting_boolean(config
, PACKAGE
, "show_indent_guide", FALSE
);
760 editor_prefs
.show_white_space
= utils_get_setting_boolean(config
, PACKAGE
, "show_white_space", FALSE
);
761 editor_prefs
.show_line_endings
= utils_get_setting_boolean(config
, PACKAGE
, "show_line_endings", FALSE
);
762 editor_prefs
.scroll_stop_at_last_line
= utils_get_setting_boolean(config
, PACKAGE
, "scroll_stop_at_last_line", TRUE
);
763 editor_prefs
.auto_close_xml_tags
= utils_get_setting_boolean(config
, PACKAGE
, "auto_close_xml_tags", TRUE
);
764 editor_prefs
.complete_snippets
= utils_get_setting_boolean(config
, PACKAGE
, "complete_snippets", TRUE
);
765 editor_prefs
.auto_complete_symbols
= utils_get_setting_boolean(config
, PACKAGE
, "auto_complete_symbols", TRUE
);
766 editor_prefs
.folding
= utils_get_setting_boolean(config
, PACKAGE
, "use_folding", TRUE
);
767 editor_prefs
.unfold_all_children
= utils_get_setting_boolean(config
, PACKAGE
, "unfold_all_children", FALSE
);
768 editor_prefs
.show_markers_margin
= utils_get_setting_boolean(config
, PACKAGE
, "show_markers_margin", TRUE
);
769 editor_prefs
.show_linenumber_margin
= utils_get_setting_boolean(config
, PACKAGE
, "show_linenumber_margin", TRUE
);
770 editor_prefs
.disable_dnd
= utils_get_setting_boolean(config
, PACKAGE
, "pref_editor_disable_dnd", FALSE
);
771 editor_prefs
.smart_home_key
= utils_get_setting_boolean(config
, PACKAGE
, "pref_editor_smart_home_key", TRUE
);
772 editor_prefs
.newline_strip
= utils_get_setting_boolean(config
, PACKAGE
, "pref_editor_newline_strip", FALSE
);
773 editor_prefs
.line_break_column
= utils_get_setting_integer(config
, PACKAGE
, "line_break_column", 72);
774 editor_prefs
.auto_continue_multiline
= utils_get_setting_boolean(config
, PACKAGE
, "auto_continue_multiline", TRUE
);
775 editor_prefs
.comment_toggle_mark
= utils_get_setting_string(config
, PACKAGE
, "comment_toggle_mark", GEANY_TOGGLE_MARK
);
776 editor_prefs
.autoclose_chars
= utils_get_setting_integer(config
, PACKAGE
, "autoclose_chars", 0);
779 * use current locale encoding as default for new files (should be UTF-8 in most cases) */
780 g_get_charset(&default_charset
);
781 tmp_string
= utils_get_setting_string(config
, PACKAGE
, "pref_editor_default_new_encoding",
785 const GeanyEncoding
*enc
= encodings_get_from_charset(tmp_string
);
787 file_prefs
.default_new_encoding
= enc
->idx
;
789 file_prefs
.default_new_encoding
= GEANY_ENCODING_UTF_8
;
793 tmp_string
= utils_get_setting_string(config
, PACKAGE
, "pref_editor_default_open_encoding",
797 const GeanyEncoding
*enc
= encodings_get_from_charset(tmp_string
);
799 file_prefs
.default_open_encoding
= enc
->idx
;
801 file_prefs
.default_open_encoding
= -1;
805 file_prefs
.default_eol_character
= utils_get_setting_integer(config
, PACKAGE
, "default_eol_character", GEANY_DEFAULT_EOL_CHARACTER
);
806 file_prefs
.replace_tabs
= utils_get_setting_boolean(config
, PACKAGE
, "pref_editor_replace_tabs", FALSE
);
807 file_prefs
.ensure_convert_new_lines
= utils_get_setting_boolean(config
, PACKAGE
, "pref_editor_ensure_convert_line_endings", FALSE
);
808 file_prefs
.final_new_line
= utils_get_setting_boolean(config
, PACKAGE
, "pref_editor_new_line", TRUE
);
809 file_prefs
.strip_trailing_spaces
= utils_get_setting_boolean(config
, PACKAGE
, "pref_editor_trail_space", FALSE
);
812 toolbar_prefs
.visible
= utils_get_setting_boolean(config
, PACKAGE
, "pref_toolbar_show", TRUE
);
813 toolbar_prefs
.append_to_menu
= utils_get_setting_boolean(config
, PACKAGE
, "pref_toolbar_append_to_menu", FALSE
);
815 toolbar_prefs
.use_gtk_default_style
= utils_get_setting_boolean(config
, PACKAGE
, "pref_toolbar_use_gtk_default_style", TRUE
);
816 if (! toolbar_prefs
.use_gtk_default_style
)
817 toolbar_prefs
.icon_style
= utils_get_setting_integer(config
, PACKAGE
, "pref_toolbar_icon_style", GTK_TOOLBAR_ICONS
);
819 toolbar_prefs
.use_gtk_default_icon
= utils_get_setting_boolean(config
, PACKAGE
, "pref_toolbar_use_gtk_default_icon", TRUE
);
820 if (! toolbar_prefs
.use_gtk_default_icon
)
821 toolbar_prefs
.icon_size
= utils_get_setting_integer(config
, PACKAGE
, "pref_toolbar_icon_size", GTK_ICON_SIZE_LARGE_TOOLBAR
);
826 vte_info
.load_vte
= utils_get_setting_boolean(config
, "VTE", "load_vte", TRUE
);
827 if (vte_info
.load_vte
)
829 struct passwd
*pw
= getpwuid(getuid());
830 const gchar
*shell
= (pw
!= NULL
) ? pw
->pw_shell
: "/bin/sh";
832 vc
= g_new0(VteConfig
, 1);
833 vte_info
.dir
= utils_get_setting_string(config
, "VTE", "last_dir", NULL
);
834 if ((vte_info
.dir
== NULL
|| utils_str_equal(vte_info
.dir
, "")) && pw
!= NULL
)
835 /* last dir is not set, fallback to user's home directory */
836 vte_info
.dir
= g_strdup(pw
->pw_dir
);
837 else if (vte_info
.dir
== NULL
&& pw
== NULL
)
838 /* fallback to root */
839 vte_info
.dir
= g_strdup("/");
841 vc
->emulation
= utils_get_setting_string(config
, "VTE", "emulation", "xterm");
842 vc
->send_selection_unsafe
= utils_get_setting_boolean(config
, "VTE",
843 "send_selection_unsafe", FALSE
);
844 vc
->image
= utils_get_setting_string(config
, "VTE", "image", "");
845 vc
->shell
= utils_get_setting_string(config
, "VTE", "shell", shell
);
846 vc
->font
= utils_get_setting_string(config
, "VTE", "font", "Monospace 10");
847 vc
->scroll_on_key
= utils_get_setting_boolean(config
, "VTE", "scroll_on_key", TRUE
);
848 vc
->scroll_on_out
= utils_get_setting_boolean(config
, "VTE", "scroll_on_out", TRUE
);
849 vc
->enable_bash_keys
= utils_get_setting_boolean(config
, "VTE", "enable_bash_keys", TRUE
);
850 vc
->ignore_menu_bar_accel
= utils_get_setting_boolean(config
, "VTE", "ignore_menu_bar_accel", FALSE
);
851 vc
->follow_path
= utils_get_setting_boolean(config
, "VTE", "follow_path", FALSE
);
852 vc
->send_cmd_prefix
= utils_get_setting_string(config
, "VTE", "send_cmd_prefix", "");
853 vc
->run_in_vte
= utils_get_setting_boolean(config
, "VTE", "run_in_vte", FALSE
);
854 vc
->skip_run_script
= utils_get_setting_boolean(config
, "VTE", "skip_run_script", FALSE
);
855 vc
->cursor_blinks
= utils_get_setting_boolean(config
, "VTE", "cursor_blinks", FALSE
);
856 vc
->scrollback_lines
= utils_get_setting_integer(config
, "VTE", "scrollback_lines", 500);
857 vc
->colour_fore
= g_new0(GdkColor
, 1);
858 vc
->colour_back
= g_new0(GdkColor
, 1);
859 tmp_string
= utils_get_setting_string(config
, "VTE", "colour_fore", "#ffffff");
860 gdk_color_parse(tmp_string
, vc
->colour_fore
);
862 tmp_string
= utils_get_setting_string(config
, "VTE", "colour_back", "#000000");
863 gdk_color_parse(tmp_string
, vc
->colour_back
);
868 template_prefs
.developer
= utils_get_setting_string(config
, PACKAGE
, "pref_template_developer", g_get_real_name());
869 template_prefs
.company
= utils_get_setting_string(config
, PACKAGE
, "pref_template_company", "");
870 tmp_string
= utils_get_initials(template_prefs
.developer
);
871 template_prefs
.initials
= utils_get_setting_string(config
, PACKAGE
, "pref_template_initial", tmp_string
);
874 template_prefs
.version
= utils_get_setting_string(config
, PACKAGE
, "pref_template_version", "1.0");
876 tmp_string
= g_strdup_printf("%s@%s", g_get_user_name(), g_get_host_name());
877 template_prefs
.mail
= utils_get_setting_string(config
, PACKAGE
, "pref_template_mail", tmp_string
);
879 template_prefs
.year_format
= utils_get_setting_string(config
, PACKAGE
, "pref_template_year", GEANY_TEMPLATES_FORMAT_YEAR
);
880 template_prefs
.date_format
= utils_get_setting_string(config
, PACKAGE
, "pref_template_date", GEANY_TEMPLATES_FORMAT_DATE
);
881 template_prefs
.datetime_format
= utils_get_setting_string(config
, PACKAGE
, "pref_template_datetime", GEANY_TEMPLATES_FORMAT_DATETIME
);
884 cmd
= utils_get_setting_string(config
, "tools", "terminal_cmd", "");
887 cmd
= utils_get_setting_string(config
, "tools", "term_cmd", "");
892 if (strstr(cmd
, "cmd.exe"))
893 cmd
= g_strconcat(cmd
, " /Q /C %c", NULL
);
895 cmd
= g_strconcat(cmd
, " %c", NULL
);
897 cmd
= g_strconcat(cmd
, " -e \"/bin/sh %c\"", NULL
);
902 cmd
= g_strdup(GEANY_DEFAULT_TOOLS_TERMINAL
);
904 tool_prefs
.term_cmd
= cmd
;
905 tool_prefs
.browser_cmd
= utils_get_setting_string(config
, "tools", "browser_cmd", GEANY_DEFAULT_TOOLS_BROWSER
);
906 tool_prefs
.grep_cmd
= utils_get_setting_string(config
, "tools", "grep_cmd", GEANY_DEFAULT_TOOLS_GREP
);
908 tool_prefs
.context_action_cmd
= utils_get_setting_string(config
, PACKAGE
, "context_action_cmd", "");
911 build_set_group_count(GEANY_GBG_FT
, build_menu_prefs
.number_ft_menu_items
);
912 build_set_group_count(GEANY_GBG_NON_FT
, build_menu_prefs
.number_non_ft_menu_items
);
913 build_set_group_count(GEANY_GBG_EXEC
, build_menu_prefs
.number_exec_menu_items
);
914 build_load_menu(config
, GEANY_BCS_PREF
, NULL
);
917 tmp_string2
= g_find_program_in_path(GEANY_DEFAULT_TOOLS_PRINTCMD
);
919 if (!EMPTY(tmp_string2
))
921 /* single quote paths on Win32 for g_spawn_command_line_async */
922 tmp_string
= g_strconcat("'", tmp_string2
, "' '%f'", NULL
);
926 tmp_string
= g_strdup("");
929 tmp_string
= g_strconcat(tmp_string2
, " %f", NULL
);
931 printing_prefs
.external_print_cmd
= utils_get_setting_string(config
, "printing", "print_cmd", tmp_string
);
935 printing_prefs
.use_gtk_printing
= utils_get_setting_boolean(config
, "printing", "use_gtk_printing", TRUE
);
936 printing_prefs
.print_line_numbers
= utils_get_setting_boolean(config
, "printing", "print_line_numbers", TRUE
);
937 printing_prefs
.print_page_numbers
= utils_get_setting_boolean(config
, "printing", "print_page_numbers", TRUE
);
938 printing_prefs
.print_page_header
= utils_get_setting_boolean(config
, "printing", "print_page_header", TRUE
);
939 printing_prefs
.page_header_basename
= utils_get_setting_boolean(config
, "printing", "page_header_basename", FALSE
);
940 printing_prefs
.page_header_datefmt
= utils_get_setting_string(config
, "printing", "page_header_datefmt", "%c");
944 static void load_ui_prefs(GKeyFile
*config
)
949 ui_prefs
.sidebar_visible
= utils_get_setting_boolean(config
, PACKAGE
, "sidebar_visible", TRUE
);
950 ui_prefs
.msgwindow_visible
= utils_get_setting_boolean(config
, PACKAGE
, "msgwindow_visible", TRUE
);
951 ui_prefs
.fullscreen
= utils_get_setting_boolean(config
, PACKAGE
, "fullscreen", FALSE
);
952 ui_prefs
.custom_date_format
= utils_get_setting_string(config
, PACKAGE
, "custom_date_format", "");
953 ui_prefs
.custom_commands
= g_key_file_get_string_list(config
, PACKAGE
, "custom_commands", NULL
, NULL
);
954 ui_prefs
.custom_commands_labels
= g_key_file_get_string_list(config
, PACKAGE
, "custom_commands_labels", NULL
, NULL
);
956 /* sanitize custom commands labels */
957 if (ui_prefs
.custom_commands
|| ui_prefs
.custom_commands_labels
)
960 guint cc_len
= ui_prefs
.custom_commands
? g_strv_length(ui_prefs
.custom_commands
) : 0;
961 guint cc_labels_len
= ui_prefs
.custom_commands_labels
? g_strv_length(ui_prefs
.custom_commands_labels
) : 0;
963 /* not enough items, resize and fill */
964 if (cc_labels_len
< cc_len
)
966 ui_prefs
.custom_commands_labels
= g_realloc(ui_prefs
.custom_commands_labels
,
967 (cc_len
+ 1) * sizeof *ui_prefs
.custom_commands_labels
);
968 for (i
= cc_labels_len
; i
< cc_len
; i
++)
969 ui_prefs
.custom_commands_labels
[i
] = g_strdup("");
970 ui_prefs
.custom_commands_labels
[cc_len
] = NULL
;
972 /* too many items, cut off */
973 else if (cc_labels_len
> cc_len
)
975 for (i
= cc_len
; i
< cc_labels_len
; i
++)
977 g_free(ui_prefs
.custom_commands_labels
[i
]);
978 ui_prefs
.custom_commands_labels
[i
] = NULL
;
983 scribble_text
= utils_get_setting_string(config
, PACKAGE
, "scribble_text",
984 _("Type here what you want, use it as a notice/scratch board"));
985 scribble_pos
= utils_get_setting_integer(config
, PACKAGE
, "scribble_pos", -1);
987 geo
= g_key_file_get_integer_list(config
, PACKAGE
, "geometry", &geo_len
, NULL
);
988 if (! geo
|| geo_len
< 5)
990 ui_prefs
.geometry
[0] = -1;
991 ui_prefs
.geometry
[1] = -1;
992 ui_prefs
.geometry
[2] = -1;
993 ui_prefs
.geometry
[3] = -1;
994 ui_prefs
.geometry
[4] = 0;
998 /* don't use insane values but when main windows was maximized last time, pos might be
999 * negative (due to differences in root window and window decorations) */
1000 /* quitting when minimized can make pos -32000, -32000 on Windows! */
1001 ui_prefs
.geometry
[0] = MAX(-1, geo
[0]);
1002 ui_prefs
.geometry
[1] = MAX(-1, geo
[1]);
1003 ui_prefs
.geometry
[2] = MAX(-1, geo
[2]);
1004 ui_prefs
.geometry
[3] = MAX(-1, geo
[3]);
1005 ui_prefs
.geometry
[4] = geo
[4] != 0;
1007 hpan_position
= utils_get_setting_integer(config
, PACKAGE
, "treeview_position", 156);
1008 vpan_position
= utils_get_setting_integer(config
, PACKAGE
, "msgwindow_position", (geo
) ?
1009 (GEANY_MSGWIN_HEIGHT
+ geo
[3] - 440) :
1010 (GEANY_MSGWIN_HEIGHT
+ GEANY_WINDOW_DEFAULT_HEIGHT
- 440));
1017 * Save current session in default configuration file
1019 void configuration_save_default_session(void)
1021 gchar
*configfile
= g_build_filename(app
->configdir
, "geany.conf", NULL
);
1023 GKeyFile
*config
= g_key_file_new();
1025 g_key_file_load_from_file(config
, configfile
, G_KEY_FILE_NONE
, NULL
);
1027 if (cl_options
.load_session
)
1028 configuration_save_session_files(config
);
1030 /* write the file */
1031 data
= g_key_file_to_data(config
, NULL
, NULL
);
1032 utils_write_file(configfile
, data
);
1035 g_key_file_free(config
);
1041 * Only reload the session part of the default configuration
1043 void configuration_reload_default_session(void)
1045 gchar
*configfile
= g_build_filename(app
->configdir
, "geany.conf", NULL
);
1046 GKeyFile
*config
= g_key_file_new();
1048 g_key_file_load_from_file(config
, configfile
, G_KEY_FILE_NONE
, NULL
);
1051 configuration_load_session_files(config
, FALSE
);
1053 g_key_file_free(config
);
1057 gboolean
configuration_load(void)
1059 gchar
*configfile
= g_build_filename(app
->configdir
, "geany.conf", NULL
);
1060 GKeyFile
*config
= g_key_file_new();
1062 if (! g_file_test(configfile
, G_FILE_TEST_IS_REGULAR
))
1063 { /* config file does not (yet) exist, so try to load a global config file which may be */
1064 /* created by distributors */
1065 geany_debug("No user config file found, trying to use global configuration.");
1066 SETPTR(configfile
, g_build_filename(app
->datadir
, "geany.conf", NULL
));
1068 g_key_file_load_from_file(config
, configfile
, G_KEY_FILE_NONE
, NULL
);
1071 load_dialog_prefs(config
);
1072 load_ui_prefs(config
);
1073 project_load_prefs(config
);
1074 configuration_load_session_files(config
, TRUE
);
1076 /* this signal can be used e.g. to delay building UI elements until settings have been read */
1077 g_signal_emit_by_name(geany_object
, "load-settings", config
);
1079 g_key_file_free(config
);
1084 static gboolean
open_session_file(gchar
**tmp
, guint len
)
1087 const gchar
*ft_name
;
1088 gchar
*locale_filename
;
1089 gchar
*unescaped_filename
;
1090 const gchar
*encoding
;
1092 gboolean ro
, auto_indent
, line_wrapping
;
1093 /** TODO when we have a global pref for line breaking, use its value */
1094 gboolean line_breaking
= FALSE
;
1095 gboolean ret
= FALSE
;
1100 if (isdigit(tmp
[3][0]))
1102 encoding
= encodings_get_charset_from_index(atoi(tmp
[3]));
1106 encoding
= &(tmp
[3][1]);
1108 indent_type
= atoi(tmp
[4]);
1109 auto_indent
= atoi(tmp
[5]);
1110 line_wrapping
= atoi(tmp
[6]);
1111 /* try to get the locale equivalent for the filename */
1112 unescaped_filename
= g_uri_unescape_string(tmp
[7], NULL
);
1113 locale_filename
= utils_get_locale_from_utf8(unescaped_filename
);
1116 line_breaking
= atoi(tmp
[8]);
1118 if (g_file_test(locale_filename
, G_FILE_TEST_IS_REGULAR
))
1120 GeanyFiletype
*ft
= filetypes_lookup_by_name(ft_name
);
1121 GeanyDocument
*doc
= document_open_file_full(
1122 NULL
, locale_filename
, pos
, ro
, ft
, encoding
);
1126 gint indent_width
= doc
->editor
->indent_width
;
1129 indent_width
= atoi(tmp
[9]);
1130 editor_set_indent(doc
->editor
, indent_type
, indent_width
);
1131 editor_set_line_wrapping(doc
->editor
, line_wrapping
);
1132 doc
->editor
->line_breaking
= line_breaking
;
1133 doc
->editor
->auto_indent
= auto_indent
;
1139 geany_debug("Could not find file '%s'.", tmp
[7]);
1142 g_free(locale_filename
);
1143 g_free(unescaped_filename
);
1148 /* Open session files
1149 * Note: notebook page switch handler and adding to recent files list is always disabled
1150 * for all files opened within this function */
1151 void configuration_open_files(void)
1154 gboolean failure
= FALSE
;
1156 /* necessary to set it to TRUE for project session support */
1157 main_status
.opening_session_files
= TRUE
;
1159 i
= file_prefs
.tab_order_ltr
? 0 : (session_files
->len
- 1);
1162 gchar
**tmp
= g_ptr_array_index(session_files
, i
);
1165 if (tmp
!= NULL
&& (len
= g_strv_length(tmp
)) >= 8)
1167 if (! open_session_file(tmp
, len
))
1172 if (file_prefs
.tab_order_ltr
)
1175 if (i
>= (gint
)session_files
->len
)
1186 g_ptr_array_free(session_files
, TRUE
);
1187 session_files
= NULL
;
1190 ui_set_statusbar(TRUE
, _("Failed to load one or more session files."));
1191 else if (session_notebook_page
>= 0)
1193 /* explicitly allow notebook switch page callback to be called for window title,
1194 * encoding settings and so other things */
1195 main_status
.opening_session_files
= FALSE
;
1196 /** TODO if session_notebook_page is equal to the current notebook tab(the last opened)
1197 ** the notebook switch page callback isn't triggered and e.g. menu items are not updated */
1198 gtk_notebook_set_current_page(GTK_NOTEBOOK(main_widgets
.notebook
), session_notebook_page
);
1200 main_status
.opening_session_files
= FALSE
;
1204 /* set some settings which are already read from the config file, but need other things, like the
1205 * realisation of the main window */
1206 void configuration_apply_settings(void)
1209 { /* update the scribble widget, because now it's realized */
1211 GtkTextBuffer
*buffer
=
1212 gtk_text_view_get_buffer(GTK_TEXT_VIEW(msgwindow
.scribble
));
1214 gtk_text_buffer_set_text(buffer
, scribble_text
, -1);
1215 gtk_text_buffer_get_iter_at_offset(buffer
, &iter
, scribble_pos
);
1216 gtk_text_buffer_place_cursor(buffer
, &iter
);
1218 g_free(scribble_text
);
1220 /* set the position of the hpaned and vpaned */
1221 if (prefs
.save_winpos
)
1223 gtk_paned_set_position(GTK_PANED(ui_lookup_widget(main_widgets
.window
, "hpaned1")), hpan_position
);
1224 gtk_paned_set_position(GTK_PANED(ui_lookup_widget(main_widgets
.window
, "vpaned1")), vpan_position
);
1227 /* set fullscreen after initial draw so that returning to normal view is the right size.
1228 * fullscreen mode is disabled by default, so act only if it is true */
1229 if (ui_prefs
.fullscreen
)
1231 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ui_lookup_widget(main_widgets
.window
, "menu_fullscreen1")), TRUE
);
1232 ui_prefs
.fullscreen
= TRUE
;
1233 ui_set_fullscreen();
1236 msgwin_show_hide_tabs();
1240 void configuration_init(void)
1242 keyfile_groups
= g_ptr_array_new();
1243 pref_groups
= g_ptr_array_new();
1248 void configuration_finalize(void)
1253 foreach_ptr_array(group
, i
, keyfile_groups
)
1254 stash_group_free(group
);
1256 g_ptr_array_free(keyfile_groups
, TRUE
);
1257 g_ptr_array_free(pref_groups
, TRUE
);