3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Jean-Marc Lasgouttes
9 * Full author contact details are available in file CREDITS.
15 #include "FuncRequest.h"
17 #include "LyXAction.h"
18 #include "qt_helpers.h"
20 #include "support/debug.h"
21 #include "support/gettext.h"
22 #include "support/lstrings.h"
24 #include <boost/bind.hpp>
29 using namespace lyx::support;
39 /////////////////////////////////////////////////////////////////////////
43 /////////////////////////////////////////////////////////////////////////
45 ToolbarItem::ToolbarItem(Type type, FuncRequest const & func, docstring const & label)
46 : type_(type), func_(func), label_(label)
51 ToolbarItem::ToolbarItem(Type type, string const & name, docstring const & label)
52 : type_(type), label_(label), name_(name)
57 void ToolbarInfo::add(ToolbarItem const & item)
59 items.push_back(item);
60 items.back().func_.origin = FuncRequest::TOOLBAR;
64 ToolbarInfo & ToolbarInfo::read(Lexer & lex)
77 struct LexerKeyword toolTags[] = {
78 { "end", TO_ENDTOOLBAR },
79 { "iconpalette", TO_ICONPALETTE },
80 { "item", TO_COMMAND },
81 { "layouts", TO_LAYOUTS },
82 { "minibuffer", TO_MINIBUFFER },
83 { "popupmenu", TO_POPUPMENU },
84 { "separator", TO_SEPARATOR },
85 { "tableinsert", TO_TABLEINSERT }
89 if (compare_ascii_no_case(lex.getString(), "toolbar")) {
90 LYXERR0("ToolbarInfo::read: ERROR wrong token:`"
91 << lex.getString() << '\'');
95 name = lex.getString();
98 gui_name = fromqstr(qt_(lex.getString()));
100 // FIXME what to do here?
102 LYXERR0("ToolbarInfo::read: Malformed toolbar "
103 "description " << lex.getString());
109 lex.pushTable(toolTags);
111 if (lyxerr.debugging(Debug::PARSER))
112 lex.printTable(lyxerr);
114 while (lex.isOK() && !quit) {
117 if (lex.next(true)) {
118 docstring const tooltip = translateIfPossible(lex.getDocString());
120 string const func_arg = lex.getString();
121 LYXERR(Debug::PARSER, "ToolbarInfo::read TO_COMMAND func: `"
122 << func_arg << '\'');
125 lyxaction.lookupFunc(func_arg);
126 add(ToolbarItem(ToolbarItem::COMMAND, func, tooltip));
131 add(ToolbarItem(ToolbarItem::MINIBUFFER,
132 FuncRequest(FuncCode(ToolbarItem::MINIBUFFER))));
136 add(ToolbarItem(ToolbarItem::SEPARATOR,
137 FuncRequest(FuncCode(ToolbarItem::SEPARATOR))));
141 if (lex.next(true)) {
142 string const name = lex.getString();
144 docstring const label = lex.getDocString();
145 add(ToolbarItem(ToolbarItem::POPUPMENU, name, label));
150 if (lex.next(true)) {
151 string const name = lex.getString();
153 docstring const label = lex.getDocString();
154 add(ToolbarItem(ToolbarItem::ICONPALETTE, name, label));
159 add(ToolbarItem(ToolbarItem::LAYOUTS,
160 FuncRequest(FuncCode(ToolbarItem::LAYOUTS))));
164 if (lex.next(true)) {
165 docstring const tooltip = lex.getDocString();
166 add(ToolbarItem(ToolbarItem::TABLEINSERT,
167 FuncRequest(FuncCode(ToolbarItem::TABLEINSERT)), tooltip));
176 lex.printError("ToolbarInfo::read: "
177 "Unknown toolbar tag: `$$Token'");
188 /////////////////////////////////////////////////////////////////////////
192 /////////////////////////////////////////////////////////////////////////
194 void Toolbars::reset()
196 toolbar_info_.clear();
197 toolbar_visibility_.clear();
201 void Toolbars::readToolbars(Lexer & lex)
208 struct LexerKeyword toolTags[] = {
209 { "end", TO_ENDTOOLBARSET },
210 { "toolbar", TO_TOOLBAR }
214 if (compare_ascii_no_case(lex.getString(), "toolbarset")) {
215 LYXERR0("Toolbars::readToolbars: ERROR wrong token:`"
216 << lex.getString() << '\'');
219 lex.pushTable(toolTags);
221 if (lyxerr.debugging(Debug::PARSER))
222 lex.printTable(lyxerr);
225 while (lex.isOK() && !quit) {
230 toolbar_info_.push_back(tbinfo);
233 case TO_ENDTOOLBARSET:
237 lex.printError("Toolbars::readToolbars: "
238 "Unknown toolbar tag: `$$Token'");
247 void Toolbars::readToolbarSettings(Lexer & lex)
250 if (compare_ascii_no_case(lex.getString(), "toolbars")) {
251 LYXERR0("Toolbars::readToolbarSettings: ERROR wrong token:`"
252 << lex.getString() << '\'');
258 string name = lex.getString();
261 if (!compare_ascii_no_case(name, "end"))
265 string flagstr = lex.getString();
267 vector<string> flags = getVectorFromString(flagstr);
269 vector<string>::const_iterator cit = flags.begin();
270 vector<string>::const_iterator end = flags.end();
272 for (; cit != end; ++cit) {
273 Visibility flag = ON;
274 if (!compare_ascii_no_case(*cit, "off"))
276 else if (!compare_ascii_no_case(*cit, "on"))
278 else if (!compare_ascii_no_case(*cit, "math"))
280 else if (!compare_ascii_no_case(*cit, "table"))
282 else if (!compare_ascii_no_case(*cit, "mathmacrotemplate"))
283 flag = MATHMACROTEMPLATE;
284 else if (!compare_ascii_no_case(*cit, "review"))
286 else if (!compare_ascii_no_case(*cit, "top"))
288 else if (!compare_ascii_no_case(*cit, "bottom"))
290 else if (!compare_ascii_no_case(*cit, "left"))
292 else if (!compare_ascii_no_case(*cit, "right"))
294 else if (!compare_ascii_no_case(*cit, "auto"))
298 "Toolbars::readToolbarSettings: unrecognised token:`"
304 toolbar_visibility_[name] = visibility;
306 if (visibility >= MATH) {
307 if (ToolbarInfo const * ti = info(name))
308 const_cast<ToolbarInfo *>(ti)->gui_name +=
309 fromqstr(" (" + qt_("auto") + ")");
315 ToolbarInfo const * Toolbars::info(std::string const & name) const
317 Infos::const_iterator end = toolbar_info_.end();
318 for (Infos::const_iterator it = toolbar_info_.begin(); it != end; ++it)
319 if (it->name == name)
325 int Toolbars::defaultVisibility(std::string const & name) const
327 map<string, int>::const_iterator it = toolbar_visibility_.find(name);
328 if (it != toolbar_visibility_.end())
334 bool Toolbars::isMainToolbar(std::string const & name) const
336 return toolbar_visibility_.find(name) != toolbar_visibility_.end();
340 } // namespace frontend