]> git.lyx.org Git - lyx.git/blob - src/ToolbarDefaults.C
* John's maths patch,
[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 extern LyXAction lyxaction;
28 ToolbarDefaults toolbardefaults;
29
30
31 ToolbarDefaults::ToolbarDefaults()
32 {
33         init();
34 }
35
36
37 void ToolbarDefaults::add(int action)
38 {
39         defaults.push_back(action);
40 }
41
42
43 void ToolbarDefaults::init() 
44 {
45         add(LAYOUTS);
46         add(LFUN_FILE_OPEN);
47         //add(LFUN_CLOSEBUFFER);
48         add(LFUN_MENUWRITE);
49         add(LFUN_MENUPRINT);
50         add(SEPARATOR);
51
52         add(LFUN_CUT);
53         add(LFUN_COPY);
54         add(LFUN_PASTE);
55         add(SEPARATOR);
56         
57         add(LFUN_EMPH);
58         add(LFUN_NOUN);
59         add(LFUN_FREE);
60         add(SEPARATOR);
61         
62         add(LFUN_INSET_FOOTNOTE);
63         add(LFUN_INSET_MARGINAL);
64
65         add(LFUN_DEPTH);
66         add(SEPARATOR);
67
68 #ifndef NO_LATEX
69         add(LFUN_TEX);
70 #endif
71         add(LFUN_MATH_MODE);
72         add(SEPARATOR);
73
74         add(LFUN_FIGURE);
75         add(LFUN_DIALOG_TABULAR_INSERT);
76 }
77
78
79 enum _tooltags {
80         TO_ADD = 1,
81         TO_ENDTOOLBAR,
82         TO_SEPARATOR,
83         TO_LAYOUTS,
84         TO_NEWLINE,
85         TO_LAST
86 };
87
88
89 struct keyword_item toolTags[TO_LAST - 1] = {
90         { "end", TO_ENDTOOLBAR },
91         { "icon", TO_ADD },
92         { "layouts", TO_LAYOUTS },
93         { "newline", TO_NEWLINE },
94         { "separator", TO_SEPARATOR }
95 };
96
97
98 void ToolbarDefaults::read(LyXLex & lex) 
99 {
100         //consistency check
101         if (compare_no_case(lex.GetString(), "toolbar"))
102                 lyxerr << "Toolbar::read: ERROR wrong token:`"
103                        << lex.GetString() << '\'' << endl;
104
105         defaults.clear();
106         
107         string func;
108         bool quit = false;
109         
110         lex.pushTable(toolTags, TO_LAST - 1);
111
112         if (lyxerr.debugging(Debug::PARSER))
113                 lex.printTable(lyxerr);
114
115         while (lex.IsOK() && !quit) {
116                 switch (lex.lex()) {
117                 case TO_ADD:
118                         if (lex.next(true)) {
119                                 func = lex.GetString();
120                                 lyxerr[Debug::PARSER]
121                                         << "Toolbar::read TO_ADD func: `"
122                                         << func << "'" << endl;
123                                 add(func);
124                         }
125                         break;
126                    
127                 case TO_SEPARATOR:
128                         add(SEPARATOR);
129                         break;
130                    
131                 case TO_LAYOUTS:
132                         add(LAYOUTS);
133                         break;
134                    
135                 case TO_NEWLINE:
136                         add(NEWLINE);
137                         break;
138                         
139                 case TO_ENDTOOLBAR:
140                         // should not set automatically
141                         //set();
142                         quit = true;
143                         break;
144                 default:
145                         lex.printError("Toolbar::read: "
146                                        "Unknown toolbar tag: `$$Token'");
147                         break;
148                 }
149         }
150         lex.popTable();
151 }
152
153
154 void ToolbarDefaults::add(string const & func)
155 {
156         int const tf = lyxaction.LookupFunc(func);
157
158         if (tf == -1) {
159                 lyxerr << "Toolbar::add: no LyX command called `"
160                        << func << "' exists!" << endl; 
161         } else {
162                 add(tf);
163         }
164 }