]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlPrefs.C
make browsing for lyxdir files DTRT
[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/globbing.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         colors_.clear();
56         redraw_gui_ = false;
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         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 (redraw_gui_) {
85                 kernel().redrawGUI();
86                 redraw_gui_ = false;
87         }
88
89         if (update_screen_font_) {
90                 kernel().dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
91                 update_screen_font_ = false;
92         }
93
94         // The Save button has been pressed
95         if (dialog().isClosing()) {
96                 kernel().dispatch(FuncRequest(LFUN_SAVEPREFERENCES));
97         }
98 }
99
100
101 void ControlPrefs::redrawGUI()
102 {
103         redraw_gui_ = true;
104 }
105
106
107 void ControlPrefs::setColor(LColor_color col, string const & hex)
108 {
109         colors_.push_back(lcolor.getLyXName(col) + ' ' + hex);
110 }
111
112
113 void ControlPrefs::updateScreenFonts()
114 {
115         update_screen_font_ = true;
116 }
117
118
119 string const ControlPrefs::browsebind(string const & file) const
120 {
121         return browseLibFile("bind", file, "bind", _("Choose bind file"),
122                           FileFilterList("LyX bind files (*.bind)"));
123 }
124
125
126 string const ControlPrefs::browseUI(string const & file) const
127 {
128         return browseLibFile("ui", file, "ui", _("Choose UI file"),
129                           FileFilterList("LyX UI files (*.ui)"));
130 }
131
132
133 string const ControlPrefs::browsekbmap(string const & file) const
134 {
135         return browseLibFile("kbd", file, "kmap", _("Choose keyboard map"),
136                           FileFilterList("LyX keyboard maps (*.kmap)"));
137 }
138
139
140 string const ControlPrefs::browsedict(string const & file) const
141 {
142         return browseFile(file, _("Choose personal dictionary"),
143                           FileFilterList("*.ispell"));
144 }
145
146
147 string const ControlPrefs::browse(string const & file,
148                                   string const & title) const
149 {
150         return browseFile(file, title, FileFilterList(), true);
151 }
152
153
154 string const ControlPrefs::browsedir(string const & path,
155                                      string const & title) const
156 {
157         return browseDir(path, title);
158 }
159
160 } // namespace frontend
161 } // namespace lyx