]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlPrefs.C
7d3f2c7fd592ce6705359e3361c9e229fc955809
[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 "LColor.h"
22
23 #include "support/filefilterlist.h"
24
25 #include <sstream>
26
27 using std::ostringstream;
28 using std::pair;
29 using std::string;
30 using std::vector;
31
32
33 extern BufferList bufferlist;
34
35 namespace lyx {
36
37 using support::FileFilterList;
38
39 namespace frontend {
40
41
42 ControlPrefs::ControlPrefs(Dialog & parent)
43         : Dialog::Controller(parent),
44           redraw_gui_(false),
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         redraw_gui_ = false;
58         update_screen_font_ = false;
59
60         return true;
61 }
62
63
64 void ControlPrefs::dispatchParams()
65 {
66         ostringstream ss;
67         rc_.write(ss, true);
68         kernel().dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
69
70         // FIXME: these need lfuns
71         bufferlist.setCurrentAuthor(rc_.user_name, rc_.user_email);
72
73         ::formats = formats_;
74
75         ::converters = converters_;
76         ::converters.update(::formats);
77         ::converters.buildGraph();
78
79         ::movers = movers_;
80
81         vector<string>::const_iterator it = colors_.begin();
82         vector<string>::const_iterator const end = colors_.end();
83         for (; it != end; ++it)
84                 kernel().dispatch(FuncRequest(LFUN_SET_COLOR, *it));
85         colors_.clear();
86
87         if (redraw_gui_) {
88                 kernel().redrawGUI();
89                 redraw_gui_ = false;
90         }
91
92         if (update_screen_font_) {
93                 kernel().dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
94                 update_screen_font_ = false;
95         }
96
97         // The Save button has been pressed
98         if (dialog().isClosing()) {
99                 kernel().dispatch(FuncRequest(LFUN_SAVEPREFERENCES));
100         }
101 }
102
103
104 void ControlPrefs::redrawGUI()
105 {
106         redraw_gui_ = true;
107 }
108
109
110 void ControlPrefs::setColor(LColor_color col, string const & hex)
111 {
112         colors_.push_back(lcolor.getLyXName(col) + ' ' + hex);
113 }
114
115
116 void ControlPrefs::updateScreenFonts()
117 {
118         update_screen_font_ = true;
119 }
120
121
122 string const ControlPrefs::browsebind(string const & file) const
123 {
124         return browseLibFile("bind", file, "bind", _("Choose bind file"),
125                           FileFilterList(_("LyX bind files (*.bind)")));
126 }
127
128
129 string const ControlPrefs::browseUI(string const & file) const
130 {
131         return browseLibFile("ui", file, "ui", _("Choose UI file"),
132                           FileFilterList(_("LyX UI files (*.ui)")));
133 }
134
135
136 string const ControlPrefs::browsekbmap(string const & file) const
137 {
138         return browseLibFile("kbd", file, "kmap", _("Choose keyboard map"),
139                           FileFilterList(_("LyX keyboard maps (*.kmap)")));
140 }
141
142
143 string const ControlPrefs::browsedict(string const & file) const
144 {
145         return browseFile(file, _("Choose personal dictionary"),
146                           FileFilterList(_("*.ispell")));
147 }
148
149
150 string const ControlPrefs::browse(string const & file,
151                                   string const & title) const
152 {
153         return browseFile(file, title, FileFilterList(), true);
154 }
155
156
157 string const ControlPrefs::browsedir(string const & path,
158                                      string const & title) const
159 {
160         return browseDir(path, title);
161 }
162
163 } // namespace frontend
164 } // namespace lyx