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 ToolbarBackend toolbarbackend;
40 struct keyword_item toolTags[TO_LAST - 1] = {
41 { "end", TO_ENDTOOLBAR },
43 { "layouts", TO_LAYOUTS },
44 { "separator", TO_SEPARATOR }
47 } // end of anon namespace
50 ToolbarBackend::ToolbarBackend()
55 void ToolbarBackend::read(LyXLex & lex)
58 if (compare_ascii_no_case(lex.getString(), "toolbar")) {
59 lyxerr << "ToolbarBackend::read: ERROR wrong token:`"
60 << lex.getString() << '\'' << endl;
66 tb.name = lex.getString();
69 string type = lex.getString();
70 if (!compare_ascii_no_case(type, "off"))
71 tb.display_type = OFF;
72 else if (!compare_ascii_no_case(type, "on"))
74 else if (!compare_ascii_no_case(type, "math"))
75 tb.display_type = MATH;
76 else if (!compare_ascii_no_case(type, "table"))
77 tb.display_type = TABLE;
79 lyxerr << "ToolbarBackend::read: unrecognised token:`"
80 << type << '\'' << endl;
85 lex.pushTable(toolTags, TO_LAST - 1);
87 if (lyxerr.debugging(Debug::PARSER))
88 lex.printTable(lyxerr);
90 while (lex.isOK() && !quit) {
94 string const tooltip = _(lex.getString());
96 string const func = lex.getString();
98 << "ToolbarBackend::read TO_ADD func: `"
99 << func << '\'' << endl;
100 add(tb, func, tooltip);
116 lex.printError("ToolbarBackend::read: "
117 "Unknown toolbar tag: `$$Token'");
122 toolbars.push_back(tb);
128 void ToolbarBackend::add(Toolbar & tb, int action, string const & tooltip)
130 tb.items.push_back(make_pair(action, tooltip));
134 void ToolbarBackend::add(Toolbar & tb, string const & func, string const & tooltip)
136 int const tf = lyxaction.LookupFunc(func);
139 lyxerr << "ToolbarBackend::add: no LyX command called `"
140 << func << "' exists!" << endl;
142 add(tb, tf, tooltip);
147 string const ToolbarBackend::getIcon(int action)
150 FuncRequest f = lyxaction.retrieveActionArg(action);
152 if (f.action == LFUN_INSERT_MATH) {
153 if (!f.argument.empty())
154 fullname = find_xpm(f.argument.substr(1));
155 } else if (f.action == LFUN_MATH_DELIM) {
156 fullname = find_xpm(f.argument);
158 string const name = lyxaction.getActionName(f.action);
159 string xpm_name(name);
161 if (!f.argument.empty())
162 xpm_name = subst(name + ' ' + f.argument, ' ', '_');
164 fullname = LibFileSearch("images", xpm_name, "xpm");
166 if (fullname.empty()) {
167 // try without the argument
168 fullname = LibFileSearch("images", name, "xpm");
172 if (!fullname.empty()) {
173 lyxerr[Debug::GUI] << "Full icon name is `"
174 << fullname << '\'' << endl;
178 return LibFileSearch("images", "unknown", "xpm");