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