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