]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlPrefs.C
12f6b7e07fcbef013ab929bea86810baa8aa01b9
[lyx.git] / src / frontends / controllers / ControlPrefs.C
1 /**
2  * \file ControlPrefs.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "ControlPrefs.h"
14
15 #include "helper_funcs.h"
16 #include "Kernel.h"
17
18 #include "bufferlist.h"
19 #include "gettext.h"
20 #include "funcrequest.h"
21 #include "LColor.h"
22
23 #include "support/filetools.h"
24 #include "support/globbing.h"
25 #include "support/path_defines.h"
26
27 #include "support/std_sstream.h"
28
29 using lyx::support::AddName;
30 using lyx::support::FileFilterList;
31 using lyx::support::system_lyxdir;
32 using lyx::support::user_lyxdir;
33
34 using std::ostringstream;
35 using std::pair;
36 using std::string;
37 using std::vector;
38
39
40 extern BufferList bufferlist;
41
42 ControlPrefs::ControlPrefs(Dialog & parent)
43         : Dialog::Controller(parent),
44           redraw_gui_(false),
45           update_screen_font_(false)
46 {}
47
48
49 bool ControlPrefs::initialiseParams(std::string const &)
50 {
51         rc_ = lyxrc;
52         formats_ = ::formats;
53         converters_ = ::converters;
54         converters_.update(formats_);
55         colors_.clear();
56         redraw_gui_ = false;
57         update_screen_font_ = false;
58
59         return true;
60 }
61
62
63 void ControlPrefs::dispatchParams()
64 {
65         ostringstream ss;
66         rc_.write(ss, true);
67         kernel().dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
68
69         // FIXME: these need lfuns
70         bufferlist.setCurrentAuthor(rc_.user_name, rc_.user_email);
71
72         ::formats = formats_;
73
74         ::converters = converters_;
75         ::converters.update(::formats);
76         ::converters.buildGraph();
77
78         vector<string>::const_iterator it = colors_.begin();
79         vector<string>::const_iterator const end = colors_.end();
80         for (; it != end; ++it)
81                 kernel().dispatch(FuncRequest(LFUN_SET_COLOR, *it));
82         colors_.clear();
83
84         if (redraw_gui_) {
85                 kernel().redrawGUI();
86                 redraw_gui_ = false;
87         }
88
89         if (update_screen_font_) {
90                 kernel().dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
91                 update_screen_font_ = false;
92         }
93
94         // The Save button has been pressed
95         if (dialog().isClosing()) {
96                 kernel().dispatch(FuncRequest(LFUN_SAVEPREFERENCES));
97         }
98 }
99
100
101 void ControlPrefs::redrawGUI()
102 {
103         redraw_gui_ = true;
104 }
105
106
107 void ControlPrefs::setColor(LColor_color col, string const & hex)
108 {
109         colors_.push_back(lcolor.getLyXName(col) + ' ' + hex);
110 }
111
112
113 void ControlPrefs::updateScreenFonts()
114 {
115         update_screen_font_ = true;
116 }
117
118
119 string const ControlPrefs::browsebind(string const & file) const
120 {
121         pair<string,string> dir1(_("System Bind|#S#s"),
122                                  AddName(system_lyxdir(), "bind"));
123
124         pair<string,string> dir2(_("User Bind|#U#u"),
125                                  AddName(user_lyxdir(), "bind"));
126
127         return browseFile(file, _("Choose bind file"),
128                           FileFilterList("*.bind"), false, dir1, dir2);
129 }
130
131
132 string const ControlPrefs::browseUI(string const & file) const
133 {
134         pair<string,string> const dir1(_("Sys UI|#S#s"),
135                                        AddName(system_lyxdir(), "ui"));
136
137         pair<string,string> const dir2(_("User UI|#U#u"),
138                                        AddName(user_lyxdir(), "ui"));
139
140         return browseFile(file, _("Choose UI file"),
141                           FileFilterList("*.ui"), false, dir1, dir2);
142 }
143
144
145 string const ControlPrefs::browsekbmap(string const & file) const
146 {
147         pair<string, string> dir(_("Key maps|#K#k"),
148                                  AddName(system_lyxdir(), "kbd"));
149
150         return browseFile(file, _("Choose keyboard map"),
151                           FileFilterList("*.kmap"), false, dir);
152 }
153
154
155 string const ControlPrefs::browsedict(string const & file) const
156 {
157         return browseFile(file, _("Choose personal dictionary"),
158                           FileFilterList("*.ispell"));
159 }
160
161
162 string const ControlPrefs::browse(string const & file,
163                                   string const & title) const
164 {
165         return browseFile(file, title, FileFilterList(), true);
166 }
167
168
169 string const ControlPrefs::browsedir(string const & path,
170                                      string const & title) const
171 {
172         return browseDir(path, title);
173 }