]> git.lyx.org Git - lyx.git/blob - src/ToolbarDefaults.C
f6267fab4fba63e6c3c43a500713fe361f8f272b
[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_FILE_OPEN);
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 #if 0
82         //add(LFUN_MELT);
83 #endif
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 const 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 }