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)
81 struct LexerKeyword toolTags[] = {
82 { "dynamicmenu", TO_DYNAMICMENU},
83 { "end", TO_ENDTOOLBAR },
84 { "exportformats", TO_EXPORTFORMATS },
85 { "iconpalette", TO_ICONPALETTE },
86 { "importformats", TO_IMPORTFORMATS },
87 { "item", TO_COMMAND },
88 { "layouts", TO_LAYOUTS },
89 { "minibuffer", TO_MINIBUFFER },
90 { "popupmenu", TO_POPUPMENU },
91 { "separator", TO_SEPARATOR },
92 { "stickypopupmenu", TO_STICKYPOPUPMENU },
93 { "tableinsert", TO_TABLEINSERT },
94 { "updateformats", TO_UPDATEFORMATS },
95 { "viewformats", TO_VIEWFORMATS },
99 if (compare_ascii_no_case(lex.getString(), "toolbar")) {
100 LYXERR0("ToolbarInfo::read: ERROR wrong token:`"
101 << lex.getString() << '\'');
105 name = lex.getString();
108 gui_name = _(lex.getString());
110 // FIXME what to do here?
112 LYXERR0("ToolbarInfo::read: Malformed toolbar "
113 "description " << lex.getString());
119 lex.pushTable(toolTags);
121 if (lyxerr.debugging(Debug::PARSER))
122 lex.printTable(lyxerr);
124 while (lex.isOK() && !quit) {
125 int const code = lex.lex();
128 if (lex.next(true)) {
129 docstring const tooltip = translateIfPossible(lex.getDocString());
131 string const func_arg = lex.getString();
132 LYXERR(Debug::PARSER, "ToolbarInfo::read TO_COMMAND func: `"
133 << func_arg << '\'');
136 lyxaction.lookupFunc(func_arg);
137 add(ToolbarItem(ToolbarItem::COMMAND, func, tooltip));
142 add(ToolbarItem(ToolbarItem::MINIBUFFER,
143 FuncRequest(FuncCode(ToolbarItem::MINIBUFFER))));
147 add(ToolbarItem(ToolbarItem::SEPARATOR,
148 FuncRequest(FuncCode(ToolbarItem::SEPARATOR))));
152 if (lex.next(true)) {
153 string const pname = lex.getString();
155 docstring const label = lex.getDocString();
156 add(ToolbarItem(ToolbarItem::POPUPMENU, pname, label));
160 case TO_DYNAMICMENU: {
161 if (lex.next(true)) {
162 string const name = lex.getString();
164 docstring const label = lex.getDocString();
165 add(ToolbarItem(ToolbarItem::DYNAMICMENU, name, label));
170 case TO_STICKYPOPUPMENU:
171 if (lex.next(true)) {
172 string const pname = lex.getString();
174 docstring const label = lex.getDocString();
175 add(ToolbarItem(ToolbarItem::STICKYPOPUPMENU, pname, label));
180 if (lex.next(true)) {
181 string const pname = lex.getString();
183 docstring const label = lex.getDocString();
184 add(ToolbarItem(ToolbarItem::ICONPALETTE, pname, label));
189 add(ToolbarItem(ToolbarItem::LAYOUTS,
190 FuncRequest(FuncCode(ToolbarItem::LAYOUTS))));
194 if (lex.next(true)) {
195 docstring const tooltip = lex.getDocString();
196 add(ToolbarItem(ToolbarItem::TABLEINSERT,
197 FuncRequest(FuncCode(ToolbarItem::TABLEINSERT)), tooltip));
205 case TO_EXPORTFORMATS:
206 case TO_IMPORTFORMATS:
207 case TO_UPDATEFORMATS:
208 case TO_VIEWFORMATS: {
210 if (code == TO_IMPORTFORMATS)
211 formats = theConverters().importableFormats();
212 else if (code == TO_EXPORTFORMATS)
213 formats = theConverters().exportableFormats(false);
215 formats = theConverters().exportableFormats(true);
216 sort(formats.begin(), formats.end());
217 for (Format const * f : formats) {
220 if (code != TO_IMPORTFORMATS &&
221 !f->documentFormat())
224 docstring const prettyname = f->prettyname();
226 FuncCode lfun = LFUN_NOACTION;
228 case TO_EXPORTFORMATS:
229 lfun = LFUN_BUFFER_EXPORT;
230 tooltip = _("Export %1$s");
232 case TO_IMPORTFORMATS:
233 lfun = LFUN_BUFFER_IMPORT;
234 tooltip = _("Import %1$s");
236 case TO_UPDATEFORMATS:
237 lfun = LFUN_BUFFER_UPDATE;
238 tooltip = _("Update %1$s");
241 lfun = LFUN_BUFFER_VIEW;
242 tooltip = _("View %1$s");
245 FuncRequest func(lfun, f->name(),
246 FuncRequest::TOOLBAR);
247 add(ToolbarItem(ToolbarItem::COMMAND, func,
248 bformat(tooltip, translateIfPossible(prettyname))));
254 lex.printError("ToolbarInfo::read: "
255 "Unknown toolbar tag: `$$Token'");
266 /////////////////////////////////////////////////////////////////////////
270 /////////////////////////////////////////////////////////////////////////
272 void Toolbars::reset()
274 toolbar_info_.clear();
275 toolbar_visibility_.clear();
279 void Toolbars::readToolbars(Lexer & lex)
286 struct LexerKeyword toolTags[] = {
287 { "end", TO_ENDTOOLBARSET },
288 { "toolbar", TO_TOOLBAR }
292 if (compare_ascii_no_case(lex.getString(), "toolbarset")) {
293 LYXERR0("Toolbars::readToolbars: ERROR wrong token:`"
294 << lex.getString() << '\'');
297 lex.pushTable(toolTags);
299 if (lyxerr.debugging(Debug::PARSER))
300 lex.printTable(lyxerr);
303 while (lex.isOK() && !quit) {
308 toolbar_info_.push_back(tbinfo);
311 case TO_ENDTOOLBARSET:
315 lex.printError("Toolbars::readToolbars: "
316 "Unknown toolbar tag: `$$Token'");
325 void Toolbars::readToolbarSettings(Lexer & lex)
328 if (compare_ascii_no_case(lex.getString(), "toolbars")) {
329 LYXERR0("Toolbars::readToolbarSettings: ERROR wrong token:`"
330 << lex.getString() << '\'');
336 string name = lex.getString();
339 if (!compare_ascii_no_case(name, "end"))
343 string flagstr = lex.getString();
345 vector<string> flags = getVectorFromString(flagstr);
347 vector<string>::const_iterator cit = flags.begin();
348 vector<string>::const_iterator end = flags.end();
350 for (; cit != end; ++cit) {
351 Visibility flag = ON;
352 if (!compare_ascii_no_case(*cit, "off"))
354 else if (!compare_ascii_no_case(*cit, "on"))
356 else if (!compare_ascii_no_case(*cit, "math"))
358 else if (!compare_ascii_no_case(*cit, "table"))
360 else if (!compare_ascii_no_case(*cit, "mathmacrotemplate"))
361 flag = MATHMACROTEMPLATE;
362 else if (!compare_ascii_no_case(*cit, "review"))
364 else if (!compare_ascii_no_case(*cit, "minibuffer"))
366 else if (!compare_ascii_no_case(*cit, "top"))
368 else if (!compare_ascii_no_case(*cit, "bottom"))
370 else if (!compare_ascii_no_case(*cit, "left"))
372 else if (!compare_ascii_no_case(*cit, "right"))
374 else if (!compare_ascii_no_case(*cit, "auto"))
376 else if (!compare_ascii_no_case(*cit, "samerow"))
378 else if (!compare_ascii_no_case(*cit, "ipa"))
382 "Toolbars::readToolbarSettings: unrecognised token:`"
388 toolbar_visibility_[name] = visibility;
390 if (visibility & ALLOWAUTO) {
391 if (ToolbarInfo const * ti = info(name))
392 const_cast<ToolbarInfo *>(ti)->gui_name +=
393 " (" + _("auto") + ")";
399 ToolbarInfo const * Toolbars::info(std::string const & name) const
401 Infos::const_iterator end = toolbar_info_.end();
402 for (Infos::const_iterator it = toolbar_info_.begin(); it != end; ++it)
403 if (it->name == name)
409 int Toolbars::defaultVisibility(std::string const & name) const
411 map<string, int>::const_iterator it = toolbar_visibility_.find(name);
412 if (it != toolbar_visibility_.end())
418 bool Toolbars::isMainToolbar(std::string const & name) const
420 return toolbar_visibility_.find(name) != toolbar_visibility_.end();
424 } // namespace frontend