]> git.lyx.org Git - lyx.git/blob - src/ToolbarDefaults.C
Minimal fix needed to give Qt a label dialog again.
[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-2001 The LyX Team.
8  *
9  *
10  * ====================================================== */
11
12 #include <config.h>
13
14 #include "ToolbarDefaults.h"
15 #include "LyXAction.h"
16 #include "lyxlex.h"
17 #include "debug.h"
18 #include "lyxlex.h"
19 #include "support/lstrings.h"
20
21 using std::endl;
22
23 ToolbarDefaults toolbardefaults;
24
25 namespace {
26
27 enum _tooltags {
28         TO_ADD = 1,
29         TO_ENDTOOLBAR,
30         TO_SEPARATOR,
31         TO_LAYOUTS,
32         TO_NEWLINE,
33         TO_LAST
34 };
35
36
37 struct keyword_item toolTags[TO_LAST - 1] = {
38         { "end", TO_ENDTOOLBAR },
39         { "icon", TO_ADD },
40         { "layouts", TO_LAYOUTS },
41         { "newline", TO_NEWLINE },
42         { "separator", TO_SEPARATOR }
43 };
44
45 } // end of anon namespace
46
47
48 ToolbarDefaults::ToolbarDefaults()
49 {
50         init();
51 }
52
53
54 void ToolbarDefaults::add(int action)
55 {
56         defaults.push_back(action);
57 }
58
59
60 void ToolbarDefaults::init()
61 {
62         add(LAYOUTS);
63         add(LFUN_FILE_OPEN);
64         //add(LFUN_CLOSEBUFFER);
65         add(LFUN_MENUWRITE);
66         add(LFUN_MENUPRINT);
67         add(SEPARATOR);
68
69         add(LFUN_CUT);
70         add(LFUN_COPY);
71         add(LFUN_PASTE);
72         add(SEPARATOR);
73
74         add(LFUN_EMPH);
75         add(LFUN_NOUN);
76         add(LFUN_FREE);
77         add(SEPARATOR);
78
79         add(LFUN_INSET_FOOTNOTE);
80         add(LFUN_INSET_MARGINAL);
81
82         add(LFUN_DEPTH_PLUS);
83         add(SEPARATOR);
84
85         add(LFUN_MATH_MODE);
86         add(SEPARATOR);
87
88         add(LFUN_INSET_GRAPHICS);
89         add(LFUN_TABULAR_INSERT);
90 }
91
92
93 void ToolbarDefaults::read(LyXLex & lex)
94 {
95         //consistency check
96         if (compare_ascii_no_case(lex.getString(), "toolbar")) {
97                 lyxerr << "Toolbar::read: ERROR wrong token:`"
98                        << lex.getString() << '\'' << endl;
99         }
100
101         defaults.clear();
102
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                 switch (lex.lex()) {
112                 case TO_ADD:
113                         if (lex.next(true)) {
114                                 string const func = lex.getString();
115                                 lyxerr[Debug::PARSER]
116                                         << "Toolbar::read TO_ADD func: `"
117                                         << func << '\'' << endl;
118                                 add(func);
119                         }
120                         break;
121
122                 case TO_SEPARATOR:
123                         add(SEPARATOR);
124                         break;
125
126                 case TO_LAYOUTS:
127                         add(LAYOUTS);
128                         break;
129
130                 case TO_NEWLINE:
131                         add(NEWLINE);
132                         break;
133
134                 case TO_ENDTOOLBAR:
135                         quit = true;
136                         break;
137                 default:
138                         lex.printError("Toolbar::read: "
139                                        "Unknown toolbar tag: `$$Token'");
140                         break;
141                 }
142         }
143         lex.popTable();
144 }
145
146
147 void ToolbarDefaults::add(string const & func)
148 {
149         int const tf = lyxaction.LookupFunc(func);
150
151         if (tf == -1) {
152                 lyxerr << "Toolbar::add: no LyX command called `"
153                        << func << "' exists!" << endl;
154         } else {
155                 add(tf);
156         }
157 }