]> git.lyx.org Git - lyx.git/blob - src/MenuBackend.C
the spellcheck cleanup
[lyx.git] / src / MenuBackend.C
1 /**
2  * \file MenuBackend.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Asger Alstrup
7  * \author Lars Gullik Bjønnes
8  * \author Jean-Marc Lasgouttes
9  * \author André Pönitz
10  * \author Dekel Tsur
11  * \author Martin Vermeer
12  *
13  * Full author contact details are available in file CREDITS.
14  */
15
16 #include <config.h>
17
18 #include "MenuBackend.h"
19
20 #include "BranchList.h"
21 #include "buffer.h"
22 #include "bufferlist.h"
23 #include "bufferparams.h"
24 #include "CutAndPaste.h"
25 #include "debug.h"
26 #include "exporter.h"
27 #include "Floating.h"
28 #include "FloatList.h"
29 #include "format.h"
30 #include "gettext.h"
31 #include "importer.h"
32 #include "kbmap.h"
33 #include "lastfiles.h"
34 #include "LyXAction.h"
35 #include "lyx_main.h" // for lastfiles
36 #include "lyxfunc.h"
37 #include "lyxlex.h"
38 #include "toc.h"
39
40 #include "frontends/LyXView.h"
41
42 #include "support/filetools.h"
43 #include "support/lyxfunctional.h"
44 #include "support/lstrings.h"
45 #include "support/tostr.h"
46
47 #include <algorithm>
48
49 using lyx::support::compare_ascii_no_case;
50 using lyx::support::contains;
51 using lyx::support::MakeDisplayPath;
52 using lyx::support::token;
53
54 using std::auto_ptr;
55 using std::endl;
56 using std::find_if;
57 using std::max;
58 using std::sort;
59 using std::string;
60 using std::vector;
61
62
63 extern BufferList bufferlist;
64 extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
65
66 // This is the global menu definition
67 MenuBackend menubackend;
68
69
70 MenuItem::MenuItem(Kind kind)
71         : kind_(kind), optional_(false)
72 {}
73
74
75 MenuItem::MenuItem(Kind kind, string const & label,
76                    string const & submenu, bool optional)
77         : kind_(kind), label_(label),
78           submenuname_(submenu), optional_(optional)
79 {
80         BOOST_ASSERT(kind == Submenu);
81 }
82
83
84 MenuItem::MenuItem(Kind kind, string const & label,
85                    FuncRequest const & func, bool optional)
86         : kind_(kind), label_(label), func_(func), optional_(optional)
87 {}
88
89
90 MenuItem::~MenuItem()
91 {}
92
93
94 void MenuItem::submenu(Menu * menu)
95 {
96         submenu_.reset(menu);
97 }
98
99
100 string const MenuItem::label() const
101 {
102         return token(label_, '|', 0);
103 }
104
105
106 string const MenuItem::shortcut() const
107 {
108         return token(label_, '|', 1);
109 }
110
111
112 string const MenuItem::binding() const
113 {
114         if (kind_ != Command)
115                 return string();
116
117         // Get the keys bound to this action, but keep only the
118         // first one later
119         string bindings = toplevel_keymap->findbinding(func_);
120
121         if (!bindings.empty()) {
122                 return bindings.substr(1, bindings.find(']') - 1);
123         } else {
124                 lyxerr[Debug::KBMAP]
125                         << "No bindings for "
126                         << lyxaction.getActionName(func_.action)
127                         << '(' << func_.argument << ')' << endl;
128                 return string();
129         }
130
131 }
132
133
134 Menu & Menu::add(MenuItem const & i, LyXView const * view)
135 {
136         if (!view) {
137                 items_.push_back(i);
138                 return *this;
139         }
140
141         switch (i.kind()) {
142         case MenuItem::Command:
143         {
144                 FuncStatus status =
145                         view->getLyXFunc().getStatus(i.func());
146                 if (status.unknown()
147                     || (status.disabled() && i.optional()))
148                         break;
149                 items_.push_back(i);
150                 items_.back().status(status);
151                 break;
152         }
153         case MenuItem::Submenu:
154         {
155                 if (i.submenu()) {
156                         bool disabled = true;
157                         for (const_iterator cit = i.submenu()->begin();
158                              cit != i.submenu()->end(); ++cit) {
159                                 if ((cit->kind() == MenuItem::Command
160                                      || cit->kind() == MenuItem::Submenu)
161                                     && !cit->status().disabled()) {
162                                         disabled = false;
163                                         break;
164                                 }
165                         }
166                         if (!disabled || !i.optional()) {
167                                 items_.push_back(i);
168                                 items_.back().status().disabled(disabled);
169                         }
170                 }
171                 else
172                         items_.push_back(i);
173                 break;
174         }
175         case MenuItem::Separator:
176                 if (!items_.empty()
177                     && items_.back().kind() != MenuItem::Separator)
178                         items_.push_back(i);
179                 break;
180         default:
181                 items_.push_back(i);
182         }
183
184         return *this;
185 }
186
187
188 Menu & Menu::read(LyXLex & lex)
189 {
190         enum Menutags {
191                 md_item = 1,
192                 md_branches,
193                 md_documents,
194                 md_endmenu,
195                 md_exportformats,
196                 md_importformats,
197                 md_lastfiles,
198                 md_optitem,
199                 md_optsubmenu,
200                 md_separator,
201                 md_submenu,
202                 md_toc,
203                 md_updateformats,
204                 md_viewformats,
205                 md_floatlistinsert,
206                 md_floatinsert,
207                 md_pasterecent,
208                 md_last
209         };
210
211         struct keyword_item menutags[md_last - 1] = {
212                 { "branches", md_branches },
213                 { "documents", md_documents },
214                 { "end", md_endmenu },
215                 { "exportformats", md_exportformats },
216                 { "floatinsert", md_floatinsert },
217                 { "floatlistinsert", md_floatlistinsert },
218                 { "importformats", md_importformats },
219                 { "item", md_item },
220                 { "lastfiles", md_lastfiles },
221                 { "optitem", md_optitem },
222                 { "optsubmenu", md_optsubmenu },
223                 { "pasterecent", md_pasterecent },
224                 { "separator", md_separator },
225                 { "submenu", md_submenu },
226                 { "toc", md_toc },
227                 { "updateformats", md_updateformats },
228                 { "viewformats", md_viewformats }
229         };
230
231         lex.pushTable(menutags, md_last - 1);
232         if (lyxerr.debugging(Debug::PARSER))
233                 lex.printTable(lyxerr);
234
235         bool quit = false;
236         bool optional = false;
237
238         while (lex.isOK() && !quit) {
239                 switch (lex.lex()) {
240                 case md_optitem:
241                         optional = true;
242                         // fallback to md_item
243                 case md_item: {
244                         lex.next(true);
245                         string const name = _(lex.getString());
246                         lex.next(true);
247                         string const command = lex.getString();
248                         FuncRequest func = lyxaction.lookupFunc(command);
249                         add(MenuItem(MenuItem::Command, name, func, optional));
250                         optional = false;
251                         break;
252                 }
253
254                 case md_separator:
255                         add(MenuItem(MenuItem::Separator));
256                         break;
257
258                 case md_lastfiles:
259                         add(MenuItem(MenuItem::Lastfiles));
260                         break;
261
262                 case md_documents:
263                         add(MenuItem(MenuItem::Documents));
264                         break;
265
266                 case md_toc:
267                         add(MenuItem(MenuItem::Toc));
268                         break;
269
270                 case md_viewformats:
271                         add(MenuItem(MenuItem::ViewFormats));
272                         break;
273
274                 case md_updateformats:
275                         add(MenuItem(MenuItem::UpdateFormats));
276                         break;
277
278                 case md_exportformats:
279                         add(MenuItem(MenuItem::ExportFormats));
280                         break;
281
282                 case md_importformats:
283                         add(MenuItem(MenuItem::ImportFormats));
284                         break;
285
286                 case md_floatlistinsert:
287                         add(MenuItem(MenuItem::FloatListInsert));
288                         break;
289
290                 case md_floatinsert:
291                         add(MenuItem(MenuItem::FloatInsert));
292                         break;
293
294                 case md_pasterecent:
295                         add(MenuItem(MenuItem::PasteRecent));
296                         break;
297
298                 case md_branches:
299                         add(MenuItem(MenuItem::Branches));
300                         break;
301
302                 case md_optsubmenu:
303                         optional = true;
304                         // fallback to md_submenu
305                 case md_submenu: {
306                         lex.next(true);
307                         string const mlabel = _(lex.getString());
308                         lex.next(true);
309                         string const mname = lex.getString();
310                         add(MenuItem(MenuItem::Submenu, mlabel, mname,
311                                      optional));
312                         optional = false;
313                         break;
314                 }
315
316                 case md_endmenu:
317                         quit = true;
318                         break;
319
320                 default:
321                         lex.printError("Menu::read: "
322                                        "Unknown menu tag: `$$Token'");
323                         break;
324                 }
325         }
326         lex.popTable();
327         return *this;
328 }
329
330
331 void Menu::checkShortcuts() const
332 {
333         // This is a quadratic algorithm, but we do not care because
334         // menus are short enough
335         for (const_iterator it1 = begin(); it1 != end(); ++it1) {
336                 string shortcut = it1->shortcut();
337                 if (shortcut.empty())
338                         continue;
339                 if (!contains(it1->label(), shortcut))
340                         lyxerr << "Menu warning: menu entry \""
341                                << it1->label()
342                                << "\" does not contain shortcut `"
343                                << shortcut << "'." << endl;
344                 for (const_iterator it2 = begin(); it2 != it1 ; ++it2) {
345                         if (!compare_ascii_no_case(it2->shortcut(), shortcut)) {
346                                 lyxerr << "Menu warning: menu entries "
347                                        << '"' << it1->fulllabel()
348                                        << "\" and \"" << it2->fulllabel()
349                                        << "\" share the same shortcut."
350                                        << endl;
351                         }
352                 }
353         }
354 }
355
356
357 namespace {
358
359 class compare_format {
360 public:
361         bool operator()(Format const * p1, Format const * p2) {
362                 return *p1 < *p2;
363         }
364 };
365
366 string const limit_string_length(string const & str)
367 {
368         string::size_type const max_item_length = 45;
369
370         if (str.size() > max_item_length)
371                 return str.substr(0, max_item_length - 3) + "...";
372         else
373                 return str;
374 }
375
376
377 void expandLastfiles(Menu & tomenu, LyXView const * view)
378 {
379         LastFiles const & lastfiles = LyX::cref().lastfiles();
380
381         int ii = 1;
382         LastFiles::const_iterator lfit = lastfiles.begin();
383         LastFiles::const_iterator end = lastfiles.end();
384
385         for (; lfit != end && ii < 10; ++lfit, ++ii) {
386                 string const label = tostr(ii) + ". "
387                         + MakeDisplayPath((*lfit), 30)
388                         + '|' + tostr(ii);
389                 tomenu.add(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_FILE_OPEN, (*lfit))), view);
390         }
391 }
392
393 void expandDocuments(Menu & tomenu, LyXView const * view)
394 {
395         typedef vector<string> Strings;
396         Strings const names = bufferlist.getFileNames();
397
398         if (names.empty()) {
399                 tomenu.add(MenuItem(MenuItem::Command, _("No Documents Open!"),
400                                     FuncRequest(LFUN_NOACTION)), view);
401                 return;
402         }
403
404         int ii = 1;
405         Strings::const_iterator docit = names.begin();
406         Strings::const_iterator end = names.end();
407         for (; docit != end; ++docit, ++ii) {
408                 string label = MakeDisplayPath(*docit, 20);
409                 if (ii < 10)
410                         label = tostr(ii) + ". " + label + '|' + tostr(ii);
411                 tomenu.add(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_SWITCHBUFFER, *docit)), view);
412         }
413 }
414
415
416 void expandFormats(MenuItem::Kind kind, Menu & tomenu, LyXView const * view)
417 {
418         if (!view->buffer() && kind != MenuItem::ImportFormats) {
419                 tomenu.add(MenuItem(MenuItem::Command,
420                                     _("No Documents Open!"),
421                                     FuncRequest(LFUN_NOACTION)),
422                                     view);
423                 return;
424         }
425
426         typedef vector<Format const *> Formats;
427         Formats formats;
428         kb_action action;
429
430         switch (kind) {
431         case MenuItem::ImportFormats:
432                 formats = Importer::GetImportableFormats();
433                 action = LFUN_IMPORT;
434                 break;
435         case MenuItem::ViewFormats:
436                 formats = Exporter::GetExportableFormats(*view->buffer(), true);
437                 action = LFUN_PREVIEW;
438                 break;
439         case MenuItem::UpdateFormats:
440                 formats = Exporter::GetExportableFormats(*view->buffer(), true);
441                 action = LFUN_UPDATE;
442                 break;
443         default:
444                 formats = Exporter::GetExportableFormats(*view->buffer(), false);
445                 action = LFUN_EXPORT;
446         }
447         sort(formats.begin(), formats.end(), compare_format());
448
449         Formats::const_iterator fit = formats.begin();
450         Formats::const_iterator end = formats.end();
451         for (; fit != end ; ++fit) {
452                 if ((*fit)->dummy())
453                         continue;
454                 string label = (*fit)->prettyname();
455                 // we need to hide the default graphic export formats
456                 // from the external menu, because we need them only
457                 // for the internal lyx-view and external latex run
458                 if (label == "EPS" || label == "XPM" || label == "PNG")
459                         continue;
460
461                 if (kind == MenuItem::ImportFormats) {
462                         if ((*fit)->name() == "text")
463                                 label = _("ASCII text as lines");
464                         else if ((*fit)->name() == "textparagraph")
465                                 label = _("ASCII text as paragraphs");
466                         label += "...";
467                 }
468                 if (!(*fit)->shortcut().empty())
469                         label += '|' + (*fit)->shortcut();
470
471                 tomenu.add(MenuItem(MenuItem::Command, label,
472                                     FuncRequest(action, (*fit)->name())),
473                            view);
474         }
475 }
476
477
478 void expandFloatListInsert(Menu & tomenu, LyXView const * view)
479 {
480         if (!view->buffer()) {
481                 tomenu.add(MenuItem(MenuItem::Command,
482                                     _("No Documents Open!"),
483                                     FuncRequest(LFUN_NOACTION)),
484                            view);
485                 return;
486         }
487
488         FloatList const & floats =
489                 view->buffer()->params().getLyXTextClass().floats();
490         FloatList::const_iterator cit = floats.begin();
491         FloatList::const_iterator end = floats.end();
492         for (; cit != end; ++cit) {
493                 tomenu.add(MenuItem(MenuItem::Command,
494                                     _(cit->second.listName()),
495                                     FuncRequest(LFUN_FLOAT_LIST,
496                                                 cit->second.type())),
497                            view);
498         }
499 }
500
501
502 void expandFloatInsert(Menu & tomenu, LyXView const * view)
503 {
504         if (!view->buffer()) {
505                 tomenu.add(MenuItem(MenuItem::Command,
506                                     _("No Documents Open!"),
507                                     FuncRequest(LFUN_NOACTION)),
508                            view);
509                 return;
510         }
511
512         FloatList const & floats =
513                 view->buffer()->params().getLyXTextClass().floats();
514         FloatList::const_iterator cit = floats.begin();
515         FloatList::const_iterator end = floats.end();
516         for (; cit != end; ++cit) {
517                 // normal float
518                 string const label = _(cit->second.name());
519                 tomenu.add(MenuItem(MenuItem::Command, label,
520                                     FuncRequest(LFUN_INSET_FLOAT,
521                                                 cit->second.type())),
522                            view);
523         }
524 }
525
526
527 Menu::size_type const max_number_of_items = 25;
528
529 void expandToc2(Menu & tomenu,
530                 lyx::toc::Toc const & toc_list,
531                 lyx::toc::Toc::size_type from,
532                 lyx::toc::Toc::size_type to, int depth)
533 {
534         int shortcut_count = 0;
535         if (to - from <= max_number_of_items) {
536                 for (lyx::toc::Toc::size_type i = from; i < to; ++i) {
537                         string label(4 * max(0, toc_list[i].depth - depth),' ');
538                         label += limit_string_length(toc_list[i].str);
539                         if (toc_list[i].depth == depth
540                             && shortcut_count < 9) {
541                                 if (label.find(tostr(shortcut_count + 1)) != string::npos)
542                                         label += '|' + tostr(++shortcut_count);
543                         }
544                         tomenu.add(MenuItem(MenuItem::Command, label,
545                                             FuncRequest(toc_list[i].action())));
546                 }
547         } else {
548                 lyx::toc::Toc::size_type pos = from;
549                 while (pos < to) {
550                         lyx::toc::Toc::size_type new_pos = pos + 1;
551                         while (new_pos < to &&
552                                toc_list[new_pos].depth > depth)
553                                 ++new_pos;
554
555                         string label(4 * max(0, toc_list[pos].depth - depth), ' ');
556                         label += limit_string_length(toc_list[pos].str);
557                         if (toc_list[pos].depth == depth &&
558                             shortcut_count < 9) {
559                                 if (label.find(tostr(shortcut_count + 1)) != string::npos)
560                                         label += '|' + tostr(++shortcut_count);
561                                 }
562                         if (new_pos == pos + 1) {
563                                 tomenu.add(MenuItem(MenuItem::Command,
564                                                     label, FuncRequest(toc_list[pos].action())));
565                         } else {
566                                 MenuItem item(MenuItem::Submenu, label);
567                                 item.submenu(new Menu);
568                                 expandToc2(*item.submenu(),
569                                            toc_list, pos, new_pos, depth + 1);
570                                 tomenu.add(item);
571                         }
572                         pos = new_pos;
573                 }
574         }
575 }
576
577
578 void expandToc(Menu & tomenu, LyXView const * view)
579 {
580         // To make things very cleanly, we would have to pass view to
581         // all MenuItem constructors and to expandToc2. However, we
582         // know that all the entries in a TOC will be have status_ ==
583         // OK, so we avoid this unnecessary overhead (JMarc)
584
585         if (!view->buffer()) {
586                 tomenu.add(MenuItem(MenuItem::Command,
587                                     _("No Documents Open!"),
588                                     FuncRequest(LFUN_NOACTION)),
589                            view);
590                 return;
591         }
592
593         lyx::toc::TocList toc_list = lyx::toc::getTocList(*view->buffer());
594         lyx::toc::TocList::const_iterator cit = toc_list.begin();
595         lyx::toc::TocList::const_iterator end = toc_list.end();
596         for (; cit != end; ++cit) {
597                 // Handle this later
598                 if (cit->first == "TOC")
599                         continue;
600
601                 // All the rest is for floats
602                 auto_ptr<Menu> menu(new Menu);
603                 lyx::toc::Toc::const_iterator ccit = cit->second.begin();
604                 lyx::toc::Toc::const_iterator eend = cit->second.end();
605                 for (; ccit != eend; ++ccit) {
606                         string const label = limit_string_length(ccit->str);
607                         menu->add(MenuItem(MenuItem::Command,
608                                            label,
609                                            FuncRequest(ccit->action())));
610                 }
611                 string const & floatName = cit->first;
612                 // Is the _(...) really needed here? (Lgb)
613                 MenuItem item(MenuItem::Submenu, _(floatName));
614                 item.submenu(menu.release());
615                 tomenu.add(item);
616         }
617
618         // Handle normal TOC
619         cit = toc_list.find("TOC");
620         if (cit == end) {
621                 tomenu.add(MenuItem(MenuItem::Command,
622                                     _("No Table of contents"),
623                                     FuncRequest()),
624                            view);
625         } else {
626                 expandToc2(tomenu, cit->second, 0, cit->second.size(), 0);
627         }
628 }
629
630
631 void expandPasteRecent(Menu & tomenu, LyXView const * view)
632 {
633         if (!view || !view->buffer())
634                 return;
635
636         vector<string> const selL =
637                 CutAndPaste::availableSelections(*view->buffer());
638
639         vector<string>::const_iterator cit = selL.begin();
640         vector<string>::const_iterator end = selL.end();
641
642         for (unsigned int index = 0; cit != end; ++cit, ++index) {
643                 tomenu.add(MenuItem(MenuItem::Command, *cit,
644                                     FuncRequest(LFUN_PASTE, tostr(index))));
645         }
646 }
647
648
649 void expandBranches(Menu & tomenu, LyXView const * view)
650 {
651         if (!view || !view->buffer())
652                 return;
653
654         BufferParams const & params = view->buffer()->params();
655
656         std::list<Branch>::const_iterator cit = params.branchlist().begin();
657         std::list<Branch>::const_iterator end = params.branchlist().end();
658
659         for (int ii = 1; cit != end; ++cit, ++ii) {
660                 string label = cit->getBranch();
661                 if (ii < 10)
662                         label = tostr(ii) + ". " + label + "|" + tostr(ii);
663                 tomenu.add(MenuItem(MenuItem::Command, label,
664                                     FuncRequest(LFUN_INSERT_BRANCH,
665                                                 cit->getBranch())), view);
666         }
667 }
668
669
670 } // namespace anon
671
672
673 void MenuBackend::expand(Menu const & frommenu, Menu & tomenu,
674                          LyXView const * view) const
675 {
676         for (Menu::const_iterator cit = frommenu.begin();
677              cit != frommenu.end() ; ++cit) {
678                 switch (cit->kind()) {
679                 case MenuItem::Lastfiles:
680                         expandLastfiles(tomenu, view);
681                         break;
682
683                 case MenuItem::Documents:
684                         expandDocuments(tomenu, view);
685                         break;
686
687                 case MenuItem::ImportFormats:
688                 case MenuItem::ViewFormats:
689                 case MenuItem::UpdateFormats:
690                 case MenuItem::ExportFormats:
691                         expandFormats(cit->kind(), tomenu, view);
692                         break;
693
694                 case MenuItem::FloatListInsert:
695                         expandFloatListInsert(tomenu, view);
696                         break;
697
698                 case MenuItem::FloatInsert:
699                         expandFloatInsert(tomenu, view);
700                         break;
701
702                 case MenuItem::PasteRecent:
703                         expandPasteRecent(tomenu, view);
704                         break;
705
706                 case MenuItem::Branches:
707                         expandBranches(tomenu, view);
708                         break;
709
710                 case MenuItem::Toc:
711                         expandToc(tomenu, view);
712                         break;
713
714                 case MenuItem::Submenu: {
715                         MenuItem item(*cit);
716                         item.submenu(new Menu(cit->submenuname()));
717                         expand(getMenu(cit->submenuname()),
718                                *item.submenu(), view);
719                         tomenu.add(item, view);
720                 }
721                 break;
722
723                 default:
724                         tomenu.add(*cit, view);
725                 }
726         }
727
728         // we do not want the menu to end with a separator
729         if (!tomenu.empty()
730             && tomenu.items_.back().kind() == MenuItem::Separator)
731                 tomenu.items_.pop_back();
732
733         // Check whether the shortcuts are unique
734         tomenu.checkShortcuts();
735 }
736
737
738 bool Menu::hasSubmenu(string const & name) const
739 {
740         return find_if(begin(), end(),
741                        lyx::compare_memfun(&MenuItem::submenuname,
742                                            name)) != end();
743 }
744
745
746 void MenuBackend::read(LyXLex & lex)
747 {
748         enum Menutags {
749                 md_menu = 1,
750                 md_menubar,
751                 md_endmenuset,
752                 md_last
753         };
754
755         struct keyword_item menutags[md_last - 1] = {
756                 { "end", md_endmenuset },
757                 { "menu", md_menu },
758                 { "menubar", md_menubar }
759         };
760
761         //consistency check
762         if (compare_ascii_no_case(lex.getString(), "menuset")) {
763                 lyxerr << "Menubackend::read: ERROR wrong token:`"
764                        << lex.getString() << '\'' << endl;
765         }
766
767         lex.pushTable(menutags, md_last - 1);
768         if (lyxerr.debugging(Debug::PARSER))
769                 lex.printTable(lyxerr);
770
771         bool quit = false;
772
773         while (lex.isOK() && !quit) {
774                 switch (lex.lex()) {
775                 case md_menubar:
776                         menubar_.read(lex);
777                         break;
778                 case md_menu: {
779                         lex.next(true);
780                         string const name = lex.getString();
781                         if (hasMenu(name)) {
782                                 getMenu(name).read(lex);
783                         } else {
784                                 Menu menu(name);
785                                 menu.read(lex);
786                                 add(menu);
787                         }
788                         break;
789                 }
790                 case md_endmenuset:
791                         quit = true;
792                         break;
793                 default:
794                         lex.printError("menubackend::read: "
795                                        "Unknown menu tag: `$$Token'");
796                         break;
797                 }
798         }
799         lex.popTable();
800 }
801
802
803 void MenuBackend::add(Menu const & menu)
804 {
805         menulist_.push_back(menu);
806 }
807
808
809 bool MenuBackend::hasMenu(string const & name) const
810 {
811         return find_if(begin(), end(),
812                        lyx::compare_memfun(&Menu::name, name)) != end();
813 }
814
815
816 Menu const & MenuBackend::getMenu(string const & name) const
817 {
818         const_iterator cit = find_if(begin(), end(),
819                                      lyx::compare_memfun(&Menu::name, name));
820         if (cit == end())
821                 lyxerr << "No submenu named " << name << endl;
822         BOOST_ASSERT(cit != end());
823         return (*cit);
824 }
825
826
827 Menu & MenuBackend::getMenu(string const & name)
828 {
829         MenuList::iterator it =
830                 find_if(menulist_.begin(), menulist_.end(),
831                         lyx::compare_memfun(&Menu::name, name));
832         BOOST_ASSERT(it != menulist_.end());
833         return (*it);
834 }
835
836
837 Menu const & MenuBackend::getMenubar() const
838 {
839         return menubar_;
840 }