mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Properly resolve files and dois in InsetCitation (#12878)
This commit is contained in:
parent
8458952e9a
commit
124eda3a0d
@ -35,6 +35,7 @@
|
||||
#include "support/debug.h"
|
||||
#include "support/docstream.h"
|
||||
#include "support/FileNameList.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/gettext.h"
|
||||
#include "support/lstrings.h"
|
||||
|
||||
@ -225,14 +226,15 @@ void InsetCitation::openCitation()
|
||||
<< " citation search pattern: " << lyxrc.citation_search_pattern);
|
||||
docstring locator;
|
||||
if (!file.empty()) {
|
||||
locator = file;
|
||||
locator = provideScheme(file, from_ascii("file"));
|
||||
} else if (!doi.empty()) {
|
||||
locator = doi;
|
||||
locator = provideScheme(doi, from_ascii("doi"));
|
||||
} else if (!url.empty()) {
|
||||
locator = url;
|
||||
} else {
|
||||
locator = "EXTERNAL " + titledata;
|
||||
}
|
||||
LYXERR(Debug::INSETS, "Resolved locator: " << locator);
|
||||
FuncRequest cmd = FuncRequest(LFUN_CITATION_OPEN, locator);
|
||||
lyx::dispatch(cmd);
|
||||
}
|
||||
|
@ -38,8 +38,10 @@
|
||||
#include "support/Systemcall.h"
|
||||
#include "support/qstring_helpers.h"
|
||||
#include "support/TempFile.h"
|
||||
#include "support/textutils.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QUrl>
|
||||
|
||||
#include "support/lassert.h"
|
||||
|
||||
@ -942,6 +944,22 @@ string const getExtension(string const & name)
|
||||
}
|
||||
|
||||
|
||||
docstring const provideScheme(docstring const & name, docstring const & scheme)
|
||||
{
|
||||
QUrl url(toqstr(name));
|
||||
if (!url.scheme().isEmpty())
|
||||
// Has a scheme. Return as is.
|
||||
return name;
|
||||
if (scheme == from_ascii("doi")) {
|
||||
// check if it is the pure DOI (without URL)
|
||||
if (isDigitASCII(name[1]))
|
||||
return from_ascii("https://doi.org/") + name;
|
||||
}
|
||||
url.setScheme(toqstr(scheme));
|
||||
return qstring_to_ucs4(url.toString());
|
||||
}
|
||||
|
||||
|
||||
string const unzippedFileName(string const & zipped_file)
|
||||
{
|
||||
string const ext = getExtension(zipped_file);
|
||||
|
@ -240,6 +240,9 @@ addExtension(std::string const & name, std::string const & extension);
|
||||
/// Return the extension of the file (not including the .)
|
||||
std::string const getExtension(std::string const & name);
|
||||
|
||||
/// Provide a scheme (such as "file") if not present. Assumes absolute path input.
|
||||
docstring const provideScheme(docstring const & name, docstring const & scheme);
|
||||
|
||||
/** \return the name that LyX will give to the unzipped file \p zipped_file
|
||||
if the second argument of unzipFile() is empty.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user