+ string::size_type const max_item_length = 45;
+
+ if (str.size() > max_item_length)
+ return str.substr(0, max_item_length - 3) + "...";
+ else
+ return str;
+}
+
+
+void expandLastfiles(Menu & tomenu, LyXView const * view)
+{
+ LastFiles const & lastfiles = LyX::cref().lastfiles();
+
+ int ii = 1;
+ LastFiles::const_iterator lfit = lastfiles.begin();
+ LastFiles::const_iterator end = lastfiles.end();
+
+ for (; lfit != end && ii < 10; ++lfit, ++ii) {
+ string const label = tostr(ii) + ". "
+ + MakeDisplayPath((*lfit), 30)
+ + '|' + tostr(ii);
+ tomenu.add(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_FILE_OPEN, (*lfit))), view);
+ }
+}
+
+void expandDocuments(Menu & tomenu, LyXView const * view)
+{
+ typedef vector<string> Strings;
+ Strings const names = bufferlist.getFileNames();
+
+ if (names.empty()) {
+ tomenu.add(MenuItem(MenuItem::Command, _("No Documents Open!"),
+ FuncRequest(LFUN_NOACTION)), view);
+ return;
+ }
+
+ int ii = 1;
+ Strings::const_iterator docit = names.begin();
+ Strings::const_iterator end = names.end();
+ for (; docit != end; ++docit, ++ii) {
+ string label = MakeDisplayPath(*docit, 20);
+ if (ii < 10)
+ label = tostr(ii) + ". " + label + '|' + tostr(ii);
+ tomenu.add(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_SWITCHBUFFER, *docit)), view);
+ }
+}
+
+
+void expandFormats(MenuItem::Kind kind, Menu & tomenu, LyXView const * view)
+{
+ if (!view->buffer() && kind != MenuItem::ImportFormats) {
+ tomenu.add(MenuItem(MenuItem::Command,
+ _("No Documents Open!"),
+ FuncRequest(LFUN_NOACTION)),
+ view);
+ return;
+ }
+
+ typedef vector<Format const *> Formats;
+ Formats formats;
+ kb_action action;
+
+ switch (kind) {
+ case MenuItem::ImportFormats:
+ formats = Importer::GetImportableFormats();
+ action = LFUN_IMPORT;
+ break;
+ case MenuItem::ViewFormats:
+ formats = Exporter::GetExportableFormats(*view->buffer(), true);
+ action = LFUN_PREVIEW;
+ break;
+ case MenuItem::UpdateFormats:
+ formats = Exporter::GetExportableFormats(*view->buffer(), true);
+ action = LFUN_UPDATE;
+ break;
+ default:
+ formats = Exporter::GetExportableFormats(*view->buffer(), false);
+ action = LFUN_EXPORT;
+ }
+ sort(formats.begin(), formats.end(), compare_format());
+
+ Formats::const_iterator fit = formats.begin();
+ Formats::const_iterator end = formats.end();
+ for (; fit != end ; ++fit) {
+ if ((*fit)->dummy())
+ continue;
+ string label = (*fit)->prettyname();
+ // we need to hide the default graphic export formats
+ // from the external menu, because we need them only
+ // for the internal lyx-view and external latex run
+ if (label == "EPS" || label == "XPM" || label == "PNG")
+ continue;
+
+ if (kind == MenuItem::ImportFormats) {
+ if ((*fit)->name() == "text")
+ label = _("ASCII text as lines");
+ else if ((*fit)->name() == "textparagraph")
+ label = _("ASCII text as paragraphs");
+ label += "...";
+ }
+ if (!(*fit)->shortcut().empty())
+ label += '|' + (*fit)->shortcut();
+
+ tomenu.add(MenuItem(MenuItem::Command, label,
+ FuncRequest(action, (*fit)->name())),
+ view);
+ }
+}
+
+
+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_INSET_FLOAT,
+ 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_INSERT_CHARSTYLE,
+ 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;
+ 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(tostr(shortcut_count + 1)) != string::npos)
+ label += '|' + tostr(++shortcut_count);