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 t, FuncRequest const & f,
43 : type(t), func(make_shared<FuncRequest>(f)), label(l)
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)
82 struct LexerKeyword toolTags[] = {
83 { "bidiitem", TO_BIDICOMMAND},
84 { "dynamicmenu", TO_DYNAMICMENU},
85 { "end", TO_ENDTOOLBAR },
86 { "exportformats", TO_EXPORTFORMATS },
87 { "iconpalette", TO_ICONPALETTE },
88 { "importformats", TO_IMPORTFORMATS },
89 { "item", TO_COMMAND },
90 { "layouts", TO_LAYOUTS },
91 { "minibuffer", TO_MINIBUFFER },
92 { "popupmenu", TO_POPUPMENU },
93 { "separator", TO_SEPARATOR },
94 { "stickypopupmenu", TO_STICKYPOPUPMENU },
95 { "tableinsert", TO_TABLEINSERT },
96 { "updateformats", TO_UPDATEFORMATS },
97 { "viewformats", TO_VIEWFORMATS },
101 if (compare_ascii_no_case(lex.getString(), "toolbar")) {
102 LYXERR0("ToolbarInfo::read: ERROR wrong token:`"
103 << lex.getString() << '\'');
107 name = lex.getString();
110 gui_name = _(lex.getString());
112 // FIXME what to do here?
114 LYXERR0("ToolbarInfo::read: Malformed toolbar "
115 "description " << lex.getString());
121 lex.pushTable(toolTags);
123 if (lyxerr.debugging(Debug::PARSER))
124 lex.printTable(lyxerr);
126 while (lex.isOK() && !quit) {
127 int const code = lex.lex();
130 if (lex.next(true)) {
131 docstring const tooltip = translateIfPossible(lex.getDocString());
133 string const func_arg = lex.getString();
134 LYXERR(Debug::PARSER, "ToolbarInfo::read TO_COMMAND func: `"
135 << func_arg << '\'');
138 lyxaction.lookupFunc(func_arg);
139 add(ToolbarItem(ToolbarItem::COMMAND, func, tooltip));
144 if (lex.next(true)) {
145 docstring const tooltip = translateIfPossible(lex.getDocString());
147 string const func_arg = lex.getString();
148 LYXERR(Debug::PARSER, "ToolbarInfo::read TO_BIDICOMMAND func: `"
149 << func_arg << '\'');
152 lyxaction.lookupFunc(func_arg);
153 add(ToolbarItem(ToolbarItem::BIDICOMMAND, func, tooltip));
158 add(ToolbarItem(ToolbarItem::MINIBUFFER,
159 FuncRequest(FuncCode(ToolbarItem::MINIBUFFER))));
163 add(ToolbarItem(ToolbarItem::SEPARATOR,
164 FuncRequest(FuncCode(ToolbarItem::SEPARATOR))));
168 if (lex.next(true)) {
169 string const pname = lex.getString();
171 docstring const label = lex.getDocString();
172 add(ToolbarItem(ToolbarItem::POPUPMENU, pname, label));
176 case TO_DYNAMICMENU: {
177 if (lex.next(true)) {
178 string const name = lex.getString();
180 docstring const label = lex.getDocString();
181 add(ToolbarItem(ToolbarItem::DYNAMICMENU, name, label));
186 case TO_STICKYPOPUPMENU:
187 if (lex.next(true)) {
188 string const pname = lex.getString();
190 docstring const label = lex.getDocString();
191 add(ToolbarItem(ToolbarItem::STICKYPOPUPMENU, pname, label));
196 if (lex.next(true)) {
197 string const pname = lex.getString();
199 docstring const label = lex.getDocString();
200 add(ToolbarItem(ToolbarItem::ICONPALETTE, pname, label));
205 add(ToolbarItem(ToolbarItem::LAYOUTS,
206 FuncRequest(FuncCode(ToolbarItem::LAYOUTS))));
210 if (lex.next(true)) {
211 docstring const tooltip = lex.getDocString();
212 add(ToolbarItem(ToolbarItem::TABLEINSERT,
213 FuncRequest(FuncCode(ToolbarItem::TABLEINSERT)), tooltip));
221 case TO_EXPORTFORMATS:
222 case TO_IMPORTFORMATS:
223 case TO_UPDATEFORMATS:
224 case TO_VIEWFORMATS: {
226 if (code == TO_IMPORTFORMATS)
227 formats = theConverters().importableFormats();
228 else if (code == TO_EXPORTFORMATS)
229 formats = theConverters().exportableFormats(false);
231 formats = theConverters().exportableFormats(true);
232 sort(formats.begin(), formats.end());
233 for (Format const * f : formats) {
236 if (code != TO_IMPORTFORMATS &&
237 !f->documentFormat())
240 docstring const prettyname = f->prettyname();
242 FuncCode lfun = LFUN_NOACTION;
244 case TO_EXPORTFORMATS:
245 lfun = LFUN_BUFFER_EXPORT;
246 tooltip = _("Export %1$s");
248 case TO_IMPORTFORMATS:
249 lfun = LFUN_BUFFER_IMPORT;
250 tooltip = _("Import %1$s");
252 case TO_UPDATEFORMATS:
253 lfun = LFUN_BUFFER_UPDATE;
254 tooltip = _("Update %1$s");
257 lfun = LFUN_BUFFER_VIEW;
258 tooltip = _("View %1$s");
261 FuncRequest func(lfun, f->name(),
262 FuncRequest::TOOLBAR);
263 add(ToolbarItem(ToolbarItem::COMMAND, func,
264 bformat(tooltip, translateIfPossible(prettyname))));
270 lex.printError("ToolbarInfo::read: "
271 "Unknown toolbar tag: `$$Token'");
282 /////////////////////////////////////////////////////////////////////////
286 /////////////////////////////////////////////////////////////////////////
288 void Toolbars::reset()
290 toolbar_info_.clear();
291 toolbar_visibility_.clear();
295 void Toolbars::readToolbars(Lexer & lex)
302 struct LexerKeyword toolTags[] = {
303 { "end", TO_ENDTOOLBARSET },
304 { "toolbar", TO_TOOLBAR }
308 if (compare_ascii_no_case(lex.getString(), "toolbarset")) {
309 LYXERR0("Toolbars::readToolbars: ERROR wrong token:`"
310 << lex.getString() << '\'');
313 lex.pushTable(toolTags);
315 if (lyxerr.debugging(Debug::PARSER))
316 lex.printTable(lyxerr);
319 while (lex.isOK() && !quit) {
324 toolbar_info_.push_back(tbinfo);
327 case TO_ENDTOOLBARSET:
331 lex.printError("Toolbars::readToolbars: "
332 "Unknown toolbar tag: `$$Token'");
341 void Toolbars::readToolbarSettings(Lexer & lex)
344 if (compare_ascii_no_case(lex.getString(), "toolbars")) {
345 LYXERR0("Toolbars::readToolbarSettings: ERROR wrong token:`"
346 << lex.getString() << '\'');
352 string name = lex.getString();
355 if (!compare_ascii_no_case(name, "end"))
359 string flagstr = lex.getString();
361 vector<string> flags = getVectorFromString(flagstr);
363 vector<string>::const_iterator cit = flags.begin();
364 vector<string>::const_iterator end = flags.end();
366 for (; cit != end; ++cit) {
367 Visibility flag = ON;
368 if (!compare_ascii_no_case(*cit, "off"))
370 else if (!compare_ascii_no_case(*cit, "on"))
372 else if (!compare_ascii_no_case(*cit, "math"))
374 else if (!compare_ascii_no_case(*cit, "table"))
376 else if (!compare_ascii_no_case(*cit, "mathmacrotemplate"))
377 flag = MATHMACROTEMPLATE;
378 else if (!compare_ascii_no_case(*cit, "review"))
380 else if (!compare_ascii_no_case(*cit, "minibuffer"))
382 else if (!compare_ascii_no_case(*cit, "top"))
384 else if (!compare_ascii_no_case(*cit, "bottom"))
386 else if (!compare_ascii_no_case(*cit, "left"))
388 else if (!compare_ascii_no_case(*cit, "right"))
390 else if (!compare_ascii_no_case(*cit, "auto"))
392 else if (!compare_ascii_no_case(*cit, "samerow"))
394 else if (!compare_ascii_no_case(*cit, "ipa"))
398 "Toolbars::readToolbarSettings: unrecognised token:`"
404 toolbar_visibility_[name] = visibility;
406 if (visibility & ALLOWAUTO) {
407 if (ToolbarInfo const * ti = info(name))
408 const_cast<ToolbarInfo *>(ti)->allow_auto = true;
414 ToolbarInfo const * Toolbars::info(std::string const & name) const
416 Infos::const_iterator end = toolbar_info_.end();
417 for (Infos::const_iterator it = toolbar_info_.begin(); it != end; ++it)
418 if (it->name == name)
424 int Toolbars::defaultVisibility(std::string const & name) const
426 map<string, int>::const_iterator it = toolbar_visibility_.find(name);
427 if (it != toolbar_visibility_.end())
433 bool Toolbars::isMainToolbar(std::string const & name) const
435 return toolbar_visibility_.find(name) != toolbar_visibility_.end();
439 } // namespace frontend