+void expandFloatListInsert(Menu & tomenu, LyXView const * view)
+{
+ if (!view->buffer()) {
+ tomenu.add(MenuItem(MenuItem::Command,
+ _("No Documents Open!"),
+ FuncRequest(LFUN_NOACTION)),
+ view);
+ return;
+ }
+
+ FloatList const & floats =
+ view->buffer()->params().getLyXTextClass().floats();
+ FloatList::const_iterator cit = floats.begin();
+ FloatList::const_iterator end = floats.end();
+ for (; cit != end; ++cit) {
+ tomenu.add(MenuItem(MenuItem::Command,
+ _(cit->second.listName()),
+ FuncRequest(LFUN_FLOAT_LIST,
+ cit->second.type())),
+ view);
+ }
+}
+
+
+void expandFloatInsert(Menu & tomenu, LyXView const * view)
+{
+ if (!view->buffer()) {
+ tomenu.add(MenuItem(MenuItem::Command,
+ _("No Documents Open!"),
+ FuncRequest(LFUN_NOACTION)),
+ view);
+ return;
+ }
+
+ FloatList const & floats =
+ view->buffer()->params().getLyXTextClass().floats();
+ FloatList::const_iterator cit = floats.begin();
+ FloatList::const_iterator end = floats.end();
+ for (; cit != end; ++cit) {
+ // normal float
+ string const label = _(cit->second.name());
+ tomenu.add(MenuItem(MenuItem::Command, label,
+ FuncRequest(LFUN_FLOAT_INSERT,
+ cit->second.type())),
+ view);
+ }
+}
+
+
+void expandCharStyleInsert(Menu & tomenu, LyXView const * view)
+{
+ if (!view->buffer()) {
+ tomenu.add(MenuItem(MenuItem::Command,
+ _("No Documents Open!"),
+ FuncRequest(LFUN_NOACTION)),
+ view);
+ return;
+ }
+ CharStyles & charstyles =
+ view->buffer()->params().getLyXTextClass().charstyles();
+ CharStyles::iterator cit = charstyles.begin();
+ CharStyles::iterator end = charstyles.end();
+ for (; cit != end; ++cit) {
+ string const label = cit->name;
+ tomenu.add(MenuItem(MenuItem::Command, label,
+ FuncRequest(LFUN_CHARSTYLE_INSERT,
+ cit->name)), view);
+ }
+}
+
+
+Menu::size_type const max_number_of_items = 25;
+
+void expandToc2(Menu & tomenu,
+ lyx::toc::Toc const & toc_list,
+ lyx::toc::Toc::size_type from,
+ lyx::toc::Toc::size_type to, int depth)
+{
+ int shortcut_count = 0;
+
+ // check whether depth is smaller than the smallest depth in toc.
+ int min_depth = 1000;
+ for (lyx::toc::Toc::size_type i = from; i < to; ++i)
+ min_depth = std::min(min_depth, toc_list[i].depth());
+ if (min_depth > depth)
+ depth = min_depth;
+
+
+ if (to - from <= max_number_of_items) {
+ for (lyx::toc::Toc::size_type i = from; i < to; ++i) {
+ string label(4 * max(0, toc_list[i].depth() - depth),' ');
+ label += limit_string_length(toc_list[i].str());
+ if (toc_list[i].depth() == depth
+ && shortcut_count < 9) {
+ if (label.find(convert<string>(shortcut_count + 1)) != string::npos)
+ label += '|' + convert<string>(++shortcut_count);
+ }
+ tomenu.add(MenuItem(MenuItem::Command, label,
+ FuncRequest(toc_list[i].action())));
+ }
+ } else {
+ lyx::toc::Toc::size_type pos = from;
+ while (pos < to) {
+ lyx::toc::Toc::size_type new_pos = pos + 1;
+ while (new_pos < to &&
+ toc_list[new_pos].depth() > depth)
+ ++new_pos;
+
+ string label(4 * max(0, toc_list[pos].depth() - depth), ' ');
+ label += limit_string_length(toc_list[pos].str());
+ if (toc_list[pos].depth() == depth &&
+ shortcut_count < 9) {
+ if (label.find(convert<string>(shortcut_count + 1)) != string::npos)
+ label += '|' + convert<string>(++shortcut_count);
+ }
+ if (new_pos == pos + 1) {