2 * \file ToolbarBackend.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Jean-Marc Lasgouttes
9 * Full author contact details are available in file CREDITS.
14 #include "ToolbarBackend.h"
15 #include "funcrequest.h"
16 #include "LyXAction.h"
21 #include "support/lstrings.h"
22 #include "support/filetools.h"
24 #include "frontends/controllers/ControlMath.h"
26 using lyx::support::compare_ascii_no_case;
27 using lyx::support::getVectorFromString;
28 using lyx::support::LibFileSearch;
29 using lyx::support::subst;
37 ToolbarBackend toolbarbackend;
50 struct keyword_item toolTags[TO_LAST - 1] = {
51 { "end", TO_ENDTOOLBAR },
53 { "layouts", TO_LAYOUTS },
54 { "minibuffer", TO_MINIBUFFER },
55 { "separator", TO_SEPARATOR }
58 } // end of anon namespace
61 ToolbarBackend::ToolbarBackend()
66 void ToolbarBackend::read(LyXLex & lex)
69 if (compare_ascii_no_case(lex.getString(), "toolbar")) {
70 lyxerr << "ToolbarBackend::read: ERROR wrong token:`"
71 << lex.getString() << '\'' << endl;
77 tb.name = lex.getString();
81 lex.pushTable(toolTags, TO_LAST - 1);
83 if (lyxerr.debugging(Debug::PARSER))
84 lex.printTable(lyxerr);
86 while (lex.isOK() && !quit) {
90 string const tooltip = _(lex.getString());
92 string const func_arg = lex.getString();
94 << "ToolbarBackend::read TO_ADD func: `"
95 << func_arg << '\'' << endl;
96 // Split func_arg in function and arg.
97 string::size_type sp = func_arg.find(' ');
98 if (sp != string::npos) {
101 func_arg.substr(0, sp);
103 func_arg.substr(sp + 1,
107 lyxaction.LookupFunc(func);
109 add(tb, FuncRequest(tf, arg), tooltip);
111 kb_action const tf = lyxaction.LookupFunc(func_arg);
112 add(tb, FuncRequest(tf), tooltip);
120 add(tb, FuncRequest(kb_action(MINIBUFFER)));
124 add(tb, FuncRequest(kb_action(SEPARATOR)));
128 add(tb, FuncRequest(kb_action(LAYOUTS)));
135 lex.printError("ToolbarBackend::read: "
136 "Unknown toolbar tag: `$$Token'");
141 toolbars.push_back(tb);
147 void ToolbarBackend::readToolbars(LyXLex & lex)
150 if (compare_ascii_no_case(lex.getString(), "toolbars")) {
151 lyxerr << "ToolbarBackend::read: ERROR wrong token:`"
152 << lex.getString() << '\'' << endl;
158 string name = lex.getString();
161 if (!compare_ascii_no_case(name, "end"))
164 Toolbars::iterator tcit = toolbars.begin();
165 Toolbars::iterator tend = toolbars.end();
166 for (; tcit != tend; ++tcit) {
167 if (tcit->name == name)
172 lyxerr << "ToolbarBackend: undefined toolbar "
177 tcit->flags = static_cast<Flags>(0);
178 string flagstr = lex.getString();
180 vector<string> flags = getVectorFromString(flagstr);
182 vector<string>::const_iterator cit = flags.begin();
183 vector<string>::const_iterator end = flags.end();
185 for (; cit != end; ++cit) {
187 if (!compare_ascii_no_case(*cit, "off"))
189 else if (!compare_ascii_no_case(*cit, "on"))
191 else if (!compare_ascii_no_case(*cit, "math"))
193 else if (!compare_ascii_no_case(*cit, "table"))
195 else if (!compare_ascii_no_case(*cit, "top"))
197 else if (!compare_ascii_no_case(*cit, "bottom"))
199 else if (!compare_ascii_no_case(*cit, "left"))
201 else if (!compare_ascii_no_case(*cit, "right"))
204 lyxerr << "ToolbarBackend::read: unrecognised token:`"
205 << *cit << '\'' << endl;
207 tcit->flags = static_cast<Flags>(tcit->flags | flag);
210 usedtoolbars.push_back(*tcit);
215 void ToolbarBackend::add(Toolbar & tb,
216 FuncRequest const & func, string const & tooltip)
218 tb.items.push_back(make_pair(func, tooltip));
222 string const ToolbarBackend::getIcon(FuncRequest const & f)
226 if (f.action == LFUN_INSERT_MATH) {
227 if (!f.argument.empty())
228 fullname = find_xpm(f.argument.substr(1));
229 } else if (f.action == LFUN_MATH_DELIM) {
230 fullname = find_xpm(f.argument);
232 string const name = lyxaction.getActionName(f.action);
233 string xpm_name(name);
235 if (!f.argument.empty())
236 xpm_name = subst(name + ' ' + f.argument, ' ', '_');
238 fullname = LibFileSearch("images", xpm_name, "xpm");
240 if (fullname.empty()) {
241 // try without the argument
242 fullname = LibFileSearch("images", name, "xpm");
246 if (!fullname.empty()) {
247 lyxerr[Debug::GUI] << "Full icon name is `"
248 << fullname << '\'' << endl;
252 lyxerr[Debug::GUI] << "Cannot find icon for command \""
253 << lyxaction.getActionName(f.action)
254 << '(' << f.argument << ")\"" << endl;
255 return LibFileSearch("images", "unknown", "xpm");