]> git.lyx.org Git - lyx.git/blob - src/ToolbarDefaults.C
encoding + etc patch from dekel
[lyx.git] / src / ToolbarDefaults.C
1 #include <config.h>
2
3 #include "ToolbarDefaults.h"
4 #include "LyXAction.h"
5 #include "toolbar.h"
6 #include "debug.h"
7
8 using std::endl;
9
10 extern LyXAction lyxaction;
11
12
13 ToolbarDefaults::ToolbarDefaults()
14 {
15         init();
16 }
17
18
19 void ToolbarDefaults::add(int action)
20 {
21         defaults.push_back(action);
22 }
23
24
25 void ToolbarDefaults::init() 
26 {
27         add(Toolbar::TOOL_LAYOUTS);
28         add(LFUN_MENUOPEN);
29         //add(LFUN_CLOSEBUFFER);
30         add(LFUN_MENUWRITE);
31         add(LFUN_MENUPRINT);
32         add(Toolbar::TOOL_SEPARATOR);
33
34         add(LFUN_CUT);
35         add(LFUN_COPY);
36         add(LFUN_PASTE);
37         add(Toolbar::TOOL_SEPARATOR);
38         
39         add(LFUN_EMPH);
40         add(LFUN_NOUN);
41         add(LFUN_FREE);
42         add(Toolbar::TOOL_SEPARATOR);
43         
44         add(LFUN_FOOTMELT);
45         add(LFUN_MARGINMELT);
46         add(LFUN_DEPTH);
47         add(Toolbar::TOOL_SEPARATOR);
48
49         add(LFUN_TEX);
50         add(LFUN_MATH_MODE);
51         add(Toolbar::TOOL_SEPARATOR);
52
53         add(LFUN_FIGURE);
54         add(LFUN_TABLE);
55         //add(LFUN_MELT);
56 }
57
58
59 enum _tooltags {
60         TO_ADD = 1,
61         TO_ENDTOOLBAR,
62         TO_SEPARATOR,
63         TO_LAYOUTS,
64         TO_NEWLINE,
65         TO_LAST
66 };
67
68
69 struct keyword_item toolTags[TO_LAST - 1] = {
70         { "\\add", TO_ADD },
71         { "\\end_toolbar", TO_ENDTOOLBAR },
72         { "\\layouts", TO_LAYOUTS },
73         { "\\newline", TO_NEWLINE },
74         { "\\separator", TO_SEPARATOR }
75 };
76
77
78 void ToolbarDefaults::read(LyXLex & lex) 
79 {
80                 //consistency check
81         if (lex.GetString() != "\\begin_toolbar")
82                 lyxerr << "Toolbar::read: ERROR wrong token:`"
83                        << lex.GetString() << '\'' << endl;
84
85         defaults.clear();
86         
87         string func;
88         bool quit = false;
89         
90         lex.pushTable(toolTags, TO_LAST - 1);
91
92         if (lyxerr.debugging(Debug::PARSER))
93                 lex.printTable(lyxerr);
94         
95         while (lex.IsOK() && !quit) {
96                 
97                 lyxerr[Debug::TOOLBAR] << "Toolbar::read: current lex text: `"
98                                        << lex.GetString() << '\'' << endl;
99
100                 switch(lex.lex()) {
101                 case TO_ADD:
102                         if (lex.EatLine()) {
103                                 func = lex.GetString();
104                                 lyxerr[Debug::TOOLBAR]
105                                         << "Toolbar::read TO_ADD func: `"
106                                         << func << "'" << endl;
107                                 add(func);
108                         }
109                         break;
110                    
111                 case TO_SEPARATOR:
112                         add(Toolbar::TOOL_SEPARATOR);
113                         break;
114                    
115                 case TO_LAYOUTS:
116                         add(Toolbar::TOOL_LAYOUTS);
117                         break;
118                    
119                 case TO_NEWLINE:
120                         add(Toolbar::TOOL_NEWLINE);
121                         break;
122                         
123                 case TO_ENDTOOLBAR:
124                         // should not set automatically
125                         //set();
126                         quit = true;
127                         break;
128                 default:
129                         lex.printError("Toolbar::read: "
130                                        "Unknown toolbar tag: `$$Token'");
131                         break;
132                 }
133         }
134         lex.popTable();
135 }
136
137
138 void ToolbarDefaults::add(string const & func)
139 {
140         int tf = lyxaction.LookupFunc(func);
141
142         if (tf == -1) {
143                 lyxerr << "Toolbar::add: no LyX command called`"
144                        << func << "'exists!" << endl; 
145         } else {
146                 add(tf);
147         }
148 }