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();
70 lex.pushTable(toolTags, TO_LAST - 1);
72 if (lyxerr.debugging(Debug::PARSER))
73 lex.printTable(lyxerr);
75 while (lex.isOK() && !quit) {
79 string const tooltip = _(lex.getString());
81 string const func = lex.getString();
83 << "ToolbarBackend::read TO_ADD func: `"
84 << func << '\'' << endl;
85 add(tb, func, tooltip);
101 lex.printError("ToolbarBackend::read: "
102 "Unknown toolbar tag: `$$Token'");
107 toolbars.push_back(tb);
113 void ToolbarBackend::add(Toolbar & tb, int action, string const & tooltip)
115 tb.items.push_back(make_pair(action, tooltip));
119 void ToolbarBackend::add(Toolbar & tb, string const & func, string const & tooltip)
121 int const tf = lyxaction.LookupFunc(func);
124 lyxerr << "ToolbarBackend::add: no LyX command called `"
125 << func << "' exists!" << endl;
127 add(tb, tf, tooltip);
132 string const ToolbarBackend::getIcon(int action)
135 FuncRequest f = lyxaction.retrieveActionArg(action);
137 if (f.action == LFUN_INSERT_MATH && !f.argument.empty()) {
138 fullname = find_xpm(f.argument.substr(1));
140 string const name = lyxaction.getActionName(f.action);
141 string xpm_name(name);
143 if (!f.argument.empty())
144 xpm_name = subst(name + ' ' + f.argument, ' ', '_');
146 fullname = LibFileSearch("images", xpm_name, "xpm");
148 if (fullname.empty()) {
149 // try without the argument
150 fullname = LibFileSearch("images", name, "xpm");
154 if (!fullname.empty()) {
155 lyxerr[Debug::GUI] << "Full icon name is `"
156 << fullname << '\'' << endl;
160 return LibFileSearch("images", "unknown", "xpm");