]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/Menus.cpp
Please Abdel
[lyx.git] / src / frontends / qt4 / Menus.cpp
1 /**
2  * \file qt4/Menus.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  * \author Asger Alstrup
8  * \author Lars Gullik Bjønnes
9  * \author Jean-Marc Lasgouttes
10  * \author André Pönitz
11  * \author Dekel Tsur
12  * \author Martin Vermeer
13  *
14  * Full author contact details are available in file CREDITS.
15  */
16
17 #include <config.h>
18
19 #include "Menus.h"
20
21 #include "Action.h"
22 #include "GuiApplication.h"
23 #include "GuiView.h"
24 #include "GuiWorkArea.h"
25 #include "qt_helpers.h"
26
27 #include "BiblioInfo.h"
28 #include "BranchList.h"
29 #include "Buffer.h"
30 #include "BufferList.h"
31 #include "BufferParams.h"
32 #include "BufferView.h"
33 #include "Converter.h"
34 #include "CutAndPaste.h"
35 #include "Floating.h"
36 #include "FloatList.h"
37 #include "Format.h"
38 #include "FuncRequest.h"
39 #include "FuncStatus.h"
40 #include "IndicesList.h"
41 #include "KeyMap.h"
42 #include "Language.h"
43 #include "Lexer.h"
44 #include "LyXAction.h"
45 #include "LyX.h"
46 #include "LyXRC.h"
47 #include "lyxfind.h"
48 #include "Paragraph.h"
49 #include "ParIterator.h"
50 #include "Session.h"
51 #include "SpellChecker.h"
52 #include "TextClass.h"
53 #include "TocBackend.h"
54 #include "Toolbars.h"
55 #include "WordLangTuple.h"
56
57 #include "insets/Inset.h"
58 #include "insets/InsetCitation.h"
59 #include "insets/InsetGraphics.h"
60
61 #include "support/lassert.h"
62 #include "support/convert.h"
63 #include "support/debug.h"
64 #include "support/docstring_list.h"
65 #include "support/filetools.h"
66 #include "support/gettext.h"
67 #include "support/lstrings.h"
68
69 #include <QCursor>
70 #include <QHash>
71 #include <QList>
72 #include <QMenuBar>
73 #include <QString>
74 #if QT_VERSION >= 0x040600
75 #include <QProxyStyle>
76 #endif
77
78 #include "support/shared_ptr.h"
79
80 #include <algorithm>
81 #include <vector>
82
83 using namespace std;
84 using namespace lyx::support;
85
86
87 namespace lyx {
88 namespace frontend {
89
90 namespace {
91
92 // MacOSX specific stuff is at the end.
93
94 class MenuDefinition;
95
96 ///
97 class MenuItem {
98 public:
99         /// The type of elements that can be in a menu
100         enum Kind {
101                 ///
102                 Command,
103                 ///
104                 Submenu,
105                 ///
106                 Separator,
107                 /** This type of item explains why something is unavailable. If this
108                     menuitem is in a submenu, the submenu is enabled to make sure the
109                     user sees the information. */
110                 Help,
111                 /** This type of item merely shows that there might be a list or 
112                     something alike at this position, but the list is still empty.
113                     If this item is in a submenu, the submenu will not always be 
114                     enabled. */
115                 Info,
116                 /** This is the list of last opened file,
117                     typically for the File menu. */
118                 Lastfiles,
119                 /** This is the list of opened Documents,
120                     typically for the Documents menu. */
121                 Documents,
122                 /** This is the bookmarks */
123                 Bookmarks,
124                 ///
125                 Toc,
126                 /** This is a list of viewable formats
127                     typically for the File->View menu. */
128                 ViewFormats,
129                 /** This is a list of updatable formats
130                     typically for the File->Update menu. */
131                 UpdateFormats,
132                 /** This is a list of exportable formats
133                     typically for the File->Export menu. */
134                 ExportFormats,
135                 /** This is a list of importable formats
136                     typically for the File->Import menu. */
137                 ImportFormats,
138                 /** This is the list of elements available
139                  * for insertion into document. */
140                 CharStyles,
141                 /** This is the list of user-configurable
142                 insets to insert into document */
143                 Custom,
144                 /** This is the list of XML elements to
145                 insert into the document */
146                 Elements,
147                 /** This is the list of floats that we can
148                     insert a list for. */
149                 FloatListInsert,
150                 /** This is the list of floats that we can
151                     insert. */
152                 FloatInsert,
153                 /** This is the list of selections that can
154                     be pasted. */
155                 PasteRecent,
156                 /** toolbars */
157                 Toolbars,
158                 /** Available branches in document */
159                 Branches,
160                 /** Available indices in document */
161                 Indices,
162                 /** Context menu for indices in document */
163                 IndicesContext,
164                 /** Available index lists in document */
165                 IndicesLists,
166                 /** Context menu for available indices lists in document */
167                 IndicesListsContext,
168                 /** Available citation styles for a given citation */
169                 CiteStyles,
170                 /** Available graphics groups */
171                 GraphicsGroups,
172                 /// Words suggested by the spellchecker.
173                 SpellingSuggestions,
174                 /** Used Languages */
175                 LanguageSelector
176         };
177
178         explicit MenuItem(Kind kind) : kind_(kind), optional_(false) {}
179
180         MenuItem(Kind kind,
181                  QString const & label,
182                  QString const & submenu = QString(),
183                  QString const & tooltip = QString(),
184                  bool optional = false)
185                 : kind_(kind), label_(label), submenuname_(submenu),
186                   tooltip_(tooltip), optional_(optional)
187         {
188                 LASSERT(kind == Submenu || kind == Help || kind == Info, /**/);
189         }
190
191         MenuItem(Kind kind,
192                  QString const & label,
193                  FuncRequest const & func,
194                  QString const & tooltip = QString(),
195                  bool optional = false,
196                  FuncRequest::Origin origin = FuncRequest::MENU)
197                 : kind_(kind), label_(label), func_(func),
198                   tooltip_(tooltip), optional_(optional)
199         {
200                 func_.setOrigin(origin);
201         }
202
203         // shared_ptr<MenuDefinition> needs this apprently...
204         ~MenuItem() {}
205
206         /// The label of a given menuitem
207         QString label() const 
208         {       
209                 int const index = label_.lastIndexOf('|');
210                 return index == -1 ? label_ : label_.left(index);
211         }
212
213         /// The keyboard shortcut (usually underlined in the entry)
214         QString shortcut() const
215         {
216                 int const index = label_.lastIndexOf('|');
217                 return index == -1 ? QString() : label_.mid(index + 1); 
218         }
219         /// The complete label, with label and shortcut separated by a '|'
220         QString fulllabel() const { return label_; }
221         /// The kind of entry
222         Kind kind() const { return kind_; }
223         /// the action (if relevant)
224         FuncRequest const & func() const { return func_; }
225         /// the tooltip
226         QString const & tooltip() const { return tooltip_; }
227         /// returns true if the entry should be omitted when disabled
228         bool optional() const { return optional_; }
229         /// returns the status of the lfun associated with this entry
230         FuncStatus const & status() const { return status_; }
231         /// returns the status of the lfun associated with this entry
232         FuncStatus & status() { return status_; }
233         /// returns the status of the lfun associated with this entry
234         void status(FuncStatus const & status) { status_ = status; }
235
236         ///returns the binding associated to this action.
237         QString binding() const
238         {
239                 if (kind_ != Command)
240                         return QString();
241                 // Get the keys bound to this action, but keep only the
242                 // first one later
243                 KeyMap::Bindings bindings = theTopLevelKeymap().findBindings(func_);
244                 if (bindings.size())
245                         return toqstr(bindings.begin()->print(KeySequence::ForGui));
246
247                 LYXERR(Debug::KBMAP, "No binding for "
248                         << lyxaction.getActionName(func_.action())
249                         << '(' << func_.argument() << ')');
250                 return QString();
251         }
252
253         /// the description of the  submenu (if relevant)
254         QString const & submenuname() const { return submenuname_; }
255         /// set the description of the  submenu
256         void submenuname(QString const & name) { submenuname_ = name; }
257         ///
258         bool hasSubmenu() const { return !submenu_.isEmpty(); }
259         ///
260         MenuDefinition const & submenu() const { return submenu_.at(0); }
261         MenuDefinition & submenu() { return submenu_[0]; }
262         ///
263         void setSubmenu(MenuDefinition const & menu)
264         {
265                 submenu_.clear();
266                 submenu_.append(menu);
267         }
268
269 private:
270         ///
271         Kind kind_;
272         ///
273         QString label_;
274         ///
275         FuncRequest func_;
276         ///
277         QString submenuname_;
278         ///
279         QString tooltip_;
280         ///
281         bool optional_;
282         ///
283         FuncStatus status_;
284         /// contains 0 or 1 item.
285         QList<MenuDefinition> submenu_;
286 };
287
288 ///
289 class MenuDefinition {
290 public:
291         ///
292         typedef std::vector<MenuItem> ItemList;
293         ///
294         typedef ItemList::const_iterator const_iterator;
295         ///
296         explicit MenuDefinition(QString const & name = QString()) : name_(name) {}
297
298         ///
299         void read(Lexer &);
300         ///
301         QString const & name() const { return name_; }
302         ///
303         bool empty() const { return items_.empty(); }
304         /// Clear the menu content.
305         void clear() { items_.clear(); }
306         ///
307         size_t size() const { return items_.size(); }
308         ///
309         MenuItem const & operator[](size_t) const;
310         ///
311         const_iterator begin() const { return items_.begin(); }
312         ///
313         const_iterator end() const { return items_.end(); }
314         ///
315         void cat(MenuDefinition const & other);
316         
317         // search for func in this menu iteratively, and put menu
318         // names in a stack.
319         bool searchMenu(FuncRequest const & func, docstring_list & names)
320                 const;
321         ///
322         bool hasFunc(FuncRequest const &) const;
323         /// Add the menu item unconditionally
324         void add(MenuItem const & item) { items_.push_back(item); }
325         /// Checks the associated FuncRequest status before adding the
326         /// menu item.
327         void addWithStatusCheck(MenuItem const &);
328         // Check whether the menu shortcuts are unique
329         void checkShortcuts() const;
330         ///
331         void expandLastfiles();
332         void expandDocuments();
333         void expandBookmarks();
334         void expandFormats(MenuItem::Kind kind, Buffer const * buf);
335         void expandFloatListInsert(Buffer const * buf);
336         void expandFloatInsert(Buffer const * buf);
337         void expandFlexInsert(Buffer const * buf, InsetLayout::InsetLyXType type);
338         void expandToc2(Toc const & toc_list, size_t from, size_t to, int depth);
339         void expandToc(Buffer const * buf);
340         void expandPasteRecent(Buffer const * buf);
341         void expandToolbars();
342         void expandBranches(Buffer const * buf);
343         void expandIndices(Buffer const * buf, bool listof = false);
344         void expandIndicesContext(Buffer const * buf, bool listof = false);
345         void expandCiteStyles(BufferView const *);
346         void expandGraphicsGroups(BufferView const *);
347         void expandSpellingSuggestions(BufferView const *);
348         void expandLanguageSelector(Buffer const * buf);
349         ///
350         ItemList items_;
351         ///
352         QString name_;
353 };
354
355
356 /// Helper for std::find_if
357 class MenuNamesEqual
358 {
359 public:
360         MenuNamesEqual(QString const & name) : name_(name) {}
361         bool operator()(MenuDefinition const & menu) const { return menu.name() == name_; }
362 private:
363         QString name_;
364 };
365
366
367 ///
368 typedef std::vector<MenuDefinition> MenuList;
369 ///
370 typedef MenuList::const_iterator const_iterator;
371 ///
372 typedef MenuList::iterator iterator;
373
374 /////////////////////////////////////////////////////////////////////
375 // MenuDefinition implementation
376 /////////////////////////////////////////////////////////////////////
377
378 void MenuDefinition::addWithStatusCheck(MenuItem const & i)
379 {
380         switch (i.kind()) {
381
382         case MenuItem::Command: {
383                 FuncStatus status = lyx::getStatus(i.func());
384                 if (status.unknown() || (!status.enabled() && i.optional()))
385                         break;
386                 items_.push_back(i);
387                 items_.back().status(status);
388                 break;
389         }
390
391         case MenuItem::Submenu: {
392                 bool enabled = false;
393                 if (i.hasSubmenu()) {
394                         for (const_iterator cit = i.submenu().begin();
395                                   cit != i.submenu().end(); ++cit) {
396                                 // Only these kind of items affect the status of the submenu
397                                 if ((cit->kind() == MenuItem::Command
398                                         || cit->kind() == MenuItem::Submenu
399                                         || cit->kind() == MenuItem::Help)
400                                     && cit->status().enabled()) {
401                                         enabled = true;
402                                         break;
403                                 }
404                         }
405                 }
406                 if (enabled || !i.optional()) {
407                         items_.push_back(i);
408                         items_.back().status().setEnabled(enabled);
409                 }
410                 break;
411         }
412
413         case MenuItem::Separator:
414                 if (!items_.empty() && items_.back().kind() != MenuItem::Separator)
415                         items_.push_back(i);
416                 break;
417
418         default:
419                 items_.push_back(i);
420         }
421 }
422
423
424 void MenuDefinition::read(Lexer & lex)
425 {
426         enum {
427                 md_item = 1,
428                 md_branches,
429                 md_citestyles,
430                 md_documents,
431                 md_bookmarks,
432                 md_charstyles,
433                 md_custom,
434                 md_elements,
435                 md_endmenu,
436                 md_exportformats,
437                 md_importformats,
438                 md_indices,
439                 md_indicescontext,
440                 md_indiceslists,
441                 md_indiceslistscontext,
442                 md_lastfiles,
443                 md_optitem,
444                 md_optsubmenu,
445                 md_separator,
446                 md_submenu,
447                 md_toc,
448                 md_updateformats,
449                 md_viewformats,
450                 md_floatlistinsert,
451                 md_floatinsert,
452                 md_pasterecent,
453                 md_toolbars,
454                 md_graphicsgroups,
455                 md_spellingsuggestions,
456                 md_languageselector
457         };
458
459         LexerKeyword menutags[] = {
460                 { "bookmarks", md_bookmarks },
461                 { "branches", md_branches },
462                 { "charstyles", md_charstyles },
463                 { "citestyles", md_citestyles },
464                 { "custom", md_custom },
465                 { "documents", md_documents },
466                 { "elements", md_elements },
467                 { "end", md_endmenu },
468                 { "exportformats", md_exportformats },
469                 { "floatinsert", md_floatinsert },
470                 { "floatlistinsert", md_floatlistinsert },
471                 { "graphicsgroups", md_graphicsgroups },
472                 { "importformats", md_importformats },
473                 { "indices", md_indices },
474                 { "indicescontext", md_indicescontext },
475                 { "indiceslists", md_indiceslists },
476                 { "indiceslistscontext", md_indiceslistscontext },
477                 { "item", md_item },
478                 { "languageselector", md_languageselector },
479                 { "lastfiles", md_lastfiles },
480                 { "optitem", md_optitem },
481                 { "optsubmenu", md_optsubmenu },
482                 { "pasterecent", md_pasterecent },
483                 { "separator", md_separator },
484                 { "spellingsuggestions", md_spellingsuggestions },
485                 { "submenu", md_submenu },
486                 { "toc", md_toc },
487                 { "toolbars", md_toolbars },
488                 { "updateformats", md_updateformats },
489                 { "viewformats", md_viewformats }
490         };
491
492         lex.pushTable(menutags);
493         lex.setContext("MenuDefinition::read: ");
494
495         bool quit = false;
496         bool optional = false;
497
498         while (lex.isOK() && !quit) {
499                 switch (lex.lex()) {
500                 case md_optitem:
501                         optional = true;
502                         // fallback to md_item
503                 case md_item: {
504                         lex.next(true);
505                         docstring const name = translateIfPossible(lex.getDocString());
506                         lex.next(true);
507                         string const command = lex.getString();
508                         FuncRequest func = lyxaction.lookupFunc(command);
509                         FuncRequest::Origin origin = FuncRequest::MENU;
510                         if (name_.startsWith("context-toc-"))
511                                 origin = FuncRequest::TOC;
512                         add(MenuItem(MenuItem::Command, toqstr(name), func, QString(), optional, origin));
513                         optional = false;
514                         break;
515                 }
516
517                 case md_separator:
518                         add(MenuItem(MenuItem::Separator));
519                         break;
520
521                 case md_lastfiles:
522                         add(MenuItem(MenuItem::Lastfiles));
523                         break;
524
525                 case md_charstyles:
526                         add(MenuItem(MenuItem::CharStyles));
527                         break;
528
529                 case md_custom:
530                         add(MenuItem(MenuItem::Custom));
531                         break;
532
533                 case md_elements:
534                         add(MenuItem(MenuItem::Elements));
535                         break;
536
537                 case md_documents:
538                         add(MenuItem(MenuItem::Documents));
539                         break;
540
541                 case md_bookmarks:
542                         add(MenuItem(MenuItem::Bookmarks));
543                         break;
544
545                 case md_toc:
546                         add(MenuItem(MenuItem::Toc));
547                         break;
548
549                 case md_viewformats:
550                         add(MenuItem(MenuItem::ViewFormats));
551                         break;
552
553                 case md_updateformats:
554                         add(MenuItem(MenuItem::UpdateFormats));
555                         break;
556
557                 case md_exportformats:
558                         add(MenuItem(MenuItem::ExportFormats));
559                         break;
560
561                 case md_importformats:
562                         add(MenuItem(MenuItem::ImportFormats));
563                         break;
564
565                 case md_floatlistinsert:
566                         add(MenuItem(MenuItem::FloatListInsert));
567                         break;
568
569                 case md_floatinsert:
570                         add(MenuItem(MenuItem::FloatInsert));
571                         break;
572
573                 case md_pasterecent:
574                         add(MenuItem(MenuItem::PasteRecent));
575                         break;
576
577                 case md_toolbars:
578                         add(MenuItem(MenuItem::Toolbars));
579                         break;
580
581                 case md_branches:
582                         add(MenuItem(MenuItem::Branches));
583                         break;
584
585                 case md_citestyles:
586                         add(MenuItem(MenuItem::CiteStyles));
587                         break;
588
589                 case md_graphicsgroups:
590                         add(MenuItem(MenuItem::GraphicsGroups));
591                         break;
592
593                 case md_spellingsuggestions:
594                         add(MenuItem(MenuItem::SpellingSuggestions));
595                         break;
596
597                 case md_languageselector:
598                         add(MenuItem(MenuItem::LanguageSelector));
599                         break;
600
601                 case md_indices:
602                         add(MenuItem(MenuItem::Indices));
603                         break;
604
605                 case md_indicescontext:
606                         add(MenuItem(MenuItem::IndicesContext));
607                         break;
608
609                 case md_indiceslists:
610                         add(MenuItem(MenuItem::IndicesLists));
611                         break;
612
613                 case md_indiceslistscontext:
614                         add(MenuItem(MenuItem::IndicesListsContext));
615                         break;
616
617                 case md_optsubmenu:
618                         optional = true;
619                         // fallback to md_submenu
620                 case md_submenu: {
621                         lex.next(true);
622                         docstring const mlabel = translateIfPossible(lex.getDocString());
623                         lex.next(true);
624                         docstring const mname = lex.getDocString();
625                         add(MenuItem(MenuItem::Submenu,
626                                 toqstr(mlabel), toqstr(mname), QString(), optional));
627                         optional = false;
628                         break;
629                 }
630
631                 case md_endmenu:
632                         quit = true;
633                         break;
634
635                 default:
636                         lex.printError("Unknown menu tag");
637                         break;
638                 }
639         }
640         lex.popTable();
641 }
642
643
644 MenuItem const & MenuDefinition::operator[](size_type i) const
645 {
646         return items_[i];
647 }
648
649
650 bool MenuDefinition::hasFunc(FuncRequest const & func) const
651 {
652         for (const_iterator it = begin(), et = end(); it != et; ++it)
653                 if (it->func() == func)
654                         return true;
655         return false;
656 }
657
658
659 void MenuDefinition::cat(MenuDefinition const & other)
660 {
661         const_iterator et = other.end();
662         for (const_iterator it = other.begin(); it != et; ++it)
663                 add(*it);
664 }
665
666
667 void MenuDefinition::checkShortcuts() const
668 {
669         // This is a quadratic algorithm, but we do not care because
670         // menus are short enough
671         for (const_iterator it1 = begin(); it1 != end(); ++it1) {
672                 QString shortcut = it1->shortcut();
673                 if (shortcut.isEmpty())
674                         continue;
675                 if (!it1->label().contains(shortcut))
676                         LYXERR0("Menu warning: menu entry \""
677                                << it1->label()
678                                << "\" does not contain shortcut `"
679                                << shortcut << "'.");
680                 for (const_iterator it2 = begin(); it2 != it1 ; ++it2) {
681                         if (!it2->shortcut().compare(shortcut, Qt::CaseInsensitive)) {
682                                 LYXERR0("Menu warning: menu entries "
683                                        << '"' << it1->fulllabel()
684                                        << "\" and \"" << it2->fulllabel()
685                                        << "\" share the same shortcut.");
686                         }
687                 }
688         }
689 }
690
691
692 bool MenuDefinition::searchMenu(FuncRequest const & func, docstring_list & names) const
693 {
694         const_iterator m = begin();
695         const_iterator m_end = end();
696         for (; m != m_end; ++m) {
697                 if (m->kind() == MenuItem::Command && m->func() == func) {
698                         names.push_back(qstring_to_ucs4(m->label()));
699                         return true;
700                 }
701                 if (m->kind() == MenuItem::Submenu) {
702                         names.push_back(qstring_to_ucs4(m->label()));
703                         if (!m->hasSubmenu()) {
704                                 LYXERR(Debug::GUI, "Warning: non existing sub menu label="
705                                         << m->label() << " name=" << m->submenuname());
706                                 names.pop_back();
707                                 continue;
708                         }
709                         if (m->submenu().searchMenu(func, names))
710                                 return true;
711                         names.pop_back();
712                 }
713         }
714         return false;
715 }
716
717
718 bool compareFormat(Format const * p1, Format const * p2)
719 {
720         return *p1 < *p2;
721 }
722
723
724 QString limitStringLength(docstring const & str)
725 {
726         size_t const max_item_length = 45;
727
728         if (str.size() > max_item_length)
729                 return toqstr(str.substr(0, max_item_length - 3) + "...");
730
731         return toqstr(str);
732 }
733
734
735 void MenuDefinition::expandGraphicsGroups(BufferView const * bv)
736 {
737         if (!bv)
738                 return;
739         set<string> grp;
740         graphics::getGraphicsGroups(bv->buffer(), grp);
741         if (grp.empty())
742                 return;
743
744         set<string>::const_iterator it = grp.begin();
745         set<string>::const_iterator end = grp.end();
746         add(MenuItem(MenuItem::Command, qt_("No Group"), 
747                      FuncRequest(LFUN_SET_GRAPHICS_GROUP)));
748         for (; it != end; it++) {
749                 addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(*it) + '|',
750                                 FuncRequest(LFUN_SET_GRAPHICS_GROUP, *it)));
751         }
752 }
753
754
755 void MenuDefinition::expandSpellingSuggestions(BufferView const * bv)
756 {
757         if (!bv)
758                 return;
759         WordLangTuple wl;
760         docstring_list suggestions;
761         Cursor const & cur = bv->cursor();
762         Paragraph const & par = cur.paragraph();
763         pos_type from = cur.pos();
764         pos_type to = from;
765         SpellChecker::Result res = par.spellCheck(from, to, wl, suggestions, true, true);
766         switch (res) {
767         case SpellChecker::UNKNOWN_WORD:
768                 if (lyxrc.spellcheck_continuously) {
769                         LYXERR(Debug::GUI, "Misspelled Word! Suggested Words = ");
770                         docstring const & selection = cur.selectionAsString(false);
771                         if (!cur.selection() || selection == wl.word()) {
772                                 size_t i = 0;
773                                 size_t m = 10; // first submenu index
774                                 MenuItem item(MenuItem::Submenu, qt_("More Spelling Suggestions"));
775                                 item.setSubmenu(MenuDefinition(qt_("More Spelling Suggestions")));
776                                 for (; i != suggestions.size(); ++i) {
777                                         docstring const & suggestion = suggestions[i];
778                                         LYXERR(Debug::GUI, suggestion);
779                                         MenuItem w(MenuItem::Command, toqstr(suggestion),
780                                                 FuncRequest(LFUN_WORD_REPLACE, 
781                                                         replace2string(suggestion,selection,
782                                                                 true, true, false, false)));
783                                         if (i < m)
784                                                 add(w);
785                                         else
786                                                 item.submenu().add(w);
787                                 }
788                                 if (i > m)
789                                         add(item);
790                                 if (i > 0)
791                                         add(MenuItem(MenuItem::Separator));
792                                 docstring const arg = wl.word() + " " + from_ascii(wl.lang()->lang());
793                                 add(MenuItem(MenuItem::Command, qt_("Add to personal dictionary|n"),
794                                                 FuncRequest(LFUN_SPELLING_ADD, arg)));
795                                 add(MenuItem(MenuItem::Command, qt_("Ignore all|I"),
796                                                 FuncRequest(LFUN_SPELLING_IGNORE, arg)));
797                         }
798                 }
799                 break;
800         case SpellChecker::LEARNED_WORD: {
801                         LYXERR(Debug::GUI, "Learned Word.");
802                         docstring const arg = wl.word() + " " + from_ascii(wl.lang()->lang());
803                         add(MenuItem(MenuItem::Command, qt_("Remove from personal dictionary|r"),
804                                         FuncRequest(LFUN_SPELLING_REMOVE, arg)));
805                 }
806                 break;
807         case SpellChecker::WORD_OK:
808         case SpellChecker::COMPOUND_WORD:
809         case SpellChecker::ROOT_FOUND:
810         case SpellChecker::IGNORED_WORD:
811                 break;
812         }
813 }
814
815 struct sortLanguageByName {
816         bool operator()(const Language * a, const Language * b) const {
817                 return qt_(a->display()).localeAwareCompare(qt_(b->display())) < 0;
818         }
819 };
820
821 void MenuDefinition::expandLanguageSelector(Buffer const * buf)
822 {
823         if (!buf)
824                 return;
825
826         std::set<Language const *> languages_buffer =
827                 buf->masterBuffer()->getLanguages();
828         
829         if (languages_buffer.size() < 2)
830                 return;
831
832         std::set<Language const *, sortLanguageByName> languages;
833
834         std::set<Language const *>::const_iterator const beg =
835                 languages_buffer.begin();
836         for (std::set<Language const *>::const_iterator cit = beg;
837              cit != languages_buffer.end(); ++cit) {
838                 languages.insert(*cit);
839         }
840
841         MenuItem item(MenuItem::Submenu, qt_("Language|L"));
842         item.setSubmenu(MenuDefinition(qt_("Language")));
843         QString morelangs = qt_("More Languages ...|M");
844         QStringList accelerators;
845         if (morelangs.contains('|'))
846                 accelerators.append(morelangs.section('|', -1));
847         std::set<Language const *, sortLanguageByName>::const_iterator const begin = languages.begin();
848         for (std::set<Language const *, sortLanguageByName>::const_iterator cit = begin;
849              cit != languages.end(); ++cit) {
850                 QString label = qt_((*cit)->display());
851                 // try to add an accelerator
852                 bool success = false;
853                 // try capitals first
854                 for (int i = 0; i < label.size(); ++i) {
855                         QChar const ch = label[i];
856                         if (!ch.isUpper())
857                                 continue;
858                         if (!accelerators.contains(ch, Qt::CaseInsensitive)) {
859                                 label = label + toqstr("|") + ch;
860                                 accelerators.append(ch);
861                                 success = true;
862                                 break;
863                         }
864                 }
865                 // if all capitals are taken, try the rest
866                 if (!success) {
867                         for (int i = 0; i < label.size(); ++i) {
868                                 if (label[i].isSpace())
869                                         continue;
870                                 QString const ch = QString(label[i]);
871                                 if (!accelerators.contains(ch, Qt::CaseInsensitive)) {
872                                         label = label + toqstr("|") + ch;
873                                         accelerators.append(ch);
874                                         break;
875                                 }
876                         }
877                 }
878                 MenuItem w(MenuItem::Command, label,
879                         FuncRequest(LFUN_LANGUAGE, (*cit)->lang()));
880                 item.submenu().addWithStatusCheck(w);
881         }
882         item.submenu().add(MenuItem(MenuItem::Separator));
883         item.submenu().add(MenuItem(MenuItem::Command, morelangs,
884                         FuncRequest(LFUN_DIALOG_SHOW, "character")));
885         add(item);
886 }
887
888
889 void MenuDefinition::expandLastfiles()
890 {
891         LastFilesSection::LastFiles const & lf = theSession().lastFiles().lastFiles();
892         LastFilesSection::LastFiles::const_iterator lfit = lf.begin();
893
894         unsigned int ii = 1;
895
896         for (; lfit != lf.end() && ii <= lyxrc.num_lastfiles; ++lfit, ++ii) {
897                 string const file = lfit->absFileName();
898                 QString const short_path = toqstr(makeDisplayPath(file, 30));
899                 QString const long_path = toqstr(makeDisplayPath(file));
900                 QString label;
901                 if (ii < 10)
902                         label = QString("%1. %2|%3").arg(ii).arg(short_path).arg(ii);
903                 else
904                         label = QString("%1. %2").arg(ii).arg(short_path);
905                 add(MenuItem(MenuItem::Command, label,
906                         FuncRequest(LFUN_FILE_OPEN, file), long_path));
907         }
908 }
909
910
911 void MenuDefinition::expandDocuments()
912 {
913         MenuItem item(MenuItem::Submenu, qt_("Hidden|H"));
914         item.setSubmenu(MenuDefinition(qt_("Hidden|H")));
915
916         Buffer * first = theBufferList().first();
917         if (!first) {
918                 add(MenuItem(MenuItem::Info, qt_("<No Documents Open>")));
919                 return;
920         }
921
922         int i = 0;
923         while (true) {
924                 if (!guiApp->currentView())
925                         break;
926                 GuiWorkArea * wa = guiApp->currentView()->workArea(i);
927                 if (!wa)
928                         break;
929                 Buffer const & b = wa->bufferView().buffer();
930                 QString label = toqstr(b.fileName().displayName(20));
931                 if (!b.isClean())
932                         label += "*";
933                 if (i < 10)
934                         label = QString::number(i) + ". " + label + '|' + QString::number(i);
935                 add(MenuItem(MenuItem::Command, label,
936                         FuncRequest(LFUN_BUFFER_SWITCH, b.absFileName())));
937                 ++i;
938         }
939
940
941         i = 0;
942         Buffer * b = first;
943         // We cannot use a for loop as the buffer list cycles.
944         do {
945                 bool const shown = guiApp->currentView()
946                         ? guiApp->currentView()->workArea(*b) : false;
947                 if (!shown) {
948                         QString label = toqstr(b->fileName().displayName(20));
949                         if (!b->isClean())
950                                 label += "*";
951                         if (i < 10)
952                                 label = QString::number(i) + ". " + label + '|' + QString::number(i);
953                         item.submenu().add(MenuItem(MenuItem::Command, label,
954                                 FuncRequest(LFUN_BUFFER_SWITCH, b->absFileName())));
955                         ++i;
956                 }
957                 b = theBufferList().next(b);
958         } while (b != first); 
959         
960         if (!item.submenu().empty())
961                 add(item);
962 }
963
964
965 void MenuDefinition::expandBookmarks()
966 {
967         lyx::BookmarksSection const & bm = theSession().bookmarks();
968
969         bool empty = true;
970         for (size_t i = 1; i <= bm.size(); ++i) {
971                 if (bm.isValid(i)) {
972                         string const file = bm.bookmark(i).filename.absFileName();
973                         QString const label = QString("%1. %2|%3").arg(i)
974                                 .arg(toqstr(makeDisplayPath(file, 20))).arg(i);
975                         add(MenuItem(MenuItem::Command, label,
976                                 FuncRequest(LFUN_BOOKMARK_GOTO, convert<docstring>(i))));
977                         empty = false;
978                 }
979         }
980         if (empty)
981                 add(MenuItem(MenuItem::Info, qt_("<No Bookmarks Saved Yet>")));
982 }
983
984
985 void MenuDefinition::expandFormats(MenuItem::Kind kind, Buffer const * buf)
986 {
987         if (!buf && kind != MenuItem::ImportFormats)
988                 return;
989
990         typedef vector<Format const *> Formats;
991         Formats formats;
992         FuncCode action;
993
994         switch (kind) {
995         case MenuItem::ImportFormats:
996                 formats = theConverters().importableFormats();
997                 action = LFUN_BUFFER_IMPORT;
998                 break;
999         case MenuItem::ViewFormats:
1000                 formats = buf->exportableFormats(true);
1001                 action = LFUN_BUFFER_VIEW;
1002                 break;
1003         case MenuItem::UpdateFormats:
1004                 formats = buf->exportableFormats(true);
1005                 action = LFUN_BUFFER_UPDATE;
1006                 break;
1007         default:
1008                 formats = buf->exportableFormats(false);
1009                 action = LFUN_BUFFER_EXPORT;
1010         }
1011         sort(formats.begin(), formats.end(), &compareFormat);
1012
1013         bool const view_update = (kind == MenuItem::ViewFormats
1014                         || kind == MenuItem::UpdateFormats);
1015
1016         QString smenue;
1017         if (view_update)
1018                 smenue = (kind == MenuItem::ViewFormats ?
1019                         qt_("View (Other Formats)|F")
1020                         : qt_("Update (Other Formats)|p"));
1021         MenuItem item(MenuItem::Submenu, smenue);
1022         item.setSubmenu(MenuDefinition(smenue));
1023
1024         Formats::const_iterator fit = formats.begin();
1025         Formats::const_iterator end = formats.end();
1026         for (; fit != end ; ++fit) {
1027                 if ((*fit)->dummy())
1028                         continue;
1029
1030                 docstring lab = from_utf8((*fit)->prettyname());
1031                 docstring scut = from_utf8((*fit)->shortcut());
1032                 docstring const tmplab = lab;
1033  
1034                 if (!scut.empty())
1035                         lab += char_type('|') + scut;
1036                 docstring lab_i18n = translateIfPossible(lab);
1037                 bool const untranslated = (lab == lab_i18n);
1038                 QString const shortcut = toqstr(split(lab_i18n, lab, '|'));
1039                 QString label = toqstr(lab);
1040                 if (untranslated)
1041                         // this might happen if the shortcut
1042                         // has been redefined
1043                         label = toqstr(translateIfPossible(tmplab));
1044
1045                 switch (kind) {
1046                 case MenuItem::ImportFormats:
1047                         label += "...";
1048                         break;
1049                 case MenuItem::ViewFormats:
1050                 case MenuItem::UpdateFormats:
1051                         if ((*fit)->name() == buf->getDefaultOutputFormat()) {
1052                                 docstring lbl = (kind == MenuItem::ViewFormats ?
1053                                         bformat(_("View [%1$s]|V"), qstring_to_ucs4(label))
1054                                         : bformat(_("Update [%1$s]|U"), qstring_to_ucs4(label)));
1055                                 MenuItem w(MenuItem::Command, toqstr(lbl),
1056                                            FuncRequest(action));
1057                                 add(w);
1058                                 continue;
1059                         }
1060                 case MenuItem::ExportFormats:
1061                         if (!(*fit)->inExportMenu())
1062                                 continue;
1063                         break;
1064                 default:
1065                         LASSERT(false, /**/);
1066                         break;
1067                 }
1068                 if (!shortcut.isEmpty())
1069                         label += '|' + shortcut;
1070
1071                 if (view_update) {
1072                         if (buf)
1073                                 item.submenu().addWithStatusCheck(MenuItem(MenuItem::Command, label,
1074                                         FuncRequest(action, (*fit)->name())));
1075                         else
1076                                 item.submenu().add(MenuItem(MenuItem::Command, label,
1077                                         FuncRequest(action, (*fit)->name())));
1078                 } else {
1079                         if (buf)
1080                                 addWithStatusCheck(MenuItem(MenuItem::Command, label,
1081                                         FuncRequest(action, (*fit)->name())));
1082                         else
1083                                 add(MenuItem(MenuItem::Command, label,
1084                                         FuncRequest(action, (*fit)->name())));
1085                 }
1086         }
1087         if (view_update)
1088                 add(item);
1089 }
1090
1091
1092 void MenuDefinition::expandFloatListInsert(Buffer const * buf)
1093 {
1094         if (!buf)
1095                 return;
1096
1097         FloatList const & floats = buf->params().documentClass().floats();
1098         FloatList::const_iterator cit = floats.begin();
1099         FloatList::const_iterator end = floats.end();
1100         set<string> seen;
1101         for (; cit != end; ++cit) {
1102                 if (!cit->second.usesFloatPkg()) {
1103                         // Different floats could declare the same ListCommand. We only
1104                         // want it on the list once, though.
1105                         string const & list_cmd = cit->second.listCommand();
1106                         if (list_cmd.empty())
1107                                 // we do not know how to generate such a list
1108                                 continue;
1109                         // This form of insert returns an iterator pointing to the newly
1110                         // inserted element OR the existing element with that value, and
1111                         // a bool indicating whether we inserted a new element. So we can
1112                         // see if one is there and insert it if not all at once.
1113                         pair<set<string>::iterator, bool> ret = seen.insert(list_cmd);
1114                         if (!ret.second)
1115                                 continue;
1116                 }
1117                 string const & list_name = cit->second.listName();
1118                 addWithStatusCheck(MenuItem(MenuItem::Command, qt_(list_name),
1119                         FuncRequest(LFUN_FLOAT_LIST_INSERT, cit->second.floattype())));
1120         }
1121 }
1122
1123
1124 void MenuDefinition::expandFloatInsert(Buffer const * buf)
1125 {
1126         if (!buf)
1127                 return;
1128
1129         FloatList const & floats = buf->params().documentClass().floats();
1130         FloatList::const_iterator cit = floats.begin();
1131         FloatList::const_iterator end = floats.end();
1132         for (; cit != end; ++cit) {
1133                 // normal float
1134                 QString const label = qt_(cit->second.name());
1135                 addWithStatusCheck(MenuItem(MenuItem::Command, label,
1136                                     FuncRequest(LFUN_FLOAT_INSERT,
1137                                                 cit->second.floattype())));
1138         }
1139 }
1140
1141
1142 void MenuDefinition::expandFlexInsert(
1143                 Buffer const * buf, InsetLayout::InsetLyXType type)
1144 {
1145         if (!buf)
1146                 return;
1147
1148         TextClass::InsetLayouts const & insetLayouts =
1149                 buf->params().documentClass().insetLayouts();
1150         TextClass::InsetLayouts::const_iterator cit = insetLayouts.begin();
1151         TextClass::InsetLayouts::const_iterator end = insetLayouts.end();
1152         for (; cit != end; ++cit) {
1153                 if (cit->second.lyxtype() == type) {
1154                         docstring label = cit->first;
1155                         // we remove the "Flex:" prefix, if it is present
1156                         if (prefixIs(label, from_utf8("Flex:")))
1157                                 label = label.substr(5);
1158                         addWithStatusCheck(MenuItem(MenuItem::Command, 
1159                                 toqstr(translateIfPossible(label)),
1160                                 FuncRequest(LFUN_FLEX_INSERT, Lexer::quoteString(label))));
1161                 }
1162         }
1163         // FIXME This is a little clunky.
1164         if (items_.empty() && type == InsetLayout::CUSTOM)
1165                 add(MenuItem(MenuItem::Help, qt_("No Custom Insets Defined!")));
1166 }
1167
1168
1169 size_t const max_number_of_items = 25;
1170
1171 void MenuDefinition::expandToc2(Toc const & toc_list,
1172                 size_t from, size_t to, int depth)
1173 {
1174         int shortcut_count = 0;
1175
1176         // check whether depth is smaller than the smallest depth in toc.
1177         int min_depth = 1000;
1178         for (size_t i = from; i < to; ++i)
1179                 min_depth = min(min_depth, toc_list[i].depth());
1180         if (min_depth > depth)
1181                 depth = min_depth;
1182
1183         if (to - from <= max_number_of_items) {
1184                 for (size_t i = from; i < to; ++i) {
1185                         QString label(4 * max(0, toc_list[i].depth() - depth), ' ');
1186                         label += limitStringLength(toc_list[i].str());
1187                         if (toc_list[i].depth() == depth) {
1188                                 label += '|';
1189                             if (shortcut_count < 9) {
1190                                         if (label.contains(QString::number(shortcut_count + 1)))
1191                                                 label += QString::number(++shortcut_count);
1192                                 }
1193                         }
1194                         add(MenuItem(MenuItem::Command, label,
1195                                             FuncRequest(toc_list[i].action())));
1196                 }
1197         } else {
1198                 size_t pos = from;
1199                 while (pos < to) {
1200                         size_t new_pos = pos + 1;
1201                         while (new_pos < to && toc_list[new_pos].depth() > depth)
1202                                 ++new_pos;
1203
1204                         QString label(4 * max(0, toc_list[pos].depth() - depth), ' ');
1205                         label += limitStringLength(toc_list[pos].str());
1206                         if (toc_list[pos].depth() == depth) {
1207                                 label += '|';
1208                             if (shortcut_count < 9) {
1209                                         if (label.contains(QString::number(shortcut_count + 1)))
1210                                                 label += QString::number(++shortcut_count);
1211                                 }
1212                         }
1213                         if (new_pos == pos + 1) {
1214                                 add(MenuItem(MenuItem::Command,
1215                                                     label, FuncRequest(toc_list[pos].action())));
1216                         } else {
1217                                 MenuDefinition sub;
1218                                 sub.expandToc2(toc_list, pos, new_pos, depth + 1);
1219                                 MenuItem item(MenuItem::Submenu, label);
1220                                 item.setSubmenu(sub);
1221                                 add(item);
1222                         }
1223                         pos = new_pos;
1224                 }
1225         }
1226 }
1227
1228
1229 void MenuDefinition::expandToc(Buffer const * buf)
1230 {
1231         // To make things very cleanly, we would have to pass buf to
1232         // all MenuItem constructors and to expandToc2. However, we
1233         // know that all the entries in a TOC will be have status_ ==
1234         // OK, so we avoid this unnecessary overhead (JMarc)
1235
1236         if (!buf) {
1237                 add(MenuItem(MenuItem::Info, qt_("<No Document Open>")));
1238                 return;
1239         }
1240
1241         // Add an entry for the master doc if this is a child doc
1242         Buffer const * const master = buf->masterBuffer();
1243         if (buf != master) {
1244                 ParIterator const pit = par_iterator_begin(master->inset());
1245                 string const arg = convert<string>(pit->id());
1246                 FuncRequest f(LFUN_PARAGRAPH_GOTO, arg);
1247                 add(MenuItem(MenuItem::Command, qt_("Master Document"), f));
1248         }
1249
1250         MenuDefinition other_lists;
1251         
1252         FloatList const & floatlist = buf->params().documentClass().floats();
1253         TocList const & toc_list = buf->tocBackend().tocs();
1254         TocList::const_iterator cit = toc_list.begin();
1255         TocList::const_iterator end = toc_list.end();
1256         for (; cit != end; ++cit) {
1257                 // Handle this later
1258                 if (cit->first == "tableofcontents")
1259                         continue;
1260
1261                 MenuDefinition submenu;
1262                 if (cit->second.size() >= 30) {
1263                         FuncRequest f(LFUN_DIALOG_SHOW, "toc " + cit->first);
1264                         submenu.add(MenuItem(MenuItem::Command, qt_("Open Navigator..."), f));
1265                 } else {
1266                         TocIterator ccit = cit->second.begin();
1267                         TocIterator eend = cit->second.end();
1268                         for (; ccit != eend; ++ccit) {
1269                                 submenu.add(MenuItem(MenuItem::Command,
1270                                         limitStringLength(ccit->str()) + '|',
1271                                         FuncRequest(ccit->action())));
1272                         }
1273                 }
1274
1275                 MenuItem item(MenuItem::Submenu, guiName(cit->first, buf->params()));
1276                 item.setSubmenu(submenu);
1277                 if (floatlist.typeExist(cit->first) || cit->first == "child") {
1278                         // Those two types deserve to be in the main menu.
1279                         item.setSubmenu(submenu);
1280                         add(item);
1281                 } else
1282                         other_lists.add(item);
1283         }
1284         if (!other_lists.empty()) {
1285                 MenuItem item(MenuItem::Submenu, qt_("Other Lists"));
1286                 item.setSubmenu(other_lists);
1287                 add(item);
1288         }
1289
1290         // Handle normal TOC
1291         cit = toc_list.find("tableofcontents");
1292         if (cit == end)
1293                 LYXERR(Debug::GUI, "No table of contents.");
1294         else {
1295                 if (cit->second.size() > 0 ) 
1296                         expandToc2(cit->second, 0, cit->second.size(), 0);
1297                 else
1298                         add(MenuItem(MenuItem::Info, qt_("<Empty Table of Contents>")));
1299         }
1300 }
1301
1302
1303 void MenuDefinition::expandPasteRecent(Buffer const * buf)
1304 {
1305         docstring_list const sel = cap::availableSelections(buf);
1306
1307         docstring_list::const_iterator cit = sel.begin();
1308         docstring_list::const_iterator end = sel.end();
1309
1310         for (unsigned int index = 0; cit != end; ++cit, ++index) {
1311                 add(MenuItem(MenuItem::Command, toqstr(*cit) + '|',
1312                                     FuncRequest(LFUN_PASTE, convert<string>(index))));
1313         }
1314 }
1315
1316
1317 void MenuDefinition::expandToolbars()
1318 {
1319         MenuDefinition other_lists;
1320         // extracts the toolbars from the backend
1321         Toolbars::Infos::const_iterator cit = guiApp->toolbars().begin();
1322         Toolbars::Infos::const_iterator end = guiApp->toolbars().end();
1323         for (; cit != end; ++cit) {
1324                 MenuItem const item(MenuItem::Command, toqstr(cit->gui_name),
1325                                 FuncRequest(LFUN_TOOLBAR_TOGGLE, cit->name));
1326                 if (guiApp->toolbars().isMainToolbar(cit->name))
1327                         add(item);
1328                 else
1329                         other_lists.add(item);
1330         }
1331
1332         if (!other_lists.empty()) {
1333                 MenuItem item(MenuItem::Submenu, qt_("Other Toolbars"));
1334                 item.setSubmenu(other_lists);
1335                 add(item);
1336         }
1337 }
1338
1339
1340 void MenuDefinition::expandBranches(Buffer const * buf)
1341 {
1342         if (!buf)
1343                 return;
1344
1345         BufferParams const & master_params = buf->masterBuffer()->params();
1346         BufferParams const & params = buf->params();
1347         if (params.branchlist().empty() && master_params.branchlist().empty() ) {
1348                 add(MenuItem(MenuItem::Help, qt_("No Branches Set for Document!")));
1349                 return;
1350         }
1351
1352         BranchList::const_iterator cit = master_params.branchlist().begin();
1353         BranchList::const_iterator end = master_params.branchlist().end();
1354
1355         for (int ii = 1; cit != end; ++cit, ++ii) {
1356                 docstring label = cit->branch();
1357                 if (ii < 10) {
1358                         label = convert<docstring>(ii) + ". " + label
1359                                 + char_type('|') + convert<docstring>(ii);
1360                 }
1361                 addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(label),
1362                                     FuncRequest(LFUN_BRANCH_INSERT,
1363                                                 cit->branch())));
1364         }
1365         
1366         if (buf == buf->masterBuffer())
1367                 return;
1368         
1369         MenuDefinition child_branches;
1370         
1371         BranchList::const_iterator ccit = params.branchlist().begin();
1372         BranchList::const_iterator cend = params.branchlist().end();
1373
1374         for (int ii = 1; ccit != cend; ++ccit, ++ii) {
1375                 docstring label = ccit->branch();
1376                 if (ii < 10) {
1377                         label = convert<docstring>(ii) + ". " + label
1378                                 + char_type('|') + convert<docstring>(ii);
1379                 } else
1380                         label += char_type('|');
1381                 child_branches.addWithStatusCheck(MenuItem(MenuItem::Command,
1382                                     toqstr(label),
1383                                     FuncRequest(LFUN_BRANCH_INSERT,
1384                                                 ccit->branch())));
1385         }
1386         
1387         if (!child_branches.empty()) {
1388                 MenuItem item(MenuItem::Submenu, qt_("Child Document"));
1389                 item.setSubmenu(child_branches);
1390                 add(item);
1391         }
1392 }
1393
1394
1395 void MenuDefinition::expandIndices(Buffer const * buf, bool listof)
1396 {
1397         if (!buf)
1398                 return;
1399
1400         BufferParams const & params = buf->masterBuffer()->params();
1401         if (!params.use_indices) {
1402                 if (listof)
1403                         addWithStatusCheck(MenuItem(MenuItem::Command,
1404                                            qt_("Index List|I"),
1405                                            FuncRequest(LFUN_INDEX_PRINT,
1406                                                   from_ascii("idx"))));
1407                 else
1408                         addWithStatusCheck(MenuItem(MenuItem::Command,
1409                                            qt_("Index Entry|d"),
1410                                            FuncRequest(LFUN_INDEX_INSERT,
1411                                                   from_ascii("idx"))));
1412                 return;
1413         }
1414
1415         if (params.indiceslist().empty())
1416                 return;
1417
1418         IndicesList::const_iterator cit = params.indiceslist().begin();
1419         IndicesList::const_iterator end = params.indiceslist().end();
1420
1421         for (int ii = 1; cit != end; ++cit, ++ii) {
1422                 if (listof) {
1423                         docstring const label = 
1424                                 bformat(_("Index: %1$s"), cit->index());
1425                         addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(label),
1426                                            FuncRequest(LFUN_INDEX_PRINT, cit->shortcut())));
1427                 } else {
1428                         docstring const label = 
1429                                 bformat(_("Index Entry (%1$s)"), cit->index());
1430                         addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(label),
1431                                            FuncRequest(LFUN_INDEX_INSERT, cit->shortcut())));
1432                 }
1433         }
1434 }
1435
1436
1437 void MenuDefinition::expandIndicesContext(Buffer const * buf, bool listof)
1438 {
1439         if (!buf)
1440                 return;
1441
1442         BufferParams const & params = buf->masterBuffer()->params();
1443         if (!params.use_indices || params.indiceslist().empty())
1444                 return;
1445
1446         IndicesList::const_iterator cit = params.indiceslist().begin();
1447         IndicesList::const_iterator end = params.indiceslist().end();
1448
1449         for (int ii = 1; cit != end; ++cit, ++ii) {
1450                 if (listof) {
1451                         InsetCommandParams p(INDEX_PRINT_CODE);
1452                         p["type"] = cit->shortcut();
1453                         string const data = InsetCommand::params2string(p);
1454                         addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(cit->index()),
1455                                            FuncRequest(LFUN_INSET_MODIFY, data)));
1456                 } else {
1457                         docstring const label = 
1458                                         bformat(_("Index Entry (%1$s)"), cit->index());
1459                         addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(label),
1460                                            FuncRequest(LFUN_INSET_MODIFY,
1461                                                   from_ascii("changetype ") + cit->shortcut())));
1462                 }
1463         }
1464 }
1465
1466
1467 void MenuDefinition::expandCiteStyles(BufferView const * bv)
1468 {
1469         if (!bv)
1470                 return;
1471
1472         Inset const * inset = bv->cursor().nextInset();
1473         if (!inset || inset->lyxCode() != CITE_CODE) {
1474                 add(MenuItem(MenuItem::Command,
1475                                     qt_("No Citation in Scope!"),
1476                                     FuncRequest(LFUN_NOACTION)));
1477                 return;
1478         }
1479         InsetCommand const * citinset =
1480                                 static_cast<InsetCommand const *>(inset);
1481         
1482         Buffer const * buf = &bv->buffer();
1483         docstring key = citinset->getParam("key");
1484         // we can only handle one key currently
1485         if (contains(key, ','))
1486                 key = qstring_to_ucs4(toqstr(key).split(',')[0]);
1487
1488         vector<CiteStyle> citeStyleList = citeStyles(buf->params().citeEngine());
1489         docstring_list citeStrings =
1490                 buf->masterBibInfo().getCiteStrings(key, bv->buffer());
1491
1492         docstring_list::const_iterator cit = citeStrings.begin();
1493         docstring_list::const_iterator end = citeStrings.end();
1494
1495         for (int ii = 1; cit != end; ++cit, ++ii) {
1496                 docstring label = *cit;
1497                 CitationStyle cs;
1498                 CiteStyle cst = citeStyleList[ii - 1];
1499                 cs.style = cst;
1500                 addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(label),
1501                                     FuncRequest(LFUN_INSET_MODIFY,
1502                                                 "changetype " + from_utf8(citationStyleToString(cs)))));
1503         }
1504 }
1505
1506 } // namespace anon
1507
1508
1509 /////////////////////////////////////////////////////////////////////
1510 // Menu::Impl definition and implementation
1511 /////////////////////////////////////////////////////////////////////
1512
1513 struct Menu::Impl
1514 {
1515         /// populates the menu or one of its submenu
1516         /// This is used as a recursive function
1517         void populate(QMenu & qMenu, MenuDefinition const & menu);
1518
1519         /// Only needed for top level menus.
1520         MenuDefinition * top_level_menu;
1521         /// our owning view
1522         GuiView * view;
1523         /// the name of this menu
1524         QString name;
1525 };
1526
1527
1528
1529 /// Get a MenuDefinition item label from the menu backend
1530 static QString label(MenuItem const & mi)
1531 {
1532         QString label = mi.label();
1533         label.replace("&", "&&");
1534
1535         QString shortcut = mi.shortcut();
1536         if (!shortcut.isEmpty()) {
1537                 int pos = label.indexOf(shortcut);
1538                 if (pos != -1)
1539                         //label.insert(pos, 1, char_type('&'));
1540                         label.replace(pos, 0, "&");
1541         }
1542
1543         QString const binding = mi.binding();
1544         if (!binding.isEmpty())
1545                 label += '\t' + binding;
1546
1547         return label;
1548 }
1549
1550 void Menu::Impl::populate(QMenu & qMenu, MenuDefinition const & menu)
1551 {
1552         LYXERR(Debug::GUI, "populating menu " << menu.name());
1553         if (menu.size() == 0) {
1554                 LYXERR(Debug::GUI, "\tERROR: empty menu " << menu.name());
1555                 return;
1556         }
1557         LYXERR(Debug::GUI, " *****  menu entries " << menu.size());
1558         MenuDefinition::const_iterator m = menu.begin();
1559         MenuDefinition::const_iterator end = menu.end();
1560         for (; m != end; ++m) {
1561                 if (m->kind() == MenuItem::Separator)
1562                         qMenu.addSeparator();
1563                 else if (m->kind() == MenuItem::Submenu) {
1564                         QMenu * subMenu = qMenu.addMenu(label(*m));
1565                         populate(*subMenu, m->submenu());
1566                         subMenu->setEnabled(m->status().enabled());
1567                 } else {
1568                         // we have a MenuItem::Command
1569                         qMenu.addAction(new Action(view, QIcon(), label(*m), 
1570                                 m->func(), m->tooltip(), &qMenu));
1571                 }
1572         }
1573 }
1574
1575 #if defined(Q_WS_WIN) && (QT_VERSION >= 0x040600)
1576 class AlwaysMnemonicStyle : public QProxyStyle {
1577 public:
1578         int styleHint(StyleHint hint, const QStyleOption *opt = 0, const QWidget *widget = 0,
1579                 QStyleHintReturn *returnData = 0) const 
1580         {
1581                 if (hint == QStyle::SH_UnderlineShortcut)
1582                         return 1;
1583                 return QProxyStyle::styleHint(hint, opt, widget, returnData);
1584         }
1585 };
1586 #endif
1587
1588 /////////////////////////////////////////////////////////////////////
1589 // Menu implementation
1590 /////////////////////////////////////////////////////////////////////
1591
1592 Menu::Menu(GuiView * gv, QString const & name, bool top_level, bool keyboard)
1593 : QMenu(gv), d(new Menu::Impl)
1594 {
1595 #if defined(Q_WS_WIN) && (QT_VERSION >= 0x040600)
1596         if (keyboard)
1597                 setStyle(new AlwaysMnemonicStyle);
1598 #else
1599         (void) keyboard;
1600 #endif
1601         d->top_level_menu = top_level? new MenuDefinition : 0;
1602         d->view = gv;
1603         d->name = name;
1604         setTitle(name);
1605         if (d->top_level_menu)
1606                 connect(this, SIGNAL(aboutToShow()), this, SLOT(updateView())); 
1607 }
1608
1609
1610 Menu::~Menu()
1611 {
1612         delete d->top_level_menu;
1613         delete d;
1614 }
1615
1616
1617 void Menu::updateView()
1618 {
1619         guiApp->menus().updateMenu(this);
1620 }
1621
1622
1623 /////////////////////////////////////////////////////////////////////
1624 // Menus::Impl definition and implementation
1625 /////////////////////////////////////////////////////////////////////
1626
1627 struct Menus::Impl {
1628         ///
1629         bool hasMenu(QString const &) const;
1630         ///
1631         MenuDefinition & getMenu(QString const &);
1632         ///
1633         MenuDefinition const & getMenu(QString const &) const;
1634
1635         /// Expands some special entries of the menu
1636         /** The entries with the following kind are expanded to a
1637             sequence of Command MenuItems: Lastfiles, Documents,
1638             ViewFormats, ExportFormats, UpdateFormats, Branches, Indices
1639         */
1640         void expand(MenuDefinition const & frommenu, MenuDefinition & tomenu,
1641                 BufferView const *) const;
1642
1643         /// Initialize specific MACOS X menubar
1644         void macxMenuBarInit(GuiView * view, QMenuBar * qmb);
1645
1646         /// Mac special menu.
1647         /** This defines a menu whose entries list the FuncRequests
1648             that will be removed by expand() in other menus. This is
1649             used by the Qt/Mac code.
1650
1651             NOTE: Qt does not remove the menu items when clearing a QMenuBar,
1652             such that the items will keep accessing the FuncRequests in
1653             the MenuDefinition. While Menus::Impl might be recreated,
1654             we keep mac_special_menu_ in memory by making it static.
1655         */
1656         static MenuDefinition mac_special_menu_;
1657
1658         ///
1659         MenuList menulist_;
1660         ///
1661         MenuDefinition menubar_;
1662
1663         typedef QMap<GuiView *, QHash<QString, Menu*> > NameMap;
1664
1665         /// name to menu for \c menu() method.
1666         NameMap name_map_;
1667 };
1668
1669
1670 MenuDefinition Menus::Impl::mac_special_menu_;
1671
1672
1673 /*
1674   Here is what the Qt documentation says about how a menubar is chosen:
1675
1676      1) If the window has a QMenuBar then it is used. 2) If the window
1677      is a modal then its menubar is used. If no menubar is specified
1678      then a default menubar is used (as documented below) 3) If the
1679      window has no parent then the default menubar is used (as
1680      documented below).
1681
1682      The above 3 steps are applied all the way up the parent window
1683      chain until one of the above are satisifed. If all else fails a
1684      default menubar will be created, the default menubar on Qt/Mac is
1685      an empty menubar, however you can create a different default
1686      menubar by creating a parentless QMenuBar, the first one created
1687      will thus be designated the default menubar, and will be used
1688      whenever a default menubar is needed.
1689
1690   Thus, for Qt/Mac, we add the menus to a free standing menubar, so
1691   that this menubar will be used also when one of LyX' dialogs has
1692   focus. (JMarc)
1693 */
1694 void Menus::Impl::macxMenuBarInit(GuiView * view, QMenuBar * qmb)
1695 {
1696         /* Since Qt 4.2, the qt/mac menu code has special code for
1697            specifying the role of a menu entry. However, it does not
1698            work very well with our scheme of creating menus on demand,
1699            and therefore we need to put these entries in a special
1700            invisible menu. (JMarc)
1701         */
1702
1703         /* The entries of our special mac menu. If we add support for
1704          * special entries in Menus, we could imagine something
1705          * like
1706          *    SpecialItem About " "About LyX" "dialog-show aboutlyx"
1707          * and therefore avoid hardcoding. I am not sure it is worth
1708          * the hassle, though. (JMarc)
1709          */
1710         struct MacMenuEntry {
1711                 FuncCode action;
1712                 char const * arg;
1713                 char const * label;
1714                 QAction::MenuRole role;
1715         };
1716
1717         MacMenuEntry entries[] = {
1718                 {LFUN_DIALOG_SHOW, "aboutlyx", "About LyX",
1719                  QAction::AboutRole},
1720                 {LFUN_DIALOG_SHOW, "prefs", "Preferences",
1721                  QAction::PreferencesRole},
1722                 {LFUN_RECONFIGURE, "", "Reconfigure",
1723                  QAction::ApplicationSpecificRole},
1724                 {LFUN_LYX_QUIT, "", "Quit LyX", QAction::QuitRole}
1725         };
1726         const size_t num_entries = sizeof(entries) / sizeof(entries[0]);
1727
1728         // the special menu for Menus. Fill it up only once.
1729         if (mac_special_menu_.size() == 0) {
1730                 for (size_t i = 0 ; i < num_entries ; ++i) {
1731                         FuncRequest const func(entries[i].action,
1732                                 from_utf8(entries[i].arg));
1733                         mac_special_menu_.add(MenuItem(MenuItem::Command,
1734                                 entries[i].label, func));
1735                 }
1736         }
1737         
1738         // add the entries to a QMenu that will eventually be empty
1739         // and therefore invisible.
1740         QMenu * qMenu = qmb->addMenu("special");
1741         MenuDefinition::const_iterator cit = mac_special_menu_.begin();
1742         MenuDefinition::const_iterator end = mac_special_menu_.end();
1743         for (size_t i = 0 ; cit != end ; ++cit, ++i) {
1744                 Action * action = new Action(view, QIcon(), cit->label(),
1745                         cit->func(), QString(), qMenu);
1746                 action->setMenuRole(entries[i].role);
1747                 qMenu->addAction(action);
1748         }
1749 }
1750
1751
1752 void Menus::Impl::expand(MenuDefinition const & frommenu,
1753         MenuDefinition & tomenu, BufferView const * bv) const
1754 {
1755         if (!tomenu.empty())
1756                 tomenu.clear();
1757
1758         for (MenuDefinition::const_iterator cit = frommenu.begin();
1759              cit != frommenu.end() ; ++cit) {
1760                 Buffer const * buf = bv ? &bv->buffer() : 0;
1761                 switch (cit->kind()) {
1762                 case MenuItem::Lastfiles:
1763                         tomenu.expandLastfiles();
1764                         break;
1765
1766                 case MenuItem::Documents:
1767                         tomenu.expandDocuments();
1768                         break;
1769
1770                 case MenuItem::Bookmarks:
1771                         tomenu.expandBookmarks();
1772                         break;
1773
1774                 case MenuItem::ImportFormats:
1775                 case MenuItem::ViewFormats:
1776                 case MenuItem::UpdateFormats:
1777                 case MenuItem::ExportFormats:
1778                         tomenu.expandFormats(cit->kind(), buf);
1779                         break;
1780
1781                 case MenuItem::CharStyles:
1782                         tomenu.expandFlexInsert(buf, InsetLayout::CHARSTYLE);
1783                         break;
1784
1785                 case MenuItem::Custom:
1786                         tomenu.expandFlexInsert(buf, InsetLayout::CUSTOM);
1787                         break;
1788
1789                 case MenuItem::Elements:
1790                         tomenu.expandFlexInsert(buf, InsetLayout::ELEMENT);
1791                         break;
1792
1793                 case MenuItem::FloatListInsert:
1794                         tomenu.expandFloatListInsert(buf);
1795                         break;
1796
1797                 case MenuItem::FloatInsert:
1798                         tomenu.expandFloatInsert(buf);
1799                         break;
1800
1801                 case MenuItem::PasteRecent:
1802                         tomenu.expandPasteRecent(buf);
1803                         break;
1804
1805                 case MenuItem::Toolbars:
1806                         tomenu.expandToolbars();
1807                         break;
1808
1809                 case MenuItem::Branches:
1810                         tomenu.expandBranches(buf);
1811                         break;
1812
1813                 case MenuItem::Indices:
1814                         tomenu.expandIndices(buf);
1815                         break;
1816
1817                 case MenuItem::IndicesContext:
1818                         tomenu.expandIndicesContext(buf);
1819                         break;
1820
1821                 case MenuItem::IndicesLists:
1822                         tomenu.expandIndices(buf, true);
1823                         break;
1824
1825                 case MenuItem::IndicesListsContext:
1826                         tomenu.expandIndicesContext(buf, true);
1827                         break;
1828
1829                 case MenuItem::CiteStyles:
1830                         tomenu.expandCiteStyles(bv);
1831                         break;
1832
1833                 case MenuItem::Toc:
1834                         tomenu.expandToc(buf);
1835                         break;
1836
1837                 case MenuItem::GraphicsGroups:
1838                         tomenu.expandGraphicsGroups(bv);
1839                         break;
1840
1841                 case MenuItem::SpellingSuggestions:
1842                         tomenu.expandSpellingSuggestions(bv);
1843                         break;
1844
1845                 case MenuItem::LanguageSelector:
1846                         tomenu.expandLanguageSelector(buf);
1847                         break;
1848
1849                 case MenuItem::Submenu: {
1850                         MenuItem item(*cit);
1851                         item.setSubmenu(MenuDefinition(cit->submenuname()));
1852                         expand(getMenu(cit->submenuname()), item.submenu(), bv);
1853                         tomenu.addWithStatusCheck(item);
1854                 }
1855                 break;
1856
1857                 case MenuItem::Info:
1858                 case MenuItem::Help:
1859                 case MenuItem::Separator:
1860                         tomenu.addWithStatusCheck(*cit);
1861                         break;
1862
1863                 case MenuItem::Command:
1864                         if (!mac_special_menu_.hasFunc(cit->func()))
1865                                 tomenu.addWithStatusCheck(*cit);
1866                 }
1867         }
1868
1869         // we do not want the menu to end with a separator
1870         if (!tomenu.empty() && tomenu.items_.back().kind() == MenuItem::Separator)
1871                 tomenu.items_.pop_back();
1872
1873         // Check whether the shortcuts are unique
1874         tomenu.checkShortcuts();
1875 }
1876
1877
1878 bool Menus::Impl::hasMenu(QString const & name) const
1879 {
1880         return find_if(menulist_.begin(), menulist_.end(),
1881                 MenuNamesEqual(name)) != menulist_.end();
1882 }
1883
1884
1885 MenuDefinition const & Menus::Impl::getMenu(QString const & name) const
1886 {
1887         const_iterator cit = find_if(menulist_.begin(), menulist_.end(),
1888                 MenuNamesEqual(name));
1889         if (cit == menulist_.end())
1890                 LYXERR0("No submenu named " << name);
1891         LASSERT(cit != menulist_.end(), /**/);
1892         return (*cit);
1893 }
1894
1895
1896 MenuDefinition & Menus::Impl::getMenu(QString const & name)
1897 {
1898         iterator it = find_if(menulist_.begin(), menulist_.end(),
1899                 MenuNamesEqual(name));
1900         if (it == menulist_.end())
1901                 LYXERR0("No submenu named " << name);
1902         LASSERT(it != menulist_.end(), /**/);
1903         return (*it);
1904 }
1905
1906
1907 /////////////////////////////////////////////////////////////////////
1908 //
1909 // Menus 
1910 //
1911 /////////////////////////////////////////////////////////////////////
1912
1913 Menus::Menus() : d(new Impl) {}
1914
1915
1916 Menus::~Menus()
1917 {
1918   delete d;
1919 }
1920
1921
1922 void Menus::reset()
1923 {
1924         delete d;
1925         d = new Impl;
1926 }
1927
1928
1929 void Menus::read(Lexer & lex)
1930 {
1931         enum {
1932                 md_menu,
1933                 md_menubar,
1934                 md_endmenuset
1935         };
1936
1937         LexerKeyword menutags[] = {
1938                 { "end", md_endmenuset },
1939                 { "menu", md_menu },
1940                 { "menubar", md_menubar }
1941         };
1942
1943         // consistency check
1944         if (compare_ascii_no_case(lex.getString(), "menuset"))
1945                 LYXERR0("Menus::read: ERROR wrong token: `" << lex.getString() << '\'');
1946
1947         lex.pushTable(menutags);
1948         lex.setContext("Menus::read");
1949
1950         bool quit = false;
1951
1952         while (lex.isOK() && !quit) {
1953                 switch (lex.lex()) {
1954                 case md_menubar:
1955                         d->menubar_.read(lex);
1956                         break;
1957                 case md_menu: {
1958                         lex.next(true);
1959                         QString const name = toqstr(lex.getDocString());
1960                         if (d->hasMenu(name))
1961                                 d->getMenu(name).read(lex);
1962                         else {
1963                                 MenuDefinition menu(name);
1964                                 menu.read(lex);
1965                                 d->menulist_.push_back(menu);
1966                         }
1967                         break;
1968                 }
1969                 case md_endmenuset:
1970                         quit = true;
1971                         break;
1972                 default:
1973                         lex.printError("Unknown menu tag");
1974                         break;
1975                 }
1976         }
1977         lex.popTable();
1978 }
1979
1980
1981 bool Menus::searchMenu(FuncRequest const & func,
1982         docstring_list & names) const
1983 {
1984         MenuDefinition menu;
1985         d->expand(d->menubar_, menu, 0);
1986         return menu.searchMenu(func, names);
1987 }
1988
1989
1990 void Menus::fillMenuBar(QMenuBar * qmb, GuiView * view, bool initial)
1991 {
1992         if (initial) {
1993 #ifdef Q_WS_MACX
1994                 // setup special mac specific menu items, but only do this
1995                 // the first time a QMenuBar is created. Otherwise Qt will
1996                 // create duplicate items in the application menu. It seems
1997                 // that Qt does not remove them when the QMenubar is cleared.
1998                 LYXERR(Debug::GUI, "Creating Mac OS X special menu bar");
1999                 d->macxMenuBarInit(view, qmb);
2000 #endif
2001         } else {
2002                 // Clear all menubar contents before filling it.
2003                 qmb->clear();
2004         }
2005
2006         LYXERR(Debug::GUI, "populating menu bar" << d->menubar_.name());
2007
2008         if (d->menubar_.size() == 0) {
2009                 LYXERR(Debug::GUI, "\tERROR: empty menu bar"
2010                         << d->menubar_.name());
2011                 return;
2012         }
2013         LYXERR(Debug::GUI, "menu bar entries " << d->menubar_.size());
2014
2015         MenuDefinition menu;
2016         BufferView * bv = 0;
2017         if (view)
2018                 bv = view->currentBufferView();
2019         d->expand(d->menubar_, menu, bv);
2020
2021         MenuDefinition::const_iterator m = menu.begin();
2022         MenuDefinition::const_iterator end = menu.end();
2023
2024         for (; m != end; ++m) {
2025
2026                 if (m->kind() != MenuItem::Submenu) {
2027                         LYXERR(Debug::GUI, "\tERROR: not a submenu " << m->label());
2028                         continue;
2029                 }
2030
2031                 LYXERR(Debug::GUI, "menu bar item " << m->label()
2032                         << " is a submenu named " << m->submenuname());
2033
2034                 QString name = m->submenuname();
2035                 if (!d->hasMenu(name)) {
2036                         LYXERR(Debug::GUI, "\tERROR: " << name
2037                                 << " submenu has no menu!");
2038                         continue;
2039                 }
2040
2041                 Menu * menu = new Menu(view, m->submenuname(), true);
2042                 menu->setTitle(label(*m));
2043                 qmb->addMenu(menu);
2044
2045                 d->name_map_[view][name] = menu;
2046         }
2047 }
2048
2049
2050 void Menus::updateMenu(Menu * qmenu)
2051 {
2052         LYXERR(Debug::GUI, "Triggered menu: " << qmenu->d->name);
2053         qmenu->clear();
2054
2055         if (qmenu->d->name.isEmpty())
2056                 return;
2057
2058         docstring identifier = qstring_to_ucs4(qmenu->d->name);
2059         MenuDefinition fromLyxMenu(qmenu->d->name);
2060         while (!identifier.empty()) {
2061                 docstring menu_name;
2062                 identifier = split(identifier, menu_name, ';');
2063
2064                 if (!d->hasMenu(toqstr(menu_name))) {
2065                         LYXERR(Debug::GUI, "\tWARNING: non existing menu: "
2066                                 << menu_name);
2067                         continue;
2068                 }
2069
2070                 fromLyxMenu.cat(d->getMenu(toqstr(menu_name)));
2071                 fromLyxMenu.add(MenuItem(MenuItem::Separator));
2072         }
2073
2074         if (fromLyxMenu.empty()) {
2075                 qmenu->addAction(qt_("No Action Defined!"));
2076                 return;
2077         }
2078
2079         BufferView * bv = 0;
2080         if (qmenu->d->view)
2081                 bv = qmenu->d->view->currentBufferView();
2082         d->expand(fromLyxMenu, *qmenu->d->top_level_menu, bv);
2083         qmenu->d->populate(*qmenu, *qmenu->d->top_level_menu);
2084 }
2085
2086
2087 Menu * Menus::menu(QString const & name, GuiView & view, bool keyboard)
2088 {
2089         LYXERR(Debug::GUI, "Context menu requested: " << name);
2090         Menu * menu = d->name_map_[&view].value(name, 0);
2091         if (!menu && !name.startsWith("context-")) {
2092                 LYXERR0("requested context menu not found: " << name);
2093                 return 0;
2094         }
2095
2096         menu = new Menu(&view, name, true, keyboard);
2097         d->name_map_[&view][name] = menu;
2098         return menu;
2099 }
2100
2101 } // namespace frontend
2102 } // namespace lyx
2103
2104 #include "moc_Menus.cpp"