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: {
197 FormatList formats = (code == TO_IMPORTFORMATS) ?
198 theConverters().importableFormats() :
199 theConverters().exportableFormats(true);
200 sort(formats.begin(), formats.end());
201 for (Format const * f : formats) {
204 if (code != TO_IMPORTFORMATS &&
205 !f->documentFormat())
208 docstring const prettyname = f->prettyname();
210 FuncCode lfun = LFUN_NOACTION;
212 case TO_EXPORTFORMATS:
213 lfun = LFUN_BUFFER_EXPORT;
214 tooltip = _("Export %1$s");
216 case TO_IMPORTFORMATS:
217 lfun = LFUN_BUFFER_IMPORT;
218 tooltip = _("Import %1$s");
220 case TO_UPDATEFORMATS:
221 lfun = LFUN_BUFFER_UPDATE;
222 tooltip = _("Update %1$s");
225 lfun = LFUN_BUFFER_VIEW;
226 tooltip = _("View %1$s");
229 FuncRequest func(lfun, f->name(),
230 FuncRequest::TOOLBAR);
231 add(ToolbarItem(ToolbarItem::COMMAND, func,
232 bformat(tooltip, prettyname)));
238 lex.printError("ToolbarInfo::read: "
239 "Unknown toolbar tag: `$$Token'");
250 /////////////////////////////////////////////////////////////////////////
254 /////////////////////////////////////////////////////////////////////////
256 void Toolbars::reset()
258 toolbar_info_.clear();
259 toolbar_visibility_.clear();
263 void Toolbars::readToolbars(Lexer & lex)
270 struct LexerKeyword toolTags[] = {
271 { "end", TO_ENDTOOLBARSET },
272 { "toolbar", TO_TOOLBAR }
276 if (compare_ascii_no_case(lex.getString(), "toolbarset")) {
277 LYXERR0("Toolbars::readToolbars: ERROR wrong token:`"
278 << lex.getString() << '\'');
281 lex.pushTable(toolTags);
283 if (lyxerr.debugging(Debug::PARSER))
284 lex.printTable(lyxerr);
287 while (lex.isOK() && !quit) {
292 toolbar_info_.push_back(tbinfo);
295 case TO_ENDTOOLBARSET:
299 lex.printError("Toolbars::readToolbars: "
300 "Unknown toolbar tag: `$$Token'");
309 void Toolbars::readToolbarSettings(Lexer & lex)
312 if (compare_ascii_no_case(lex.getString(), "toolbars")) {
313 LYXERR0("Toolbars::readToolbarSettings: ERROR wrong token:`"
314 << lex.getString() << '\'');
320 string name = lex.getString();
323 if (!compare_ascii_no_case(name, "end"))
327 string flagstr = lex.getString();
329 vector<string> flags = getVectorFromString(flagstr);
331 vector<string>::const_iterator cit = flags.begin();
332 vector<string>::const_iterator end = flags.end();
334 for (; cit != end; ++cit) {
335 Visibility flag = ON;
336 if (!compare_ascii_no_case(*cit, "off"))
338 else if (!compare_ascii_no_case(*cit, "on"))
340 else if (!compare_ascii_no_case(*cit, "math"))
342 else if (!compare_ascii_no_case(*cit, "table"))
344 else if (!compare_ascii_no_case(*cit, "mathmacrotemplate"))
345 flag = MATHMACROTEMPLATE;
346 else if (!compare_ascii_no_case(*cit, "review"))
348 else if (!compare_ascii_no_case(*cit, "minibuffer"))
350 else if (!compare_ascii_no_case(*cit, "top"))
352 else if (!compare_ascii_no_case(*cit, "bottom"))
354 else if (!compare_ascii_no_case(*cit, "left"))
356 else if (!compare_ascii_no_case(*cit, "right"))
358 else if (!compare_ascii_no_case(*cit, "auto"))
360 else if (!compare_ascii_no_case(*cit, "samerow"))
362 else if (!compare_ascii_no_case(*cit, "ipa"))
366 "Toolbars::readToolbarSettings: unrecognised token:`"
372 toolbar_visibility_[name] = visibility;
374 if (visibility & ALLOWAUTO) {
375 if (ToolbarInfo const * ti = info(name))
376 const_cast<ToolbarInfo *>(ti)->gui_name +=
377 " (" + _("auto") + ")";
383 ToolbarInfo const * Toolbars::info(std::string const & name) const
385 Infos::const_iterator end = toolbar_info_.end();
386 for (Infos::const_iterator it = toolbar_info_.begin(); it != end; ++it)
387 if (it->name == name)
393 int Toolbars::defaultVisibility(std::string const & name) const
395 map<string, int>::const_iterator it = toolbar_visibility_.find(name);
396 if (it != toolbar_visibility_.end())
402 bool Toolbars::isMainToolbar(std::string const & name) const
404 return toolbar_visibility_.find(name) != toolbar_visibility_.end();
408 } // namespace frontend