]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlPrefs.C
Wrap most of the frontend code up inside namespace lyx::frontend.
[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 std::ostringstream;
30 using std::pair;
31 using std::string;
32 using std::vector;
33
34
35 extern BufferList bufferlist;
36
37 namespace lyx {
38
39 using support::AddName;
40 using support::FileFilterList;
41 using support::system_lyxdir;
42 using support::user_lyxdir;
43
44 namespace frontend {
45
46
47 ControlPrefs::ControlPrefs(Dialog & parent)
48         : Dialog::Controller(parent),
49           redraw_gui_(false),
50           update_screen_font_(false)
51 {}
52
53
54 bool ControlPrefs::initialiseParams(std::string const &)
55 {
56         rc_ = lyxrc;
57         formats_ = ::formats;
58         converters_ = ::converters;
59         converters_.update(formats_);
60         colors_.clear();
61         redraw_gui_ = false;
62         update_screen_font_ = false;
63
64         return true;
65 }
66
67
68 void ControlPrefs::dispatchParams()
69 {
70         ostringstream ss;
71         rc_.write(ss, true);
72         kernel().dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
73
74         // FIXME: these need lfuns
75         bufferlist.setCurrentAuthor(rc_.user_name, rc_.user_email);
76
77         ::formats = formats_;
78
79         ::converters = converters_;
80         ::converters.update(::formats);
81         ::converters.buildGraph();
82
83         vector<string>::const_iterator it = colors_.begin();
84         vector<string>::const_iterator const end = colors_.end();
85         for (; it != end; ++it)
86                 kernel().dispatch(FuncRequest(LFUN_SET_COLOR, *it));
87         colors_.clear();
88
89         if (redraw_gui_) {
90                 kernel().redrawGUI();
91                 redraw_gui_ = false;
92         }
93
94         if (update_screen_font_) {
95                 kernel().dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
96                 update_screen_font_ = false;
97         }
98
99         // The Save button has been pressed
100         if (dialog().isClosing()) {
101                 kernel().dispatch(FuncRequest(LFUN_SAVEPREFERENCES));
102         }
103 }
104
105
106 void ControlPrefs::redrawGUI()
107 {
108         redraw_gui_ = true;
109 }
110
111
112 void ControlPrefs::setColor(LColor_color col, string const & hex)
113 {
114         colors_.push_back(lcolor.getLyXName(col) + ' ' + hex);
115 }
116
117
118 void ControlPrefs::updateScreenFonts()
119 {
120         update_screen_font_ = true;
121 }
122
123
124 string const ControlPrefs::browsebind(string const & file) const
125 {
126         pair<string,string> dir1(_("System Bind|#S#s"),
127                                  AddName(system_lyxdir(), "bind"));
128
129         pair<string,string> dir2(_("User Bind|#U#u"),
130                                  AddName(user_lyxdir(), "bind"));
131
132         return browseFile(file, _("Choose bind file"),
133                           FileFilterList("*.bind"), false, dir1, dir2);
134 }
135
136
137 string const ControlPrefs::browseUI(string const & file) const
138 {
139         pair<string,string> const dir1(_("Sys UI|#S#s"),
140                                        AddName(system_lyxdir(), "ui"));
141
142         pair<string,string> const dir2(_("User UI|#U#u"),
143                                        AddName(user_lyxdir(), "ui"));
144
145         return browseFile(file, _("Choose UI file"),
146                           FileFilterList("*.ui"), false, dir1, dir2);
147 }
148
149
150 string const ControlPrefs::browsekbmap(string const & file) const
151 {
152         pair<string, string> dir(_("Key maps|#K#k"),
153                                  AddName(system_lyxdir(), "kbd"));
154
155         return browseFile(file, _("Choose keyboard map"),
156                           FileFilterList("*.kmap"), false, dir);
157 }
158
159
160 string const ControlPrefs::browsedict(string const & file) const
161 {
162         return browseFile(file, _("Choose personal dictionary"),
163                           FileFilterList("*.ispell"));
164 }
165
166
167 string const ControlPrefs::browse(string const & file,
168                                   string const & title) const
169 {
170         return browseFile(file, title, FileFilterList(), true);
171 }
172
173
174 string const ControlPrefs::browsedir(string const & path,
175                                      string const & title) const
176 {
177         return browseDir(path, title);
178 }
179
180 } // namespace frontend
181 } // namespace lyx