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
18 #include "support/LAssert.h"
19 #include "MenuBackend.h"
21 #include "LyXAction.h"
25 extern LyXAction lyxaction;
29 // This is the global menu definition
30 MenuBackend menubackend;
33 MenuItem::MenuItem(Kind kind, string const & label,
34 string const & command, bool optional)
35 : kind_(kind), label_(label), optional_(optional)
48 action_ = lyxaction.LookupFunc(command);
50 if (action_ == LFUN_UNKNOWN_ACTION) {
51 lyxerr << "MenuItem(): LyX command `"
52 << command << "' does not exist." << endl;
55 lyxerr[Debug::GUI] << "Optional item "
65 Menu & Menu::add(MenuItem const & i)
72 Menu & Menu::read(LyXLex & lex)
90 struct keyword_item menutags[md_last-1] = {
91 { "documents", md_documents },
92 { "end", md_endmenu },
93 { "exportformats", md_exportformats },
95 { "lastfiles", md_lastfiles },
96 { "optitem", md_optitem },
97 { "references", md_references },
98 { "separator", md_separator },
99 { "submenu", md_submenu },
101 { "updateformats", md_updateformats },
102 { "viewformats", md_viewformats }
105 lex.pushTable(menutags, md_last - 1);
106 if (lyxerr.debugging(Debug::PARSER))
107 lex.printTable(lyxerr);
110 bool optional = false;
112 while (lex.IsOK() && !quit) {
116 // fallback to md_item
119 char * tmp = strdup(lex.GetString().c_str());
120 string name = _(tmp);
123 string command = lex.GetString();
124 add(MenuItem(MenuItem::Command, name,
131 add(MenuItem(MenuItem::Separator));
135 add(MenuItem(MenuItem::Lastfiles));
139 add(MenuItem(MenuItem::Documents));
143 add(MenuItem(MenuItem::Toc));
147 add(MenuItem(MenuItem::References));
151 add(MenuItem(MenuItem::ViewFormats));
154 case md_updateformats:
155 add(MenuItem(MenuItem::UpdateFormats));
158 case md_exportformats:
159 add(MenuItem(MenuItem::ExportFormats));
164 char * tmp = strdup(lex.GetString().c_str());
165 string mlabel = _(tmp);
168 string mname = lex.GetString();
169 add(MenuItem(MenuItem::Submenu, mlabel, mname));
178 lex.printError("menubar::read: "
179 "Unknown menu tag: `$$Token'");
188 void MenuBackend::read(LyXLex & lex)
197 struct keyword_item menutags[md_last - 1] = {
198 { "end", md_endmenuset },
200 { "menubar", md_menubar }
204 if (compare_no_case(lex.GetString(), "menuset"))
205 lyxerr << "Menubackend::read: ERROR wrong token:`"
206 << lex.GetString() << '\'' << endl;
208 lex.pushTable(menutags, md_last - 1);
209 if (lyxerr.debugging(Debug::PARSER))
210 lex.printTable(lyxerr);
213 bool menubar = false;
215 while (lex.IsOK() && !quit) {
219 // fallback to md_menu
222 string name = lex.GetString();
224 if (getMenu(name).menubar() == menubar) {
225 getMenu(name).read(lex);
227 lex.printError("Cannot append to menu `$$Token' unless it is of the same type");
231 Menu menu(name, menubar);
242 lex.printError("menubackend::read: "
243 "Unknown menu tag: `$$Token'");
251 void MenuBackend::defaults()
255 lyxerr[Debug::GUI] << "MenuBackend::defaults: using default values"
260 .add(MenuItem(MenuItem::Command, _("New...|N"), "buffer-new"))
261 .add(MenuItem(MenuItem::Command, _("Open...|O"), "buffer-open"))
262 .add(MenuItem(MenuItem::Submenu, _("Import|I"), "import"))
263 .add(MenuItem(MenuItem::Command, _("Quit|Q"), "lyx-quit"))
264 .add(MenuItem(MenuItem::Separator))
265 .add(MenuItem(MenuItem::Lastfiles));
268 Menu import("import");
270 .add(MenuItem(MenuItem::Command,
271 _("LaTeX...|L"), "buffer-import latex"))
272 .add(MenuItem(MenuItem::Command,
273 _("LinuxDoc...|L"), "buffer-import linuxdoc"));
278 .add(MenuItem(MenuItem::Command, _("Cut"), "cut"))
279 .add(MenuItem(MenuItem::Command, _("Copy"), "copy"))
280 .add(MenuItem(MenuItem::Command, _("Paste"), "paste"))
281 .add(MenuItem(MenuItem::Command, _("Emphasize"), "font-emph"));
284 Menu documents("documents");
285 documents.add(MenuItem(MenuItem::Documents));
288 Menu main("main", true);
290 .add(MenuItem(MenuItem::Submenu, _("File|F"), "file"))
291 .add(MenuItem(MenuItem::Submenu, _("Edit|E"), "edit"))
292 .add(MenuItem(MenuItem::Submenu,
293 _("Documents|D"), "documents"));
296 Menu main_nobuffer("main_nobuffer", true);
297 main_nobuffer.add(MenuItem(MenuItem::Submenu, _("File|F"), "file"));
300 if (lyxerr.debugging(Debug::GUI)) {
301 for(const_iterator cit = begin();
302 cit != end() ; ++cit)
303 lyxerr << "Menu name: " << cit->name()
304 << ", Menubar: " << cit->menubar()
310 void MenuBackend::add(Menu const & menu)
312 menulist_.push_back(menu);
316 bool MenuBackend::hasMenu(string const & name) const
318 const_iterator mend = end();
319 for (const_iterator cit = begin(); cit != mend; ++cit) {
320 if ((*cit).name() == name)
327 Menu const & MenuBackend::getMenu(string const & name) const
329 const_iterator mend = end();
330 for (const_iterator cit = begin(); cit != mend; ++cit) {
331 if ((*cit).name() == name)
334 Assert(false); // we actually require the name to exist.
335 return menulist_.front();
339 Menu & MenuBackend::getMenu(string const & name)
341 MenuList::iterator end = menulist_.end();
342 for (MenuList::iterator cit = menulist_.begin();
344 if ((*cit).name() == name)
347 Assert(false); // we actually require the name to exist.
348 return menulist_.front();