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_arg = lex.getString();
94 << "ToolbarBackend::read TO_ADD func: `"
95 << func_arg << '\'' << endl;
98 lyxaction.lookupFunc(func_arg);
99 add(tb, func, tooltip);
104 add(tb, FuncRequest(kb_action(MINIBUFFER)));
108 add(tb, FuncRequest(kb_action(SEPARATOR)));
112 add(tb, FuncRequest(kb_action(LAYOUTS)));
119 lex.printError("ToolbarBackend::read: "
120 "Unknown toolbar tag: `$$Token'");
125 toolbars.push_back(tb);
131 void ToolbarBackend::readToolbars(LyXLex & lex)
134 if (compare_ascii_no_case(lex.getString(), "toolbars")) {
135 lyxerr << "ToolbarBackend::read: ERROR wrong token:`"
136 << lex.getString() << '\'' << endl;
142 string name = lex.getString();
145 if (!compare_ascii_no_case(name, "end"))
148 Toolbars::iterator tcit = toolbars.begin();
149 Toolbars::iterator tend = toolbars.end();
150 for (; tcit != tend; ++tcit) {
151 if (tcit->name == name)
156 lyxerr << "ToolbarBackend: undefined toolbar "
161 tcit->flags = static_cast<Flags>(0);
162 string flagstr = lex.getString();
164 vector<string> flags = getVectorFromString(flagstr);
166 vector<string>::const_iterator cit = flags.begin();
167 vector<string>::const_iterator end = flags.end();
169 for (; cit != end; ++cit) {
171 if (!compare_ascii_no_case(*cit, "off"))
173 else if (!compare_ascii_no_case(*cit, "on"))
175 else if (!compare_ascii_no_case(*cit, "math"))
177 else if (!compare_ascii_no_case(*cit, "table"))
179 else if (!compare_ascii_no_case(*cit, "top"))
181 else if (!compare_ascii_no_case(*cit, "bottom"))
183 else if (!compare_ascii_no_case(*cit, "left"))
185 else if (!compare_ascii_no_case(*cit, "right"))
188 lyxerr << "ToolbarBackend::read: unrecognised token:`"
189 << *cit << '\'' << endl;
191 tcit->flags = static_cast<Flags>(tcit->flags | flag);
194 usedtoolbars.push_back(*tcit);
199 void ToolbarBackend::add(Toolbar & tb,
200 FuncRequest const & func, string const & tooltip)
202 tb.items.push_back(make_pair(func, tooltip));
206 string const ToolbarBackend::getIcon(FuncRequest const & f)
210 if (f.action == LFUN_INSERT_MATH) {
211 if (!f.argument.empty())
212 fullname = find_xpm(f.argument.substr(1));
213 } else if (f.action == LFUN_MATH_DELIM) {
214 fullname = find_xpm(f.argument);
216 string const name = lyxaction.getActionName(f.action);
217 string xpm_name(name);
219 if (!f.argument.empty())
220 xpm_name = subst(name + ' ' + f.argument, ' ', '_');
222 fullname = LibFileSearch("images", xpm_name, "xpm");
224 if (fullname.empty()) {
225 // try without the argument
226 fullname = LibFileSearch("images", name, "xpm");
230 if (!fullname.empty()) {
231 lyxerr[Debug::GUI] << "Full icon name is `"
232 << fullname << '\'' << endl;
236 lyxerr[Debug::GUI] << "Cannot find icon for command \""
237 << lyxaction.getActionName(f.action)
238 << '(' << f.argument << ")\"" << endl;
239 return LibFileSearch("images", "unknown", "xpm");