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