X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FToolbarBackend.C;h=b12fed44df1b0f956d33e2acc45285935a02072b;hb=e7f4618bcce770369cf46335c2c7f0164b4b8857;hp=0d15ccc091ab9cf1b11ee6d14e2105a7e2af0949;hpb=0e9bd2e87dbf1f2791cead146f114b555d2ca86d;p=lyx.git diff --git a/src/ToolbarBackend.C b/src/ToolbarBackend.C index 0d15ccc091..b12fed44df 100644 --- a/src/ToolbarBackend.C +++ b/src/ToolbarBackend.C @@ -3,18 +3,19 @@ * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * - * \author unknown + * \author Jean-Marc Lasgouttes + * \author John Levon * - * Full author contact details are available in file CREDITS + * Full author contact details are available in file CREDITS. */ #include #include "ToolbarBackend.h" +#include "funcrequest.h" #include "LyXAction.h" #include "lyxlex.h" #include "debug.h" -#include "lyxlex.h" #include "gettext.h" #include "support/lstrings.h" @@ -22,11 +23,19 @@ #include "frontends/controllers/ControlMath.h" -#include + +namespace lyx { + +using support::compare_ascii_no_case; +using support::getVectorFromString; +using support::libFileSearch; +using support::subst; using std::endl; -using std::vector; using std::make_pair; +using std::string; +using std::vector; + ToolbarBackend toolbarbackend; @@ -49,7 +58,7 @@ struct keyword_item toolTags[TO_LAST - 1] = { { "separator", TO_SEPARATOR } }; -} // end of anon namespace +} // namespace anon ToolbarBackend::ToolbarBackend() @@ -70,38 +79,12 @@ void ToolbarBackend::read(LyXLex & lex) Toolbar tb; tb.name = lex.getString(); lex.next(true); - - tb.flags = static_cast(0); - string flagstr = lex.getString(); - vector flags = getVectorFromString(flagstr); - - vector::const_iterator cit = flags.begin(); - vector::const_iterator end = flags.end(); - - for (; cit != end; ++cit) { - int flag = 0; - if (!compare_ascii_no_case(*cit, "off")) - flag = OFF; - else if (!compare_ascii_no_case(*cit, "on")) - flag = ON; - else if (!compare_ascii_no_case(*cit, "math")) - flag = MATH; - else if (!compare_ascii_no_case(*cit, "table")) - flag = TABLE; - else if (!compare_ascii_no_case(*cit, "top")) - flag = TOP; - else if (!compare_ascii_no_case(*cit, "bottom")) - flag = BOTTOM; - else if (!compare_ascii_no_case(*cit, "left")) - flag = LEFT; - else if (!compare_ascii_no_case(*cit, "right")) - flag = RIGHT; - else { - lyxerr << "ToolbarBackend::read: unrecognised token:`" - << *cit << '\'' << endl; - } - tb.flags = static_cast(tb.flags | flag); + if (!lex.isOK()) { + lyxerr << "ToolbarBackend::read: Malformed toolbar " + "description " << lex.getString() << endl; + return; } + tb.gui_name = lex.getString(); bool quit = false; @@ -114,26 +97,29 @@ void ToolbarBackend::read(LyXLex & lex) switch (lex.lex()) { case TO_ADD: if (lex.next(true)) { - string const tooltip = _(lex.getString()); + docstring const tooltip = translateIfPossible(lex.getDocString()); lex.next(true); - string const func = lex.getString(); + string const func_arg = lex.getString(); lyxerr[Debug::PARSER] << "ToolbarBackend::read TO_ADD func: `" - << func << '\'' << endl; + << func_arg << '\'' << endl; + + FuncRequest func = + lyxaction.lookupFunc(func_arg); add(tb, func, tooltip); } break; case TO_MINIBUFFER: - add(tb, MINIBUFFER); + add(tb, FuncRequest(kb_action(MINIBUFFER))); break; case TO_SEPARATOR: - add(tb, SEPARATOR); + add(tb, FuncRequest(kb_action(SEPARATOR))); break; case TO_LAYOUTS: - add(tb, LAYOUTS); + add(tb, FuncRequest(kb_action(LAYOUTS))); break; case TO_ENDTOOLBAR: @@ -152,47 +138,111 @@ void ToolbarBackend::read(LyXLex & lex) } -void ToolbarBackend::add(Toolbar & tb, int action, string const & tooltip) +void ToolbarBackend::readToolbars(LyXLex & lex) { - tb.items.push_back(make_pair(action, tooltip)); -} + //consistency check + if (compare_ascii_no_case(lex.getString(), "toolbars")) { + lyxerr << "ToolbarBackend::read: ERROR wrong token:`" + << lex.getString() << '\'' << endl; + } + + lex.next(true); + while (lex.isOK()) { + string name = lex.getString(); + lex.next(true); -void ToolbarBackend::add(Toolbar & tb, string const & func, string const & tooltip) -{ - int const tf = lyxaction.LookupFunc(func); + if (!compare_ascii_no_case(name, "end")) + return; - if (tf == -1) { - lyxerr << "ToolbarBackend::add: no LyX command called `" - << func << "' exists!" << endl; - } else { - add(tb, tf, tooltip); + Toolbars::iterator tcit = toolbars.begin(); + Toolbars::iterator tend = toolbars.end(); + for (; tcit != tend; ++tcit) { + if (tcit->name == name) + break; + } + + if (tcit == tend) { + lyxerr << "ToolbarBackend: undefined toolbar " + << name << endl; + return; + } + + tcit->flags = static_cast(0); + string flagstr = lex.getString(); + lex.next(true); + vector flags = getVectorFromString(flagstr); + + vector::const_iterator cit = flags.begin(); + vector::const_iterator end = flags.end(); + + for (; cit != end; ++cit) { + int flag = 0; + if (!compare_ascii_no_case(*cit, "off")) + flag = OFF; + else if (!compare_ascii_no_case(*cit, "on")) + flag = ON; + else if (!compare_ascii_no_case(*cit, "math")) + flag = MATH; + else if (!compare_ascii_no_case(*cit, "table")) + flag = TABLE; + else if (!compare_ascii_no_case(*cit, "review")) + flag = REVIEW; + else if (!compare_ascii_no_case(*cit, "top")) + flag = TOP; + else if (!compare_ascii_no_case(*cit, "bottom")) + flag = BOTTOM; + else if (!compare_ascii_no_case(*cit, "left")) + flag = LEFT; + else if (!compare_ascii_no_case(*cit, "right")) + flag = RIGHT; + else { + lyxerr << "ToolbarBackend::read: unrecognised token:`" + << *cit << '\'' << endl; + } + tcit->flags = static_cast(tcit->flags | flag); + } + + usedtoolbars.push_back(*tcit); } } -string const ToolbarBackend::getIcon(int action) +void ToolbarBackend::add(Toolbar & tb, + FuncRequest const & func, docstring const & tooltip) { + tb.items.push_back(make_pair(func, tooltip)); + tb.items.back().first.origin = FuncRequest::TOOLBAR; +} + + +string const ToolbarBackend::getIcon(FuncRequest const & f) +{ + using frontend::find_xpm; + string fullname; - FuncRequest f = lyxaction.retrieveActionArg(action); - - if (f.action == LFUN_INSERT_MATH) { - if (!f.argument.empty()) - fullname = find_xpm(f.argument.substr(1)); - } else if (f.action == LFUN_MATH_DELIM) { - fullname = find_xpm(f.argument); - } else { + + switch (f.action) { + case LFUN_MATH_INSERT: + if (!f.argument().empty()) + fullname = find_xpm(to_utf8(f.argument()).substr(1)); + break; + case LFUN_MATH_DELIM: + case LFUN_MATH_BIGDELIM: + fullname = find_xpm(to_utf8(f.argument())); + break; + default: string const name = lyxaction.getActionName(f.action); string xpm_name(name); - if (!f.argument.empty()) - xpm_name = subst(name + ' ' + f.argument, ' ', '_'); + if (!f.argument().empty()) + xpm_name = subst(name + ' ' + to_utf8(f.argument()), ' ', '_'); - fullname = LibFileSearch("images", xpm_name, "xpm"); + fullname = libFileSearch("images", xpm_name, "xpm").absFilename(); if (fullname.empty()) { // try without the argument - fullname = LibFileSearch("images", name, "xpm"); + fullname = libFileSearch("images", name, "xpm").absFilename(); } } @@ -202,5 +252,11 @@ string const ToolbarBackend::getIcon(int action) return fullname; } - return LibFileSearch("images", "unknown", "xpm"); + lyxerr[Debug::GUI] << "Cannot find icon for command \"" + << lyxaction.getActionName(f.action) + << '(' << to_utf8(f.argument()) << ")\"" << endl; + return libFileSearch("images", "unknown", "xpm").absFilename(); } + + +} // namespace lyx