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