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