]> git.lyx.org Git - lyx.git/blob - src/ToolbarDefaults.C
LyX Drinkers United: patch 2
[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
24 using std::endl;
25
26 extern LyXAction lyxaction;
27 ToolbarDefaults toolbardefaults;
28
29
30 ToolbarDefaults::ToolbarDefaults()
31 {
32         init();
33 }
34
35
36 void ToolbarDefaults::add(int action)
37 {
38         defaults.push_back(action);
39 }
40
41
42 void ToolbarDefaults::init() 
43 {
44         add(LAYOUTS);
45         add(LFUN_FILE_OPEN);
46         //add(LFUN_CLOSEBUFFER);
47         add(LFUN_MENUWRITE);
48         add(LFUN_MENUPRINT);
49         add(SEPARATOR);
50
51         add(LFUN_CUT);
52         add(LFUN_COPY);
53         add(LFUN_PASTE);
54         add(SEPARATOR);
55         
56         add(LFUN_EMPH);
57         add(LFUN_NOUN);
58         add(LFUN_FREE);
59         add(SEPARATOR);
60         
61         add(LFUN_INSET_FOOTNOTE);
62         add(LFUN_INSET_MARGINAL);
63
64         add(LFUN_DEPTH);
65         add(SEPARATOR);
66
67 #ifndef NO_LATEX
68         add(LFUN_TEX);
69 #endif
70         add(LFUN_MATH_MODE);
71         add(SEPARATOR);
72
73         add(LFUN_FIGURE);
74         add(LFUN_DIALOG_TABULAR_INSERT);
75 }
76
77
78 enum _tooltags {
79         TO_ADD = 1,
80         TO_ENDTOOLBAR,
81         TO_SEPARATOR,
82         TO_LAYOUTS,
83         TO_NEWLINE,
84         TO_LAST
85 };
86
87
88 struct keyword_item toolTags[TO_LAST - 1] = {
89         { "end", TO_ENDTOOLBAR },
90         { "icon", TO_ADD },
91         { "layouts", TO_LAYOUTS },
92         { "newline", TO_NEWLINE },
93         { "separator", TO_SEPARATOR }
94 };
95
96
97 void ToolbarDefaults::read(LyXLex & lex) 
98 {
99         //consistency check
100         if (compare_no_case(lex.GetString(), "toolbar"))
101                 lyxerr << "Toolbar::read: ERROR wrong token:`"
102                        << lex.GetString() << '\'' << endl;
103
104         defaults.clear();
105         
106         string func;
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()) {
118                                 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                         // should not set automatically
140                         //set();
141                         quit = true;
142                         break;
143                 default:
144                         lex.printError("Toolbar::read: "
145                                        "Unknown toolbar tag: `$$Token'");
146                         break;
147                 }
148         }
149         lex.popTable();
150 }
151
152
153 void ToolbarDefaults::add(string const & func)
154 {
155         int const tf = lyxaction.LookupFunc(func);
156
157         if (tf == -1) {
158                 lyxerr << "Toolbar::add: no LyX command called`"
159                        << func << "'exists!" << endl; 
160         } else {
161                 add(tf);
162         }
163 }