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();
76 lex.pushTable(toolTags, TO_LAST - 1);
78 if (lyxerr.debugging(Debug::PARSER))
79 lex.printTable(lyxerr);
81 while (lex.isOK() && !quit) {
85 string const tooltip = _(lex.getString());
87 string const func = lex.getString();
89 << "ToolbarBackend::read TO_ADD func: `"
90 << func << '\'' << endl;
91 add(tb, func, tooltip);
111 lex.printError("ToolbarBackend::read: "
112 "Unknown toolbar tag: `$$Token'");
117 toolbars.push_back(tb);
123 void ToolbarBackend::readToolbars(LyXLex & lex)
126 if (compare_ascii_no_case(lex.getString(), "toolbars")) {
127 lyxerr << "ToolbarBackend::read: ERROR wrong token:`"
128 << lex.getString() << '\'' << endl;
134 string name = lex.getString();
137 if (!compare_ascii_no_case(name, "end"))
140 Toolbars::iterator tcit = toolbars.begin();
141 Toolbars::iterator tend = toolbars.end();
142 for (; tcit != tend; ++tcit) {
143 if (tcit->name == name)
148 lyxerr << "ToolbarBackend: undefined toolbar "
153 tcit->flags = static_cast<Flags>(0);
154 string flagstr = lex.getString();
156 vector<string> flags = getVectorFromString(flagstr);
158 vector<string>::const_iterator cit = flags.begin();
159 vector<string>::const_iterator end = flags.end();
161 for (; cit != end; ++cit) {
163 if (!compare_ascii_no_case(*cit, "off"))
165 else if (!compare_ascii_no_case(*cit, "on"))
167 else if (!compare_ascii_no_case(*cit, "math"))
169 else if (!compare_ascii_no_case(*cit, "table"))
171 else if (!compare_ascii_no_case(*cit, "top"))
173 else if (!compare_ascii_no_case(*cit, "bottom"))
175 else if (!compare_ascii_no_case(*cit, "left"))
177 else if (!compare_ascii_no_case(*cit, "right"))
180 lyxerr << "ToolbarBackend::read: unrecognised token:`"
181 << *cit << '\'' << endl;
183 tcit->flags = static_cast<Flags>(tcit->flags | flag);
186 usedtoolbars.push_back(*tcit);
191 void ToolbarBackend::add(Toolbar & tb, int action, string const & tooltip)
193 tb.items.push_back(make_pair(action, tooltip));
197 void ToolbarBackend::add(Toolbar & tb, string const & func, string const & tooltip)
199 int const tf = lyxaction.LookupFunc(func);
202 lyxerr << "ToolbarBackend::add: no LyX command called `"
203 << func << "' exists!" << endl;
205 add(tb, tf, tooltip);
210 string const ToolbarBackend::getIcon(int action)
213 FuncRequest f = lyxaction.retrieveActionArg(action);
215 if (f.action == LFUN_INSERT_MATH) {
216 if (!f.argument.empty())
217 fullname = find_xpm(f.argument.substr(1));
218 } else if (f.action == LFUN_MATH_DELIM) {
219 fullname = find_xpm(f.argument);
221 string const name = lyxaction.getActionName(f.action);
222 string xpm_name(name);
224 if (!f.argument.empty())
225 xpm_name = subst(name + ' ' + f.argument, ' ', '_');
227 fullname = LibFileSearch("images", xpm_name, "xpm");
229 if (fullname.empty()) {
230 // try without the argument
231 fullname = LibFileSearch("images", name, "xpm");
235 if (!fullname.empty()) {
236 lyxerr[Debug::GUI] << "Full icon name is `"
237 << fullname << '\'' << endl;
241 return LibFileSearch("images", "unknown", "xpm");