]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlPrefs.C
5 new lfuns, move all apply code out of ControlDocument and into the core.
[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 "ViewBase.h"
17
18 #include "bufferlist.h"
19 #include "converter.h"
20 #include "format.h"
21 #include "gettext.h"
22 #include "funcrequest.h"
23 #include "LColor.h"
24 #include "lfuns.h"
25
26 #include "frontends/Dialogs.h"
27 #include "frontends/LyXView.h"
28
29 #include "support/filetools.h"
30 #include "support/globbing.h"
31 #include "support/path_defines.h"
32
33 #include <utility>
34
35 using lyx::support::AddName;
36 using lyx::support::FileFilterList;
37 using lyx::support::system_lyxdir;
38 using lyx::support::user_lyxdir;
39
40 using std::pair;
41 using std::string;
42
43
44 extern BufferList bufferlist;
45
46 ControlPrefs::ControlPrefs(LyXView & lv, Dialogs & d)
47         : ControlDialogBI(lv, d)
48 {}
49
50
51 void ControlPrefs::setParams()
52 {
53         rc_ = lyxrc;
54 }
55
56
57 void ControlPrefs::apply()
58 {
59         view().apply();
60         lyxrc = rc_;
61
62         bufferlist.setCurrentAuthor(rc_.user_name, rc_.user_email);
63
64         // The Save button has been pressed
65         if (isClosing()) {
66                 lv_.dispatch(FuncRequest(LFUN_SAVEPREFERENCES));
67         }
68 }
69
70
71 string const ControlPrefs::browsebind(string const & file) const
72 {
73         string dir  = AddName(system_lyxdir(), "bind");
74         // FIXME: stupid name
75         string name = _("System Bind|#S#s");
76         pair<string,string> dir1(name, dir);
77
78         dir = AddName(user_lyxdir(), "bind");
79         // FIXME: stupid name
80         name = _("User Bind|#U#u");
81         pair<string,string> dir2(name, dir);
82
83         return browseFile(file, _("Choose bind file"),
84                           FileFilterList("*.bind"), false, dir1, dir2);
85 }
86
87
88 string const ControlPrefs::browseUI(string const & file) const
89 {
90         string dir  = AddName(system_lyxdir(), "ui");
91         // FIXME: stupid name
92         string name = _("Sys UI|#S#s");
93         pair<string,string> dir1(name, dir);
94
95         dir = AddName(user_lyxdir(), "ui");
96         // FIXME: stupid name
97         name = _("User UI|#U#u");
98         pair<string,string> dir2(name, dir);
99
100         return browseFile(file, _("Choose UI file"),
101                           FileFilterList("*.ui"), false, dir1, dir2);
102 }
103
104
105 string const ControlPrefs::browsekbmap(string const & file) const
106 {
107         string const dir = AddName(system_lyxdir(), "kbd");
108         string const name = _("Key maps|#K#k");
109         pair<string, string> dir1(name, dir);
110
111         return browseFile(file, _("Choose keyboard map"),
112                           FileFilterList("*.kmap"), false, dir1);
113 }
114
115
116 string const ControlPrefs::browsedict(string const & file) const
117 {
118         return browseFile(file, _("Choose personal dictionary"),
119                           FileFilterList("*.ispell"));
120 }
121
122
123 string const ControlPrefs::browse(string const & file,
124                                   string const & title) const
125 {
126         return browseFile(file, title, FileFilterList(), true);
127 }
128
129
130 string const ControlPrefs::browsedir(string const & path,
131                                      string const & title) const
132 {
133         return browseDir(path, title);
134 }
135
136
137 void ControlPrefs::redrawGUI()
138 {
139         // we must be sure to get the new values first
140         lyxrc = rc_;
141
142         lv_.getDialogs().redrawGUI();
143 }
144
145
146 void ControlPrefs::setColor(LColor_color col, string const & hex)
147 {
148         string const s = lcolor.getLyXName(col) + ' ' + hex;
149         lv_.dispatch(FuncRequest(LFUN_SET_COLOR, s));
150 }
151
152
153 void ControlPrefs::updateScreenFonts()
154 {
155         // we must be sure to get the new values first
156         lyxrc = rc_;
157
158         lv_.dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
159 }
160
161
162 void ControlPrefs::setConverters(Converters const & conv)
163 {
164         converters = conv;
165         converters.update(formats);
166         converters.buildGraph();
167 }
168
169
170 void ControlPrefs::setFormats(Formats const & form)
171 {
172         formats = form;
173 }