mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 10:58:52 +00:00
Do not apply \origin at existing files
The current behaviour of the \origin parameter replaces relative file names with the absolute original names if a document has been moved even if the files have been moved as well. This behaviour is annoying e.g. for editing the LyX docs in a git checkout. Now file names are only replaced if the referenced file sdo not exist.
This commit is contained in:
parent
7e72c1d0d3
commit
d80fa17175
@ -2,7 +2,7 @@
|
||||
\lyxformat 503
|
||||
\begin_document
|
||||
\begin_header
|
||||
\origin unavailable
|
||||
\origin /systemlyxdir/doc/
|
||||
\textclass scrbook
|
||||
\begin_preamble
|
||||
% DO NOT ALTER THIS PREAMBLE!!!
|
||||
|
@ -2,7 +2,7 @@
|
||||
\lyxformat 503
|
||||
\begin_document
|
||||
\begin_header
|
||||
\origin unavailable
|
||||
\origin /systemlyxdir/doc/
|
||||
\textclass scrbook
|
||||
\begin_preamble
|
||||
% DO NOT ALTER THIS PREAMBLE!!!
|
||||
|
@ -2,7 +2,7 @@
|
||||
\lyxformat 503
|
||||
\begin_document
|
||||
\begin_header
|
||||
\origin unavailable
|
||||
\origin /systemlyxdir/doc/
|
||||
\textclass scrbook
|
||||
\begin_preamble
|
||||
% that links to image floats jumps
|
||||
|
@ -2,7 +2,7 @@
|
||||
\lyxformat 503
|
||||
\begin_document
|
||||
\begin_header
|
||||
\origin unavailable
|
||||
\origin /systemlyxdir/doc/
|
||||
\textclass article
|
||||
\begin_preamble
|
||||
% DO NOT ALTER THIS PREAMBLE!!!
|
||||
|
@ -2,7 +2,7 @@
|
||||
\lyxformat 503
|
||||
\begin_document
|
||||
\begin_header
|
||||
\origin unavailable
|
||||
\origin /systemlyxdir/doc/
|
||||
\textclass article
|
||||
\use_default_options false
|
||||
\maintain_unincluded_children false
|
||||
|
@ -2,7 +2,7 @@
|
||||
\lyxformat 503
|
||||
\begin_document
|
||||
\begin_header
|
||||
\origin unavailable
|
||||
\origin /systemlyxdir/doc/
|
||||
\textclass scrartcl
|
||||
\begin_preamble
|
||||
% DO NOT ALTER THIS PREAMBLE!!!
|
||||
|
@ -2,7 +2,7 @@
|
||||
\lyxformat 503
|
||||
\begin_document
|
||||
\begin_header
|
||||
\origin unavailable
|
||||
\origin /systemlyxdir/doc/
|
||||
\textclass book
|
||||
\begin_preamble
|
||||
% DO NOT ALTER THIS PREAMBLE!!!
|
||||
|
@ -2,7 +2,7 @@
|
||||
\lyxformat 503
|
||||
\begin_document
|
||||
\begin_header
|
||||
\origin unavailable
|
||||
\origin /systemlyxdir/doc/
|
||||
\textclass scrbook
|
||||
\begin_preamble
|
||||
% DO NOT ALTER THIS PREAMBLE!!!
|
||||
|
@ -1033,7 +1033,10 @@ bool Buffer::readDocument(Lexer & lex)
|
||||
params().indiceslist().addDefault(B_("Index"));
|
||||
|
||||
// read main text
|
||||
d->old_position = originFilePath();
|
||||
if (FileName::isAbsolute(params().origin))
|
||||
d->old_position = params().origin;
|
||||
else
|
||||
d->old_position = filePath();
|
||||
bool const res = text().read(lex, errorList, d->inset);
|
||||
d->old_position.clear();
|
||||
|
||||
@ -3029,12 +3032,21 @@ string Buffer::filePath() const
|
||||
}
|
||||
|
||||
|
||||
string Buffer::originFilePath() const
|
||||
DocFileName Buffer::getReferencedFileName(string const & fn) const
|
||||
{
|
||||
if (FileName::isAbsolute(params().origin))
|
||||
return params().origin;
|
||||
DocFileName result;
|
||||
if (FileName::isAbsolute(fn) || !FileName::isAbsolute(params().origin))
|
||||
result.set(fn, filePath());
|
||||
else {
|
||||
// filePath() ends with a path separator
|
||||
FileName const test(filePath() + fn);
|
||||
if (test.exists())
|
||||
result.set(fn, filePath());
|
||||
else
|
||||
result.set(fn, params().origin);
|
||||
}
|
||||
|
||||
return filePath();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@ -5071,13 +5083,23 @@ void Buffer::checkMasterBuffer()
|
||||
|
||||
string Buffer::includedFilePath(string const & name, string const & ext) const
|
||||
{
|
||||
bool isabsolute = FileName::isAbsolute(name);
|
||||
// old_position already contains a trailing path separator
|
||||
string const absname = isabsolute ? name : d->old_position + name;
|
||||
if (d->old_position.empty() ||
|
||||
equivalent(FileName(d->old_position), FileName(filePath())))
|
||||
return name;
|
||||
|
||||
if (d->old_position.empty()
|
||||
|| equivalent(FileName(d->old_position), FileName(filePath()))
|
||||
|| !FileName(addExtension(absname, ext)).exists())
|
||||
bool isabsolute = FileName::isAbsolute(name);
|
||||
// both old_position and filePath() end with a path separator
|
||||
string absname = isabsolute ? name : d->old_position + name;
|
||||
|
||||
// if old_position is set to origin, we need to do the equivalent of
|
||||
// getReferencedFileName() (see readDocument())
|
||||
if (!isabsolute && d->old_position == params().origin) {
|
||||
FileName const test(addExtension(filePath() + name, ext));
|
||||
if (test.exists())
|
||||
absname = filePath() + name;
|
||||
}
|
||||
|
||||
if (!FileName(addExtension(absname, ext)).exists())
|
||||
return name;
|
||||
|
||||
if (isabsolute)
|
||||
|
13
src/Buffer.h
13
src/Buffer.h
@ -66,6 +66,7 @@ class WorkAreaManager;
|
||||
}
|
||||
|
||||
namespace support {
|
||||
class DocFileName;
|
||||
class FileName;
|
||||
class FileNameList;
|
||||
}
|
||||
@ -405,12 +406,14 @@ public:
|
||||
/// It is always an absolute path.
|
||||
std::string filePath() const;
|
||||
|
||||
/** Returns the path where the document was last saved.
|
||||
* It may be different from filePath() if the document was later
|
||||
* manually moved to a different location.
|
||||
* It is always an absolute path.
|
||||
/** Contructs a file name of a referenced file (child doc, included graphics etc).
|
||||
* Absolute names are returned as is. If the name is relative, it is
|
||||
* interpreted relative to filePath() if the file exists, otherwise
|
||||
* relative to the original path where the document was last saved.
|
||||
* The original path may be different from filePath() if the document was
|
||||
* later manually moved to a different location.
|
||||
*/
|
||||
std::string originFilePath() const;
|
||||
support::DocFileName getReferencedFileName(std::string const & fn) const;
|
||||
|
||||
/** Returns the path where a local layout file lives.
|
||||
* An empty string is returned for standard system and user layouts.
|
||||
|
@ -273,7 +273,7 @@ bool InsetExternalParams::read(Buffer const & buffer, Lexer & lex)
|
||||
case EX_FILENAME: {
|
||||
lex.eatLine();
|
||||
string const name = lex.getString();
|
||||
filename.set(name, buffer.originFilePath());
|
||||
filename = buffer.getReferencedFileName(name);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -139,7 +139,7 @@ string findTargetFormat(string const & format, OutputParams const & runparams)
|
||||
}
|
||||
|
||||
|
||||
void readInsetGraphics(Lexer & lex, string const & bufpath,
|
||||
void readInsetGraphics(Lexer & lex, Buffer const & buf, bool allowOrigin,
|
||||
InsetGraphicsParams & params)
|
||||
{
|
||||
bool finished = false;
|
||||
@ -156,7 +156,7 @@ void readInsetGraphics(Lexer & lex, string const & bufpath,
|
||||
if (token == "\\end_inset") {
|
||||
finished = true;
|
||||
} else {
|
||||
if (!params.Read(lex, token, bufpath))
|
||||
if (!params.Read(lex, token, buf, allowOrigin))
|
||||
lyxerr << "Unknown token, "
|
||||
<< token
|
||||
<< ", skipping."
|
||||
@ -299,7 +299,7 @@ void InsetGraphics::read(Lexer & lex)
|
||||
{
|
||||
lex.setContext("InsetGraphics::read");
|
||||
//lex >> "Graphics";
|
||||
readInsetGraphics(lex, buffer().originFilePath(), params_);
|
||||
readInsetGraphics(lex, buffer(), true, params_);
|
||||
graphic_->update(params().as_grfxParams());
|
||||
}
|
||||
|
||||
@ -1054,7 +1054,7 @@ void InsetGraphics::string2params(string const & in, Buffer const & buffer,
|
||||
lex.setContext("InsetGraphics::string2params");
|
||||
lex >> "graphics";
|
||||
params = InsetGraphicsParams();
|
||||
readInsetGraphics(lex, buffer.filePath(), params);
|
||||
readInsetGraphics(lex, buffer, false, params);
|
||||
}
|
||||
|
||||
|
||||
|
@ -177,11 +177,15 @@ void InsetGraphicsParams::Write(ostream & os, Buffer const & buffer) const
|
||||
}
|
||||
|
||||
|
||||
bool InsetGraphicsParams::Read(Lexer & lex, string const & token, string const & bufpath)
|
||||
bool InsetGraphicsParams::Read(Lexer & lex, string const & token,
|
||||
Buffer const & buf, bool allowOrigin)
|
||||
{
|
||||
if (token == "filename") {
|
||||
lex.eatLine();
|
||||
filename.set(lex.getString(), bufpath);
|
||||
if (allowOrigin)
|
||||
filename = buf.getReferencedFileName(lex.getString());
|
||||
else
|
||||
filename.set(lex.getString(), buf.filePath());
|
||||
} else if (token == "lyxscale") {
|
||||
lex.next();
|
||||
lyxscale = lex.getInteger();
|
||||
|
@ -73,7 +73,8 @@ public:
|
||||
/// Buffer is needed to figure out if a figure is embedded.
|
||||
void Write(std::ostream & os, Buffer const & buf) const;
|
||||
/// If the token belongs to our parameters, read it.
|
||||
bool Read(Lexer & lex, std::string const & token, std::string const & bufpath);
|
||||
bool Read(Lexer & lex, std::string const & token, Buffer const & buf,
|
||||
bool allowOrigin);
|
||||
/// convert
|
||||
// Only a subset of InsetGraphicsParams is needed for display purposes.
|
||||
// This function also interrogates lyxrc to ascertain whether
|
||||
|
Loading…
Reference in New Issue
Block a user