X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FBuffer.cpp;h=d68ef97c7a48c9eccce5515598ecdc983665eb51;hb=0011f47885e070cf36e92d3a2f11f29ce1d4fdf4;hp=b3d1091affed5754c3e3b2e11b3ff4ba0421e979;hpb=932998494ba1e5e28bd3dc347c9987dffc33181a;p=lyx.git diff --git a/src/Buffer.cpp b/src/Buffer.cpp index b3d1091aff..d68ef97c7a 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -51,7 +51,6 @@ #include "ParagraphParameters.h" #include "ParIterator.h" #include "PDFOptions.h" -#include "Session.h" #include "sgml.h" #include "TexRow.h" #include "TexStream.h" @@ -117,7 +116,7 @@ namespace os = support::os; namespace { -int const LYX_FORMAT = 318; +int const LYX_FORMAT = 321; typedef map DepClean; typedef map > RefCache; @@ -174,6 +173,8 @@ public: typedef pair ScopeMacro; typedef map PositionScopeMacroMap; typedef map NamePositionScopeMacroMap; + /// map from the macro name to the position map, + /// which maps the macro definition position to the scope and the MacroData. NamePositionScopeMacroMap macros; bool macro_lock; @@ -181,7 +182,9 @@ public: typedef map BufferPositionMap; typedef pair ScopeBuffer; typedef map PositionScopeBufferMap; + /// position of children buffers in this buffer BufferPositionMap children_positions; + /// map from children inclusion positions to their scope and their buffer PositionScopeBufferMap position_to_children; /// Container for all sort of Buffer dependant errors. @@ -498,7 +501,8 @@ int Buffer::readHeader(Lexer & lex) LYXERR(Debug::PARSER, "Handling document header token: `" << token << '\''); - string unknown = params().readToken(lex, token, d->filename.onlyPath()); + string unknown = params().readToken(lex, token, d->filename.onlyPath(), + d->temppath); if (!unknown.empty()) { if (unknown[0] != '\\' && token == "\\textclass") { Alert::warning(_("Unknown document class"), @@ -573,7 +577,19 @@ bool Buffer::readDocument(Lexer & lex) // Enable embeded files, which will set temp path and move // inconsistent inzip files if needed. - embeddedFiles().enable(params().embedded, *this, false); + try { + embeddedFiles().validate(*this); + embeddedFiles().enable(params().embedded, *this, false); + } catch (ExceptionMessage const & message) { + Alert::error(message.title_, message.details_); + Alert::warning(_("Failed to read embedded files"), + _("Due to most likely a bug, LyX failed to locate all embedded " + "file. If you unzip the LyX file, you should be able to see and " + "open content.lyx which is your main text. You may also be able " + "to recover some embedded files. Please report this bug to the " + "lyx-devel mailing list.")); + return false; + } updateMacros(); updateMacroInstances(); @@ -909,18 +925,18 @@ bool Buffer::writeFile(FileName const & fname) const } if (!retval) { - message(str + _(" could not write file!.")); + message(str + _(" could not write file!")); return false; } removeAutosaveFile(d->filename.absFilename()); if (params().embedded) { - message(str + _(" writing embedded files!.")); + message(str + _(" writing embedded files.")); // if embedding is enabled, write file.lyx and all the embedded files // to the zip file fname. if (!d->embedded_files.writeFile(fname, *this)) { - message(str + _(" could not write embedded files!.")); + message(str + _(" could not write embedded files!")); return false; } } @@ -1813,25 +1829,14 @@ MacroData const * Buffer::getMacro(docstring const & name, } -void Buffer::updateEnvironmentMacros(DocIterator & it, pit_type lastpit, - DocIterator & scope) const +void Buffer::updateMacros(DocIterator & it, DocIterator & scope) const { - Paragraph & par = it.paragraph(); - depth_type depth = par.params().depth(); - Length const & leftIndent = par.params().leftIndent(); + pit_type lastpit = it.lastpit(); // look for macros in each paragraph while (it.pit() <= lastpit) { Paragraph & par = it.paragraph(); - // increased depth? - if ((par.params().depth() > depth - || par.params().leftIndent() != leftIndent) - && par.layout().isEnvironment()) { - updateBlockMacros(it, scope); - continue; - } - // iterate over the insets of the current paragraph InsetList const & insets = par.insetList(); InsetList::const_iterator iit = insets.begin(); @@ -1852,7 +1857,7 @@ void Buffer::updateEnvironmentMacros(DocIterator & it, pit_type lastpit, // collect macros in inset it.push_back(CursorSlice(*iit->inset)); - updateInsetMacros(it, newScope ? insetScope : scope); + updateMacros(it, newScope ? insetScope : scope); it.pop_back(); continue; } @@ -1909,48 +1914,6 @@ void Buffer::updateEnvironmentMacros(DocIterator & it, pit_type lastpit, } -void Buffer::updateBlockMacros(DocIterator & it, DocIterator & scope) const -{ - Paragraph & par = it.paragraph(); - - // set scope for macros in this paragraph: - // * either the "old" outer scope - // * or the scope ending after the environment - if (par.layout().isEnvironment()) { - // find end of environment block, - DocIterator envEnd = it; - pit_type n = it.lastpit() + 1; - depth_type depth = par.params().depth(); - Length const & length = par.params().leftIndent(); - // looping through the paragraph, basically until - // the layout changes or the depth gets smaller. - // (the logic of output_latex.cpp's TeXEnvironment) - do { - envEnd.pit()++; - if (envEnd.pit() == n) - break; - } while (par.layout() == envEnd.paragraph().layout() - || depth < envEnd.paragraph().params().depth() - || length != envEnd.paragraph().params().leftIndent()); - - // collect macros from environment block - updateEnvironmentMacros(it, envEnd.pit() - 1, envEnd); - } else { - // collect macros from paragraph - updateEnvironmentMacros(it, it.pit(), scope); - } -} - - -void Buffer::updateInsetMacros(DocIterator & it, DocIterator & scope) const -{ - // look for macros in each paragraph - pit_type n = it.lastpit() + 1; - while (it.pit() < n) - updateBlockMacros(it, scope); -} - - void Buffer::updateMacros() const { if (d->macro_lock) @@ -1970,7 +1933,7 @@ void Buffer::updateMacros() const DocIterator it = par_iterator_begin(); DocIterator outerScope = it; outerScope.pit() = outerScope.lastpit() + 2; - updateInsetMacros(it, outerScope); + updateMacros(it, outerScope); }