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