1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
10 * ====================================================== */
13 #pragma implementation
17 #include "support/LAssert.h"
18 #include "MenuBackend.h"
20 #include "LyXAction.h"
23 extern LyXAction lyxaction;
27 // This is the global menu definition
28 MenuBackend menubackend;
31 MenuItem::MenuItem(Kind kind, string const & label,
32 string const & command, bool optional)
33 : kind_(kind), label_(label), optional_(optional)
41 action_ = lyxaction.LookupFunc(command);
43 if (action_ == LFUN_UNKNOWN_ACTION) {
44 lyxerr << "MenuItem(): LyX command `"
45 << command << "' does not exist." << endl;
48 lyxerr[Debug::GUI] << "Optional item "
58 Menu & Menu::add(MenuItem const & i)
65 void Menu::read(LyXLex & lex)
78 struct keyword_item menutags[md_last-1] = {
79 { "documents", md_documents },
80 { "end", md_endmenu },
82 { "lastfiles", md_lastfiles },
83 { "optitem", md_optitem },
84 { "separator", md_separator },
85 { "submenu", md_submenu }
88 lex.pushTable(menutags, md_last - 1);
89 if (lyxerr.debugging(Debug::PARSER))
90 lex.printTable(lyxerr);
93 bool optional = false;
95 while (lex.IsOK() && !quit) {
99 // fallback to md_item
102 string name = lex.GetString();
104 string command = lex.GetString();
105 add(MenuItem(MenuItem::Command, name,
111 add(MenuItem(MenuItem::Separator));
114 add(MenuItem(MenuItem::Lastfiles));
117 add(MenuItem(MenuItem::Documents));
121 string mlabel = lex.GetString();
123 string mname = lex.GetString();
124 add(MenuItem(MenuItem::Submenu, mlabel, mname));
131 lex.printError("menubar::read: "
132 "Unknown menu tag: `$$Token'");
140 void MenuBackend::read(LyXLex & lex)
149 struct keyword_item menutags[md_last - 1] = {
150 { "end", md_endmenuset },
152 { "menubar", md_menubar }
156 if (compare_no_case(lex.GetString(), "menuset"))
157 lyxerr << "Menubackend::read: ERROR wrong token:`"
158 << lex.GetString() << '\'' << endl;
160 lex.pushTable(menutags, md_last - 1);
161 if (lyxerr.debugging(Debug::PARSER))
162 lex.printTable(lyxerr);
166 while (lex.IsOK() && !quit) {
170 string name = lex.GetString();
171 Menu menu(name, false);
178 string name = lex.GetString();
179 Menu menubar(name, true);
188 lex.printError("menubackend::read: "
189 "Unknown menu tag: `$$Token'");
197 void MenuBackend::defaults()
201 lyxerr[Debug::GUI] << "MenuBackend::defaults: using default values"
206 .add(MenuItem(MenuItem::Command, "New...|N", "buffer-new"))
207 .add(MenuItem(MenuItem::Command, "Open...|O", "buffer-open"))
208 .add(MenuItem(MenuItem::Submenu, "Import|I", "import"))
209 .add(MenuItem(MenuItem::Command, "Quit|Q", "lyx-quit"))
210 .add(MenuItem(MenuItem::Separator))
211 .add(MenuItem(MenuItem::Lastfiles));
214 Menu import("import");
216 .add(MenuItem(MenuItem::Command,
217 "LaTeX...|L", "buffer-import latex"))
218 .add(MenuItem(MenuItem::Command,
219 "LinuxDoc...|L", "buffer-import linuxdoc"));
224 .add(MenuItem(MenuItem::Command, "Cut", "cut"))
225 .add(MenuItem(MenuItem::Command, "Copy", "copy"))
226 .add(MenuItem(MenuItem::Command, "Paste", "paste"))
227 .add(MenuItem(MenuItem::Command, "Emphasize", "font-emph"));
230 Menu documents("documents");
231 documents.add(MenuItem(MenuItem::Documents));
234 Menu main("main", true);
236 .add(MenuItem(MenuItem::Submenu, "File|F", "file"))
237 .add(MenuItem(MenuItem::Submenu, "Edit|E", "edit"))
238 .add(MenuItem(MenuItem::Submenu,
239 "Documents|D", "documents"));
242 Menu main_nobuffer("main_nobuffer", true);
243 main_nobuffer.add(MenuItem(MenuItem::Submenu, "File|F", "file"));
246 if (lyxerr.debugging(Debug::GUI)) {
247 for(const_iterator cit = begin();
248 cit != end() ; ++cit)
249 lyxerr << "Menu name: " << cit->name()
250 << ", Menubar: " << cit->menubar()
256 void MenuBackend::add(Menu const & menu)
258 menulist_.push_back(menu);
262 bool MenuBackend::hasMenu(string const & name) const
264 for (const_iterator cit = begin(); cit != end(); ++cit) {
265 if ((*cit).name() == name)
272 Menu const & MenuBackend::getMenu(string const & name) const
274 for (const_iterator cit = begin(); cit != end(); ++cit) {
275 if ((*cit).name() == name)
278 Assert(false); // we actually require the name to exist.
279 return menulist_.front();