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