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"
22 #include "support/lstrings.h"
23 #include "support/filetools.h"
25 #include "frontends/controllers/ControlMath.h"
29 using namespace lyx::support;
35 ToolbarBackend toolbarbackend;
48 struct keyword_item toolTags[TO_LAST - 1] = {
49 { "end", TO_ENDTOOLBAR },
51 { "layouts", TO_LAYOUTS },
52 { "minibuffer", TO_MINIBUFFER },
53 { "separator", TO_SEPARATOR }
56 } // end of anon namespace
59 ToolbarBackend::ToolbarBackend()
64 void ToolbarBackend::read(LyXLex & lex)
67 if (compare_ascii_no_case(lex.getString(), "toolbar")) {
68 lyxerr << "ToolbarBackend::read: ERROR wrong token:`"
69 << lex.getString() << '\'' << endl;
75 tb.name = lex.getString();
79 lex.pushTable(toolTags, TO_LAST - 1);
81 if (lyxerr.debugging(Debug::PARSER))
82 lex.printTable(lyxerr);
84 while (lex.isOK() && !quit) {
88 string const tooltip = _(lex.getString());
90 string const func = lex.getString();
92 << "ToolbarBackend::read TO_ADD func: `"
93 << func << '\'' << endl;
94 add(tb, func, tooltip);
114 lex.printError("ToolbarBackend::read: "
115 "Unknown toolbar tag: `$$Token'");
120 toolbars.push_back(tb);
126 void ToolbarBackend::readToolbars(LyXLex & lex)
129 if (compare_ascii_no_case(lex.getString(), "toolbars")) {
130 lyxerr << "ToolbarBackend::read: ERROR wrong token:`"
131 << lex.getString() << '\'' << endl;
137 string name = lex.getString();
140 if (!compare_ascii_no_case(name, "end"))
143 Toolbars::iterator tcit = toolbars.begin();
144 Toolbars::iterator tend = toolbars.end();
145 for (; tcit != tend; ++tcit) {
146 if (tcit->name == name)
151 lyxerr << "ToolbarBackend: undefined toolbar "
156 tcit->flags = static_cast<Flags>(0);
157 string flagstr = lex.getString();
159 vector<string> flags = getVectorFromString(flagstr);
161 vector<string>::const_iterator cit = flags.begin();
162 vector<string>::const_iterator end = flags.end();
164 for (; cit != end; ++cit) {
166 if (!compare_ascii_no_case(*cit, "off"))
168 else if (!compare_ascii_no_case(*cit, "on"))
170 else if (!compare_ascii_no_case(*cit, "math"))
172 else if (!compare_ascii_no_case(*cit, "table"))
174 else if (!compare_ascii_no_case(*cit, "top"))
176 else if (!compare_ascii_no_case(*cit, "bottom"))
178 else if (!compare_ascii_no_case(*cit, "left"))
180 else if (!compare_ascii_no_case(*cit, "right"))
183 lyxerr << "ToolbarBackend::read: unrecognised token:`"
184 << *cit << '\'' << endl;
186 tcit->flags = static_cast<Flags>(tcit->flags | flag);
189 usedtoolbars.push_back(*tcit);
194 void ToolbarBackend::add(Toolbar & tb, int action, string const & tooltip)
196 tb.items.push_back(make_pair(action, tooltip));
200 void ToolbarBackend::add(Toolbar & tb, string const & func, string const & tooltip)
202 int const tf = lyxaction.LookupFunc(func);
205 lyxerr << "ToolbarBackend::add: no LyX command called `"
206 << func << "' exists!" << endl;
208 add(tb, tf, tooltip);
213 string const ToolbarBackend::getIcon(int action)
216 FuncRequest f = lyxaction.retrieveActionArg(action);
218 if (f.action == LFUN_INSERT_MATH) {
219 if (!f.argument.empty())
220 fullname = find_xpm(f.argument.substr(1));
221 } else if (f.action == LFUN_MATH_DELIM) {
222 fullname = find_xpm(f.argument);
224 string const name = lyxaction.getActionName(f.action);
225 string xpm_name(name);
227 if (!f.argument.empty())
228 xpm_name = subst(name + ' ' + f.argument, ' ', '_');
230 fullname = LibFileSearch("images", xpm_name, "xpm");
232 if (fullname.empty()) {
233 // try without the argument
234 fullname = LibFileSearch("images", name, "xpm");
238 if (!fullname.empty()) {
239 lyxerr[Debug::GUI] << "Full icon name is `"
240 << fullname << '\'' << endl;
244 lyxerr[Debug::GUI] << "Cannot find icon for command \""
245 << lyxaction.getActionName(f.action)
246 << ' ' << f.argument << '"' << endl;
247 return LibFileSearch("images", "unknown", "xpm");