]> git.lyx.org Git - lyx.git/blob - src/ToolbarBackend.C
fix tab order
[lyx.git] / src / ToolbarBackend.C
1 /**
2  * \file ToolbarBackend.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author unknown
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #include <config.h>
12
13 #include "ToolbarBackend.h"
14 #include "LyXAction.h"
15 #include "lyxlex.h"
16 #include "debug.h"
17 #include "lyxlex.h"
18 #include "gettext.h"
19
20 #include "support/lstrings.h"
21 #include "support/filetools.h"
22
23 #include "frontends/controllers/ControlMath.h"
24
25 using std::endl;
26
27 ToolbarBackend toolbarbackend;
28
29 namespace {
30
31 enum tooltags {
32         TO_ADD = 1,
33         TO_ENDTOOLBAR,
34         TO_SEPARATOR,
35         TO_LAYOUTS,
36         TO_LAST
37 };
38
39
40 struct keyword_item toolTags[TO_LAST - 1] = {
41         { "end", TO_ENDTOOLBAR },
42         { "item", TO_ADD },
43         { "layouts", TO_LAYOUTS },
44         { "separator", TO_SEPARATOR }
45 };
46
47 } // end of anon namespace
48
49
50 ToolbarBackend::ToolbarBackend()
51 {
52 }
53
54
55 void ToolbarBackend::read(LyXLex & lex)
56 {
57         //consistency check
58         if (compare_ascii_no_case(lex.getString(), "toolbar")) {
59                 lyxerr << "ToolbarBackend::read: ERROR wrong token:`"
60                        << lex.getString() << '\'' << endl;
61         }
62
63         lex.next(true);
64
65         Toolbar tb;
66         tb.name = lex.getString();
67
68         lex.next(true);
69         string type = lex.getString();
70         if (!compare_ascii_no_case(type, "off"))
71                 tb.display_type = OFF;
72         else if (!compare_ascii_no_case(type, "on"))
73                 tb.display_type = ON;
74         else if (!compare_ascii_no_case(type, "math"))
75                 tb.display_type = MATH;
76         else if (!compare_ascii_no_case(type, "table"))
77                 tb.display_type = TABLE;
78         else {
79                 lyxerr << "ToolbarBackend::read: unrecognised token:`"
80                        << type << '\'' << endl;
81         }
82
83         bool quit = false;
84
85         lex.pushTable(toolTags, TO_LAST - 1);
86
87         if (lyxerr.debugging(Debug::PARSER))
88                 lex.printTable(lyxerr);
89
90         while (lex.isOK() && !quit) {
91                 switch (lex.lex()) {
92                 case TO_ADD:
93                         if (lex.next(true)) {
94                                 string const tooltip = _(lex.getString());
95                                 lex.next(true);
96                                 string const func = lex.getString();
97                                 lyxerr[Debug::PARSER]
98                                         << "ToolbarBackend::read TO_ADD func: `"
99                                         << func << '\'' << endl;
100                                 add(tb, func, tooltip);
101                         }
102                         break;
103
104                 case TO_SEPARATOR:
105                         add(tb, SEPARATOR);
106                         break;
107
108                 case TO_LAYOUTS:
109                         add(tb, LAYOUTS);
110                         break;
111
112                 case TO_ENDTOOLBAR:
113                         quit = true;
114                         break;
115                 default:
116                         lex.printError("ToolbarBackend::read: "
117                                        "Unknown toolbar tag: `$$Token'");
118                         break;
119                 }
120         }
121
122         toolbars.push_back(tb);
123
124         lex.popTable();
125 }
126
127
128 void ToolbarBackend::add(Toolbar & tb, int action, string const & tooltip)
129 {
130         tb.items.push_back(make_pair(action, tooltip));
131 }
132
133
134 void ToolbarBackend::add(Toolbar & tb, string const & func, string const & tooltip)
135 {
136         int const tf = lyxaction.LookupFunc(func);
137
138         if (tf == -1) {
139                 lyxerr << "ToolbarBackend::add: no LyX command called `"
140                        << func << "' exists!" << endl;
141         } else {
142                 add(tb, tf, tooltip);
143         }
144 }
145
146
147 string const ToolbarBackend::getIcon(int action)
148 {
149         string fullname;
150         FuncRequest f = lyxaction.retrieveActionArg(action);
151
152         if (f.action == LFUN_INSERT_MATH) {
153                 if (!f.argument.empty())
154                         fullname = find_xpm(f.argument.substr(1));
155         } else if (f.action == LFUN_MATH_DELIM) {
156                 fullname = find_xpm(f.argument);
157         } else {
158                 string const name = lyxaction.getActionName(f.action);
159                 string xpm_name(name);
160
161                 if (!f.argument.empty())
162                         xpm_name = subst(name + ' ' + f.argument, ' ', '_');
163
164                 fullname = LibFileSearch("images", xpm_name, "xpm");
165
166                 if (fullname.empty()) {
167                         // try without the argument
168                         fullname = LibFileSearch("images", name, "xpm");
169                 }
170         }
171
172         if (!fullname.empty()) {
173                 lyxerr[Debug::GUI] << "Full icon name is `"
174                                    << fullname << '\'' << endl;
175                 return fullname;
176         }
177
178         return LibFileSearch("images", "unknown", "xpm");
179 }