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,
42 docstring const & label)
43 : type_(type), func_(make_shared<FuncRequest>(func)), label_(label)
48 ToolbarItem::ToolbarItem(Type type, string const & name,
49 docstring const & label)
50 : type_(type), func_(make_shared<FuncRequest>()), label_(label), name_(name)
55 void ToolbarInfo::add(ToolbarItem const & item)
57 items.push_back(item);
58 items.back().func_->setOrigin(FuncRequest::TOOLBAR);
62 ToolbarInfo & ToolbarInfo::read(Lexer & lex)
80 struct LexerKeyword toolTags[] = {
81 { "end", TO_ENDTOOLBAR },
82 { "exportformats", TO_EXPORTFORMATS },
83 { "iconpalette", TO_ICONPALETTE },
84 { "importformats", TO_IMPORTFORMATS },
85 { "item", TO_COMMAND },
86 { "layouts", TO_LAYOUTS },
87 { "minibuffer", TO_MINIBUFFER },
88 { "popupmenu", TO_POPUPMENU },
89 { "separator", TO_SEPARATOR },
90 { "stickypopupmenu", TO_STICKYPOPUPMENU },
91 { "tableinsert", TO_TABLEINSERT },
92 { "updateformats", TO_UPDATEFORMATS },
93 { "viewformats", TO_VIEWFORMATS },
97 if (compare_ascii_no_case(lex.getString(), "toolbar")) {
98 LYXERR0("ToolbarInfo::read: ERROR wrong token:`"
99 << lex.getString() << '\'');
103 name = lex.getString();
106 gui_name = _(lex.getString());
108 // FIXME what to do here?
110 LYXERR0("ToolbarInfo::read: Malformed toolbar "
111 "description " << lex.getString());
117 lex.pushTable(toolTags);
119 if (lyxerr.debugging(Debug::PARSER))
120 lex.printTable(lyxerr);
122 while (lex.isOK() && !quit) {
123 int const code = lex.lex();
126 if (lex.next(true)) {
127 docstring const tooltip = translateIfPossible(lex.getDocString());
129 string const func_arg = lex.getString();
130 LYXERR(Debug::PARSER, "ToolbarInfo::read TO_COMMAND func: `"
131 << func_arg << '\'');
134 lyxaction.lookupFunc(func_arg);
135 add(ToolbarItem(ToolbarItem::COMMAND, func, tooltip));
140 add(ToolbarItem(ToolbarItem::MINIBUFFER,
141 FuncRequest(FuncCode(ToolbarItem::MINIBUFFER))));
145 add(ToolbarItem(ToolbarItem::SEPARATOR,
146 FuncRequest(FuncCode(ToolbarItem::SEPARATOR))));
150 if (lex.next(true)) {
151 string const name = lex.getString();
153 docstring const label = lex.getDocString();
154 add(ToolbarItem(ToolbarItem::POPUPMENU, name, label));
158 case TO_STICKYPOPUPMENU:
159 if (lex.next(true)) {
160 string const name = lex.getString();
162 docstring const label = lex.getDocString();
163 add(ToolbarItem(ToolbarItem::STICKYPOPUPMENU, name, label));
168 if (lex.next(true)) {
169 string const name = lex.getString();
171 docstring const label = lex.getDocString();
172 add(ToolbarItem(ToolbarItem::ICONPALETTE, name, label));
177 add(ToolbarItem(ToolbarItem::LAYOUTS,
178 FuncRequest(FuncCode(ToolbarItem::LAYOUTS))));
182 if (lex.next(true)) {
183 docstring const tooltip = lex.getDocString();
184 add(ToolbarItem(ToolbarItem::TABLEINSERT,
185 FuncRequest(FuncCode(ToolbarItem::TABLEINSERT)), tooltip));
193 case TO_EXPORTFORMATS:
194 case TO_IMPORTFORMATS:
195 case TO_UPDATEFORMATS:
196 case TO_VIEWFORMATS: {
198 if (code == TO_IMPORTFORMATS)
199 formats = theConverters().importableFormats();
200 else if (code == TO_EXPORTFORMATS)
201 formats = theConverters().exportableFormats(false);
203 formats = theConverters().exportableFormats(true);
204 sort(formats.begin(), formats.end());
205 for (Format const * f : formats) {
208 if (code != TO_IMPORTFORMATS &&
209 !f->documentFormat())
212 docstring const prettyname = f->prettyname();
214 FuncCode lfun = LFUN_NOACTION;
216 case TO_EXPORTFORMATS:
217 lfun = LFUN_BUFFER_EXPORT;
218 tooltip = _("Export %1$s");
220 case TO_IMPORTFORMATS:
221 lfun = LFUN_BUFFER_IMPORT;
222 tooltip = _("Import %1$s");
224 case TO_UPDATEFORMATS:
225 lfun = LFUN_BUFFER_UPDATE;
226 tooltip = _("Update %1$s");
229 lfun = LFUN_BUFFER_VIEW;
230 tooltip = _("View %1$s");
233 FuncRequest func(lfun, f->name(),
234 FuncRequest::TOOLBAR);
235 add(ToolbarItem(ToolbarItem::COMMAND, func,
236 bformat(tooltip, translateIfPossible(prettyname))));
242 lex.printError("ToolbarInfo::read: "
243 "Unknown toolbar tag: `$$Token'");
254 /////////////////////////////////////////////////////////////////////////
258 /////////////////////////////////////////////////////////////////////////
260 void Toolbars::reset()
262 toolbar_info_.clear();
263 toolbar_visibility_.clear();
267 void Toolbars::readToolbars(Lexer & lex)
274 struct LexerKeyword toolTags[] = {
275 { "end", TO_ENDTOOLBARSET },
276 { "toolbar", TO_TOOLBAR }
280 if (compare_ascii_no_case(lex.getString(), "toolbarset")) {
281 LYXERR0("Toolbars::readToolbars: ERROR wrong token:`"
282 << lex.getString() << '\'');
285 lex.pushTable(toolTags);
287 if (lyxerr.debugging(Debug::PARSER))
288 lex.printTable(lyxerr);
291 while (lex.isOK() && !quit) {
296 toolbar_info_.push_back(tbinfo);
299 case TO_ENDTOOLBARSET:
303 lex.printError("Toolbars::readToolbars: "
304 "Unknown toolbar tag: `$$Token'");
313 void Toolbars::readToolbarSettings(Lexer & lex)
316 if (compare_ascii_no_case(lex.getString(), "toolbars")) {
317 LYXERR0("Toolbars::readToolbarSettings: ERROR wrong token:`"
318 << lex.getString() << '\'');
324 string name = lex.getString();
327 if (!compare_ascii_no_case(name, "end"))
331 string flagstr = lex.getString();
333 vector<string> flags = getVectorFromString(flagstr);
335 vector<string>::const_iterator cit = flags.begin();
336 vector<string>::const_iterator end = flags.end();
338 for (; cit != end; ++cit) {
339 Visibility flag = ON;
340 if (!compare_ascii_no_case(*cit, "off"))
342 else if (!compare_ascii_no_case(*cit, "on"))
344 else if (!compare_ascii_no_case(*cit, "math"))
346 else if (!compare_ascii_no_case(*cit, "table"))
348 else if (!compare_ascii_no_case(*cit, "mathmacrotemplate"))
349 flag = MATHMACROTEMPLATE;
350 else if (!compare_ascii_no_case(*cit, "review"))
352 else if (!compare_ascii_no_case(*cit, "minibuffer"))
354 else if (!compare_ascii_no_case(*cit, "top"))
356 else if (!compare_ascii_no_case(*cit, "bottom"))
358 else if (!compare_ascii_no_case(*cit, "left"))
360 else if (!compare_ascii_no_case(*cit, "right"))
362 else if (!compare_ascii_no_case(*cit, "auto"))
364 else if (!compare_ascii_no_case(*cit, "samerow"))
366 else if (!compare_ascii_no_case(*cit, "ipa"))
370 "Toolbars::readToolbarSettings: unrecognised token:`"
376 toolbar_visibility_[name] = visibility;
378 if (visibility & ALLOWAUTO) {
379 if (ToolbarInfo const * ti = info(name))
380 const_cast<ToolbarInfo *>(ti)->gui_name +=
381 " (" + _("auto") + ")";
387 ToolbarInfo const * Toolbars::info(std::string const & name) const
389 Infos::const_iterator end = toolbar_info_.end();
390 for (Infos::const_iterator it = toolbar_info_.begin(); it != end; ++it)
391 if (it->name == name)
397 int Toolbars::defaultVisibility(std::string const & name) const
399 map<string, int>::const_iterator it = toolbar_visibility_.find(name);
400 if (it != toolbar_visibility_.end())
406 bool Toolbars::isMainToolbar(std::string const & name) const
408 return toolbar_visibility_.find(name) != toolbar_visibility_.end();
412 } // namespace frontend