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();
80 lyxerr << "ToolbarBackend::read: Malformed toolbar "
81 "description " << lex.getString() << endl;
84 tb.gui_name = lex.getString();
88 lex.pushTable(toolTags, TO_LAST - 1);
90 if (lyxerr.debugging(Debug::PARSER))
91 lex.printTable(lyxerr);
93 while (lex.isOK() && !quit) {
97 string const tooltip = _(lex.getString());
99 string const func_arg = lex.getString();
100 lyxerr[Debug::PARSER]
101 << "ToolbarBackend::read TO_ADD func: `"
102 << func_arg << '\'' << endl;
105 lyxaction.lookupFunc(func_arg);
106 add(tb, func, tooltip);
111 add(tb, FuncRequest(kb_action(MINIBUFFER)));
115 add(tb, FuncRequest(kb_action(SEPARATOR)));
119 add(tb, FuncRequest(kb_action(LAYOUTS)));
126 lex.printError("ToolbarBackend::read: "
127 "Unknown toolbar tag: `$$Token'");
132 toolbars.push_back(tb);
138 void ToolbarBackend::readToolbars(LyXLex & lex)
141 if (compare_ascii_no_case(lex.getString(), "toolbars")) {
142 lyxerr << "ToolbarBackend::read: ERROR wrong token:`"
143 << lex.getString() << '\'' << endl;
149 string name = lex.getString();
152 if (!compare_ascii_no_case(name, "end"))
155 Toolbars::iterator tcit = toolbars.begin();
156 Toolbars::iterator tend = toolbars.end();
157 for (; tcit != tend; ++tcit) {
158 if (tcit->name == name)
163 lyxerr << "ToolbarBackend: undefined toolbar "
168 tcit->flags = static_cast<Flags>(0);
169 string flagstr = lex.getString();
171 vector<string> flags = getVectorFromString(flagstr);
173 vector<string>::const_iterator cit = flags.begin();
174 vector<string>::const_iterator end = flags.end();
176 for (; cit != end; ++cit) {
178 if (!compare_ascii_no_case(*cit, "off"))
180 else if (!compare_ascii_no_case(*cit, "on"))
182 else if (!compare_ascii_no_case(*cit, "math"))
184 else if (!compare_ascii_no_case(*cit, "table"))
186 else if (!compare_ascii_no_case(*cit, "top"))
188 else if (!compare_ascii_no_case(*cit, "bottom"))
190 else if (!compare_ascii_no_case(*cit, "left"))
192 else if (!compare_ascii_no_case(*cit, "right"))
195 lyxerr << "ToolbarBackend::read: unrecognised token:`"
196 << *cit << '\'' << endl;
198 tcit->flags = static_cast<Flags>(tcit->flags | flag);
201 usedtoolbars.push_back(*tcit);
206 void ToolbarBackend::add(Toolbar & tb,
207 FuncRequest const & func, string const & tooltip)
209 tb.items.push_back(make_pair(func, tooltip));
210 tb.items.back().first.origin = FuncRequest::UI;
214 string const ToolbarBackend::getIcon(FuncRequest const & f)
216 using lyx::frontend::find_xpm;
221 case LFUN_MATH_INSERT:
222 if (!f.argument.empty())
223 fullname = find_xpm(f.argument.substr(1));
225 case LFUN_MATH_DELIM:
226 case LFUN_MATH_BIGDELIM:
227 fullname = find_xpm(f.argument);
230 string const name = lyxaction.getActionName(f.action);
231 string xpm_name(name);
233 if (!f.argument.empty())
234 xpm_name = subst(name + ' ' + f.argument, ' ', '_');
236 fullname = libFileSearch("images", xpm_name, "xpm");
238 if (fullname.empty()) {
239 // try without the argument
240 fullname = libFileSearch("images", name, "xpm");
244 if (!fullname.empty()) {
245 lyxerr[Debug::GUI] << "Full icon name is `"
246 << fullname << '\'' << endl;
250 lyxerr[Debug::GUI] << "Cannot find icon for command \""
251 << lyxaction.getActionName(f.action)
252 << '(' << f.argument << ")\"" << endl;
253 return libFileSearch("images", "unknown", "xpm");