source: src/i4ucconfiguration.vala @ b69edd1f9a76705089583267e077d4894eacf5bf

Revision b69edd1f9a76705089583267e077d4894eacf5bf, 3.8 KB checked in by Matias De la Puente <mfpuente.ar@…>, 4 years ago (diff)

Add source files preferences page

This page will be used to configure the font, tab width, auto indent,
highlight current line, insert spaces instead of tabs and show line
numbers of the source files pages

  • Property mode set to 100644
Line 
1/* i4ucconfiguration.vala
2 *
3 * Copyright (C) 2009  Matias De la Puente
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Author:
19 *      Matias De la Puente <mfpuente.ar@gmail.com>
20 */
21
22public class I4uc.Configuration: GLib.Object
23{
24        private const string _I4UC_CONFIG = "i4uc config";
25        private const string _SOURCE_FILES_CONFIG = "Source files preferences";
26       
27        private static Configuration _config;
28        private string _filename;
29       
30        public bool is_open { set; get; }
31        public bool projects_panel_visible { set; get; }
32        public bool logs_panel_visible { set; get; }
33       
34        public string source_files_font { set; get; default = "Monospace 11"; }
35        public int source_files_tab_width { set; get; default = 8; }
36        public bool source_files_auto_indent { set; get; }
37        public bool source_files_highlight_current_line { set; get; }
38        public bool source_files_insert_spaces_instead_of_tabs { set; get; }
39        public bool source_files_show_line_numbers { set; get; }
40
41        public static Configuration get_instance ()
42        {
43                if (_config == null)
44                        _config = new Configuration ();
45                return _config;
46        }
47       
48        public bool open ()
49        {
50                _filename = Path.build_filename (Environment.get_home_dir (), ".config", "i4uc.conf");
51                if (!FileUtils.test (Path.get_dirname (_filename), FileTest.EXISTS))
52                        DirUtils.create (Path.get_dirname (_filename), 0700);
53               
54                if (!FileUtils.test (_filename, FileTest.EXISTS))
55                        return false;
56               
57                var key_file = new KeyFile ();
58                if (!key_file.load_from_file (_filename, KeyFileFlags.NONE))
59                {
60                        print ("Error opening %s", _filename);
61                        this.is_open = false;
62                        return false;
63                }
64               
65                this.projects_panel_visible = key_file.get_boolean (_I4UC_CONFIG, "projects_panel_visible");
66                this.logs_panel_visible = key_file.get_boolean (_I4UC_CONFIG, "logs_panel_visible");
67               
68                this.source_files_font = key_file.get_string (_SOURCE_FILES_CONFIG, "font");
69                this.source_files_tab_width = key_file.get_integer (_SOURCE_FILES_CONFIG, "tab_width");
70                this.source_files_auto_indent = key_file.get_boolean (_SOURCE_FILES_CONFIG, "auto_indent");
71                this.source_files_highlight_current_line = key_file.get_boolean (_SOURCE_FILES_CONFIG, "highlight_current_line");
72                this.source_files_insert_spaces_instead_of_tabs = key_file.get_boolean (_SOURCE_FILES_CONFIG, "insert_spaces_instead_of_tabs");
73                this.source_files_show_line_numbers = key_file.get_boolean (_SOURCE_FILES_CONFIG, "show_line_numbers");
74               
75                this.is_open = true;
76                return true;
77        }
78       
79        public void save ()
80        {
81                var key_file = new KeyFile ();
82               
83                key_file.set_boolean (_I4UC_CONFIG, "projects_panel_visible", _projects_panel_visible);
84                key_file.set_boolean (_I4UC_CONFIG, "logs_panel_visible", _logs_panel_visible);
85               
86                key_file.set_string (_SOURCE_FILES_CONFIG, "font", _source_files_font);
87                key_file.set_integer (_SOURCE_FILES_CONFIG, "tab_width", _source_files_tab_width);
88                key_file.set_boolean (_SOURCE_FILES_CONFIG, "auto_indent", _source_files_auto_indent);
89                key_file.set_boolean (_SOURCE_FILES_CONFIG, "highlight_current_line", _source_files_highlight_current_line);
90                key_file.set_boolean (_SOURCE_FILES_CONFIG, "insert_spaces_instead_of_tabs", _source_files_insert_spaces_instead_of_tabs);
91                key_file.set_boolean (_SOURCE_FILES_CONFIG, "show_line_numbers", _source_files_show_line_numbers);
92               
93                FileUtils.set_contents (_filename, key_file.to_data (null));
94        }
95}
Note: See TracBrowser for help on using the repository browser.