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"
31 ToolbarBackend toolbarbackend;
44 struct keyword_item toolTags[TO_LAST - 1] = {
45 { "end", TO_ENDTOOLBAR },
47 { "layouts", TO_LAYOUTS },
48 { "minibuffer", TO_MINIBUFFER },
49 { "separator", TO_SEPARATOR }
52 } // end of anon namespace
55 ToolbarBackend::ToolbarBackend()
60 void ToolbarBackend::read(LyXLex & lex)
63 if (compare_ascii_no_case(lex.getString(), "toolbar")) {
64 lyxerr << "ToolbarBackend::read: ERROR wrong token:`"
65 << lex.getString() << '\'' << endl;
71 tb.name = lex.getString();
75 lex.pushTable(toolTags, TO_LAST - 1);
77 if (lyxerr.debugging(Debug::PARSER))
78 lex.printTable(lyxerr);
80 while (lex.isOK() && !quit) {
84 string const tooltip = _(lex.getString());
86 string const func = lex.getString();
88 << "ToolbarBackend::read TO_ADD func: `"
89 << func << '\'' << endl;
90 add(tb, func, tooltip);
110 lex.printError("ToolbarBackend::read: "
111 "Unknown toolbar tag: `$$Token'");
116 toolbars.push_back(tb);
122 void ToolbarBackend::readToolbars(LyXLex & lex)
125 if (compare_ascii_no_case(lex.getString(), "toolbars")) {
126 lyxerr << "ToolbarBackend::read: ERROR wrong token:`"
127 << lex.getString() << '\'' << endl;
133 string name = lex.getString();
136 if (!compare_ascii_no_case(name, "end"))
139 Toolbars::iterator tcit = toolbars.begin();
140 Toolbars::iterator tend = toolbars.end();
141 for (; tcit != tend; ++tcit) {
142 if (tcit->name == name)
147 lyxerr << "ToolbarBackend: undefined toolbar "
152 tcit->flags = static_cast<Flags>(0);
153 string flagstr = lex.getString();
155 vector<string> flags = getVectorFromString(flagstr);
157 vector<string>::const_iterator cit = flags.begin();
158 vector<string>::const_iterator end = flags.end();
160 for (; cit != end; ++cit) {
162 if (!compare_ascii_no_case(*cit, "off"))
164 else if (!compare_ascii_no_case(*cit, "on"))
166 else if (!compare_ascii_no_case(*cit, "math"))
168 else if (!compare_ascii_no_case(*cit, "table"))
170 else if (!compare_ascii_no_case(*cit, "top"))
172 else if (!compare_ascii_no_case(*cit, "bottom"))
174 else if (!compare_ascii_no_case(*cit, "left"))
176 else if (!compare_ascii_no_case(*cit, "right"))
179 lyxerr << "ToolbarBackend::read: unrecognised token:`"
180 << *cit << '\'' << endl;
182 tcit->flags = static_cast<Flags>(tcit->flags | flag);
185 usedtoolbars.push_back(*tcit);
190 void ToolbarBackend::add(Toolbar & tb, int action, string const & tooltip)
192 tb.items.push_back(make_pair(action, tooltip));
196 void ToolbarBackend::add(Toolbar & tb, string const & func, string const & tooltip)
198 int const tf = lyxaction.LookupFunc(func);
201 lyxerr << "ToolbarBackend::add: no LyX command called `"
202 << func << "' exists!" << endl;
204 add(tb, tf, tooltip);
209 string const ToolbarBackend::getIcon(int action)
212 FuncRequest f = lyxaction.retrieveActionArg(action);
214 if (f.action == LFUN_INSERT_MATH) {
215 if (!f.argument.empty())
216 fullname = find_xpm(f.argument.substr(1));
217 } else if (f.action == LFUN_MATH_DELIM) {
218 fullname = find_xpm(f.argument);
220 string const name = lyxaction.getActionName(f.action);
221 string xpm_name(name);
223 if (!f.argument.empty())
224 xpm_name = subst(name + ' ' + f.argument, ' ', '_');
226 fullname = LibFileSearch("images", xpm_name, "xpm");
228 if (fullname.empty()) {
229 // try without the argument
230 fullname = LibFileSearch("images", name, "xpm");
234 if (!fullname.empty()) {
235 lyxerr[Debug::GUI] << "Full icon name is `"
236 << fullname << '\'' << endl;
240 return LibFileSearch("images", "unknown", "xpm");