2 * \file ToolbarBackend.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS
13 #include "ToolbarBackend.h"
14 #include "LyXAction.h"
20 #include "support/lstrings.h"
21 #include "support/filetools.h"
23 #include "frontends/controllers/ControlMath.h"
27 using namespace lyx::support;
33 ToolbarBackend toolbarbackend;
46 struct keyword_item toolTags[TO_LAST - 1] = {
47 { "end", TO_ENDTOOLBAR },
49 { "layouts", TO_LAYOUTS },
50 { "minibuffer", TO_MINIBUFFER },
51 { "separator", TO_SEPARATOR }
54 } // end of anon namespace
57 ToolbarBackend::ToolbarBackend()
62 void ToolbarBackend::read(LyXLex & lex)
65 if (compare_ascii_no_case(lex.getString(), "toolbar")) {
66 lyxerr << "ToolbarBackend::read: ERROR wrong token:`"
67 << lex.getString() << '\'' << endl;
73 tb.name = lex.getString();
77 lex.pushTable(toolTags, TO_LAST - 1);
79 if (lyxerr.debugging(Debug::PARSER))
80 lex.printTable(lyxerr);
82 while (lex.isOK() && !quit) {
86 string const tooltip = _(lex.getString());
88 string const func = lex.getString();
90 << "ToolbarBackend::read TO_ADD func: `"
91 << func << '\'' << endl;
92 add(tb, func, tooltip);
112 lex.printError("ToolbarBackend::read: "
113 "Unknown toolbar tag: `$$Token'");
118 toolbars.push_back(tb);
124 void ToolbarBackend::readToolbars(LyXLex & lex)
127 if (compare_ascii_no_case(lex.getString(), "toolbars")) {
128 lyxerr << "ToolbarBackend::read: ERROR wrong token:`"
129 << lex.getString() << '\'' << endl;
135 string name = lex.getString();
138 if (!compare_ascii_no_case(name, "end"))
141 Toolbars::iterator tcit = toolbars.begin();
142 Toolbars::iterator tend = toolbars.end();
143 for (; tcit != tend; ++tcit) {
144 if (tcit->name == name)
149 lyxerr << "ToolbarBackend: undefined toolbar "
154 tcit->flags = static_cast<Flags>(0);
155 string flagstr = lex.getString();
157 vector<string> flags = getVectorFromString(flagstr);
159 vector<string>::const_iterator cit = flags.begin();
160 vector<string>::const_iterator end = flags.end();
162 for (; cit != end; ++cit) {
164 if (!compare_ascii_no_case(*cit, "off"))
166 else if (!compare_ascii_no_case(*cit, "on"))
168 else if (!compare_ascii_no_case(*cit, "math"))
170 else if (!compare_ascii_no_case(*cit, "table"))
172 else if (!compare_ascii_no_case(*cit, "top"))
174 else if (!compare_ascii_no_case(*cit, "bottom"))
176 else if (!compare_ascii_no_case(*cit, "left"))
178 else if (!compare_ascii_no_case(*cit, "right"))
181 lyxerr << "ToolbarBackend::read: unrecognised token:`"
182 << *cit << '\'' << endl;
184 tcit->flags = static_cast<Flags>(tcit->flags | flag);
187 usedtoolbars.push_back(*tcit);
192 void ToolbarBackend::add(Toolbar & tb, int action, string const & tooltip)
194 tb.items.push_back(make_pair(action, tooltip));
198 void ToolbarBackend::add(Toolbar & tb, string const & func, string const & tooltip)
200 int const tf = lyxaction.LookupFunc(func);
203 lyxerr << "ToolbarBackend::add: no LyX command called `"
204 << func << "' exists!" << endl;
206 add(tb, tf, tooltip);
211 string const ToolbarBackend::getIcon(int action)
214 FuncRequest f = lyxaction.retrieveActionArg(action);
216 if (f.action == LFUN_INSERT_MATH) {
217 if (!f.argument.empty())
218 fullname = find_xpm(f.argument.substr(1));
219 } else if (f.action == LFUN_MATH_DELIM) {
220 fullname = find_xpm(f.argument);
222 string const name = lyxaction.getActionName(f.action);
223 string xpm_name(name);
225 if (!f.argument.empty())
226 xpm_name = subst(name + ' ' + f.argument, ' ', '_');
228 fullname = LibFileSearch("images", xpm_name, "xpm");
230 if (fullname.empty()) {
231 // try without the argument
232 fullname = LibFileSearch("images", name, "xpm");
236 if (!fullname.empty()) {
237 lyxerr[Debug::GUI] << "Full icon name is `"
238 << fullname << '\'' << endl;
242 lyxerr[Debug::GUI] << "Cannot find icon for command \""
243 << lyxaction.getActionName(f.action)
244 << ' ' << f.argument << '"' << endl;
245 return LibFileSearch("images", "unknown", "xpm");