2 * \file ToolbarBackend.C
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.
14 #include "ToolbarBackend.h"
15 #include "funcrequest.h"
16 #include "LyXAction.h"
21 #include "support/lstrings.h"
22 #include "support/filetools.h"
24 #include "frontends/controllers/ControlMath.h"
26 using lyx::support::compare_ascii_no_case;
27 using lyx::support::getVectorFromString;
28 using lyx::support::LibFileSearch;
29 using lyx::support::subst;
37 ToolbarBackend toolbarbackend;
50 struct keyword_item toolTags[TO_LAST - 1] = {
51 { "end", TO_ENDTOOLBAR },
53 { "layouts", TO_LAYOUTS },
54 { "minibuffer", TO_MINIBUFFER },
55 { "separator", TO_SEPARATOR }
58 } // end of anon namespace
61 ToolbarBackend::ToolbarBackend()
66 void ToolbarBackend::read(LyXLex & lex)
69 if (compare_ascii_no_case(lex.getString(), "toolbar")) {
70 lyxerr << "ToolbarBackend::read: ERROR wrong token:`"
71 << lex.getString() << '\'' << endl;
77 tb.name = lex.getString();
81 lex.pushTable(toolTags, TO_LAST - 1);
83 if (lyxerr.debugging(Debug::PARSER))
84 lex.printTable(lyxerr);
86 while (lex.isOK() && !quit) {
90 string const tooltip = _(lex.getString());
92 string const func = lex.getString();
94 << "ToolbarBackend::read TO_ADD func: `"
95 << func << '\'' << endl;
96 add(tb, func, tooltip);
116 lex.printError("ToolbarBackend::read: "
117 "Unknown toolbar tag: `$$Token'");
122 toolbars.push_back(tb);
128 void ToolbarBackend::readToolbars(LyXLex & lex)
131 if (compare_ascii_no_case(lex.getString(), "toolbars")) {
132 lyxerr << "ToolbarBackend::read: ERROR wrong token:`"
133 << lex.getString() << '\'' << endl;
139 string name = lex.getString();
142 if (!compare_ascii_no_case(name, "end"))
145 Toolbars::iterator tcit = toolbars.begin();
146 Toolbars::iterator tend = toolbars.end();
147 for (; tcit != tend; ++tcit) {
148 if (tcit->name == name)
153 lyxerr << "ToolbarBackend: undefined toolbar "
158 tcit->flags = static_cast<Flags>(0);
159 string flagstr = lex.getString();
161 vector<string> flags = getVectorFromString(flagstr);
163 vector<string>::const_iterator cit = flags.begin();
164 vector<string>::const_iterator end = flags.end();
166 for (; cit != end; ++cit) {
168 if (!compare_ascii_no_case(*cit, "off"))
170 else if (!compare_ascii_no_case(*cit, "on"))
172 else if (!compare_ascii_no_case(*cit, "math"))
174 else if (!compare_ascii_no_case(*cit, "table"))
176 else if (!compare_ascii_no_case(*cit, "top"))
178 else if (!compare_ascii_no_case(*cit, "bottom"))
180 else if (!compare_ascii_no_case(*cit, "left"))
182 else if (!compare_ascii_no_case(*cit, "right"))
185 lyxerr << "ToolbarBackend::read: unrecognised token:`"
186 << *cit << '\'' << endl;
188 tcit->flags = static_cast<Flags>(tcit->flags | flag);
191 usedtoolbars.push_back(*tcit);
196 void ToolbarBackend::add(Toolbar & tb, int action, string const & tooltip)
198 tb.items.push_back(make_pair(action, tooltip));
202 void ToolbarBackend::add(Toolbar & tb, string const & func, string const & tooltip)
204 int const tf = lyxaction.LookupFunc(func);
207 lyxerr << "ToolbarBackend::add: no LyX command called `"
208 << func << "' exists!" << endl;
210 add(tb, tf, tooltip);
215 string const ToolbarBackend::getIcon(int action)
218 FuncRequest f = lyxaction.retrieveActionArg(action);
220 if (f.action == LFUN_INSERT_MATH) {
221 if (!f.argument.empty())
222 fullname = find_xpm(f.argument.substr(1));
223 } else if (f.action == LFUN_MATH_DELIM) {
224 fullname = find_xpm(f.argument);
226 string const name = lyxaction.getActionName(f.action);
227 string xpm_name(name);
229 if (!f.argument.empty())
230 xpm_name = subst(name + ' ' + f.argument, ' ', '_');
232 fullname = LibFileSearch("images", xpm_name, "xpm");
234 if (fullname.empty()) {
235 // try without the argument
236 fullname = LibFileSearch("images", name, "xpm");
240 if (!fullname.empty()) {
241 lyxerr[Debug::GUI] << "Full icon name is `"
242 << fullname << '\'' << endl;
246 lyxerr[Debug::GUI] << "Cannot find icon for command \""
247 << lyxaction.getActionName(f.action)
248 << ' ' << f.argument << '"' << endl;
249 return LibFileSearch("images", "unknown", "xpm");