]> git.lyx.org Git - lyx.git/blob - src/MenuBackend.C
Turn LyX into a singleton class. Kill the BufferView cache.
[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         LastFiles const & lastfiles = LyX::cref().lastfiles();
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                 tomenu.add(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_FILE_OPEN, (*lfit))), view);
389         }
390 }
391
392 void expandDocuments(Menu & tomenu, LyXView const * view)
393 {
394         typedef vector<string> Strings;
395         Strings const names = bufferlist.getFileNames();
396
397         if (names.empty()) {
398                 tomenu.add(MenuItem(MenuItem::Command, _("No Documents Open!"),
399                                     FuncRequest(LFUN_NOACTION)), view);
400                 return;
401         }
402
403         int ii = 1;
404         Strings::const_iterator docit = names.begin();
405         Strings::const_iterator end = names.end();
406         for (; docit != end; ++docit, ++ii) {
407                 string label = MakeDisplayPath(*docit, 20);
408                 if (ii < 10)
409                         label = tostr(ii) + ". " + label + '|' + tostr(ii);
410                 tomenu.add(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_SWITCHBUFFER, *docit)), view);
411         }
412 }
413
414
415 void expandFormats(MenuItem::Kind kind, Menu & tomenu, LyXView const * view)
416 {
417         if (!view->buffer() && kind != MenuItem::ImportFormats) {
418                 tomenu.add(MenuItem(MenuItem::Command,
419                                     _("No Documents Open!"),
420                                     FuncRequest(LFUN_NOACTION)),
421                                     view);
422                 return;
423         }
424
425         typedef vector<Format const *> Formats;
426         Formats formats;
427         kb_action action;
428
429         switch (kind) {
430         case MenuItem::ImportFormats:
431                 formats = Importer::GetImportableFormats();
432                 action = LFUN_IMPORT;
433                 break;
434         case MenuItem::ViewFormats:
435                 formats = Exporter::GetExportableFormats(*view->buffer(), true);
436                 action = LFUN_PREVIEW;
437                 break;
438         case MenuItem::UpdateFormats:
439                 formats = Exporter::GetExportableFormats(*view->buffer(), true);
440                 action = LFUN_UPDATE;
441                 break;
442         default:
443                 formats = Exporter::GetExportableFormats(*view->buffer(), false);
444                 action = LFUN_EXPORT;
445         }
446         sort(formats.begin(), formats.end(), compare_format());
447
448         Formats::const_iterator fit = formats.begin();
449         Formats::const_iterator end = formats.end();
450         for (; fit != end ; ++fit) {
451                 if ((*fit)->dummy())
452                         continue;
453                 string label = (*fit)->prettyname();
454                 // we need to hide the default graphic export formats
455                 // from the external menu, because we need them only
456                 // for the internal lyx-view and external latex run
457                 if (label == "EPS" || label == "XPM" || label == "PNG")
458                         continue;
459
460                 if (kind == MenuItem::ImportFormats) {
461                         if ((*fit)->name() == "text")
462                                 label = _("ASCII text as lines");
463                         else if ((*fit)->name() == "textparagraph")
464                                 label = _("ASCII text as paragraphs");
465                         label += "...";
466                 }
467                 if (!(*fit)->shortcut().empty())
468                         label += '|' + (*fit)->shortcut();
469
470                 tomenu.add(MenuItem(MenuItem::Command, label,
471                                     FuncRequest(action, (*fit)->name())),
472                            view);
473         }
474 }
475
476
477 void expandFloatListInsert(Menu & tomenu, LyXView const * view)
478 {
479         if (!view->buffer()) {
480                 tomenu.add(MenuItem(MenuItem::Command,
481                                     _("No Documents Open!"),
482                                     FuncRequest(LFUN_NOACTION)),
483                            view);
484                 return;
485         }
486
487         FloatList const & floats =
488                 view->buffer()->params().getLyXTextClass().floats();
489         FloatList::const_iterator cit = floats.begin();
490         FloatList::const_iterator end = floats.end();
491         for (; cit != end; ++cit) {
492                 tomenu.add(MenuItem(MenuItem::Command,
493                                     _(cit->second.listName()),
494                                     FuncRequest(LFUN_FLOAT_LIST,
495                                                 cit->second.type())),
496                            view);
497         }
498 }
499
500
501 void expandFloatInsert(Menu & tomenu, LyXView const * view)
502 {
503         if (!view->buffer()) {
504                 tomenu.add(MenuItem(MenuItem::Command,
505                                     _("No Documents Open!"),
506                                     FuncRequest(LFUN_NOACTION)),
507                            view);
508                 return;
509         }
510
511         FloatList const & floats =
512                 view->buffer()->params().getLyXTextClass().floats();
513         FloatList::const_iterator cit = floats.begin();
514         FloatList::const_iterator end = floats.end();
515         for (; cit != end; ++cit) {
516                 // normal float
517                 string const label = _(cit->second.name());
518                 tomenu.add(MenuItem(MenuItem::Command, label,
519                                     FuncRequest(LFUN_INSET_FLOAT,
520                                                 cit->second.type())),
521                            view);
522         }
523 }
524
525
526 Menu::size_type const max_number_of_items = 25;
527
528 void expandToc2(Menu & tomenu,
529                 lyx::toc::Toc const & toc_list,
530                 lyx::toc::Toc::size_type from,
531                 lyx::toc::Toc::size_type to, int depth)
532 {
533         int shortcut_count = 0;
534         if (to - from <= max_number_of_items) {
535                 for (lyx::toc::Toc::size_type i = from; i < to; ++i) {
536                         string label(4 * max(0, toc_list[i].depth - depth),' ');
537                         label += limit_string_length(toc_list[i].str);
538                         if (toc_list[i].depth == depth
539                             && ++shortcut_count <= 9) {
540                                 label += '|' + tostr(shortcut_count);
541                         }
542                         tomenu.add(MenuItem(MenuItem::Command, label,
543                                             FuncRequest(toc_list[i].action())));
544                 }
545         } else {
546                 lyx::toc::Toc::size_type pos = from;
547                 while (pos < to) {
548                         lyx::toc::Toc::size_type new_pos = pos + 1;
549                         while (new_pos < to &&
550                                toc_list[new_pos].depth > depth)
551                                 ++new_pos;
552
553                         string label(4 * max(0, toc_list[pos].depth - depth), ' ');
554                         label += limit_string_length(toc_list[pos].str);
555                         if (toc_list[pos].depth == depth &&
556                             ++shortcut_count <= 9)
557                                 label += '|' + tostr(shortcut_count);
558
559                         if (new_pos == pos + 1) {
560                                 tomenu.add(MenuItem(MenuItem::Command,
561                                                     label, FuncRequest(toc_list[pos].action())));
562                         } else {
563                                 MenuItem item(MenuItem::Submenu, label);
564                                 item.submenu(new Menu);
565                                 expandToc2(*item.submenu(),
566                                            toc_list, pos, new_pos, depth + 1);
567                                 tomenu.add(item);
568                         }
569                         pos = new_pos;
570                 }
571         }
572 }
573
574
575 void expandToc(Menu & tomenu, LyXView const * view)
576 {
577         // To make things very cleanly, we would have to pass view to
578         // all MenuItem constructors and to expandToc2. However, we
579         // know that all the entries in a TOC will be have status_ ==
580         // OK, so we avoid this unnecessary overhead (JMarc)
581
582         if (!view->buffer()) {
583                 tomenu.add(MenuItem(MenuItem::Command,
584                                     _("No Documents Open!"),
585                                     FuncRequest(LFUN_NOACTION)),
586                            view);
587                 return;
588         }
589
590         lyx::toc::TocList toc_list = lyx::toc::getTocList(*view->buffer());
591         lyx::toc::TocList::const_iterator cit = toc_list.begin();
592         lyx::toc::TocList::const_iterator end = toc_list.end();
593         for (; cit != end; ++cit) {
594                 // Handle this later
595                 if (cit->first == "TOC")
596                         continue;
597
598                 // All the rest is for floats
599                 Menu * menu = new Menu;
600                 lyx::toc::Toc::const_iterator ccit = cit->second.begin();
601                 lyx::toc::Toc::const_iterator eend = cit->second.end();
602                 for (; ccit != eend; ++ccit) {
603                         string const label = limit_string_length(ccit->str);
604                         menu->add(MenuItem(MenuItem::Command,
605                                            label,
606                                            FuncRequest(ccit->action())));
607                 }
608                 string const & floatName = cit->first;
609                 // Is the _(...) really needed here? (Lgb)
610                 MenuItem item(MenuItem::Submenu, _(floatName));
611                 item.submenu(menu);
612                 tomenu.add(item);
613         }
614
615         // Handle normal TOC
616         cit = toc_list.find("TOC");
617         if (cit == end) {
618                 tomenu.add(MenuItem(MenuItem::Command,
619                                     _("No Table of contents"),
620                                     FuncRequest()),
621                            view);
622         } else {
623                 expandToc2(tomenu, cit->second, 0, cit->second.size(), 0);
624         }
625 }
626
627
628 void expandPasteRecent(Menu & tomenu, LyXView const * view)
629 {
630         if (!view || !view->buffer())
631                 return;
632
633         vector<string> const selL =
634                 CutAndPaste::availableSelections(*view->buffer());
635
636         vector<string>::const_iterator cit = selL.begin();
637         vector<string>::const_iterator end = selL.end();
638
639         for (unsigned int index = 0; cit != end; ++cit, ++index) {
640                 tomenu.add(MenuItem(MenuItem::Command, *cit,
641                                     FuncRequest(LFUN_PASTE, tostr(index))));
642         }
643 }
644
645
646 void expandBranches(Menu & tomenu, LyXView const * view)
647 {
648         if (!view || !view->buffer())
649                 return;
650
651         BufferParams const & params = view->buffer()->params();
652
653         std::list<Branch>::const_iterator cit = params.branchlist().begin();
654         std::list<Branch>::const_iterator end = params.branchlist().end();
655
656         for (int ii = 1; cit != end; ++cit, ++ii) {
657                 string label = cit->getBranch();
658                 if (ii < 10)
659                         label = tostr(ii) + ". " + label + "|" + tostr(ii);
660                 tomenu.add(MenuItem(MenuItem::Command, label,
661                                     FuncRequest(LFUN_INSERT_BRANCH,
662                                                 cit->getBranch())), view);
663         }
664 }
665
666
667 } // namespace anon
668
669
670 void MenuBackend::expand(Menu const & frommenu, Menu & tomenu,
671                          LyXView const * view) const
672 {
673         for (Menu::const_iterator cit = frommenu.begin();
674              cit != frommenu.end() ; ++cit) {
675                 switch (cit->kind()) {
676                 case MenuItem::Lastfiles:
677                         expandLastfiles(tomenu, view);
678                         break;
679
680                 case MenuItem::Documents:
681                         expandDocuments(tomenu, view);
682                         break;
683
684                 case MenuItem::ImportFormats:
685                 case MenuItem::ViewFormats:
686                 case MenuItem::UpdateFormats:
687                 case MenuItem::ExportFormats:
688                         expandFormats(cit->kind(), tomenu, view);
689                         break;
690
691                 case MenuItem::FloatListInsert:
692                         expandFloatListInsert(tomenu, view);
693                         break;
694
695                 case MenuItem::FloatInsert:
696                         expandFloatInsert(tomenu, view);
697                         break;
698
699                 case MenuItem::PasteRecent:
700                         expandPasteRecent(tomenu, view);
701                         break;
702
703                 case MenuItem::Branches:
704                         expandBranches(tomenu, view);
705                         break;
706
707                 case MenuItem::Toc:
708                         expandToc(tomenu, view);
709                         break;
710
711                 case MenuItem::Submenu: {
712                         MenuItem item(*cit);
713                         item.submenu(new Menu(cit->submenuname()));
714                         expand(getMenu(cit->submenuname()),
715                                *item.submenu(), view);
716                         tomenu.add(item, view);
717                 }
718                 break;
719
720                 default:
721                         tomenu.add(*cit, view);
722                 }
723         }
724
725         // we do not want the menu to end with a separator
726         if (!tomenu.empty()
727             && tomenu.items_.back().kind() == MenuItem::Separator)
728                 tomenu.items_.pop_back();
729
730         // Check whether the shortcuts are unique
731         tomenu.checkShortcuts();
732 }
733
734
735 bool Menu::hasSubmenu(string const & name) const
736 {
737         return find_if(begin(), end(),
738                        lyx::compare_memfun(&MenuItem::submenuname,
739                                            name)) != end();
740 }
741
742
743 void MenuBackend::read(LyXLex & lex)
744 {
745         enum Menutags {
746                 md_menu = 1,
747                 md_menubar,
748                 md_endmenuset,
749                 md_last
750         };
751
752         struct keyword_item menutags[md_last - 1] = {
753                 { "end", md_endmenuset },
754                 { "menu", md_menu },
755                 { "menubar", md_menubar }
756         };
757
758         //consistency check
759         if (compare_ascii_no_case(lex.getString(), "menuset")) {
760                 lyxerr << "Menubackend::read: ERROR wrong token:`"
761                        << lex.getString() << '\'' << endl;
762         }
763
764         lex.pushTable(menutags, md_last - 1);
765         if (lyxerr.debugging(Debug::PARSER))
766                 lex.printTable(lyxerr);
767
768         bool quit = false;
769
770         while (lex.isOK() && !quit) {
771                 switch (lex.lex()) {
772                 case md_menubar:
773                         menubar_.read(lex);
774                         break;
775                 case md_menu: {
776                         lex.next(true);
777                         string const name = lex.getString();
778                         if (hasMenu(name)) {
779                                 getMenu(name).read(lex);
780                         } else {
781                                 Menu menu(name);
782                                 menu.read(lex);
783                                 add(menu);
784                         }
785                         break;
786                 }
787                 case md_endmenuset:
788                         quit = true;
789                         break;
790                 default:
791                         lex.printError("menubackend::read: "
792                                        "Unknown menu tag: `$$Token'");
793                         break;
794                 }
795         }
796         lex.popTable();
797 }
798
799
800 void MenuBackend::add(Menu const & menu)
801 {
802         menulist_.push_back(menu);
803 }
804
805
806 bool MenuBackend::hasMenu(string const & name) const
807 {
808         return find_if(begin(), end(),
809                        lyx::compare_memfun(&Menu::name, name)) != end();
810 }
811
812
813 Menu const & MenuBackend::getMenu(string const & name) const
814 {
815         const_iterator cit = find_if(begin(), end(),
816                                      lyx::compare_memfun(&Menu::name, name));
817         if (cit == end())
818                 lyxerr << "No submenu named " << name << endl;
819         BOOST_ASSERT(cit != end());
820         return (*cit);
821 }
822
823
824 Menu & MenuBackend::getMenu(string const & name)
825 {
826         MenuList::iterator it =
827                 find_if(menulist_.begin(), menulist_.end(),
828                         lyx::compare_memfun(&Menu::name, name));
829         BOOST_ASSERT(it != menulist_.end());
830         return (*it);
831 }
832
833
834 Menu const & MenuBackend::getMenubar() const
835 {
836         return menubar_;
837 }