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"
46 #include "Paragraph.h"
47 #include "ParIterator.h"
49 #include "TextClass.h"
50 #include "TocBackend.h"
52 #include "WordLangTuple.h"
54 #include "insets/Inset.h"
55 #include "insets/InsetCitation.h"
56 #include "insets/InsetGraphics.h"
58 #include "support/lassert.h"
59 #include "support/convert.h"
60 #include "support/debug.h"
61 #include "support/docstring_list.h"
62 #include "support/filetools.h"
63 #include "support/gettext.h"
64 #include "support/lstrings.h"
72 #include <boost/shared_ptr.hpp>
78 using namespace lyx::support;
86 // MacOSX specific stuff is at the end.
93 /// The type of elements that can be in a menu
101 /** This type of item explains why something is unavailable. If this
102 menuitem is in a submenu, the submenu is enabled to make sure the
103 user sees the information. */
105 /** This type of item merely shows that there might be a list or
106 something alike at this position, but the list is still empty.
107 If this item is in a submenu, the submenu will not always be
110 /** This is the list of last opened file,
111 typically for the File menu. */
113 /** This is the list of opened Documents,
114 typically for the Documents menu. */
116 /** This is the bookmarks */
120 /** This is a list of viewable formats
121 typically for the File->View menu. */
123 /** This is a list of updatable formats
124 typically for the File->Update menu. */
126 /** This is a list of exportable formats
127 typically for the File->Export menu. */
129 /** This is a list of importable formats
130 typically for the File->Export menu. */
132 /** This is the list of elements available
133 * for insertion into document. */
135 /** This is the list of user-configurable
136 insets to insert into document */
138 /** This is the list of XML elements to
139 insert into the document */
141 /** This is the list of floats that we can
142 insert a list for. */
144 /** This is the list of floats that we can
147 /** This is the list of selections that can
152 /** Available branches in document */
154 /** Available indices in document */
156 /** Context menu for indices in document */
158 /** Available index lists in document */
160 /** Context menu for available indices lists in document */
162 /** Available citation styles for a given citation */
164 /** Available graphics groups */
166 /// Words suggested by the spellchecker.
168 /** Used Languages */
172 explicit MenuItem(Kind kind) : kind_(kind), optional_(false) {}
175 QString const & label,
176 QString const & submenu = QString(),
177 bool optional = false)
178 : kind_(kind), label_(label), submenuname_(submenu), optional_(optional)
180 LASSERT(kind == Submenu || kind == Help || kind == Info, /**/);
184 QString const & label,
185 FuncRequest const & func,
186 bool optional = false,
187 FuncRequest::Origin origin = FuncRequest::MENU)
188 : kind_(kind), label_(label), func_(func), optional_(optional)
190 func_.origin = origin;
193 // boost::shared_ptr<MenuDefinition> needs this apprently...
196 /// The label of a given menuitem
197 QString label() const { return label_.split('|')[0]; }
199 /// The keyboard shortcut (usually underlined in the entry)
200 QString shortcut() const
202 return label_.contains('|') ? label_.split('|')[1] : QString();
204 /// The complete label, with label and shortcut separated by a '|'
205 QString fulllabel() const { return label_;}
206 /// The kind of entry
207 Kind kind() const { return kind_; }
208 /// the action (if relevant)
209 FuncRequest const & func() const { return func_; }
210 /// returns true if the entry should be omitted when disabled
211 bool optional() const { return optional_; }
212 /// returns the status of the lfun associated with this entry
213 FuncStatus const & status() const { return status_; }
214 /// returns the status of the lfun associated with this entry
215 FuncStatus & status() { return status_; }
216 /// returns the status of the lfun associated with this entry
217 void status(FuncStatus const & status) { status_ = status; }
219 ///returns the binding associated to this action.
220 QString binding() const
222 if (kind_ != Command)
224 // Get the keys bound to this action, but keep only the
226 KeyMap::Bindings bindings = theTopLevelKeymap().findBindings(func_);
228 return toqstr(bindings.begin()->print(KeySequence::ForGui));
230 LYXERR(Debug::KBMAP, "No binding for "
231 << lyxaction.getActionName(func_.action)
232 << '(' << func_.argument() << ')');
236 /// the description of the submenu (if relevant)
237 QString const & submenuname() const { return submenuname_; }
238 /// set the description of the submenu
239 void submenuname(QString const & name) { submenuname_ = name; }
241 bool hasSubmenu() const { return !submenu_.isEmpty(); }
243 MenuDefinition const & submenu() const { return submenu_.at(0); }
244 MenuDefinition & submenu() { return submenu_[0]; }
246 void setSubmenu(MenuDefinition const & menu)
249 submenu_.append(menu);
260 QString submenuname_;
265 /// contains 0 or 1 item.
266 QList<MenuDefinition> submenu_;
270 class MenuDefinition {
273 typedef std::vector<MenuItem> ItemList;
275 typedef ItemList::const_iterator const_iterator;
277 explicit MenuDefinition(QString const & name = QString()) : name_(name) {}
282 QString const & name() const { return name_; }
284 bool empty() const { return items_.empty(); }
285 /// Clear the menu content.
286 void clear() { items_.clear(); }
288 size_t size() const { return items_.size(); }
290 MenuItem const & operator[](size_t) const;
292 const_iterator begin() const { return items_.begin(); }
294 const_iterator end() const { return items_.end(); }
296 // search for func in this menu iteratively, and put menu
298 bool searchMenu(FuncRequest const & func, docstring_list & names)
301 bool hasFunc(FuncRequest const &) const;
302 /// Add the menu item unconditionally
303 void add(MenuItem const & item) { items_.push_back(item); }
304 /// Checks the associated FuncRequest status before adding the
306 void addWithStatusCheck(MenuItem const &);
307 // Check whether the menu shortcuts are unique
308 void checkShortcuts() const;
310 void expandLastfiles();
311 void expandDocuments();
312 void expandBookmarks();
313 void expandFormats(MenuItem::Kind kind, Buffer const * buf);
314 void expandFloatListInsert(Buffer const * buf);
315 void expandFloatInsert(Buffer const * buf);
316 void expandFlexInsert(Buffer const * buf, InsetLayout::InsetLyXType type);
317 void expandToc2(Toc const & toc_list, size_t from, size_t to, int depth);
318 void expandToc(Buffer const * buf);
319 void expandPasteRecent(Buffer const * buf);
320 void expandToolbars();
321 void expandBranches(Buffer const * buf);
322 void expandIndices(Buffer const * buf, bool listof = false);
323 void expandIndicesContext(Buffer const * buf, bool listof = false);
324 void expandCiteStyles(BufferView const *);
325 void expandGraphicsGroups(BufferView const *);
326 void expandSpellingSuggestions(BufferView const *);
327 void expandLanguageSelector(Buffer const * buf);
335 /// Helper for std::find_if
339 MenuNamesEqual(QString const & name) : name_(name) {}
340 bool operator()(MenuDefinition const & menu) const { return menu.name() == name_; }
347 typedef std::vector<MenuDefinition> MenuList;
349 typedef MenuList::const_iterator const_iterator;
351 typedef MenuList::iterator iterator;
353 /////////////////////////////////////////////////////////////////////
354 // MenuDefinition implementation
355 /////////////////////////////////////////////////////////////////////
357 void MenuDefinition::addWithStatusCheck(MenuItem const & i)
361 case MenuItem::Command: {
362 FuncStatus status = lyx::getStatus(i.func());
363 if (status.unknown() || (!status.enabled() && i.optional()))
366 items_.back().status(status);
370 case MenuItem::Submenu: {
371 bool enabled = false;
372 if (i.hasSubmenu()) {
373 for (const_iterator cit = i.submenu().begin();
374 cit != i.submenu().end(); ++cit) {
375 // Only these kind of items affect the status of the submenu
376 if ((cit->kind() == MenuItem::Command
377 || cit->kind() == MenuItem::Submenu
378 || cit->kind() == MenuItem::Help)
379 && cit->status().enabled()) {
385 if (enabled || !i.optional()) {
387 items_.back().status().setEnabled(enabled);
392 case MenuItem::Separator:
393 if (!items_.empty() && items_.back().kind() != MenuItem::Separator)
403 void MenuDefinition::read(Lexer & lex)
420 md_indiceslistscontext,
434 md_spellingsuggestions,
438 LexerKeyword menutags[] = {
439 { "bookmarks", md_bookmarks },
440 { "branches", md_branches },
441 { "charstyles", md_charstyles },
442 { "citestyles", md_citestyles },
443 { "custom", md_custom },
444 { "documents", md_documents },
445 { "elements", md_elements },
446 { "end", md_endmenu },
447 { "exportformats", md_exportformats },
448 { "floatinsert", md_floatinsert },
449 { "floatlistinsert", md_floatlistinsert },
450 { "graphicsgroups", md_graphicsgroups },
451 { "importformats", md_importformats },
452 { "indices", md_indices },
453 { "indicescontext", md_indicescontext },
454 { "indiceslists", md_indiceslists },
455 { "indiceslistscontext", md_indiceslistscontext },
457 { "languageselector", md_languageselector },
458 { "lastfiles", md_lastfiles },
459 { "optitem", md_optitem },
460 { "optsubmenu", md_optsubmenu },
461 { "pasterecent", md_pasterecent },
462 { "separator", md_separator },
463 { "spellingsuggestions", md_spellingsuggestions },
464 { "submenu", md_submenu },
466 { "toolbars", md_toolbars },
467 { "updateformats", md_updateformats },
468 { "viewformats", md_viewformats }
471 lex.pushTable(menutags);
472 lex.setContext("MenuDefinition::read: ");
475 bool optional = false;
477 while (lex.isOK() && !quit) {
481 // fallback to md_item
484 docstring const name = translateIfPossible(lex.getDocString());
486 string const command = lex.getString();
487 FuncRequest func = lyxaction.lookupFunc(command);
488 FuncRequest::Origin origin = FuncRequest::MENU;
489 if (name_.startsWith("context-toc-"))
490 origin = FuncRequest::TOC;
491 add(MenuItem(MenuItem::Command, toqstr(name), func, optional, origin));
497 add(MenuItem(MenuItem::Separator));
501 add(MenuItem(MenuItem::Lastfiles));
505 add(MenuItem(MenuItem::CharStyles));
509 add(MenuItem(MenuItem::Custom));
513 add(MenuItem(MenuItem::Elements));
517 add(MenuItem(MenuItem::Documents));
521 add(MenuItem(MenuItem::Bookmarks));
525 add(MenuItem(MenuItem::Toc));
529 add(MenuItem(MenuItem::ViewFormats));
532 case md_updateformats:
533 add(MenuItem(MenuItem::UpdateFormats));
536 case md_exportformats:
537 add(MenuItem(MenuItem::ExportFormats));
540 case md_importformats:
541 add(MenuItem(MenuItem::ImportFormats));
544 case md_floatlistinsert:
545 add(MenuItem(MenuItem::FloatListInsert));
549 add(MenuItem(MenuItem::FloatInsert));
553 add(MenuItem(MenuItem::PasteRecent));
557 add(MenuItem(MenuItem::Toolbars));
561 add(MenuItem(MenuItem::Branches));
565 add(MenuItem(MenuItem::CiteStyles));
568 case md_graphicsgroups:
569 add(MenuItem(MenuItem::GraphicsGroups));
572 case md_spellingsuggestions:
573 add(MenuItem(MenuItem::SpellingSuggestions));
576 case md_languageselector:
577 add(MenuItem(MenuItem::LanguageSelector));
581 add(MenuItem(MenuItem::Indices));
584 case md_indicescontext:
585 add(MenuItem(MenuItem::IndicesContext));
588 case md_indiceslists:
589 add(MenuItem(MenuItem::IndicesLists));
592 case md_indiceslistscontext:
593 add(MenuItem(MenuItem::IndicesListsContext));
598 // fallback to md_submenu
601 docstring const mlabel = translateIfPossible(lex.getDocString());
603 docstring const mname = lex.getDocString();
604 add(MenuItem(MenuItem::Submenu,
605 toqstr(mlabel), toqstr(mname), optional));
615 lex.printError("Unknown menu tag");
623 MenuItem const & MenuDefinition::operator[](size_type i) const
629 bool MenuDefinition::hasFunc(FuncRequest const & func) const
631 for (const_iterator it = begin(), et = end(); it != et; ++it)
632 if (it->func() == func)
638 void MenuDefinition::checkShortcuts() const
640 // This is a quadratic algorithm, but we do not care because
641 // menus are short enough
642 for (const_iterator it1 = begin(); it1 != end(); ++it1) {
643 QString shortcut = it1->shortcut();
644 if (shortcut.isEmpty())
646 if (!it1->label().contains(shortcut))
647 LYXERR0("Menu warning: menu entry \""
649 << "\" does not contain shortcut `"
650 << shortcut << "'.");
651 for (const_iterator it2 = begin(); it2 != it1 ; ++it2) {
652 if (!it2->shortcut().compare(shortcut, Qt::CaseInsensitive)) {
653 LYXERR0("Menu warning: menu entries "
654 << '"' << it1->fulllabel()
655 << "\" and \"" << it2->fulllabel()
656 << "\" share the same shortcut.");
663 bool MenuDefinition::searchMenu(FuncRequest const & func, docstring_list & names) const
665 const_iterator m = begin();
666 const_iterator m_end = end();
667 for (; m != m_end; ++m) {
668 if (m->kind() == MenuItem::Command && m->func() == func) {
669 names.push_back(qstring_to_ucs4(m->label()));
672 if (m->kind() == MenuItem::Submenu) {
673 names.push_back(qstring_to_ucs4(m->label()));
674 if (!m->hasSubmenu()) {
675 LYXERR(Debug::GUI, "Warning: non existing sub menu label="
676 << m->label() << " name=" << m->submenuname());
680 if (m->submenu().searchMenu(func, names))
689 bool compareFormat(Format const * p1, Format const * p2)
695 QString limitStringLength(docstring const & str)
697 size_t const max_item_length = 45;
699 if (str.size() > max_item_length)
700 return toqstr(str.substr(0, max_item_length - 3) + "...");
706 void MenuDefinition::expandGraphicsGroups(BufferView const * bv)
711 graphics::getGraphicsGroups(bv->buffer(), grp);
715 set<string>::const_iterator it = grp.begin();
716 set<string>::const_iterator end = grp.end();
717 add(MenuItem(MenuItem::Command, qt_("No Group"),
718 FuncRequest(LFUN_SET_GRAPHICS_GROUP)));
719 for (; it != end; it++) {
720 addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(*it),
721 FuncRequest(LFUN_SET_GRAPHICS_GROUP, *it)));
726 void MenuDefinition::expandSpellingSuggestions(BufferView const * bv)
728 if (!bv || !lyxrc.spellcheck_continuously)
731 docstring_list suggestions;
732 pos_type from = bv->cursor().pos();
734 Paragraph const & par = bv->cursor().paragraph();
735 if (!par.spellCheck(from, to, wl, suggestions))
737 LYXERR(Debug::GUI, "Misspelled Word! Suggested Words = ");
739 MenuItem item(MenuItem::Submenu, qt_("More Spelling Suggestions"));
740 item.setSubmenu(MenuDefinition(qt_("More Spelling Suggestions")));
741 for (; i != suggestions.size(); ++i) {
742 docstring const & suggestion = suggestions[i];
743 LYXERR(Debug::GUI, suggestion);
744 MenuItem w(MenuItem::Command, toqstr(suggestion),
745 FuncRequest(LFUN_WORD_REPLACE, suggestion));
749 item.submenu().add(w);
754 add(MenuItem(MenuItem::Separator));
755 docstring const arg = wl.word() + " " + from_ascii(wl.lang()->lang());
756 add(MenuItem(MenuItem::Command, qt_("Add to personal dictionary|c"),
757 FuncRequest(LFUN_SPELLING_ADD, arg)));
758 add(MenuItem(MenuItem::Command, qt_("Ignore all|I"),
759 FuncRequest(LFUN_SPELLING_IGNORE, arg)));
764 void MenuDefinition::expandLanguageSelector(Buffer const * buf)
769 std::set<Language const *> languages =
770 buf->masterBuffer()->getLanguages();
772 if (languages.size() < 2) {
773 add(MenuItem(MenuItem::Command, qt_("Language ...|L"),
774 FuncRequest(LFUN_DIALOG_SHOW, "character")));
778 MenuItem item(MenuItem::Submenu, qt_("Language|L"));
779 item.setSubmenu(MenuDefinition(qt_("Language")));
780 QStringList accelerators;
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 QString label = qt_((*cit)->display());
785 // try to add an accelerator
786 for (int i = 0; i < label.size(); ++i) {
787 QString const ch = QString(label[i]);
788 if (!accelerators.contains(ch, Qt::CaseInsensitive)) {
789 label = label + toqstr("|") + ch;
790 accelerators.append(ch);
794 MenuItem w(MenuItem::Command, label,
795 FuncRequest(LFUN_LANGUAGE, (*cit)->lang()));
796 item.submenu().addWithStatusCheck(w);
798 item.submenu().add(MenuItem(MenuItem::Separator));
799 item.submenu().add(MenuItem(MenuItem::Command, qt_("More Languages ..."),
800 FuncRequest(LFUN_DIALOG_SHOW, "character")));
805 void MenuDefinition::expandLastfiles()
807 LastFilesSection::LastFiles const & lf = theSession().lastFiles().lastFiles();
808 LastFilesSection::LastFiles::const_iterator lfit = lf.begin();
812 for (; lfit != lf.end() && ii <= lyxrc.num_lastfiles; ++lfit, ++ii) {
813 string const file = lfit->absFilename();
816 label = QString("%1. %2|%3").arg(ii)
817 .arg(toqstr(makeDisplayPath(file, 30))).arg(ii);
819 label = QString("%1. %2").arg(ii)
820 .arg(toqstr(makeDisplayPath(file, 30)));
821 add(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_FILE_OPEN, file)));
826 void MenuDefinition::expandDocuments()
828 MenuItem item(MenuItem::Submenu, qt_("Invisible"));
829 item.setSubmenu(MenuDefinition(qt_("Invisible")));
831 Buffer * first = theBufferList().first();
837 // We cannot use a for loop as the buffer list cycles.
839 QString label = toqstr(b->fileName().displayName(20));
842 bool const shown = guiApp->currentView()
843 ? guiApp->currentView()->workArea(*b) : false;
844 int ii = shown ? vis : invis;
846 label = QString::number(ii) + ". " + label + '|' + QString::number(ii);
848 add(MenuItem(MenuItem::Command, label,
849 FuncRequest(LFUN_BUFFER_SWITCH, b->absFileName())));
852 item.submenu().add(MenuItem(MenuItem::Command, label,
853 FuncRequest(LFUN_BUFFER_SWITCH, b->absFileName())));
856 b = theBufferList().next(b);
857 } while (b != first);
858 if (!item.submenu().empty())
861 add(MenuItem(MenuItem::Info, qt_("<No Documents Open>")));
865 void MenuDefinition::expandBookmarks()
867 lyx::BookmarksSection const & bm = theSession().bookmarks();
870 for (size_t i = 1; i <= bm.size(); ++i) {
872 string const file = bm.bookmark(i).filename.absFilename();
873 QString const label = QString("%1. %2|%3").arg(i)
874 .arg(toqstr(makeDisplayPath(file, 20))).arg(i);
875 add(MenuItem(MenuItem::Command, label,
876 FuncRequest(LFUN_BOOKMARK_GOTO, convert<docstring>(i))));
881 add(MenuItem(MenuItem::Info, qt_("<No Bookmarks Saved Yet>")));
885 void MenuDefinition::expandFormats(MenuItem::Kind kind, Buffer const * buf)
887 if (!buf && kind != MenuItem::ImportFormats)
890 typedef vector<Format const *> Formats;
895 case MenuItem::ImportFormats:
896 formats = theConverters().importableFormats();
897 action = LFUN_BUFFER_IMPORT;
899 case MenuItem::ViewFormats:
900 formats = buf->exportableFormats(true);
901 action = LFUN_BUFFER_VIEW;
903 case MenuItem::UpdateFormats:
904 formats = buf->exportableFormats(true);
905 action = LFUN_BUFFER_UPDATE;
908 formats = buf->exportableFormats(false);
909 action = LFUN_BUFFER_EXPORT;
911 sort(formats.begin(), formats.end(), &compareFormat);
913 bool const view_update = (kind == MenuItem::ViewFormats
914 || kind == MenuItem::UpdateFormats);
918 smenue = (kind == MenuItem::ViewFormats ?
919 qt_("View (Other Formats)|F")
920 : qt_("Update (Other Formats)|p"));
921 MenuItem item(MenuItem::Submenu, smenue);
922 item.setSubmenu(MenuDefinition(smenue));
924 Formats::const_iterator fit = formats.begin();
925 Formats::const_iterator end = formats.end();
926 for (; fit != end ; ++fit) {
930 docstring lab = from_utf8((*fit)->prettyname());
931 docstring scut = from_utf8((*fit)->shortcut());
932 docstring const tmplab = lab;
935 lab += char_type('|') + scut;
936 docstring lab_i18n = translateIfPossible(lab);
937 bool const untranslated = (lab == lab_i18n);
938 QString const shortcut = toqstr(split(lab_i18n, lab, '|'));
939 QString label = toqstr(lab);
941 // this might happen if the shortcut
942 // has been redefined
943 label = toqstr(translateIfPossible(tmplab));
946 case MenuItem::ImportFormats:
949 case MenuItem::ViewFormats:
950 case MenuItem::UpdateFormats:
951 if ((*fit)->name() == buf->getDefaultOutputFormat()) {
952 docstring lbl = (kind == MenuItem::ViewFormats ?
953 bformat(_("View [%1$s]|V"), qstring_to_ucs4(label))
954 : bformat(_("Update [%1$s]|U"), qstring_to_ucs4(label)));
955 MenuItem w(MenuItem::Command, toqstr(lbl),
956 FuncRequest(action, (*fit)->name()));
960 case MenuItem::ExportFormats:
961 if (!(*fit)->documentFormat())
965 LASSERT(false, /**/);
968 if (!shortcut.isEmpty())
969 label += '|' + shortcut;
973 item.submenu().addWithStatusCheck(MenuItem(MenuItem::Command, label,
974 FuncRequest(action, (*fit)->name())));
976 item.submenu().add(MenuItem(MenuItem::Command, label,
977 FuncRequest(action, (*fit)->name())));
980 addWithStatusCheck(MenuItem(MenuItem::Command, label,
981 FuncRequest(action, (*fit)->name())));
983 add(MenuItem(MenuItem::Command, label,
984 FuncRequest(action, (*fit)->name())));
992 void MenuDefinition::expandFloatListInsert(Buffer const * buf)
997 FloatList const & floats = buf->params().documentClass().floats();
998 FloatList::const_iterator cit = floats.begin();
999 FloatList::const_iterator end = floats.end();
1000 for (; cit != end; ++cit) {
1001 addWithStatusCheck(MenuItem(MenuItem::Command,
1002 qt_(cit->second.listName()),
1003 FuncRequest(LFUN_FLOAT_LIST_INSERT,
1004 cit->second.type())));
1009 void MenuDefinition::expandFloatInsert(Buffer const * buf)
1014 FloatList const & floats = buf->params().documentClass().floats();
1015 FloatList::const_iterator cit = floats.begin();
1016 FloatList::const_iterator end = floats.end();
1017 for (; cit != end; ++cit) {
1019 QString const label = qt_(cit->second.name());
1020 addWithStatusCheck(MenuItem(MenuItem::Command, label,
1021 FuncRequest(LFUN_FLOAT_INSERT,
1022 cit->second.type())));
1027 void MenuDefinition::expandFlexInsert(
1028 Buffer const * buf, InsetLayout::InsetLyXType type)
1033 TextClass::InsetLayouts const & insetLayouts =
1034 buf->params().documentClass().insetLayouts();
1035 TextClass::InsetLayouts::const_iterator cit = insetLayouts.begin();
1036 TextClass::InsetLayouts::const_iterator end = insetLayouts.end();
1037 for (; cit != end; ++cit) {
1038 if (cit->second.lyxtype() == type) {
1039 docstring const label = cit->first;
1040 addWithStatusCheck(MenuItem(MenuItem::Command,
1041 toqstr(translateIfPossible(label)),
1042 FuncRequest(LFUN_FLEX_INSERT, Lexer::quoteString(label))));
1045 // FIXME This is a little clunky.
1046 if (items_.empty() && type == InsetLayout::CUSTOM)
1047 add(MenuItem(MenuItem::Help, qt_("No Custom Insets Defined!")));
1051 size_t const max_number_of_items = 25;
1053 void MenuDefinition::expandToc2(Toc const & toc_list,
1054 size_t from, size_t to, int depth)
1056 int shortcut_count = 0;
1058 // check whether depth is smaller than the smallest depth in toc.
1059 int min_depth = 1000;
1060 for (size_t i = from; i < to; ++i)
1061 min_depth = min(min_depth, toc_list[i].depth());
1062 if (min_depth > depth)
1065 if (to - from <= max_number_of_items) {
1066 for (size_t i = from; i < to; ++i) {
1067 QString label(4 * max(0, toc_list[i].depth() - depth), ' ');
1068 label += limitStringLength(toc_list[i].str());
1069 if (toc_list[i].depth() == depth
1070 && shortcut_count < 9) {
1071 if (label.contains(QString::number(shortcut_count + 1)))
1072 label += '|' + QString::number(++shortcut_count);
1074 add(MenuItem(MenuItem::Command, label,
1075 FuncRequest(toc_list[i].action())));
1080 size_t new_pos = pos + 1;
1081 while (new_pos < to && toc_list[new_pos].depth() > depth)
1084 QString label(4 * max(0, toc_list[pos].depth() - depth), ' ');
1085 label += limitStringLength(toc_list[pos].str());
1086 if (toc_list[pos].depth() == depth &&
1087 shortcut_count < 9) {
1088 if (label.contains(QString::number(shortcut_count + 1)))
1089 label += '|' + QString::number(++shortcut_count);
1091 if (new_pos == pos + 1) {
1092 add(MenuItem(MenuItem::Command,
1093 label, FuncRequest(toc_list[pos].action())));
1096 sub.expandToc2(toc_list, pos, new_pos, depth + 1);
1097 MenuItem item(MenuItem::Submenu, label);
1098 item.setSubmenu(sub);
1107 void MenuDefinition::expandToc(Buffer const * buf)
1109 // To make things very cleanly, we would have to pass buf to
1110 // all MenuItem constructors and to expandToc2. However, we
1111 // know that all the entries in a TOC will be have status_ ==
1112 // OK, so we avoid this unnecessary overhead (JMarc)
1115 add(MenuItem(MenuItem::Info, qt_("<No Document Open>")));
1119 // Add an entry for the master doc if this is a child doc
1120 Buffer const * const master = buf->masterBuffer();
1121 if (buf != master) {
1122 ParIterator const pit = par_iterator_begin(master->inset());
1123 string const arg = convert<string>(pit->id());
1124 FuncRequest f(LFUN_PARAGRAPH_GOTO, arg);
1125 add(MenuItem(MenuItem::Command, qt_("Master Document"), f));
1128 MenuDefinition other_lists;
1130 FloatList const & floatlist = buf->params().documentClass().floats();
1131 TocList const & toc_list = buf->tocBackend().tocs();
1132 TocList::const_iterator cit = toc_list.begin();
1133 TocList::const_iterator end = toc_list.end();
1134 for (; cit != end; ++cit) {
1135 // Handle this later
1136 if (cit->first == "tableofcontents")
1139 MenuDefinition submenu;
1140 if (cit->second.size() >= 30) {
1141 FuncRequest f(LFUN_DIALOG_SHOW, "toc " + cit->first);
1142 submenu.add(MenuItem(MenuItem::Command, qt_("Open Navigator..."), f));
1144 TocIterator ccit = cit->second.begin();
1145 TocIterator eend = cit->second.end();
1146 for (; ccit != eend; ++ccit) {
1147 submenu.add(MenuItem(MenuItem::Command,
1148 limitStringLength(ccit->str()),
1149 FuncRequest(ccit->action())));
1153 MenuItem item(MenuItem::Submenu, guiName(cit->first, buf->params()));
1154 item.setSubmenu(submenu);
1155 if (floatlist.typeExist(cit->first) || cit->first == "child") {
1156 // Those two types deserve to be in the main menu.
1157 item.setSubmenu(submenu);
1160 other_lists.add(item);
1162 if (!other_lists.empty()) {
1163 MenuItem item(MenuItem::Submenu, qt_("Other Lists"));
1164 item.setSubmenu(other_lists);
1168 // Handle normal TOC
1169 cit = toc_list.find("tableofcontents");
1171 LYXERR(Debug::GUI, "No table of contents.");
1173 if (cit->second.size() > 0 )
1174 expandToc2(cit->second, 0, cit->second.size(), 0);
1176 add(MenuItem(MenuItem::Info, qt_("<Empty Table of Contents>")));
1181 void MenuDefinition::expandPasteRecent(Buffer const * buf)
1183 docstring_list const sel = cap::availableSelections(buf);
1185 docstring_list::const_iterator cit = sel.begin();
1186 docstring_list::const_iterator end = sel.end();
1188 for (unsigned int index = 0; cit != end; ++cit, ++index) {
1189 add(MenuItem(MenuItem::Command, toqstr(*cit),
1190 FuncRequest(LFUN_PASTE, convert<string>(index))));
1195 void MenuDefinition::expandToolbars()
1197 MenuDefinition other_lists;
1198 // extracts the toolbars from the backend
1199 Toolbars::Infos::const_iterator cit = guiApp->toolbars().begin();
1200 Toolbars::Infos::const_iterator end = guiApp->toolbars().end();
1201 for (; cit != end; ++cit) {
1202 MenuItem const item(MenuItem::Command, toqstr(cit->gui_name),
1203 FuncRequest(LFUN_TOOLBAR_TOGGLE, cit->name));
1204 if (guiApp->toolbars().isMainToolbar(cit->name))
1207 other_lists.add(item);
1210 if (!other_lists.empty()) {
1211 MenuItem item(MenuItem::Submenu, qt_("Other Toolbars"));
1212 item.setSubmenu(other_lists);
1218 void MenuDefinition::expandBranches(Buffer const * buf)
1223 BufferParams const & master_params = buf->masterBuffer()->params();
1224 BufferParams const & params = buf->params();
1225 if (params.branchlist().empty() && master_params.branchlist().empty() ) {
1226 add(MenuItem(MenuItem::Help, qt_("No Branches Set for Document!")));
1230 BranchList::const_iterator cit = master_params.branchlist().begin();
1231 BranchList::const_iterator end = master_params.branchlist().end();
1233 for (int ii = 1; cit != end; ++cit, ++ii) {
1234 docstring label = cit->branch();
1236 label = convert<docstring>(ii) + ". " + label
1237 + char_type('|') + convert<docstring>(ii);
1239 addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(label),
1240 FuncRequest(LFUN_BRANCH_INSERT,
1244 if (buf == buf->masterBuffer())
1247 MenuDefinition child_branches;
1249 BranchList::const_iterator ccit = params.branchlist().begin();
1250 BranchList::const_iterator cend = params.branchlist().end();
1252 for (int ii = 1; ccit != cend; ++ccit, ++ii) {
1253 docstring label = ccit->branch();
1255 label = convert<docstring>(ii) + ". " + label
1256 + char_type('|') + convert<docstring>(ii);
1258 child_branches.addWithStatusCheck(MenuItem(MenuItem::Command,
1260 FuncRequest(LFUN_BRANCH_INSERT,
1264 if (!child_branches.empty()) {
1265 MenuItem item(MenuItem::Submenu, qt_("Child Document"));
1266 item.setSubmenu(child_branches);
1272 void MenuDefinition::expandIndices(Buffer const * buf, bool listof)
1277 BufferParams const & params = buf->masterBuffer()->params();
1278 if (!params.use_indices) {
1280 addWithStatusCheck(MenuItem(MenuItem::Command,
1281 qt_("Index List|I"),
1282 FuncRequest(LFUN_INDEX_PRINT,
1283 from_ascii("idx"))));
1285 addWithStatusCheck(MenuItem(MenuItem::Command,
1286 qt_("Index Entry|d"),
1287 FuncRequest(LFUN_INDEX_INSERT,
1288 from_ascii("idx"))));
1292 if (params.indiceslist().empty())
1295 IndicesList::const_iterator cit = params.indiceslist().begin();
1296 IndicesList::const_iterator end = params.indiceslist().end();
1298 for (int ii = 1; cit != end; ++cit, ++ii) {
1300 addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(cit->index()),
1301 FuncRequest(LFUN_INDEX_PRINT,
1304 docstring label = _("Index Entry");
1305 label += " (" + cit->index() + ")";
1306 addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(label),
1307 FuncRequest(LFUN_INDEX_INSERT,
1314 void MenuDefinition::expandIndicesContext(Buffer const * buf, bool listof)
1319 BufferParams const & params = buf->masterBuffer()->params();
1320 if (!params.use_indices || params.indiceslist().empty())
1323 IndicesList::const_iterator cit = params.indiceslist().begin();
1324 IndicesList::const_iterator end = params.indiceslist().end();
1326 for (int ii = 1; cit != end; ++cit, ++ii) {
1328 InsetCommandParams p(INDEX_PRINT_CODE);
1329 p["type"] = cit->shortcut();
1330 string const data = InsetCommand::params2string("index_print", p);
1331 addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(cit->index()),
1332 FuncRequest(LFUN_INSET_MODIFY, data)));
1334 docstring label = _("Index Entry");
1335 label += " (" + cit->index() + ")";
1336 addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(label),
1337 FuncRequest(LFUN_INSET_MODIFY,
1338 from_ascii("changetype ") + cit->shortcut())));
1344 void MenuDefinition::expandCiteStyles(BufferView const * bv)
1349 Inset const * inset = bv->cursor().nextInset();
1350 if (!inset || inset->lyxCode() != CITE_CODE) {
1351 add(MenuItem(MenuItem::Command,
1352 qt_("No Citation in Scope!"),
1353 FuncRequest(LFUN_NOACTION)));
1356 InsetCommand const * citinset =
1357 static_cast<InsetCommand const *>(inset);
1359 Buffer const * buf = &bv->buffer();
1360 docstring key = citinset->getParam("key");
1361 // we can only handle one key currently
1362 if (contains(key, ','))
1363 key = qstring_to_ucs4(toqstr(key).split(',')[0]);
1365 vector<CiteStyle> citeStyleList = citeStyles(buf->params().citeEngine());
1366 docstring_list citeStrings =
1367 buf->masterBibInfo().getCiteStrings(key, bv->buffer());
1369 docstring_list::const_iterator cit = citeStrings.begin();
1370 docstring_list::const_iterator end = citeStrings.end();
1372 for (int ii = 1; cit != end; ++cit, ++ii) {
1373 docstring label = *cit;
1375 CiteStyle cst = citeStyleList[ii - 1];
1377 addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(label),
1378 FuncRequest(LFUN_INSET_MODIFY,
1379 "changetype " + from_utf8(citationStyleToString(cs)))));
1386 /////////////////////////////////////////////////////////////////////
1387 // Menu::Impl definition and implementation
1388 /////////////////////////////////////////////////////////////////////
1392 /// populates the menu or one of its submenu
1393 /// This is used as a recursive function
1394 void populate(QMenu & qMenu, MenuDefinition const & menu);
1396 /// Only needed for top level menus.
1397 MenuDefinition * top_level_menu;
1400 /// the name of this menu
1406 /// Get a MenuDefinition item label from the menu backend
1407 static QString label(MenuItem const & mi)
1409 QString label = mi.label();
1410 label.replace("&", "&&");
1412 QString shortcut = mi.shortcut();
1413 if (!shortcut.isEmpty()) {
1414 int pos = label.indexOf(shortcut);
1416 //label.insert(pos, 1, char_type('&'));
1417 label.replace(pos, 0, "&");
1420 QString const binding = mi.binding();
1421 if (!binding.isEmpty())
1422 label += '\t' + binding;
1427 void Menu::Impl::populate(QMenu & qMenu, MenuDefinition const & menu)
1429 LYXERR(Debug::GUI, "populating menu " << menu.name());
1430 if (menu.size() == 0) {
1431 LYXERR(Debug::GUI, "\tERROR: empty menu " << menu.name());
1434 LYXERR(Debug::GUI, " ***** menu entries " << menu.size());
1435 MenuDefinition::const_iterator m = menu.begin();
1436 MenuDefinition::const_iterator end = menu.end();
1437 for (; m != end; ++m) {
1438 if (m->kind() == MenuItem::Separator)
1439 qMenu.addSeparator();
1440 else if (m->kind() == MenuItem::Submenu) {
1441 QMenu * subMenu = qMenu.addMenu(label(*m));
1442 populate(*subMenu, m->submenu());
1443 subMenu->setEnabled(m->status().enabled());
1445 // we have a MenuItem::Command
1446 qMenu.addAction(new Action(view, QIcon(), label(*m),
1447 m->func(), QString(), &qMenu));
1452 /////////////////////////////////////////////////////////////////////
1453 // Menu implementation
1454 /////////////////////////////////////////////////////////////////////
1456 Menu::Menu(GuiView * gv, QString const & name, bool top_level)
1457 : QMenu(gv), d(new Menu::Impl)
1459 d->top_level_menu = top_level? new MenuDefinition : 0;
1463 if (d->top_level_menu)
1464 connect(this, SIGNAL(aboutToShow()), this, SLOT(updateView()));
1470 delete d->top_level_menu;
1475 void Menu::updateView()
1477 guiApp->menus().updateMenu(this);
1481 /////////////////////////////////////////////////////////////////////
1482 // Menus::Impl definition and implementation
1483 /////////////////////////////////////////////////////////////////////
1485 struct Menus::Impl {
1487 bool hasMenu(QString const &) const;
1489 MenuDefinition & getMenu(QString const &);
1491 MenuDefinition const & getMenu(QString const &) const;
1493 /// Expands some special entries of the menu
1494 /** The entries with the following kind are expanded to a
1495 sequence of Command MenuItems: Lastfiles, Documents,
1496 ViewFormats, ExportFormats, UpdateFormats, Branches, Indices
1498 void expand(MenuDefinition const & frommenu, MenuDefinition & tomenu,
1499 BufferView const *) const;
1501 /// Initialize specific MACOS X menubar
1502 void macxMenuBarInit(GuiView * view, QMenuBar * qmb);
1504 /// Mac special menu.
1505 /** This defines a menu whose entries list the FuncRequests
1506 that will be removed by expand() in other menus. This is
1507 used by the Qt/Mac code.
1509 NOTE: Qt does not remove the menu items when clearing a QMenuBar,
1510 such that the items will keep accessing the FuncRequests in
1511 the MenuDefinition. While Menus::Impl might be recreated,
1512 we keep mac_special_menu_ in memory by making it static.
1514 static MenuDefinition mac_special_menu_;
1519 MenuDefinition menubar_;
1521 typedef QMap<GuiView *, QHash<QString, Menu*> > NameMap;
1523 /// name to menu for \c menu() method.
1528 MenuDefinition Menus::Impl::mac_special_menu_;
1532 Here is what the Qt documentation says about how a menubar is chosen:
1534 1) If the window has a QMenuBar then it is used. 2) If the window
1535 is a modal then its menubar is used. If no menubar is specified
1536 then a default menubar is used (as documented below) 3) If the
1537 window has no parent then the default menubar is used (as
1540 The above 3 steps are applied all the way up the parent window
1541 chain until one of the above are satisifed. If all else fails a
1542 default menubar will be created, the default menubar on Qt/Mac is
1543 an empty menubar, however you can create a different default
1544 menubar by creating a parentless QMenuBar, the first one created
1545 will thus be designated the default menubar, and will be used
1546 whenever a default menubar is needed.
1548 Thus, for Qt/Mac, we add the menus to a free standing menubar, so
1549 that this menubar will be used also when one of LyX' dialogs has
1552 void Menus::Impl::macxMenuBarInit(GuiView * view, QMenuBar * qmb)
1554 /* Since Qt 4.2, the qt/mac menu code has special code for
1555 specifying the role of a menu entry. However, it does not
1556 work very well with our scheme of creating menus on demand,
1557 and therefore we need to put these entries in a special
1558 invisible menu. (JMarc)
1561 /* The entries of our special mac menu. If we add support for
1562 * special entries in Menus, we could imagine something
1564 * SpecialItem About " "About LyX" "dialog-show aboutlyx"
1565 * and therefore avoid hardcoding. I am not sure it is worth
1566 * the hassle, though. (JMarc)
1568 struct MacMenuEntry {
1572 QAction::MenuRole role;
1575 MacMenuEntry entries[] = {
1576 {LFUN_DIALOG_SHOW, "aboutlyx", "About LyX",
1577 QAction::AboutRole},
1578 {LFUN_DIALOG_SHOW, "prefs", "Preferences",
1579 QAction::PreferencesRole},
1580 {LFUN_RECONFIGURE, "", "Reconfigure",
1581 QAction::ApplicationSpecificRole},
1582 {LFUN_LYX_QUIT, "", "Quit LyX", QAction::QuitRole}
1584 const size_t num_entries = sizeof(entries) / sizeof(entries[0]);
1586 // the special menu for Menus. Fill it up only once.
1587 if (mac_special_menu_.size() == 0) {
1588 for (size_t i = 0 ; i < num_entries ; ++i) {
1589 FuncRequest const func(entries[i].action,
1590 from_utf8(entries[i].arg));
1591 mac_special_menu_.add(MenuItem(MenuItem::Command,
1592 entries[i].label, func));
1596 // add the entries to a QMenu that will eventually be empty
1597 // and therefore invisible.
1598 QMenu * qMenu = qmb->addMenu("special");
1599 MenuDefinition::const_iterator cit = mac_special_menu_.begin();
1600 MenuDefinition::const_iterator end = mac_special_menu_.end();
1601 for (size_t i = 0 ; cit != end ; ++cit, ++i) {
1602 Action * action = new Action(view, QIcon(), cit->label(),
1603 cit->func(), QString(), qMenu);
1604 action->setMenuRole(entries[i].role);
1605 qMenu->addAction(action);
1610 void Menus::Impl::expand(MenuDefinition const & frommenu,
1611 MenuDefinition & tomenu, BufferView const * bv) const
1613 if (!tomenu.empty())
1616 for (MenuDefinition::const_iterator cit = frommenu.begin();
1617 cit != frommenu.end() ; ++cit) {
1618 Buffer const * buf = bv ? &bv->buffer() : 0;
1619 switch (cit->kind()) {
1620 case MenuItem::Lastfiles:
1621 tomenu.expandLastfiles();
1624 case MenuItem::Documents:
1625 tomenu.expandDocuments();
1628 case MenuItem::Bookmarks:
1629 tomenu.expandBookmarks();
1632 case MenuItem::ImportFormats:
1633 case MenuItem::ViewFormats:
1634 case MenuItem::UpdateFormats:
1635 case MenuItem::ExportFormats:
1636 tomenu.expandFormats(cit->kind(), buf);
1639 case MenuItem::CharStyles:
1640 tomenu.expandFlexInsert(buf, InsetLayout::CHARSTYLE);
1643 case MenuItem::Custom:
1644 tomenu.expandFlexInsert(buf, InsetLayout::CUSTOM);
1647 case MenuItem::Elements:
1648 tomenu.expandFlexInsert(buf, InsetLayout::ELEMENT);
1651 case MenuItem::FloatListInsert:
1652 tomenu.expandFloatListInsert(buf);
1655 case MenuItem::FloatInsert:
1656 tomenu.expandFloatInsert(buf);
1659 case MenuItem::PasteRecent:
1660 tomenu.expandPasteRecent(buf);
1663 case MenuItem::Toolbars:
1664 tomenu.expandToolbars();
1667 case MenuItem::Branches:
1668 tomenu.expandBranches(buf);
1671 case MenuItem::Indices:
1672 tomenu.expandIndices(buf);
1675 case MenuItem::IndicesContext:
1676 tomenu.expandIndicesContext(buf);
1679 case MenuItem::IndicesLists:
1680 tomenu.expandIndices(buf, true);
1683 case MenuItem::IndicesListsContext:
1684 tomenu.expandIndicesContext(buf, true);
1687 case MenuItem::CiteStyles:
1688 tomenu.expandCiteStyles(bv);
1692 tomenu.expandToc(buf);
1695 case MenuItem::GraphicsGroups:
1696 tomenu.expandGraphicsGroups(bv);
1699 case MenuItem::SpellingSuggestions:
1700 tomenu.expandSpellingSuggestions(bv);
1703 case MenuItem::LanguageSelector:
1704 tomenu.expandLanguageSelector(buf);
1707 case MenuItem::Submenu: {
1708 MenuItem item(*cit);
1709 item.setSubmenu(MenuDefinition(cit->submenuname()));
1710 expand(getMenu(cit->submenuname()), item.submenu(), bv);
1711 tomenu.addWithStatusCheck(item);
1715 case MenuItem::Info:
1716 case MenuItem::Help:
1717 case MenuItem::Separator:
1718 tomenu.addWithStatusCheck(*cit);
1721 case MenuItem::Command:
1722 if (!mac_special_menu_.hasFunc(cit->func()))
1723 tomenu.addWithStatusCheck(*cit);
1727 // we do not want the menu to end with a separator
1728 if (!tomenu.empty() && tomenu.items_.back().kind() == MenuItem::Separator)
1729 tomenu.items_.pop_back();
1731 // Check whether the shortcuts are unique
1732 tomenu.checkShortcuts();
1736 bool Menus::Impl::hasMenu(QString const & name) const
1738 return find_if(menulist_.begin(), menulist_.end(),
1739 MenuNamesEqual(name)) != menulist_.end();
1743 MenuDefinition const & Menus::Impl::getMenu(QString const & name) const
1745 const_iterator cit = find_if(menulist_.begin(), menulist_.end(),
1746 MenuNamesEqual(name));
1747 if (cit == menulist_.end())
1748 LYXERR0("No submenu named " << name);
1749 LASSERT(cit != menulist_.end(), /**/);
1754 MenuDefinition & Menus::Impl::getMenu(QString const & name)
1756 iterator it = find_if(menulist_.begin(), menulist_.end(),
1757 MenuNamesEqual(name));
1758 if (it == menulist_.end())
1759 LYXERR0("No submenu named " << name);
1760 LASSERT(it != menulist_.end(), /**/);
1765 /////////////////////////////////////////////////////////////////////
1769 /////////////////////////////////////////////////////////////////////
1771 Menus::Menus() : d(new Impl) {}
1787 void Menus::read(Lexer & lex)
1795 LexerKeyword menutags[] = {
1796 { "end", md_endmenuset },
1797 { "menu", md_menu },
1798 { "menubar", md_menubar }
1801 // consistency check
1802 if (compare_ascii_no_case(lex.getString(), "menuset"))
1803 LYXERR0("Menus::read: ERROR wrong token: `" << lex.getString() << '\'');
1805 lex.pushTable(menutags);
1806 lex.setContext("Menus::read");
1810 while (lex.isOK() && !quit) {
1811 switch (lex.lex()) {
1813 d->menubar_.read(lex);
1817 QString const name = toqstr(lex.getDocString());
1818 if (d->hasMenu(name))
1819 d->getMenu(name).read(lex);
1821 MenuDefinition menu(name);
1823 d->menulist_.push_back(menu);
1831 lex.printError("Unknown menu tag");
1839 bool Menus::searchMenu(FuncRequest const & func,
1840 docstring_list & names) const
1842 MenuDefinition menu;
1843 d->expand(d->menubar_, menu, 0);
1844 return menu.searchMenu(func, names);
1848 void Menus::fillMenuBar(QMenuBar * qmb, GuiView * view, bool initial)
1852 // setup special mac specific menu items, but only do this
1853 // the first time a QMenuBar is created. Otherwise Qt will
1854 // create duplicate items in the application menu. It seems
1855 // that Qt does not remove them when the QMenubar is cleared.
1856 LYXERR(Debug::GUI, "Creating Mac OS X special menu bar");
1857 d->macxMenuBarInit(view, qmb);
1860 // Clear all menubar contents before filling it.
1864 LYXERR(Debug::GUI, "populating menu bar" << d->menubar_.name());
1866 if (d->menubar_.size() == 0) {
1867 LYXERR(Debug::GUI, "\tERROR: empty menu bar"
1868 << d->menubar_.name());
1871 LYXERR(Debug::GUI, "menu bar entries " << d->menubar_.size());
1873 MenuDefinition menu;
1874 BufferView * bv = 0;
1876 bv = view->currentBufferView();
1877 d->expand(d->menubar_, menu, bv);
1879 MenuDefinition::const_iterator m = menu.begin();
1880 MenuDefinition::const_iterator end = menu.end();
1882 for (; m != end; ++m) {
1884 if (m->kind() != MenuItem::Submenu) {
1885 LYXERR(Debug::GUI, "\tERROR: not a submenu " << m->label());
1889 LYXERR(Debug::GUI, "menu bar item " << m->label()
1890 << " is a submenu named " << m->submenuname());
1892 QString name = m->submenuname();
1893 if (!d->hasMenu(name)) {
1894 LYXERR(Debug::GUI, "\tERROR: " << name
1895 << " submenu has no menu!");
1899 Menu * menu = new Menu(view, m->submenuname(), true);
1900 menu->setTitle(label(*m));
1903 d->name_map_[view][name] = menu;
1908 void Menus::updateMenu(Menu * qmenu)
1910 LYXERR(Debug::GUI, "Triggered menu: " << qmenu->d->name);
1913 if (qmenu->d->name.isEmpty())
1916 if (!d->hasMenu(qmenu->d->name)) {
1917 qmenu->addAction(qt_("No Action Defined!"));
1918 LYXERR(Debug::GUI, "\tWARNING: non existing menu: "
1923 MenuDefinition const & fromLyxMenu = d->getMenu(qmenu->d->name);
1924 BufferView * bv = 0;
1926 bv = qmenu->d->view->currentBufferView();
1927 d->expand(fromLyxMenu, *qmenu->d->top_level_menu, bv);
1928 qmenu->d->populate(*qmenu, *qmenu->d->top_level_menu);
1932 Menu * Menus::menu(QString const & name, GuiView & view)
1934 LYXERR(Debug::GUI, "Context menu requested: " << name);
1935 Menu * menu = d->name_map_[&view].value(name, 0);
1936 if (!menu && !name.startsWith("context-")) {
1937 LYXERR0("requested context menu not found: " << name);
1941 menu = new Menu(&view, name, true);
1942 d->name_map_[&view][name] = menu;
1946 } // namespace frontend
1949 #include "moc_Menus.cpp"