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"
29 using support::compare_ascii_no_case;
30 using support::getVectorFromString;
31 using support::libFileSearch;
40 ToolbarBackend toolbarbackend;
53 struct keyword_item toolTags[TO_LAST - 1] = {
54 { "end", TO_ENDTOOLBAR },
56 { "layouts", TO_LAYOUTS },
57 { "minibuffer", TO_MINIBUFFER },
58 { "separator", TO_SEPARATOR }
64 ToolbarBackend::ToolbarBackend()
69 void ToolbarBackend::read(LyXLex & lex)
72 if (compare_ascii_no_case(lex.getString(), "toolbar")) {
73 lyxerr << "ToolbarBackend::read: ERROR wrong token:`"
74 << lex.getString() << '\'' << endl;
80 tb.name = lex.getString();
83 lyxerr << "ToolbarBackend::read: Malformed toolbar "
84 "description " << lex.getString() << endl;
87 tb.gui_name = lex.getString();
91 lex.pushTable(toolTags, TO_LAST - 1);
93 if (lyxerr.debugging(Debug::PARSER))
94 lex.printTable(lyxerr);
96 while (lex.isOK() && !quit) {
100 docstring const tooltip = translateIfPossible(lex.getDocString());
102 string const func_arg = lex.getString();
103 lyxerr[Debug::PARSER]
104 << "ToolbarBackend::read TO_ADD func: `"
105 << func_arg << '\'' << endl;
108 lyxaction.lookupFunc(func_arg);
109 add(tb, func, tooltip);
114 add(tb, FuncRequest(kb_action(MINIBUFFER)));
118 add(tb, FuncRequest(kb_action(SEPARATOR)));
122 add(tb, FuncRequest(kb_action(LAYOUTS)));
129 lex.printError("ToolbarBackend::read: "
130 "Unknown toolbar tag: `$$Token'");
135 toolbars.push_back(tb);
141 void ToolbarBackend::readToolbars(LyXLex & lex)
144 if (compare_ascii_no_case(lex.getString(), "toolbars")) {
145 lyxerr << "ToolbarBackend::read: ERROR wrong token:`"
146 << lex.getString() << '\'' << endl;
152 string name = lex.getString();
155 if (!compare_ascii_no_case(name, "end"))
158 Toolbars::iterator tcit = toolbars.begin();
159 Toolbars::iterator tend = toolbars.end();
160 for (; tcit != tend; ++tcit) {
161 if (tcit->name == name)
166 lyxerr << "ToolbarBackend: undefined toolbar "
171 tcit->flags = static_cast<Flags>(0);
172 string flagstr = lex.getString();
174 vector<string> flags = getVectorFromString(flagstr);
176 vector<string>::const_iterator cit = flags.begin();
177 vector<string>::const_iterator end = flags.end();
179 for (; cit != end; ++cit) {
181 if (!compare_ascii_no_case(*cit, "off"))
183 else if (!compare_ascii_no_case(*cit, "on"))
185 else if (!compare_ascii_no_case(*cit, "math"))
187 else if (!compare_ascii_no_case(*cit, "table"))
189 else if (!compare_ascii_no_case(*cit, "review"))
191 else if (!compare_ascii_no_case(*cit, "top"))
193 else if (!compare_ascii_no_case(*cit, "bottom"))
195 else if (!compare_ascii_no_case(*cit, "left"))
197 else if (!compare_ascii_no_case(*cit, "right"))
200 lyxerr << "ToolbarBackend::read: unrecognised token:`"
201 << *cit << '\'' << endl;
203 tcit->flags = static_cast<Flags>(tcit->flags | flag);
206 usedtoolbars.push_back(*tcit);
211 void ToolbarBackend::add(Toolbar & tb,
212 FuncRequest const & func, docstring const & tooltip)
214 tb.items.push_back(make_pair(func, tooltip));
215 tb.items.back().first.origin = FuncRequest::TOOLBAR;
219 string const ToolbarBackend::getIcon(FuncRequest const & f)
221 using frontend::find_xpm;
226 case LFUN_MATH_INSERT:
227 if (!f.argument().empty())
228 fullname = find_xpm(to_utf8(f.argument()).substr(1));
230 case LFUN_MATH_DELIM:
231 case LFUN_MATH_BIGDELIM:
232 fullname = find_xpm(to_utf8(f.argument()));
235 string const name = lyxaction.getActionName(f.action);
236 string xpm_name(name);
238 if (!f.argument().empty())
239 xpm_name = subst(name + ' ' + to_utf8(f.argument()), ' ', '_');
241 fullname = libFileSearch("images", xpm_name, "xpm").absFilename();
243 if (fullname.empty()) {
244 // try without the argument
245 fullname = libFileSearch("images", name, "xpm").absFilename();
249 if (!fullname.empty()) {
250 lyxerr[Debug::GUI] << "Full icon name is `"
251 << fullname << '\'' << endl;
255 lyxerr[Debug::GUI] << "Cannot find icon for command \""
256 << lyxaction.getActionName(f.action)
257 << '(' << to_utf8(f.argument()) << ")\"" << endl;
258 return libFileSearch("images", "unknown", "xpm").absFilename();