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