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