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