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