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