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)
46 action_ = lyxaction.LookupFunc(command);
48 if (action_ == LFUN_UNKNOWN_ACTION) {
49 lyxerr << "MenuItem(): LyX command `"
50 << command << "' does not exist." << endl;
53 lyxerr[Debug::GUI] << "Optional item "
63 Menu & Menu::add(MenuItem const & i)
70 Menu & Menu::read(LyXLex & lex)
86 struct keyword_item menutags[md_last-1] = {
87 { "documents", md_documents },
88 { "end", md_endmenu },
89 { "exportformats", md_exportformats },
91 { "lastfiles", md_lastfiles },
92 { "optitem", md_optitem },
93 { "separator", md_separator },
94 { "submenu", md_submenu },
95 { "updateformats", md_updateformats },
96 { "viewformats", md_viewformats }
99 lex.pushTable(menutags, md_last - 1);
100 if (lyxerr.debugging(Debug::PARSER))
101 lex.printTable(lyxerr);
104 bool optional = false;
106 while (lex.IsOK() && !quit) {
110 // fallback to md_item
113 char * tmp = strdup(lex.GetString().c_str());
114 string name = _(tmp);
117 string command = lex.GetString();
118 add(MenuItem(MenuItem::Command, name,
124 add(MenuItem(MenuItem::Separator));
127 add(MenuItem(MenuItem::Lastfiles));
130 add(MenuItem(MenuItem::Documents));
133 add(MenuItem(MenuItem::ViewFormats));
135 case md_updateformats:
136 add(MenuItem(MenuItem::UpdateFormats));
138 case md_exportformats:
139 add(MenuItem(MenuItem::ExportFormats));
143 char * tmp = strdup(lex.GetString().c_str());
144 string mlabel = _(tmp);
147 string mname = lex.GetString();
148 add(MenuItem(MenuItem::Submenu, mlabel, mname));
155 lex.printError("menubar::read: "
156 "Unknown menu tag: `$$Token'");
165 void MenuBackend::read(LyXLex & lex)
174 struct keyword_item menutags[md_last - 1] = {
175 { "end", md_endmenuset },
177 { "menubar", md_menubar }
181 if (compare_no_case(lex.GetString(), "menuset"))
182 lyxerr << "Menubackend::read: ERROR wrong token:`"
183 << lex.GetString() << '\'' << endl;
185 lex.pushTable(menutags, md_last - 1);
186 if (lyxerr.debugging(Debug::PARSER))
187 lex.printTable(lyxerr);
190 bool menubar = false;
192 while (lex.IsOK() && !quit) {
196 // fallback to md_menu
199 string name = lex.GetString();
201 if (getMenu(name).menubar() == menubar) {
202 getMenu(name).read(lex);
204 lex.printError("Cannot append to menu `$$Token' unless it is of the same type");
208 Menu menu(name, menubar);
219 lex.printError("menubackend::read: "
220 "Unknown menu tag: `$$Token'");
228 void MenuBackend::defaults()
232 lyxerr[Debug::GUI] << "MenuBackend::defaults: using default values"
237 .add(MenuItem(MenuItem::Command, _("New...|N"), "buffer-new"))
238 .add(MenuItem(MenuItem::Command, _("Open...|O"), "buffer-open"))
239 .add(MenuItem(MenuItem::Submenu, _("Import|I"), "import"))
240 .add(MenuItem(MenuItem::Command, _("Quit|Q"), "lyx-quit"))
241 .add(MenuItem(MenuItem::Separator))
242 .add(MenuItem(MenuItem::Lastfiles));
245 Menu import("import");
247 .add(MenuItem(MenuItem::Command,
248 _("LaTeX...|L"), "buffer-import latex"))
249 .add(MenuItem(MenuItem::Command,
250 _("LinuxDoc...|L"), "buffer-import linuxdoc"));
255 .add(MenuItem(MenuItem::Command, _("Cut"), "cut"))
256 .add(MenuItem(MenuItem::Command, _("Copy"), "copy"))
257 .add(MenuItem(MenuItem::Command, _("Paste"), "paste"))
258 .add(MenuItem(MenuItem::Command, _("Emphasize"), "font-emph"));
261 Menu documents("documents");
262 documents.add(MenuItem(MenuItem::Documents));
265 Menu main("main", true);
267 .add(MenuItem(MenuItem::Submenu, _("File|F"), "file"))
268 .add(MenuItem(MenuItem::Submenu, _("Edit|E"), "edit"))
269 .add(MenuItem(MenuItem::Submenu,
270 _("Documents|D"), "documents"));
273 Menu main_nobuffer("main_nobuffer", true);
274 main_nobuffer.add(MenuItem(MenuItem::Submenu, _("File|F"), "file"));
277 if (lyxerr.debugging(Debug::GUI)) {
278 for(const_iterator cit = begin();
279 cit != end() ; ++cit)
280 lyxerr << "Menu name: " << cit->name()
281 << ", Menubar: " << cit->menubar()
287 void MenuBackend::add(Menu const & menu)
289 menulist_.push_back(menu);
293 bool MenuBackend::hasMenu(string const & name) const
295 const_iterator mend = end();
296 for (const_iterator cit = begin(); cit != mend; ++cit) {
297 if ((*cit).name() == name)
304 Menu const & MenuBackend::getMenu(string const & name) const
306 const_iterator mend = end();
307 for (const_iterator cit = begin(); cit != mend; ++cit) {
308 if ((*cit).name() == name)
311 Assert(false); // we actually require the name to exist.
312 return menulist_.front();
316 Menu & MenuBackend::getMenu(string const & name)
318 MenuList::iterator end = menulist_.end();
319 for (MenuList::iterator cit = menulist_.begin();
321 if ((*cit).name() == name)
324 Assert(false); // we actually require the name to exist.
325 return menulist_.front();