+ case InsetInfoParams::MENU_INFO: {
+ // only need to do this once.
+ if (initialized_)
+ break;
+ docstring_list names;
+ FuncRequest func = lyxaction.lookupFunc(params_.name);
+ if (func.action() == LFUN_UNKNOWN_ACTION) {
+ gui = _("Unknown action %1$s");
+ error(from_ascii("Unknown action %1$s"), params_.lang);
+ break;
+ }
+ if (func.action() == LFUN_BUFFER_VIEW || func.action() == LFUN_BUFFER_UPDATE)
+ // The default output format is in the menu without argument,
+ // so strip it here.
+ if (func.argument() == from_ascii(buffer().params().getDefaultOutputFormat()))
+ func = FuncRequest(func.action());
+ // iterate through the menubackend to find it
+ if (!theApp()) {
+ gui = _("Can't determine menu entry for action %1$s in batch mode");
+ error(from_ascii("Can't determine menu entry for action %1$s in batch mode"), params_.lang);
+ initialized_ = true;
+ break;
+ }
+ // and we will not keep trying if we fail
+ initialized_ = theApp()->hasBufferView();
+ if (!theApp()->searchMenu(func, names)) {
+ gui = _("No menu entry for action %1$s");
+ error(from_ascii("No menu entry for action %1$s"), params_.lang);
+ break;
+ }
+ // if found, return its path.
+ clear();
+ Paragraph & par = paragraphs().front();
+ Font const f(inherit_font, guilang);
+ params_.force_ltr = !guilang->rightToLeft();
+ //Font fu = f;
+ //fu.fontInfo().setUnderbar(FONT_ON);
+ for (docstring const & name : names) {
+ // do not insert > for the top level menu item
+ if (&name != &names.front())
+ par.insertInset(par.size(), new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR),
+ f, Change(Change::UNCHANGED));
+ //FIXME: add proper underlines here. This
+ // involves rewriting searchMenu used above to
+ // return a vector of menus. If we do not do
+ // that, we might as well use below
+ // Paragraph::insert on each string (JMarc)
+ for (char_type c : name)
+ par.insertChar(par.size(), c, f, Change(Change::UNCHANGED));
+ }
+ break;
+ }
+ case InsetInfoParams::L7N_INFO: {
+ docstring locstring = _(params_.name);
+ // Remove trailing colons
+ locstring = rtrim(locstring, ":");
+ // Remove menu accelerators
+ if (contains(locstring, from_ascii("|"))) {
+ docstring nlocstring;
+ rsplit(locstring, nlocstring, '|');
+ locstring = nlocstring;
+ }
+ // Remove Qt accelerators, but keep literal ampersands
+ locstring = subst(locstring, from_ascii(" & "), from_ascii("</amp;>"));
+ locstring = subst(locstring, from_ascii("&"), docstring());
+ locstring = subst(locstring, from_ascii("</amp;>"), from_ascii(" & "));
+ setText(locstring, guilang);
+ params_.force_ltr = !guilang->rightToLeft() && !params_.lang->rightToLeft();
+ break;
+ }
+ case InsetInfoParams::ICON_INFO: {
+ // only need to do this once.
+ if (initialized_)
+ break;
+ // and we will not keep trying if we fail
+ initialized_ = true;
+ FuncRequest func = lyxaction.lookupFunc(params_.name);
+ docstring icon_name = frontend::Application::iconName(func, true);
+ FileName file(to_utf8(icon_name));
+ if (file.onlyFileNameWithoutExt() == "unknown") {
+ string dir = "images";
+ FileName file2(imageLibFileSearch(dir, params_.name, "svgz,png"));
+ if (!file2.empty())
+ file = file2;
+ }
+ if (!file.exists())
+ break;
+ int percent_scale = 100;
+ if (use_gui) {
+ // Compute the scale factor for the icon such that its
+ // width on screen is equal to 1em in pixels.
+ // The scale factor is rounded to the integer nearest
+ // to the float value of the ratio 100*iconsize/imgsize.
+ int imgsize = QImage(toqstr(file.absFileName())).width();
+ if (imgsize > 0) {
+ int iconsize = Length(1, Length::EM).inPixels(1);
+ percent_scale = (100 * iconsize + imgsize / 2)/imgsize;
+ }
+ }
+ InsetGraphicsTight * inset = new InsetGraphicsTight(buffer_);
+ InsetGraphicsParams igp;
+ igp.filename = file;
+ igp.lyxscale = percent_scale;
+ igp.scale = string();
+ igp.width = Length(1, Length::EM);
+ if (contains(file.absoluteFilePath(), from_ascii("math"))
+ || contains(file.absoluteFilePath(), from_ascii("ert-insert"))
+ || suffixIs(file.onlyPath().absoluteFilePath(), from_ascii("ipa")))
+ igp.darkModeSensitive = true;
+ inset->setParams(igp);
+ clear();
+ Font const f(inherit_font, params_.lang);
+ paragraphs().front().insertInset(0, inset, f,
+ Change(Change::UNCHANGED));
+ break;
+ }
+ case InsetInfoParams::BUFFER_INFO: {
+ // this could all change, so we will recalculate each time
+ if (params_.name == "name")
+ setText(from_utf8(buffer().fileName().onlyFileName()), params_.lang);
+ else if (params_.name == "name-noext")
+ setText(from_utf8(buffer().fileName().onlyFileNameWithoutExt()), params_.lang);
+ else if (params_.name == "path")
+ setText(from_utf8(os::latex_path(buffer().filePath())), params_.lang);
+ else if (params_.name == "class")
+ setText(from_utf8(buffer().params().documentClass().name()), params_.lang);
+ break;
+ }
+ case InsetInfoParams::VCS_INFO: {
+ // this information could change, in principle, so we will
+ // recalculate each time through
+ if (!buffer().lyxvc().inUse()) {
+ gui = _("No version control!");
+ info(from_ascii("No version control!"), params_.lang);
+ break;
+ }
+ LyXVC::RevisionInfo itype = LyXVC::Unknown;
+ if (params_.name == "revision")
+ itype = LyXVC::File;
+ else if (params_.name == "revision-abbrev")
+ itype = LyXVC::FileAbbrev;
+ else if (params_.name == "tree-revision")
+ itype = LyXVC::Tree;
+ else if (params_.name == "author")
+ itype = LyXVC::Author;
+ else if (params_.name == "time")
+ itype = LyXVC::Time;
+ else if (params_.name == "date")
+ itype = LyXVC::Date;
+ string binfo = buffer().lyxvc().revisionInfo(itype);
+ if (binfo.empty()) {
+ gui = _("%1$s[[vcs data]] unknown");
+ error(from_ascii("%1$s[[vcs data]] unknown"), params_.lang);
+ } else
+ setText(from_utf8(binfo), params_.lang);
+ break;
+ }
+ case InsetInfoParams::LYX_INFO:
+ // only need to do this once.
+ if (initialized_)
+ break;
+ if (params_.name == "version")
+ setText(from_ascii(lyx_version), params_.lang);
+ else if (params_.name == "layoutformat")
+ setText(convert<docstring>(LAYOUT_FORMAT), params_.lang);
+ initialized_ = true;
+ break;
+ case InsetInfoParams::DATE_INFO:
+ case InsetInfoParams::MODDATE_INFO:
+ case InsetInfoParams::FIXDATE_INFO: {
+ string date_format = params_.name;
+ string const date_specifier = (params_.type == InsetInfoParams::FIXDATE_INFO
+ && contains(params_.name, '@'))
+ ? split(params_.name, date_format, '@') : string();
+ QDate date;
+ if (params_.type == InsetInfoParams::MODDATE_INFO)
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
+ date = QDateTime::fromSecsSinceEpoch(buffer().fileName().lastModified()).date();
+#else
+ date = QDateTime::fromTime_t(buffer().fileName().lastModified()).date();
+#endif
+ else if (params_.type == InsetInfoParams::FIXDATE_INFO && !date_specifier.empty())
+ date = QDate::fromString(toqstr(date_specifier), Qt::ISODate);
+ else
+ date = QDate::currentDate();
+ setText(params_.getDate(date_format, date), params_.lang);
+ break;
+ }
+ case InsetInfoParams::TIME_INFO:
+ case InsetInfoParams::MODTIME_INFO:
+ case InsetInfoParams::FIXTIME_INFO: {
+ string time_format = params_.name;
+ string const time_specifier = (params_.type == InsetInfoParams::FIXTIME_INFO
+ && contains(params_.name, '@'))
+ ? split(params_.name, time_format, '@') : string();
+ QTime time;
+ if (params_.type == InsetInfoParams::MODTIME_INFO)
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
+ time = QDateTime::fromSecsSinceEpoch(buffer().fileName().lastModified()).time();
+#else
+ time = QDateTime::fromTime_t(buffer().fileName().lastModified()).time();
+#endif
+ else if (params_.type == InsetInfoParams::FIXTIME_INFO && !time_specifier.empty())
+ time = QTime::fromString(toqstr(time_specifier), Qt::ISODate);
+ else
+ time = QTime::currentTime();
+ setText(params_.getTime(time_format, time), params_.lang);
+ break;