-
Notifications
You must be signed in to change notification settings - Fork 593
/
keyfile.c
1319 lines (1132 loc) · 53 KB
/
keyfile.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* keyfile.c - this file is part of Geany, a fast and lightweight IDE
*
* Copyright 2005-2012 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
* Copyright 2006-2012 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/*
* geany.conf preferences file loading and saving.
*/
/*
* Session file format:
* filename_xx=pos;filetype UID;read only;Eencoding;use_tabs;auto_indent;line_wrapping;filename
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "keyfile.h"
#include "app.h"
#include "build.h"
#include "document.h"
#include "encodings.h"
#include "encodingsprivate.h"
#include "filetypes.h"
#include "geanyobject.h"
#include "main.h"
#include "msgwindow.h"
#include "prefs.h"
#include "printing.h"
#include "project.h"
#include "sciwrappers.h"
#include "stash.h"
#include "support.h"
#include "symbols.h"
#include "templates.h"
#include "toolbar.h"
#include "ui_utils.h"
#include "utils.h"
#include "vte.h"
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#ifdef HAVE_VTE
#include <pwd.h>
#include <sys/types.h>
#include <unistd.h>
#endif
/* some default settings which are used at the very first start of Geany to fill
* the configuration file */
#define GEANY_MAX_SYMBOLLIST_HEIGHT 10
#define GEANY_MIN_SYMBOLLIST_CHARS 4
#define GEANY_MSGWIN_HEIGHT 208
#define GEANY_DISK_CHECK_TIMEOUT 30
#define GEANY_DEFAULT_TOOLS_MAKE "make"
#ifdef G_OS_WIN32
#define GEANY_DEFAULT_TOOLS_TERMINAL "cmd.exe /Q /C %c"
#elif defined(__APPLE__)
#define GEANY_DEFAULT_TOOLS_TERMINAL "open -a terminal %c"
#else
#define GEANY_DEFAULT_TOOLS_TERMINAL "xterm -e \"/bin/sh %c\""
#endif
#ifdef __APPLE__
#define GEANY_DEFAULT_TOOLS_BROWSER "open -a safari"
#define GEANY_DEFAULT_FONT_SYMBOL_LIST "Helvetica Medium 12"
#define GEANY_DEFAULT_FONT_MSG_WINDOW "Menlo Medium 12"
#define GEANY_DEFAULT_FONT_EDITOR "Menlo Medium 12"
#else
#define GEANY_DEFAULT_TOOLS_BROWSER "firefox"
#define GEANY_DEFAULT_FONT_SYMBOL_LIST "Sans 9"
#define GEANY_DEFAULT_FONT_MSG_WINDOW "Monospace 9"
#define GEANY_DEFAULT_FONT_EDITOR "Monospace 10"
#endif
#define GEANY_DEFAULT_TOOLS_PRINTCMD "lpr"
#define GEANY_DEFAULT_TOOLS_GREP "grep"
#define GEANY_DEFAULT_MRU_LENGTH 10
#define GEANY_TOGGLE_MARK "~ "
#define GEANY_MAX_AUTOCOMPLETE_WORDS 30
#define GEANY_MAX_SYMBOLS_UPDATE_FREQ 250
#define GEANY_DEFAULT_FILETYPE_REGEX "-\\*-\\s*([^\\s]+)\\s*-\\*-"
static gchar *scribble_text = NULL;
static gint scribble_pos = -1;
static GPtrArray *session_files = NULL;
static gint session_notebook_page;
static const gchar atomic_file_saving_key[] = "use_atomic_file_saving";
static GPtrArray *keyfile_groups = NULL;
GPtrArray *pref_groups = NULL;
static struct
{
gint number_ft_menu_items;
gint number_non_ft_menu_items;
gint number_exec_menu_items;
}
build_menu_prefs;
/* The group will be free'd on quitting.
* @param for_prefs_dialog is whether the group also has Prefs dialog items. */
void configuration_add_pref_group(struct StashGroup *group, gboolean for_prefs_dialog)
{
g_ptr_array_add(keyfile_groups, group);
if (for_prefs_dialog)
g_ptr_array_add(pref_groups, group);
}
/* The group will be free'd on quitting. */
void configuration_add_various_pref_group(struct StashGroup *group)
{
configuration_add_pref_group(group, TRUE);
stash_group_set_various(group, TRUE);
}
static void init_pref_groups(void)
{
StashGroup *group;
group = stash_group_new(PACKAGE);
configuration_add_pref_group(group, TRUE);
stash_group_add_entry(group, &prefs.default_open_path,
"default_open_path", "", "startup_path_entry");
stash_group_add_toggle_button(group, &file_prefs.cmdline_new_files,
"cmdline_new_files", TRUE, "check_cmdline_new_files");
stash_group_add_toggle_button(group, &interface_prefs.notebook_double_click_hides_widgets,
"notebook_double_click_hides_widgets", FALSE, "check_double_click_hides_widgets");
stash_group_add_toggle_button(group, &file_prefs.tab_close_switch_to_mru,
"tab_close_switch_to_mru", FALSE, "check_tab_close_switch_to_mru");
stash_group_add_integer(group, &interface_prefs.tab_pos_sidebar, "tab_pos_sidebar", GTK_POS_TOP);
stash_group_add_radio_buttons(group, &interface_prefs.sidebar_pos,
"sidebar_pos", GTK_POS_LEFT,
"radio_sidebar_left", GTK_POS_LEFT,
"radio_sidebar_right", GTK_POS_RIGHT,
NULL);
stash_group_add_radio_buttons(group, &interface_prefs.symbols_sort_mode,
"symbols_sort_mode", SYMBOLS_SORT_BY_NAME,
"radio_symbols_sort_by_name", SYMBOLS_SORT_BY_NAME,
"radio_symbols_sort_by_appearance", SYMBOLS_SORT_BY_APPEARANCE,
NULL);
stash_group_add_radio_buttons(group, &interface_prefs.msgwin_orientation,
"msgwin_orientation", GTK_ORIENTATION_VERTICAL,
"radio_msgwin_vertical", GTK_ORIENTATION_VERTICAL,
"radio_msgwin_horizontal", GTK_ORIENTATION_HORIZONTAL,
NULL);
/* editor display */
stash_group_add_toggle_button(group, &interface_prefs.highlighting_invert_all,
"highlighting_invert_all", FALSE, "check_highlighting_invert");
stash_group_add_toggle_button(group, &search_prefs.use_current_word,
"pref_main_search_use_current_word", TRUE, "check_search_use_current_word");
/* editor */
stash_group_add_toggle_button(group, &editor_prefs.indentation->detect_type,
"check_detect_indent", FALSE, "check_detect_indent_type");
stash_group_add_toggle_button(group, &editor_prefs.indentation->detect_width,
"detect_indent_width", FALSE, "check_detect_indent_width");
stash_group_add_toggle_button(group, &editor_prefs.use_tab_to_indent,
"use_tab_to_indent", TRUE, "check_tab_key_indents");
stash_group_add_spin_button_integer(group, &editor_prefs.indentation->width,
"pref_editor_tab_width", 4, "spin_indent_width");
stash_group_add_combo_box(group, (gint*)(void*)&editor_prefs.indentation->auto_indent_mode,
"indent_mode", GEANY_AUTOINDENT_CURRENTCHARS, "combo_auto_indent_mode");
stash_group_add_radio_buttons(group, (gint*)(void*)&editor_prefs.indentation->type,
"indent_type", GEANY_INDENT_TYPE_TABS,
"radio_indent_spaces", GEANY_INDENT_TYPE_SPACES,
"radio_indent_tabs", GEANY_INDENT_TYPE_TABS,
"radio_indent_both", GEANY_INDENT_TYPE_BOTH,
NULL);
stash_group_add_radio_buttons(group, (gint*)(void*)&editor_prefs.show_virtual_space,
"virtualspace", GEANY_VIRTUAL_SPACE_SELECTION,
"radio_virtualspace_disabled", GEANY_VIRTUAL_SPACE_DISABLED,
"radio_virtualspace_selection", GEANY_VIRTUAL_SPACE_SELECTION,
"radio_virtualspace_always", GEANY_VIRTUAL_SPACE_ALWAYS,
NULL);
stash_group_add_toggle_button(group, &editor_prefs.autocomplete_doc_words,
"autocomplete_doc_words", FALSE, "check_autocomplete_doc_words");
stash_group_add_toggle_button(group, &editor_prefs.completion_drops_rest_of_word,
"completion_drops_rest_of_word", FALSE, "check_completion_drops_rest_of_word");
stash_group_add_spin_button_integer(group, (gint*)&editor_prefs.autocompletion_max_entries,
"autocompletion_max_entries", GEANY_MAX_AUTOCOMPLETE_WORDS,
"spin_autocompletion_max_entries");
stash_group_add_spin_button_integer(group, (gint*)&editor_prefs.autocompletion_update_freq,
"autocompletion_update_freq", GEANY_MAX_SYMBOLS_UPDATE_FREQ, "spin_symbol_update_freq");
stash_group_add_string(group, &editor_prefs.color_scheme,
"color_scheme", NULL);
/* files */
stash_group_add_spin_button_integer(group, (gint*)&file_prefs.mru_length,
"mru_length", GEANY_DEFAULT_MRU_LENGTH, "spin_mru");
stash_group_add_spin_button_integer(group, &file_prefs.disk_check_timeout,
"disk_check_timeout", GEANY_DISK_CHECK_TIMEOUT, "spin_disk_check");
/* various geany prefs */
group = stash_group_new(PACKAGE);
configuration_add_various_pref_group(group);
stash_group_add_boolean(group, &editor_prefs.show_scrollbars,
"show_editor_scrollbars", TRUE);
stash_group_add_boolean(group, &editor_prefs.brace_match_ltgt,
"brace_match_ltgt", FALSE);
stash_group_add_boolean(group, &editor_prefs.use_gtk_word_boundaries,
"use_gtk_word_boundaries", TRUE);
stash_group_add_boolean(group, &editor_prefs.complete_snippets_whilst_editing,
"complete_snippets_whilst_editing", FALSE);
stash_group_add_boolean(group, &file_prefs.use_safe_file_saving,
atomic_file_saving_key, FALSE);
stash_group_add_boolean(group, &file_prefs.gio_unsafe_save_backup,
"gio_unsafe_save_backup", FALSE);
stash_group_add_boolean(group, &file_prefs.use_gio_unsafe_file_saving,
"use_gio_unsafe_file_saving", TRUE);
stash_group_add_boolean(group, &file_prefs.keep_edit_history_on_reload,
"keep_edit_history_on_reload", TRUE);
stash_group_add_boolean(group, &file_prefs.show_keep_edit_history_on_reload_msg,
"show_keep_edit_history_on_reload_msg", TRUE);
/* for backwards-compatibility */
stash_group_add_integer(group, &editor_prefs.indentation->hard_tab_width,
"indent_hard_tab_width", 8);
stash_group_add_integer(group, (gint*)&search_prefs.find_selection_type,
"find_selection_type", GEANY_FIND_SEL_CURRENT_WORD);
stash_group_add_string(group, &file_prefs.extract_filetype_regex,
"extract_filetype_regex", GEANY_DEFAULT_FILETYPE_REGEX);
stash_group_add_boolean(group, &search_prefs.replace_and_find_by_default,
"replace_and_find_by_default", TRUE);
/* Note: Interface-related various prefs are in ui_init_prefs() */
/* various build-menu prefs */
group = stash_group_new("build-menu");
configuration_add_various_pref_group(group);
stash_group_add_integer(group, &build_menu_prefs.number_ft_menu_items,
"number_ft_menu_items", 0);
stash_group_add_integer(group, &build_menu_prefs.number_non_ft_menu_items,
"number_non_ft_menu_items", 0);
stash_group_add_integer(group, &build_menu_prefs.number_exec_menu_items,
"number_exec_menu_items", 0);
}
typedef enum SettingAction
{
SETTING_READ,
SETTING_WRITE
}
SettingAction;
static void settings_action(GKeyFile *config, SettingAction action)
{
guint i;
StashGroup *group;
foreach_ptr_array(group, i, keyfile_groups)
{
switch (action)
{
case SETTING_READ:
stash_group_load_from_key_file(group, config); break;
case SETTING_WRITE:
stash_group_save_to_key_file(group, config); break;
}
}
}
static void save_recent_files(GKeyFile *config, GQueue *queue, gchar const *key)
{
gchar **recent_files = g_new0(gchar*, file_prefs.mru_length + 1);
guint i;
for (i = 0; i < file_prefs.mru_length; i++)
{
if (! g_queue_is_empty(queue))
{
/* copy the values, this is necessary when this function is called from the
* preferences dialog or when quitting is canceled to keep the queue intact */
recent_files[i] = g_strdup(g_queue_peek_nth(queue, i));
}
else
{
recent_files[i] = NULL;
break;
}
}
/* There is a bug in GTK 2.6 g_key_file_set_string_list, we must NULL terminate. */
recent_files[file_prefs.mru_length] = NULL;
g_key_file_set_string_list(config, "files", key,
(const gchar**)recent_files, file_prefs.mru_length);
g_strfreev(recent_files);
}
static gchar *get_session_file_string(GeanyDocument *doc)
{
gchar *fname;
gchar *locale_filename;
gchar *escaped_filename;
GeanyFiletype *ft = doc->file_type;
if (ft == NULL) /* can happen when saving a new file when quitting */
ft = filetypes[GEANY_FILETYPES_NONE];
locale_filename = utils_get_locale_from_utf8(doc->file_name);
escaped_filename = g_uri_escape_string(locale_filename, NULL, TRUE);
fname = g_strdup_printf("%d;%s;%d;E%s;%d;%d;%d;%s;%d;%d",
sci_get_current_position(doc->editor->sci),
ft->name,
doc->readonly,
doc->encoding,
doc->editor->indent_type,
doc->editor->auto_indent,
doc->editor->line_wrapping,
escaped_filename,
doc->editor->line_breaking,
doc->editor->indent_width);
g_free(escaped_filename);
g_free(locale_filename);
return fname;
}
static void remove_session_files(GKeyFile *config)
{
gchar **ptr;
gchar **keys = g_key_file_get_keys(config, "files", NULL, NULL);
foreach_strv(ptr, keys)
{
if (g_str_has_prefix(*ptr, "FILE_NAME_"))
g_key_file_remove_key(config, "files", *ptr, NULL);
}
g_strfreev(keys);
}
void configuration_save_session_files(GKeyFile *config)
{
gint npage;
gchar entry[16];
guint i = 0, j = 0, max;
GeanyDocument *doc;
npage = gtk_notebook_get_current_page(GTK_NOTEBOOK(main_widgets.notebook));
g_key_file_set_integer(config, "files", "current_page", npage);
// clear existing entries first as they might not all be overwritten
remove_session_files(config);
/* store the filenames in the notebook tab order to reopen them the next time */
max = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook));
for (i = 0; i < max; i++)
{
doc = document_get_from_page(i);
if (doc != NULL && doc->real_path != NULL)
{
gchar *fname;
g_snprintf(entry, sizeof(entry), "FILE_NAME_%d", j);
fname = get_session_file_string(doc);
g_key_file_set_string(config, "files", entry, fname);
g_free(fname);
j++;
}
}
#ifdef HAVE_VTE
if (vte_info.have_vte)
{
vte_get_working_directory(); /* refresh vte_info.dir */
g_key_file_set_string(config, "VTE", "last_dir", vte_info.dir);
}
#endif
}
static void save_dialog_prefs(GKeyFile *config)
{
/* new settings should be added in init_pref_groups() */
settings_action(config, SETTING_WRITE);
/* Some of the key names are not consistent, but this is for backwards compatibility */
/* general */
g_key_file_set_boolean(config, PACKAGE, "pref_main_load_session", prefs.load_session);
g_key_file_set_boolean(config, PACKAGE, "pref_main_project_session", project_prefs.project_session);
g_key_file_set_boolean(config, PACKAGE, "pref_main_project_file_in_basedir", project_prefs.project_file_in_basedir);
g_key_file_set_boolean(config, PACKAGE, "pref_main_save_winpos", prefs.save_winpos);
g_key_file_set_boolean(config, PACKAGE, "pref_main_confirm_exit", prefs.confirm_exit);
g_key_file_set_boolean(config, PACKAGE, "pref_main_suppress_status_messages", prefs.suppress_status_messages);
g_key_file_set_boolean(config, PACKAGE, "switch_msgwin_pages", prefs.switch_to_status);
g_key_file_set_boolean(config, PACKAGE, "beep_on_errors", prefs.beep_on_errors);
g_key_file_set_boolean(config, PACKAGE, "auto_focus", prefs.auto_focus);
/* interface */
g_key_file_set_boolean(config, PACKAGE, "sidebar_symbol_visible", interface_prefs.sidebar_symbol_visible);
g_key_file_set_boolean(config, PACKAGE, "sidebar_openfiles_visible", interface_prefs.sidebar_openfiles_visible);
g_key_file_set_string(config, PACKAGE, "editor_font", interface_prefs.editor_font);
g_key_file_set_string(config, PACKAGE, "tagbar_font", interface_prefs.tagbar_font);
g_key_file_set_string(config, PACKAGE, "msgwin_font", interface_prefs.msgwin_font);
g_key_file_set_boolean(config, PACKAGE, "show_notebook_tabs", interface_prefs.show_notebook_tabs);
g_key_file_set_boolean(config, PACKAGE, "show_tab_cross", file_prefs.show_tab_cross);
g_key_file_set_boolean(config, PACKAGE, "tab_order_ltr", file_prefs.tab_order_ltr);
g_key_file_set_boolean(config, PACKAGE, "tab_order_beside", file_prefs.tab_order_beside);
g_key_file_set_integer(config, PACKAGE, "tab_pos_editor", interface_prefs.tab_pos_editor);
g_key_file_set_integer(config, PACKAGE, "tab_pos_msgwin", interface_prefs.tab_pos_msgwin);
g_key_file_set_boolean(config, PACKAGE, "use_native_windows_dialogs", interface_prefs.use_native_windows_dialogs);
/* display */
g_key_file_set_boolean(config, PACKAGE, "show_indent_guide", editor_prefs.show_indent_guide);
g_key_file_set_boolean(config, PACKAGE, "show_white_space", editor_prefs.show_white_space);
g_key_file_set_boolean(config, PACKAGE, "show_line_endings", editor_prefs.show_line_endings);
g_key_file_set_boolean(config, PACKAGE, "show_markers_margin", editor_prefs.show_markers_margin);
g_key_file_set_boolean(config, PACKAGE, "show_linenumber_margin", editor_prefs.show_linenumber_margin);
g_key_file_set_boolean(config, PACKAGE, "long_line_enabled", editor_prefs.long_line_enabled);
g_key_file_set_integer(config, PACKAGE, "long_line_type", editor_prefs.long_line_type);
g_key_file_set_integer(config, PACKAGE, "long_line_column", editor_prefs.long_line_column);
g_key_file_set_string(config, PACKAGE, "long_line_color", editor_prefs.long_line_color);
/* editor */
g_key_file_set_integer(config, PACKAGE, "symbolcompletion_max_height", editor_prefs.symbolcompletion_max_height);
g_key_file_set_integer(config, PACKAGE, "symbolcompletion_min_chars", editor_prefs.symbolcompletion_min_chars);
g_key_file_set_boolean(config, PACKAGE, "use_folding", editor_prefs.folding);
g_key_file_set_boolean(config, PACKAGE, "unfold_all_children", editor_prefs.unfold_all_children);
g_key_file_set_boolean(config, PACKAGE, "use_indicators", editor_prefs.use_indicators);
g_key_file_set_boolean(config, PACKAGE, "line_wrapping", editor_prefs.line_wrapping);
g_key_file_set_boolean(config, PACKAGE, "auto_close_xml_tags", editor_prefs.auto_close_xml_tags);
g_key_file_set_boolean(config, PACKAGE, "complete_snippets", editor_prefs.complete_snippets);
g_key_file_set_boolean(config, PACKAGE, "auto_complete_symbols", editor_prefs.auto_complete_symbols);
g_key_file_set_boolean(config, PACKAGE, "pref_editor_disable_dnd", editor_prefs.disable_dnd);
g_key_file_set_boolean(config, PACKAGE, "pref_editor_smart_home_key", editor_prefs.smart_home_key);
g_key_file_set_boolean(config, PACKAGE, "pref_editor_newline_strip", editor_prefs.newline_strip);
g_key_file_set_integer(config, PACKAGE, "line_break_column", editor_prefs.line_break_column);
g_key_file_set_boolean(config, PACKAGE, "auto_continue_multiline", editor_prefs.auto_continue_multiline);
g_key_file_set_string(config, PACKAGE, "comment_toggle_mark", editor_prefs.comment_toggle_mark);
g_key_file_set_boolean(config, PACKAGE, "scroll_stop_at_last_line", editor_prefs.scroll_stop_at_last_line);
g_key_file_set_integer(config, PACKAGE, "autoclose_chars", editor_prefs.autoclose_chars);
/* files */
g_key_file_set_string(config, PACKAGE, "pref_editor_default_new_encoding", encodings[file_prefs.default_new_encoding].charset);
if (file_prefs.default_open_encoding == -1)
g_key_file_set_string(config, PACKAGE, "pref_editor_default_open_encoding", "none");
else
g_key_file_set_string(config, PACKAGE, "pref_editor_default_open_encoding", encodings[file_prefs.default_open_encoding].charset);
g_key_file_set_integer(config, PACKAGE, "default_eol_character", file_prefs.default_eol_character);
g_key_file_set_boolean(config, PACKAGE, "pref_editor_new_line", file_prefs.final_new_line);
g_key_file_set_boolean(config, PACKAGE, "pref_editor_ensure_convert_line_endings", file_prefs.ensure_convert_new_lines);
g_key_file_set_boolean(config, PACKAGE, "pref_editor_replace_tabs", file_prefs.replace_tabs);
g_key_file_set_boolean(config, PACKAGE, "pref_editor_trail_space", file_prefs.strip_trailing_spaces);
/* toolbar */
g_key_file_set_boolean(config, PACKAGE, "pref_toolbar_show", toolbar_prefs.visible);
g_key_file_set_boolean(config, PACKAGE, "pref_toolbar_append_to_menu", toolbar_prefs.append_to_menu);
g_key_file_set_boolean(config, PACKAGE, "pref_toolbar_use_gtk_default_style", toolbar_prefs.use_gtk_default_style);
g_key_file_set_boolean(config, PACKAGE, "pref_toolbar_use_gtk_default_icon", toolbar_prefs.use_gtk_default_icon);
g_key_file_set_integer(config, PACKAGE, "pref_toolbar_icon_style", toolbar_prefs.icon_style);
g_key_file_set_integer(config, PACKAGE, "pref_toolbar_icon_size", toolbar_prefs.icon_size);
/* templates */
g_key_file_set_string(config, PACKAGE, "pref_template_developer", template_prefs.developer);
g_key_file_set_string(config, PACKAGE, "pref_template_company", template_prefs.company);
g_key_file_set_string(config, PACKAGE, "pref_template_mail", template_prefs.mail);
g_key_file_set_string(config, PACKAGE, "pref_template_initial", template_prefs.initials);
g_key_file_set_string(config, PACKAGE, "pref_template_version", template_prefs.version);
g_key_file_set_string(config, PACKAGE, "pref_template_year", template_prefs.year_format);
g_key_file_set_string(config, PACKAGE, "pref_template_date", template_prefs.date_format);
g_key_file_set_string(config, PACKAGE, "pref_template_datetime", template_prefs.datetime_format);
/* tools settings */
g_key_file_set_string(config, "tools", "terminal_cmd", tool_prefs.term_cmd ? tool_prefs.term_cmd : "");
g_key_file_set_string(config, "tools", "browser_cmd", tool_prefs.browser_cmd ? tool_prefs.browser_cmd : "");
g_key_file_set_string(config, "tools", "grep_cmd", tool_prefs.grep_cmd ? tool_prefs.grep_cmd : "");
g_key_file_set_string(config, PACKAGE, "context_action_cmd", tool_prefs.context_action_cmd);
/* build menu */
build_save_menu(config, NULL, GEANY_BCS_PREF);
/* printing */
g_key_file_set_string(config, "printing", "print_cmd", printing_prefs.external_print_cmd ? printing_prefs.external_print_cmd : "");
g_key_file_set_boolean(config, "printing", "use_gtk_printing", printing_prefs.use_gtk_printing);
g_key_file_set_boolean(config, "printing", "print_line_numbers", printing_prefs.print_line_numbers);
g_key_file_set_boolean(config, "printing", "print_page_numbers", printing_prefs.print_page_numbers);
g_key_file_set_boolean(config, "printing", "print_page_header", printing_prefs.print_page_header);
g_key_file_set_boolean(config, "printing", "page_header_basename", printing_prefs.page_header_basename);
g_key_file_set_string(config, "printing", "page_header_datefmt", printing_prefs.page_header_datefmt);
/* VTE */
#ifdef HAVE_VTE
g_key_file_set_boolean(config, "VTE", "load_vte", vte_info.load_vte);
if (vte_info.have_vte)
{
gchar *tmp_string;
if (!g_key_file_has_key(config, "VTE", "emulation", NULL)) /* hidden */
g_key_file_set_string(config, "VTE", "emulation", vc->emulation);
if (!g_key_file_has_key(config, "VTE", "send_selection_unsafe", NULL)) /* hidden */
g_key_file_set_boolean(config, "VTE", "send_selection_unsafe",
vc->send_selection_unsafe);
if (!g_key_file_has_key(config, "VTE", "send_cmd_prefix", NULL)) /* hidden */
g_key_file_set_string(config, "VTE", "send_cmd_prefix", vc->send_cmd_prefix);
g_key_file_set_string(config, "VTE", "font", vc->font);
g_key_file_set_boolean(config, "VTE", "scroll_on_key", vc->scroll_on_key);
g_key_file_set_boolean(config, "VTE", "scroll_on_out", vc->scroll_on_out);
g_key_file_set_boolean(config, "VTE", "enable_bash_keys", vc->enable_bash_keys);
g_key_file_set_boolean(config, "VTE", "ignore_menu_bar_accel", vc->ignore_menu_bar_accel);
g_key_file_set_boolean(config, "VTE", "follow_path", vc->follow_path);
g_key_file_set_boolean(config, "VTE", "run_in_vte", vc->run_in_vte);
g_key_file_set_boolean(config, "VTE", "skip_run_script", vc->skip_run_script);
g_key_file_set_boolean(config, "VTE", "cursor_blinks", vc->cursor_blinks);
g_key_file_set_integer(config, "VTE", "scrollback_lines", vc->scrollback_lines);
g_key_file_set_string(config, "VTE", "font", vc->font);
g_key_file_set_string(config, "VTE", "image", vc->image);
g_key_file_set_string(config, "VTE", "shell", vc->shell);
tmp_string = utils_get_hex_from_color(&vc->colour_fore);
g_key_file_set_string(config, "VTE", "colour_fore", tmp_string);
g_free(tmp_string);
tmp_string = utils_get_hex_from_color(&vc->colour_back);
g_key_file_set_string(config, "VTE", "colour_back", tmp_string);
g_free(tmp_string);
}
#endif
}
static void save_ui_prefs(GKeyFile *config)
{
g_key_file_set_boolean(config, PACKAGE, "sidebar_visible", ui_prefs.sidebar_visible);
g_key_file_set_boolean(config, PACKAGE, "statusbar_visible", interface_prefs.statusbar_visible);
g_key_file_set_boolean(config, PACKAGE, "msgwindow_visible", ui_prefs.msgwindow_visible);
g_key_file_set_boolean(config, PACKAGE, "fullscreen", ui_prefs.fullscreen);
/* get the text from the scribble textview */
{
GtkTextBuffer *buffer;
GtkTextIter start, end, iter;
GtkTextMark *mark;
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(msgwindow.scribble));
gtk_text_buffer_get_bounds(buffer, &start, &end);
scribble_text = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
g_key_file_set_string(config, PACKAGE, "scribble_text", scribble_text);
g_free(scribble_text);
mark = gtk_text_buffer_get_insert(buffer);
gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
scribble_pos = gtk_text_iter_get_offset(&iter);
g_key_file_set_integer(config, PACKAGE, "scribble_pos", scribble_pos);
}
if (prefs.save_winpos)
{
GdkWindowState wstate;
g_key_file_set_integer(config, PACKAGE, "treeview_position",
gtk_paned_get_position(GTK_PANED(ui_lookup_widget(main_widgets.window, "hpaned1"))));
g_key_file_set_integer(config, PACKAGE, "msgwindow_position",
gtk_paned_get_position(GTK_PANED(ui_lookup_widget(main_widgets.window, "vpaned1"))));
gtk_window_get_position(GTK_WINDOW(main_widgets.window), &ui_prefs.geometry[0], &ui_prefs.geometry[1]);
gtk_window_get_size(GTK_WINDOW(main_widgets.window), &ui_prefs.geometry[2], &ui_prefs.geometry[3]);
wstate = gdk_window_get_state(gtk_widget_get_window(main_widgets.window));
ui_prefs.geometry[4] = (wstate & GDK_WINDOW_STATE_MAXIMIZED) ? 1 : 0;
g_key_file_set_integer_list(config, PACKAGE, "geometry", ui_prefs.geometry, 5);
}
g_key_file_set_string(config, PACKAGE, "custom_date_format", ui_prefs.custom_date_format);
if (ui_prefs.custom_commands != NULL)
{
g_key_file_set_string_list(config, PACKAGE, "custom_commands",
(const gchar**) ui_prefs.custom_commands, g_strv_length(ui_prefs.custom_commands));
g_key_file_set_string_list(config, PACKAGE, "custom_commands_labels",
(const gchar**) ui_prefs.custom_commands_labels, g_strv_length(ui_prefs.custom_commands_labels));
}
}
void configuration_save(void)
{
GKeyFile *config = g_key_file_new();
gchar *configfile = g_build_filename(app->configdir, "geany.conf", NULL);
gchar *data;
g_key_file_load_from_file(config, configfile, G_KEY_FILE_NONE, NULL);
/* this signal can be used e.g. to prepare any settings before Stash code reads them below */
g_signal_emit_by_name(geany_object, "save-settings", config);
save_dialog_prefs(config);
save_ui_prefs(config);
project_save_prefs(config); /* save project filename, etc. */
save_recent_files(config, ui_prefs.recent_queue, "recent_files");
save_recent_files(config, ui_prefs.recent_projects_queue, "recent_projects");
if (cl_options.load_session)
configuration_save_session_files(config);
#ifdef HAVE_VTE
else if (vte_info.have_vte)
{
vte_get_working_directory(); /* refresh vte_info.dir */
g_key_file_set_string(config, "VTE", "last_dir", vte_info.dir);
}
#endif
/* write the file */
data = g_key_file_to_data(config, NULL, NULL);
utils_write_file(configfile, data);
g_free(data);
g_key_file_free(config);
g_free(configfile);
}
static void load_recent_files(GKeyFile *config, GQueue *queue, const gchar *key)
{
gchar **recent_files;
gsize i, len = 0;
recent_files = g_key_file_get_string_list(config, "files", key, &len, NULL);
if (recent_files != NULL)
{
for (i = 0; (i < len) && (i < file_prefs.mru_length); i++)
{
gchar *filename = g_strdup(recent_files[i]);
g_queue_push_tail(queue, filename);
}
g_strfreev(recent_files);
}
}
/*
* Load session list from the given keyfile, and store it in the global
* session_files variable for later file loading
* */
void configuration_load_session_files(GKeyFile *config, gboolean read_recent_files)
{
guint i;
gboolean have_session_files;
gchar entry[16];
gchar **tmp_array;
GError *error = NULL;
session_notebook_page = utils_get_setting_integer(config, "files", "current_page", -1);
if (read_recent_files)
{
load_recent_files(config, ui_prefs.recent_queue, "recent_files");
load_recent_files(config, ui_prefs.recent_projects_queue, "recent_projects");
}
/* the project may load another list than the main setting */
if (session_files != NULL)
{
foreach_ptr_array(tmp_array, i, session_files)
g_strfreev(tmp_array);
g_ptr_array_free(session_files, TRUE);
}
session_files = g_ptr_array_new();
have_session_files = TRUE;
i = 0;
while (have_session_files)
{
g_snprintf(entry, sizeof(entry), "FILE_NAME_%d", i);
tmp_array = g_key_file_get_string_list(config, "files", entry, NULL, &error);
if (! tmp_array || error)
{
g_error_free(error);
error = NULL;
have_session_files = FALSE;
}
g_ptr_array_add(session_files, tmp_array);
i++;
}
#ifdef HAVE_VTE
/* BUG: after loading project at startup, closing project doesn't restore old VTE path */
if (vte_info.have_vte)
{
gchar *tmp_string = utils_get_setting_string(config, "VTE", "last_dir", NULL);
vte_cwd(tmp_string,TRUE);
g_free(tmp_string);
}
#endif
}
#ifdef HAVE_VTE
static void get_setting_color(GKeyFile *config, const gchar *section, const gchar *key,
GdkColor *color, const gchar *default_color)
{
gchar *str = utils_get_setting_string(config, section, key, NULL);
if (str == NULL || ! utils_parse_color(str, color))
utils_parse_color(default_color, color);
g_free(str);
}
#endif
/* note: new settings should be added in init_pref_groups() */
static void load_dialog_prefs(GKeyFile *config)
{
gchar *tmp_string, *tmp_string2;
const gchar *default_charset = NULL;
gchar *cmd;
/* compatibility with Geany 0.20 */
if (!g_key_file_has_key(config, PACKAGE, atomic_file_saving_key, NULL))
{
g_key_file_set_boolean(config, PACKAGE, atomic_file_saving_key,
utils_get_setting_boolean(config, PACKAGE, "use_safe_file_saving", FALSE));
}
/* compatibility with Geany 0.21 */
{
gboolean suppress_search_dialogs = utils_get_setting_boolean(config, PACKAGE, "pref_main_suppress_search_dialogs", FALSE);
if (!g_key_file_has_key(config, "search", "pref_search_always_wrap", NULL))
g_key_file_set_boolean(config, "search", "pref_search_always_wrap", suppress_search_dialogs);
if (!g_key_file_has_key(config, "search", "pref_search_hide_find_dialog", NULL))
g_key_file_set_boolean(config, "search", "pref_search_hide_find_dialog", suppress_search_dialogs);
}
/* read stash prefs */
settings_action(config, SETTING_READ);
/* general */
prefs.confirm_exit = utils_get_setting_boolean(config, PACKAGE, "pref_main_confirm_exit", FALSE);
prefs.suppress_status_messages = utils_get_setting_boolean(config, PACKAGE, "pref_main_suppress_status_messages", FALSE);
prefs.load_session = utils_get_setting_boolean(config, PACKAGE, "pref_main_load_session", TRUE);
project_prefs.project_session = utils_get_setting_boolean(config, PACKAGE, "pref_main_project_session", TRUE);
project_prefs.project_file_in_basedir = utils_get_setting_boolean(config, PACKAGE, "pref_main_project_file_in_basedir", FALSE);
prefs.save_winpos = utils_get_setting_boolean(config, PACKAGE, "pref_main_save_winpos", TRUE);
prefs.beep_on_errors = utils_get_setting_boolean(config, PACKAGE, "beep_on_errors", TRUE);
prefs.switch_to_status = utils_get_setting_boolean(config, PACKAGE, "switch_msgwin_pages", FALSE);
prefs.auto_focus = utils_get_setting_boolean(config, PACKAGE, "auto_focus", FALSE);
/* interface */
interface_prefs.tab_pos_editor = utils_get_setting_integer(config, PACKAGE, "tab_pos_editor", GTK_POS_TOP);
interface_prefs.tab_pos_msgwin = utils_get_setting_integer(config, PACKAGE, "tab_pos_msgwin",GTK_POS_LEFT);
interface_prefs.sidebar_symbol_visible = utils_get_setting_boolean(config, PACKAGE, "sidebar_symbol_visible", TRUE);
interface_prefs.sidebar_openfiles_visible = utils_get_setting_boolean(config, PACKAGE, "sidebar_openfiles_visible", TRUE);
interface_prefs.statusbar_visible = utils_get_setting_boolean(config, PACKAGE, "statusbar_visible", TRUE);
file_prefs.tab_order_ltr = utils_get_setting_boolean(config, PACKAGE, "tab_order_ltr", TRUE);
file_prefs.tab_order_beside = utils_get_setting_boolean(config, PACKAGE, "tab_order_beside", FALSE);
interface_prefs.show_notebook_tabs = utils_get_setting_boolean(config, PACKAGE, "show_notebook_tabs", TRUE);
file_prefs.show_tab_cross = utils_get_setting_boolean(config, PACKAGE, "show_tab_cross", TRUE);
interface_prefs.editor_font = utils_get_setting_string(config, PACKAGE, "editor_font", GEANY_DEFAULT_FONT_EDITOR);
interface_prefs.tagbar_font = utils_get_setting_string(config, PACKAGE, "tagbar_font", GEANY_DEFAULT_FONT_SYMBOL_LIST);
interface_prefs.msgwin_font = utils_get_setting_string(config, PACKAGE, "msgwin_font", GEANY_DEFAULT_FONT_MSG_WINDOW);
interface_prefs.use_native_windows_dialogs = utils_get_setting_boolean(config, PACKAGE, "use_native_windows_dialogs", FALSE);
/* display, editor */
editor_prefs.long_line_enabled = utils_get_setting_boolean(config, PACKAGE, "long_line_enabled", TRUE);
editor_prefs.long_line_type = utils_get_setting_integer(config, PACKAGE, "long_line_type", 0);
if (editor_prefs.long_line_type == 2) /* backward compatibility */
{
editor_prefs.long_line_type = 0;
editor_prefs.long_line_enabled = FALSE;
}
editor_prefs.long_line_color = utils_get_setting_string(config, PACKAGE, "long_line_color", "#C2EBC2");
editor_prefs.long_line_column = utils_get_setting_integer(config, PACKAGE, "long_line_column", 72);
editor_prefs.symbolcompletion_min_chars = utils_get_setting_integer(config, PACKAGE, "symbolcompletion_min_chars", GEANY_MIN_SYMBOLLIST_CHARS);
editor_prefs.symbolcompletion_max_height = utils_get_setting_integer(config, PACKAGE, "symbolcompletion_max_height", GEANY_MAX_SYMBOLLIST_HEIGHT);
editor_prefs.line_wrapping = utils_get_setting_boolean(config, PACKAGE, "line_wrapping", FALSE); /* default is off for better performance */
editor_prefs.use_indicators = utils_get_setting_boolean(config, PACKAGE, "use_indicators", TRUE);
editor_prefs.show_indent_guide = utils_get_setting_boolean(config, PACKAGE, "show_indent_guide", FALSE);
editor_prefs.show_white_space = utils_get_setting_boolean(config, PACKAGE, "show_white_space", FALSE);
editor_prefs.show_line_endings = utils_get_setting_boolean(config, PACKAGE, "show_line_endings", FALSE);
editor_prefs.scroll_stop_at_last_line = utils_get_setting_boolean(config, PACKAGE, "scroll_stop_at_last_line", TRUE);
editor_prefs.auto_close_xml_tags = utils_get_setting_boolean(config, PACKAGE, "auto_close_xml_tags", TRUE);
editor_prefs.complete_snippets = utils_get_setting_boolean(config, PACKAGE, "complete_snippets", TRUE);
editor_prefs.auto_complete_symbols = utils_get_setting_boolean(config, PACKAGE, "auto_complete_symbols", TRUE);
editor_prefs.folding = utils_get_setting_boolean(config, PACKAGE, "use_folding", TRUE);
editor_prefs.unfold_all_children = utils_get_setting_boolean(config, PACKAGE, "unfold_all_children", FALSE);
editor_prefs.show_markers_margin = utils_get_setting_boolean(config, PACKAGE, "show_markers_margin", TRUE);
editor_prefs.show_linenumber_margin = utils_get_setting_boolean(config, PACKAGE, "show_linenumber_margin", TRUE);
editor_prefs.disable_dnd = utils_get_setting_boolean(config, PACKAGE, "pref_editor_disable_dnd", FALSE);
editor_prefs.smart_home_key = utils_get_setting_boolean(config, PACKAGE, "pref_editor_smart_home_key", TRUE);
editor_prefs.newline_strip = utils_get_setting_boolean(config, PACKAGE, "pref_editor_newline_strip", FALSE);
editor_prefs.line_break_column = utils_get_setting_integer(config, PACKAGE, "line_break_column", 72);
editor_prefs.auto_continue_multiline = utils_get_setting_boolean(config, PACKAGE, "auto_continue_multiline", TRUE);
editor_prefs.comment_toggle_mark = utils_get_setting_string(config, PACKAGE, "comment_toggle_mark", GEANY_TOGGLE_MARK);
editor_prefs.autoclose_chars = utils_get_setting_integer(config, PACKAGE, "autoclose_chars", 0);
/* Files
* use current locale encoding as default for new files (should be UTF-8 in most cases) */
g_get_charset(&default_charset);
tmp_string = utils_get_setting_string(config, PACKAGE, "pref_editor_default_new_encoding",
default_charset);
if (tmp_string)
{
const GeanyEncoding *enc = encodings_get_from_charset(tmp_string);
if (enc != NULL)
file_prefs.default_new_encoding = enc->idx;
else
file_prefs.default_new_encoding = GEANY_ENCODING_UTF_8;
g_free(tmp_string);
}
tmp_string = utils_get_setting_string(config, PACKAGE, "pref_editor_default_open_encoding",
"none");
if (tmp_string)
{
const GeanyEncoding *enc = encodings_get_from_charset(tmp_string);
if (enc != NULL)
file_prefs.default_open_encoding = enc->idx;
else
file_prefs.default_open_encoding = -1;
g_free(tmp_string);
}
file_prefs.default_eol_character = utils_get_setting_integer(config, PACKAGE, "default_eol_character", GEANY_DEFAULT_EOL_CHARACTER);
file_prefs.replace_tabs = utils_get_setting_boolean(config, PACKAGE, "pref_editor_replace_tabs", FALSE);
file_prefs.ensure_convert_new_lines = utils_get_setting_boolean(config, PACKAGE, "pref_editor_ensure_convert_line_endings", FALSE);
file_prefs.final_new_line = utils_get_setting_boolean(config, PACKAGE, "pref_editor_new_line", TRUE);
file_prefs.strip_trailing_spaces = utils_get_setting_boolean(config, PACKAGE, "pref_editor_trail_space", FALSE);
/* toolbar */
toolbar_prefs.visible = utils_get_setting_boolean(config, PACKAGE, "pref_toolbar_show", TRUE);
toolbar_prefs.append_to_menu = utils_get_setting_boolean(config, PACKAGE, "pref_toolbar_append_to_menu", FALSE);
{
toolbar_prefs.use_gtk_default_style = utils_get_setting_boolean(config, PACKAGE, "pref_toolbar_use_gtk_default_style", TRUE);
if (! toolbar_prefs.use_gtk_default_style)
toolbar_prefs.icon_style = utils_get_setting_integer(config, PACKAGE, "pref_toolbar_icon_style", GTK_TOOLBAR_ICONS);
toolbar_prefs.use_gtk_default_icon = utils_get_setting_boolean(config, PACKAGE, "pref_toolbar_use_gtk_default_icon", TRUE);
if (! toolbar_prefs.use_gtk_default_icon)
toolbar_prefs.icon_size = utils_get_setting_integer(config, PACKAGE, "pref_toolbar_icon_size", GTK_ICON_SIZE_LARGE_TOOLBAR);
}
/* VTE */
#ifdef HAVE_VTE
vte_info.load_vte = utils_get_setting_boolean(config, "VTE", "load_vte", TRUE);
if (vte_info.load_vte)
{
struct passwd *pw = getpwuid(getuid());
const gchar *shell = (pw != NULL) ? pw->pw_shell : "/bin/sh";
#ifdef __APPLE__
/* Geany is started using launchd on OS X and we don't get any environment variables
* so PS1 isn't defined. Start as a login shell to read the corresponding config files. */
if (strcmp(shell, "/bin/bash") == 0)
shell = "/bin/bash -l";
#endif
vc = g_new0(VteConfig, 1);
vte_info.dir = utils_get_setting_string(config, "VTE", "last_dir", NULL);
if ((vte_info.dir == NULL || utils_str_equal(vte_info.dir, "")) && pw != NULL)
/* last dir is not set, fallback to user's home directory */
SETPTR(vte_info.dir, g_strdup(pw->pw_dir));
else if (vte_info.dir == NULL && pw == NULL)
/* fallback to root */
vte_info.dir = g_strdup("/");
vc->emulation = utils_get_setting_string(config, "VTE", "emulation", "xterm");
vc->send_selection_unsafe = utils_get_setting_boolean(config, "VTE",
"send_selection_unsafe", FALSE);
vc->image = utils_get_setting_string(config, "VTE", "image", "");
vc->shell = utils_get_setting_string(config, "VTE", "shell", shell);
vc->font = utils_get_setting_string(config, "VTE", "font", GEANY_DEFAULT_FONT_EDITOR);
vc->scroll_on_key = utils_get_setting_boolean(config, "VTE", "scroll_on_key", TRUE);
vc->scroll_on_out = utils_get_setting_boolean(config, "VTE", "scroll_on_out", TRUE);
vc->enable_bash_keys = utils_get_setting_boolean(config, "VTE", "enable_bash_keys", TRUE);
vc->ignore_menu_bar_accel = utils_get_setting_boolean(config, "VTE", "ignore_menu_bar_accel", FALSE);
vc->follow_path = utils_get_setting_boolean(config, "VTE", "follow_path", FALSE);
vc->send_cmd_prefix = utils_get_setting_string(config, "VTE", "send_cmd_prefix", "");
vc->run_in_vte = utils_get_setting_boolean(config, "VTE", "run_in_vte", FALSE);
vc->skip_run_script = utils_get_setting_boolean(config, "VTE", "skip_run_script", FALSE);
vc->cursor_blinks = utils_get_setting_boolean(config, "VTE", "cursor_blinks", FALSE);
vc->scrollback_lines = utils_get_setting_integer(config, "VTE", "scrollback_lines", 500);
get_setting_color(config, "VTE", "colour_fore", &vc->colour_fore, "#ffffff");
get_setting_color(config, "VTE", "colour_back", &vc->colour_back, "#000000");
}
#endif
/* templates */
template_prefs.developer = utils_get_setting_string(config, PACKAGE, "pref_template_developer", g_get_real_name());
template_prefs.company = utils_get_setting_string(config, PACKAGE, "pref_template_company", "");
tmp_string = utils_get_initials(template_prefs.developer);
template_prefs.initials = utils_get_setting_string(config, PACKAGE, "pref_template_initial", tmp_string);
g_free(tmp_string);
template_prefs.version = utils_get_setting_string(config, PACKAGE, "pref_template_version", "1.0");
tmp_string = g_strdup_printf("%s@%s", g_get_user_name(), g_get_host_name());
template_prefs.mail = utils_get_setting_string(config, PACKAGE, "pref_template_mail", tmp_string);
g_free(tmp_string);
template_prefs.year_format = utils_get_setting_string(config, PACKAGE, "pref_template_year", GEANY_TEMPLATES_FORMAT_YEAR);
template_prefs.date_format = utils_get_setting_string(config, PACKAGE, "pref_template_date", GEANY_TEMPLATES_FORMAT_DATE);
template_prefs.datetime_format = utils_get_setting_string(config, PACKAGE, "pref_template_datetime", GEANY_TEMPLATES_FORMAT_DATETIME);
/* tools */
cmd = utils_get_setting_string(config, "tools", "terminal_cmd", "");
if (EMPTY(cmd))
{
SETPTR(cmd, utils_get_setting_string(config, "tools", "term_cmd", ""));
if (!EMPTY(cmd))
{
tmp_string = cmd;
#ifdef G_OS_WIN32
if (strstr(cmd, "cmd.exe"))
cmd = g_strconcat(cmd, " /Q /C %c", NULL);
else
cmd = g_strconcat(cmd, " %c", NULL);
#else
cmd = g_strconcat(cmd, " -e \"/bin/sh %c\"", NULL);
#endif
g_free(tmp_string);
}
else
SETPTR(cmd, g_strdup(GEANY_DEFAULT_TOOLS_TERMINAL));
}
tool_prefs.term_cmd = cmd;
tool_prefs.browser_cmd = utils_get_setting_string(config, "tools", "browser_cmd", GEANY_DEFAULT_TOOLS_BROWSER);
tool_prefs.grep_cmd = utils_get_setting_string(config, "tools", "grep_cmd", GEANY_DEFAULT_TOOLS_GREP);
tool_prefs.context_action_cmd = utils_get_setting_string(config, PACKAGE, "context_action_cmd", "");
/* build menu */
build_set_group_count(GEANY_GBG_FT, build_menu_prefs.number_ft_menu_items);
build_set_group_count(GEANY_GBG_NON_FT, build_menu_prefs.number_non_ft_menu_items);
build_set_group_count(GEANY_GBG_EXEC, build_menu_prefs.number_exec_menu_items);
build_load_menu(config, GEANY_BCS_PREF, NULL);
/* printing */
tmp_string2 = g_find_program_in_path(GEANY_DEFAULT_TOOLS_PRINTCMD);
if (!EMPTY(tmp_string2))
{
#ifdef G_OS_WIN32
tmp_string = g_strconcat(GEANY_DEFAULT_TOOLS_PRINTCMD, " \"%f\"", NULL);
#else
tmp_string = g_strconcat(GEANY_DEFAULT_TOOLS_PRINTCMD, " '%f'", NULL);
#endif
}
else
{
tmp_string = g_strdup("");
}
printing_prefs.external_print_cmd = utils_get_setting_string(config, "printing", "print_cmd", tmp_string);
g_free(tmp_string);
g_free(tmp_string2);
printing_prefs.use_gtk_printing = utils_get_setting_boolean(config, "printing", "use_gtk_printing", TRUE);
printing_prefs.print_line_numbers = utils_get_setting_boolean(config, "printing", "print_line_numbers", TRUE);
printing_prefs.print_page_numbers = utils_get_setting_boolean(config, "printing", "print_page_numbers", TRUE);
printing_prefs.print_page_header = utils_get_setting_boolean(config, "printing", "print_page_header", TRUE);
printing_prefs.page_header_basename = utils_get_setting_boolean(config, "printing", "page_header_basename", FALSE);
printing_prefs.page_header_datefmt = utils_get_setting_string(config, "printing", "page_header_datefmt", "%c");
}
static void load_ui_prefs(GKeyFile *config)
{
gint *geo;
gsize geo_len;
ui_prefs.sidebar_visible = utils_get_setting_boolean(config, PACKAGE, "sidebar_visible", TRUE);
ui_prefs.msgwindow_visible = utils_get_setting_boolean(config, PACKAGE, "msgwindow_visible", TRUE);
ui_prefs.fullscreen = utils_get_setting_boolean(config, PACKAGE, "fullscreen", FALSE);
ui_prefs.custom_date_format = utils_get_setting_string(config, PACKAGE, "custom_date_format", "");
ui_prefs.custom_commands = g_key_file_get_string_list(config, PACKAGE, "custom_commands", NULL, NULL);
ui_prefs.custom_commands_labels = g_key_file_get_string_list(config, PACKAGE, "custom_commands_labels", NULL, NULL);
/* sanitize custom commands labels */
if (ui_prefs.custom_commands || ui_prefs.custom_commands_labels)
{
guint i;