]> git.lyx.org Git - features.git/commitdiff
Handle multiple files in file and localfile BibTeX field (#12896)
authorJuergen Spitzmueller <spitz@lyx.org>
Fri, 8 Sep 2023 12:02:23 +0000 (14:02 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Fri, 8 Sep 2023 12:02:23 +0000 (14:02 +0200)
src/BiblioInfo.cpp
src/frontends/qt/qt_helpers.cpp
src/support/filetools.cpp

index 36509c6c7c9557d0525acb56acd7b5fbc1ed4aca..c5094b285f426a18727252692c4c23963e80e6e8 100644 (file)
@@ -688,30 +688,46 @@ void BibTeXInfo::getLocators(docstring & doi, docstring & url, docstring & file)
 
                // Jabref case, field has a format:
                // Description:Location:Filetype;Description:Location:Filetype...
-               // We will grab only first pdf
+               // We will strip out the locations and return an \n-separated list
                if (!file.empty()) {
-                       docstring ret, filedest, tmp;
-                       ret = split(file, tmp, ':');
-                       tmp = split(ret, filedest, ':');
-                       //TODO howto deal with relative directories?
-                       FileName f(to_utf8(filedest));
-                       if (f.exists())
-                               file = "file:///" + filedest;
+                       docstring filelist;
+                       vector<docstring> files = getVectorFromString(file, from_ascii(";"));
+                       for (auto const & f : files) {
+                               docstring ret, filedest, tmp;
+                               ret = split(f, tmp, ':');
+                               tmp = split(ret, filedest, ':');
+                               // TODO howto deal with relative directories?
+                               FileName fn(to_utf8(filedest));
+                               if (fn.exists()) {
+                                       if (!filelist.empty())
+                                               filelist += '\n';
+                                       filelist += "file:///" + filedest;
+                               }
+                       }
+                       if (!filelist.empty())
+                               file = filelist;
                }
 
                // kbibtex case, format:
                // file1.pdf;file2.pdf
-               // We will grab only first pdf
+               // We will strip out the locations and return an \n-separated list
                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;
+                       docstring filelist;
+                       vector<docstring> files = getVectorFromString(kfile, from_ascii(";"));
+                       for (auto const & f : files) {
+                               // TODO howto deal with relative directories?
+                               FileName fn(to_utf8(f));
+                               if (fn.exists()) {
+                                       if (!filelist.empty())
+                                               filelist += '\n';
+                                       filelist = "file:///" + f;
+                               }
+                       }
+                       if (!filelist.empty())
+                               file = filelist;
                }
 
                if (!url.empty())
index 3f6e6c0f23dcdc8604ed4023cd33f4502d84b63b..37e5ed5ba6b3897c2939af58263b3f108b3de4bb 100644 (file)
@@ -299,10 +299,11 @@ void showDirectory(FileName const & directory)
 
 void showTarget(string const & target_in, Buffer const & buf)
 {
-       LYXERR(Debug::INSETS, "Showtarget:" << target_in << "\n");
+       LYXERR(Debug::INSETS, "Showtarget: " << target_in << "\n");
 
        string target = target_in;
        string const & docpath = buf.absFileName();
+       vector<string> targets;
 
        bool const is_external = prefixIs(target, "EXTERNAL ");
        if (is_external) {
@@ -320,13 +321,19 @@ void showTarget(string const & target_in, Buffer const & buf)
                        return;
                }
                // lyxpaperview returns a \n-separated list of paths
-               vector<string> targets = getVectorFromString(rtrim(ret.result, "\n"), "\n");
+               targets = getVectorFromString(rtrim(ret.result, "\n"), "\n");
                if (targets.empty()) {
                        frontend::Alert::error(_("Could not open file"),
                                bformat(_("No file was found using the pattern `%1$s'."),
                                        from_utf8(tar)));
                        return;
                }
+       }
+       if (prefixIs(target, "file://")) {
+               // file might have a \n-separated list of paths
+               targets = getVectorFromString(target, "\n");
+       }
+       if (!targets.empty()) {
                if (targets.size() > 1) {
                        QStringList files;
                        for (auto const & t : targets)
index d2191cf1fd0854aeabcfc2fd2b631b80a57611af..e8f3aa19ceef9d7894a8c9cf8b165b04f31d818e 100644 (file)
@@ -946,6 +946,8 @@ string const getExtension(string const & name)
 
 docstring const provideScheme(docstring const & name, docstring const & scheme)
 {
+       if (prefixIs(name, scheme + "://"))
+               return name;
        QUrl url(toqstr(name));
        if (!url.scheme().isEmpty())
                // Has a scheme. Return as is.