+ if (cmd.getArg(0) == "toggleparam") {
+ string cmdname = getCmdName();
+ string const alias =
+ buffer().masterParams().getCiteAlias(cmdname);
+ if (!alias.empty())
+ cmdname = alias;
+ string const par = cmd.getArg(1);
+ string newcmdname = cmdname;
+ if (par == "star") {
+ if (suffixIs(cmdname, "*"))
+ newcmdname = rtrim(cmdname, "*");
+ else
+ newcmdname = cmdname + "*";
+ } else if (par == "casing") {
+ if (isUpperCase(cmdname[0]))
+ newcmdname[0] = lowercase(cmdname[0]);
+ else
+ newcmdname[0] = uppercase(newcmdname[0]);
+ }
+ cmd = FuncRequest(LFUN_INSET_MODIFY, "changetype " + newcmdname);
+ }
+ }
+ // fall through
+ default:
+ InsetCommand::doDispatch(cur, cmd);
+ if (cmd.action() == LFUN_INSET_MODIFY)
+ cleanKeys();
+ }
+}
+
+bool InsetCitation::openCitationPossible() const
+{
+ Buffer const & buf = *buffer_;
+ // only after the buffer is loaded from file...
+ if (!buf.isFullyLoaded())
+ return false;
+
+ BiblioInfo const & bi = buf.masterBibInfo();
+ if (bi.empty())
+ return false;
+
+ docstring const & key = getParam("key");
+ if (key.empty())
+ return false;
+
+ // does bibtex item contains some locator?
+ vector<docstring> keys = getVectorFromString(key);
+ docstring doi, url, file;
+ for (docstring const & kvar : keys) {
+ bi.getLocators(kvar, doi, url, file);
+ if (!file.empty() || !doi.empty() || !url.empty())
+ return true;
+ }
+
+ // last resort: is external script activated?
+ return lyxrc.citation_search;
+}
+
+void InsetCitation::openCitation()
+{
+ Buffer const & buf = *buffer_;
+ BiblioInfo const & bi = buf.masterBibInfo();
+ docstring const & key = getParam("key");
+
+ vector<docstring> keys = getVectorFromString(key);
+ docstring titledata, doi, url, file;
+ for (docstring const & kvar : keys) {
+ CiteItem ci;
+ titledata = bi.getInfo(kvar, buffer(), ci,
+ from_ascii(lyxrc.citation_search_pattern));
+ // some cleanup: commas, " and " and " et al.", as used in name lists,
+ // are not expected in file names
+ titledata = subst(titledata, from_ascii(","), docstring());
+ titledata = subst(titledata, from_ascii(" and "), from_ascii(" "));
+ titledata = subst(titledata, from_ascii(" et al."), docstring());
+ bi.getLocators(kvar, doi, url, file);
+ LYXERR(Debug::INSETS, "Locators: doi:" << doi << " url:"
+ << url << " file:" << file << " title data:" << titledata
+ << " citation search: " << lyxrc.citation_search
+ << " citation search pattern: " << lyxrc.citation_search_pattern);
+ docstring locator;
+ if (!file.empty()) {
+ locator = file;
+ } else if (!doi.empty()) {
+ locator = doi;
+ } else if (!url.empty()) {
+ locator = url;
+ } else {
+ locator = "EXTERNAL " + titledata;
+ }
+ FuncRequest cmd = FuncRequest(LFUN_CITATION_OPEN, locator);
+ lyx::dispatch(cmd);
+ }
+}
+
+
+bool InsetCitation::getStatus(Cursor & cur, FuncRequest const & cmd,
+ FuncStatus & status) const
+{
+ switch (cmd.action()) {
+ // Handle the alias case
+ case LFUN_INSET_MODIFY:
+ if (cmd.getArg(0) == "changetype") {
+ string cmdname = getCmdName();
+ string const alias =
+ buffer().masterParams().getCiteAlias(cmdname);
+ if (!alias.empty())
+ cmdname = alias;
+ if (suffixIs(cmdname, "*"))
+ cmdname = rtrim(cmdname, "*");
+ string const newtype = cmd.getArg(1);
+ status.setEnabled(isCompatibleCommand(newtype));
+ status.setOnOff(newtype == cmdname);
+ }
+ if (cmd.getArg(0) == "toggleparam") {
+ string cmdname = getCmdName();
+ string const alias =
+ buffer().masterParams().getCiteAlias(cmdname);
+ if (!alias.empty())
+ cmdname = alias;
+ vector<CitationStyle> citation_styles =
+ buffer().masterParams().citeStyles();
+ CitationStyle cs = getCitationStyle(buffer().masterParams(),
+ cmdname, citation_styles);
+ if (cmd.getArg(1) == "star") {
+ status.setEnabled(cs.hasStarredVersion);
+ status.setOnOff(suffixIs(cmdname, "*"));
+ }
+ else if (cmd.getArg(1) == "casing") {
+ status.setEnabled(cs.forceUpperCase);
+ status.setOnOff(isUpperCase(cmdname[0]));
+ }
+ }
+ return true;
+ case LFUN_INSET_EDIT:
+ return openCitationPossible();
+ default:
+ return InsetCommand::getStatus(cur, cmd, status);