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 "LyXAction.h"
21 #include "support/lstrings.h"
22 #include "support/filetools.h"
24 #include "frontends/controllers/ControlMath.h"
28 using namespace lyx::support;
34 ToolbarBackend toolbarbackend;
47 struct keyword_item toolTags[TO_LAST - 1] = {
48 { "end", TO_ENDTOOLBAR },
50 { "layouts", TO_LAYOUTS },
51 { "minibuffer", TO_MINIBUFFER },
52 { "separator", TO_SEPARATOR }
55 } // end of anon namespace
58 ToolbarBackend::ToolbarBackend()
63 void ToolbarBackend::read(LyXLex & lex)
66 if (compare_ascii_no_case(lex.getString(), "toolbar")) {
67 lyxerr << "ToolbarBackend::read: ERROR wrong token:`"
68 << lex.getString() << '\'' << endl;
74 tb.name = lex.getString();
78 lex.pushTable(toolTags, TO_LAST - 1);
80 if (lyxerr.debugging(Debug::PARSER))
81 lex.printTable(lyxerr);
83 while (lex.isOK() && !quit) {
87 string const tooltip = _(lex.getString());
89 string const func = lex.getString();
91 << "ToolbarBackend::read TO_ADD func: `"
92 << func << '\'' << endl;
93 add(tb, func, tooltip);
113 lex.printError("ToolbarBackend::read: "
114 "Unknown toolbar tag: `$$Token'");
119 toolbars.push_back(tb);
125 void ToolbarBackend::readToolbars(LyXLex & lex)
128 if (compare_ascii_no_case(lex.getString(), "toolbars")) {
129 lyxerr << "ToolbarBackend::read: ERROR wrong token:`"
130 << lex.getString() << '\'' << endl;
136 string name = lex.getString();
139 if (!compare_ascii_no_case(name, "end"))
142 Toolbars::iterator tcit = toolbars.begin();
143 Toolbars::iterator tend = toolbars.end();
144 for (; tcit != tend; ++tcit) {
145 if (tcit->name == name)
150 lyxerr << "ToolbarBackend: undefined toolbar "
155 tcit->flags = static_cast<Flags>(0);
156 string flagstr = lex.getString();
158 vector<string> flags = getVectorFromString(flagstr);
160 vector<string>::const_iterator cit = flags.begin();
161 vector<string>::const_iterator end = flags.end();
163 for (; cit != end; ++cit) {
165 if (!compare_ascii_no_case(*cit, "off"))
167 else if (!compare_ascii_no_case(*cit, "on"))
169 else if (!compare_ascii_no_case(*cit, "math"))
171 else if (!compare_ascii_no_case(*cit, "table"))
173 else if (!compare_ascii_no_case(*cit, "top"))
175 else if (!compare_ascii_no_case(*cit, "bottom"))
177 else if (!compare_ascii_no_case(*cit, "left"))
179 else if (!compare_ascii_no_case(*cit, "right"))
182 lyxerr << "ToolbarBackend::read: unrecognised token:`"
183 << *cit << '\'' << endl;
185 tcit->flags = static_cast<Flags>(tcit->flags | flag);
188 usedtoolbars.push_back(*tcit);
193 void ToolbarBackend::add(Toolbar & tb, int action, string const & tooltip)
195 tb.items.push_back(make_pair(action, tooltip));
199 void ToolbarBackend::add(Toolbar & tb, string const & func, string const & tooltip)
201 int const tf = lyxaction.LookupFunc(func);
204 lyxerr << "ToolbarBackend::add: no LyX command called `"
205 << func << "' exists!" << endl;
207 add(tb, tf, tooltip);
212 string const ToolbarBackend::getIcon(int action)
215 FuncRequest f = lyxaction.retrieveActionArg(action);
217 if (f.action == LFUN_INSERT_MATH) {
218 if (!f.argument.empty())
219 fullname = find_xpm(f.argument.substr(1));
220 } else if (f.action == LFUN_MATH_DELIM) {
221 fullname = find_xpm(f.argument);
223 string const name = lyxaction.getActionName(f.action);
224 string xpm_name(name);
226 if (!f.argument.empty())
227 xpm_name = subst(name + ' ' + f.argument, ' ', '_');
229 fullname = LibFileSearch("images", xpm_name, "xpm");
231 if (fullname.empty()) {
232 // try without the argument
233 fullname = LibFileSearch("images", name, "xpm");
237 if (!fullname.empty()) {
238 lyxerr[Debug::GUI] << "Full icon name is `"
239 << fullname << '\'' << endl;
243 lyxerr[Debug::GUI] << "Cannot find icon for command \""
244 << lyxaction.getActionName(f.action)
245 << ' ' << f.argument << '"' << endl;
246 return LibFileSearch("images", "unknown", "xpm");