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"
27 using lyx::support::compare_ascii_no_case;
28 using lyx::support::getVectorFromString;
29 using lyx::support::libFileSearch;
30 using lyx::support::subst;
38 ToolbarBackend toolbarbackend;
51 struct keyword_item toolTags[TO_LAST - 1] = {
52 { "end", TO_ENDTOOLBAR },
54 { "layouts", TO_LAYOUTS },
55 { "minibuffer", TO_MINIBUFFER },
56 { "separator", TO_SEPARATOR }
59 } // end of anon namespace
62 ToolbarBackend::ToolbarBackend()
67 void ToolbarBackend::read(LyXLex & lex)
70 if (compare_ascii_no_case(lex.getString(), "toolbar")) {
71 lyxerr << "ToolbarBackend::read: ERROR wrong token:`"
72 << lex.getString() << '\'' << endl;
78 tb.name = lex.getString();
81 lyxerr << "ToolbarBackend::read: Malformed toolbar "
82 "description " << lex.getString() << endl;
85 tb.gui_name = lex.getString();
89 lex.pushTable(toolTags, TO_LAST - 1);
91 if (lyxerr.debugging(Debug::PARSER))
92 lex.printTable(lyxerr);
94 while (lex.isOK() && !quit) {
98 docstring const tooltip = _(lex.getString());
100 string const func_arg = lex.getString();
101 lyxerr[Debug::PARSER]
102 << "ToolbarBackend::read TO_ADD func: `"
103 << func_arg << '\'' << endl;
106 lyxaction.lookupFunc(func_arg);
107 add(tb, func, tooltip);
112 add(tb, FuncRequest(kb_action(MINIBUFFER)));
116 add(tb, FuncRequest(kb_action(SEPARATOR)));
120 add(tb, FuncRequest(kb_action(LAYOUTS)));
127 lex.printError("ToolbarBackend::read: "
128 "Unknown toolbar tag: `$$Token'");
133 toolbars.push_back(tb);
139 void ToolbarBackend::readToolbars(LyXLex & lex)
142 if (compare_ascii_no_case(lex.getString(), "toolbars")) {
143 lyxerr << "ToolbarBackend::read: ERROR wrong token:`"
144 << lex.getString() << '\'' << endl;
150 string name = lex.getString();
153 if (!compare_ascii_no_case(name, "end"))
156 Toolbars::iterator tcit = toolbars.begin();
157 Toolbars::iterator tend = toolbars.end();
158 for (; tcit != tend; ++tcit) {
159 if (tcit->name == name)
164 lyxerr << "ToolbarBackend: undefined toolbar "
169 tcit->flags = static_cast<Flags>(0);
170 string flagstr = lex.getString();
172 vector<string> flags = getVectorFromString(flagstr);
174 vector<string>::const_iterator cit = flags.begin();
175 vector<string>::const_iterator end = flags.end();
177 for (; cit != end; ++cit) {
179 if (!compare_ascii_no_case(*cit, "off"))
181 else if (!compare_ascii_no_case(*cit, "on"))
183 else if (!compare_ascii_no_case(*cit, "math"))
185 else if (!compare_ascii_no_case(*cit, "table"))
187 else if (!compare_ascii_no_case(*cit, "top"))
189 else if (!compare_ascii_no_case(*cit, "bottom"))
191 else if (!compare_ascii_no_case(*cit, "left"))
193 else if (!compare_ascii_no_case(*cit, "right"))
196 lyxerr << "ToolbarBackend::read: unrecognised token:`"
197 << *cit << '\'' << endl;
199 tcit->flags = static_cast<Flags>(tcit->flags | flag);
202 usedtoolbars.push_back(*tcit);
207 void ToolbarBackend::add(Toolbar & tb,
208 FuncRequest const & func, docstring const & tooltip)
210 tb.items.push_back(make_pair(func, tooltip));
211 tb.items.back().first.origin = FuncRequest::UI;
215 string const ToolbarBackend::getIcon(FuncRequest const & f)
217 using lyx::frontend::find_xpm;
222 case LFUN_MATH_INSERT:
223 if (!f.argument().empty())
224 fullname = find_xpm(lyx::to_utf8(f.argument()).substr(1));
226 case LFUN_MATH_DELIM:
227 case LFUN_MATH_BIGDELIM:
228 fullname = find_xpm(lyx::to_utf8(f.argument()));
231 string const name = lyxaction.getActionName(f.action);
232 string xpm_name(name);
234 if (!f.argument().empty())
235 xpm_name = subst(name + ' ' + lyx::to_utf8(f.argument()), ' ', '_');
237 fullname = libFileSearch("images", xpm_name, "xpm");
239 if (fullname.empty()) {
240 // try without the argument
241 fullname = libFileSearch("images", name, "xpm");
245 if (!fullname.empty()) {
246 lyxerr[Debug::GUI] << "Full icon name is `"
247 << fullname << '\'' << endl;
251 lyxerr[Debug::GUI] << "Cannot find icon for command \""
252 << lyxaction.getActionName(f.action)
253 << '(' << lyx::to_utf8(f.argument()) << ")\"" << endl;
254 return libFileSearch("images", "unknown", "xpm");