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