+void add_toc2(int menu, string const & extra_label,
+ vector<int> & smn, Window win,
+ vector<Buffer::TocItem> const & toc_list,
+ size_type from, size_type to, int depth)
+{
+ int shortcut_count = 0;
+ if (to - from <= max_number_of_items) {
+ for (size_type i = from; i < to; ++i) {
+ int const action = lyxaction.
+ getPseudoAction(LFUN_GOTO_PARAGRAPH,
+ tostr(toc_list[i].par->id()));
+ string label(4 * max(0, toc_list[i].depth - depth),' ');
+ label += fixlabel(toc_list[i].str);
+ label = limit_string_length(label);
+ label += "%x" + tostr(action + action_offset);
+ if (i == to - 1 && depth == 0)
+ label += extra_label;
+ if (toc_list[i].depth == depth
+ && ++shortcut_count <= 9) {
+ label += "%h";
+ fl_addtopup(menu, label.c_str(),
+ tostr(shortcut_count).c_str());
+ } else
+ fl_addtopup(menu, label.c_str());
+ }
+ } else {
+ size_type pos = from;
+ size_type count = 0;
+ while (pos < to) {
+ ++count;
+ if (count > max_number_of_items) {
+ int menu2 = get_new_submenu(smn, win);
+ add_toc2(menu2, extra_label, smn, win,
+ toc_list, pos, to, depth);
+ string label = _("More");
+ label += "...%m";
+ if (depth == 0)
+ label += extra_label;
+ fl_addtopup(menu, label.c_str(), menu2);
+ break;
+ }
+ size_type new_pos = pos+1;
+ while (new_pos < to &&
+ toc_list[new_pos].depth > depth)
+ ++new_pos;
+
+ int const action = lyxaction.
+ getPseudoAction(LFUN_GOTO_PARAGRAPH,
+ tostr(toc_list[pos].par->id()));
+ string label(4 * max(0, toc_list[pos].depth - depth), ' ');
+ label += fixlabel(toc_list[pos].str);
+ label = limit_string_length(label);
+ if (new_pos == to && depth == 0)
+ label += extra_label;
+ string shortcut;
+ if (toc_list[pos].depth == depth &&
+ ++shortcut_count <= 9)
+ shortcut = tostr(shortcut_count);
+
+ if (new_pos == pos + 1) {
+ label += "%x" + tostr(action + action_offset);
+ if (!shortcut.empty()) {
+ label += "%h";
+ fl_addtopup(menu, label.c_str(),
+ shortcut.c_str());
+ } else
+ fl_addtopup(menu, label.c_str());
+ } else {
+ int menu2 = get_new_submenu(smn, win);
+ add_toc2(menu2, extra_label, smn, win,
+ toc_list, pos, new_pos, depth+1);
+ label += "%m";
+ if (!shortcut.empty()) {
+ label += "%h";
+ fl_addtopup(menu, label.c_str(), menu2,
+ shortcut.c_str());
+ } else
+ fl_addtopup(menu, label.c_str(), menu2);
+ }
+ pos = new_pos;
+ }
+ }