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