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 "support/lstrings.h"
20 #include "support/debug.h"
21 #include "support/gettext.h"
23 #include <boost/bind.hpp>
28 using namespace lyx::support;
38 /////////////////////////////////////////////////////////////////////////
42 /////////////////////////////////////////////////////////////////////////
44 ToolbarItem::ToolbarItem(Type type, FuncRequest const & func, docstring const & label)
45 : type_(type), func_(func), label_(label)
50 ToolbarItem::ToolbarItem(Type type, string const & name, docstring const & label)
51 : type_(type), label_(label), name_(name)
56 void ToolbarInfo::add(ToolbarItem const & item)
58 items.push_back(item);
59 items.back().func_.origin = FuncRequest::TOOLBAR;
63 ToolbarInfo & ToolbarInfo::read(Lexer & lex)
76 struct LexerKeyword toolTags[] = {
77 { "end", TO_ENDTOOLBAR },
78 { "iconpalette", TO_ICONPALETTE },
79 { "item", TO_COMMAND },
80 { "layouts", TO_LAYOUTS },
81 { "minibuffer", TO_MINIBUFFER },
82 { "popupmenu", TO_POPUPMENU },
83 { "separator", TO_SEPARATOR },
84 { "tableinsert", TO_TABLEINSERT }
88 if (compare_ascii_no_case(lex.getString(), "toolbar")) {
89 LYXERR0("ToolbarInfo::read: ERROR wrong token:`"
90 << lex.getString() << '\'');
94 name = lex.getString();
97 gui_name = lex.getString();
99 // FIXME what to do here?
101 LYXERR0("ToolbarInfo::read: Malformed toolbar "
102 "description " << lex.getString());
108 lex.pushTable(toolTags);
110 if (lyxerr.debugging(Debug::PARSER))
111 lex.printTable(lyxerr);
113 while (lex.isOK() && !quit) {
116 if (lex.next(true)) {
117 docstring const tooltip = translateIfPossible(lex.getDocString());
119 string const func_arg = lex.getString();
120 LYXERR(Debug::PARSER, "ToolbarInfo::read TO_COMMAND func: `"
121 << func_arg << '\'');
124 lyxaction.lookupFunc(func_arg);
125 add(ToolbarItem(ToolbarItem::COMMAND, func, tooltip));
130 add(ToolbarItem(ToolbarItem::MINIBUFFER,
131 FuncRequest(FuncCode(ToolbarItem::MINIBUFFER))));
135 add(ToolbarItem(ToolbarItem::SEPARATOR,
136 FuncRequest(FuncCode(ToolbarItem::SEPARATOR))));
140 if (lex.next(true)) {
141 string const name = lex.getString();
143 docstring const label = lex.getDocString();
144 add(ToolbarItem(ToolbarItem::POPUPMENU, name, label));
149 if (lex.next(true)) {
150 string const name = lex.getString();
152 docstring const label = lex.getDocString();
153 add(ToolbarItem(ToolbarItem::ICONPALETTE, name, label));
158 add(ToolbarItem(ToolbarItem::LAYOUTS,
159 FuncRequest(FuncCode(ToolbarItem::LAYOUTS))));
163 if (lex.next(true)) {
164 docstring const tooltip = lex.getDocString();
165 add(ToolbarItem(ToolbarItem::TABLEINSERT,
166 FuncRequest(FuncCode(ToolbarItem::TABLEINSERT)), tooltip));
175 lex.printError("ToolbarInfo::read: "
176 "Unknown toolbar tag: `$$Token'");
187 /////////////////////////////////////////////////////////////////////////
191 /////////////////////////////////////////////////////////////////////////
194 void Toolbars::readToolbars(Lexer & lex)
201 struct LexerKeyword toolTags[] = {
202 { "end", TO_ENDTOOLBARSET },
203 { "toolbar", TO_TOOLBAR }
207 if (compare_ascii_no_case(lex.getString(), "toolbarset")) {
208 LYXERR0("Toolbars::readToolbars: ERROR wrong token:`"
209 << lex.getString() << '\'');
212 lex.pushTable(toolTags);
214 if (lyxerr.debugging(Debug::PARSER))
215 lex.printTable(lyxerr);
218 while (lex.isOK() && !quit) {
223 toolbar_info_.push_back(tbinfo);
226 case TO_ENDTOOLBARSET:
230 lex.printError("Toolbars::readToolbars: "
231 "Unknown toolbar tag: `$$Token'");
240 void Toolbars::readToolbarSettings(Lexer & lex)
243 if (compare_ascii_no_case(lex.getString(), "toolbars")) {
244 LYXERR0("Toolbars::readToolbarSettings: ERROR wrong token:`"
245 << lex.getString() << '\'');
251 string name = lex.getString();
254 if (!compare_ascii_no_case(name, "end"))
258 string flagstr = lex.getString();
260 vector<string> flags = getVectorFromString(flagstr);
262 vector<string>::const_iterator cit = flags.begin();
263 vector<string>::const_iterator end = flags.end();
265 for (; cit != end; ++cit) {
266 Visibility flag = ON;
267 if (!compare_ascii_no_case(*cit, "off"))
269 else if (!compare_ascii_no_case(*cit, "on"))
271 else if (!compare_ascii_no_case(*cit, "math"))
273 else if (!compare_ascii_no_case(*cit, "table"))
275 else if (!compare_ascii_no_case(*cit, "mathmacrotemplate"))
276 flag = MATHMACROTEMPLATE;
277 else if (!compare_ascii_no_case(*cit, "review"))
279 else if (!compare_ascii_no_case(*cit, "top"))
281 else if (!compare_ascii_no_case(*cit, "bottom"))
283 else if (!compare_ascii_no_case(*cit, "left"))
285 else if (!compare_ascii_no_case(*cit, "right"))
287 else if (!compare_ascii_no_case(*cit, "auto"))
291 "Toolbars::readToolbarSettings: unrecognised token:`"
297 toolbar_visibility_[name] = visibility;
299 if (visibility >= MATH) {
300 if (ToolbarInfo const * ti = info(name))
301 const_cast<ToolbarInfo *>(ti)->gui_name += " (auto)";
307 ToolbarInfo const * Toolbars::info(std::string const & name) const
309 Infos::const_iterator end = toolbar_info_.end();
310 for (Infos::const_iterator it = toolbar_info_.begin(); it != end; ++it)
311 if (it->name == name)
317 int Toolbars::defaultVisibility(std::string const & name) const
319 map<string, int>::const_iterator it = toolbar_visibility_.find(name);
320 if (it != toolbar_visibility_.end())
326 bool Toolbars::isMainToolbar(std::string const & name) const
328 return toolbar_visibility_.find(name) != toolbar_visibility_.end();
332 } // namespace frontend