3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Asger Alstrup
8 * \author Lars Gullik Bjønnes
9 * \author Jean-Marc Lasgouttes
10 * \author André Pönitz
12 * \author Martin Vermeer
14 * Full author contact details are available in file CREDITS.
22 #include "GuiApplication.h"
24 #include "GuiWorkArea.h"
25 #include "qt_helpers.h"
27 #include "BiblioInfo.h"
28 #include "BranchList.h"
30 #include "BufferList.h"
31 #include "BufferParams.h"
32 #include "BufferView.h"
33 #include "Converter.h"
34 #include "CutAndPaste.h"
36 #include "FloatList.h"
38 #include "FuncRequest.h"
39 #include "FuncStatus.h"
40 #include "IndicesList.h"
45 #include "LyXAction.h"
49 #include "Paragraph.h"
50 #include "ParagraphParameters.h"
51 #include "ParIterator.h"
53 #include "SpellChecker.h"
54 #include "TextClass.h"
56 #include "TocBackend.h"
58 #include "WordLangTuple.h"
60 #include "insets/Inset.h"
61 #include "insets/InsetCitation.h"
62 #include "insets/InsetGraphics.h"
63 #include "insets/InsetQuotes.h"
65 #include "support/lassert.h"
66 #include "support/convert.h"
67 #include "support/debug.h"
68 #include "support/docstring_list.h"
69 #include "support/filetools.h"
70 #include "support/gettext.h"
71 #include "support/lstrings.h"
78 #if QT_VERSION >= 0x040600
79 #include <QProxyStyle>
87 using namespace lyx::support;
95 // MacOSX specific stuff is at the end.
102 /// The type of elements that can be in a menu
110 /** This type of item explains why something is unavailable. If this
111 menuitem is in a submenu, the submenu is enabled to make sure the
112 user sees the information. */
114 /** This type of item merely shows that there might be a list or
115 something alike at this position, but the list is still empty.
116 If this item is in a submenu, the submenu will not always be
119 /** This is the list of last opened file,
120 typically for the File menu. */
122 /** This is the list of opened Documents,
123 typically for the Documents menu. */
125 /** This is the bookmarks */
129 /** This is a list of viewable formats
130 typically for the File->View menu. */
132 /** This is a list of updatable formats
133 typically for the File->Update menu. */
135 /** This is a list of exportable formats
136 typically for the File->Export menu. */
138 /** This exports the document default format
139 typically for the File->Export menu. */
141 /** This is a list of importable formats
142 typically for the File->Import menu. */
144 /** This is the list of elements available
145 * for insertion into document. */
147 /** This is the list of user-configurable
148 insets to insert into document */
150 /** This is the list of XML elements to
151 insert into the document */
153 /** This is the list of floats that we can
154 insert a list for. */
156 /** This is the list of floats that we can
159 /** This is the list of selections that can
164 /** Available branches in document */
166 /** Available indices in document */
168 /** Context menu for indices in document */
170 /** Available index lists in document */
172 /** Context menu for available indices lists in document */
174 /** Available citation styles for a given citation */
176 /** Available graphics groups */
178 /// Words suggested by the spellchecker.
180 /** Used Languages */
182 /** This is the list of arguments available
183 for insertion into the current layout. */
185 /** This is the list of arguments available
186 in the InsetArgument context menu. */
188 /** This is the list of captions available
189 in the current layout. */
191 /** This is the list of captions available
192 in the InsetCaption context menu. */
194 /** Commands to separate environments. */
195 EnvironmentSeparators,
196 /** This is the list of quotation marks available */
200 explicit MenuItem(Kind kind) : kind_(kind), optional_(false) {}
203 QString const & label,
204 QString const & submenu = QString(),
205 QString const & tooltip = QString(),
206 bool optional = false)
207 : kind_(kind), label_(label), func_(make_shared<FuncRequest>()),
208 submenuname_(submenu), tooltip_(tooltip), optional_(optional)
210 LATTEST(kind == Submenu || kind == Help || kind == Info);
214 QString const & label,
215 FuncRequest const & func,
216 QString const & tooltip = QString(),
217 bool optional = false,
218 FuncRequest::Origin origin = FuncRequest::MENU)
219 : kind_(kind), label_(label), func_(make_shared<FuncRequest>(func)),
220 tooltip_(tooltip), optional_(optional)
222 func_->setOrigin(origin);
225 /// The label of a given menuitem
226 QString label() const
228 int const index = label_.lastIndexOf('|');
229 return index == -1 ? label_ : label_.left(index);
232 /// The keyboard shortcut (usually underlined in the entry)
233 QString shortcut() const
235 int const index = label_.lastIndexOf('|');
236 return index == -1 ? QString() : label_.mid(index + 1);
238 /// The complete label, with label and shortcut separated by a '|'
239 QString fulllabel() const { return label_; }
240 /// The kind of entry
241 Kind kind() const { return kind_; }
242 /// the action (if relevant)
243 shared_ptr<FuncRequest const> func() const { return func_; }
245 QString const & tooltip() const { return tooltip_; }
246 /// returns true if the entry should be omitted when disabled
247 bool optional() const { return optional_; }
248 /// returns the status of the lfun associated with this entry
249 FuncStatus const & status() const { return status_; }
250 /// returns the status of the lfun associated with this entry
251 FuncStatus & status() { return status_; }
252 /// returns the status of the lfun associated with this entry
253 void status(FuncStatus const & status) { status_ = status; }
255 ///returns the binding associated to this action.
256 QString binding() const
258 if (kind_ != Command)
260 // Get the keys bound to this action, but keep only the
262 KeyMap::Bindings bindings = theTopLevelKeymap().findBindings(*func_);
263 if (!bindings.empty())
264 return toqstr(bindings.begin()->print(KeySequence::ForGui));
266 LYXERR(Debug::KBMAP, "No binding for "
267 << lyxaction.getActionName(func_->action())
268 << '(' << func_->argument() << ')');
272 /// the description of the submenu (if relevant)
273 QString const & submenuname() const { return submenuname_; }
274 /// set the description of the submenu
275 void submenuname(QString const & name) { submenuname_ = name; }
277 bool hasSubmenu() const { return !submenu_.isEmpty(); }
279 MenuDefinition const & submenu() const { return submenu_.at(0); }
280 MenuDefinition & submenu() { return submenu_[0]; }
282 void setSubmenu(MenuDefinition const & menu)
285 submenu_.append(menu);
294 shared_ptr<FuncRequest> func_;// non-null
296 QString submenuname_;
303 /// contains 0 or 1 item.
304 QList<MenuDefinition> submenu_;
308 class MenuDefinition {
311 typedef std::vector<MenuItem> ItemList;
313 typedef ItemList::const_iterator const_iterator;
315 explicit MenuDefinition(QString const & name = QString()) : name_(name) {}
320 QString const & name() const { return name_; }
322 bool empty() const { return items_.empty(); }
323 /// Clear the menu content.
324 void clear() { items_.clear(); }
326 size_t size() const { return items_.size(); }
328 const_iterator begin() const { return items_.begin(); }
330 const_iterator end() const { return items_.end(); }
332 void cat(MenuDefinition const & other);
334 void catSub(docstring const & name);
336 // search for func in this menu iteratively, and put menu
338 bool searchMenu(FuncRequest const & func, docstring_list & names)
341 bool hasFunc(FuncRequest const &) const;
342 /// Add the menu item unconditionally
343 void add(MenuItem const & item) { items_.push_back(item); }
344 /// Checks the associated FuncRequest status before adding the
346 void addWithStatusCheck(MenuItem const &);
347 // Check whether the menu shortcuts are unique
348 void checkShortcuts() const;
350 void expandLastfiles();
351 void expandDocuments();
352 void expandBookmarks();
353 void expandFormats(MenuItem::Kind const kind, Buffer const * buf);
354 void expandFloatListInsert(Buffer const * buf);
355 void expandFloatInsert(Buffer const * buf);
356 void expandFlexInsert(Buffer const * buf, InsetLayout::InsetLyXType type);
357 void expandTocSubmenu(std::string const & type, Toc const & toc_list);
358 void expandToc2(Toc const & toc_list, size_t from, size_t to, int depth, string toc_type);
359 void expandToc(Buffer const * buf);
360 void expandPasteRecent(Buffer const * buf);
361 void expandToolbars();
362 void expandBranches(Buffer const * buf);
363 void expandIndices(Buffer const * buf, bool listof = false);
364 void expandIndicesContext(Buffer const * buf, bool listof = false);
365 void expandCiteStyles(BufferView const *);
366 void expandGraphicsGroups(BufferView const *);
367 void expandSpellingSuggestions(BufferView const *);
368 void expandLanguageSelector(Buffer const * buf);
369 void expandArguments(BufferView const *, bool switcharg = false);
370 void expandCaptions(Buffer const * buf, bool switchcap = false);
371 void expandEnvironmentSeparators(BufferView const *);
372 void expandQuotes(BufferView const *);
380 /// Helper for std::find_if
384 MenuNamesEqual(QString const & name) : name_(name) {}
385 bool operator()(MenuDefinition const & menu) const { return menu.name() == name_; }
392 typedef std::vector<MenuDefinition> MenuList;
394 typedef MenuList::const_iterator const_iterator;
396 typedef MenuList::iterator iterator;
398 /////////////////////////////////////////////////////////////////////
399 // MenuDefinition implementation
400 /////////////////////////////////////////////////////////////////////
402 void MenuDefinition::addWithStatusCheck(MenuItem const & i)
406 case MenuItem::Command: {
407 FuncStatus status = lyx::getStatus(*i.func());
408 if (status.unknown() || (!status.enabled() && i.optional()))
411 items_.back().status(status);
415 case MenuItem::Submenu: {
416 bool enabled = false;
417 if (i.hasSubmenu()) {
418 for (const_iterator cit = i.submenu().begin();
419 cit != i.submenu().end(); ++cit) {
420 // Only these kind of items affect the status of the submenu
421 if ((cit->kind() == MenuItem::Command
422 || cit->kind() == MenuItem::Submenu
423 || cit->kind() == MenuItem::Help)
424 && cit->status().enabled()) {
430 if (enabled || !i.optional()) {
432 items_.back().status().setEnabled(enabled);
437 case MenuItem::Separator:
438 if (!items_.empty() && items_.back().kind() != MenuItem::Separator)
448 void MenuDefinition::read(Lexer & lex)
466 md_indiceslistscontext,
480 md_spellingsuggestions,
490 LexerKeyword menutags[] = {
491 { "arguments", md_arguments },
492 { "bookmarks", md_bookmarks },
493 { "branches", md_branches },
494 { "captions", md_captions },
495 { "charstyles", md_charstyles },
496 { "citestyles", md_citestyles },
497 { "custom", md_custom },
498 { "documents", md_documents },
499 { "elements", md_elements },
500 { "end", md_endmenu },
501 { "environmentseparators", md_env_separators },
502 { "exportformat", md_exportformat },
503 { "exportformats", md_exportformats },
504 { "floatinsert", md_floatinsert },
505 { "floatlistinsert", md_floatlistinsert },
506 { "graphicsgroups", md_graphicsgroups },
507 { "importformats", md_importformats },
508 { "indices", md_indices },
509 { "indicescontext", md_indicescontext },
510 { "indiceslists", md_indiceslists },
511 { "indiceslistscontext", md_indiceslistscontext },
513 { "languageselector", md_languageselector },
514 { "lastfiles", md_lastfiles },
515 { "optitem", md_optitem },
516 { "optsubmenu", md_optsubmenu },
517 { "pasterecent", md_pasterecent },
518 { "separator", md_separator },
519 { "spellingsuggestions", md_spellingsuggestions },
520 { "submenu", md_submenu },
521 { "switcharguments", md_switcharguments },
522 { "switchcaptions", md_switchcaptions },
523 { "switchquotes", md_switchquotes },
525 { "toolbars", md_toolbars },
526 { "updateformats", md_updateformats },
527 { "viewformats", md_viewformats }
530 lex.pushTable(menutags);
531 lex.setContext("MenuDefinition::read: ");
534 while (lex.isOK() && md_type != md_endmenu) {
535 switch (md_type = lex.lex()) {
539 docstring const name = translateIfPossible(lex.getDocString());
541 string const command = lex.getString();
542 FuncRequest func = lyxaction.lookupFunc(command);
543 FuncRequest::Origin origin = FuncRequest::MENU;
544 if (name_.startsWith("context-toc-"))
545 origin = FuncRequest::TOC;
546 bool const optional = (md_type == md_optitem);
547 add(MenuItem(MenuItem::Command, toqstr(name), func, QString(), optional, origin));
552 add(MenuItem(MenuItem::Separator));
556 add(MenuItem(MenuItem::Lastfiles));
560 add(MenuItem(MenuItem::CharStyles));
564 add(MenuItem(MenuItem::Custom));
568 add(MenuItem(MenuItem::Elements));
572 add(MenuItem(MenuItem::Documents));
576 add(MenuItem(MenuItem::Bookmarks));
580 add(MenuItem(MenuItem::Toc));
584 add(MenuItem(MenuItem::ViewFormats));
587 case md_updateformats:
588 add(MenuItem(MenuItem::UpdateFormats));
591 case md_exportformats:
592 add(MenuItem(MenuItem::ExportFormats));
595 case md_exportformat:
596 add(MenuItem(MenuItem::ExportFormat));
599 case md_importformats:
600 add(MenuItem(MenuItem::ImportFormats));
603 case md_floatlistinsert:
604 add(MenuItem(MenuItem::FloatListInsert));
608 add(MenuItem(MenuItem::FloatInsert));
612 add(MenuItem(MenuItem::PasteRecent));
616 add(MenuItem(MenuItem::Toolbars));
620 add(MenuItem(MenuItem::Branches));
624 add(MenuItem(MenuItem::CiteStyles));
627 case md_graphicsgroups:
628 add(MenuItem(MenuItem::GraphicsGroups));
631 case md_spellingsuggestions:
632 add(MenuItem(MenuItem::SpellingSuggestions));
635 case md_languageselector:
636 add(MenuItem(MenuItem::LanguageSelector));
640 add(MenuItem(MenuItem::Indices));
643 case md_indicescontext:
644 add(MenuItem(MenuItem::IndicesContext));
647 case md_indiceslists:
648 add(MenuItem(MenuItem::IndicesLists));
651 case md_indiceslistscontext:
652 add(MenuItem(MenuItem::IndicesListsContext));
656 add(MenuItem(MenuItem::Arguments));
659 case md_switcharguments:
660 add(MenuItem(MenuItem::SwitchArguments));
664 add(MenuItem(MenuItem::Captions));
667 case md_switchcaptions:
668 add(MenuItem(MenuItem::SwitchCaptions));
671 case md_env_separators:
672 add(MenuItem(MenuItem::EnvironmentSeparators));
675 case md_switchquotes:
676 add(MenuItem(MenuItem::SwitchQuotes));
682 docstring const mlabel = translateIfPossible(lex.getDocString());
684 docstring const mname = lex.getDocString();
685 bool const optional = (md_type == md_optsubmenu);
686 add(MenuItem(MenuItem::Submenu,
687 toqstr(mlabel), toqstr(mname), QString(), optional));
695 lex.printError("Unknown menu tag");
703 bool MenuDefinition::hasFunc(FuncRequest const & func) const
705 for (const_iterator it = begin(), et = end(); it != et; ++it)
706 if (*it->func() == func)
712 void MenuDefinition::catSub(docstring const & name)
714 add(MenuItem(MenuItem::Submenu,
715 qt_("More...|M"), toqstr(name), QString(), false));
718 void MenuDefinition::cat(MenuDefinition const & other)
720 const_iterator et = other.end();
721 for (const_iterator it = other.begin(); it != et; ++it)
726 void MenuDefinition::checkShortcuts() const
728 // This is a quadratic algorithm, but we do not care because
729 // menus are short enough
730 for (const_iterator it1 = begin(); it1 != end(); ++it1) {
731 QString shortcut = it1->shortcut();
732 if (shortcut.isEmpty())
734 if (!it1->label().contains(shortcut))
735 LYXERR0("Menu warning: menu entry \""
737 << "\" does not contain shortcut `"
738 << shortcut << "'.");
739 for (const_iterator it2 = begin(); it2 != it1 ; ++it2) {
740 if (!it2->shortcut().compare(shortcut, Qt::CaseInsensitive)) {
741 LYXERR0("Menu warning: menu entries "
742 << '"' << it1->fulllabel()
743 << "\" and \"" << it2->fulllabel()
744 << "\" share the same shortcut.");
751 bool MenuDefinition::searchMenu(FuncRequest const & func, docstring_list & names) const
753 const_iterator m = begin();
754 const_iterator m_end = end();
755 for (; m != m_end; ++m) {
756 if (m->kind() == MenuItem::Command && *m->func() == func) {
757 names.push_back(qstring_to_ucs4(m->label()));
760 if (m->kind() == MenuItem::Submenu) {
761 names.push_back(qstring_to_ucs4(m->label()));
762 if (!m->hasSubmenu()) {
763 LYXERR(Debug::GUI, "Warning: non existing sub menu label="
764 << m->label() << " name=" << m->submenuname());
768 if (m->submenu().searchMenu(func, names))
777 QString limitStringLength(docstring const & str)
779 size_t const max_item_length = 45;
780 docstring ret = str.substr(0, max_item_length + 1);
781 support::truncateWithEllipsis(ret, max_item_length);
786 void MenuDefinition::expandGraphicsGroups(BufferView const * bv)
791 graphics::getGraphicsGroups(bv->buffer(), grp);
795 set<string>::const_iterator it = grp.begin();
796 set<string>::const_iterator end = grp.end();
797 add(MenuItem(MenuItem::Command, qt_("No Group"),
798 FuncRequest(LFUN_SET_GRAPHICS_GROUP)));
799 for (; it != end; ++it) {
800 addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(*it) + '|',
801 FuncRequest(LFUN_SET_GRAPHICS_GROUP, *it)));
806 void MenuDefinition::expandSpellingSuggestions(BufferView const * bv)
810 Cursor const & cur = bv->cursor();
814 docstring_list suggestions;
815 Paragraph const & par = cur.paragraph();
816 pos_type from = cur.pos();
818 SpellChecker::Result res = par.spellCheck(from, to, wl, suggestions, true, true);
820 case SpellChecker::UNKNOWN_WORD:
821 if (lyxrc.spellcheck_continuously) {
822 LYXERR(Debug::GUI, "Misspelled Word! Suggested Words = ");
823 docstring const & selection = cur.selectionAsString(false);
824 if (!cur.selection() || selection == wl.word()) {
826 size_t m = 10; // first submenu index
827 MenuItem item(MenuItem::Submenu, qt_("More Spelling Suggestions"));
828 item.setSubmenu(MenuDefinition(qt_("More Spelling Suggestions")));
829 for (; i != suggestions.size(); ++i) {
830 docstring const & suggestion = suggestions[i];
831 LYXERR(Debug::GUI, suggestion);
832 MenuItem w(MenuItem::Command, toqstr(suggestion),
833 FuncRequest(LFUN_WORD_REPLACE,
834 replace2string(suggestion, selection,
835 true, // case sensitive
839 false))); // find next
843 item.submenu().add(w);
848 add(MenuItem(MenuItem::Separator));
849 docstring const arg = wl.word() + " " + from_ascii(wl.lang()->lang());
850 add(MenuItem(MenuItem::Command, qt_("Add to personal dictionary|n"),
851 FuncRequest(LFUN_SPELLING_ADD, arg)));
852 add(MenuItem(MenuItem::Command, qt_("Ignore all|I"),
853 FuncRequest(LFUN_SPELLING_IGNORE, arg)));
857 case SpellChecker::LEARNED_WORD: {
858 LYXERR(Debug::GUI, "Learned Word.");
859 docstring const arg = wl.word() + " " + from_ascii(wl.lang()->lang());
860 add(MenuItem(MenuItem::Command, qt_("Remove from personal dictionary|r"),
861 FuncRequest(LFUN_SPELLING_REMOVE, arg)));
864 case SpellChecker::NO_DICTIONARY:
865 LYXERR(Debug::GUI, "No dictionary for language " + from_ascii(wl.lang()->lang()));
867 case SpellChecker::WORD_OK:
868 case SpellChecker::COMPOUND_WORD:
869 case SpellChecker::ROOT_FOUND:
870 case SpellChecker::IGNORED_WORD:
875 struct sortLanguageByName {
876 bool operator()(const Language * a, const Language * b) const {
877 return qt_(a->display()).localeAwareCompare(qt_(b->display())) < 0;
881 void MenuDefinition::expandLanguageSelector(Buffer const * buf)
886 std::set<Language const *> languages_buffer =
887 buf->masterBuffer()->getLanguages();
889 if (languages_buffer.size() < 2)
892 std::set<Language const *, sortLanguageByName> languages;
894 std::set<Language const *>::const_iterator const beg =
895 languages_buffer.begin();
896 for (std::set<Language const *>::const_iterator cit = beg;
897 cit != languages_buffer.end(); ++cit) {
898 languages.insert(*cit);
901 MenuItem item(MenuItem::Submenu, qt_("Language|L"));
902 item.setSubmenu(MenuDefinition(qt_("Language")));
903 QString morelangs = qt_("More Languages ...|M");
904 QStringList accelerators;
905 if (morelangs.contains('|'))
906 accelerators.append(morelangs.section('|', -1));
907 std::set<Language const *, sortLanguageByName>::const_iterator const begin = languages.begin();
908 for (std::set<Language const *, sortLanguageByName>::const_iterator cit = begin;
909 cit != languages.end(); ++cit) {
910 QString label = qt_((*cit)->display());
911 // try to add an accelerator
912 bool success = false;
913 // try capitals first
914 for (int i = 0; i < label.size(); ++i) {
915 QChar const ch = label[i];
918 if (!accelerators.contains(ch, Qt::CaseInsensitive)) {
919 label = label + toqstr("|") + ch;
920 accelerators.append(ch);
925 // if all capitals are taken, try the rest
927 for (int i = 0; i < label.size(); ++i) {
928 if (label[i].isSpace())
930 QString const ch = QString(label[i]);
931 if (!accelerators.contains(ch, Qt::CaseInsensitive)) {
932 label = label + toqstr("|") + ch;
933 accelerators.append(ch);
938 MenuItem w(MenuItem::Command, label,
939 FuncRequest(LFUN_LANGUAGE, (*cit)->lang() + " set"));
940 item.submenu().addWithStatusCheck(w);
942 item.submenu().add(MenuItem(MenuItem::Separator));
943 item.submenu().add(MenuItem(MenuItem::Command, morelangs,
944 FuncRequest(LFUN_DIALOG_SHOW, "character")));
949 void MenuDefinition::expandLastfiles()
951 LastFilesSection::LastFiles const & lf = theSession().lastFiles().lastFiles();
952 LastFilesSection::LastFiles::const_iterator lfit = lf.begin();
956 for (; lfit != lf.end() && ii <= lyxrc.num_lastfiles; ++lfit, ++ii) {
957 string const file = lfit->absFileName();
958 QString const short_path = toqstr(makeDisplayPath(file, 30));
959 QString const long_path = toqstr(makeDisplayPath(file));
962 label = QString("%1. %2|%3").arg(ii).arg(short_path).arg(ii);
964 label = QString("%1. %2").arg(ii).arg(short_path);
965 add(MenuItem(MenuItem::Command, label,
966 FuncRequest(LFUN_FILE_OPEN, file), long_path));
971 void MenuDefinition::expandDocuments()
973 MenuItem item(MenuItem::Submenu, qt_("Hidden|H"));
974 item.setSubmenu(MenuDefinition(qt_("Hidden|H")));
976 Buffer * first = theBufferList().first();
978 add(MenuItem(MenuItem::Info, qt_("<No Documents Open>")));
984 if (!guiApp->currentView())
986 GuiWorkArea * wa = guiApp->currentView()->workArea(i);
989 Buffer const & b = wa->bufferView().buffer();
990 QString label = toqstr(b.fileName().displayName(20));
994 label = QString::number(i) + ". " + label + '|' + QString::number(i);
995 add(MenuItem(MenuItem::Command, label,
996 FuncRequest(LFUN_BUFFER_SWITCH, b.absFileName())));
1003 // We cannot use a for loop as the buffer list cycles.
1005 if (!(guiApp->currentView()
1006 && guiApp->currentView()->workArea(*b))) {
1007 QString label = toqstr(b->fileName().displayName(20));
1011 label = QString::number(i) + ". " + label + '|' + QString::number(i);
1012 item.submenu().add(MenuItem(MenuItem::Command, label,
1013 FuncRequest(LFUN_BUFFER_SWITCH, b->absFileName())));
1016 b = theBufferList().next(b);
1017 } while (b != first);
1019 if (!item.submenu().empty())
1024 void MenuDefinition::expandBookmarks()
1026 lyx::BookmarksSection const & bm = theSession().bookmarks();
1029 for (size_t i = 1; i <= bm.size(); ++i) {
1030 if (bm.isValid(i)) {
1031 string const file = bm.bookmark(i).filename.absFileName();
1032 QString const label = QString("%1. %2|%3").arg(i)
1033 .arg(toqstr(makeDisplayPath(file, 20))).arg(i);
1034 add(MenuItem(MenuItem::Command, label,
1035 FuncRequest(LFUN_BOOKMARK_GOTO, convert<docstring>(i))));
1040 add(MenuItem(MenuItem::Info, qt_("<No Bookmarks Saved Yet>")));
1044 void MenuDefinition::expandFormats(MenuItem::Kind const kind, Buffer const * buf)
1046 if (!buf && kind != MenuItem::ImportFormats)
1050 FuncCode action = LFUN_NOACTION;
1053 case MenuItem::ImportFormats:
1054 formats = theConverters().importableFormats();
1055 action = LFUN_BUFFER_IMPORT;
1057 case MenuItem::ViewFormats:
1058 formats = buf->params().exportableFormats(true);
1059 action = LFUN_BUFFER_VIEW;
1061 case MenuItem::UpdateFormats:
1062 formats = buf->params().exportableFormats(true);
1063 action = LFUN_BUFFER_UPDATE;
1065 case MenuItem::ExportFormats:
1066 formats = buf->params().exportableFormats(false);
1067 action = LFUN_BUFFER_EXPORT;
1074 bool const view_update = (kind == MenuItem::ViewFormats
1075 || kind == MenuItem::UpdateFormats);
1079 smenue = (kind == MenuItem::ViewFormats
1080 ? qt_("View (Other Formats)|F")
1081 : qt_("Update (Other Formats)|p"));
1082 MenuItem item(MenuItem::Submenu, smenue);
1083 item.setSubmenu(MenuDefinition(smenue));
1085 for (Format const * f : formats) {
1089 docstring lab = f->prettyname();
1090 docstring const scut = from_utf8(f->shortcut());
1091 docstring const tmplab = lab;
1094 lab += char_type('|') + scut;
1095 docstring const lab_i18n = translateIfPossible(lab);
1096 docstring const shortcut = split(lab_i18n, lab, '|');
1098 bool const untranslated = (lab == lab_i18n);
1099 docstring label = untranslated ? translateIfPossible(tmplab) : lab;
1102 case MenuItem::ImportFormats:
1103 label += from_ascii("...");
1105 case MenuItem::ViewFormats:
1106 case MenuItem::UpdateFormats:
1107 if (f->name() == buf->params().getDefaultOutputFormat()) {
1108 docstring lbl = (kind == MenuItem::ViewFormats
1109 ? bformat(_("View [%1$s]|V"), label)
1110 : bformat(_("Update [%1$s]|U"), label));
1111 add(MenuItem(MenuItem::Command, toqstr(lbl), FuncRequest(action)));
1115 case MenuItem::ExportFormats:
1116 if (!f->inExportMenu())
1120 // we already asserted earlier in this case
1124 if (!shortcut.empty())
1125 label += '|' + shortcut;
1128 // note that at this point, we know that buf is not null
1130 item.submenu().addWithStatusCheck(MenuItem(MenuItem::Command,
1131 toqstr(label), FuncRequest(action, f->name())));
1134 addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(label),
1135 FuncRequest(action, f->name())));
1137 add(MenuItem(MenuItem::Command, toqstr(label),
1138 FuncRequest(action, f->name())));
1146 void MenuDefinition::expandFloatListInsert(Buffer const * buf)
1151 FloatList const & floats = buf->params().documentClass().floats();
1152 FloatList::const_iterator cit = floats.begin();
1153 FloatList::const_iterator end = floats.end();
1155 for (; cit != end; ++cit) {
1156 if (!cit->second.usesFloatPkg()) {
1157 // Different floats could declare the same ListCommand. We only
1158 // want it on the list once, though.
1159 string const & list_cmd = cit->second.listCommand();
1160 if (list_cmd.empty())
1161 // we do not know how to generate such a list
1163 // This form of insert returns an iterator pointing to the newly
1164 // inserted element OR the existing element with that value, and
1165 // a bool indicating whether we inserted a new element. So we can
1166 // see if one is there and insert it if not all at once.
1167 pair<set<string>::iterator, bool> ret = seen.insert(list_cmd);
1171 string const & list_name = cit->second.listName();
1172 addWithStatusCheck(MenuItem(MenuItem::Command, qt_(list_name),
1173 FuncRequest(LFUN_FLOAT_LIST_INSERT, cit->second.floattype())));
1178 void MenuDefinition::expandFloatInsert(Buffer const * buf)
1183 FloatList const & floats = buf->params().documentClass().floats();
1184 FloatList::const_iterator cit = floats.begin();
1185 FloatList::const_iterator end = floats.end();
1186 for (; cit != end; ++cit) {
1188 QString const label = qt_(cit->second.name());
1189 addWithStatusCheck(MenuItem(MenuItem::Command, label,
1190 FuncRequest(LFUN_FLOAT_INSERT,
1191 cit->second.floattype())));
1196 void MenuDefinition::expandFlexInsert(
1197 Buffer const * buf, InsetLayout::InsetLyXType type)
1202 TextClass::InsetLayouts const & insetLayouts =
1203 buf->params().documentClass().insetLayouts();
1204 TextClass::InsetLayouts::const_iterator cit = insetLayouts.begin();
1205 TextClass::InsetLayouts::const_iterator end = insetLayouts.end();
1206 for (; cit != end; ++cit) {
1207 if (cit->second.lyxtype() == type) {
1208 if (!cit->second.obsoleted_by().empty())
1210 docstring label = cit->first;
1211 // we remove the "Flex:" prefix, if it is present
1212 if (prefixIs(label, from_ascii("Flex:")))
1213 label = label.substr(5);
1214 addWithStatusCheck(MenuItem(MenuItem::Command,
1215 toqstr(translateIfPossible(label)),
1216 FuncRequest(LFUN_FLEX_INSERT, Lexer::quoteString(label))));
1219 // FIXME This is a little clunky.
1220 if (items_.empty() && type == InsetLayout::CUSTOM && !buf->isReadonly())
1221 add(MenuItem(MenuItem::Help, qt_("No Custom Insets Defined!")));
1225 // Threshold before we stop displaying sub-items alongside items
1226 // (for display purposes). Ideally this should fit on a screen.
1227 size_t const max_number_of_items = 30;
1228 // Size limit for the menu. This is for performance purposes,
1229 // because qt already displays a scrollable menu when necessary.
1230 // Ideally this should be the menu size from which scrollable
1231 // menus become unpractical.
1232 size_t const menu_size_limit = 80;
1234 void MenuDefinition::expandToc2(Toc const & toc_list,
1235 size_t from, size_t to, int depth,
1238 int shortcut_count = 0;
1240 // check whether depth is smaller than the smallest depth in toc.
1241 int min_depth = 1000;
1242 for (size_t i = from; i < to; ++i)
1243 min_depth = min(min_depth, toc_list[i].depth());
1244 if (min_depth > depth)
1247 if (to - from <= max_number_of_items) {
1248 for (size_t i = from; i < to; ++i) {
1249 QString label(4 * max(0, toc_list[i].depth() - depth), ' ');
1250 label += limitStringLength(toc_list[i].asString());
1251 if (toc_list[i].depth() == depth) {
1253 if (shortcut_count < 9) {
1254 if (label.contains(QString::number(shortcut_count + 1)))
1255 label += QString::number(++shortcut_count);
1258 add(MenuItem(MenuItem::Command, label,
1259 FuncRequest(toc_list[i].action())));
1260 // separator after the menu heading
1261 if (toc_list[i].depth() < depth)
1262 add(MenuItem(MenuItem::Separator));
1268 size_t new_pos = pos + 1;
1269 while (new_pos < to && toc_list[new_pos].depth() > depth)
1272 QString label(4 * max(0, toc_list[pos].depth() - depth), ' ');
1273 label += limitStringLength(toc_list[pos].asString());
1274 if (toc_list[pos].depth() == depth) {
1276 if (shortcut_count < 9) {
1277 if (label.contains(QString::number(shortcut_count + 1)))
1278 label += QString::number(++shortcut_count);
1281 if (size >= menu_size_limit) {
1282 FuncRequest f(LFUN_DIALOG_SHOW, "toc " + toc_type);
1283 add(MenuItem(MenuItem::Command, "...", f));
1286 if (new_pos == pos + 1) {
1287 add(MenuItem(MenuItem::Command,
1288 label, FuncRequest(toc_list[pos].action())));
1291 sub.expandToc2(toc_list, pos, new_pos, depth + 1, toc_type);
1292 MenuItem item(MenuItem::Submenu, label);
1293 item.setSubmenu(sub);
1303 void MenuDefinition::expandToc(Buffer const * buf)
1305 // To make things very cleanly, we would have to pass buf to
1306 // all MenuItem constructors and to expandToc2. However, we
1307 // know that all the entries in a TOC will be have status_ ==
1308 // OK, so we avoid this unnecessary overhead (JMarc)
1310 add(MenuItem(MenuItem::Info, qt_("(No Document Open)")));
1313 // Add an entry for the master doc if this is a child doc
1314 Buffer const * const master = buf->masterBuffer();
1315 if (buf != master) {
1316 ParIterator const pit = par_iterator_begin(master->inset());
1317 string const arg = convert<string>(pit->id());
1318 FuncRequest f(LFUN_PARAGRAPH_GOTO, arg);
1319 add(MenuItem(MenuItem::Command, qt_("Master Document"), f));
1322 MenuDefinition other_lists;
1323 // In the navigation menu, only add tocs from this document
1324 TocBackend const & backend = buf->tocBackend();
1325 TocList const & toc_list = backend.tocs();
1326 for (pair<string, shared_ptr<Toc>> const & toc : toc_list) {
1327 // Handle table of contents later
1328 if (toc.first == "tableofcontents" || toc.second->empty())
1330 MenuDefinition submenu;
1331 submenu.expandTocSubmenu(toc.first, *toc.second);
1332 docstring const toc_name = backend.outlinerName(toc.first);
1333 MenuItem item(MenuItem::Submenu, toqstr(toc_name));
1334 item.setSubmenu(submenu);
1335 // deserves to be in the main menu?
1336 if (!TocBackend::isOther(toc.first))
1339 other_lists.add(item);
1341 if (!other_lists.empty()) {
1342 MenuItem item(MenuItem::Submenu, qt_("Other Lists"));
1343 item.setSubmenu(other_lists);
1346 // Handle normal TOC
1347 add(MenuItem(MenuItem::Separator));
1348 TocList::const_iterator cit = toc_list.find("tableofcontents");
1349 if (cit == toc_list.end())
1350 LYXERR(Debug::GUI, "No table of contents.");
1352 if (!cit->second->empty())
1353 expandToc2(*cit->second, 0, cit->second->size(), 0,
1356 add(MenuItem(MenuItem::Info, qt_("(Empty Table of Contents)")));
1361 void MenuDefinition::expandTocSubmenu(std::string const & type, Toc const & toc)
1363 // "Open outliner..." entry
1364 FuncRequest f(LFUN_DIALOG_SHOW, "toc " + type);
1365 add(MenuItem(MenuItem::Command, qt_("Open Outliner..."), f));
1366 add(MenuItem(MenuItem::Separator));
1368 expandToc2(toc, 0, toc.size(), 0, type);
1372 void MenuDefinition::expandPasteRecent(Buffer const * buf)
1374 docstring_list const sel = cap::availableSelections(buf);
1376 docstring_list::const_iterator cit = sel.begin();
1377 docstring_list::const_iterator end = sel.end();
1379 for (unsigned int index = 0; cit != end; ++cit, ++index) {
1380 add(MenuItem(MenuItem::Command, toqstr(*cit) + '|',
1381 FuncRequest(LFUN_PASTE, convert<string>(index))));
1386 void MenuDefinition::expandToolbars()
1388 MenuDefinition other_lists;
1389 // extracts the toolbars from the backend
1390 Toolbars::Infos::const_iterator cit = guiApp->toolbars().begin();
1391 Toolbars::Infos::const_iterator end = guiApp->toolbars().end();
1392 for (; cit != end; ++cit) {
1393 MenuItem const item(MenuItem::Command, toqstr(cit->gui_name),
1394 FuncRequest(LFUN_TOOLBAR_TOGGLE, cit->name));
1395 if (guiApp->toolbars().isMainToolbar(cit->name))
1398 other_lists.add(item);
1401 if (!other_lists.empty()) {
1402 MenuItem item(MenuItem::Submenu, qt_("Other Toolbars"));
1403 item.setSubmenu(other_lists);
1409 void MenuDefinition::expandBranches(Buffer const * buf)
1411 if (!buf || buf->isReadonly())
1414 BufferParams const & master_params = buf->masterBuffer()->params();
1415 BufferParams const & params = buf->params();
1416 if (params.branchlist().empty() && master_params.branchlist().empty() ) {
1417 add(MenuItem(MenuItem::Help, qt_("No Branches Set for Document!")));
1421 BranchList::const_iterator cit = master_params.branchlist().begin();
1422 BranchList::const_iterator end = master_params.branchlist().end();
1424 for (int ii = 1; cit != end; ++cit, ++ii) {
1425 docstring label = cit->branch();
1427 label = convert<docstring>(ii) + ". " + label
1428 + char_type('|') + convert<docstring>(ii);
1430 addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(label),
1431 FuncRequest(LFUN_BRANCH_INSERT,
1435 if (buf == buf->masterBuffer())
1438 MenuDefinition child_branches;
1440 BranchList::const_iterator ccit = params.branchlist().begin();
1441 BranchList::const_iterator cend = params.branchlist().end();
1443 for (int ii = 1; ccit != cend; ++ccit, ++ii) {
1444 docstring label = ccit->branch();
1446 label = convert<docstring>(ii) + ". " + label
1447 + char_type('|') + convert<docstring>(ii);
1449 label += char_type('|');
1450 child_branches.addWithStatusCheck(MenuItem(MenuItem::Command,
1452 FuncRequest(LFUN_BRANCH_INSERT,
1456 if (!child_branches.empty()) {
1457 MenuItem item(MenuItem::Submenu, qt_("Child Document"));
1458 item.setSubmenu(child_branches);
1464 void MenuDefinition::expandIndices(Buffer const * buf, bool listof)
1469 BufferParams const & params = buf->masterBuffer()->params();
1470 if (!params.use_indices) {
1472 addWithStatusCheck(MenuItem(MenuItem::Command,
1473 qt_("Index List|I"),
1474 FuncRequest(LFUN_INDEX_PRINT,
1475 from_ascii("idx"))));
1477 addWithStatusCheck(MenuItem(MenuItem::Command,
1478 qt_("Index Entry|d"),
1479 FuncRequest(LFUN_INDEX_INSERT,
1480 from_ascii("idx"))));
1484 if (params.indiceslist().empty())
1487 IndicesList::const_iterator cit = params.indiceslist().begin();
1488 IndicesList::const_iterator end = params.indiceslist().end();
1490 for (int ii = 1; cit != end; ++cit, ++ii) {
1492 docstring const label =
1493 bformat(_("Index: %1$s"), cit->index());
1494 addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(label),
1495 FuncRequest(LFUN_INDEX_PRINT, cit->shortcut())));
1497 docstring const label =
1498 bformat(_("Index Entry (%1$s)"), cit->index());
1499 addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(label),
1500 FuncRequest(LFUN_INDEX_INSERT, cit->shortcut())));
1506 void MenuDefinition::expandIndicesContext(Buffer const * buf, bool listof)
1511 BufferParams const & params = buf->masterBuffer()->params();
1512 if (!params.use_indices || params.indiceslist().empty())
1515 IndicesList::const_iterator cit = params.indiceslist().begin();
1516 IndicesList::const_iterator end = params.indiceslist().end();
1518 for (int ii = 1; cit != end; ++cit, ++ii) {
1520 InsetCommandParams p(INDEX_PRINT_CODE);
1521 p["type"] = cit->shortcut();
1522 string const data = InsetCommand::params2string(p);
1523 addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(cit->index()),
1524 FuncRequest(LFUN_INSET_MODIFY, data)));
1526 docstring const label =
1527 bformat(_("Index Entry (%1$s)"), cit->index());
1528 addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(label),
1529 FuncRequest(LFUN_INSET_MODIFY,
1530 from_ascii("changetype ") + cit->shortcut())));
1536 void MenuDefinition::expandCiteStyles(BufferView const * bv)
1541 Inset const * inset = bv->cursor().nextInset();
1542 if (!inset || inset->lyxCode() != CITE_CODE) {
1543 add(MenuItem(MenuItem::Command,
1544 qt_("No Citation in Scope!"),
1545 FuncRequest(LFUN_NOACTION)));
1548 InsetCitation const * citinset =
1549 static_cast<InsetCitation const *>(inset);
1551 Buffer const * buf = &bv->buffer();
1552 BufferParams const & bp = buf->masterParams();
1553 string const cmd = citinset->params().getCmdName();
1555 docstring const & key = citinset->getParam("key");
1557 add(MenuItem(MenuItem::Command,
1558 qt_("No citations selected!"),
1559 FuncRequest(LFUN_NOACTION)));
1563 size_t const n = cmd.size();
1564 bool const force = isUpperCase(cmd[0]);
1565 bool const star = cmd[n] == '*';
1567 vector<docstring> const keys = getVectorFromString(key);
1569 vector<CitationStyle> const citeStyleList = bp.citeStyles();
1571 CitationStyle cs = citinset->getCitationStyle(bp, cmd, citeStyleList);
1572 bool const qualified = cs.hasQualifiedList
1574 || !citinset->getParam("pretextlist").empty()
1575 || !citinset->getParam("posttextlist").empty());
1576 std::map<docstring, docstring> pres =
1577 citinset->getQualifiedLists(citinset->getParam("pretextlist"));
1578 std::map<docstring, docstring> posts =
1579 citinset->getQualifiedLists(citinset->getParam("posttextlist"));
1582 ci.textBefore = citinset->getParam("before");
1583 ci.textAfter = citinset->getParam("after");
1584 ci.forceUpperCase = force;
1586 ci.context = CiteItem::Dialog;
1588 ci.isQualified = qualified;
1590 ci.posttexts = posts;
1591 vector<docstring> citeStrings =
1592 buf->masterBibInfo().getCiteStrings(keys, citeStyleList, bv->buffer(), ci);
1594 vector<docstring>::const_iterator cit = citeStrings.begin();
1595 vector<docstring>::const_iterator end = citeStrings.end();
1597 for (int ii = 1; cit != end; ++cit, ++ii) {
1598 docstring label = *cit;
1599 CitationStyle cs = citeStyleList[ii - 1];
1600 cs.forceUpperCase &= force;
1601 cs.hasStarredVersion &= star;
1602 addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(label),
1603 FuncRequest(LFUN_INSET_MODIFY,
1604 "changetype " + from_utf8(citationStyleToString(cs)))));
1607 if (cs.hasStarredVersion) {
1608 docstring starred = _("All authors|h");
1609 // Check if we have a custom string/tooltip for the starred version
1610 if (!cs.stardesc.empty()) {
1612 bp.documentClass().getCiteMacro(buf->params().citeEngineType(), cs.stardesc);
1614 starred = translateIfPossible(from_utf8(val));
1615 // Transform qt-style accelerators to menu-style
1616 int const amps = count_char(starred, '&');
1619 starred = subst(starred, from_ascii("&&"), from_ascii("<:amp:>"));
1620 size_t n = starred.find('&');
1621 char_type accel = char_type();
1622 if (n != docstring::npos && n < starred.size() - 1)
1623 accel = starred[n + 1];
1624 starred = subst(starred, from_ascii("&"), from_ascii(""));
1626 starred = subst(starred, from_ascii("<:amp:>"), from_ascii("&&"));
1627 if (accel != char_type())
1628 starred = starred + '|' + accel;
1631 add(MenuItem(MenuItem::Separator));
1632 addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(starred),
1633 FuncRequest(LFUN_INSET_MODIFY, "toggleparam star")));
1636 if (cs.forceUpperCase) {
1637 if (!cs.hasStarredVersion)
1638 add(MenuItem(MenuItem::Separator));
1639 addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(_("Force upper case|u")),
1640 FuncRequest(LFUN_INSET_MODIFY, "toggleparam casing")));
1645 void MenuDefinition::expandArguments(BufferView const * bv, bool switcharg)
1650 if (!bv->cursor().inTexted())
1653 Inset const * inset = &bv->cursor().inset();
1654 Layout::LaTeXArgMap args = bv->cursor().paragraph().layout().args();
1655 if (inset && args.empty())
1656 args = inset->getLayout().args();
1657 if (args.empty() || (switcharg && args.size() == 1))
1659 Layout::LaTeXArgMap::const_iterator lait = args.begin();
1660 Layout::LaTeXArgMap::const_iterator const laend = args.end();
1661 for (; lait != laend; ++lait) {
1662 Layout::latexarg arg = (*lait).second;
1663 docstring str = arg.menustring.empty()? arg.labelstring : arg.menustring;
1664 QString item = toqstr(translateIfPossible(str));
1666 add(MenuItem(MenuItem::Command, item,
1667 FuncRequest(LFUN_INSET_MODIFY,
1668 from_ascii("changetype ")
1669 + from_ascii((*lait).first))));
1671 add(MenuItem(MenuItem::Command, item,
1672 FuncRequest(LFUN_ARGUMENT_INSERT,
1673 from_ascii((*lait).first))));
1678 void MenuDefinition::expandCaptions(Buffer const * buf, bool switchcap)
1683 DocumentClass const & dc = buf->params().documentClass();
1684 vector< pair<docstring, FuncRequest> > caps;
1685 for (pair<docstring, InsetLayout> const & il : dc.insetLayouts()) {
1687 docstring const type = split(il.first, instype, ':');
1688 if (instype == from_ascii("Caption")) {
1689 // skip forbidden caption types
1690 FuncRequest const cmd = switchcap
1691 ? FuncRequest(LFUN_INSET_MODIFY, from_ascii("changetype ") + type)
1692 : FuncRequest(LFUN_CAPTION_INSERT, type);
1693 if (getStatus(cmd).enabled())
1694 caps.push_back(make_pair(type, cmd));
1698 if (caps.empty() || (switchcap && caps.size() == 1))
1700 if (caps.size() == 1) {
1701 add(MenuItem(MenuItem::Command, qt_("Caption"), caps.front().second));
1705 MenuDefinition captions;
1706 for (pair<docstring, FuncRequest> const & cap : caps) {
1707 docstring const type = cap.first;
1708 docstring const trtype = translateIfPossible(type);
1709 docstring const cmitem = bformat(_("Caption (%1$s)"), trtype);
1711 add(MenuItem(MenuItem::Command, toqstr(cmitem), cap.second));
1713 captions.add(MenuItem(MenuItem::Command, toqstr(trtype), cap.second));
1715 if (!captions.empty()) {
1716 MenuItem item(MenuItem::Submenu, qt_("Caption"));
1717 item.setSubmenu(captions);
1723 void MenuDefinition::expandQuotes(BufferView const * bv)
1728 if (!bv->cursor().inTexted())
1731 Inset const * inset = bv->cursor().nextInset();
1732 if (!inset || inset->lyxCode() != QUOTE_CODE) {
1733 add(MenuItem(MenuItem::Command,
1734 qt_("No Quote in Scope!"),
1735 FuncRequest(LFUN_NOACTION)));
1738 InsetQuotes const * qinset =
1739 static_cast<InsetQuotes const *>(inset);
1741 map<string, docstring> styles = quoteparams.getTypes();
1742 string const qtype = qinset->getType();
1744 map<string, docstring>::const_iterator qq = styles.begin();
1745 map<string, docstring>::const_iterator end = styles.end();
1749 BufferParams const & bp = bv->buffer().masterBuffer()->params();
1751 // The global setting
1752 InsetQuotesParams::QuoteStyle globalqs = bp.quotes_style;
1753 char const globalqsc = quoteparams.getStyleChar(globalqs);
1755 // The current language's default
1756 InsetQuotesParams::QuoteStyle langdefqs =
1757 bp.getQuoteStyle(bv->cursor().current_font.language()->quoteStyle());
1758 char const langqs = quoteparams.getStyleChar(langdefqs);
1760 bool main_global_qs = false;
1761 bool main_langdef_qs = false;
1762 bool main_dynamic_qs = false;
1763 docstring const subcmd = from_ascii("changetype ");
1764 docstring const wildcards = from_ascii("..");
1766 // First the top level menu (all glyphs of the current style) ...
1767 // Begin with dynamic (if they are current style),
1768 if (qtype[0] == 'x') {
1769 FuncRequest cmd = FuncRequest(LFUN_INSET_MODIFY, subcmd + from_ascii("xld"));
1770 docstring desc = bformat(_("%1$s (dynamic)"),
1771 quoteparams.getShortGuiLabel(globalqsc + from_ascii("ld")));
1772 add(MenuItem(MenuItem::Command, toqstr(desc), cmd));
1773 cmd = FuncRequest(LFUN_INSET_MODIFY, subcmd + from_ascii("xls"));
1774 desc = bformat(_("%1$s (dynamic)"),
1775 quoteparams.getShortGuiLabel(globalqsc + from_ascii("ls")));
1776 add(MenuItem(MenuItem::Command, toqstr(desc), cmd));
1777 cmd = FuncRequest(LFUN_INSET_MODIFY, subcmd + from_ascii("xrd"));
1778 desc = bformat(_("%1$s (dynamic)"),
1779 quoteparams.getShortGuiLabel(globalqsc + from_ascii("rd")));
1780 add(MenuItem(MenuItem::Command, toqstr(desc), cmd));
1781 cmd = FuncRequest(LFUN_INSET_MODIFY, subcmd + from_ascii("xrs"));
1782 desc = bformat(_("%1$s (dynamic)"),
1783 quoteparams.getShortGuiLabel(globalqsc + from_ascii("rs")));
1784 add(MenuItem(MenuItem::Command, toqstr(desc), cmd));
1785 main_dynamic_qs = true;
1787 // now traverse through the static styles ...
1788 for (; qq != end; ++qq) {
1789 docstring const style = from_ascii(qq->first);
1790 bool langdef = (style[0] == langqs);
1791 bool globaldef = (style[0] == globalqsc);
1793 if (prefixIs(style, qtype[0])) {
1794 FuncRequest cmd = FuncRequest(LFUN_INSET_MODIFY, subcmd + style);
1795 docstring const desc = quoteparams.getShortGuiLabel(style);
1796 add(MenuItem(MenuItem::Command, toqstr(desc), cmd));
1797 main_global_qs = globaldef;
1798 main_langdef_qs = langdef;
1800 else if (!langdef && !globaldef && suffixIs(style, from_ascii("ld"))) {
1801 docstring const desc =
1802 quoteparams.getGuiLabel(quoteparams.getQuoteStyle(to_ascii(style)));
1803 FuncRequest cmd = FuncRequest(LFUN_INSET_MODIFY, subcmd + style[0] + "..");
1804 aqs.add(MenuItem(MenuItem::Command, toqstr(desc), cmd));
1808 add(MenuItem(MenuItem::Separator));
1810 bool display_static = false;
1811 // ... then potentially items to reset to the defaults and to dynamic style ...
1812 if (!main_dynamic_qs && globalqsc != 'x') {
1813 FuncRequest cmd = FuncRequest(LFUN_INSET_MODIFY, subcmd + 'x' + wildcards);
1814 docstring const desc = bformat(_("Use dynamic quotes (%1$s)|d"),
1815 quoteparams.getGuiLabel(globalqs));
1816 add(MenuItem(MenuItem::Command, toqstr(desc), cmd));
1817 display_static = true;
1819 if (!main_global_qs && langdefqs != globalqs) {
1820 docstring const variant = main_dynamic_qs ? _("dynamic[[Quotes]]") : _("static[[Quotes]]");
1821 FuncRequest cmd = FuncRequest(LFUN_INSET_MODIFY, subcmd + globalqsc + wildcards);
1822 docstring const desc = bformat(_("Reset to document default (%1$s, %2$s)|o"),
1823 quoteparams.getGuiLabel(globalqs), variant);
1824 add(MenuItem(MenuItem::Command, toqstr(desc), cmd));
1826 if (!main_langdef_qs) {
1827 FuncRequest cmd = FuncRequest(LFUN_INSET_MODIFY, subcmd + globalqsc + wildcards);
1828 docstring const desc = (main_dynamic_qs || display_static)
1829 ? bformat(_("Reset to language default (%1$s, %2$s)|l"),
1830 quoteparams.getGuiLabel(langdefqs), _("static[[Quotes]]"))
1831 : bformat(_("Reset to language default (%1$s)|l"),
1832 quoteparams.getGuiLabel(langdefqs));
1833 add(MenuItem(MenuItem::Command, toqstr(desc), cmd));
1836 add(MenuItem(MenuItem::Separator));
1838 // ... and a subitem with the rest
1839 MenuItem item(MenuItem::Submenu, qt_("Change Style|y"));
1840 item.setSubmenu(aqs);
1845 void MenuDefinition::expandEnvironmentSeparators(BufferView const * bv)
1849 Text const * text = bv->cursor().text();
1850 // no paragraphs and no separators exist in math
1854 pit_type pit = bv->cursor().selBegin().pit();
1855 Paragraph const & par = text->getPar(pit);
1856 docstring const curlayout = par.layout().name();
1857 docstring outerlayout;
1858 depth_type current_depth = par.params().depth();
1859 // check if we have an environment in our nesting hierarchy
1860 Paragraph cpar = par;
1862 if (pit == 0 || cpar.params().depth() == 0)
1865 cpar = text->getPar(pit);
1866 if (cpar.params().depth() < current_depth
1867 && cpar.layout().isEnvironment()) {
1868 outerlayout = cpar.layout().name();
1869 current_depth = cpar.params().depth();
1872 if (par.layout().isEnvironment()) {
1873 docstring const label =
1874 bformat(_("Start New Environment (%1$s)"),
1875 translateIfPossible(curlayout));
1876 add(MenuItem(MenuItem::Command, toqstr(label),
1877 FuncRequest(LFUN_ENVIRONMENT_SPLIT)));
1879 if (!outerlayout.empty()) {
1880 docstring const label =
1881 bformat(_("Start New Parent Environment (%1$s)"),
1882 translateIfPossible(outerlayout));
1883 add(MenuItem(MenuItem::Command, toqstr(label),
1884 FuncRequest(LFUN_ENVIRONMENT_SPLIT,
1885 from_ascii("outer"))));
1892 /////////////////////////////////////////////////////////////////////
1893 // Menu::Impl definition and implementation
1894 /////////////////////////////////////////////////////////////////////
1898 /// populates the menu or one of its submenu
1899 /// This is used as a recursive function
1900 void populate(QMenu * qMenu, MenuDefinition const & menu);
1902 /// Only needed for top level menus.
1903 MenuDefinition * top_level_menu;
1906 /// the name of this menu
1912 /// Get a MenuDefinition item label from the menu backend
1913 static QString label(MenuItem const & mi)
1915 QString label = mi.label();
1916 label.replace("&", "&&");
1918 QString shortcut = mi.shortcut();
1919 if (!shortcut.isEmpty()) {
1920 int pos = label.indexOf(shortcut);
1922 //label.insert(pos, 1, char_type('&'));
1923 label.replace(pos, 0, "&");
1926 QString const binding = mi.binding();
1927 if (!binding.isEmpty())
1928 label += '\t' + binding;
1933 void Menu::Impl::populate(QMenu * qMenu, MenuDefinition const & menu)
1935 LYXERR(Debug::GUI, "populating menu " << menu.name());
1937 LYXERR(Debug::GUI, "\tERROR: empty menu " << menu.name());
1940 LYXERR(Debug::GUI, " ***** menu entries " << menu.size());
1941 for (MenuItem const & m : menu)
1943 case MenuItem::Separator:
1944 qMenu->addSeparator();
1946 case MenuItem::Submenu: {
1947 QMenu * subMenu = qMenu->addMenu(label(m));
1948 populate(subMenu, m.submenu());
1949 subMenu->setEnabled(!subMenu->isEmpty());
1952 case MenuItem::Command:
1954 // FIXME: A previous comment assured that MenuItem::Command was the
1955 // only possible case in practice, but this is wrong. It would be
1956 // good to document which cases are actually treated here.
1957 qMenu->addAction(new Action(m.func(), QIcon(), label(m),
1958 m.tooltip(), qMenu));
1963 #if (defined(Q_OS_WIN) || defined(Q_CYGWIN_WIN)) && (QT_VERSION >= 0x040600)
1964 class AlwaysMnemonicStyle : public QProxyStyle {
1966 int styleHint(StyleHint hint, const QStyleOption *opt = 0, const QWidget *widget = 0,
1967 QStyleHintReturn *returnData = 0) const
1969 if (hint == QStyle::SH_UnderlineShortcut)
1971 return QProxyStyle::styleHint(hint, opt, widget, returnData);
1976 /////////////////////////////////////////////////////////////////////
1977 // Menu implementation
1978 /////////////////////////////////////////////////////////////////////
1980 Menu::Menu(GuiView * gv, QString const & name, bool top_level, bool keyboard)
1981 : QMenu(gv), d(new Menu::Impl)
1983 #if (defined(Q_OS_WIN) || defined(Q_CYGWIN_WIN)) && (QT_VERSION >= 0x040600)
1985 setStyle(new AlwaysMnemonicStyle);
1989 d->top_level_menu = top_level? new MenuDefinition : 0;
1993 if (d->top_level_menu)
1994 connect(this, SIGNAL(aboutToShow()), this, SLOT(updateView()));
2000 delete d->top_level_menu;
2005 void Menu::updateView()
2007 guiApp->menus().updateMenu(this);
2013 QList<QAction *> items = actions();
2014 for (int i = 0; i != items.size(); ++i) {
2015 // QAction::menu() returns 0 if there's no submenu.
2016 delete items.at(i)->menu();
2022 /////////////////////////////////////////////////////////////////////
2023 // Menus::Impl definition and implementation
2024 /////////////////////////////////////////////////////////////////////
2026 struct Menus::Impl {
2028 bool hasMenu(QString const &) const;
2030 MenuDefinition & getMenu(QString const &);
2032 MenuDefinition const & getMenu(QString const &) const;
2034 /// Expands some special entries of the menu
2035 /** The entries with the following kind are expanded to a
2036 sequence of Command MenuItems: Lastfiles, Documents,
2037 ViewFormats, ExportFormats, UpdateFormats, Branches,
2038 Indices, Arguments, SwitchArguments, Captions, SwitchCaptions,
2039 EnvironmentSeparators
2041 void expand(MenuDefinition const & frommenu, MenuDefinition & tomenu,
2042 BufferView const *) const;
2044 /// Initialize specific MACOS X menubar
2045 void macxMenuBarInit(QMenuBar * qmb);
2047 /// Mac special menu.
2048 /** This defines a menu whose entries list the FuncRequests
2049 that will be removed by expand() in other menus. This is
2050 used by the Qt/Mac code.
2052 NOTE: Qt does not remove the menu items when clearing a QMenuBar,
2053 such that the items will keep accessing the FuncRequests in
2054 the MenuDefinition. While Menus::Impl might be recreated,
2055 we keep mac_special_menu_ in memory by making it static.
2057 static MenuDefinition mac_special_menu_;
2062 MenuDefinition menubar_;
2064 typedef QMap<GuiView *, QHash<QString, Menu*> > NameMap;
2066 /// name to menu for \c menu() method.
2071 MenuDefinition Menus::Impl::mac_special_menu_;
2075 Here is what the Qt documentation says about how a menubar is chosen:
2077 1) If the window has a QMenuBar then it is used. 2) If the window
2078 is a modal then its menubar is used. If no menubar is specified
2079 then a default menubar is used (as documented below) 3) If the
2080 window has no parent then the default menubar is used (as
2083 The above 3 steps are applied all the way up the parent window
2084 chain until one of the above are satisifed. If all else fails a
2085 default menubar will be created, the default menubar on Qt/Mac is
2086 an empty menubar, however you can create a different default
2087 menubar by creating a parentless QMenuBar, the first one created
2088 will thus be designated the default menubar, and will be used
2089 whenever a default menubar is needed.
2091 Thus, for Qt/Mac, we add the menus to a free standing menubar, so
2092 that this menubar will be used also when one of LyX' dialogs has
2095 void Menus::Impl::macxMenuBarInit(QMenuBar * qmb)
2097 /* Since Qt 4.2, the qt/mac menu code has special code for
2098 specifying the role of a menu entry. However, it does not
2099 work very well with our scheme of creating menus on demand,
2100 and therefore we need to put these entries in a special
2101 invisible menu. (JMarc)
2104 /* The entries of our special mac menu. If we add support for
2105 * special entries in Menus, we could imagine something
2107 * SpecialItem About " "About LyX" "dialog-show aboutlyx"
2108 * and therefore avoid hardcoding. I am not sure it is worth
2109 * the hassle, though. (JMarc)
2111 struct MacMenuEntry {
2115 QAction::MenuRole role;
2118 static const MacMenuEntry entries[] = {
2119 {LFUN_DIALOG_SHOW, "aboutlyx", "About LyX",
2120 QAction::AboutRole},
2121 {LFUN_DIALOG_SHOW, "prefs", "Preferences",
2122 QAction::PreferencesRole},
2123 #if !(defined(QT_MAC_USE_COCOA) || (QT_VERSION >= 0x050000))
2124 /* This doesn't work with Cocoa. */
2125 {LFUN_RECONFIGURE, "", "Reconfigure",
2126 QAction::ApplicationSpecificRole},
2128 {LFUN_LYX_QUIT, "", "Quit LyX", QAction::QuitRole}
2130 const size_t num_entries = sizeof(entries) / sizeof(entries[0]);
2131 const bool first_call = mac_special_menu_.empty();
2133 LYXERR(Debug::GUI, "Creating Mac OS X special menu bar");
2134 // the special menu for Menus. Fill it up only once.
2136 for (size_t i = 0 ; i < num_entries ; ++i) {
2137 FuncRequest const func(entries[i].action,
2138 from_utf8(entries[i].arg));
2139 mac_special_menu_.add(MenuItem(MenuItem::Command,
2140 entries[i].label, func));
2144 // add the entries to a QMenu that will eventually be empty
2145 // and therefore invisible.
2146 QMenu * qMenu = qmb->addMenu("special");
2148 for (MenuItem const & m : mac_special_menu_) {
2149 Action * action = new Action(m.func(), QIcon(), m.label(),
2151 action->setMenuRole(entries[i].role);
2152 qMenu->addAction(action);
2158 void Menus::Impl::expand(MenuDefinition const & frommenu,
2159 MenuDefinition & tomenu, BufferView const * bv) const
2161 if (!tomenu.empty())
2164 for (MenuDefinition::const_iterator cit = frommenu.begin();
2165 cit != frommenu.end() ; ++cit) {
2166 Buffer const * buf = bv ? &bv->buffer() : 0;
2167 switch (cit->kind()) {
2168 case MenuItem::Lastfiles:
2169 tomenu.expandLastfiles();
2172 case MenuItem::Documents:
2173 tomenu.expandDocuments();
2176 case MenuItem::Bookmarks:
2177 tomenu.expandBookmarks();
2180 case MenuItem::ImportFormats:
2181 case MenuItem::ViewFormats:
2182 case MenuItem::UpdateFormats:
2183 case MenuItem::ExportFormats:
2184 tomenu.expandFormats(cit->kind(), buf);
2187 case MenuItem::ExportFormat: {
2190 string const format = buf->params().getDefaultOutputFormat();
2191 Format const * f = formats.getFormat(format);
2192 docstring const name = f ? f->prettyname() : from_utf8(format);
2193 docstring const label = bformat(_("Export [%1$s]|E"), name);
2194 MenuItem item(MenuItem::Command, toqstr(label),
2195 FuncRequest(LFUN_BUFFER_EXPORT));
2196 tomenu.addWithStatusCheck(item);
2200 case MenuItem::CharStyles:
2201 tomenu.expandFlexInsert(buf, InsetLayout::CHARSTYLE);
2204 case MenuItem::Custom:
2205 tomenu.expandFlexInsert(buf, InsetLayout::CUSTOM);
2208 case MenuItem::Elements:
2209 tomenu.expandFlexInsert(buf, InsetLayout::ELEMENT);
2212 case MenuItem::FloatListInsert:
2213 tomenu.expandFloatListInsert(buf);
2216 case MenuItem::FloatInsert:
2217 tomenu.expandFloatInsert(buf);
2220 case MenuItem::PasteRecent:
2221 tomenu.expandPasteRecent(buf);
2224 case MenuItem::Toolbars:
2225 tomenu.expandToolbars();
2228 case MenuItem::Branches:
2229 tomenu.expandBranches(buf);
2232 case MenuItem::Indices:
2233 tomenu.expandIndices(buf);
2236 case MenuItem::IndicesContext:
2237 tomenu.expandIndicesContext(buf);
2240 case MenuItem::IndicesLists:
2241 tomenu.expandIndices(buf, true);
2244 case MenuItem::IndicesListsContext:
2245 tomenu.expandIndicesContext(buf, true);
2248 case MenuItem::CiteStyles:
2249 tomenu.expandCiteStyles(bv);
2253 tomenu.expandToc(buf);
2256 case MenuItem::GraphicsGroups:
2257 tomenu.expandGraphicsGroups(bv);
2260 case MenuItem::SpellingSuggestions:
2261 tomenu.expandSpellingSuggestions(bv);
2264 case MenuItem::LanguageSelector:
2265 tomenu.expandLanguageSelector(buf);
2268 case MenuItem::Arguments:
2269 tomenu.expandArguments(bv, false);
2272 case MenuItem::SwitchArguments:
2273 tomenu.expandArguments(bv, true);
2276 case MenuItem::Captions:
2277 tomenu.expandCaptions(buf, false);
2280 case MenuItem::SwitchCaptions:
2281 tomenu.expandCaptions(buf, true);
2284 case MenuItem::EnvironmentSeparators:
2285 tomenu.expandEnvironmentSeparators(bv);
2288 case MenuItem::SwitchQuotes:
2289 tomenu.expandQuotes(bv);
2292 case MenuItem::Submenu: {
2293 MenuItem item(*cit);
2294 item.setSubmenu(MenuDefinition(cit->submenuname()));
2295 expand(getMenu(cit->submenuname()), item.submenu(), bv);
2296 tomenu.addWithStatusCheck(item);
2300 case MenuItem::Info:
2301 case MenuItem::Help:
2302 case MenuItem::Separator:
2303 tomenu.addWithStatusCheck(*cit);
2306 case MenuItem::Command:
2307 if (!mac_special_menu_.hasFunc(*cit->func()))
2308 tomenu.addWithStatusCheck(*cit);
2312 // we do not want the menu to end with a separator
2313 if (!tomenu.empty() && tomenu.items_.back().kind() == MenuItem::Separator)
2314 tomenu.items_.pop_back();
2316 // Check whether the shortcuts are unique
2317 tomenu.checkShortcuts();
2321 bool Menus::Impl::hasMenu(QString const & name) const
2323 return find_if(menulist_.begin(), menulist_.end(),
2324 MenuNamesEqual(name)) != menulist_.end();
2328 MenuDefinition const & Menus::Impl::getMenu(QString const & name) const
2330 const_iterator cit = find_if(menulist_.begin(), menulist_.end(),
2331 MenuNamesEqual(name));
2332 if (cit == menulist_.end()) {
2333 LYXERR0("No submenu named " << name);
2334 LASSERT(false, { static const MenuDefinition m; return m; });
2340 MenuDefinition & Menus::Impl::getMenu(QString const & name)
2342 iterator it = find_if(menulist_.begin(), menulist_.end(),
2343 MenuNamesEqual(name));
2344 if (it == menulist_.end()) {
2345 LYXERR0("No submenu named " << name);
2346 LASSERT(false, { static MenuDefinition m; return m; });
2352 /////////////////////////////////////////////////////////////////////
2356 /////////////////////////////////////////////////////////////////////
2358 Menus::Menus() : d(new Impl) {}
2374 void Menus::read(Lexer & lex)
2382 LexerKeyword menutags[] = {
2383 { "end", md_endmenuset },
2384 { "menu", md_menu },
2385 { "menubar", md_menubar }
2388 // consistency check
2389 if (compare_ascii_no_case(lex.getString(), "menuset"))
2390 LYXERR0("Menus::read: ERROR wrong token: `" << lex.getString() << '\'');
2392 lex.pushTable(menutags);
2393 lex.setContext("Menus::read");
2397 while (lex.isOK() && !quit) {
2398 switch (lex.lex()) {
2400 d->menubar_.read(lex);
2404 QString const name = toqstr(lex.getDocString());
2405 if (d->hasMenu(name))
2406 d->getMenu(name).read(lex);
2408 MenuDefinition menu(name);
2410 d->menulist_.push_back(menu);
2418 lex.printError("Unknown menu tag");
2426 bool Menus::searchMenu(FuncRequest const & func,
2427 docstring_list & names) const
2429 MenuDefinition menu;
2430 d->expand(d->menubar_, menu, 0);
2431 return menu.searchMenu(func, names);
2435 void Menus::fillMenuBar(QMenuBar * qmb, GuiView * view, bool initial)
2439 // setup special mac specific menu items, but only do this
2440 // the first time a QMenuBar is created. Otherwise Qt will
2441 // create duplicate items in the application menu. It seems
2442 // that Qt does not remove them when the QMenubar is cleared.
2443 d->macxMenuBarInit(qmb);
2446 // Clear all menubar contents before filling it.
2448 #if (QT_VERSION >= 0x050000 && defined(Q_OS_MAC))
2449 d->macxMenuBarInit(qmb);
2453 LYXERR(Debug::GUI, "populating menu bar" << d->menubar_.name());
2455 if (d->menubar_.empty()) {
2456 LYXERR(Debug::GUI, "\tERROR: empty menu bar"
2457 << d->menubar_.name());
2460 LYXERR(Debug::GUI, "menu bar entries " << d->menubar_.size());
2462 MenuDefinition menu;
2463 BufferView * bv = 0;
2465 bv = view->currentBufferView();
2466 d->expand(d->menubar_, menu, bv);
2468 MenuDefinition::const_iterator m = menu.begin();
2469 MenuDefinition::const_iterator end = menu.end();
2471 for (; m != end; ++m) {
2473 if (m->kind() != MenuItem::Submenu) {
2474 LYXERR(Debug::GUI, "\tERROR: not a submenu " << m->label());
2478 LYXERR(Debug::GUI, "menu bar item " << m->label()
2479 << " is a submenu named " << m->submenuname());
2481 QString name = m->submenuname();
2482 if (!d->hasMenu(name)) {
2483 LYXERR(Debug::GUI, "\tERROR: " << name
2484 << " submenu has no menu!");
2488 Menu * menu = new Menu(view, m->submenuname(), true);
2489 menu->setTitle(label(*m));
2491 #if defined(Q_OS_MAC) && (defined(QT_MAC_USE_COCOA) || (QT_VERSION >= 0x050000))
2492 // On Mac OS with QT/cocoa, the menu is not displayed if there is no action
2493 // so we create a temporary one here
2494 QAction * action = new QAction(menu);
2495 menu->addAction(action);
2500 d->name_map_[view][name] = menu;
2505 void Menus::updateMenu(Menu * qmenu)
2507 LYXERR(Debug::GUI, "Triggered menu: " << qmenu->d->name);
2510 if (qmenu->d->name.isEmpty())
2513 docstring identifier = qstring_to_ucs4(qmenu->d->name);
2514 MenuDefinition fromLyxMenu(qmenu->d->name);
2515 while (!identifier.empty()) {
2516 docstring menu_name;
2517 identifier = split(identifier, menu_name, ';');
2519 if (!d->hasMenu(toqstr(menu_name))) {
2520 LYXERR(Debug::GUI, "\tWARNING: non existing menu: "
2525 MenuDefinition cat_menu = d->getMenu(toqstr(menu_name));
2526 //FIXME: 50 is a wild guess. We should take into account here
2527 //the expansion of menu items, disabled optional items etc.
2528 bool const in_sub_menu = !fromLyxMenu.empty()
2529 && fromLyxMenu.size() + cat_menu.size() > 50 ;
2531 fromLyxMenu.catSub(menu_name);
2533 fromLyxMenu.cat(cat_menu);
2534 fromLyxMenu.add(MenuItem(MenuItem::Separator));
2537 if (fromLyxMenu.empty()) {
2538 qmenu->addAction(qt_("No Action Defined!"));
2542 BufferView * bv = 0;
2544 bv = qmenu->d->view->currentBufferView();
2545 d->expand(fromLyxMenu, *qmenu->d->top_level_menu, bv);
2546 qmenu->d->populate(qmenu, *qmenu->d->top_level_menu);
2550 Menu * Menus::menu(QString const & name, GuiView & view, bool keyboard)
2552 LYXERR(Debug::GUI, "Context menu requested: " << name);
2553 Menu * menu = d->name_map_[&view].value(name, 0);
2554 if (!menu && !name.startsWith("context-")) {
2555 LYXERR0("requested context menu not found: " << name);
2559 menu = new Menu(&view, name, true, keyboard);
2560 d->name_map_[&view][name] = menu;
2564 } // namespace frontend
2567 #include "moc_Menus.cpp"