+
+void expandToc(Menu & tomenu, Buffer const * buf)
+{
+ // To make things very cleanly, we would have to pass buf to
+ // all MenuItem constructors and to expandToc2. However, we
+ // know that all the entries in a TOC will be have status_ ==
+ // OK, so we avoid this unnecessary overhead (JMarc)
+
+ if (!buf) {
+ tomenu.add(MenuItem(MenuItem::Command,
+ _("No Documents Open!"),
+ FuncRequest(LFUN_NOACTION)));
+ return;
+ }
+
+ // Add an entry for the master doc if this is a child doc
+ Buffer const * const master = buf->getMasterBuffer();
+ if (buf != master) {
+ ParIterator const pit = par_iterator_begin(master->inset());
+ string const arg = convert<string>(pit->id());
+ FuncRequest f(LFUN_PARAGRAPH_GOTO, arg);
+ tomenu.add(MenuItem(MenuItem::Command, _("Master Document"), f));
+ }
+
+ FloatList const & floatlist = buf->params().getLyXTextClass().floats();
+ TocList const & toc_list = buf->tocBackend().tocs();
+ TocList::const_iterator cit = toc_list.begin();
+ TocList::const_iterator end = toc_list.end();
+ for (; cit != end; ++cit) {
+ // Handle this later
+ if (cit->first == "tableofcontents")
+ continue;
+
+ // All the rest is for floats
+ auto_ptr<Menu> menu(new Menu);
+ TocIterator ccit = cit->second.begin();
+ TocIterator eend = cit->second.end();
+ for (; ccit != eend; ++ccit) {
+ docstring const label = limit_string_length(ccit->str());
+ menu->add(MenuItem(MenuItem::Command,
+ label,
+ FuncRequest(ccit->action())));
+ }
+ string const & floatName = floatlist.getType(cit->first).listName();
+ MenuItem item(MenuItem::Submenu, _(floatName));
+ item.submenu(menu.release());
+ tomenu.add(item);
+ }
+
+ // Handle normal TOC
+ cit = toc_list.find("tableofcontents");
+ if (cit == end) {
+ tomenu.addWithStatusCheck(MenuItem(MenuItem::Command,
+ _("No Table of contents"),
+ FuncRequest()));
+ } else {
+ expandToc2(tomenu, cit->second, 0, cit->second.size(), 0);
+ }
+}
+
+
+void expandPasteRecent(Menu & tomenu, Buffer const * buf)
+{
+ if (!buf)
+ return;
+
+ vector<docstring> const sel =
+ cap::availableSelections(*buf);
+
+ vector<docstring>::const_iterator cit = sel.begin();
+ vector<docstring>::const_iterator end = sel.end();
+
+ for (unsigned int index = 0; cit != end; ++cit, ++index) {
+ tomenu.add(MenuItem(MenuItem::Command, *cit,
+ FuncRequest(LFUN_PASTE, convert<string>(index))));
+ }
+}
+
+
+void expandToolbars(Menu & tomenu)
+{
+ //
+ // extracts the toolbars from the backend
+ ToolbarBackend::Toolbars::const_iterator cit = toolbarbackend.begin();
+ ToolbarBackend::Toolbars::const_iterator end = toolbarbackend.end();
+
+ for (; cit != end; ++cit) {
+ docstring label = _(cit->gui_name);
+ // frontends are not supposed to turn on/off toolbars, if they cannot
+ // update ToolbarBackend::flags. That is to say, ToolbarsBackend::flags
+ // should reflect the true state of toolbars.
+ //
+ // menu is displayed as
+ // on/off review
+ // and
+ // review (auto)
+ // in the case of auto.
+ if (cit->flags & ToolbarBackend::AUTO)
+ label += _(" (auto)");
+ tomenu.add(MenuItem(MenuItem::Command, label,
+ FuncRequest(LFUN_TOOLBAR_TOGGLE_STATE, cit->name)));
+ }
+}
+
+
+void expandBranches(Menu & tomenu, Buffer const * buf)
+{
+ if (!buf)
+ return;
+
+ BufferParams const & params = buf->getMasterBuffer()->params();
+
+ BranchList::const_iterator cit = params.branchlist().begin();
+ BranchList::const_iterator end = params.branchlist().end();
+
+ for (int ii = 1; cit != end; ++cit, ++ii) {
+ docstring label = cit->getBranch();
+ if (ii < 10)
+ label = convert<docstring>(ii) + ". " + label + char_type('|') + convert<docstring>(ii);
+ tomenu.addWithStatusCheck(MenuItem(MenuItem::Command, label,
+ FuncRequest(LFUN_BRANCH_INSERT,
+ cit->getBranch())));
+ }
+}
+
+