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"
23 #include "GuiPopupMenu.h"
26 #include "BranchList.h"
28 #include "BufferList.h"
29 #include "BufferParams.h"
30 #include "Converter.h"
31 #include "CutAndPaste.h"
33 #include "FloatList.h"
37 #include "LyXAction.h"
38 #include "LyX.h" // for lastfiles
41 #include "Paragraph.h"
42 #include "TextClass.h"
43 #include "TocBackend.h"
44 #include "ToolbarBackend.h"
46 #include "frontends/Application.h"
48 #include "support/convert.h"
49 #include "support/debug.h"
50 #include "support/filetools.h"
51 #include "support/gettext.h"
52 #include "support/lstrings.h"
54 #include "qt_helpers.h"
63 using namespace lyx::support;
74 MenuNamesEqual(QString const & name) : name_(name) {}
75 bool operator()(Menu const & menu) const { return menu.name() == name_; }
82 // MacOSX specific stuff is at the end.
84 void Menus::fillMenuBar(GuiView * view)
86 // Clear all menubar contents before filling it.
87 view->menuBar()->clear();
90 // setup special mac specific menu item
91 macxMenuBarInit(view);
94 LYXERR(Debug::GUI, "populating menu bar" << fromqstr(getMenubar().name()));
96 if (getMenubar().size() == 0) {
97 LYXERR(Debug::GUI, "\tERROR: empty menu bar"
98 << fromqstr(getMenubar().name()));
102 LYXERR(Debug::GUI, "menu bar entries "
103 << getMenubar().size());
107 expand(getMenubar(), menu, view->buffer());
109 Menu::const_iterator m = menu.begin();
110 Menu::const_iterator end = menu.end();
112 for (; m != end; ++m) {
114 if (m->kind() != MenuItem::Submenu) {
115 LYXERR(Debug::GUI, "\tERROR: not a submenu " << fromqstr(m->label()));
119 LYXERR(Debug::GUI, "menu bar item " << fromqstr(m->label())
120 << " is a submenu named " << fromqstr(m->submenuname()));
122 QString name = m->submenuname();
123 if (!hasMenu(name)) {
124 LYXERR(Debug::GUI, "\tERROR: " << fromqstr(name)
125 << " submenu has no menu!");
129 GuiPopupMenu * qMenu = new GuiPopupMenu(view, *m, true);
130 view->menuBar()->addMenu(qMenu);
132 name_map_[name] = qMenu;
137 QMenu * Menus::menu(QString const & name)
139 LYXERR(Debug::GUI, "Context menu requested: " << fromqstr(name));
140 GuiPopupMenu * menu = name_map_.value(name, 0);
142 LYXERR0("resquested context menu not found: " << fromqstr(name));
147 /// Some special Qt/Mac support hacks
150 Here is what the Qt documentation says about how a menubar is chosen:
152 1) If the window has a QMenuBar then it is used. 2) If the window
153 is a modal then its menubar is used. If no menubar is specified
154 then a default menubar is used (as documented below) 3) If the
155 window has no parent then the default menubar is used (as
158 The above 3 steps are applied all the way up the parent window
159 chain until one of the above are satisifed. If all else fails a
160 default menubar will be created, the default menubar on Qt/Mac is
161 an empty menubar, however you can create a different default
162 menubar by creating a parentless QMenuBar, the first one created
163 will thus be designated the default menubar, and will be used
164 whenever a default menubar is needed.
166 Thus, for Qt/Mac, we add the menus to a free standing menubar, so
167 that this menubar will be used also when one of LyX' dialogs has
171 void Menus::macxMenuBarInit(GuiView * view)
173 // The Mac menubar initialisation must be done only once!
174 static bool done = false;
179 /* Since Qt 4.2, the qt/mac menu code has special code for
180 specifying the role of a menu entry. However, it does not
181 work very well with our scheme of creating menus on demand,
182 and therefore we need to put these entries in a special
183 invisible menu. (JMarc)
186 /* The entries of our special mac menu. If we add support for
187 * special entries in Menus, we could imagine something
189 * SpecialItem About " "About LyX" "dialog-show aboutlyx"
190 * and therefore avoid hardcoding. I am not sure it is worth
191 * the hassle, though. (JMarc)
193 struct MacMenuEntry {
197 QAction::MenuRole role;
200 MacMenuEntry entries[] = {
201 {LFUN_DIALOG_SHOW, "aboutlyx", "About LyX",
203 {LFUN_DIALOG_SHOW, "prefs", "Preferences",
204 QAction::PreferencesRole},
205 {LFUN_RECONFIGURE, "", "Reconfigure",
206 QAction::ApplicationSpecificRole},
207 {LFUN_LYX_QUIT, "", "Quit LyX", QAction::QuitRole}
209 const size_t num_entries = sizeof(entries) / sizeof(entries[0]);
211 // the special menu for Menus.
213 for (size_t i = 0 ; i < num_entries ; ++i) {
214 FuncRequest const func(entries[i].action,
215 from_utf8(entries[i].arg));
216 special.add(MenuItem(MenuItem::Command, entries[i].label, func));
218 setSpecialMenu(special);
220 // add the entries to a QMenu that will eventually be empty
221 // and therefore invisible.
222 QMenu * qMenu = view->menuBar()->addMenu("special");
224 // we do not use 'special' because it is a temporary variable,
225 // whereas Menus::specialMenu points to a persistent copy.
226 Menu::const_iterator cit = specialMenu().begin();
227 Menu::const_iterator end = specialMenu().end();
228 for (size_t i = 0 ; cit != end ; ++cit, ++i) {
229 Action * action = new Action(*view, QIcon(), cit->label(),
230 cit->func(), QString());
231 action->setMenuRole(entries[i].role);
232 qMenu->addAction(action);
237 MenuItem::MenuItem(Kind kind)
238 : kind_(kind), optional_(false)
242 MenuItem::MenuItem(Kind kind, QString const & label,
243 QString const & submenu, bool optional)
244 : kind_(kind), label_(label),
245 submenuname_(submenu), optional_(optional)
247 BOOST_ASSERT(kind == Submenu);
251 MenuItem::MenuItem(Kind kind, QString const & label,
252 FuncRequest const & func, bool optional)
253 : kind_(kind), label_(label), func_(func), optional_(optional)
255 func_.origin = FuncRequest::MENU;
259 MenuItem::~MenuItem()
263 void MenuItem::setSubmenu(Menu * menu)
265 submenu_.reset(menu);
269 QString MenuItem::label() const
271 return label_.split('|')[0];
275 QString MenuItem::shortcut() const
277 return label_.contains('|') ? label_.split('|')[1] : QString();
281 QString MenuItem::binding() const
283 if (kind_ != Command)
286 // Get the keys bound to this action, but keep only the
288 KeyMap::Bindings bindings = theTopLevelKeymap().findBindings(func_);
291 return toqstr(bindings.begin()->print(KeySequence::ForGui));
293 LYXERR(Debug::KBMAP, "No binding for "
294 << lyxaction.getActionName(func_.action)
295 << '(' << func_.argument() << ')');
300 void Menu::addWithStatusCheck(MenuItem const & i)
304 case MenuItem::Command: {
305 FuncStatus status = lyx::getStatus(i.func());
306 if (status.unknown() || (!status.enabled() && i.optional()))
309 items_.back().status(status);
313 case MenuItem::Submenu: {
315 bool enabled = false;
316 for (const_iterator cit = i.submenu()->begin();
317 cit != i.submenu()->end(); ++cit) {
318 if ((cit->kind() == MenuItem::Command
319 || cit->kind() == MenuItem::Submenu)
320 && cit->status().enabled()) {
325 if (enabled || !i.optional()) {
327 items_.back().status().enabled(enabled);
335 case MenuItem::Separator:
336 if (!items_.empty() && items_.back().kind() != MenuItem::Separator)
346 void Menu::read(Lexer & lex)
374 struct keyword_item menutags[md_last - 1] = {
375 { "bookmarks", md_bookmarks },
376 { "branches", md_branches },
377 { "charstyles", md_charstyles },
378 { "custom", md_custom },
379 { "documents", md_documents },
380 { "elements", md_elements },
381 { "end", md_endmenu },
382 { "exportformats", md_exportformats },
383 { "floatinsert", md_floatinsert },
384 { "floatlistinsert", md_floatlistinsert },
385 { "importformats", md_importformats },
387 { "lastfiles", md_lastfiles },
388 { "optitem", md_optitem },
389 { "optsubmenu", md_optsubmenu },
390 { "pasterecent", md_pasterecent },
391 { "separator", md_separator },
392 { "submenu", md_submenu },
394 { "toolbars", md_toolbars },
395 { "updateformats", md_updateformats },
396 { "viewformats", md_viewformats }
399 lex.pushTable(menutags, md_last - 1);
400 if (lyxerr.debugging(Debug::PARSER))
401 lex.printTable(lyxerr);
404 bool optional = false;
406 while (lex.isOK() && !quit) {
410 // fallback to md_item
413 docstring const name = translateIfPossible(lex.getDocString());
415 string const command = lex.getString();
416 FuncRequest func = lyxaction.lookupFunc(command);
417 add(MenuItem(MenuItem::Command, toqstr(name), func, optional));
423 add(MenuItem(MenuItem::Separator));
427 add(MenuItem(MenuItem::Lastfiles));
431 add(MenuItem(MenuItem::CharStyles));
435 add(MenuItem(MenuItem::Custom));
439 add(MenuItem(MenuItem::Elements));
443 add(MenuItem(MenuItem::Documents));
447 add(MenuItem(MenuItem::Bookmarks));
451 add(MenuItem(MenuItem::Toc));
455 add(MenuItem(MenuItem::ViewFormats));
458 case md_updateformats:
459 add(MenuItem(MenuItem::UpdateFormats));
462 case md_exportformats:
463 add(MenuItem(MenuItem::ExportFormats));
466 case md_importformats:
467 add(MenuItem(MenuItem::ImportFormats));
470 case md_floatlistinsert:
471 add(MenuItem(MenuItem::FloatListInsert));
475 add(MenuItem(MenuItem::FloatInsert));
479 add(MenuItem(MenuItem::PasteRecent));
483 add(MenuItem(MenuItem::Toolbars));
487 add(MenuItem(MenuItem::Branches));
492 // fallback to md_submenu
495 docstring const mlabel = translateIfPossible(lex.getDocString());
497 docstring const mname = lex.getDocString();
498 add(MenuItem(MenuItem::Submenu,
499 toqstr(mlabel), toqstr(mname), optional));
509 lex.printError("Menu::read: "
510 "Unknown menu tag: `$$Token'");
518 MenuItem const & Menu::operator[](size_type i) const
524 bool Menu::hasFunc(FuncRequest const & func) const
526 for (const_iterator it = begin(), et = end(); it != et; ++it)
527 if (it->func() == func)
533 void Menu::checkShortcuts() const
535 // This is a quadratic algorithm, but we do not care because
536 // menus are short enough
537 for (const_iterator it1 = begin(); it1 != end(); ++it1) {
538 QString shortcut = it1->shortcut();
539 if (shortcut.isEmpty())
541 if (!it1->label().contains(shortcut))
542 lyxerr << "Menu warning: menu entry \""
543 << fromqstr(it1->label())
544 << "\" does not contain shortcut `"
545 << fromqstr(shortcut) << "'." << endl;
546 for (const_iterator it2 = begin(); it2 != it1 ; ++it2) {
547 if (!it2->shortcut().compare(shortcut, Qt::CaseInsensitive)) {
548 lyxerr << "Menu warning: menu entries "
549 << '"' << fromqstr(it1->fulllabel())
550 << "\" and \"" << fromqstr(it2->fulllabel())
551 << "\" share the same shortcut."
559 bool Menu::searchMenu(FuncRequest const & func, vector<docstring> & names) const
561 const_iterator m = begin();
562 const_iterator m_end = end();
563 for (; m != m_end; ++m) {
564 if (m->kind() == MenuItem::Command && m->func() == func) {
565 names.push_back(qstring_to_ucs4(m->label()));
568 if (m->kind() == MenuItem::Submenu) {
569 names.push_back(qstring_to_ucs4(m->label()));
570 Menu const & submenu = *m->submenu();
571 if (submenu.searchMenu(func, names))
582 bool compareFormat(Format const * p1, Format const * p2)
588 QString limitStringLength(docstring const & str)
590 size_t const max_item_length = 45;
592 if (str.size() > max_item_length)
593 return toqstr(str.substr(0, max_item_length - 3) + "...");
601 void Menu::expandLastfiles()
603 LastFilesSection::LastFiles const & lf = LyX::cref().session().lastFiles().lastFiles();
604 LastFilesSection::LastFiles::const_iterator lfit = lf.begin();
608 for (; lfit != lf.end() && ii < 10; ++lfit, ++ii) {
609 string const file = lfit->absFilename();
610 QString const label = QString("%1. %2|%3").arg(ii)
611 .arg(toqstr(makeDisplayPath(file, 30))).arg(ii);
612 add(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_FILE_OPEN, file)));
617 void Menu::expandDocuments()
619 Buffer * first = theBufferList().first();
624 // We cannot use a for loop as the buffer list cycles.
626 QString label = toqstr(b->fileName().displayName(20));
630 label = QString::number(ii) + ". " + label + '|' + QString::number(ii);
631 add(MenuItem(MenuItem::Command, label,
632 FuncRequest(LFUN_BUFFER_SWITCH, b->absFileName())));
634 b = theBufferList().next(b);
636 } while (b != first);
638 add(MenuItem(MenuItem::Command, qt_("No Documents Open!"),
639 FuncRequest(LFUN_NOACTION)));
644 void Menu::expandBookmarks()
646 lyx::BookmarksSection const & bm = LyX::cref().session().bookmarks();
648 for (size_t i = 1; i <= bm.size(); ++i) {
650 string const file = bm.bookmark(i).filename.absFilename();
651 QString const label = QString("%1. %2|%3").arg(i)
652 .arg(toqstr(makeDisplayPath(file, 20))).arg(i);
653 add(MenuItem(MenuItem::Command, label,
654 FuncRequest(LFUN_BOOKMARK_GOTO, convert<docstring>(i))));
660 void Menu::expandFormats(MenuItem::Kind kind, Buffer const * buf)
662 if (!buf && kind != MenuItem::ImportFormats) {
663 add(MenuItem(MenuItem::Command,
664 qt_("No Document Open!"),
665 FuncRequest(LFUN_NOACTION)));
669 typedef vector<Format const *> Formats;
674 case MenuItem::ImportFormats:
675 formats = theConverters().importableFormats();
676 action = LFUN_BUFFER_IMPORT;
678 case MenuItem::ViewFormats:
679 formats = buf->exportableFormats(true);
680 action = LFUN_BUFFER_VIEW;
682 case MenuItem::UpdateFormats:
683 formats = buf->exportableFormats(true);
684 action = LFUN_BUFFER_UPDATE;
687 formats = buf->exportableFormats(false);
688 action = LFUN_BUFFER_EXPORT;
690 sort(formats.begin(), formats.end(), &compareFormat);
692 Formats::const_iterator fit = formats.begin();
693 Formats::const_iterator end = formats.end();
694 for (; fit != end ; ++fit) {
697 QString label = toqstr((*fit)->prettyname());
698 QString const shortcut = toqstr((*fit)->shortcut());
701 case MenuItem::ImportFormats:
702 // FIXME: This is a hack, we should rather solve
703 // FIXME: bug 2488 instead.
704 if ((*fit)->name() == "text")
705 label = qt_("Plain Text");
706 else if ((*fit)->name() == "textparagraph")
707 label = qt_("Plain Text, Join Lines");
710 case MenuItem::ViewFormats:
711 case MenuItem::ExportFormats:
712 case MenuItem::UpdateFormats:
713 if (!(*fit)->documentFormat())
720 // FIXME: if we had proper support for translating the
721 // format names defined in configure.py, there would
722 // not be a need to check whether the shortcut is
723 // correct. If we add it uncondiitonally, it would
724 // create useless warnings on bad shortcuts
725 if (!shortcut.isEmpty() && label.contains(shortcut))
726 label += '|' + shortcut;
729 addWithStatusCheck(MenuItem(MenuItem::Command, label,
730 FuncRequest(action, (*fit)->name())));
732 add(MenuItem(MenuItem::Command, label,
733 FuncRequest(action, (*fit)->name())));
738 void Menu::expandFloatListInsert(Buffer const * buf)
741 add(MenuItem(MenuItem::Command, qt_("No Document Open!"),
742 FuncRequest(LFUN_NOACTION)));
746 FloatList const & floats = buf->params().documentClass().floats();
747 FloatList::const_iterator cit = floats.begin();
748 FloatList::const_iterator end = floats.end();
749 for (; cit != end; ++cit) {
750 addWithStatusCheck(MenuItem(MenuItem::Command,
751 qt_(cit->second.listName()),
752 FuncRequest(LFUN_FLOAT_LIST,
753 cit->second.type())));
758 void Menu::expandFloatInsert(Buffer const * buf)
761 add(MenuItem(MenuItem::Command, qt_("No Document Open!"),
762 FuncRequest(LFUN_NOACTION)));
766 FloatList const & floats = buf->params().documentClass().floats();
767 FloatList::const_iterator cit = floats.begin();
768 FloatList::const_iterator end = floats.end();
769 for (; cit != end; ++cit) {
771 QString const label = qt_(cit->second.name());
772 addWithStatusCheck(MenuItem(MenuItem::Command, label,
773 FuncRequest(LFUN_FLOAT_INSERT,
774 cit->second.type())));
779 void Menu::expandFlexInsert(Buffer const * buf, string s)
782 add(MenuItem(MenuItem::Command, qt_("No Document Open!"),
783 FuncRequest(LFUN_NOACTION)));
786 TextClass::InsetLayouts const & insetLayouts =
787 buf->params().documentClass().insetLayouts();
788 TextClass::InsetLayouts::const_iterator cit = insetLayouts.begin();
789 TextClass::InsetLayouts::const_iterator end = insetLayouts.end();
790 for (; cit != end; ++cit) {
791 docstring const label = cit->first;
792 if (cit->second.lyxtype() == s)
793 addWithStatusCheck(MenuItem(MenuItem::Command,
794 toqstr(label), FuncRequest(LFUN_FLEX_INSERT,
800 size_t const max_number_of_items = 25;
802 void Menu::expandToc2(Toc const & toc_list,
803 size_t from, size_t to, int depth)
805 int shortcut_count = 0;
807 // check whether depth is smaller than the smallest depth in toc.
808 int min_depth = 1000;
809 for (size_t i = from; i < to; ++i)
810 min_depth = min(min_depth, toc_list[i].depth());
811 if (min_depth > depth)
814 if (to - from <= max_number_of_items) {
815 for (size_t i = from; i < to; ++i) {
816 QString label(4 * max(0, toc_list[i].depth() - depth), ' ');
817 label += limitStringLength(toc_list[i].str());
818 if (toc_list[i].depth() == depth
819 && shortcut_count < 9) {
820 if (label.contains(QString::number(shortcut_count + 1)))
821 label += '|' + QString::number(++shortcut_count);
823 add(MenuItem(MenuItem::Command, label,
824 FuncRequest(toc_list[i].action())));
829 size_t new_pos = pos + 1;
830 while (new_pos < to &&
831 toc_list[new_pos].depth() > depth)
834 QString label(4 * max(0, toc_list[pos].depth() - depth), ' ');
835 label += limitStringLength(toc_list[pos].str());
836 if (toc_list[pos].depth() == depth &&
837 shortcut_count < 9) {
838 if (label.contains(QString::number(shortcut_count + 1)))
839 label += '|' + QString::number(++shortcut_count);
841 if (new_pos == pos + 1) {
842 add(MenuItem(MenuItem::Command,
843 label, FuncRequest(toc_list[pos].action())));
845 MenuItem item(MenuItem::Submenu, label);
846 item.setSubmenu(new Menu);
847 item.submenu()->expandToc2(toc_list, pos, new_pos, depth + 1);
856 void Menu::expandToc(Buffer const * buf)
858 // To make things very cleanly, we would have to pass buf to
859 // all MenuItem constructors and to expandToc2. However, we
860 // know that all the entries in a TOC will be have status_ ==
861 // OK, so we avoid this unnecessary overhead (JMarc)
864 add(MenuItem(MenuItem::Command, qt_("No Document Open!"),
865 FuncRequest(LFUN_NOACTION)));
869 Buffer* cbuf = const_cast<Buffer*>(buf);
870 cbuf->tocBackend().update();
871 cbuf->structureChanged();
873 // Add an entry for the master doc if this is a child doc
874 Buffer const * const master = buf->masterBuffer();
876 ParIterator const pit = par_iterator_begin(master->inset());
877 string const arg = convert<string>(pit->id());
878 FuncRequest f(LFUN_PARAGRAPH_GOTO, arg);
879 add(MenuItem(MenuItem::Command, qt_("Master Document"), f));
882 FloatList const & floatlist = buf->params().documentClass().floats();
883 TocList const & toc_list = buf->tocBackend().tocs();
884 TocList::const_iterator cit = toc_list.begin();
885 TocList::const_iterator end = toc_list.end();
886 for (; cit != end; ++cit) {
888 if (cit->first == "tableofcontents")
891 // All the rest is for floats
892 auto_ptr<Menu> menu(new Menu);
893 TocIterator ccit = cit->second.begin();
894 TocIterator eend = cit->second.end();
895 for (; ccit != eend; ++ccit) {
896 QString const label = limitStringLength(ccit->str());
897 menu->add(MenuItem(MenuItem::Command, label,
898 FuncRequest(ccit->action())));
900 string const & floatName = floatlist.getType(cit->first).listName();
902 if (!floatName.empty())
903 label = qt_(floatName);
904 // BUG3633: listings is not a proper float so its name
905 // is not shown in floatlist.
906 else if (cit->first == "equation")
907 label = qt_("List of Equations");
908 else if (cit->first == "index")
909 label = qt_("List of Indexes");
910 else if (cit->first == "listing")
911 label = qt_("List of Listings");
912 else if (cit->first == "marginalnote")
913 label = qt_("List of Marginal notes");
914 else if (cit->first == "note")
915 label = qt_("List of Notes");
916 else if (cit->first == "footnote")
917 label = qt_("List of Foot notes");
918 else if (cit->first == "label")
919 label = qt_("Labels and References");
920 else if (cit->first == "citation")
921 label = qt_("List of Citations");
922 // this should not happen now, but if something else like
923 // listings is added later, this can avoid an empty menu name.
925 label = qt_("Other floats");
926 MenuItem item(MenuItem::Submenu, label);
927 item.setSubmenu(menu.release());
932 cit = toc_list.find("tableofcontents");
934 addWithStatusCheck(MenuItem(MenuItem::Command,
935 qt_("No Table of contents"),
938 expandToc2(cit->second, 0, cit->second.size(), 0);
943 void Menu::expandPasteRecent()
945 vector<docstring> const sel = cap::availableSelections();
947 vector<docstring>::const_iterator cit = sel.begin();
948 vector<docstring>::const_iterator end = sel.end();
950 for (unsigned int index = 0; cit != end; ++cit, ++index) {
951 add(MenuItem(MenuItem::Command, toqstr(*cit),
952 FuncRequest(LFUN_PASTE, convert<string>(index))));
957 void Menu::expandToolbars()
960 // extracts the toolbars from the backend
961 ToolbarBackend::Toolbars::const_iterator cit = toolbarbackend.begin();
962 ToolbarBackend::Toolbars::const_iterator end = toolbarbackend.end();
964 for (; cit != end; ++cit) {
965 QString label = qt_(cit->gui_name);
966 // frontends are not supposed to turn on/off toolbars,
967 // if they cannot update ToolbarBackend::flags. That
968 // is to say, ToolbarsBackend::flags should reflect
969 // the true state of toolbars.
971 // menu is displayed as
975 // in the case of auto.
976 if (cit->flags & ToolbarInfo::AUTO)
977 label += qt_(" (auto)");
978 add(MenuItem(MenuItem::Command, label,
979 FuncRequest(LFUN_TOOLBAR_TOGGLE, cit->name + " allowauto")));
984 void Menu::expandBranches(Buffer const * buf)
987 add(MenuItem(MenuItem::Command,
988 qt_("No Document Open!"),
989 FuncRequest(LFUN_NOACTION)));
993 BufferParams const & params = buf->masterBuffer()->params();
994 if (params.branchlist().empty()) {
995 add(MenuItem(MenuItem::Command,
996 qt_("No Branch in Document!"),
997 FuncRequest(LFUN_NOACTION)));
1001 BranchList::const_iterator cit = params.branchlist().begin();
1002 BranchList::const_iterator end = params.branchlist().end();
1004 for (int ii = 1; cit != end; ++cit, ++ii) {
1005 docstring label = cit->getBranch();
1007 label = convert<docstring>(ii) + ". " + label + char_type('|') + convert<docstring>(ii);
1008 addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(label),
1009 FuncRequest(LFUN_BRANCH_INSERT,
1010 cit->getBranch())));
1015 void Menus::expand(Menu const & frommenu, Menu & tomenu,
1016 Buffer const * buf) const
1018 if (!tomenu.empty())
1021 for (Menu::const_iterator cit = frommenu.begin();
1022 cit != frommenu.end() ; ++cit) {
1023 switch (cit->kind()) {
1024 case MenuItem::Lastfiles:
1025 tomenu.expandLastfiles();
1028 case MenuItem::Documents:
1029 tomenu.expandDocuments();
1032 case MenuItem::Bookmarks:
1033 tomenu.expandBookmarks();
1036 case MenuItem::ImportFormats:
1037 case MenuItem::ViewFormats:
1038 case MenuItem::UpdateFormats:
1039 case MenuItem::ExportFormats:
1040 tomenu.expandFormats(cit->kind(), buf);
1043 case MenuItem::CharStyles:
1044 tomenu.expandFlexInsert(buf, "charstyle");
1047 case MenuItem::Custom:
1048 tomenu.expandFlexInsert(buf, "custom");
1051 case MenuItem::Elements:
1052 tomenu.expandFlexInsert(buf, "element");
1055 case MenuItem::FloatListInsert:
1056 tomenu.expandFloatListInsert(buf);
1059 case MenuItem::FloatInsert:
1060 tomenu.expandFloatInsert(buf);
1063 case MenuItem::PasteRecent:
1064 tomenu.expandPasteRecent();
1067 case MenuItem::Toolbars:
1068 tomenu.expandToolbars();
1071 case MenuItem::Branches:
1072 tomenu.expandBranches(buf);
1076 tomenu.expandToc(buf);
1079 case MenuItem::Submenu: {
1080 MenuItem item(*cit);
1081 item.setSubmenu(new Menu(cit->submenuname()));
1082 expand(getMenu(cit->submenuname()),
1083 *item.submenu(), buf);
1084 tomenu.addWithStatusCheck(item);
1088 case MenuItem::Separator:
1089 tomenu.addWithStatusCheck(*cit);
1092 case MenuItem::Command:
1093 if (!specialmenu_.hasFunc(cit->func()))
1094 tomenu.addWithStatusCheck(*cit);
1098 // we do not want the menu to end with a separator
1100 && tomenu.items_.back().kind() == MenuItem::Separator)
1101 tomenu.items_.pop_back();
1103 // Check whether the shortcuts are unique
1104 tomenu.checkShortcuts();
1108 void Menus::read(Lexer & lex)
1117 struct keyword_item menutags[md_last - 1] = {
1118 { "end", md_endmenuset },
1119 { "menu", md_menu },
1120 { "menubar", md_menubar }
1124 if (compare_ascii_no_case(lex.getString(), "menuset")) {
1125 lyxerr << "Menubackend::read: ERROR wrong token:`"
1126 << lex.getString() << '\'' << endl;
1129 lex.pushTable(menutags, md_last - 1);
1130 if (lyxerr.debugging(Debug::PARSER))
1131 lex.printTable(lyxerr);
1135 while (lex.isOK() && !quit) {
1136 switch (lex.lex()) {
1142 QString const name = toqstr(lex.getDocString());
1143 if (hasMenu(name)) {
1144 getMenu(name).read(lex);
1156 lex.printError("menubackend::read: "
1157 "Unknown menu tag: `$$Token'");
1165 void Menus::add(Menu const & menu)
1167 menulist_.push_back(menu);
1171 bool Menus::hasMenu(QString const & name) const
1173 return find_if(begin(), end(), MenuNamesEqual(name)) != end();
1177 Menu const & Menus::getMenu(QString const & name) const
1179 const_iterator cit = find_if(begin(), end(), MenuNamesEqual(name));
1181 lyxerr << "No submenu named " << fromqstr(name) << endl;
1182 BOOST_ASSERT(cit != end());
1187 Menu & Menus::getMenu(QString const & name)
1189 iterator it = find_if(begin(), end(), MenuNamesEqual(name));
1191 lyxerr << "No submenu named " << fromqstr(name) << endl;
1192 BOOST_ASSERT(it != end());
1197 Menu const & Menus::getMenubar() const
1203 } // namespace frontend
1206 #include "Menus_moc.cpp"