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