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