]> git.lyx.org Git - lyx.git/blob - src/ToolbarDefaults.C
9e8cc03a780656abc5f622fa2d3e18f765a0a28e
[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
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         add(LFUN_TEX);
68         add(LFUN_MATH_MODE);
69         add(SEPARATOR);
70
71         add(LFUN_FIGURE);
72         add(LFUN_DIALOG_TABULAR_INSERT);
73 #if 0
74         //add(LFUN_MELT);
75 #endif
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
117                 switch (lex.lex()) {
118                 case TO_ADD:
119                         if (lex.next()) {
120                                 func = lex.GetString();
121                                 lyxerr[Debug::GUI]
122                                         << "Toolbar::read TO_ADD func: `"
123                                         << func << "'" << endl;
124                                 add(func);
125                         }
126                         break;
127                    
128                 case TO_SEPARATOR:
129                         add(SEPARATOR);
130                         break;
131                    
132                 case TO_LAYOUTS:
133                         add(LAYOUTS);
134                         break;
135                    
136                 case TO_NEWLINE:
137                         add(NEWLINE);
138                         break;
139                         
140                 case TO_ENDTOOLBAR:
141                         // should not set automatically
142                         //set();
143                         quit = true;
144                         break;
145                 default:
146                         lex.printError("Toolbar::read: "
147                                        "Unknown toolbar tag: `$$Token'");
148                         break;
149                 }
150         }
151         lex.popTable();
152         lex.next();
153 }
154
155
156 void ToolbarDefaults::add(string const & func)
157 {
158         int const tf = lyxaction.LookupFunc(func);
159
160         if (tf == -1) {
161                 lyxerr << "Toolbar::add: no LyX command called`"
162                        << func << "'exists!" << endl; 
163         } else {
164                 add(tf);
165         }
166 }