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"
24 extern LyXAction lyxaction;
28 // This is the global menu definition
29 MenuBackend menubackend;
32 MenuItem::MenuItem(Kind kind, string const & label,
33 string const & command, bool optional)
34 : kind_(kind), label_(label), optional_(optional)
42 action_ = lyxaction.LookupFunc(command);
44 if (action_ == LFUN_UNKNOWN_ACTION) {
45 lyxerr << "MenuItem(): LyX command `"
46 << command << "' does not exist." << endl;
49 lyxerr[Debug::GUI] << "Optional item "
59 Menu & Menu::add(MenuItem const & i)
66 void Menu::read(LyXLex & lex)
79 struct keyword_item menutags[md_last-1] = {
80 { "documents", md_documents },
81 { "end", md_endmenu },
83 { "lastfiles", md_lastfiles },
84 { "optitem", md_optitem },
85 { "separator", md_separator },
86 { "submenu", md_submenu }
89 lex.pushTable(menutags, md_last - 1);
90 if (lyxerr.debugging(Debug::PARSER))
91 lex.printTable(lyxerr);
94 bool optional = false;
96 while (lex.IsOK() && !quit) {
100 // fallback to md_item
103 string name = _(lex.GetString().c_str());
105 string command = lex.GetString();
106 add(MenuItem(MenuItem::Command, name,
112 add(MenuItem(MenuItem::Separator));
115 add(MenuItem(MenuItem::Lastfiles));
118 add(MenuItem(MenuItem::Documents));
122 string mlabel = _(lex.GetString().c_str());
124 string mname = lex.GetString();
125 add(MenuItem(MenuItem::Submenu, mlabel, mname));
132 lex.printError("menubar::read: "
133 "Unknown menu tag: `$$Token'");
141 void MenuBackend::read(LyXLex & lex)
150 struct keyword_item menutags[md_last - 1] = {
151 { "end", md_endmenuset },
153 { "menubar", md_menubar }
157 if (compare_no_case(lex.GetString(), "menuset"))
158 lyxerr << "Menubackend::read: ERROR wrong token:`"
159 << lex.GetString() << '\'' << endl;
161 lex.pushTable(menutags, md_last - 1);
162 if (lyxerr.debugging(Debug::PARSER))
163 lex.printTable(lyxerr);
167 while (lex.IsOK() && !quit) {
171 string name = lex.GetString();
172 Menu menu(name, false);
179 string name = lex.GetString();
180 Menu menubar(name, true);
189 lex.printError("menubackend::read: "
190 "Unknown menu tag: `$$Token'");
198 void MenuBackend::defaults()
202 lyxerr[Debug::GUI] << "MenuBackend::defaults: using default values"
207 .add(MenuItem(MenuItem::Command, N_("New...|N"), "buffer-new"))
208 .add(MenuItem(MenuItem::Command, N_("Open...|O"), "buffer-open"))
209 .add(MenuItem(MenuItem::Submenu, N_("Import|I"), "import"))
210 .add(MenuItem(MenuItem::Command, N_("Quit|Q"), "lyx-quit"))
211 .add(MenuItem(MenuItem::Separator))
212 .add(MenuItem(MenuItem::Lastfiles));
215 Menu import("import");
217 .add(MenuItem(MenuItem::Command,
218 N_("LaTeX...|L"), "buffer-import latex"))
219 .add(MenuItem(MenuItem::Command,
220 N_("LinuxDoc...|L"), "buffer-import linuxdoc"));
225 .add(MenuItem(MenuItem::Command, N_("Cut"), "cut"))
226 .add(MenuItem(MenuItem::Command, N_("Copy"), "copy"))
227 .add(MenuItem(MenuItem::Command, N_("Paste"), "paste"))
228 .add(MenuItem(MenuItem::Command, N_("Emphasize"), "font-emph"));
231 Menu documents("documents");
232 documents.add(MenuItem(MenuItem::Documents));
235 Menu main("main", true);
237 .add(MenuItem(MenuItem::Submenu, N_("File|F"), "file"))
238 .add(MenuItem(MenuItem::Submenu, N_("Edit|E"), "edit"))
239 .add(MenuItem(MenuItem::Submenu,
240 N_("Documents|D"), "documents"));
243 Menu main_nobuffer("main_nobuffer", true);
244 main_nobuffer.add(MenuItem(MenuItem::Submenu, N_("File|F"), "file"));
247 if (lyxerr.debugging(Debug::GUI)) {
248 for(const_iterator cit = begin();
249 cit != end() ; ++cit)
250 lyxerr << "Menu name: " << cit->name()
251 << ", Menubar: " << cit->menubar()
257 void MenuBackend::add(Menu const & menu)
259 menulist_.push_back(menu);
263 bool MenuBackend::hasMenu(string const & name) const
265 for (const_iterator cit = begin(); cit != end(); ++cit) {
266 if ((*cit).name() == name)
273 Menu const & MenuBackend::getMenu(string const & name) const
275 for (const_iterator cit = begin(); cit != end(); ++cit) {
276 if ((*cit).name() == name)
279 Assert(false); // we actually require the name to exist.
280 return menulist_.front();