+ 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);