return false;
FileName const lyx = tempFileName("Buffer_importFileXXXXXX.lyx");
- if (theConverters().convert(0, name, lyx, name, format, "lyx", errorList)) {
+ Converters::RetVal const retval =
+ theConverters().convert(0, name, lyx, name, format, "lyx", errorList);
+ if (retval == Converters::SUCCESS) {
bool const success = readFile(lyx) == ReadSuccess;
removeTempFile(lyx);
return success;
}
-bool Buffer::makeLaTeXFile(FileName const & fname,
+Buffer::ExportStatus Buffer::makeLaTeXFile(FileName const & fname,
string const & original_path,
OutputParams const & runparams_in,
OutputWhat output) const
Alert::error(_("Iconv software exception Detected"), bformat(_("Please "
"verify that the support software for your encoding (%1$s) is "
"properly installed"), from_ascii(encoding)));
- return false;
+ return ExportError;
}
if (!openFileWrite(ofs, fname))
- return false;
+ return ExportError;
ErrorList & errorList = d->errorLists["Export"];
errorList.clear();
- bool failed_export = false;
+ ExportStatus status = ExportSuccess;
otexstream os(ofs);
// make sure we are ready to export
updateBuffer();
updateMacroInstances(OutputUpdate);
+ ExportStatus retval;
try {
- writeLaTeXSource(os, original_path, runparams, output);
+ retval = writeLaTeXSource(os, original_path, runparams, output);
+ if (retval == ExportKilled)
+ return ExportKilled;
}
catch (EncodingException const & e) {
docstring const failed(1, e.failed_char);
"Changing the document encoding to utf8 could help."),
{e.par_id, e.pos}, {e.par_id, e.pos + 1}));
}
- failed_export = true;
+ status = ExportError;
}
catch (iconv_codecvt_facet_exception const & e) {
errorList.push_back(ErrorItem(_("iconv conversion failed"),
_(e.what())));
- failed_export = true;
+ status = ExportError;
}
catch (exception const & e) {
errorList.push_back(ErrorItem(_("conversion failed"),
_(e.what())));
lyxerr << e.what() << endl;
- failed_export = true;
+ status = ExportError;
}
catch (...) {
lyxerr << "Caught some really weird exception..." << endl;
ofs.close();
if (ofs.fail()) {
- failed_export = true;
+ status = ExportError;
lyxerr << "File '" << fname << "' was not closed properly." << endl;
}
errorList.clear();
else
errors("Export");
- return !failed_export;
+ return status;
}
-void Buffer::writeLaTeXSource(otexstream & os,
+Buffer::ExportStatus Buffer::writeLaTeXSource(otexstream & os,
string const & original_path,
OutputParams const & runparams_in,
OutputWhat output) const
// (or not reached) and characters encodable in the current
// encoding are not converted to ASCII-representation.
+ // Some macros rely on font encoding
+ runparams.main_fontenc = params().main_font_encoding();
+
// If we are compiling a file standalone, even if this is the
// child of some other buffer, let's cut the link here, so the
// file is really independent and no concurring settings from
// Restore the parenthood if needed
if (!runparams.is_child)
d->ignore_parent = false;
- return;
+ return ExportSuccess;
}
// make the body.
LYXERR(Debug::INFO, "preamble finished, now the body.");
// the real stuff
- latexParagraphs(*this, text(), os, runparams);
+ try {
+ latexParagraphs(*this, text(), os, runparams);
+ }
+ catch (ConversionException const &) { return ExportKilled; }
// Restore the parenthood if needed
if (!runparams.is_child)
LYXERR(Debug::INFO, "Finished making LaTeX file.");
LYXERR(Debug::INFO, "Row count was " << os.texrow().rows() - 1 << '.');
+ return ExportSuccess;
}
-void Buffer::makeDocBookFile(FileName const & fname,
+Buffer::ExportStatus Buffer::makeDocBookFile(FileName const & fname,
OutputParams const & runparams,
OutputWhat output) const
{
ofdocstream ofs;
if (!openFileWrite(ofs, fname))
- return;
+ return ExportError;
// make sure we are ready to export
// this needs to be done before we validate
updateBuffer();
updateMacroInstances(OutputUpdate);
- writeDocBookSource(ofs, fname.absFileName(), runparams, output);
+ ExportStatus const retval =
+ writeDocBookSource(ofs, fname.absFileName(), runparams, output);
+ if (retval == ExportKilled)
+ return ExportKilled;
ofs.close();
if (ofs.fail())
lyxerr << "File '" << fname << "' was not closed properly." << endl;
+ return ExportSuccess;
}
-void Buffer::writeDocBookSource(odocstream & os, string const & fname,
+Buffer::ExportStatus Buffer::writeDocBookSource(odocstream & os, string const & fname,
OutputParams const & runparams,
OutputWhat output) const
{
sgml::openTag(os, top);
os << '\n';
- docbookParagraphs(text(), *this, os, runparams);
+ try {
+ docbookParagraphs(text(), *this, os, runparams);
+ }
+ catch (ConversionException const &) { return ExportKilled; }
sgml::closeTag(os, top_element);
}
+ return ExportSuccess;
}
-void Buffer::makeLyXHTMLFile(FileName const & fname,
+Buffer::ExportStatus Buffer::makeLyXHTMLFile(FileName const & fname,
OutputParams const & runparams) const
{
LYXERR(Debug::LATEX, "makeLyXHTMLFile...");
ofdocstream ofs;
if (!openFileWrite(ofs, fname))
- return;
+ return ExportError;
// make sure we are ready to export
// this has to be done before we validate
updateBuffer(UpdateMaster, OutputUpdate);
updateMacroInstances(OutputUpdate);
- writeLyXHTMLSource(ofs, runparams, FullSource);
+ ExportStatus const retval = writeLyXHTMLSource(ofs, runparams, FullSource);
+ if (retval == ExportKilled)
+ return retval;
ofs.close();
if (ofs.fail())
lyxerr << "File '" << fname << "' was not closed properly." << endl;
+ return retval;
}
-void Buffer::writeLyXHTMLSource(odocstream & os,
+Buffer::ExportStatus Buffer::writeLyXHTMLSource(odocstream & os,
OutputParams const & runparams,
OutputWhat output) const
{
if (output != IncludedFile)
// if we're an included file, the counters are in the master.
params().documentClass().counters().reset();
- xhtmlParagraphs(text(), *this, xs, runparams);
+ try {
+ xhtmlParagraphs(text(), *this, xs, runparams);
+ }
+ catch (ConversionException const &) { return ExportKilled; }
if (output_body_tag)
os << "</body>\n";
}
if (output_preamble)
os << "</html>\n";
+
+ return ExportSuccess;
}
runparams.flavor = OutputParams::LATEX;
runparams.nice = false;
runparams.linelen = lyxrc.plaintext_linelen;
- makeLaTeXFile(FileName(name), org_path, runparams);
+ ExportStatus const retval =
+ makeLaTeXFile(FileName(name), org_path, runparams);
+ if (retval != ExportSuccess) {
+ // error code on failure
+ return -1;
+ }
TeXErrors terr;
Chktex chktex(lyxrc.chktex_command, onlyFileName(name), filePath());
string utf8input = to_utf8(bit.first);
string database =
prepareFileNameForLaTeX(utf8input, ".bib", runparams.nice);
- FileName const try_in_file =
+ FileName try_in_file =
makeAbsPath(database + ".bib", filePath());
- bool const not_from_texmf = try_in_file.isReadableFile();
+ bool not_from_texmf = try_in_file.isReadableFile();
+ // If the file has not been found, try with the real file name
+ // (it might come from a child in a sub-directory)
+ if (!not_from_texmf) {
+ try_in_file = bit.second;
+ if (try_in_file.isReadableFile()) {
+ // Check if the file is in texmf
+ FileName kpsefile(findtexfile(changeExtension(utf8input, "bib"), "bib", true));
+ not_from_texmf = kpsefile.empty()
+ || kpsefile.absFileName() != try_in_file.absFileName();
+ if (not_from_texmf)
+ // If this exists, make path relative to the master
+ // FIXME Unicode
+ database =
+ removeExtension(prepareFileNameForLaTeX(
+ to_utf8(makeRelPath(from_utf8(try_in_file.absFileName()),
+ from_utf8(filePath()))),
+ ".bib", runparams.nice));
+ }
+ }
if (!runparams.inComment && !runparams.dryrun && !runparams.nice &&
not_from_texmf) {
return ExportNoPathToFormat;
}
runparams.flavor = converters.getFlavor(path, this);
+ runparams.hyperref_driver = converters.getHyperrefDriver(path);
for (auto const & edge : path)
if (theConverters().get(edge).nice()) {
need_nice_file = true;
// Plain text backend
if (backend_format == "text") {
runparams.flavor = OutputParams::TEXT;
- writePlaintextFile(*this, FileName(filename), runparams);
+ try {
+ writePlaintextFile(*this, FileName(filename), runparams);
+ }
+ catch (ConversionException const &) { return ExportCancel; }
}
// HTML backend
else if (backend_format == "xhtml") {
runparams.flavor = OutputParams::HTML;
setMathFlavor(runparams);
- makeLyXHTMLFile(FileName(filename), runparams);
+ if (makeLyXHTMLFile(FileName(filename), runparams) == ExportKilled)
+ return ExportKilled;
} else if (backend_format == "lyx")
writeFile(FileName(filename));
// Docbook backend
else if (params().isDocBook()) {
runparams.nice = !put_in_tempdir;
- makeDocBookFile(FileName(filename), runparams);
+ if (makeDocBookFile(FileName(filename), runparams) == ExportKilled)
+ return ExportKilled;
}
// LaTeX backend
else if (backend_format == format || need_nice_file) {
runparams.nice = true;
- bool const success = makeLaTeXFile(FileName(filename), string(), runparams);
+ ExportStatus const retval =
+ makeLaTeXFile(FileName(filename), string(), runparams);
+ if (retval == ExportKilled)
+ return ExportKilled;
if (d->cloned_buffer_)
d->cloned_buffer_->d->errorLists["Export"] = d->errorLists["Export"];
- if (!success)
- return ExportError;
+ if (retval != ExportSuccess)
+ return retval;
} else if (!lyxrc.tex_allows_spaces
&& contains(filePath(), ' ')) {
Alert::error(_("File name error"),
- _("The directory path to the document cannot contain spaces."));
+ bformat(_("The directory path to the document\n%1$s\n"
+ "contains spaces, but your TeX installation does "
+ "not allow them."), from_ascii(filePath())));
return ExportTexPathHasSpaces;
} else {
runparams.nice = false;
- bool const success = makeLaTeXFile(
- FileName(filename), filePath(), runparams);
+ ExportStatus const retval =
+ makeLaTeXFile(FileName(filename), filePath(), runparams);
+ if (retval == ExportKilled)
+ return ExportKilled;
if (d->cloned_buffer_)
d->cloned_buffer_->d->errorLists["Export"] = d->errorLists["Export"];
- if (!success)
+ if (retval != ExportSuccess)
return ExportError;
}
ErrorList & error_list = d->errorLists[error_type];
string const ext = theFormats().extension(format);
FileName const tmp_result_file(changeExtension(filename, ext));
- bool const success = converters.convert(this, FileName(filename),
- tmp_result_file, FileName(absFileName()), backend_format, format,
- error_list);
+ Converters::RetVal const retval =
+ converters.convert(this, FileName(filename), tmp_result_file,
+ FileName(absFileName()), backend_format, format, error_list);
+ if (retval == Converters::KILLED)
+ return ExportCancel;
+ bool success = (retval == Converters::SUCCESS);
// Emit the signal to show the error list or copy it back to the
// cloned Buffer so that it can be emitted afterwards.
DocumentClass const & textclass = master->params().documentClass();
FileNamePairList old_bibfiles;
- // do this only if we are the top-level Buffer
- if (master == this) {
+ // Do this only if we are the top-level Buffer. We also need to account
+ // for the case of a previewed child with ignored parent here.
+ if (master == this && !d->ignore_parent) {
textclass.counters().reset(from_ascii("bibitem"));
reloadBibInfoCache();
// we will re-read this cache as we go through, but we need
return;
// if the bibfiles changed, the cache of bibinfo is invalid
- sort(d->bibfiles_cache_.begin(), d->bibfiles_cache_.end());
- // the old one should already be sorted
- if (old_bibfiles != d->bibfiles_cache_) {
+ FileNamePairList new_bibfiles = d->bibfiles_cache_;
+ // this is a trick to determine whether the two vectors have
+ // the same elements.
+ sort(new_bibfiles.begin(), new_bibfiles.end());
+ sort(old_bibfiles.begin(), old_bibfiles.end());
+ if (old_bibfiles != new_bibfiles) {
+ LYXERR(Debug::FILES, "Reloading bibinfo cache.");
invalidateBibinfoCache();
reloadBibInfoCache();
// We relied upon the bibinfo cache when recalculating labels. But that
// labels. Nothing else will have changed. So we could create a new
// UpdateType that would signal that fact, if we needed to do so.
parit = cbuf.par_iterator_begin();
+ // we will be re-doing the counters and references and such.
+ textclass.counters().reset();
+ clearReferenceCache();
+ // we should not need to do this again?
+ // updateMacros();
+ setChangesPresent(false);
updateBuffer(parit, utype);
+ // this will already have been done by reloadBibInfoCache();
+ // d->bibinfo_cache_valid_ = true;
}
- else
+ else {
+ LYXERR(Debug::FILES, "Bibfiles unchanged.");
+ // this is also set to true on the other path, by reloadBibInfoCache.
d->bibinfo_cache_valid_ = true;
+ }
d->cite_labels_valid_ = true;
/// FIXME: Perf
cbuf.tocBackend().update(true, utype);