+ }
+}
+
+
+void expandToc(Menu & tomenu, LyXView const * view)
+{
+ // To make things very cleanly, we would have to pass view 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)
+
+
+ Buffer const * buf = view->buffer();
+ if (!buf) {
+ tomenu.add(MenuItem(MenuItem::Command,
+ _("No Documents Open!"),
+ FuncRequest(LFUN_NOACTION)),
+ view);
+ return;
+ }
+
+ FloatList const & floatlist = buf->params().getLyXTextClass().floats();
+ lyx::toc::TocList toc_list = lyx::toc::getTocList(*buf);
+ lyx::toc::TocList::const_iterator cit = toc_list.begin();
+ lyx::toc::TocList::const_iterator end = toc_list.end();
+ for (; cit != end; ++cit) {
+ // Handle this later
+ if (cit->first == "TOC")
+ continue;
+
+ // All the rest is for floats
+ auto_ptr<Menu> menu(new Menu);
+ lyx::toc::Toc::const_iterator ccit = cit->second.begin();
+ lyx::toc::Toc::const_iterator eend = cit->second.end();
+ for (; ccit != eend; ++ccit) {
+ string 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("TOC");
+ if (cit == end) {
+ tomenu.add(MenuItem(MenuItem::Command,
+ _("No Table of contents"),
+ FuncRequest()),
+ view);
+ } else {
+ expandToc2(tomenu, cit->second, 0, cit->second.size(), 0);
+ }
+}
+
+
+void expandPasteRecent(Menu & tomenu, LyXView const * view)
+{
+ if (!view || !view->buffer())
+ return;
+
+ vector<string> const sel =
+ lyx::cap::availableSelections(*view->buffer());
+
+ vector<string>::const_iterator cit = sel.begin();
+ vector<string>::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 expandBranches(Menu & tomenu, LyXView const * view)
+{
+ if (!view || !view->buffer())
+ return;
+
+ BufferParams const & params = view->buffer()->getMasterBuffer()->params();
+
+ BranchList::const_iterator cit = params.branchlist().begin();
+ BranchList::const_iterator end = params.branchlist().end();
+
+ for (int ii = 1; cit != end; ++cit, ++ii) {
+ string label = cit->getBranch();
+ if (ii < 10)
+ label = convert<string>(ii) + ". " + label + "|" + convert<string>(ii);
+ tomenu.add(MenuItem(MenuItem::Command, label,
+ FuncRequest(LFUN_INSERT_BRANCH,
+ cit->getBranch())), view);
+ }
+}
+
+
+} // namespace anon
+
+
+void MenuBackend::expand(Menu const & frommenu, Menu & tomenu,
+ LyXView const * view) const
+{
+ for (Menu::const_iterator cit = frommenu.begin();
+ cit != frommenu.end() ; ++cit) {
+ switch (cit->kind()) {
+ case MenuItem::Lastfiles:
+ expandLastfiles(tomenu, view);
+ break;
+
+ case MenuItem::Documents:
+ expandDocuments(tomenu, view);
+ break;