]> git.lyx.org Git - lyx.git/blobdiff - src/ToolbarBackend.C
update Basque and Romanian l10n
[lyx.git] / src / ToolbarBackend.C
index 4fc07de1fb2351495d88ace9323281ad705f2c48..970829b1aa285dd0f0666597eba8a525ce29b2c1 100644 (file)
 #include "frontends/controllers/ControlMath.h"
 
 
-using namespace lyx::support;
+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;
 
@@ -51,7 +58,7 @@ struct keyword_item toolTags[TO_LAST - 1] = {
        { "separator", TO_SEPARATOR }
 };
 
-} // end of anon namespace
+} // namespace anon
 
 
 ToolbarBackend::ToolbarBackend()
@@ -71,6 +78,13 @@ void ToolbarBackend::read(LyXLex & lex)
 
        Toolbar tb;
        tb.name = lex.getString();
+       lex.next(true);
+       if (!lex.isOK()) {
+               lyxerr << "ToolbarBackend::read: Malformed toolbar "
+                       "description " <<  lex.getString() << endl;
+               return;
+       }
+       tb.gui_name = lex.getString();
 
        bool quit = false;
 
@@ -83,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 = _(lex.getString());
                                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:
@@ -169,6 +186,8 @@ void ToolbarBackend::readToolbars(LyXLex & lex)
                                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"))
@@ -189,47 +208,41 @@ void ToolbarBackend::readToolbars(LyXLex & lex)
 }
 
 
-void ToolbarBackend::add(Toolbar & tb, int action, string const & tooltip)
+void ToolbarBackend::add(Toolbar & tb,
+                        FuncRequest const & func, docstring const & tooltip)
 {
-       tb.items.push_back(make_pair(action, tooltip));
+       tb.items.push_back(make_pair(func, tooltip));
+       tb.items.back().first.origin = FuncRequest::TOOLBAR;
 }
 
 
-void ToolbarBackend::add(Toolbar & tb, string const & func, string const & tooltip)
+string const ToolbarBackend::getIcon(FuncRequest const & f)
 {
-       int const tf = lyxaction.LookupFunc(func);
+       using frontend::find_xpm;
 
-       if (tf == -1) {
-               lyxerr << "ToolbarBackend::add: no LyX command called `"
-                      << func << "' exists!" << endl;
-       } else {
-               add(tb, tf, tooltip);
-       }
-}
-
-
-string const ToolbarBackend::getIcon(int action)
-{
        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");
 
                if (fullname.empty()) {
                        // try without the argument
-                       fullname = LibFileSearch("images", name, "xpm");
+                       fullname = libFileSearch("images", name, "xpm");
                }
        }
 
@@ -241,6 +254,9 @@ string const ToolbarBackend::getIcon(int action)
 
        lyxerr[Debug::GUI] << "Cannot find icon for command \""
                           << lyxaction.getActionName(f.action)
-                          << ' ' << f.argument << '"' << endl;
-       return LibFileSearch("images", "unknown", "xpm");
+                          << '(' << to_utf8(f.argument()) << ")\"" << endl;
+       return libFileSearch("images", "unknown", "xpm");
 }
+
+
+} // namespace lyx