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 "qt_helpers.h"
26 #include "BiblioInfo.h"
27 #include "BranchList.h"
29 #include "BufferList.h"
30 #include "BufferParams.h"
31 #include "BufferView.h"
32 #include "Converter.h"
33 #include "CutAndPaste.h"
35 #include "FloatList.h"
37 #include "FuncRequest.h"
38 #include "FuncStatus.h"
39 #include "IndicesList.h"
43 #include "LyXAction.h"
44 #include "LyX.h" // for lastfiles
47 #include "Paragraph.h"
48 #include "ParIterator.h"
50 #include "TextClass.h"
51 #include "TocBackend.h"
53 #include "WordLangTuple.h"
55 #include "insets/Inset.h"
56 #include "insets/InsetCitation.h"
57 #include "insets/InsetGraphics.h"
59 #include "support/lassert.h"
60 #include "support/convert.h"
61 #include "support/debug.h"
62 #include "support/docstring_list.h"
63 #include "support/filetools.h"
64 #include "support/gettext.h"
65 #include "support/lstrings.h"
73 #include <boost/shared_ptr.hpp>
79 using namespace lyx::support;
87 // MacOSX specific stuff is at the end.
94 /// The type of elements that can be in a menu
102 /** This type of item explains why something is unavailable. If this
103 menuitem is in a submenu, the submenu is enabled to make sure the
104 user sees the information. */
106 /** This type of item merely shows that there might be a list or
107 something alike at this position, but the list is still empty.
108 If this item is in a submenu, the submenu will not always be
111 /** This is the list of last opened file,
112 typically for the File menu. */
114 /** This is the list of opened Documents,
115 typically for the Documents menu. */
117 /** This is the bookmarks */
121 /** This is a list of viewable formats
122 typically for the File->View menu. */
124 /** This is a list of updatable formats
125 typically for the File->Update menu. */
127 /** This is a list of exportable formats
128 typically for the File->Export menu. */
130 /** This is a list of importable formats
131 typically for the File->Export menu. */
133 /** This is the list of elements available
134 * for insertion into document. */
136 /** This is the list of user-configurable
137 insets to insert into document */
139 /** This is the list of XML elements to
140 insert into the document */
142 /** This is the list of floats that we can
143 insert a list for. */
145 /** This is the list of floats that we can
148 /** This is the list of selections that can
153 /** Available branches in document */
155 /** Available indices in document */
157 /** Context menu for indices in document */
159 /** Available index lists in document */
161 /** Context menu for available indices lists in document */
163 /** Available citation styles for a given citation */
165 /** Available graphics groups */
167 /// Words suggested by the spellchecker.
169 /** Used Languages */
173 explicit MenuItem(Kind kind) : kind_(kind), optional_(false) {}
176 QString const & label,
177 QString const & submenu = QString(),
178 bool optional = false)
179 : kind_(kind), label_(label), submenuname_(submenu), optional_(optional)
181 LASSERT(kind == Submenu || kind == Help || kind == Info, /**/);
185 QString const & label,
186 FuncRequest const & func,
187 bool optional = false,
188 FuncRequest::Origin origin = FuncRequest::MENU)
189 : kind_(kind), label_(label), func_(func), optional_(optional)
191 func_.origin = origin;
194 // boost::shared_ptr<MenuDefinition> needs this apprently...
197 /// The label of a given menuitem
198 QString label() const { return label_.split('|')[0]; }
200 /// The keyboard shortcut (usually underlined in the entry)
201 QString shortcut() const
203 return label_.contains('|') ? label_.split('|')[1] : QString();
205 /// The complete label, with label and shortcut separated by a '|'
206 QString fulllabel() const { return label_;}
207 /// The kind of entry
208 Kind kind() const { return kind_; }
209 /// the action (if relevant)
210 FuncRequest const & func() const { return func_; }
211 /// returns true if the entry should be omitted when disabled
212 bool optional() const { return optional_; }
213 /// returns the status of the lfun associated with this entry
214 FuncStatus const & status() const { return status_; }
215 /// returns the status of the lfun associated with this entry
216 FuncStatus & status() { return status_; }
217 /// returns the status of the lfun associated with this entry
218 void status(FuncStatus const & status) { status_ = status; }
220 ///returns the binding associated to this action.
221 QString binding() const
223 if (kind_ != Command)
225 // Get the keys bound to this action, but keep only the
227 KeyMap::Bindings bindings = theTopLevelKeymap().findBindings(func_);
229 return toqstr(bindings.begin()->print(KeySequence::ForGui));
231 LYXERR(Debug::KBMAP, "No binding for "
232 << lyxaction.getActionName(func_.action)
233 << '(' << func_.argument() << ')');
237 /// the description of the submenu (if relevant)
238 QString const & submenuname() const { return submenuname_; }
239 /// set the description of the submenu
240 void submenuname(QString const & name) { submenuname_ = name; }
242 bool hasSubmenu() const { return !submenu_.isEmpty(); }
244 MenuDefinition const & submenu() const { return submenu_.at(0); }
245 MenuDefinition & submenu() { return submenu_[0]; }
247 void setSubmenu(MenuDefinition const & menu)
250 submenu_.append(menu);
261 QString submenuname_;
266 /// contains 0 or 1 item.
267 QList<MenuDefinition> submenu_;
271 class MenuDefinition {
274 typedef std::vector<MenuItem> ItemList;
276 typedef ItemList::const_iterator const_iterator;
278 explicit MenuDefinition(QString const & name = QString()) : name_(name) {}
283 QString const & name() const { return name_; }
285 bool empty() const { return items_.empty(); }
286 /// Clear the menu content.
287 void clear() { items_.clear(); }
289 size_t size() const { return items_.size(); }
291 MenuItem const & operator[](size_t) const;
293 const_iterator begin() const { return items_.begin(); }
295 const_iterator end() const { return items_.end(); }
297 // search for func in this menu iteratively, and put menu
299 bool searchMenu(FuncRequest const & func, docstring_list & names)
302 bool hasFunc(FuncRequest const &) const;
303 /// Add the menu item unconditionally
304 void add(MenuItem const & item) { items_.push_back(item); }
305 /// Checks the associated FuncRequest status before adding the
307 void addWithStatusCheck(MenuItem const &);
308 // Check whether the menu shortcuts are unique
309 void checkShortcuts() const;
311 void expandLastfiles();
312 void expandDocuments();
313 void expandBookmarks();
314 void expandFormats(MenuItem::Kind kind, Buffer const * buf);
315 void expandFloatListInsert(Buffer const * buf);
316 void expandFloatInsert(Buffer const * buf);
317 void expandFlexInsert(Buffer const * buf, InsetLayout::InsetLyXType type);
318 void expandToc2(Toc const & toc_list, size_t from, size_t to, int depth);
319 void expandToc(Buffer const * buf);
320 void expandPasteRecent(Buffer const * buf);
321 void expandToolbars();
322 void expandBranches(Buffer const * buf);
323 void expandIndices(Buffer const * buf, bool listof = false);
324 void expandIndicesContext(Buffer const * buf, bool listof = false);
325 void expandCiteStyles(BufferView const *);
326 void expandGraphicsGroups(BufferView const *);
327 void expandSpellingSuggestions(BufferView const *);
328 void expandLanguageSelector(Buffer const * buf);
336 /// Helper for std::find_if
340 MenuNamesEqual(QString const & name) : name_(name) {}
341 bool operator()(MenuDefinition const & menu) const { return menu.name() == name_; }
348 typedef std::vector<MenuDefinition> MenuList;
350 typedef MenuList::const_iterator const_iterator;
352 typedef MenuList::iterator iterator;
354 /////////////////////////////////////////////////////////////////////
355 // MenuDefinition implementation
356 /////////////////////////////////////////////////////////////////////
358 void MenuDefinition::addWithStatusCheck(MenuItem const & i)
362 case MenuItem::Command: {
363 FuncStatus status = lyx::getStatus(i.func());
364 if (status.unknown() || (!status.enabled() && i.optional()))
367 items_.back().status(status);
371 case MenuItem::Submenu: {
372 bool enabled = false;
373 if (i.hasSubmenu()) {
374 for (const_iterator cit = i.submenu().begin();
375 cit != i.submenu().end(); ++cit) {
376 // Only these kind of items affect the status of the submenu
377 if ((cit->kind() == MenuItem::Command
378 || cit->kind() == MenuItem::Submenu
379 || cit->kind() == MenuItem::Help)
380 && cit->status().enabled()) {
386 if (enabled || !i.optional()) {
388 items_.back().status().setEnabled(enabled);
393 case MenuItem::Separator:
394 if (!items_.empty() && items_.back().kind() != MenuItem::Separator)
404 void MenuDefinition::read(Lexer & lex)
421 md_indiceslistscontext,
435 md_spellingsuggestions,
439 LexerKeyword menutags[] = {
440 { "bookmarks", md_bookmarks },
441 { "branches", md_branches },
442 { "charstyles", md_charstyles },
443 { "citestyles", md_citestyles },
444 { "custom", md_custom },
445 { "documents", md_documents },
446 { "elements", md_elements },
447 { "end", md_endmenu },
448 { "exportformats", md_exportformats },
449 { "floatinsert", md_floatinsert },
450 { "floatlistinsert", md_floatlistinsert },
451 { "graphicsgroups", md_graphicsgroups },
452 { "importformats", md_importformats },
453 { "indices", md_indices },
454 { "indicescontext", md_indicescontext },
455 { "indiceslists", md_indiceslists },
456 { "indiceslistscontext", md_indiceslistscontext },
458 { "languageselector", md_languageselector },
459 { "lastfiles", md_lastfiles },
460 { "optitem", md_optitem },
461 { "optsubmenu", md_optsubmenu },
462 { "pasterecent", md_pasterecent },
463 { "separator", md_separator },
464 { "spellingsuggestions", md_spellingsuggestions },
465 { "submenu", md_submenu },
467 { "toolbars", md_toolbars },
468 { "updateformats", md_updateformats },
469 { "viewformats", md_viewformats }
472 lex.pushTable(menutags);
473 lex.setContext("MenuDefinition::read: ");
476 bool optional = false;
478 while (lex.isOK() && !quit) {
482 // fallback to md_item
485 docstring const name = translateIfPossible(lex.getDocString());
487 string const command = lex.getString();
488 FuncRequest func = lyxaction.lookupFunc(command);
489 FuncRequest::Origin origin = FuncRequest::MENU;
490 if (name_.startsWith("context-toc-"))
491 origin = FuncRequest::TOC;
492 add(MenuItem(MenuItem::Command, toqstr(name), func, optional, origin));
498 add(MenuItem(MenuItem::Separator));
502 add(MenuItem(MenuItem::Lastfiles));
506 add(MenuItem(MenuItem::CharStyles));
510 add(MenuItem(MenuItem::Custom));
514 add(MenuItem(MenuItem::Elements));
518 add(MenuItem(MenuItem::Documents));
522 add(MenuItem(MenuItem::Bookmarks));
526 add(MenuItem(MenuItem::Toc));
530 add(MenuItem(MenuItem::ViewFormats));
533 case md_updateformats:
534 add(MenuItem(MenuItem::UpdateFormats));
537 case md_exportformats:
538 add(MenuItem(MenuItem::ExportFormats));
541 case md_importformats:
542 add(MenuItem(MenuItem::ImportFormats));
545 case md_floatlistinsert:
546 add(MenuItem(MenuItem::FloatListInsert));
550 add(MenuItem(MenuItem::FloatInsert));
554 add(MenuItem(MenuItem::PasteRecent));
558 add(MenuItem(MenuItem::Toolbars));
562 add(MenuItem(MenuItem::Branches));
566 add(MenuItem(MenuItem::CiteStyles));
569 case md_graphicsgroups:
570 add(MenuItem(MenuItem::GraphicsGroups));
573 case md_spellingsuggestions:
574 add(MenuItem(MenuItem::SpellingSuggestions));
577 case md_languageselector:
578 add(MenuItem(MenuItem::LanguageSelector));
582 add(MenuItem(MenuItem::Indices));
585 case md_indicescontext:
586 add(MenuItem(MenuItem::IndicesContext));
589 case md_indiceslists:
590 add(MenuItem(MenuItem::IndicesLists));
593 case md_indiceslistscontext:
594 add(MenuItem(MenuItem::IndicesListsContext));
599 // fallback to md_submenu
602 docstring const mlabel = translateIfPossible(lex.getDocString());
604 docstring const mname = lex.getDocString();
605 add(MenuItem(MenuItem::Submenu,
606 toqstr(mlabel), toqstr(mname), optional));
616 lex.printError("Unknown menu tag");
624 MenuItem const & MenuDefinition::operator[](size_type i) const
630 bool MenuDefinition::hasFunc(FuncRequest const & func) const
632 for (const_iterator it = begin(), et = end(); it != et; ++it)
633 if (it->func() == func)
639 void MenuDefinition::checkShortcuts() const
641 // This is a quadratic algorithm, but we do not care because
642 // menus are short enough
643 for (const_iterator it1 = begin(); it1 != end(); ++it1) {
644 QString shortcut = it1->shortcut();
645 if (shortcut.isEmpty())
647 if (!it1->label().contains(shortcut))
648 LYXERR0("Menu warning: menu entry \""
650 << "\" does not contain shortcut `"
651 << shortcut << "'.");
652 for (const_iterator it2 = begin(); it2 != it1 ; ++it2) {
653 if (!it2->shortcut().compare(shortcut, Qt::CaseInsensitive)) {
654 LYXERR0("Menu warning: menu entries "
655 << '"' << it1->fulllabel()
656 << "\" and \"" << it2->fulllabel()
657 << "\" share the same shortcut.");
664 bool MenuDefinition::searchMenu(FuncRequest const & func, docstring_list & names) const
666 const_iterator m = begin();
667 const_iterator m_end = end();
668 for (; m != m_end; ++m) {
669 if (m->kind() == MenuItem::Command && m->func() == func) {
670 names.push_back(qstring_to_ucs4(m->label()));
673 if (m->kind() == MenuItem::Submenu) {
674 names.push_back(qstring_to_ucs4(m->label()));
675 if (!m->hasSubmenu()) {
676 LYXERR(Debug::GUI, "Warning: non existing sub menu label="
677 << m->label() << " name=" << m->submenuname());
681 if (m->submenu().searchMenu(func, names))
690 bool compareFormat(Format const * p1, Format const * p2)
696 QString limitStringLength(docstring const & str)
698 size_t const max_item_length = 45;
700 if (str.size() > max_item_length)
701 return toqstr(str.substr(0, max_item_length - 3) + "...");
707 void MenuDefinition::expandGraphicsGroups(BufferView const * bv)
712 graphics::getGraphicsGroups(bv->buffer(), grp);
716 set<string>::const_iterator it = grp.begin();
717 set<string>::const_iterator end = grp.end();
718 add(MenuItem(MenuItem::Command, qt_("No Group"),
719 FuncRequest(LFUN_SET_GRAPHICS_GROUP)));
720 for (; it != end; it++) {
721 addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(*it),
722 FuncRequest(LFUN_SET_GRAPHICS_GROUP, *it)));
727 void MenuDefinition::expandSpellingSuggestions(BufferView const * bv)
732 docstring_list suggestions;
733 pos_type from = bv->cursor().pos();
735 Paragraph const & par = bv->cursor().paragraph();
736 if (!par.spellCheck(from, to, wl, suggestions))
738 LYXERR(Debug::GUI, "Misspelled Word! Suggested Words = ");
740 MenuItem item(MenuItem::Submenu, qt_("More Spelling Suggestions"));
741 item.setSubmenu(MenuDefinition(qt_("More Spelling Suggestions")));
742 for (; i != suggestions.size(); ++i) {
743 docstring const & suggestion = suggestions[i];
744 LYXERR(Debug::GUI, suggestion);
745 MenuItem w(MenuItem::Command, toqstr(suggestion),
746 FuncRequest(LFUN_WORD_REPLACE, suggestion));
750 item.submenu().add(w);
755 add(MenuItem(MenuItem::Separator));
756 docstring const arg = wl.word() + " " + from_ascii(wl.lang()->lang());
757 add(MenuItem(MenuItem::Command, qt_("Add to personal dictionary|c"),
758 FuncRequest(LFUN_SPELLING_ADD, arg)));
759 add(MenuItem(MenuItem::Command, qt_("Ignore all|I"),
760 FuncRequest(LFUN_SPELLING_IGNORE, arg)));
765 void MenuDefinition::expandLanguageSelector(Buffer const * buf)
770 std::set<Language const *> languages =
771 buf->masterBuffer()->getLanguages();
773 if (languages.size() < 2) {
774 add(MenuItem(MenuItem::Command, qt_("Language ...|L"),
775 FuncRequest(LFUN_DIALOG_SHOW, "character")));
779 MenuItem item(MenuItem::Submenu, qt_("Language|L"));
780 item.setSubmenu(MenuDefinition(qt_("Language")));
781 std::set<Language const *>::const_iterator const begin = languages.begin();
782 for (std::set<Language const *>::const_iterator cit = begin;
783 cit != languages.end(); ++cit) {
784 MenuItem w(MenuItem::Command, qt_((*cit)->display()),
785 FuncRequest(LFUN_LANGUAGE, (*cit)->lang()));
786 item.submenu().addWithStatusCheck(w);
788 item.submenu().add(MenuItem(MenuItem::Separator));
789 item.submenu().add(MenuItem(MenuItem::Command, qt_("More Languages ..."),
790 FuncRequest(LFUN_DIALOG_SHOW, "character")));
795 void MenuDefinition::expandLastfiles()
797 LastFilesSection::LastFiles const & lf = theSession().lastFiles().lastFiles();
798 LastFilesSection::LastFiles::const_iterator lfit = lf.begin();
802 for (; lfit != lf.end() && ii <= lyxrc.num_lastfiles; ++lfit, ++ii) {
803 string const file = lfit->absFilename();
806 label = QString("%1. %2|%3").arg(ii)
807 .arg(toqstr(makeDisplayPath(file, 30))).arg(ii);
809 label = QString("%1. %2").arg(ii)
810 .arg(toqstr(makeDisplayPath(file, 30)));
811 add(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_FILE_OPEN, file)));
816 void MenuDefinition::expandDocuments()
818 MenuItem item(MenuItem::Submenu, qt_("Invisible"));
819 item.setSubmenu(MenuDefinition(qt_("Invisible")));
821 Buffer * first = theBufferList().first();
827 // We cannot use a for loop as the buffer list cycles.
829 QString label = toqstr(b->fileName().displayName(20));
832 bool const shown = guiApp->currentView()
833 ? guiApp->currentView()->workArea(*b) : false;
834 int ii = shown ? vis : invis;
836 label = QString::number(ii) + ". " + label + '|' + QString::number(ii);
838 add(MenuItem(MenuItem::Command, label,
839 FuncRequest(LFUN_BUFFER_SWITCH, b->absFileName())));
842 item.submenu().add(MenuItem(MenuItem::Command, label,
843 FuncRequest(LFUN_BUFFER_SWITCH, b->absFileName())));
846 b = theBufferList().next(b);
847 } while (b != first);
848 if (!item.submenu().empty())
851 add(MenuItem(MenuItem::Info, qt_("<No Documents Open>")));
855 void MenuDefinition::expandBookmarks()
857 lyx::BookmarksSection const & bm = theSession().bookmarks();
860 for (size_t i = 1; i <= bm.size(); ++i) {
862 string const file = bm.bookmark(i).filename.absFilename();
863 QString const label = QString("%1. %2|%3").arg(i)
864 .arg(toqstr(makeDisplayPath(file, 20))).arg(i);
865 add(MenuItem(MenuItem::Command, label,
866 FuncRequest(LFUN_BOOKMARK_GOTO, convert<docstring>(i))));
871 add(MenuItem(MenuItem::Info, qt_("<No Bookmarks Saved Yet>")));
875 void MenuDefinition::expandFormats(MenuItem::Kind kind, Buffer const * buf)
877 if (!buf && kind != MenuItem::ImportFormats)
880 typedef vector<Format const *> Formats;
885 case MenuItem::ImportFormats:
886 formats = theConverters().importableFormats();
887 action = LFUN_BUFFER_IMPORT;
889 case MenuItem::ViewFormats:
890 formats = buf->exportableFormats(true);
891 action = LFUN_BUFFER_VIEW;
893 case MenuItem::UpdateFormats:
894 formats = buf->exportableFormats(true);
895 action = LFUN_BUFFER_UPDATE;
898 formats = buf->exportableFormats(false);
899 action = LFUN_BUFFER_EXPORT;
901 sort(formats.begin(), formats.end(), &compareFormat);
903 bool const view_update = (kind == MenuItem::ViewFormats
904 || kind == MenuItem::UpdateFormats);
908 smenue = (kind == MenuItem::ViewFormats ?
909 qt_("View (Other Formats)|F")
910 : qt_("Update (Other Formats)|p"));
911 MenuItem item(MenuItem::Submenu, smenue);
912 item.setSubmenu(MenuDefinition(smenue));
914 Formats::const_iterator fit = formats.begin();
915 Formats::const_iterator end = formats.end();
916 for (; fit != end ; ++fit) {
920 docstring lab = from_utf8((*fit)->prettyname());
921 docstring scut = from_utf8((*fit)->shortcut());
922 docstring const tmplab = lab;
925 lab += char_type('|') + scut;
926 docstring lab_i18n = translateIfPossible(lab);
927 bool const untranslated = (lab == lab_i18n);
928 QString const shortcut = toqstr(split(lab_i18n, lab, '|'));
929 QString label = toqstr(lab);
931 // this might happen if the shortcut
932 // has been redefined
933 label = toqstr(translateIfPossible(tmplab));
936 case MenuItem::ImportFormats:
939 case MenuItem::ViewFormats:
940 case MenuItem::UpdateFormats:
941 if ((*fit)->name() == buf->getDefaultOutputFormat()) {
942 docstring lbl = (kind == MenuItem::ViewFormats ?
943 bformat(_("View [%1$s]|V"), qstring_to_ucs4(label))
944 : bformat(_("Update [%1$s]|U"), qstring_to_ucs4(label)));
945 MenuItem w(MenuItem::Command, toqstr(lbl),
946 FuncRequest(action, (*fit)->name()));
950 case MenuItem::ExportFormats:
951 if (!(*fit)->documentFormat())
955 LASSERT(false, /**/);
958 if (!shortcut.isEmpty())
959 label += '|' + shortcut;
963 item.submenu().addWithStatusCheck(MenuItem(MenuItem::Command, label,
964 FuncRequest(action, (*fit)->name())));
966 item.submenu().add(MenuItem(MenuItem::Command, label,
967 FuncRequest(action, (*fit)->name())));
970 addWithStatusCheck(MenuItem(MenuItem::Command, label,
971 FuncRequest(action, (*fit)->name())));
973 add(MenuItem(MenuItem::Command, label,
974 FuncRequest(action, (*fit)->name())));
982 void MenuDefinition::expandFloatListInsert(Buffer const * buf)
987 FloatList const & floats = buf->params().documentClass().floats();
988 FloatList::const_iterator cit = floats.begin();
989 FloatList::const_iterator end = floats.end();
990 for (; cit != end; ++cit) {
991 addWithStatusCheck(MenuItem(MenuItem::Command,
992 qt_(cit->second.listName()),
993 FuncRequest(LFUN_FLOAT_LIST_INSERT,
994 cit->second.type())));
999 void MenuDefinition::expandFloatInsert(Buffer const * buf)
1004 FloatList const & floats = buf->params().documentClass().floats();
1005 FloatList::const_iterator cit = floats.begin();
1006 FloatList::const_iterator end = floats.end();
1007 for (; cit != end; ++cit) {
1009 QString const label = qt_(cit->second.name());
1010 addWithStatusCheck(MenuItem(MenuItem::Command, label,
1011 FuncRequest(LFUN_FLOAT_INSERT,
1012 cit->second.type())));
1017 void MenuDefinition::expandFlexInsert(
1018 Buffer const * buf, InsetLayout::InsetLyXType type)
1023 TextClass::InsetLayouts const & insetLayouts =
1024 buf->params().documentClass().insetLayouts();
1025 TextClass::InsetLayouts::const_iterator cit = insetLayouts.begin();
1026 TextClass::InsetLayouts::const_iterator end = insetLayouts.end();
1027 for (; cit != end; ++cit) {
1028 if (cit->second.lyxtype() == type) {
1029 docstring const label = cit->first;
1030 addWithStatusCheck(MenuItem(MenuItem::Command,
1031 toqstr(translateIfPossible(label)),
1032 FuncRequest(LFUN_FLEX_INSERT, Lexer::quoteString(label))));
1035 // FIXME This is a little clunky.
1036 if (items_.empty() && type == InsetLayout::CUSTOM)
1037 add(MenuItem(MenuItem::Help, qt_("No Custom Insets Defined!")));
1041 size_t const max_number_of_items = 25;
1043 void MenuDefinition::expandToc2(Toc const & toc_list,
1044 size_t from, size_t to, int depth)
1046 int shortcut_count = 0;
1048 // check whether depth is smaller than the smallest depth in toc.
1049 int min_depth = 1000;
1050 for (size_t i = from; i < to; ++i)
1051 min_depth = min(min_depth, toc_list[i].depth());
1052 if (min_depth > depth)
1055 if (to - from <= max_number_of_items) {
1056 for (size_t i = from; i < to; ++i) {
1057 QString label(4 * max(0, toc_list[i].depth() - depth), ' ');
1058 label += limitStringLength(toc_list[i].str());
1059 if (toc_list[i].depth() == depth
1060 && shortcut_count < 9) {
1061 if (label.contains(QString::number(shortcut_count + 1)))
1062 label += '|' + QString::number(++shortcut_count);
1064 add(MenuItem(MenuItem::Command, label,
1065 FuncRequest(toc_list[i].action())));
1070 size_t new_pos = pos + 1;
1071 while (new_pos < to && toc_list[new_pos].depth() > depth)
1074 QString label(4 * max(0, toc_list[pos].depth() - depth), ' ');
1075 label += limitStringLength(toc_list[pos].str());
1076 if (toc_list[pos].depth() == depth &&
1077 shortcut_count < 9) {
1078 if (label.contains(QString::number(shortcut_count + 1)))
1079 label += '|' + QString::number(++shortcut_count);
1081 if (new_pos == pos + 1) {
1082 add(MenuItem(MenuItem::Command,
1083 label, FuncRequest(toc_list[pos].action())));
1086 sub.expandToc2(toc_list, pos, new_pos, depth + 1);
1087 MenuItem item(MenuItem::Submenu, label);
1088 item.setSubmenu(sub);
1097 void MenuDefinition::expandToc(Buffer const * buf)
1099 // To make things very cleanly, we would have to pass buf to
1100 // all MenuItem constructors and to expandToc2. However, we
1101 // know that all the entries in a TOC will be have status_ ==
1102 // OK, so we avoid this unnecessary overhead (JMarc)
1105 add(MenuItem(MenuItem::Info, qt_("<No Document Open>")));
1109 // Add an entry for the master doc if this is a child doc
1110 Buffer const * const master = buf->masterBuffer();
1111 if (buf != master) {
1112 ParIterator const pit = par_iterator_begin(master->inset());
1113 string const arg = convert<string>(pit->id());
1114 FuncRequest f(LFUN_PARAGRAPH_GOTO, arg);
1115 add(MenuItem(MenuItem::Command, qt_("Master Document"), f));
1118 MenuDefinition other_lists;
1120 FloatList const & floatlist = buf->params().documentClass().floats();
1121 TocList const & toc_list = buf->tocBackend().tocs();
1122 TocList::const_iterator cit = toc_list.begin();
1123 TocList::const_iterator end = toc_list.end();
1124 for (; cit != end; ++cit) {
1125 // Handle this later
1126 if (cit->first == "tableofcontents")
1129 MenuDefinition submenu;
1130 if (cit->second.size() >= 30) {
1131 FuncRequest f(LFUN_DIALOG_SHOW, "toc " + cit->first);
1132 submenu.add(MenuItem(MenuItem::Command, qt_("Open Navigator..."), f));
1134 TocIterator ccit = cit->second.begin();
1135 TocIterator eend = cit->second.end();
1136 for (; ccit != eend; ++ccit) {
1137 submenu.add(MenuItem(MenuItem::Command,
1138 limitStringLength(ccit->str()),
1139 FuncRequest(ccit->action())));
1143 MenuItem item(MenuItem::Submenu, guiName(cit->first, buf->params()));
1144 item.setSubmenu(submenu);
1145 if (floatlist.typeExist(cit->first) || cit->first == "child") {
1146 // Those two types deserve to be in the main menu.
1147 item.setSubmenu(submenu);
1150 other_lists.add(item);
1152 if (!other_lists.empty()) {
1153 MenuItem item(MenuItem::Submenu, qt_("Other Lists"));
1154 item.setSubmenu(other_lists);
1158 // Handle normal TOC
1159 cit = toc_list.find("tableofcontents");
1161 LYXERR(Debug::GUI, "No table of contents.");
1163 if (cit->second.size() > 0 )
1164 expandToc2(cit->second, 0, cit->second.size(), 0);
1166 add(MenuItem(MenuItem::Info, qt_("<Empty Table of Contents>")));
1171 void MenuDefinition::expandPasteRecent(Buffer const * buf)
1173 docstring_list const sel = cap::availableSelections(buf);
1175 docstring_list::const_iterator cit = sel.begin();
1176 docstring_list::const_iterator end = sel.end();
1178 for (unsigned int index = 0; cit != end; ++cit, ++index) {
1179 add(MenuItem(MenuItem::Command, toqstr(*cit),
1180 FuncRequest(LFUN_PASTE, convert<string>(index))));
1185 void MenuDefinition::expandToolbars()
1187 MenuDefinition other_lists;
1188 // extracts the toolbars from the backend
1189 Toolbars::Infos::const_iterator cit = guiApp->toolbars().begin();
1190 Toolbars::Infos::const_iterator end = guiApp->toolbars().end();
1191 for (; cit != end; ++cit) {
1192 MenuItem const item(MenuItem::Command, toqstr(cit->gui_name),
1193 FuncRequest(LFUN_TOOLBAR_TOGGLE, cit->name));
1194 if (guiApp->toolbars().isMainToolbar(cit->name))
1197 other_lists.add(item);
1200 if (!other_lists.empty()) {
1201 MenuItem item(MenuItem::Submenu, qt_("Other Toolbars"));
1202 item.setSubmenu(other_lists);
1208 void MenuDefinition::expandBranches(Buffer const * buf)
1213 BufferParams const & master_params = buf->masterBuffer()->params();
1214 BufferParams const & params = buf->params();
1215 if (params.branchlist().empty() && master_params.branchlist().empty() ) {
1216 add(MenuItem(MenuItem::Help, qt_("No Branches Set for Document!")));
1220 BranchList::const_iterator cit = master_params.branchlist().begin();
1221 BranchList::const_iterator end = master_params.branchlist().end();
1223 for (int ii = 1; cit != end; ++cit, ++ii) {
1224 docstring label = cit->branch();
1226 label = convert<docstring>(ii) + ". " + label
1227 + char_type('|') + convert<docstring>(ii);
1229 addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(label),
1230 FuncRequest(LFUN_BRANCH_INSERT,
1234 if (buf == buf->masterBuffer())
1237 MenuDefinition child_branches;
1239 BranchList::const_iterator ccit = params.branchlist().begin();
1240 BranchList::const_iterator cend = params.branchlist().end();
1242 for (int ii = 1; ccit != cend; ++ccit, ++ii) {
1243 docstring label = ccit->branch();
1245 label = convert<docstring>(ii) + ". " + label
1246 + char_type('|') + convert<docstring>(ii);
1248 child_branches.addWithStatusCheck(MenuItem(MenuItem::Command,
1250 FuncRequest(LFUN_BRANCH_INSERT,
1254 if (!child_branches.empty()) {
1255 MenuItem item(MenuItem::Submenu, qt_("Child Document"));
1256 item.setSubmenu(child_branches);
1262 void MenuDefinition::expandIndices(Buffer const * buf, bool listof)
1267 BufferParams const & params = buf->masterBuffer()->params();
1268 if (!params.use_indices) {
1270 addWithStatusCheck(MenuItem(MenuItem::Command,
1271 qt_("Index List|I"),
1272 FuncRequest(LFUN_INDEX_PRINT,
1273 from_ascii("idx"))));
1275 addWithStatusCheck(MenuItem(MenuItem::Command,
1276 qt_("Index Entry|d"),
1277 FuncRequest(LFUN_INDEX_INSERT,
1278 from_ascii("idx"))));
1282 if (params.indiceslist().empty())
1285 IndicesList::const_iterator cit = params.indiceslist().begin();
1286 IndicesList::const_iterator end = params.indiceslist().end();
1288 for (int ii = 1; cit != end; ++cit, ++ii) {
1290 addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(cit->index()),
1291 FuncRequest(LFUN_INDEX_PRINT,
1294 docstring label = _("Index Entry");
1295 label += " (" + cit->index() + ")";
1296 addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(label),
1297 FuncRequest(LFUN_INDEX_INSERT,
1304 void MenuDefinition::expandIndicesContext(Buffer const * buf, bool listof)
1309 BufferParams const & params = buf->masterBuffer()->params();
1310 if (!params.use_indices || params.indiceslist().empty())
1313 IndicesList::const_iterator cit = params.indiceslist().begin();
1314 IndicesList::const_iterator end = params.indiceslist().end();
1316 for (int ii = 1; cit != end; ++cit, ++ii) {
1318 InsetCommandParams p(INDEX_PRINT_CODE);
1319 p["type"] = cit->shortcut();
1320 string const data = InsetCommand::params2string("index_print", p);
1321 addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(cit->index()),
1322 FuncRequest(LFUN_INSET_MODIFY, data)));
1324 docstring label = _("Index Entry");
1325 label += " (" + cit->index() + ")";
1326 addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(label),
1327 FuncRequest(LFUN_INSET_MODIFY,
1328 from_ascii("changetype ") + cit->shortcut())));
1334 void MenuDefinition::expandCiteStyles(BufferView const * bv)
1339 Inset const * inset = bv->cursor().nextInset();
1340 if (!inset || inset->lyxCode() != CITE_CODE) {
1341 add(MenuItem(MenuItem::Command,
1342 qt_("No Citation in Scope!"),
1343 FuncRequest(LFUN_NOACTION)));
1346 InsetCommand const * citinset =
1347 static_cast<InsetCommand const *>(inset);
1349 Buffer const * buf = &bv->buffer();
1350 docstring key = citinset->getParam("key");
1351 // we can only handle one key currently
1352 if (contains(key, ','))
1353 key = qstring_to_ucs4(toqstr(key).split(',')[0]);
1355 vector<CiteStyle> citeStyleList = citeStyles(buf->params().citeEngine());
1356 docstring_list citeStrings =
1357 buf->masterBibInfo().getCiteStrings(key, bv->buffer());
1359 docstring_list::const_iterator cit = citeStrings.begin();
1360 docstring_list::const_iterator end = citeStrings.end();
1362 for (int ii = 1; cit != end; ++cit, ++ii) {
1363 docstring label = *cit;
1365 CiteStyle cst = citeStyleList[ii - 1];
1367 addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(label),
1368 FuncRequest(LFUN_INSET_MODIFY,
1369 "changetype " + from_utf8(citationStyleToString(cs)))));
1376 /////////////////////////////////////////////////////////////////////
1377 // Menu::Impl definition and implementation
1378 /////////////////////////////////////////////////////////////////////
1382 /// populates the menu or one of its submenu
1383 /// This is used as a recursive function
1384 void populate(QMenu & qMenu, MenuDefinition const & menu);
1386 /// Only needed for top level menus.
1387 MenuDefinition * top_level_menu;
1390 /// the name of this menu
1396 /// Get a MenuDefinition item label from the menu backend
1397 static QString label(MenuItem const & mi)
1399 QString label = mi.label();
1400 label.replace("&", "&&");
1402 QString shortcut = mi.shortcut();
1403 if (!shortcut.isEmpty()) {
1404 int pos = label.indexOf(shortcut);
1406 //label.insert(pos, 1, char_type('&'));
1407 label.replace(pos, 0, "&");
1410 QString const binding = mi.binding();
1411 if (!binding.isEmpty())
1412 label += '\t' + binding;
1417 void Menu::Impl::populate(QMenu & qMenu, MenuDefinition const & menu)
1419 LYXERR(Debug::GUI, "populating menu " << menu.name());
1420 if (menu.size() == 0) {
1421 LYXERR(Debug::GUI, "\tERROR: empty menu " << menu.name());
1424 LYXERR(Debug::GUI, " ***** menu entries " << menu.size());
1425 MenuDefinition::const_iterator m = menu.begin();
1426 MenuDefinition::const_iterator end = menu.end();
1427 for (; m != end; ++m) {
1428 if (m->kind() == MenuItem::Separator)
1429 qMenu.addSeparator();
1430 else if (m->kind() == MenuItem::Submenu) {
1431 QMenu * subMenu = qMenu.addMenu(label(*m));
1432 populate(*subMenu, m->submenu());
1433 subMenu->setEnabled(m->status().enabled());
1435 // we have a MenuItem::Command
1436 qMenu.addAction(new Action(view, QIcon(), label(*m),
1437 m->func(), QString(), &qMenu));
1442 /////////////////////////////////////////////////////////////////////
1443 // Menu implementation
1444 /////////////////////////////////////////////////////////////////////
1446 Menu::Menu(GuiView * gv, QString const & name, bool top_level)
1447 : QMenu(gv), d(new Menu::Impl)
1449 d->top_level_menu = top_level? new MenuDefinition : 0;
1453 if (d->top_level_menu)
1454 connect(this, SIGNAL(aboutToShow()), this, SLOT(updateView()));
1460 delete d->top_level_menu;
1465 void Menu::updateView()
1467 guiApp->menus().updateMenu(this);
1471 /////////////////////////////////////////////////////////////////////
1472 // Menus::Impl definition and implementation
1473 /////////////////////////////////////////////////////////////////////
1475 struct Menus::Impl {
1477 bool hasMenu(QString const &) const;
1479 MenuDefinition & getMenu(QString const &);
1481 MenuDefinition const & getMenu(QString const &) const;
1483 /// Expands some special entries of the menu
1484 /** The entries with the following kind are expanded to a
1485 sequence of Command MenuItems: Lastfiles, Documents,
1486 ViewFormats, ExportFormats, UpdateFormats, Branches, Indices
1488 void expand(MenuDefinition const & frommenu, MenuDefinition & tomenu,
1489 BufferView const *) const;
1491 /// Initialize specific MACOS X menubar
1492 void macxMenuBarInit(GuiView * view, QMenuBar * qmb);
1494 /// Mac special menu.
1495 /** This defines a menu whose entries list the FuncRequests
1496 that will be removed by expand() in other menus. This is
1497 used by the Qt/Mac code.
1499 NOTE: Qt does not remove the menu items when clearing a QMenuBar,
1500 such that the items will keep accessing the FuncRequests in
1501 the MenuDefinition. While Menus::Impl might be recreated,
1502 we keep mac_special_menu_ in memory by making it static.
1504 static MenuDefinition mac_special_menu_;
1509 MenuDefinition menubar_;
1511 typedef QMap<GuiView *, QHash<QString, Menu*> > NameMap;
1513 /// name to menu for \c menu() method.
1518 MenuDefinition Menus::Impl::mac_special_menu_;
1522 Here is what the Qt documentation says about how a menubar is chosen:
1524 1) If the window has a QMenuBar then it is used. 2) If the window
1525 is a modal then its menubar is used. If no menubar is specified
1526 then a default menubar is used (as documented below) 3) If the
1527 window has no parent then the default menubar is used (as
1530 The above 3 steps are applied all the way up the parent window
1531 chain until one of the above are satisifed. If all else fails a
1532 default menubar will be created, the default menubar on Qt/Mac is
1533 an empty menubar, however you can create a different default
1534 menubar by creating a parentless QMenuBar, the first one created
1535 will thus be designated the default menubar, and will be used
1536 whenever a default menubar is needed.
1538 Thus, for Qt/Mac, we add the menus to a free standing menubar, so
1539 that this menubar will be used also when one of LyX' dialogs has
1542 void Menus::Impl::macxMenuBarInit(GuiView * view, QMenuBar * qmb)
1544 /* Since Qt 4.2, the qt/mac menu code has special code for
1545 specifying the role of a menu entry. However, it does not
1546 work very well with our scheme of creating menus on demand,
1547 and therefore we need to put these entries in a special
1548 invisible menu. (JMarc)
1551 /* The entries of our special mac menu. If we add support for
1552 * special entries in Menus, we could imagine something
1554 * SpecialItem About " "About LyX" "dialog-show aboutlyx"
1555 * and therefore avoid hardcoding. I am not sure it is worth
1556 * the hassle, though. (JMarc)
1558 struct MacMenuEntry {
1562 QAction::MenuRole role;
1565 MacMenuEntry entries[] = {
1566 {LFUN_DIALOG_SHOW, "aboutlyx", "About LyX",
1567 QAction::AboutRole},
1568 {LFUN_DIALOG_SHOW, "prefs", "Preferences",
1569 QAction::PreferencesRole},
1570 {LFUN_RECONFIGURE, "", "Reconfigure",
1571 QAction::ApplicationSpecificRole},
1572 {LFUN_LYX_QUIT, "", "Quit LyX", QAction::QuitRole}
1574 const size_t num_entries = sizeof(entries) / sizeof(entries[0]);
1576 // the special menu for Menus. Fill it up only once.
1577 if (mac_special_menu_.size() == 0) {
1578 for (size_t i = 0 ; i < num_entries ; ++i) {
1579 FuncRequest const func(entries[i].action,
1580 from_utf8(entries[i].arg));
1581 mac_special_menu_.add(MenuItem(MenuItem::Command,
1582 entries[i].label, func));
1586 // add the entries to a QMenu that will eventually be empty
1587 // and therefore invisible.
1588 QMenu * qMenu = qmb->addMenu("special");
1589 MenuDefinition::const_iterator cit = mac_special_menu_.begin();
1590 MenuDefinition::const_iterator end = mac_special_menu_.end();
1591 for (size_t i = 0 ; cit != end ; ++cit, ++i) {
1592 Action * action = new Action(view, QIcon(), cit->label(),
1593 cit->func(), QString(), qMenu);
1594 action->setMenuRole(entries[i].role);
1595 qMenu->addAction(action);
1600 void Menus::Impl::expand(MenuDefinition const & frommenu,
1601 MenuDefinition & tomenu, BufferView const * bv) const
1603 if (!tomenu.empty())
1606 for (MenuDefinition::const_iterator cit = frommenu.begin();
1607 cit != frommenu.end() ; ++cit) {
1608 Buffer const * buf = bv ? &bv->buffer() : 0;
1609 switch (cit->kind()) {
1610 case MenuItem::Lastfiles:
1611 tomenu.expandLastfiles();
1614 case MenuItem::Documents:
1615 tomenu.expandDocuments();
1618 case MenuItem::Bookmarks:
1619 tomenu.expandBookmarks();
1622 case MenuItem::ImportFormats:
1623 case MenuItem::ViewFormats:
1624 case MenuItem::UpdateFormats:
1625 case MenuItem::ExportFormats:
1626 tomenu.expandFormats(cit->kind(), buf);
1629 case MenuItem::CharStyles:
1630 tomenu.expandFlexInsert(buf, InsetLayout::CHARSTYLE);
1633 case MenuItem::Custom:
1634 tomenu.expandFlexInsert(buf, InsetLayout::CUSTOM);
1637 case MenuItem::Elements:
1638 tomenu.expandFlexInsert(buf, InsetLayout::ELEMENT);
1641 case MenuItem::FloatListInsert:
1642 tomenu.expandFloatListInsert(buf);
1645 case MenuItem::FloatInsert:
1646 tomenu.expandFloatInsert(buf);
1649 case MenuItem::PasteRecent:
1650 tomenu.expandPasteRecent(buf);
1653 case MenuItem::Toolbars:
1654 tomenu.expandToolbars();
1657 case MenuItem::Branches:
1658 tomenu.expandBranches(buf);
1661 case MenuItem::Indices:
1662 tomenu.expandIndices(buf);
1665 case MenuItem::IndicesContext:
1666 tomenu.expandIndicesContext(buf);
1669 case MenuItem::IndicesLists:
1670 tomenu.expandIndices(buf, true);
1673 case MenuItem::IndicesListsContext:
1674 tomenu.expandIndicesContext(buf, true);
1677 case MenuItem::CiteStyles:
1678 tomenu.expandCiteStyles(bv);
1682 tomenu.expandToc(buf);
1685 case MenuItem::GraphicsGroups:
1686 tomenu.expandGraphicsGroups(bv);
1689 case MenuItem::SpellingSuggestions:
1690 tomenu.expandSpellingSuggestions(bv);
1693 case MenuItem::LanguageSelector:
1694 tomenu.expandLanguageSelector(buf);
1697 case MenuItem::Submenu: {
1698 MenuItem item(*cit);
1699 item.setSubmenu(MenuDefinition(cit->submenuname()));
1700 expand(getMenu(cit->submenuname()), item.submenu(), bv);
1701 tomenu.addWithStatusCheck(item);
1705 case MenuItem::Info:
1706 case MenuItem::Help:
1707 case MenuItem::Separator:
1708 tomenu.addWithStatusCheck(*cit);
1711 case MenuItem::Command:
1712 if (!mac_special_menu_.hasFunc(cit->func()))
1713 tomenu.addWithStatusCheck(*cit);
1717 // we do not want the menu to end with a separator
1718 if (!tomenu.empty() && tomenu.items_.back().kind() == MenuItem::Separator)
1719 tomenu.items_.pop_back();
1721 // Check whether the shortcuts are unique
1722 tomenu.checkShortcuts();
1726 bool Menus::Impl::hasMenu(QString const & name) const
1728 return find_if(menulist_.begin(), menulist_.end(),
1729 MenuNamesEqual(name)) != menulist_.end();
1733 MenuDefinition const & Menus::Impl::getMenu(QString const & name) const
1735 const_iterator cit = find_if(menulist_.begin(), menulist_.end(),
1736 MenuNamesEqual(name));
1737 if (cit == menulist_.end())
1738 LYXERR0("No submenu named " << name);
1739 LASSERT(cit != menulist_.end(), /**/);
1744 MenuDefinition & Menus::Impl::getMenu(QString const & name)
1746 iterator it = find_if(menulist_.begin(), menulist_.end(),
1747 MenuNamesEqual(name));
1748 if (it == menulist_.end())
1749 LYXERR0("No submenu named " << name);
1750 LASSERT(it != menulist_.end(), /**/);
1755 /////////////////////////////////////////////////////////////////////
1759 /////////////////////////////////////////////////////////////////////
1761 Menus::Menus() : d(new Impl) {}
1777 void Menus::read(Lexer & lex)
1785 LexerKeyword menutags[] = {
1786 { "end", md_endmenuset },
1787 { "menu", md_menu },
1788 { "menubar", md_menubar }
1791 // consistency check
1792 if (compare_ascii_no_case(lex.getString(), "menuset"))
1793 LYXERR0("Menus::read: ERROR wrong token: `" << lex.getString() << '\'');
1795 lex.pushTable(menutags);
1796 lex.setContext("Menus::read");
1800 while (lex.isOK() && !quit) {
1801 switch (lex.lex()) {
1803 d->menubar_.read(lex);
1807 QString const name = toqstr(lex.getDocString());
1808 if (d->hasMenu(name))
1809 d->getMenu(name).read(lex);
1811 MenuDefinition menu(name);
1813 d->menulist_.push_back(menu);
1821 lex.printError("Unknown menu tag");
1829 bool Menus::searchMenu(FuncRequest const & func,
1830 docstring_list & names) const
1832 MenuDefinition menu;
1833 d->expand(d->menubar_, menu, 0);
1834 return menu.searchMenu(func, names);
1838 void Menus::fillMenuBar(QMenuBar * qmb, GuiView * view, bool initial)
1842 // setup special mac specific menu items, but only do this
1843 // the first time a QMenuBar is created. Otherwise Qt will
1844 // create duplicate items in the application menu. It seems
1845 // that Qt does not remove them when the QMenubar is cleared.
1846 LYXERR(Debug::GUI, "Creating Mac OS X special menu bar");
1847 d->macxMenuBarInit(view, qmb);
1850 // Clear all menubar contents before filling it.
1854 LYXERR(Debug::GUI, "populating menu bar" << d->menubar_.name());
1856 if (d->menubar_.size() == 0) {
1857 LYXERR(Debug::GUI, "\tERROR: empty menu bar"
1858 << d->menubar_.name());
1861 LYXERR(Debug::GUI, "menu bar entries " << d->menubar_.size());
1863 MenuDefinition menu;
1864 BufferView * bv = 0;
1866 bv = view->currentBufferView();
1867 d->expand(d->menubar_, menu, bv);
1869 MenuDefinition::const_iterator m = menu.begin();
1870 MenuDefinition::const_iterator end = menu.end();
1872 for (; m != end; ++m) {
1874 if (m->kind() != MenuItem::Submenu) {
1875 LYXERR(Debug::GUI, "\tERROR: not a submenu " << m->label());
1879 LYXERR(Debug::GUI, "menu bar item " << m->label()
1880 << " is a submenu named " << m->submenuname());
1882 QString name = m->submenuname();
1883 if (!d->hasMenu(name)) {
1884 LYXERR(Debug::GUI, "\tERROR: " << name
1885 << " submenu has no menu!");
1889 Menu * menu = new Menu(view, m->submenuname(), true);
1890 menu->setTitle(label(*m));
1893 d->name_map_[view][name] = menu;
1898 void Menus::updateMenu(Menu * qmenu)
1900 LYXERR(Debug::GUI, "Triggered menu: " << qmenu->d->name);
1903 if (qmenu->d->name.isEmpty())
1906 if (!d->hasMenu(qmenu->d->name)) {
1907 qmenu->addAction(qt_("No Action Defined!"));
1908 LYXERR(Debug::GUI, "\tWARNING: non existing menu: "
1913 MenuDefinition const & fromLyxMenu = d->getMenu(qmenu->d->name);
1914 BufferView * bv = 0;
1916 bv = qmenu->d->view->currentBufferView();
1917 d->expand(fromLyxMenu, *qmenu->d->top_level_menu, bv);
1918 qmenu->d->populate(*qmenu, *qmenu->d->top_level_menu);
1922 Menu * Menus::menu(QString const & name, GuiView & view)
1924 LYXERR(Debug::GUI, "Context menu requested: " << name);
1925 Menu * menu = d->name_map_[&view].value(name, 0);
1926 if (!menu && !name.startsWith("context-")) {
1927 LYXERR0("requested context menu not found: " << name);
1931 menu = new Menu(&view, name, true);
1932 d->name_map_[&view][name] = menu;
1936 } // namespace frontend
1939 #include "moc_Menus.cpp"