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