]> git.lyx.org Git - lyx.git/blob - src/ToolbarBackend.C
3c2a8d08b9d7f3600dee7ecd5f45e248be7a7e93
[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 "support/lstrings.h"
19
20 using std::endl;
21
22 ToolbarBackend toolbarbackend;
23
24 namespace {
25
26 enum _tooltags {
27         TO_ADD = 1,
28         TO_ENDTOOLBAR,
29         TO_SEPARATOR,
30         TO_LAYOUTS,
31         TO_NEWLINE,
32         TO_LAST
33 };
34
35
36 struct keyword_item toolTags[TO_LAST - 1] = {
37         { "end", TO_ENDTOOLBAR },
38         { "icon", TO_ADD },
39         { "layouts", TO_LAYOUTS },
40         { "newline", TO_NEWLINE },
41         { "separator", TO_SEPARATOR }
42 };
43
44 } // end of anon namespace
45
46
47 ToolbarBackend::ToolbarBackend()
48 {
49 }
50
51
52 void ToolbarBackend::add(int action)
53 {
54         items.push_back(action);
55 }
56
57
58 void ToolbarBackend::read(LyXLex & lex)
59 {
60         //consistency check
61         if (compare_ascii_no_case(lex.getString(), "toolbar")) {
62                 lyxerr << "ToolbarBackend::read: ERROR wrong token:`"
63                        << lex.getString() << '\'' << endl;
64         }
65
66         bool quit = false;
67
68         lex.pushTable(toolTags, TO_LAST - 1);
69
70         if (lyxerr.debugging(Debug::PARSER))
71                 lex.printTable(lyxerr);
72
73         while (lex.isOK() && !quit) {
74                 switch (lex.lex()) {
75                 case TO_ADD:
76                         if (lex.next(true)) {
77                                 string const func = lex.getString();
78                                 lyxerr[Debug::PARSER]
79                                         << "ToolbarBackend::read TO_ADD func: `"
80                                         << func << '\'' << endl;
81                                 add(func);
82                         }
83                         break;
84
85                 case TO_SEPARATOR:
86                         add(SEPARATOR);
87                         break;
88
89                 case TO_LAYOUTS:
90                         add(LAYOUTS);
91                         break;
92
93                 case TO_NEWLINE:
94                         add(NEWLINE);
95                         break;
96
97                 case TO_ENDTOOLBAR:
98                         quit = true;
99                         break;
100                 default:
101                         lex.printError("ToolbarBackend::read: "
102                                        "Unknown toolbar tag: `$$Token'");
103                         break;
104                 }
105         }
106         lex.popTable();
107 }
108
109
110 void ToolbarBackend::add(string const & func)
111 {
112         int const tf = lyxaction.LookupFunc(func);
113
114         if (tf == -1) {
115                 lyxerr << "ToolbarBackend::add: no LyX command called `"
116                        << func << "' exists!" << endl;
117         } else {
118                 add(tf);
119         }
120 }