]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlPrefs.C
move everything into namespace lyx
[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 "paper.h"
22 #include "LColor.h"
23
24 #include "support/filefilterlist.h"
25
26 #include <sstream>
27
28 using lyx::docstring;
29
30 using std::ostringstream;
31 using std::pair;
32 using std::string;
33 using std::vector;
34 using lyx::support::FileFilterList;
35
36 namespace lyx {
37
38 namespace frontend {
39
40
41 ControlPrefs::ControlPrefs(Dialog & parent)
42         : Dialog::Controller(parent),
43           update_screen_font_(false)
44 {}
45
46
47 bool ControlPrefs::initialiseParams(std::string const &)
48 {
49         rc_ = lyxrc;
50         formats_ = lyx::formats;
51         converters_ = lyx::converters;
52         converters_.update(formats_);
53         movers_ = lyx::movers;
54         colors_.clear();
55         update_screen_font_ = false;
56
57         return true;
58 }
59
60
61 void ControlPrefs::dispatchParams()
62 {
63         ostringstream ss;
64         rc_.write(ss, true);
65         kernel().dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
66
67         // FIXME: these need lfuns
68         theBufferList().setCurrentAuthor(rc_.user_name, rc_.user_email);
69
70         lyx::formats = formats_;
71
72         lyx::converters = converters_;
73         lyx::converters.update(lyx::formats);
74         lyx::converters.buildGraph();
75
76         lyx::movers = movers_;
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 (update_screen_font_) {
85                 kernel().dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
86                 update_screen_font_ = false;
87         }
88
89         // The Save button has been pressed
90         if (dialog().isClosing()) {
91                 kernel().dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
92         }
93 }
94
95
96 void ControlPrefs::setColor(LColor_color col, string const & hex)
97 {
98         colors_.push_back(lcolor.getLyXName(col) + ' ' + hex);
99 }
100
101
102 void ControlPrefs::updateScreenFonts()
103 {
104         update_screen_font_ = true;
105 }
106
107
108 docstring const ControlPrefs::browsebind(docstring const & file) const
109 {
110         return browseLibFile(lyx::from_ascii("bind"), file, lyx::from_ascii("bind"),
111                              _("Choose bind file"),
112                              FileFilterList(_("LyX bind files (*.bind)")));
113 }
114
115
116 docstring const ControlPrefs::browseUI(docstring const & file) const
117 {
118         return browseLibFile(lyx::from_ascii("ui"), file, lyx::from_ascii("ui"),
119                              _("Choose UI file"),
120                              FileFilterList(_("LyX UI files (*.ui)")));
121 }
122
123
124 docstring const ControlPrefs::browsekbmap(docstring const & file) const
125 {
126         return browseLibFile(lyx::from_ascii("kbd"), file, lyx::from_ascii("kmap"),
127                              _("Choose keyboard map"),
128                              FileFilterList(_("LyX keyboard maps (*.kmap)")));
129 }
130
131
132 docstring const ControlPrefs::browsedict(docstring const & file) const
133 {
134         return browseFile(file,
135                           _("Choose personal dictionary"),
136                           FileFilterList(_("*.ispell")));
137 }
138
139
140 docstring const ControlPrefs::browse(docstring const & file,
141                                   docstring const & title) const
142 {
143         return browseFile(file, title, FileFilterList(), true);
144 }
145
146
147 docstring const ControlPrefs::browsedir(docstring const & path,
148                                      docstring const & title) const
149 {
150         return browseDir(path, title);
151 }
152
153
154 // We support less paper sizes than the document dialog
155 // Therefore this adjustment is needed.
156 PAPER_SIZE const ControlPrefs::toPaperSize(int i) const
157 {
158         switch (i) {
159         case 0:
160                 return PAPER_DEFAULT;
161         case 1:
162                 return PAPER_USLETTER;
163         case 2:
164                 return PAPER_USLEGAL;
165         case 3:
166                 return PAPER_USEXECUTIVE;
167         case 4:
168                 return PAPER_A3;
169         case 5:
170                 return PAPER_A4;
171         case 6:
172                 return PAPER_A5;
173         case 7:
174                 return PAPER_B5;
175         default:
176                 // should not happen
177                 return PAPER_DEFAULT;
178         }
179 }
180
181
182 int const ControlPrefs::fromPaperSize(PAPER_SIZE papersize) const
183 {
184         switch (papersize) {
185         case PAPER_DEFAULT:
186                 return 0;
187         case PAPER_USLETTER:
188                 return 1;
189         case PAPER_USLEGAL:
190                 return 2;
191         case PAPER_USEXECUTIVE:
192                 return 3;
193         case PAPER_A3:
194                 return 4;
195         case PAPER_A4:
196                 return 5;
197         case PAPER_A5:
198                 return 6;
199         case PAPER_B5:
200                 return 7;
201         default:
202                 // should not happen
203                 return 0;
204         }
205 }
206
207 } // namespace frontend
208 } // namespace lyx