mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
Georg's take on Bug 605.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8528 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
0d43ba149a
commit
7c70a8ee0f
@ -2,6 +2,7 @@ src/BranchList.h
|
||||
src/BufferView.C
|
||||
src/BufferView_pimpl.C
|
||||
src/Chktex.C
|
||||
src/CutAndPaste.C
|
||||
src/LColor.C
|
||||
src/LaTeX.C
|
||||
src/MenuBackend.C
|
||||
@ -187,7 +188,6 @@ src/output_docbook.C
|
||||
src/output_linuxdoc.C
|
||||
src/output_plaintext.C
|
||||
src/paragraph.C
|
||||
src/paragraph_funcs.C
|
||||
src/rowpainter.C
|
||||
src/support/globbing.C
|
||||
src/text.C
|
||||
|
@ -1,3 +1,15 @@
|
||||
2003-02-12 Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
|
||||
|
||||
* buffer.C (makeLaTeXFile): if the main latex file that is
|
||||
processed is usually a subdocument of some master, then pretend
|
||||
for a while that it is actually the master
|
||||
|
||||
2003-02-10 Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
|
||||
|
||||
* buffer.C (getLabelList):
|
||||
(getBibkeyList): use getMasterBuffer()
|
||||
(getMasterBuffer): new method. Returns the main document in the
|
||||
case where one is using included documents.
|
||||
|
||||
2004-03-25 André Pönitz <poenitz@gmx.net>
|
||||
|
||||
|
52
src/buffer.C
52
src/buffer.C
@ -858,6 +858,9 @@ void Buffer::makeLaTeXFile(ostream & os,
|
||||
// input@path is set when the actual parameter
|
||||
// original_path is set. This is done for usual tex-file, but not
|
||||
// for nice-latex-file. (Matthias 250696)
|
||||
// Note that input@path is only needed for something the user does
|
||||
// in the preamble, included .tex files or ERT, files included by
|
||||
// LyX work without it.
|
||||
if (output_preamble) {
|
||||
if (!runparams.nice) {
|
||||
// code for usual, NOT nice-latex-file
|
||||
@ -896,8 +899,22 @@ void Buffer::makeLaTeXFile(ostream & os,
|
||||
texrow().newline();
|
||||
}
|
||||
|
||||
// if we are doing a real file with body, even if this is the
|
||||
// child of some other buffer, let's cut the link here.
|
||||
// This happens for example if only a child document is printed.
|
||||
string save_parentname;
|
||||
if (output_preamble) {
|
||||
save_parentname = params().parentname;
|
||||
params().parentname.erase();
|
||||
}
|
||||
|
||||
// the real stuff
|
||||
latexParagraphs(*this, paragraphs(), os, texrow(), runparams);
|
||||
|
||||
// Restore the parenthood if needed
|
||||
if (output_preamble)
|
||||
params().parentname = save_parentname;
|
||||
|
||||
// add this just in case after all the paragraphs
|
||||
os << endl;
|
||||
texrow().newline();
|
||||
@ -1165,13 +1182,10 @@ void Buffer::getLabelList(std::vector<string> & list) const
|
||||
{
|
||||
/// if this is a child document and the parent is already loaded
|
||||
/// Use the parent's list instead [ale990407]
|
||||
if (!params().parentname.empty()
|
||||
&& bufferlist.exists(params().parentname)) {
|
||||
Buffer const * tmp = bufferlist.getBuffer(params().parentname);
|
||||
if (tmp) {
|
||||
tmp->getLabelList(list);
|
||||
return;
|
||||
}
|
||||
Buffer const * tmp = getMasterBuffer();
|
||||
if (tmp != this) {
|
||||
tmp->getLabelList(list);
|
||||
return;
|
||||
}
|
||||
|
||||
for (inset_iterator it = inset_const_iterator_begin();
|
||||
@ -1187,13 +1201,10 @@ void Buffer::fillWithBibKeys(std::vector<std::pair<string, string> > & keys)
|
||||
{
|
||||
/// if this is a child document and the parent is already loaded
|
||||
/// use the parent's list instead [ale990412]
|
||||
if (!params().parentname.empty() &&
|
||||
bufferlist.exists(params().parentname)) {
|
||||
Buffer const * tmp = bufferlist.getBuffer(params().parentname);
|
||||
if (tmp) {
|
||||
tmp->fillWithBibKeys(keys);
|
||||
return;
|
||||
}
|
||||
Buffer const * tmp = getMasterBuffer();
|
||||
if (tmp != this) {
|
||||
tmp->fillWithBibKeys(keys);
|
||||
return;
|
||||
}
|
||||
|
||||
for (inset_iterator it = inset_const_iterator_begin();
|
||||
@ -1463,6 +1474,19 @@ void Buffer::setParentName(string const & name)
|
||||
}
|
||||
|
||||
|
||||
Buffer const * Buffer::getMasterBuffer() const
|
||||
{
|
||||
if (!params().parentname.empty()
|
||||
&& bufferlist.exists(params().parentname)) {
|
||||
Buffer const * buf = bufferlist.getBuffer(params().parentname);
|
||||
if (buf)
|
||||
return buf->getMasterBuffer();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
Buffer::inset_iterator::inset_iterator(ParagraphList & pars, base_type p)
|
||||
: pit(p), pars_(&pars)
|
||||
{
|
||||
|
@ -208,6 +208,11 @@ public:
|
||||
/// Name of the document's parent
|
||||
void setParentName(std::string const &);
|
||||
|
||||
/** Get the document's master (or \c this if this is not a
|
||||
child document)
|
||||
*/
|
||||
Buffer const * getMasterBuffer() const;
|
||||
|
||||
/// Is buffer read-only?
|
||||
bool isReadonly() const;
|
||||
|
||||
|
@ -1,3 +1,24 @@
|
||||
2004-03-19 Georg Baum <Georg.Baum@post.rwth-aachen.de>
|
||||
|
||||
* ExternalSupport.C: use the master buffer's temp dir
|
||||
* insetgraphics.C (latex): make relative filename relative to the
|
||||
master file
|
||||
* insetgraphics.C: use the master buffer's temp dir
|
||||
* insetinclude.C (masterFilename): new function
|
||||
* insetinclude.C (linuxdoc, docbook): simplify logic (IsLyXFilename()
|
||||
is always true if loadIfNeeded() returns true)
|
||||
|
||||
2003-02-10 Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
|
||||
|
||||
* insetinclude.C (loadIfNeeded): when the child buffer is loaded,
|
||||
set its parent to the current buffer.
|
||||
(latex): use the tmppath of the master buffer, not just the parent
|
||||
buffer (makes a difference with more than one level of include
|
||||
insets). If the file name is relative write in the .tex file a
|
||||
name relative to the master buffer directory.
|
||||
|
||||
* insetinclude.C: rename masterFilename to parentFilename (this
|
||||
points to the direct parent)
|
||||
|
||||
2004-03-25 André Pönitz <poenitz@gmx.net>
|
||||
|
||||
|
@ -96,7 +96,7 @@ string const doSubstitution(InsetExternalParams const & params,
|
||||
string contents;
|
||||
|
||||
string const filepath = support::IsFileReadable(file) ?
|
||||
buffer.filePath() : buffer.temppath();
|
||||
buffer.filePath() : buffer.getMasterBuffer()->temppath();
|
||||
support::Path p(filepath);
|
||||
|
||||
if (support::IsFileReadable(file))
|
||||
@ -163,11 +163,15 @@ void updateExternal(InsetExternalParams const & params,
|
||||
return; // FAILURE
|
||||
}
|
||||
|
||||
// The master buffer. This is useful when there are multiple levels
|
||||
// of include files
|
||||
Buffer const * m_buffer = buffer.getMasterBuffer();
|
||||
|
||||
if (external_in_tmpdir && !from_file.empty()) {
|
||||
// We are running stuff through LaTeX
|
||||
string const temp_file =
|
||||
support::MakeAbsPath(params.filename.mangledFilename(),
|
||||
buffer.temppath());
|
||||
m_buffer->temppath());
|
||||
unsigned long const from_checksum = support::sum(from_file);
|
||||
unsigned long const temp_checksum = support::sum(temp_file);
|
||||
|
||||
@ -184,7 +188,9 @@ void updateExternal(InsetExternalParams const & params,
|
||||
from_file);
|
||||
|
||||
string const abs_to_file =
|
||||
support::MakeAbsPath(to_file, buffer.filePath());
|
||||
support::MakeAbsPath(to_file, external_in_tmpdir
|
||||
? m_buffer->temppath()
|
||||
: buffer.filePath());
|
||||
|
||||
// Do we need to perform the conversion?
|
||||
// Yes if to_file does not exist or if from_file is newer than to_file
|
||||
@ -235,7 +241,7 @@ int writeExternal(InsetExternalParams const & params,
|
||||
// We are running stuff through LaTeX
|
||||
from_file =
|
||||
support::MakeAbsPath(params.filename.mangledFilename(),
|
||||
buffer.temppath());
|
||||
buffer.getMasterBuffer()->temppath());
|
||||
}
|
||||
|
||||
string str = doSubstitution(params, buffer, cit->second.product,
|
||||
|
@ -434,10 +434,15 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
|
||||
// we move it to a temp dir or uncompress it.
|
||||
string temp_file = orig_file;
|
||||
|
||||
// We place all temporary files in the master buffer's temp dir.
|
||||
// This is possible because we use mangled file names.
|
||||
// This is necessary for DVI export.
|
||||
string const temp_path = buf.getMasterBuffer()->temppath();
|
||||
|
||||
if (zipped) {
|
||||
CopyStatus status;
|
||||
boost::tie(status, temp_file) =
|
||||
copyToDirIfNeeded(orig_file, buf.temppath());
|
||||
copyToDirIfNeeded(orig_file, temp_path);
|
||||
|
||||
if (status == FAILURE)
|
||||
return orig_file;
|
||||
@ -465,7 +470,7 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
|
||||
bool conversion_needed = true;
|
||||
CopyStatus status;
|
||||
boost::tie(status, temp_file) =
|
||||
copyToDirIfNeeded(orig_file, buf.temppath());
|
||||
copyToDirIfNeeded(orig_file, temp_path);
|
||||
|
||||
if (status == FAILURE)
|
||||
return orig_file;
|
||||
@ -523,6 +528,10 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
|
||||
int InsetGraphics::latex(Buffer const & buf, ostream & os,
|
||||
OutputParams const & runparams) const
|
||||
{
|
||||
// The master buffer. This is useful when there are multiple levels
|
||||
// of include files
|
||||
Buffer const * m_buffer = buf.getMasterBuffer();
|
||||
|
||||
// If there is no file specified or not existing,
|
||||
// just output a message about it in the latex output.
|
||||
lyxerr[Debug::GRAPHICS]
|
||||
@ -576,19 +585,23 @@ int InsetGraphics::latex(Buffer const & buf, ostream & os,
|
||||
<< "\n\tafter = " << after << endl;
|
||||
|
||||
|
||||
string latex_str = before + '{';
|
||||
// "nice" means that the buffer is exported to LaTeX format but not
|
||||
// run through the LaTeX compiler.
|
||||
if (runparams.nice) {
|
||||
os << before <<'{' << relative_file << '}' << after;
|
||||
return 1;
|
||||
}
|
||||
// a relative filename should be relative to the master
|
||||
// buffer.
|
||||
latex_str += params().filename.outputFilename(m_buffer->filePath());
|
||||
} else if (file_exists) {
|
||||
// Make the filename relative to the lyx file
|
||||
// and remove the extension so the LaTeX will use whatever
|
||||
// is appropriate (when there are several versions in
|
||||
// different formats)
|
||||
latex_str += os::external_path(prepareFile(buf, runparams));
|
||||
} else
|
||||
latex_str += relative_file + " not found!";
|
||||
|
||||
// Make the filename relative to the lyx file
|
||||
// and remove the extension so the LaTeX will use whatever is
|
||||
// appropriate (when there are several versions in different formats)
|
||||
string const latex_str = message.empty() ?
|
||||
(before + '{' + os::external_path(prepareFile(buf, runparams)) + '}' + after) :
|
||||
(before + '{' + relative_file + " not found!}" + after);
|
||||
latex_str += '}' + after;
|
||||
os << latex_str;
|
||||
|
||||
lyxerr[Debug::GRAPHICS] << "InsetGraphics::latex outputting:\n"
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include "support/filename.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/lstrings.h" // contains
|
||||
#include "support/lyxlib.h"
|
||||
#include "support/tostr.h"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
@ -48,9 +49,11 @@
|
||||
#include "support/std_sstream.h"
|
||||
|
||||
using lyx::support::AddName;
|
||||
using lyx::support::AbsolutePath;
|
||||
using lyx::support::bformat;
|
||||
using lyx::support::ChangeExtension;
|
||||
using lyx::support::contains;
|
||||
using lyx::support::copy;
|
||||
using lyx::support::FileInfo;
|
||||
using lyx::support::FileName;
|
||||
using lyx::support::GetFileContents;
|
||||
@ -58,9 +61,11 @@ using lyx::support::IsFileReadable;
|
||||
using lyx::support::IsLyXFilename;
|
||||
using lyx::support::MakeAbsPath;
|
||||
using lyx::support::MakeDisplayPath;
|
||||
using lyx::support::MakeRelPath;
|
||||
using lyx::support::OnlyFilename;
|
||||
using lyx::support::OnlyPath;
|
||||
using lyx::support::subst;
|
||||
using lyx::support::sum;
|
||||
|
||||
using std::endl;
|
||||
using std::string;
|
||||
@ -186,6 +191,12 @@ bool isVerbatim(InsetCommandParams const & params)
|
||||
|
||||
|
||||
string const masterFilename(Buffer const & buffer)
|
||||
{
|
||||
return buffer.getMasterBuffer()->fileName();
|
||||
}
|
||||
|
||||
|
||||
string const parentFilename(Buffer const & buffer)
|
||||
{
|
||||
return buffer.fileName();
|
||||
}
|
||||
@ -195,7 +206,7 @@ string const includedFilename(Buffer const & buffer,
|
||||
InsetCommandParams const & params)
|
||||
{
|
||||
return MakeAbsPath(params.getContents(),
|
||||
OnlyPath(masterFilename(buffer)));
|
||||
OnlyPath(parentFilename(buffer)));
|
||||
}
|
||||
|
||||
|
||||
@ -282,15 +293,19 @@ bool loadIfNeeded(Buffer const & buffer, InsetCommandParams const & params)
|
||||
if (!IsLyXFilename(included_file))
|
||||
return false;
|
||||
|
||||
if (bufferlist.exists(included_file))
|
||||
return true;
|
||||
|
||||
// the readonly flag can/will be wrong, not anymore I think.
|
||||
FileInfo finfo(included_file);
|
||||
if (!finfo.isOK())
|
||||
return false;
|
||||
return loadLyXFile(bufferlist.newBuffer(included_file),
|
||||
included_file);
|
||||
Buffer * buf = bufferlist.getBuffer(included_file);
|
||||
if (!buf) {
|
||||
// the readonly flag can/will be wrong, not anymore I think.
|
||||
FileInfo finfo(included_file);
|
||||
if (!finfo.isOK())
|
||||
return false;
|
||||
buf = bufferlist.newBuffer(included_file);
|
||||
if (!loadLyXFile(buf, included_file))
|
||||
return false;
|
||||
}
|
||||
if (buf)
|
||||
buf->setParentName(parentFilename(buffer));
|
||||
return buf != 0;
|
||||
}
|
||||
|
||||
|
||||
@ -307,37 +322,67 @@ int InsetInclude::latex(Buffer const & buffer, ostream & os,
|
||||
return 0;
|
||||
|
||||
string const included_file = includedFilename(buffer, params_);
|
||||
Buffer const * const m_buffer = buffer.getMasterBuffer();
|
||||
|
||||
// if incfile is relative, make it relative to the master
|
||||
// buffer directory.
|
||||
if (!AbsolutePath(incfile)) {
|
||||
incfile = MakeRelPath(included_file,
|
||||
m_buffer->filePath());
|
||||
}
|
||||
|
||||
// write it to a file (so far the complete file)
|
||||
string writefile = ChangeExtension(included_file, ".tex");
|
||||
|
||||
if (!runparams.nice) {
|
||||
incfile = FileName(writefile).mangledFilename();
|
||||
writefile = MakeAbsPath(incfile, m_buffer->temppath());
|
||||
}
|
||||
lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
|
||||
lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
|
||||
|
||||
if (loadIfNeeded(buffer, params_)) {
|
||||
Buffer * tmp = bufferlist.getBuffer(included_file);
|
||||
|
||||
if (tmp->params().textclass != buffer.params().textclass) {
|
||||
if (tmp->params().textclass != m_buffer->params().textclass) {
|
||||
string text = bformat(_("Included file `%1$s'\n"
|
||||
"has textclass `%2$s'\n"
|
||||
"while parent file has textclass `%3$s'."),
|
||||
MakeDisplayPath(included_file),
|
||||
tmp->params().getLyXTextClass().name(),
|
||||
buffer.params().getLyXTextClass().name());
|
||||
m_buffer->params().getLyXTextClass().name());
|
||||
Alert::warning(_("Different textclasses"), text);
|
||||
//return 0;
|
||||
}
|
||||
|
||||
// write it to a file (so far the complete file)
|
||||
string writefile = ChangeExtension(included_file, ".tex");
|
||||
|
||||
if (!runparams.nice) {
|
||||
incfile = FileName(writefile).mangledFilename();
|
||||
writefile = MakeAbsPath(incfile, buffer.temppath());
|
||||
}
|
||||
|
||||
lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
|
||||
lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
|
||||
|
||||
tmp->markDepClean(buffer.temppath());
|
||||
tmp->markDepClean(m_buffer->temppath());
|
||||
|
||||
#ifdef WITH_WARNINGS
|
||||
#warning Second argument is irrelevant!
|
||||
// since only_body is true, makeLaTeXFile will not look at second
|
||||
// argument. Should we set it to string(), or should makeLaTeXFile
|
||||
// make use of it somehow? (JMarc 20031002)
|
||||
#endif
|
||||
tmp->makeLaTeXFile(writefile,
|
||||
OnlyPath(masterFilename(buffer)),
|
||||
runparams, false);
|
||||
} else if (!runparams.nice) {
|
||||
// Copy the file to the temp dir, so that .aux files etc.
|
||||
// are not created in the original dir. Files included by
|
||||
// this file will be found via input@path, see ../buffer.C.
|
||||
unsigned long const checksum_in = sum(included_file);
|
||||
unsigned long const checksum_out = sum(writefile);
|
||||
|
||||
if (checksum_in != checksum_out) {
|
||||
if (!copy(included_file, writefile)) {
|
||||
lyxerr[Debug::LATEX]
|
||||
<< bformat(_("Could not copy the file\n%1$s\n"
|
||||
"into the temporary directory."),
|
||||
included_file)
|
||||
<< endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isVerbatim(params_)) {
|
||||
@ -387,15 +432,12 @@ int InsetInclude::linuxdoc(Buffer const & buffer, ostream & os,
|
||||
Buffer * tmp = bufferlist.getBuffer(included_file);
|
||||
|
||||
// write it to a file (so far the complete file)
|
||||
string writefile;
|
||||
if (IsLyXFilename(included_file))
|
||||
writefile = ChangeExtension(included_file, ".sgml");
|
||||
else
|
||||
writefile = included_file;
|
||||
string writefile = ChangeExtension(included_file, ".sgml");
|
||||
|
||||
if (!runparams.nice) {
|
||||
incfile = FileName(writefile).mangledFilename();
|
||||
writefile = MakeAbsPath(incfile, buffer.temppath());
|
||||
writefile = MakeAbsPath(incfile,
|
||||
buffer.getMasterBuffer()->temppath());
|
||||
}
|
||||
|
||||
lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
|
||||
@ -431,15 +473,12 @@ int InsetInclude::docbook(Buffer const & buffer, ostream & os,
|
||||
Buffer * tmp = bufferlist.getBuffer(included_file);
|
||||
|
||||
// write it to a file (so far the complete file)
|
||||
string writefile;
|
||||
if (IsLyXFilename(included_file))
|
||||
writefile = ChangeExtension(included_file, ".sgml");
|
||||
else
|
||||
writefile = included_file;
|
||||
string writefile = ChangeExtension(included_file, ".sgml");
|
||||
|
||||
if (!runparams.nice) {
|
||||
incfile = FileName(writefile).mangledFilename();
|
||||
writefile = MakeAbsPath(incfile, buffer.temppath());
|
||||
writefile = MakeAbsPath(incfile,
|
||||
buffer.getMasterBuffer()->temppath());
|
||||
}
|
||||
|
||||
lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
|
||||
@ -476,7 +515,8 @@ void InsetInclude::validate(LaTeXFeatures & features) const
|
||||
|
||||
if (!features.nice() && !isVerbatim(params_)) {
|
||||
incfile = FileName(writefile).mangledFilename();
|
||||
writefile = MakeAbsPath(incfile, buffer.temppath());
|
||||
writefile = MakeAbsPath(incfile,
|
||||
buffer.getMasterBuffer()->temppath());
|
||||
}
|
||||
|
||||
features.includeFile(include_label, writefile);
|
||||
@ -504,7 +544,7 @@ void InsetInclude::getLabelList(Buffer const & buffer,
|
||||
Buffer * tmp = bufferlist.getBuffer(included_file);
|
||||
tmp->setParentName("");
|
||||
tmp->getLabelList(list);
|
||||
tmp->setParentName(masterFilename(buffer));
|
||||
tmp->setParentName(parentFilename(buffer));
|
||||
}
|
||||
}
|
||||
|
||||
@ -517,7 +557,7 @@ void InsetInclude::fillWithBibKeys(Buffer const & buffer,
|
||||
Buffer * tmp = bufferlist.getBuffer(included_file);
|
||||
tmp->setParentName("");
|
||||
tmp->fillWithBibKeys(keys);
|
||||
tmp->setParentName(masterFilename(buffer));
|
||||
tmp->setParentName(parentFilename(buffer));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user