[LyX/master] New attempt on #9906: allow following hyperlinks via context menu.

Richard Kimberly Heck rikiheck at lyx.org
Wed Aug 19 02:21:23 UTC 2020


This does work with JabRef.

> diff --git a/src/BiblioInfo.cpp b/src/BiblioInfo.cpp
> index e37d56389a..a9562c9170 100644
> --- a/src/BiblioInfo.cpp
> +++ b/src/BiblioInfo.cpp
> @@ -651,6 +651,72 @@ docstring const BibTeXInfo::getYear() const
>  }
>  
>  
> +void BibTeXInfo::getLocators(docstring &doi, docstring &url,
> docstring &file) const

Space after the "&". Some other places for this, too, and spaces around
commas.


> +{
> +    if (is_bibtex_) {
> +        doi = operator[]("doi");
> +        if (!doi.empty() && !prefixIs(doi,from_ascii("http")))
> +            doi = "https://doi.org/" + doi;
> +        url = operator[]("url");

I'm confused about what this is for. Comment?


> +        file = operator[]("file");
> +
> +        // Jabref case, field has a format:
> +        // Description:Location:Filetype;Description:Location:Filetype...
> +        // We will grab only first pdf

Since the second might be an absolute path, it might be worth a loop.
Shouldn't be too hard. Just split on ; first and loop over the results.
(Same with kbibtex.)


> +        if (!file.empty()) {
> +            docstring ret, filedest, tmp;
> +            ret = split(file, tmp, ':');
> +            tmp = split(ret, filedest, ':');
> +            //TODO howto deal with relative directories?

We'd have (i) to know the name of the bibfile from which this reference
came and then (ii) be able to find its absolute path. I'm not sure it's
worth it, though somewhere we should document that this only works with
absolute paths.


> +            FileName f(to_utf8(filedest));
> +            if (f.exists())
> +                file = "file:///" + filedest;
> +        }
> +
> +        // kbibtex case, format:
> +        // file1.pdf;file2.pdf
> +        // We will grab only first pdf
> +        docstring kfile;
> +        if (file.empty())
> +            kfile = operator[]("localfile");
> +        if (!kfile.empty()) {
> +            docstring filedest, tmp;
> +            tmp = split(kfile, filedest, ';');
> +            //TODO howto deal with relative directories?
> +            FileName f(to_utf8(filedest));
> +            if (f.exists())
> +                file = "file:///" + filedest;
> +        }

It occurred to me (and maybe I'll do this) that we could possibly have a
configuration file for this that would look something like:

localfile : ^([^;]+?)
file ^:([^:]+?)

I.e., for each possible field, we have a regex telling how to get the
path we want. That could simplify the code, too.

Riki




More information about the lyx-devel mailing list