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.
15 #include "Converter.h"
17 #include "FuncRequest.h"
19 #include "LyXAction.h"
20 #include "qt_helpers.h"
22 #include "support/debug.h"
23 #include "support/gettext.h"
24 #include "support/lstrings.h"
29 using namespace lyx::support;
35 /////////////////////////////////////////////////////////////////////////
39 /////////////////////////////////////////////////////////////////////////
41 ToolbarItem::ToolbarItem(Type type, FuncRequest const & func, docstring const & label)
42 : type_(type), func_(func), label_(label)
47 ToolbarItem::ToolbarItem(Type type, string const & name, docstring const & label)
48 : type_(type), label_(label), name_(name)
53 void ToolbarInfo::add(ToolbarItem const & item)
55 items.push_back(item);
56 items.back().func_.setOrigin(FuncRequest::TOOLBAR);
60 ToolbarInfo & ToolbarInfo::read(Lexer & lex)
78 struct LexerKeyword toolTags[] = {
79 { "end", TO_ENDTOOLBAR },
80 { "exportformats", TO_EXPORTFORMATS },
81 { "iconpalette", TO_ICONPALETTE },
82 { "importformats", TO_IMPORTFORMATS },
83 { "item", TO_COMMAND },
84 { "layouts", TO_LAYOUTS },
85 { "minibuffer", TO_MINIBUFFER },
86 { "popupmenu", TO_POPUPMENU },
87 { "separator", TO_SEPARATOR },
88 { "stickypopupmenu", TO_STICKYPOPUPMENU },
89 { "tableinsert", TO_TABLEINSERT },
90 { "updateformats", TO_UPDATEFORMATS },
91 { "viewformats", TO_VIEWFORMATS },
95 if (compare_ascii_no_case(lex.getString(), "toolbar")) {
96 LYXERR0("ToolbarInfo::read: ERROR wrong token:`"
97 << lex.getString() << '\'');
101 name = lex.getString();
104 gui_name = _(lex.getString());
106 // FIXME what to do here?
108 LYXERR0("ToolbarInfo::read: Malformed toolbar "
109 "description " << lex.getString());
115 lex.pushTable(toolTags);
117 if (lyxerr.debugging(Debug::PARSER))
118 lex.printTable(lyxerr);
120 while (lex.isOK() && !quit) {
121 int const code = lex.lex();
124 if (lex.next(true)) {
125 docstring const tooltip = translateIfPossible(lex.getDocString());
127 string const func_arg = lex.getString();
128 LYXERR(Debug::PARSER, "ToolbarInfo::read TO_COMMAND func: `"
129 << func_arg << '\'');
132 lyxaction.lookupFunc(func_arg);
133 add(ToolbarItem(ToolbarItem::COMMAND, func, tooltip));
138 add(ToolbarItem(ToolbarItem::MINIBUFFER,
139 FuncRequest(FuncCode(ToolbarItem::MINIBUFFER))));
143 add(ToolbarItem(ToolbarItem::SEPARATOR,
144 FuncRequest(FuncCode(ToolbarItem::SEPARATOR))));
148 if (lex.next(true)) {
149 string const name = lex.getString();
151 docstring const label = lex.getDocString();
152 add(ToolbarItem(ToolbarItem::POPUPMENU, name, label));
156 case TO_STICKYPOPUPMENU:
157 if (lex.next(true)) {
158 string const name = lex.getString();
160 docstring const label = lex.getDocString();
161 add(ToolbarItem(ToolbarItem::STICKYPOPUPMENU, name, label));
166 if (lex.next(true)) {
167 string const name = lex.getString();
169 docstring const label = lex.getDocString();
170 add(ToolbarItem(ToolbarItem::ICONPALETTE, name, label));
175 add(ToolbarItem(ToolbarItem::LAYOUTS,
176 FuncRequest(FuncCode(ToolbarItem::LAYOUTS))));
180 if (lex.next(true)) {
181 docstring const tooltip = lex.getDocString();
182 add(ToolbarItem(ToolbarItem::TABLEINSERT,
183 FuncRequest(FuncCode(ToolbarItem::TABLEINSERT)), tooltip));
191 case TO_EXPORTFORMATS:
192 case TO_IMPORTFORMATS:
193 case TO_UPDATEFORMATS:
194 case TO_VIEWFORMATS: {
195 vector<Format const *> formats = (code == TO_IMPORTFORMATS) ?
196 theConverters().importableFormats() :
197 theConverters().exportableFormats(code != TO_EXPORTFORMATS);
198 sort(formats.begin(), formats.end());
199 vector<Format const *>::const_iterator fit = formats.begin();
200 vector<Format const *>::const_iterator end = formats.end();
201 for (; fit != end ; ++fit) {
204 if (code != TO_IMPORTFORMATS &&
205 !(*fit)->documentFormat())
208 docstring const prettyname =
209 from_utf8((*fit)->prettyname());
211 FuncCode lfun = LFUN_NOACTION;
213 case TO_EXPORTFORMATS:
214 lfun = LFUN_BUFFER_EXPORT;
215 tooltip = _("Export %1$s");
217 case TO_IMPORTFORMATS:
218 lfun = LFUN_BUFFER_IMPORT;
219 tooltip = _("Import %1$s");
221 case TO_UPDATEFORMATS:
222 lfun = LFUN_BUFFER_UPDATE;
223 tooltip = _("Update %1$s");
226 lfun = LFUN_BUFFER_VIEW;
227 tooltip = _("View %1$s");
230 FuncRequest func(lfun, (*fit)->name(),
231 FuncRequest::TOOLBAR);
232 add(ToolbarItem(ToolbarItem::COMMAND, func,
233 bformat(tooltip, prettyname)));
239 lex.printError("ToolbarInfo::read: "
240 "Unknown toolbar tag: `$$Token'");
251 /////////////////////////////////////////////////////////////////////////
255 /////////////////////////////////////////////////////////////////////////
257 void Toolbars::reset()
259 toolbar_info_.clear();
260 toolbar_visibility_.clear();
264 void Toolbars::readToolbars(Lexer & lex)
271 struct LexerKeyword toolTags[] = {
272 { "end", TO_ENDTOOLBARSET },
273 { "toolbar", TO_TOOLBAR }
277 if (compare_ascii_no_case(lex.getString(), "toolbarset")) {
278 LYXERR0("Toolbars::readToolbars: ERROR wrong token:`"
279 << lex.getString() << '\'');
282 lex.pushTable(toolTags);
284 if (lyxerr.debugging(Debug::PARSER))
285 lex.printTable(lyxerr);
288 while (lex.isOK() && !quit) {
293 toolbar_info_.push_back(tbinfo);
296 case TO_ENDTOOLBARSET:
300 lex.printError("Toolbars::readToolbars: "
301 "Unknown toolbar tag: `$$Token'");
310 void Toolbars::readToolbarSettings(Lexer & lex)
313 if (compare_ascii_no_case(lex.getString(), "toolbars")) {
314 LYXERR0("Toolbars::readToolbarSettings: ERROR wrong token:`"
315 << lex.getString() << '\'');
321 string name = lex.getString();
324 if (!compare_ascii_no_case(name, "end"))
328 string flagstr = lex.getString();
330 vector<string> flags = getVectorFromString(flagstr);
332 vector<string>::const_iterator cit = flags.begin();
333 vector<string>::const_iterator end = flags.end();
335 for (; cit != end; ++cit) {
336 Visibility flag = ON;
337 if (!compare_ascii_no_case(*cit, "off"))
339 else if (!compare_ascii_no_case(*cit, "on"))
341 else if (!compare_ascii_no_case(*cit, "math"))
343 else if (!compare_ascii_no_case(*cit, "table"))
345 else if (!compare_ascii_no_case(*cit, "mathmacrotemplate"))
346 flag = MATHMACROTEMPLATE;
347 else if (!compare_ascii_no_case(*cit, "review"))
349 else if (!compare_ascii_no_case(*cit, "minibuffer"))
351 else if (!compare_ascii_no_case(*cit, "top"))
353 else if (!compare_ascii_no_case(*cit, "bottom"))
355 else if (!compare_ascii_no_case(*cit, "left"))
357 else if (!compare_ascii_no_case(*cit, "right"))
359 else if (!compare_ascii_no_case(*cit, "auto"))
361 else if (!compare_ascii_no_case(*cit, "samerow"))
363 else if (!compare_ascii_no_case(*cit, "ipa"))
367 "Toolbars::readToolbarSettings: unrecognised token:`"
373 toolbar_visibility_[name] = visibility;
375 if (visibility & ALLOWAUTO) {
376 if (ToolbarInfo const * ti = info(name))
377 const_cast<ToolbarInfo *>(ti)->gui_name +=
378 " (" + _("auto") + ")";
384 ToolbarInfo const * Toolbars::info(std::string const & name) const
386 Infos::const_iterator end = toolbar_info_.end();
387 for (Infos::const_iterator it = toolbar_info_.begin(); it != end; ++it)
388 if (it->name == name)
394 int Toolbars::defaultVisibility(std::string const & name) const
396 map<string, int>::const_iterator it = toolbar_visibility_.find(name);
397 if (it != toolbar_visibility_.end())
403 bool Toolbars::isMainToolbar(std::string const & name) const
405 return toolbar_visibility_.find(name) != toolbar_visibility_.end();
409 } // namespace frontend