2 * keyfile.c - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2005-2011 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5 * Copyright 2006-2011 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
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 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;encoding idx;use_tabs;auto_indent;line_wrapping;filename
38 #include <sys/types.h>
48 #include "filetypes.h"
49 #include "sciwrappers.h"
50 #include "encodings.h"
53 #include "msgwindow.h"
58 #include "templates.h"
63 /* some default settings which are used at the very first start of Geany to fill
64 * the configuration file */
65 #define GEANY_MAX_SYMBOLLIST_HEIGHT 10
66 #define GEANY_MIN_SYMBOLLIST_CHARS 4
67 #define GEANY_MSGWIN_HEIGHT 208
68 #define GEANY_DISK_CHECK_TIMEOUT 30
69 #define GEANY_DEFAULT_TOOLS_MAKE "make"
71 #define GEANY_DEFAULT_TOOLS_TERMINAL "cmd.exe"
73 #define GEANY_DEFAULT_TOOLS_TERMINAL "xterm"
75 #define GEANY_DEFAULT_TOOLS_BROWSER "firefox"
76 #define GEANY_DEFAULT_TOOLS_PRINTCMD "lpr"
77 #define GEANY_DEFAULT_TOOLS_GREP "grep"
78 #define GEANY_DEFAULT_MRU_LENGTH 10
79 #define GEANY_DEFAULT_FONT_SYMBOL_LIST "Sans 9"
80 #define GEANY_DEFAULT_FONT_MSG_WINDOW "Sans 9"
81 #define GEANY_DEFAULT_FONT_EDITOR "Monospace 10"
82 #define GEANY_TOGGLE_MARK "~ "
83 #define GEANY_MAX_AUTOCOMPLETE_WORDS 30
84 #define GEANY_MAX_SYMBOLS_UPDATE_FREQ 250
87 static gchar
*scribble_text
= NULL
;
88 static gint scribble_pos
= -1;
89 static GPtrArray
*session_files
= NULL
;
90 static gint session_notebook_page
;
91 static gint hpan_position
;
92 static gint vpan_position
;
93 static const gchar atomic_file_saving_key
[] = "use_atomic_file_saving";
95 static GPtrArray
*keyfile_groups
= NULL
;
97 GPtrArray
*pref_groups
= NULL
;
101 int number_ft_menu_items
;
102 int number_non_ft_menu_items
;
103 int number_exec_menu_items
;
108 /* The group will be free'd on quitting.
109 * @param for_prefs_dialog is whether the group also has Prefs dialog items. */
110 void configuration_add_pref_group(struct StashGroup
*group
, gboolean for_prefs_dialog
)
112 g_ptr_array_add(keyfile_groups
, group
);
114 if (for_prefs_dialog
)
115 g_ptr_array_add(pref_groups
, group
);
119 /* The group will be free'd on quitting. */
120 void configuration_add_various_pref_group(struct StashGroup
*group
)
122 configuration_add_pref_group(group
, TRUE
);
123 stash_group_set_various(group
, TRUE
);
127 static void init_pref_groups(void)
131 group
= stash_group_new(PACKAGE
);
132 configuration_add_pref_group(group
, TRUE
);
133 stash_group_add_entry(group
, &prefs
.default_open_path
,
134 "default_open_path", "", "startup_path_entry");
136 stash_group_add_toggle_button(group
, &file_prefs
.cmdline_new_files
,
137 "cmdline_new_files", TRUE
, "check_cmdline_new_files");
139 stash_group_add_toggle_button(group
, &interface_prefs
.notebook_double_click_hides_widgets
,
140 "notebook_double_click_hides_widgets", FALSE
, "check_double_click_hides_widgets");
141 stash_group_add_integer(group
, &interface_prefs
.tab_pos_sidebar
, "tab_pos_sidebar", GTK_POS_TOP
);
142 stash_group_add_radio_buttons(group
, &interface_prefs
.sidebar_pos
,
143 "sidebar_pos", GTK_POS_LEFT
,
144 "radio_sidebar_left", GTK_POS_LEFT
,
145 "radio_sidebar_right", GTK_POS_RIGHT
,
149 stash_group_add_toggle_button(group
, &interface_prefs
.highlighting_invert_all
,
150 "highlighting_invert_all", FALSE
, "check_highlighting_invert");
152 stash_group_add_toggle_button(group
, &search_prefs
.suppress_dialogs
,
153 "pref_main_suppress_search_dialogs", FALSE
, "check_ask_suppress_search_dialogs");
154 stash_group_add_toggle_button(group
, &search_prefs
.use_current_word
,
155 "pref_main_search_use_current_word", TRUE
, "check_search_use_current_word");
158 stash_group_add_toggle_button(group
, &editor_prefs
.indentation
->detect_type
,
159 "check_detect_indent", FALSE
, "check_detect_indent_type");
160 stash_group_add_toggle_button(group
, &editor_prefs
.indentation
->detect_width
,
161 "detect_indent_width", FALSE
, "check_detect_indent_width");
162 stash_group_add_toggle_button(group
, &editor_prefs
.use_tab_to_indent
,
163 "use_tab_to_indent", TRUE
, "check_tab_key_indents");
164 stash_group_add_spin_button_integer(group
, &editor_prefs
.indentation
->width
,
165 "pref_editor_tab_width", 4, "spin_indent_width");
166 stash_group_add_combo_box(group
, (gint
*)(void*)&editor_prefs
.indentation
->auto_indent_mode
,
167 "indent_mode", GEANY_AUTOINDENT_CURRENTCHARS
, "combo_auto_indent_mode");
168 stash_group_add_radio_buttons(group
, (gint
*)(void*)&editor_prefs
.indentation
->type
,
169 "indent_type", GEANY_INDENT_TYPE_TABS
,
170 "radio_indent_spaces", GEANY_INDENT_TYPE_SPACES
,
171 "radio_indent_tabs", GEANY_INDENT_TYPE_TABS
,
172 "radio_indent_both", GEANY_INDENT_TYPE_BOTH
,
174 stash_group_add_radio_buttons(group
, (gint
*)(void*)&editor_prefs
.show_virtual_space
,
175 "virtualspace", GEANY_VIRTUAL_SPACE_SELECTION
,
176 "radio_virtualspace_disabled", GEANY_VIRTUAL_SPACE_DISABLED
,
177 "radio_virtualspace_selection", GEANY_VIRTUAL_SPACE_SELECTION
,
178 "radio_virtualspace_always", GEANY_VIRTUAL_SPACE_ALWAYS
,
180 stash_group_add_toggle_button(group
, &editor_prefs
.autocomplete_doc_words
,
181 "autocomplete_doc_words", FALSE
, "check_autocomplete_doc_words");
182 stash_group_add_toggle_button(group
, &editor_prefs
.completion_drops_rest_of_word
,
183 "completion_drops_rest_of_word", FALSE
, "check_completion_drops_rest_of_word");
184 stash_group_add_spin_button_integer(group
, (gint
*)&editor_prefs
.autocompletion_max_entries
,
185 "autocompletion_max_entries", GEANY_MAX_AUTOCOMPLETE_WORDS
,
186 "spin_autocompletion_max_entries");
187 stash_group_add_spin_button_integer(group
, (gint
*)&editor_prefs
.autocompletion_update_freq
,
188 "autocompletion_update_freq", GEANY_MAX_SYMBOLS_UPDATE_FREQ
, "spin_symbol_update_freq");
189 stash_group_add_string(group
, &editor_prefs
.color_scheme
,
190 "color_scheme", NULL
);
193 stash_group_add_spin_button_integer(group
, (gint
*)&file_prefs
.mru_length
,
194 "mru_length", GEANY_DEFAULT_MRU_LENGTH
, "spin_mru");
195 stash_group_add_spin_button_integer(group
, &file_prefs
.disk_check_timeout
,
196 "disk_check_timeout", GEANY_DISK_CHECK_TIMEOUT
, "spin_disk_check");
198 /* various geany prefs */
199 group
= stash_group_new(PACKAGE
);
200 configuration_add_various_pref_group(group
);
202 stash_group_add_boolean(group
, &editor_prefs
.show_scrollbars
,
203 "show_editor_scrollbars", TRUE
);
204 stash_group_add_boolean(group
, &editor_prefs
.brace_match_ltgt
,
205 "brace_match_ltgt", FALSE
);
206 stash_group_add_boolean(group
, &editor_prefs
.use_gtk_word_boundaries
,
207 "use_gtk_word_boundaries", TRUE
);
208 stash_group_add_boolean(group
, &editor_prefs
.complete_snippets_whilst_editing
,
209 "complete_snippets_whilst_editing", FALSE
);
210 stash_group_add_boolean(group
, &file_prefs
.use_safe_file_saving
,
211 atomic_file_saving_key
, FALSE
);
212 stash_group_add_boolean(group
, &file_prefs
.gio_unsafe_save_backup
,
213 "gio_unsafe_save_backup", FALSE
);
214 stash_group_add_boolean(group
, &file_prefs
.use_gio_unsafe_file_saving
,
215 "use_gio_unsafe_file_saving", TRUE
);
216 /* for backwards-compatibility */
217 stash_group_add_integer(group
, &editor_prefs
.indentation
->hard_tab_width
,
218 "indent_hard_tab_width", 8);
219 stash_group_add_integer(group
, (gint
*)&search_prefs
.find_selection_type
,
220 "find_selection_type", GEANY_FIND_SEL_CURRENT_WORD
);
222 /* Note: Interface-related various prefs are in ui_init_prefs() */
224 /* various build-menu prefs */
225 group
= stash_group_new("build-menu");
226 configuration_add_various_pref_group(group
);
228 stash_group_add_integer(group
, &build_menu_prefs
.number_ft_menu_items
,
229 "number_ft_menu_items", 0);
230 stash_group_add_integer(group
, &build_menu_prefs
.number_non_ft_menu_items
,
231 "number_non_ft_menu_items", 0);
232 stash_group_add_integer(group
, &build_menu_prefs
.number_exec_menu_items
,
233 "number_exec_menu_items", 0);
237 typedef enum SettingAction
244 static void settings_action(GKeyFile
*config
, SettingAction action
)
249 foreach_ptr_array(group
, i
, keyfile_groups
)
254 stash_group_load_from_key_file(group
, config
); break;
256 stash_group_save_to_key_file(group
, config
); break;
262 static void save_recent_files(GKeyFile
*config
, GQueue
*queue
, gchar
const *key
)
264 gchar
**recent_files
= g_new0(gchar
*, file_prefs
.mru_length
+ 1);
267 for (i
= 0; i
< file_prefs
.mru_length
; i
++)
269 if (! g_queue_is_empty(queue
))
271 /* copy the values, this is necessary when this function is called from the
272 * preferences dialog or when quitting is canceled to keep the queue intact */
273 recent_files
[i
] = g_strdup(g_queue_peek_nth(queue
, i
));
277 recent_files
[i
] = NULL
;
281 /* There is a bug in GTK 2.6 g_key_file_set_string_list, we must NULL terminate. */
282 recent_files
[file_prefs
.mru_length
] = NULL
;
283 g_key_file_set_string_list(config
, "files", key
,
284 (const gchar
**)recent_files
, file_prefs
.mru_length
);
285 g_strfreev(recent_files
);
289 static gchar
*get_session_file_string(GeanyDocument
*doc
)
292 gchar
*locale_filename
;
293 GeanyFiletype
*ft
= doc
->file_type
;
295 if (ft
== NULL
) /* can happen when saving a new file when quitting */
296 ft
= filetypes
[GEANY_FILETYPES_NONE
];
298 locale_filename
= utils_get_locale_from_utf8(doc
->file_name
);
299 /* If the filename contains any ';' (semi-colons) we need to escape them otherwise
300 * g_key_file_get_string_list() would fail reading them, so we replace them before
301 * writing with usual colons which must never appear in a filename and replace them
302 * back when we read the file again from the file.
303 * (g_path_skip_root() to skip C:\... on Windows) */
304 g_strdelimit((gchar
*) utils_path_skip_root(locale_filename
), ";", ':');
306 fname
= g_strdup_printf("%d;%s;%d;%d;%d;%d;%d;%s;%d;%d",
307 sci_get_current_position(doc
->editor
->sci
),
310 encodings_get_idx_from_charset(doc
->encoding
),
311 doc
->editor
->indent_type
,
312 doc
->editor
->auto_indent
,
313 doc
->editor
->line_wrapping
,
315 doc
->editor
->line_breaking
,
316 doc
->editor
->indent_width
);
317 g_free(locale_filename
);
322 void configuration_save_session_files(GKeyFile
*config
)
327 guint i
= 0, j
= 0, max
;
330 npage
= gtk_notebook_get_current_page(GTK_NOTEBOOK(main_widgets
.notebook
));
331 g_key_file_set_integer(config
, "files", "current_page", npage
);
333 /* store the filenames to reopen them the next time */
334 max
= gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets
.notebook
));
335 for (i
= 0; i
< max
; i
++)
337 doc
= document_get_from_page(i
);
338 if (doc
!= NULL
&& doc
->real_path
!= NULL
)
342 g_snprintf(entry
, sizeof(entry
), "FILE_NAME_%d", j
);
343 fname
= get_session_file_string(doc
);
344 g_key_file_set_string(config
, "files", entry
, fname
);
349 /* if open filenames less than saved session files, delete existing entries in the list */
353 g_snprintf(entry
, sizeof(entry
), "FILE_NAME_%d", i
);
354 tmp
= g_key_file_get_string(config
, "files", entry
, NULL
);
355 if (G_UNLIKELY(tmp
== NULL
))
361 g_key_file_remove_key(config
, "files", entry
, NULL
);
368 if (vte_info
.have_vte
)
370 vte_get_working_directory(); /* refresh vte_info.dir */
371 g_key_file_set_string(config
, "VTE", "last_dir", vte_info
.dir
);
377 static void save_dialog_prefs(GKeyFile
*config
)
379 /* new settings should be added in init_pref_groups() */
380 settings_action(config
, SETTING_WRITE
);
382 /* Some of the key names are not consistent, but this is for backwards compatibility */
385 g_key_file_set_boolean(config
, PACKAGE
, "pref_main_load_session", prefs
.load_session
);
386 g_key_file_set_boolean(config
, PACKAGE
, "pref_main_project_session", project_prefs
.project_session
);
387 g_key_file_set_boolean(config
, PACKAGE
, "pref_main_project_file_in_basedir", project_prefs
.project_file_in_basedir
);
388 g_key_file_set_boolean(config
, PACKAGE
, "pref_main_save_winpos", prefs
.save_winpos
);
389 g_key_file_set_boolean(config
, PACKAGE
, "pref_main_confirm_exit", prefs
.confirm_exit
);
390 g_key_file_set_boolean(config
, PACKAGE
, "pref_main_suppress_status_messages", prefs
.suppress_status_messages
);
391 g_key_file_set_boolean(config
, PACKAGE
, "switch_msgwin_pages", prefs
.switch_to_status
);
392 g_key_file_set_boolean(config
, PACKAGE
, "beep_on_errors", prefs
.beep_on_errors
);
393 g_key_file_set_boolean(config
, PACKAGE
, "auto_focus", prefs
.auto_focus
);
396 g_key_file_set_boolean(config
, PACKAGE
, "sidebar_symbol_visible", interface_prefs
.sidebar_symbol_visible
);
397 g_key_file_set_boolean(config
, PACKAGE
, "sidebar_openfiles_visible", interface_prefs
.sidebar_openfiles_visible
);
398 g_key_file_set_string(config
, PACKAGE
, "editor_font", interface_prefs
.editor_font
);
399 g_key_file_set_string(config
, PACKAGE
, "tagbar_font", interface_prefs
.tagbar_font
);
400 g_key_file_set_string(config
, PACKAGE
, "msgwin_font", interface_prefs
.msgwin_font
);
401 g_key_file_set_boolean(config
, PACKAGE
, "show_notebook_tabs", interface_prefs
.show_notebook_tabs
);
402 g_key_file_set_boolean(config
, PACKAGE
, "show_tab_cross", file_prefs
.show_tab_cross
);
403 g_key_file_set_boolean(config
, PACKAGE
, "tab_order_ltr", file_prefs
.tab_order_ltr
);
404 g_key_file_set_boolean(config
, PACKAGE
, "tab_order_beside", file_prefs
.tab_order_beside
);
405 g_key_file_set_integer(config
, PACKAGE
, "tab_pos_editor", interface_prefs
.tab_pos_editor
);
406 g_key_file_set_integer(config
, PACKAGE
, "tab_pos_msgwin", interface_prefs
.tab_pos_msgwin
);
407 g_key_file_set_boolean(config
, PACKAGE
, "use_native_windows_dialogs", interface_prefs
.use_native_windows_dialogs
);
410 g_key_file_set_boolean(config
, PACKAGE
, "show_indent_guide", editor_prefs
.show_indent_guide
);
411 g_key_file_set_boolean(config
, PACKAGE
, "show_white_space", editor_prefs
.show_white_space
);
412 g_key_file_set_boolean(config
, PACKAGE
, "show_line_endings", editor_prefs
.show_line_endings
);
413 g_key_file_set_boolean(config
, PACKAGE
, "show_markers_margin", editor_prefs
.show_markers_margin
);
414 g_key_file_set_boolean(config
, PACKAGE
, "show_linenumber_margin", editor_prefs
.show_linenumber_margin
);
415 g_key_file_set_boolean(config
, PACKAGE
, "long_line_enabled", editor_prefs
.long_line_enabled
);
416 g_key_file_set_integer(config
, PACKAGE
, "long_line_type", editor_prefs
.long_line_type
);
417 g_key_file_set_integer(config
, PACKAGE
, "long_line_column", editor_prefs
.long_line_column
);
418 g_key_file_set_string(config
, PACKAGE
, "long_line_color", editor_prefs
.long_line_color
);
421 g_key_file_set_integer(config
, PACKAGE
, "symbolcompletion_max_height", editor_prefs
.symbolcompletion_max_height
);
422 g_key_file_set_integer(config
, PACKAGE
, "symbolcompletion_min_chars", editor_prefs
.symbolcompletion_min_chars
);
423 g_key_file_set_boolean(config
, PACKAGE
, "use_folding", editor_prefs
.folding
);
424 g_key_file_set_boolean(config
, PACKAGE
, "unfold_all_children", editor_prefs
.unfold_all_children
);
425 g_key_file_set_boolean(config
, PACKAGE
, "use_indicators", editor_prefs
.use_indicators
);
426 g_key_file_set_boolean(config
, PACKAGE
, "line_wrapping", editor_prefs
.line_wrapping
);
427 g_key_file_set_boolean(config
, PACKAGE
, "auto_close_xml_tags", editor_prefs
.auto_close_xml_tags
);
428 g_key_file_set_boolean(config
, PACKAGE
, "complete_snippets", editor_prefs
.complete_snippets
);
429 g_key_file_set_boolean(config
, PACKAGE
, "auto_complete_symbols", editor_prefs
.auto_complete_symbols
);
430 g_key_file_set_boolean(config
, PACKAGE
, "pref_editor_disable_dnd", editor_prefs
.disable_dnd
);
431 g_key_file_set_boolean(config
, PACKAGE
, "pref_editor_smart_home_key", editor_prefs
.smart_home_key
);
432 g_key_file_set_boolean(config
, PACKAGE
, "pref_editor_newline_strip", editor_prefs
.newline_strip
);
433 g_key_file_set_integer(config
, PACKAGE
, "line_break_column", editor_prefs
.line_break_column
);
434 g_key_file_set_boolean(config
, PACKAGE
, "auto_continue_multiline", editor_prefs
.auto_continue_multiline
);
435 g_key_file_set_string(config
, PACKAGE
, "comment_toggle_mark", editor_prefs
.comment_toggle_mark
);
436 g_key_file_set_boolean(config
, PACKAGE
, "scroll_stop_at_last_line", editor_prefs
.scroll_stop_at_last_line
);
437 g_key_file_set_integer(config
, PACKAGE
, "autoclose_chars", editor_prefs
.autoclose_chars
);
440 g_key_file_set_string(config
, PACKAGE
, "pref_editor_default_new_encoding", encodings
[file_prefs
.default_new_encoding
].charset
);
441 if (file_prefs
.default_open_encoding
== -1)
442 g_key_file_set_string(config
, PACKAGE
, "pref_editor_default_open_encoding", "none");
444 g_key_file_set_string(config
, PACKAGE
, "pref_editor_default_open_encoding", encodings
[file_prefs
.default_open_encoding
].charset
);
445 g_key_file_set_integer(config
, PACKAGE
, "default_eol_character", file_prefs
.default_eol_character
);
446 g_key_file_set_boolean(config
, PACKAGE
, "pref_editor_new_line", file_prefs
.final_new_line
);
447 g_key_file_set_boolean(config
, PACKAGE
, "pref_editor_ensure_convert_line_endings", file_prefs
.ensure_convert_new_lines
);
448 g_key_file_set_boolean(config
, PACKAGE
, "pref_editor_replace_tabs", file_prefs
.replace_tabs
);
449 g_key_file_set_boolean(config
, PACKAGE
, "pref_editor_trail_space", file_prefs
.strip_trailing_spaces
);
452 g_key_file_set_boolean(config
, PACKAGE
, "pref_toolbar_show", toolbar_prefs
.visible
);
453 g_key_file_set_boolean(config
, PACKAGE
, "pref_toolbar_append_to_menu", toolbar_prefs
.append_to_menu
);
454 g_key_file_set_boolean(config
, PACKAGE
, "pref_toolbar_use_gtk_default_style", toolbar_prefs
.use_gtk_default_style
);
455 g_key_file_set_boolean(config
, PACKAGE
, "pref_toolbar_use_gtk_default_icon", toolbar_prefs
.use_gtk_default_icon
);
456 g_key_file_set_integer(config
, PACKAGE
, "pref_toolbar_icon_style", toolbar_prefs
.icon_style
);
457 g_key_file_set_integer(config
, PACKAGE
, "pref_toolbar_icon_size", toolbar_prefs
.icon_size
);
460 g_key_file_set_string(config
, PACKAGE
, "pref_template_developer", template_prefs
.developer
);
461 g_key_file_set_string(config
, PACKAGE
, "pref_template_company", template_prefs
.company
);
462 g_key_file_set_string(config
, PACKAGE
, "pref_template_mail", template_prefs
.mail
);
463 g_key_file_set_string(config
, PACKAGE
, "pref_template_initial", template_prefs
.initials
);
464 g_key_file_set_string(config
, PACKAGE
, "pref_template_version", template_prefs
.version
);
465 g_key_file_set_string(config
, PACKAGE
, "pref_template_year", template_prefs
.year_format
);
466 g_key_file_set_string(config
, PACKAGE
, "pref_template_date", template_prefs
.date_format
);
467 g_key_file_set_string(config
, PACKAGE
, "pref_template_datetime", template_prefs
.datetime_format
);
470 g_key_file_set_string(config
, "tools", "term_cmd", tool_prefs
.term_cmd
? tool_prefs
.term_cmd
: "");
471 g_key_file_set_string(config
, "tools", "browser_cmd", tool_prefs
.browser_cmd
? tool_prefs
.browser_cmd
: "");
472 g_key_file_set_string(config
, "tools", "grep_cmd", tool_prefs
.grep_cmd
? tool_prefs
.grep_cmd
: "");
473 g_key_file_set_string(config
, PACKAGE
, "context_action_cmd", tool_prefs
.context_action_cmd
);
476 build_save_menu(config
, NULL
, GEANY_BCS_PREF
);
479 g_key_file_set_string(config
, "printing", "print_cmd", printing_prefs
.external_print_cmd
? printing_prefs
.external_print_cmd
: "");
480 g_key_file_set_boolean(config
, "printing", "use_gtk_printing", printing_prefs
.use_gtk_printing
);
481 g_key_file_set_boolean(config
, "printing", "print_line_numbers", printing_prefs
.print_line_numbers
);
482 g_key_file_set_boolean(config
, "printing", "print_page_numbers", printing_prefs
.print_page_numbers
);
483 g_key_file_set_boolean(config
, "printing", "print_page_header", printing_prefs
.print_page_header
);
484 g_key_file_set_boolean(config
, "printing", "page_header_basename", printing_prefs
.page_header_basename
);
485 g_key_file_set_string(config
, "printing", "page_header_datefmt", printing_prefs
.page_header_datefmt
);
489 g_key_file_set_boolean(config
, "VTE", "load_vte", vte_info
.load_vte
);
490 if (vte_info
.have_vte
)
494 if (!g_key_file_has_key(config
, "VTE", "emulation", NULL
)) /* hidden */
495 g_key_file_set_string(config
, "VTE", "emulation", vc
->emulation
);
496 if (!g_key_file_has_key(config
, "VTE", "send_selection_unsafe", NULL
)) /* hidden */
497 g_key_file_set_boolean(config
, "VTE", "send_selection_unsafe",
498 vc
->send_selection_unsafe
);
499 g_key_file_set_string(config
, "VTE", "font", vc
->font
);
500 g_key_file_set_boolean(config
, "VTE", "scroll_on_key", vc
->scroll_on_key
);
501 g_key_file_set_boolean(config
, "VTE", "scroll_on_out", vc
->scroll_on_out
);
502 g_key_file_set_boolean(config
, "VTE", "enable_bash_keys", vc
->enable_bash_keys
);
503 g_key_file_set_boolean(config
, "VTE", "ignore_menu_bar_accel", vc
->ignore_menu_bar_accel
);
504 g_key_file_set_boolean(config
, "VTE", "follow_path", vc
->follow_path
);
505 g_key_file_set_boolean(config
, "VTE", "run_in_vte", vc
->run_in_vte
);
506 g_key_file_set_boolean(config
, "VTE", "skip_run_script", vc
->skip_run_script
);
507 g_key_file_set_boolean(config
, "VTE", "cursor_blinks", vc
->cursor_blinks
);
508 g_key_file_set_integer(config
, "VTE", "scrollback_lines", vc
->scrollback_lines
);
509 g_key_file_set_string(config
, "VTE", "font", vc
->font
);
510 g_key_file_set_string(config
, "VTE", "shell", vc
->shell
);
511 tmp_string
= utils_get_hex_from_color(vc
->colour_fore
);
512 g_key_file_set_string(config
, "VTE", "colour_fore", tmp_string
);
514 tmp_string
= utils_get_hex_from_color(vc
->colour_back
);
515 g_key_file_set_string(config
, "VTE", "colour_back", tmp_string
);
522 static void save_ui_prefs(GKeyFile
*config
)
524 g_key_file_set_boolean(config
, PACKAGE
, "sidebar_visible", ui_prefs
.sidebar_visible
);
525 g_key_file_set_boolean(config
, PACKAGE
, "statusbar_visible", interface_prefs
.statusbar_visible
);
526 g_key_file_set_boolean(config
, PACKAGE
, "msgwindow_visible", ui_prefs
.msgwindow_visible
);
527 g_key_file_set_boolean(config
, PACKAGE
, "fullscreen", ui_prefs
.fullscreen
);
529 /* get the text from the scribble textview */
531 GtkTextBuffer
*buffer
;
532 GtkTextIter start
, end
, iter
;
535 buffer
= gtk_text_view_get_buffer(GTK_TEXT_VIEW(msgwindow
.scribble
));
536 gtk_text_buffer_get_bounds(buffer
, &start
, &end
);
537 scribble_text
= gtk_text_buffer_get_text(buffer
, &start
, &end
, FALSE
);
538 g_key_file_set_string(config
, PACKAGE
, "scribble_text", scribble_text
);
539 g_free(scribble_text
);
541 mark
= gtk_text_buffer_get_insert(buffer
);
542 gtk_text_buffer_get_iter_at_mark(buffer
, &iter
, mark
);
543 scribble_pos
= gtk_text_iter_get_offset(&iter
);
544 g_key_file_set_integer(config
, PACKAGE
, "scribble_pos", scribble_pos
);
547 if (prefs
.save_winpos
)
549 g_key_file_set_integer(config
, PACKAGE
, "treeview_position",
550 gtk_paned_get_position(GTK_PANED(ui_lookup_widget(main_widgets
.window
, "hpaned1"))));
551 g_key_file_set_integer(config
, PACKAGE
, "msgwindow_position",
552 gtk_paned_get_position(GTK_PANED(ui_lookup_widget(main_widgets
.window
, "vpaned1"))));
554 gtk_window_get_position(GTK_WINDOW(main_widgets
.window
), &ui_prefs
.geometry
[0], &ui_prefs
.geometry
[1]);
555 gtk_window_get_size(GTK_WINDOW(main_widgets
.window
), &ui_prefs
.geometry
[2], &ui_prefs
.geometry
[3]);
556 if (gdk_window_get_state(main_widgets
.window
->window
) & GDK_WINDOW_STATE_MAXIMIZED
)
557 ui_prefs
.geometry
[4] = 1;
559 ui_prefs
.geometry
[4] = 0;
561 g_key_file_set_integer_list(config
, PACKAGE
, "geometry", ui_prefs
.geometry
, 5);
564 g_key_file_set_string(config
, PACKAGE
, "custom_date_format", ui_prefs
.custom_date_format
);
565 if (ui_prefs
.custom_commands
!= NULL
)
567 g_key_file_set_string_list(config
, PACKAGE
, "custom_commands",
568 (const gchar
**) ui_prefs
.custom_commands
, g_strv_length(ui_prefs
.custom_commands
));
573 void configuration_save(void)
575 GKeyFile
*config
= g_key_file_new();
576 gchar
*configfile
= g_strconcat(app
->configdir
, G_DIR_SEPARATOR_S
, "geany.conf", NULL
);
579 g_key_file_load_from_file(config
, configfile
, G_KEY_FILE_NONE
, NULL
);
581 /* this signal can be used e.g. to prepare any settings before Stash code reads them below */
582 g_signal_emit_by_name(geany_object
, "save-settings", config
);
584 save_dialog_prefs(config
);
585 save_ui_prefs(config
);
586 project_save_prefs(config
); /* save project filename, etc. */
587 save_recent_files(config
, ui_prefs
.recent_queue
, "recent_files");
588 save_recent_files(config
, ui_prefs
.recent_projects_queue
, "recent_projects");
590 if (cl_options
.load_session
)
591 configuration_save_session_files(config
);
593 else if (vte_info
.have_vte
)
595 vte_get_working_directory(); /* refresh vte_info.dir */
596 g_key_file_set_string(config
, "VTE", "last_dir", vte_info
.dir
);
601 data
= g_key_file_to_data(config
, NULL
, NULL
);
602 utils_write_file(configfile
, data
);
605 g_key_file_free(config
);
610 static void load_recent_files(GKeyFile
*config
, GQueue
*queue
, const gchar
*key
)
612 gchar
**recent_files
;
615 recent_files
= g_key_file_get_string_list(config
, "files", key
, &len
, NULL
);
616 if (recent_files
!= NULL
)
618 for (i
= 0; (i
< len
) && (i
< file_prefs
.mru_length
); i
++)
620 gchar
*filename
= g_strdup(recent_files
[i
]);
621 g_queue_push_tail(queue
, filename
);
623 g_strfreev(recent_files
);
629 * Load session list from the given keyfile, and store it in the global
630 * session_files variable for later file loading
632 void configuration_load_session_files(GKeyFile
*config
, gboolean read_recent_files
)
635 gboolean have_session_files
;
638 GError
*error
= NULL
;
640 session_notebook_page
= utils_get_setting_integer(config
, "files", "current_page", -1);
642 if (read_recent_files
)
644 load_recent_files(config
, ui_prefs
.recent_queue
, "recent_files");
645 load_recent_files(config
, ui_prefs
.recent_projects_queue
, "recent_projects");
648 /* the project may load another list than the main setting */
649 if (session_files
!= NULL
)
650 g_ptr_array_free(session_files
, TRUE
);
652 session_files
= g_ptr_array_new();
653 have_session_files
= TRUE
;
655 while (have_session_files
)
657 g_snprintf(entry
, sizeof(entry
), "FILE_NAME_%d", i
);
658 tmp_array
= g_key_file_get_string_list(config
, "files", entry
, NULL
, &error
);
659 if (! tmp_array
|| error
)
663 have_session_files
= FALSE
;
665 g_ptr_array_add(session_files
, tmp_array
);
670 /* BUG: after loading project at startup, closing project doesn't restore old VTE path */
671 if (vte_info
.have_vte
)
673 gchar
*tmp_string
= utils_get_setting_string(config
, "VTE", "last_dir", NULL
);
674 vte_cwd(tmp_string
,TRUE
);
681 /* note: new settings should be added in init_pref_groups() */
682 static void load_dialog_prefs(GKeyFile
*config
)
684 gchar
*tmp_string
, *tmp_string2
;
685 const gchar
*default_charset
= NULL
;
687 /* compatibility with Geany 0.20 */
688 if (!g_key_file_has_key(config
, PACKAGE
, atomic_file_saving_key
, NULL
))
690 g_key_file_set_boolean(config
, PACKAGE
, atomic_file_saving_key
,
691 utils_get_setting_boolean(config
, PACKAGE
, "use_safe_file_saving", FALSE
));
694 /* read stash prefs */
695 settings_action(config
, SETTING_READ
);
698 prefs
.confirm_exit
= utils_get_setting_boolean(config
, PACKAGE
, "pref_main_confirm_exit", FALSE
);
699 prefs
.suppress_status_messages
= utils_get_setting_boolean(config
, PACKAGE
, "pref_main_suppress_status_messages", FALSE
);
700 prefs
.load_session
= utils_get_setting_boolean(config
, PACKAGE
, "pref_main_load_session", TRUE
);
701 project_prefs
.project_session
= utils_get_setting_boolean(config
, PACKAGE
, "pref_main_project_session", TRUE
);
702 project_prefs
.project_file_in_basedir
= utils_get_setting_boolean(config
, PACKAGE
, "pref_main_project_file_in_basedir", FALSE
);
703 prefs
.save_winpos
= utils_get_setting_boolean(config
, PACKAGE
, "pref_main_save_winpos", TRUE
);
704 prefs
.beep_on_errors
= utils_get_setting_boolean(config
, PACKAGE
, "beep_on_errors", TRUE
);
705 prefs
.switch_to_status
= utils_get_setting_boolean(config
, PACKAGE
, "switch_msgwin_pages", FALSE
);
706 prefs
.auto_focus
= utils_get_setting_boolean(config
, PACKAGE
, "auto_focus", FALSE
);
709 interface_prefs
.tab_pos_editor
= utils_get_setting_integer(config
, PACKAGE
, "tab_pos_editor", GTK_POS_TOP
);
710 interface_prefs
.tab_pos_msgwin
= utils_get_setting_integer(config
, PACKAGE
, "tab_pos_msgwin",GTK_POS_LEFT
);
711 interface_prefs
.sidebar_symbol_visible
= utils_get_setting_boolean(config
, PACKAGE
, "sidebar_symbol_visible", TRUE
);
712 interface_prefs
.sidebar_openfiles_visible
= utils_get_setting_boolean(config
, PACKAGE
, "sidebar_openfiles_visible", TRUE
);
713 interface_prefs
.statusbar_visible
= utils_get_setting_boolean(config
, PACKAGE
, "statusbar_visible", TRUE
);
714 file_prefs
.tab_order_ltr
= utils_get_setting_boolean(config
, PACKAGE
, "tab_order_ltr", TRUE
);
715 file_prefs
.tab_order_beside
= utils_get_setting_boolean(config
, PACKAGE
, "tab_order_beside", FALSE
);
716 interface_prefs
.show_notebook_tabs
= utils_get_setting_boolean(config
, PACKAGE
, "show_notebook_tabs", TRUE
);
717 file_prefs
.show_tab_cross
= utils_get_setting_boolean(config
, PACKAGE
, "show_tab_cross", TRUE
);
718 interface_prefs
.editor_font
= utils_get_setting_string(config
, PACKAGE
, "editor_font", GEANY_DEFAULT_FONT_EDITOR
);
719 interface_prefs
.tagbar_font
= utils_get_setting_string(config
, PACKAGE
, "tagbar_font", GEANY_DEFAULT_FONT_SYMBOL_LIST
);
720 interface_prefs
.msgwin_font
= utils_get_setting_string(config
, PACKAGE
, "msgwin_font", GEANY_DEFAULT_FONT_MSG_WINDOW
);
721 interface_prefs
.use_native_windows_dialogs
= utils_get_setting_boolean(config
, PACKAGE
, "use_native_windows_dialogs", FALSE
);
723 /* display, editor */
724 editor_prefs
.long_line_enabled
= utils_get_setting_boolean(config
, PACKAGE
, "long_line_enabled", TRUE
);
725 editor_prefs
.long_line_type
= utils_get_setting_integer(config
, PACKAGE
, "long_line_type", 0);
726 if (editor_prefs
.long_line_type
== 2) /* backward compatibility */
728 editor_prefs
.long_line_type
= 0;
729 editor_prefs
.long_line_enabled
= FALSE
;
731 editor_prefs
.long_line_color
= utils_get_setting_string(config
, PACKAGE
, "long_line_color", "#C2EBC2");
732 editor_prefs
.long_line_column
= utils_get_setting_integer(config
, PACKAGE
, "long_line_column", 72);
733 editor_prefs
.symbolcompletion_min_chars
= utils_get_setting_integer(config
, PACKAGE
, "symbolcompletion_min_chars", GEANY_MIN_SYMBOLLIST_CHARS
);
734 editor_prefs
.symbolcompletion_max_height
= utils_get_setting_integer(config
, PACKAGE
, "symbolcompletion_max_height", GEANY_MAX_SYMBOLLIST_HEIGHT
);
735 editor_prefs
.line_wrapping
= utils_get_setting_boolean(config
, PACKAGE
, "line_wrapping", FALSE
); /* default is off for better performance */
736 editor_prefs
.use_indicators
= utils_get_setting_boolean(config
, PACKAGE
, "use_indicators", TRUE
);
737 editor_prefs
.show_indent_guide
= utils_get_setting_boolean(config
, PACKAGE
, "show_indent_guide", FALSE
);
738 editor_prefs
.show_white_space
= utils_get_setting_boolean(config
, PACKAGE
, "show_white_space", FALSE
);
739 editor_prefs
.show_line_endings
= utils_get_setting_boolean(config
, PACKAGE
, "show_line_endings", FALSE
);
740 editor_prefs
.scroll_stop_at_last_line
= utils_get_setting_boolean(config
, PACKAGE
, "scroll_stop_at_last_line", TRUE
);
741 editor_prefs
.auto_close_xml_tags
= utils_get_setting_boolean(config
, PACKAGE
, "auto_close_xml_tags", TRUE
);
742 editor_prefs
.complete_snippets
= utils_get_setting_boolean(config
, PACKAGE
, "complete_snippets", TRUE
);
743 editor_prefs
.auto_complete_symbols
= utils_get_setting_boolean(config
, PACKAGE
, "auto_complete_symbols", TRUE
);
744 editor_prefs
.folding
= utils_get_setting_boolean(config
, PACKAGE
, "use_folding", TRUE
);
745 editor_prefs
.unfold_all_children
= utils_get_setting_boolean(config
, PACKAGE
, "unfold_all_children", FALSE
);
746 editor_prefs
.show_markers_margin
= utils_get_setting_boolean(config
, PACKAGE
, "show_markers_margin", TRUE
);
747 editor_prefs
.show_linenumber_margin
= utils_get_setting_boolean(config
, PACKAGE
, "show_linenumber_margin", TRUE
);
748 editor_prefs
.disable_dnd
= utils_get_setting_boolean(config
, PACKAGE
, "pref_editor_disable_dnd", FALSE
);
749 editor_prefs
.smart_home_key
= utils_get_setting_boolean(config
, PACKAGE
, "pref_editor_smart_home_key", TRUE
);
750 editor_prefs
.newline_strip
= utils_get_setting_boolean(config
, PACKAGE
, "pref_editor_newline_strip", FALSE
);
751 editor_prefs
.line_break_column
= utils_get_setting_integer(config
, PACKAGE
, "line_break_column", 72);
752 editor_prefs
.auto_continue_multiline
= utils_get_setting_boolean(config
, PACKAGE
, "auto_continue_multiline", TRUE
);
753 editor_prefs
.comment_toggle_mark
= utils_get_setting_string(config
, PACKAGE
, "comment_toggle_mark", GEANY_TOGGLE_MARK
);
754 editor_prefs
.autoclose_chars
= utils_get_setting_integer(config
, PACKAGE
, "autoclose_chars", 0);
757 * use current locale encoding as default for new files (should be UTF-8 in most cases) */
758 g_get_charset(&default_charset
);
759 tmp_string
= utils_get_setting_string(config
, PACKAGE
, "pref_editor_default_new_encoding",
763 const GeanyEncoding
*enc
= encodings_get_from_charset(tmp_string
);
765 file_prefs
.default_new_encoding
= enc
->idx
;
767 file_prefs
.default_new_encoding
= GEANY_ENCODING_UTF_8
;
771 tmp_string
= utils_get_setting_string(config
, PACKAGE
, "pref_editor_default_open_encoding",
775 const GeanyEncoding
*enc
= encodings_get_from_charset(tmp_string
);
777 file_prefs
.default_open_encoding
= enc
->idx
;
779 file_prefs
.default_open_encoding
= -1;
783 file_prefs
.default_eol_character
= utils_get_setting_integer(config
, PACKAGE
, "default_eol_character", GEANY_DEFAULT_EOL_CHARACTER
);
784 file_prefs
.replace_tabs
= utils_get_setting_boolean(config
, PACKAGE
, "pref_editor_replace_tabs", FALSE
);
785 file_prefs
.ensure_convert_new_lines
= utils_get_setting_boolean(config
, PACKAGE
, "pref_editor_ensure_convert_line_endings", FALSE
);
786 file_prefs
.final_new_line
= utils_get_setting_boolean(config
, PACKAGE
, "pref_editor_new_line", TRUE
);
787 file_prefs
.strip_trailing_spaces
= utils_get_setting_boolean(config
, PACKAGE
, "pref_editor_trail_space", FALSE
);
790 toolbar_prefs
.visible
= utils_get_setting_boolean(config
, PACKAGE
, "pref_toolbar_show", TRUE
);
791 toolbar_prefs
.append_to_menu
= utils_get_setting_boolean(config
, PACKAGE
, "pref_toolbar_append_to_menu", FALSE
);
793 toolbar_prefs
.use_gtk_default_style
= utils_get_setting_boolean(config
, PACKAGE
, "pref_toolbar_use_gtk_default_style", TRUE
);
794 if (! toolbar_prefs
.use_gtk_default_style
)
795 toolbar_prefs
.icon_style
= utils_get_setting_integer(config
, PACKAGE
, "pref_toolbar_icon_style", GTK_TOOLBAR_ICONS
);
797 toolbar_prefs
.use_gtk_default_icon
= utils_get_setting_boolean(config
, PACKAGE
, "pref_toolbar_use_gtk_default_icon", TRUE
);
798 if (! toolbar_prefs
.use_gtk_default_icon
)
799 toolbar_prefs
.icon_size
= utils_get_setting_integer(config
, PACKAGE
, "pref_toolbar_icon_size", GTK_ICON_SIZE_LARGE_TOOLBAR
);
804 vte_info
.load_vte
= utils_get_setting_boolean(config
, "VTE", "load_vte", TRUE
);
805 if (vte_info
.load_vte
)
807 struct passwd
*pw
= getpwuid(getuid());
808 const gchar
*shell
= (pw
!= NULL
) ? pw
->pw_shell
: "/bin/sh";
810 vc
= g_new0(VteConfig
, 1);
811 vte_info
.dir
= utils_get_setting_string(config
, "VTE", "last_dir", NULL
);
812 if ((vte_info
.dir
== NULL
|| utils_str_equal(vte_info
.dir
, "")) && pw
!= NULL
)
813 /* last dir is not set, fallback to user's home directory */
814 vte_info
.dir
= g_strdup(pw
->pw_dir
);
815 else if (vte_info
.dir
== NULL
&& pw
== NULL
)
816 /* fallback to root */
817 vte_info
.dir
= g_strdup("/");
819 vc
->emulation
= utils_get_setting_string(config
, "VTE", "emulation", "xterm");
820 vc
->send_selection_unsafe
= utils_get_setting_boolean(config
, "VTE",
821 "send_selection_unsafe", FALSE
);
822 vc
->shell
= utils_get_setting_string(config
, "VTE", "shell", shell
);
823 vc
->font
= utils_get_setting_string(config
, "VTE", "font", "Monospace 10");
824 vc
->scroll_on_key
= utils_get_setting_boolean(config
, "VTE", "scroll_on_key", TRUE
);
825 vc
->scroll_on_out
= utils_get_setting_boolean(config
, "VTE", "scroll_on_out", TRUE
);
826 vc
->enable_bash_keys
= utils_get_setting_boolean(config
, "VTE", "enable_bash_keys", TRUE
);
827 vc
->ignore_menu_bar_accel
= utils_get_setting_boolean(config
, "VTE", "ignore_menu_bar_accel", FALSE
);
828 vc
->follow_path
= utils_get_setting_boolean(config
, "VTE", "follow_path", FALSE
);
829 vc
->run_in_vte
= utils_get_setting_boolean(config
, "VTE", "run_in_vte", FALSE
);
830 vc
->skip_run_script
= utils_get_setting_boolean(config
, "VTE", "skip_run_script", FALSE
);
831 vc
->cursor_blinks
= utils_get_setting_boolean(config
, "VTE", "cursor_blinks", FALSE
);
832 vc
->scrollback_lines
= utils_get_setting_integer(config
, "VTE", "scrollback_lines", 500);
833 vc
->colour_fore
= g_new0(GdkColor
, 1);
834 vc
->colour_back
= g_new0(GdkColor
, 1);
835 tmp_string
= utils_get_setting_string(config
, "VTE", "colour_fore", "#ffffff");
836 gdk_color_parse(tmp_string
, vc
->colour_fore
);
838 tmp_string
= utils_get_setting_string(config
, "VTE", "colour_back", "#000000");
839 gdk_color_parse(tmp_string
, vc
->colour_back
);
844 template_prefs
.developer
= utils_get_setting_string(config
, PACKAGE
, "pref_template_developer", g_get_real_name());
845 template_prefs
.company
= utils_get_setting_string(config
, PACKAGE
, "pref_template_company", "");
846 tmp_string
= utils_get_initials(template_prefs
.developer
);
847 template_prefs
.initials
= utils_get_setting_string(config
, PACKAGE
, "pref_template_initial", tmp_string
);
850 template_prefs
.version
= utils_get_setting_string(config
, PACKAGE
, "pref_template_version", "1.0");
852 tmp_string2
= utils_get_hostname();
853 tmp_string
= g_strdup_printf("%s@%s", g_get_user_name(), tmp_string2
);
854 template_prefs
.mail
= utils_get_setting_string(config
, PACKAGE
, "pref_template_mail", tmp_string
);
857 template_prefs
.year_format
= utils_get_setting_string(config
, PACKAGE
, "pref_template_year", "%Y");
858 template_prefs
.date_format
= utils_get_setting_string(config
, PACKAGE
, "pref_template_date", "%Y-%m-%d");
859 template_prefs
.datetime_format
= utils_get_setting_string(config
, PACKAGE
, "pref_template_datetime", "%d.%m.%Y %H:%M:%S %Z");
862 tool_prefs
.term_cmd
= utils_get_setting_string(config
, "tools", "term_cmd", GEANY_DEFAULT_TOOLS_TERMINAL
);
863 tool_prefs
.browser_cmd
= utils_get_setting_string(config
, "tools", "browser_cmd", GEANY_DEFAULT_TOOLS_BROWSER
);
864 tool_prefs
.grep_cmd
= utils_get_setting_string(config
, "tools", "grep_cmd", GEANY_DEFAULT_TOOLS_GREP
);
866 tool_prefs
.context_action_cmd
= utils_get_setting_string(config
, PACKAGE
, "context_action_cmd", "");
869 build_set_group_count(GEANY_GBG_FT
, build_menu_prefs
.number_ft_menu_items
);
870 build_set_group_count(GEANY_GBG_NON_FT
, build_menu_prefs
.number_non_ft_menu_items
);
871 build_set_group_count(GEANY_GBG_EXEC
, build_menu_prefs
.number_exec_menu_items
);
872 build_load_menu(config
, GEANY_BCS_PREF
, NULL
);
875 tmp_string2
= g_find_program_in_path(GEANY_DEFAULT_TOOLS_PRINTCMD
);
877 /* single quote paths on Win32 for g_spawn_command_line_async */
878 tmp_string
= g_strconcat("'", tmp_string2
, "' '%f'", NULL
);
880 tmp_string
= g_strconcat(tmp_string2
, " %f", NULL
);
882 printing_prefs
.external_print_cmd
= utils_get_setting_string(config
, "printing", "print_cmd", tmp_string
);
886 printing_prefs
.use_gtk_printing
= utils_get_setting_boolean(config
, "printing", "use_gtk_printing", TRUE
);
887 printing_prefs
.print_line_numbers
= utils_get_setting_boolean(config
, "printing", "print_line_numbers", TRUE
);
888 printing_prefs
.print_page_numbers
= utils_get_setting_boolean(config
, "printing", "print_page_numbers", TRUE
);
889 printing_prefs
.print_page_header
= utils_get_setting_boolean(config
, "printing", "print_page_header", TRUE
);
890 printing_prefs
.page_header_basename
= utils_get_setting_boolean(config
, "printing", "page_header_basename", FALSE
);
891 printing_prefs
.page_header_datefmt
= utils_get_setting_string(config
, "printing", "page_header_datefmt", "%c");
895 static void load_ui_prefs(GKeyFile
*config
)
898 GError
*error
= NULL
;
900 ui_prefs
.sidebar_visible
= utils_get_setting_boolean(config
, PACKAGE
, "sidebar_visible", TRUE
);
901 ui_prefs
.msgwindow_visible
= utils_get_setting_boolean(config
, PACKAGE
, "msgwindow_visible", TRUE
);
902 ui_prefs
.fullscreen
= utils_get_setting_boolean(config
, PACKAGE
, "fullscreen", FALSE
);
903 ui_prefs
.custom_date_format
= utils_get_setting_string(config
, PACKAGE
, "custom_date_format", "");
904 ui_prefs
.custom_commands
= g_key_file_get_string_list(config
, PACKAGE
, "custom_commands", NULL
, NULL
);
906 scribble_text
= utils_get_setting_string(config
, PACKAGE
, "scribble_text",
907 _("Type here what you want, use it as a notice/scratch board"));
908 scribble_pos
= utils_get_setting_integer(config
, PACKAGE
, "scribble_pos", -1);
910 geo
= g_key_file_get_integer_list(config
, PACKAGE
, "geometry", NULL
, &error
);
913 ui_prefs
.geometry
[0] = -1;
921 ui_prefs
.geometry
[0] = geo
[0];
922 ui_prefs
.geometry
[1] = geo
[1];
923 ui_prefs
.geometry
[2] = geo
[2];
924 ui_prefs
.geometry
[3] = geo
[3];
925 ui_prefs
.geometry
[4] = geo
[4];
927 /* don't use insane values but when main windows was maximized last time, pos might be
928 * negative (due to differences in root window and window decorations) */
929 if (ui_prefs
.geometry
[4] != 1)
931 for (i
= 2; i
< 4; i
++)
933 if (ui_prefs
.geometry
[i
] < -1)
934 ui_prefs
.geometry
[i
] = -1;
938 hpan_position
= utils_get_setting_integer(config
, PACKAGE
, "treeview_position", 156);
939 vpan_position
= utils_get_setting_integer(config
, PACKAGE
, "msgwindow_position", (geo
) ?
940 (GEANY_MSGWIN_HEIGHT
+ geo
[3] - 440) :
941 (GEANY_MSGWIN_HEIGHT
+ GEANY_WINDOW_DEFAULT_HEIGHT
- 440));
948 * Save current session in default configuration file
950 void configuration_save_default_session(void)
952 gchar
*configfile
= g_strconcat(app
->configdir
, G_DIR_SEPARATOR_S
, "geany.conf", NULL
);
954 GKeyFile
*config
= g_key_file_new();
956 g_key_file_load_from_file(config
, configfile
, G_KEY_FILE_NONE
, NULL
);
958 if (cl_options
.load_session
)
959 configuration_save_session_files(config
);
962 data
= g_key_file_to_data(config
, NULL
, NULL
);
963 utils_write_file(configfile
, data
);
966 g_key_file_free(config
);
972 * Only reload the session part of the default configuration
974 void configuration_reload_default_session(void)
976 const gchar
*configfile
= utils_build_path(app
->configdir
, "geany.conf", NULL
);
977 GKeyFile
*config
= g_key_file_new();
979 g_key_file_load_from_file(config
, configfile
, G_KEY_FILE_NONE
, NULL
);
981 configuration_load_session_files(config
, FALSE
);
983 g_key_file_free(config
);
987 gboolean
configuration_load(void)
989 gchar
*configfile
= utils_build_path(app
->configdir
, "geany.conf", NULL
);
990 GKeyFile
*config
= g_key_file_new();
992 if (! g_file_test(configfile
, G_FILE_TEST_IS_REGULAR
))
993 { /* config file does not (yet) exist, so try to load a global config file which may be */
994 /* created by distributors */
995 geany_debug("No user config file found, trying to use global configuration.");
996 setptr(configfile
, utils_build_path(app
->datadir
, "geany.conf", NULL
));
998 g_key_file_load_from_file(config
, configfile
, G_KEY_FILE_NONE
, NULL
);
1001 load_dialog_prefs(config
);
1002 load_ui_prefs(config
);
1003 project_load_prefs(config
);
1004 configuration_load_session_files(config
, TRUE
);
1006 /* this signal can be used e.g. to delay building UI elements until settings have been read */
1007 g_signal_emit_by_name(geany_object
, "load-settings", config
);
1009 g_key_file_free(config
);
1014 static gboolean
open_session_file(gchar
**tmp
, guint len
)
1017 const gchar
*ft_name
;
1018 gchar
*locale_filename
;
1019 gint enc_idx
, indent_type
;
1020 gboolean ro
, auto_indent
, line_wrapping
;
1021 /** TODO when we have a global pref for line breaking, use its value */
1022 gboolean line_breaking
= FALSE
;
1023 gboolean ret
= FALSE
;
1028 enc_idx
= atoi(tmp
[3]);
1029 indent_type
= atoi(tmp
[4]);
1030 auto_indent
= atoi(tmp
[5]);
1031 line_wrapping
= atoi(tmp
[6]);
1032 /* try to get the locale equivalent for the filename */
1033 locale_filename
= utils_get_locale_from_utf8(tmp
[7]);
1034 /* replace ':' back with ';' (see get_session_file_string for details) */
1035 g_strdelimit((gchar
*) utils_path_skip_root(locale_filename
), ":", ';');
1038 line_breaking
= atoi(tmp
[8]);
1040 if (g_file_test(locale_filename
, G_FILE_TEST_IS_REGULAR
))
1042 GeanyFiletype
*ft
= filetypes_lookup_by_name(ft_name
);
1043 GeanyDocument
*doc
= document_open_file_full(
1044 NULL
, locale_filename
, pos
, ro
, ft
,
1045 (enc_idx
>= 0 && enc_idx
< GEANY_ENCODINGS_MAX
) ?
1046 encodings
[enc_idx
].charset
: NULL
);
1050 gint indent_width
= doc
->editor
->indent_width
;
1053 indent_width
= atoi(tmp
[9]);
1054 editor_set_indent(doc
->editor
, indent_type
, indent_width
);
1055 editor_set_line_wrapping(doc
->editor
, line_wrapping
);
1056 doc
->editor
->line_breaking
= line_breaking
;
1057 doc
->editor
->auto_indent
= auto_indent
;
1063 geany_debug("Could not find file '%s'.", tmp
[7]);
1066 g_free(locale_filename
);
1071 /* Open session files
1072 * Note: notebook page switch handler and adding to recent files list is always disabled
1073 * for all files opened within this function */
1074 void configuration_open_files(void)
1077 gboolean failure
= FALSE
;
1079 /* necessary to set it to TRUE for project session support */
1080 main_status
.opening_session_files
= TRUE
;
1082 i
= file_prefs
.tab_order_ltr
? 0 : (session_files
->len
- 1);
1085 gchar
**tmp
= g_ptr_array_index(session_files
, i
);
1088 if (tmp
!= NULL
&& (len
= g_strv_length(tmp
)) >= 8)
1090 if (! open_session_file(tmp
, len
))
1095 if (file_prefs
.tab_order_ltr
)
1098 if (i
>= (gint
)session_files
->len
)
1109 g_ptr_array_free(session_files
, TRUE
);
1110 session_files
= NULL
;
1113 ui_set_statusbar(TRUE
, _("Failed to load one or more session files."));
1114 else if (session_notebook_page
>= 0)
1116 /* explicitly allow notebook switch page callback to be called for window title,
1117 * encoding settings and so other things */
1118 main_status
.opening_session_files
= FALSE
;
1119 /** TODO if session_notebook_page is equal to the current notebook tab(the last opened)
1120 ** the notebook switch page callback isn't triggered and e.g. menu items are not updated */
1121 gtk_notebook_set_current_page(GTK_NOTEBOOK(main_widgets
.notebook
), session_notebook_page
);
1123 main_status
.opening_session_files
= FALSE
;
1127 /* set some settings which are already read from the config file, but need other things, like the
1128 * realisation of the main window */
1129 void configuration_apply_settings(void)
1132 { /* update the scribble widget, because now it's realized */
1134 GtkTextBuffer
*buffer
=
1135 gtk_text_view_get_buffer(GTK_TEXT_VIEW(msgwindow
.scribble
));
1137 gtk_text_buffer_set_text(buffer
, scribble_text
, -1);
1138 gtk_text_buffer_get_iter_at_offset(buffer
, &iter
, scribble_pos
);
1139 gtk_text_buffer_place_cursor(buffer
, &iter
);
1141 g_free(scribble_text
);
1143 /* set the position of the hpaned and vpaned */
1144 if (prefs
.save_winpos
)
1146 gtk_paned_set_position(GTK_PANED(ui_lookup_widget(main_widgets
.window
, "hpaned1")), hpan_position
);
1147 gtk_paned_set_position(GTK_PANED(ui_lookup_widget(main_widgets
.window
, "vpaned1")), vpan_position
);
1150 /* set fullscreen after initial draw so that returning to normal view is the right size.
1151 * fullscreen mode is disabled by default, so act only if it is true */
1152 if (ui_prefs
.fullscreen
)
1154 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ui_lookup_widget(main_widgets
.window
, "menu_fullscreen1")), TRUE
);
1155 ui_prefs
.fullscreen
= TRUE
;
1156 ui_set_fullscreen();
1159 msgwin_show_hide_tabs();
1163 void configuration_init(void)
1165 keyfile_groups
= g_ptr_array_new();
1166 pref_groups
= g_ptr_array_new();
1171 void configuration_finalize(void)
1176 foreach_ptr_array(group
, i
, keyfile_groups
)
1177 stash_group_free(group
);
1179 g_ptr_array_free(keyfile_groups
, TRUE
);
1180 g_ptr_array_free(pref_groups
, TRUE
);