X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FBuffer.cpp;h=8105d5261ba8b57006528033b55105e4116f2080;hb=2420f5ed1e9fe98c6273de3c9d661641aefc011b;hp=444887bdb6e810d8904cacf4ffda1ab722748a39;hpb=412f520892233da229635de57e46b954d6807370;p=lyx.git diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 444887bdb6..8105d5261b 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -118,7 +118,7 @@ namespace { // Do not remove the comment below, so we get merge conflict in // independent branches. Instead add your own. -int const LYX_FORMAT = 345; // jamatos: xml elements +int const LYX_FORMAT = 348; // uwestoehr: add support for \*phantom typedef map DepClean; typedef map > RefCache; @@ -289,8 +289,12 @@ Buffer::~Buffer() // loop over children Impl::BufferPositionMap::iterator it = d->children_positions.begin(); Impl::BufferPositionMap::iterator end = d->children_positions.end(); - for (; it != end; ++it) - theBufferList().releaseChild(this, const_cast(it->first)); + for (; it != end; ++it) { + Buffer * child = const_cast(it->first); + // The child buffer might have been closed already. + if (theBufferList().isLoaded(child)) + theBufferList().releaseChild(this, child); + } // clear references to children in macro tables d->children_positions.clear(); @@ -547,7 +551,7 @@ int Buffer::readHeader(Lexer & lex) // Uwe C. Schroeder // changed to be public and have one parameter -// Returns false if "\end_document" is not read (Asger) +// Returns true if "\end_document" is not read (Asger) bool Buffer::readDocument(Lexer & lex) { ErrorList & errorList = d->errorLists["Parse"]; @@ -566,19 +570,19 @@ bool Buffer::readDocument(Lexer & lex) if (params().outputChanges) { bool dvipost = LaTeXFeatures::isAvailable("dvipost"); - bool xcolorsoul = LaTeXFeatures::isAvailable("soul") && + bool xcolorulem = LaTeXFeatures::isAvailable("ulem") && LaTeXFeatures::isAvailable("xcolor"); - if (!dvipost && !xcolorsoul) { + if (!dvipost && !xcolorulem) { Alert::warning(_("Changes not shown in LaTeX output"), _("Changes will not be highlighted in LaTeX output, " - "because neither dvipost nor xcolor/soul are installed.\n" + "because neither dvipost nor xcolor/ulem are installed.\n" "Please install these packages or redefine " "\\lyxadded and \\lyxdeleted in the LaTeX preamble.")); - } else if (!xcolorsoul) { + } else if (!xcolorulem) { Alert::warning(_("Changes not shown in LaTeX output"), _("Changes will not be highlighted in LaTeX output " - "when using pdflatex, because xcolor and soul are not installed.\n" + "when using pdflatex, because xcolor and ulem are not installed.\n" "Please install both packages or redefine " "\\lyxadded and \\lyxdeleted in the LaTeX preamble.")); } @@ -588,8 +592,24 @@ bool Buffer::readDocument(Lexer & lex) FileName const master_file = makeAbsPath(params().master, onlyPath(absFileName())); if (isLyXFilename(master_file.absFilename())) { - Buffer * master = checkAndLoadLyXFile(master_file); - d->parent_buffer = master; + Buffer * master = + checkAndLoadLyXFile(master_file, true); + if (master) { + // set master as master buffer, but only + // if we are a real child + if (master->isChild(this)) + setParent(master); + // if the master is not fully loaded + // it is probably just loading this + // child. No warning needed then. + else if (master->isFullyLoaded()) + LYXERR0("The master '" + << params().master + << "' assigned to this document '" + << absFileName() + << "' does not include " + "this document. Ignoring the master assignment."); + } } } @@ -685,6 +705,8 @@ bool Buffer::readFile(FileName const & filename) { FileName fname(filename); + params().compressed = fname.isZippedFile(); + // remove dummy empty par paragraphs().clear(); Lexer lex; @@ -757,7 +779,7 @@ Buffer::ReadStatus Buffer::readFile(Lexer & lex, FileName const & filename, bformat(_("%1$s is from a different" " version of LyX, but a temporary" " file for converting it could" - " not be created."), + " not be created."), from_utf8(filename.absFilename()))); return failure; } @@ -767,7 +789,7 @@ Buffer::ReadStatus Buffer::readFile(Lexer & lex, FileName const & filename, bformat(_("%1$s is from a different" " version of LyX, but the" " conversion script lyx2lyx" - " could not be found."), + " could not be found."), from_utf8(filename.absFilename()))); return failure; } @@ -786,7 +808,7 @@ Buffer::ReadStatus Buffer::readFile(Lexer & lex, FileName const & filename, Alert::error(_("Conversion script failed"), bformat(_("%1$s is from a different version" " of LyX, but the lyx2lyx script" - " failed to convert it."), + " failed to convert it."), from_utf8(filename.absFilename()))); return failure; } else { @@ -1346,10 +1368,10 @@ void Buffer::getLabelList(vector & list) const } -void Buffer::updateBibfilesCache() const +void Buffer::updateBibfilesCache(UpdateScope scope) const { // If this is a child document, use the parent's cache instead. - if (d->parent_buffer) { + if (d->parent_buffer && scope != UpdateChildOnly) { d->parent_buffer->updateBibfilesCache(); return; } @@ -1368,7 +1390,7 @@ void Buffer::updateBibfilesCache() const static_cast(*it); inset.updateBibfilesCache(); support::FileNameList const & bibfiles = - inset.getBibfilesCache(*this); + inset.getBibfilesCache(); d->bibfilesCache_.insert(d->bibfilesCache_.end(), bibfiles.begin(), bibfiles.end()); @@ -1385,15 +1407,15 @@ void Buffer::invalidateBibinfoCache() } -support::FileNameList const & Buffer::getBibfilesCache() const +support::FileNameList const & Buffer::getBibfilesCache(UpdateScope scope) const { // If this is a child document, use the parent's cache instead. - if (d->parent_buffer) + if (d->parent_buffer && scope != UpdateChildOnly) return d->parent_buffer->getBibfilesCache(); // We update the cache when first used instead of at loading time. if (d->bibfilesCache_.empty()) - const_cast(this)->updateBibfilesCache(); + const_cast(this)->updateBibfilesCache(scope); return d->bibfilesCache_; } @@ -1515,17 +1537,18 @@ bool Buffer::isMultiLingual() const DocIterator Buffer::getParFromID(int const id) const { + Buffer * buf = const_cast(this); if (id < 0) { // John says this is called with id == -1 from undo lyxerr << "getParFromID(), id: " << id << endl; - return doc_iterator_end(inset()); + return doc_iterator_end(buf); } - for (DocIterator it = doc_iterator_begin(inset()); !it.atEnd(); it.forwardPar()) + for (DocIterator it = doc_iterator_begin(buf); !it.atEnd(); it.forwardPar()) if (it.paragraph().id() == id) return it; - return doc_iterator_end(inset()); + return doc_iterator_end(buf); } @@ -1537,25 +1560,25 @@ bool Buffer::hasParWithID(int const id) const ParIterator Buffer::par_iterator_begin() { - return ParIterator(doc_iterator_begin(inset())); + return ParIterator(doc_iterator_begin(this)); } ParIterator Buffer::par_iterator_end() { - return ParIterator(doc_iterator_end(inset())); + return ParIterator(doc_iterator_end(this)); } ParConstIterator Buffer::par_iterator_begin() const { - return lyx::par_const_iterator_begin(inset()); + return ParConstIterator(doc_iterator_begin(this)); } ParConstIterator Buffer::par_iterator_end() const { - return lyx::par_const_iterator_end(inset()); + return ParConstIterator(doc_iterator_end(this)); } @@ -1737,11 +1760,30 @@ DocIterator Buffer::firstChildPosition(Buffer const * child) Impl::BufferPositionMap::iterator it; it = d->children_positions.find(child); if (it == d->children_positions.end()) - return DocIterator(); + return DocIterator(this); return it->second; } +std::vector Buffer::getChildren() const +{ + std::vector clist; + // loop over children + Impl::BufferPositionMap::iterator it = d->children_positions.begin(); + Impl::BufferPositionMap::iterator end = d->children_positions.end(); + for (; it != end; ++it) { + Buffer * child = const_cast(it->first); + clist.push_back(child); + // there might be grandchildren + std::vector glist = child->getChildren(); + for (vector::const_iterator git = glist.begin(); + git != glist.end(); ++git) + clist.push_back(*git); + } + return clist; +} + + template typename M::iterator greatest_below(M & m, typename M::key_type const & x) { @@ -1772,11 +1814,11 @@ MacroData const * Buffer::getBufferMacro(docstring const & name, // find macro definitions for name Impl::NamePositionScopeMacroMap::iterator nameIt - = d->macros.find(name); + = d->macros.find(name); if (nameIt != d->macros.end()) { // find last definition in front of pos or at pos itself Impl::PositionScopeMacroMap::const_iterator it - = greatest_below(nameIt->second, pos); + = greatest_below(nameIt->second, pos); if (it != nameIt->second.end()) { while (true) { // scope ends behind pos? @@ -1799,7 +1841,7 @@ MacroData const * Buffer::getBufferMacro(docstring const & name, // find macros in included files Impl::PositionScopeBufferMap::const_iterator it - = greatest_below(d->position_to_children, pos); + = greatest_below(d->position_to_children, pos); if (it == d->position_to_children.end()) // no children before return bestData; @@ -1906,8 +1948,7 @@ void Buffer::updateMacros(DocIterator & it, DocIterator & scope) const // is it a nested text inset? if (iit->inset->asInsetText()) { // Inset needs its own scope? - InsetText const * itext - = iit->inset->asInsetText(); + InsetText const * itext = iit->inset->asInsetText(); bool newScope = itext->isMacroScope(); // scope which ends just behind the inset @@ -1924,20 +1965,19 @@ void Buffer::updateMacros(DocIterator & it, DocIterator & scope) const // is it an external file? if (iit->inset->lyxCode() == INCLUDE_CODE) { // get buffer of external file - InsetCommand const & inset - = static_cast(*iit->inset); - InsetCommandParams const & ip = inset.params(); + InsetInclude const & inset = + static_cast(*iit->inset); d->macro_lock = true; - Buffer * child = loadIfNeeded(*this, ip); + Buffer * child = inset.getChildBuffer(); d->macro_lock = false; if (!child) continue; // register its position, but only when it is // included first in the buffer - if (d->children_positions.find(child) - == d->children_positions.end()) - d->children_positions[child] = it; + if (d->children_positions.find(child) == + d->children_positions.end()) + d->children_positions[child] = it; // register child with its scope d->position_to_children[it] = Impl::ScopeBuffer(scope, child); @@ -1948,8 +1988,8 @@ void Buffer::updateMacros(DocIterator & it, DocIterator & scope) const continue; // get macro data - MathMacroTemplate & macroTemplate - = static_cast(*iit->inset); + MathMacroTemplate & macroTemplate = + static_cast(*iit->inset); MacroContext mc(*this, it); macroTemplate.updateToContext(mc); @@ -2000,8 +2040,8 @@ void Buffer::updateMacroInstances() const { LYXERR(Debug::MACROS, "updateMacroInstances for " << d->filename.onlyFileName()); - DocIterator it = doc_iterator_begin(inset()); - DocIterator end = doc_iterator_end(inset()); + DocIterator it = doc_iterator_begin(this); + DocIterator end = doc_iterator_end(this); for (; it != end; it.forwardPos()) { // look for MathData cells in InsetMathNest insets Inset * inset = it.nextInset(); @@ -2265,6 +2305,12 @@ void Buffer::resetAutosaveTimers() const } +bool Buffer::hasGuiDelegate() const +{ + return gui_; +} + + void Buffer::setGuiDelegate(frontend::GuiBufferDelegate * gui) { gui_ = gui; @@ -2682,9 +2728,13 @@ void Buffer::bufferErrors(TeXErrors const & terr, ErrorList & errorList) const } -// FIXME: buf should should be const because updateLabels() modifies -// the contents of the paragraphs. -void Buffer::updateLabels(bool childonly) const +void Buffer::setBuffersForInsets() const +{ + inset().setBuffer(const_cast(*this)); +} + + +void Buffer::updateLabels(UpdateScope scope) const { // Use the master text class also for child documents Buffer const * const master = masterBuffer(); @@ -2694,11 +2744,15 @@ void Buffer::updateLabels(bool childonly) const // master comes back we can see which of them were actually seen (i.e. // via an InsetInclude). The remaining ones in the set need still be updated. static std::set bufToUpdate; - if (!childonly) { + if (scope == UpdateMaster) { // If this is a child document start with the master if (master != this) { bufToUpdate.insert(this); - master->updateLabels(false); + master->updateLabels(); + // Do this here in case the master has no gui associated with it. Then, + // the TocModel is not updated and TocModel::toc_ is invalid (bug 5699). + if (!master->gui_) + structureChanged(); // was buf referenced from the master (i.e. not in bufToUpdate anymore)? if (bufToUpdate.find(this) == bufToUpdate.end()) @@ -2714,7 +2768,6 @@ void Buffer::updateLabels(bool childonly) const // update all caches clearReferenceCache(); - inset().setBuffer(const_cast(*this)); updateMacros(); Buffer & cbuf = const_cast(*this); @@ -2730,7 +2783,7 @@ void Buffer::updateLabels(bool childonly) const return; cbuf.tocBackend().update(); - if (!childonly) + if (scope == UpdateMaster) cbuf.structureChanged(); }