]> git.lyx.org Git - lyx.git/blob - src/ToolbarDefaults.C
another compile fix from herbert
[lyx.git] / src / ToolbarDefaults.C
1 /* This file is part of
2  * ======================================================
3  *
4  *           LyX, The Document Processor
5  *
6  *           Copyright 1995 Matthias Ettrich
7  *           Copyright 1995-2001 The LyX Team.
8  *
9  *
10  * ====================================================== */
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 #include <config.h>
17
18 #include "ToolbarDefaults.h"
19 #include "LyXAction.h"
20 #include "lyxlex.h"
21 #include "debug.h"
22 #include "lyxlex.h"
23 #include "support/lstrings.h"
24
25 using std::endl;
26
27 ToolbarDefaults toolbardefaults;
28
29 namespace {
30
31 enum _tooltags {
32         TO_ADD = 1,
33         TO_ENDTOOLBAR,
34         TO_SEPARATOR,
35         TO_LAYOUTS,
36         TO_NEWLINE,
37         TO_LAST
38 };
39
40
41 struct keyword_item toolTags[TO_LAST - 1] = {
42         { "end", TO_ENDTOOLBAR },
43         { "icon", TO_ADD },
44         { "layouts", TO_LAYOUTS },
45         { "newline", TO_NEWLINE },
46         { "separator", TO_SEPARATOR }
47 };
48
49 } // end of anon namespace
50
51
52 ToolbarDefaults::ToolbarDefaults()
53 {
54         init();
55 }
56
57
58 void ToolbarDefaults::add(int action)
59 {
60         defaults.push_back(action);
61 }
62
63
64 void ToolbarDefaults::init()
65 {
66         add(LAYOUTS);
67         add(LFUN_FILE_OPEN);
68         //add(LFUN_CLOSEBUFFER);
69         add(LFUN_MENUWRITE);
70         add(LFUN_MENUPRINT);
71         add(SEPARATOR);
72
73         add(LFUN_CUT);
74         add(LFUN_COPY);
75         add(LFUN_PASTE);
76         add(SEPARATOR);
77
78         add(LFUN_EMPH);
79         add(LFUN_NOUN);
80         add(LFUN_FREE);
81         add(SEPARATOR);
82
83         add(LFUN_INSET_FOOTNOTE);
84         add(LFUN_INSET_MARGINAL);
85
86         add(LFUN_DEPTH_PLUS);
87         add(SEPARATOR);
88
89         add(LFUN_MATH_MODE);
90         add(SEPARATOR);
91
92         add(LFUN_INSET_GRAPHICS);
93         add(LFUN_TABULAR_INSERT);
94 }
95
96
97 void ToolbarDefaults::read(LyXLex & lex)
98 {
99         //consistency check
100         if (compare_ascii_no_case(lex.getString(), "toolbar")) {
101                 lyxerr << "Toolbar::read: ERROR wrong token:`"
102                        << lex.getString() << '\'' << endl;
103         }
104
105         defaults.clear();
106
107         bool quit = false;
108
109         lex.pushTable(toolTags, TO_LAST - 1);
110
111         if (lyxerr.debugging(Debug::PARSER))
112                 lex.printTable(lyxerr);
113
114         while (lex.isOK() && !quit) {
115                 switch (lex.lex()) {
116                 case TO_ADD:
117                         if (lex.next(true)) {
118                                 string const func = lex.getString();
119                                 lyxerr[Debug::PARSER]
120                                         << "Toolbar::read TO_ADD func: `"
121                                         << func << "'" << endl;
122                                 add(func);
123                         }
124                         break;
125
126                 case TO_SEPARATOR:
127                         add(SEPARATOR);
128                         break;
129
130                 case TO_LAYOUTS:
131                         add(LAYOUTS);
132                         break;
133
134                 case TO_NEWLINE:
135                         add(NEWLINE);
136                         break;
137
138                 case TO_ENDTOOLBAR:
139                         quit = true;
140                         break;
141                 default:
142                         lex.printError("Toolbar::read: "
143                                        "Unknown toolbar tag: `$$Token'");
144                         break;
145                 }
146         }
147         lex.popTable();
148 }
149
150
151 void ToolbarDefaults::add(string const & func)
152 {
153         int const tf = lyxaction.LookupFunc(func);
154
155         if (tf == -1) {
156                 lyxerr << "Toolbar::add: no LyX command called `"
157                        << func << "' exists!" << endl;
158         } else {
159                 add(tf);
160         }
161 }