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;
35 class ToolbarNamesEqual
38 ToolbarNamesEqual(string const & name) : name_(name) {}
39 bool operator()(ToolbarInfo const & tbinfo) const
41 return tbinfo.name == name_;
50 /////////////////////////////////////////////////////////////////////////
54 /////////////////////////////////////////////////////////////////////////
56 ToolbarItem::ToolbarItem(Type type, FuncRequest const & func, docstring const & label)
57 : type_(type), func_(func), label_(label)
62 ToolbarItem::ToolbarItem(Type type, string const & name, docstring const & label)
63 : type_(type), label_(label), name_(name)
68 ToolbarItem::~ToolbarItem()
72 void ToolbarInfo::add(ToolbarItem const & item)
74 items.push_back(item);
75 items.back().func_.origin = FuncRequest::TOOLBAR;
79 ToolbarInfo & ToolbarInfo::read(Lexer & lex)
92 struct LexerKeyword toolTags[] = {
93 { "end", TO_ENDTOOLBAR },
94 { "iconpalette", TO_ICONPALETTE },
95 { "item", TO_COMMAND },
96 { "layouts", TO_LAYOUTS },
97 { "minibuffer", TO_MINIBUFFER },
98 { "popupmenu", TO_POPUPMENU },
99 { "separator", TO_SEPARATOR },
100 { "tableinsert", TO_TABLEINSERT }
104 if (compare_ascii_no_case(lex.getString(), "toolbar")) {
105 LYXERR0("ToolbarInfo::read: ERROR wrong token:`"
106 << lex.getString() << '\'');
110 name = lex.getString();
113 gui_name = lex.getString();
115 // FIXME what to do here?
117 LYXERR0("ToolbarInfo::read: Malformed toolbar "
118 "description " << lex.getString());
124 lex.pushTable(toolTags);
126 if (lyxerr.debugging(Debug::PARSER))
127 lex.printTable(lyxerr);
129 while (lex.isOK() && !quit) {
132 if (lex.next(true)) {
133 docstring const tooltip = translateIfPossible(lex.getDocString());
135 string const func_arg = lex.getString();
136 LYXERR(Debug::PARSER, "ToolbarInfo::read TO_COMMAND func: `"
137 << func_arg << '\'');
140 lyxaction.lookupFunc(func_arg);
141 add(ToolbarItem(ToolbarItem::COMMAND, func, tooltip));
146 add(ToolbarItem(ToolbarItem::MINIBUFFER,
147 FuncRequest(FuncCode(ToolbarItem::MINIBUFFER))));
151 add(ToolbarItem(ToolbarItem::SEPARATOR,
152 FuncRequest(FuncCode(ToolbarItem::SEPARATOR))));
156 if (lex.next(true)) {
157 string const name = lex.getString();
159 docstring const label = lex.getDocString();
160 add(ToolbarItem(ToolbarItem::POPUPMENU, name, label));
165 if (lex.next(true)) {
166 string const name = lex.getString();
168 docstring const label = lex.getDocString();
169 add(ToolbarItem(ToolbarItem::ICONPALETTE, name, label));
174 add(ToolbarItem(ToolbarItem::LAYOUTS,
175 FuncRequest(FuncCode(ToolbarItem::LAYOUTS))));
179 if (lex.next(true)) {
180 docstring const tooltip = lex.getDocString();
181 add(ToolbarItem(ToolbarItem::TABLEINSERT,
182 FuncRequest(FuncCode(ToolbarItem::TABLEINSERT)), tooltip));
191 lex.printError("ToolbarInfo::read: "
192 "Unknown toolbar tag: `$$Token'");
203 /////////////////////////////////////////////////////////////////////////
207 /////////////////////////////////////////////////////////////////////////
212 fullScreenWindows = 0;
216 void Toolbars::readToolbars(Lexer & lex)
223 struct LexerKeyword toolTags[] = {
224 { "end", TO_ENDTOOLBARSET },
225 { "toolbar", TO_TOOLBAR }
229 if (compare_ascii_no_case(lex.getString(), "toolbarset")) {
230 LYXERR0("Toolbars::readToolbars: ERROR wrong token:`"
231 << lex.getString() << '\'');
234 lex.pushTable(toolTags);
236 if (lyxerr.debugging(Debug::PARSER))
237 lex.printTable(lyxerr);
240 while (lex.isOK() && !quit) {
245 toolbars.push_back(tbinfo);
248 case TO_ENDTOOLBARSET:
252 lex.printError("Toolbars::readToolbars: "
253 "Unknown toolbar tag: `$$Token'");
262 void Toolbars::readToolbarSettings(Lexer & lex)
265 if (compare_ascii_no_case(lex.getString(), "toolbars")) {
266 LYXERR0("Toolbars::readToolbarSettings: ERROR wrong token:`"
267 << lex.getString() << '\'');
273 string name = lex.getString();
276 if (!compare_ascii_no_case(name, "end"))
279 Infos::iterator tcit = toolbars.begin();
280 Infos::iterator tend = toolbars.end();
281 for (; tcit != tend; ++tcit) {
282 if (tcit->name == name)
287 LYXERR0("Toolbars: undefined toolbar " << name);
291 tcit->flags = static_cast<ToolbarInfo::Flags>(0);
292 string flagstr = lex.getString();
294 vector<string> flags = getVectorFromString(flagstr);
296 vector<string>::const_iterator cit = flags.begin();
297 vector<string>::const_iterator end = flags.end();
299 for (; cit != end; ++cit) {
301 if (!compare_ascii_no_case(*cit, "off"))
302 flag = ToolbarInfo::OFF;
303 else if (!compare_ascii_no_case(*cit, "on"))
304 flag = ToolbarInfo::ON;
305 else if (!compare_ascii_no_case(*cit, "math"))
306 flag = ToolbarInfo::MATH;
307 else if (!compare_ascii_no_case(*cit, "table"))
308 flag = ToolbarInfo::TABLE;
309 else if (!compare_ascii_no_case(*cit, "mathmacrotemplate"))
310 flag = ToolbarInfo::MATHMACROTEMPLATE;
311 else if (!compare_ascii_no_case(*cit, "review"))
312 flag = ToolbarInfo::REVIEW;
313 else if (!compare_ascii_no_case(*cit, "top"))
314 flag = ToolbarInfo::TOP;
315 else if (!compare_ascii_no_case(*cit, "bottom"))
316 flag = ToolbarInfo::BOTTOM;
317 else if (!compare_ascii_no_case(*cit, "left"))
318 flag = ToolbarInfo::LEFT;
319 else if (!compare_ascii_no_case(*cit, "right"))
320 flag = ToolbarInfo::RIGHT;
321 else if (!compare_ascii_no_case(*cit, "auto"))
322 flag = ToolbarInfo::AUTO;
325 "Toolbars::readToolbarSettings: unrecognised token:`"
328 tcit->flags = static_cast<ToolbarInfo::Flags>(tcit->flags | flag);
331 usedtoolbars.push_back(*tcit);
336 ToolbarInfo const * Toolbars::getDefinedToolbarInfo(string const & name) const
338 Infos::const_iterator it = find_if(toolbars.begin(), toolbars.end(), ToolbarNamesEqual(name));
339 if (it == toolbars.end())
345 ToolbarInfo * Toolbars::getUsedToolbarInfo(string const &name)
347 Infos::iterator it = find_if(usedtoolbars.begin(), usedtoolbars.end(), ToolbarNamesEqual(name));
348 if (it == usedtoolbars.end())
353 } // namespace frontend