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