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();
74 tb.flags = static_cast<Flags>(0);
75 string flagstr = lex.getString();
76 vector<string> flags = getVectorFromString(flagstr);
78 vector<string>::const_iterator cit = flags.begin();
79 vector<string>::const_iterator end = flags.end();
81 for (; cit != end; ++cit) {
83 if (!compare_ascii_no_case(*cit, "off"))
85 else if (!compare_ascii_no_case(*cit, "on"))
87 else if (!compare_ascii_no_case(*cit, "math"))
89 else if (!compare_ascii_no_case(*cit, "table"))
91 else if (!compare_ascii_no_case(*cit, "top"))
93 else if (!compare_ascii_no_case(*cit, "bottom"))
95 else if (!compare_ascii_no_case(*cit, "left"))
97 else if (!compare_ascii_no_case(*cit, "right"))
100 lyxerr << "ToolbarBackend::read: unrecognised token:`"
101 << *cit << '\'' << endl;
103 tb.flags = static_cast<Flags>(tb.flags | flag);
108 lex.pushTable(toolTags, TO_LAST - 1);
110 if (lyxerr.debugging(Debug::PARSER))
111 lex.printTable(lyxerr);
113 while (lex.isOK() && !quit) {
116 if (lex.next(true)) {
117 string const tooltip = _(lex.getString());
119 string const func = lex.getString();
120 lyxerr[Debug::PARSER]
121 << "ToolbarBackend::read TO_ADD func: `"
122 << func << '\'' << endl;
123 add(tb, func, tooltip);
143 lex.printError("ToolbarBackend::read: "
144 "Unknown toolbar tag: `$$Token'");
149 toolbars.push_back(tb);
155 void ToolbarBackend::add(Toolbar & tb, int action, string const & tooltip)
157 tb.items.push_back(make_pair(action, tooltip));
161 void ToolbarBackend::add(Toolbar & tb, string const & func, string const & tooltip)
163 int const tf = lyxaction.LookupFunc(func);
166 lyxerr << "ToolbarBackend::add: no LyX command called `"
167 << func << "' exists!" << endl;
169 add(tb, tf, tooltip);
174 string const ToolbarBackend::getIcon(int action)
177 FuncRequest f = lyxaction.retrieveActionArg(action);
179 if (f.action == LFUN_INSERT_MATH) {
180 if (!f.argument.empty())
181 fullname = find_xpm(f.argument.substr(1));
182 } else if (f.action == LFUN_MATH_DELIM) {
183 fullname = find_xpm(f.argument);
185 string const name = lyxaction.getActionName(f.action);
186 string xpm_name(name);
188 if (!f.argument.empty())
189 xpm_name = subst(name + ' ' + f.argument, ' ', '_');
191 fullname = LibFileSearch("images", xpm_name, "xpm");
193 if (fullname.empty()) {
194 // try without the argument
195 fullname = LibFileSearch("images", name, "xpm");
199 if (!fullname.empty()) {
200 lyxerr[Debug::GUI] << "Full icon name is `"
201 << fullname << '\'' << endl;
205 return LibFileSearch("images", "unknown", "xpm");