2 * \file ToolbarBackend.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS
13 #include "ToolbarBackend.h"
14 #include "LyXAction.h"
20 #include "support/lstrings.h"
21 #include "support/filetools.h"
23 #include "frontends/controllers/ControlMath.h"
30 ToolbarBackend toolbarbackend;
43 struct keyword_item toolTags[TO_LAST - 1] = {
44 { "end", TO_ENDTOOLBAR },
46 { "layouts", TO_LAYOUTS },
47 { "minibuffer", TO_MINIBUFFER },
48 { "separator", TO_SEPARATOR }
51 } // end of anon namespace
54 ToolbarBackend::ToolbarBackend()
59 void ToolbarBackend::read(LyXLex & lex)
62 if (compare_ascii_no_case(lex.getString(), "toolbar")) {
63 lyxerr << "ToolbarBackend::read: ERROR wrong token:`"
64 << lex.getString() << '\'' << endl;
70 tb.name = lex.getString();
73 tb.flags = static_cast<Flags>(0);
74 string flagstr = lex.getString();
75 vector<string> flags = getVectorFromString(flagstr);
77 vector<string>::const_iterator cit = flags.begin();
78 vector<string>::const_iterator end = flags.end();
80 for (; cit != end; ++cit) {
82 if (!compare_ascii_no_case(*cit, "off"))
84 else if (!compare_ascii_no_case(*cit, "on"))
86 else if (!compare_ascii_no_case(*cit, "math"))
88 else if (!compare_ascii_no_case(*cit, "table"))
90 else if (!compare_ascii_no_case(*cit, "top"))
92 else if (!compare_ascii_no_case(*cit, "bottom"))
94 else if (!compare_ascii_no_case(*cit, "left"))
96 else if (!compare_ascii_no_case(*cit, "right"))
99 lyxerr << "ToolbarBackend::read: unrecognised token:`"
100 << *cit << '\'' << endl;
102 tb.flags = static_cast<Flags>(tb.flags | flag);
107 lex.pushTable(toolTags, TO_LAST - 1);
109 if (lyxerr.debugging(Debug::PARSER))
110 lex.printTable(lyxerr);
112 while (lex.isOK() && !quit) {
115 if (lex.next(true)) {
116 string const tooltip = _(lex.getString());
118 string const func = lex.getString();
119 lyxerr[Debug::PARSER]
120 << "ToolbarBackend::read TO_ADD func: `"
121 << func << '\'' << endl;
122 add(tb, func, tooltip);
142 lex.printError("ToolbarBackend::read: "
143 "Unknown toolbar tag: `$$Token'");
148 toolbars.push_back(tb);
154 void ToolbarBackend::add(Toolbar & tb, int action, string const & tooltip)
156 tb.items.push_back(make_pair(action, tooltip));
160 void ToolbarBackend::add(Toolbar & tb, string const & func, string const & tooltip)
162 int const tf = lyxaction.LookupFunc(func);
165 lyxerr << "ToolbarBackend::add: no LyX command called `"
166 << func << "' exists!" << endl;
168 add(tb, tf, tooltip);
173 string const ToolbarBackend::getIcon(int action)
176 FuncRequest f = lyxaction.retrieveActionArg(action);
178 if (f.action == LFUN_INSERT_MATH) {
179 if (!f.argument.empty())
180 fullname = find_xpm(f.argument.substr(1));
181 } else if (f.action == LFUN_MATH_DELIM) {
182 fullname = find_xpm(f.argument);
184 string const name = lyxaction.getActionName(f.action);
185 string xpm_name(name);
187 if (!f.argument.empty())
188 xpm_name = subst(name + ' ' + f.argument, ' ', '_');
190 fullname = LibFileSearch("images", xpm_name, "xpm");
192 if (fullname.empty()) {
193 // try without the argument
194 fullname = LibFileSearch("images", name, "xpm");
198 if (!fullname.empty()) {
199 lyxerr[Debug::GUI] << "Full icon name is `"
200 << fullname << '\'' << endl;
204 return LibFileSearch("images", "unknown", "xpm");