]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlPrefs.C
fix bug 895
[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_ = theConverters();
52         converters_.update(formats_);
53         movers_ = theMovers();
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         // FIXME UNICODE
69         theBufferList().setCurrentAuthor(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
70
71         lyx::formats = formats_;
72
73         theConverters() = converters_;
74         theConverters().update(lyx::formats);
75         theConverters().buildGraph();
76
77         theMovers() = movers_;
78
79         vector<string>::const_iterator it = colors_.begin();
80         vector<string>::const_iterator const end = colors_.end();
81         for (; it != end; ++it)
82                 kernel().dispatch(FuncRequest(LFUN_SET_COLOR, *it));
83         colors_.clear();
84
85         if (update_screen_font_) {
86                 kernel().dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
87                 update_screen_font_ = false;
88         }
89
90         // The Save button has been pressed
91         if (dialog().isClosing()) {
92                 kernel().dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
93         }
94 }
95
96
97 void ControlPrefs::setColor(LColor_color col, string const & hex)
98 {
99         colors_.push_back(lcolor.getLyXName(col) + ' ' + hex);
100 }
101
102
103 void ControlPrefs::updateScreenFonts()
104 {
105         update_screen_font_ = true;
106 }
107
108
109 docstring const ControlPrefs::browsebind(docstring const & file) const
110 {
111         return browseLibFile(lyx::from_ascii("bind"), file, lyx::from_ascii("bind"),
112                              _("Choose bind file"),
113                              FileFilterList(_("LyX bind files (*.bind)")));
114 }
115
116
117 docstring const ControlPrefs::browseUI(docstring const & file) const
118 {
119         return browseLibFile(lyx::from_ascii("ui"), file, lyx::from_ascii("ui"),
120                              _("Choose UI file"),
121                              FileFilterList(_("LyX UI files (*.ui)")));
122 }
123
124
125 docstring const ControlPrefs::browsekbmap(docstring const & file) const
126 {
127         return browseLibFile(lyx::from_ascii("kbd"), file, lyx::from_ascii("kmap"),
128                              _("Choose keyboard map"),
129                              FileFilterList(_("LyX keyboard maps (*.kmap)")));
130 }
131
132
133 docstring const ControlPrefs::browsedict(docstring const & file) const
134 {
135         if (lyxrc.use_spell_lib)
136                 return browseFile(file,
137                                   _("Choose personal dictionary"),
138                                   FileFilterList(_("*.pws")));
139         else
140                 return browseFile(file,
141                                   _("Choose personal dictionary"),
142                                   FileFilterList(_("*.ispell")));
143 }
144
145
146 docstring const ControlPrefs::browse(docstring const & file,
147                                   docstring const & title) const
148 {
149         return browseFile(file, title, FileFilterList(), true);
150 }
151
152
153 docstring const ControlPrefs::browsedir(docstring const & path,
154                                      docstring const & title) const
155 {
156         return browseDir(path, title);
157 }
158
159
160 // We support less paper sizes than the document dialog
161 // Therefore this adjustment is needed.
162 PAPER_SIZE const ControlPrefs::toPaperSize(int i) const
163 {
164         switch (i) {
165         case 0:
166                 return PAPER_DEFAULT;
167         case 1:
168                 return PAPER_USLETTER;
169         case 2:
170                 return PAPER_USLEGAL;
171         case 3:
172                 return PAPER_USEXECUTIVE;
173         case 4:
174                 return PAPER_A3;
175         case 5:
176                 return PAPER_A4;
177         case 6:
178                 return PAPER_A5;
179         case 7:
180                 return PAPER_B5;
181         default:
182                 // should not happen
183                 return PAPER_DEFAULT;
184         }
185 }
186
187
188 int const ControlPrefs::fromPaperSize(PAPER_SIZE papersize) const
189 {
190         switch (papersize) {
191         case PAPER_DEFAULT:
192                 return 0;
193         case PAPER_USLETTER:
194                 return 1;
195         case PAPER_USLEGAL:
196                 return 2;
197         case PAPER_USEXECUTIVE:
198                 return 3;
199         case PAPER_A3:
200                 return 4;
201         case PAPER_A4:
202                 return 5;
203         case PAPER_A5:
204                 return 6;
205         case PAPER_B5:
206                 return 7;
207         default:
208                 // should not happen
209                 return 0;
210         }
211 }
212
213 } // namespace frontend
214 } // namespace lyx