]> git.lyx.org Git - lyx.git/blobdiff - src/Buffer.cpp
Buffer::resetChildDocuments() Check for Buffer emptiness before proceeding.
[lyx.git] / src / Buffer.cpp
index 83c182a99c66245abfa574b51dd3e5f986fab5e6..c90e30a2e267af9d7cff9199d7c2e1517e4509af 100644 (file)
@@ -79,7 +79,6 @@
 #include "support/convert.h"
 #include "support/debug.h"
 #include "support/ExceptionMessage.h"
-#include "support/FileFilterList.h"
 #include "support/FileName.h"
 #include "support/FileNameList.h"
 #include "support/filetools.h"
@@ -114,7 +113,7 @@ namespace os = support::os;
 
 namespace {
 
-int const LYX_FORMAT = 314; // Uwe Stöhr: scrlttr2 for serial letters
+int const LYX_FORMAT = 315; // Richard Heck: column separation
 
 } // namespace anon
 
@@ -467,6 +466,7 @@ int Buffer::readHeader(Lexer & lex)
        params().headheight.erase();
        params().headsep.erase();
        params().footskip.erase();
+       params().columnsep.erase();
        params().listings_params.clear();
        params().clearLayoutModules();
        params().pdfoptions().clear();
@@ -568,10 +568,7 @@ bool Buffer::readDocument(Lexer & lex)
        }
 
        // read main text
-       bool const res = text().read(*this, lex, errorList);
-       for_each(text().paragraphs().begin(),
-                text().paragraphs().end(),
-                bind(&Paragraph::setInsetOwner, _1, &inset()));
+       bool const res = text().read(*this, lex, errorList, &(d->inset));
 
        updateMacros();
        updateMacroInstances();
@@ -1486,60 +1483,37 @@ bool Buffer::isMultiLingual() const
 }
 
 
-ParConstIterator Buffer::getParFromID(int const id) const
+DocIterator Buffer::getParFromID(int const id) const
 {
-       ParConstIterator it = par_iterator_begin();
-       ParConstIterator const end = par_iterator_end();
-
-       if (id < 0) {
-               // John says this is called with id == -1 from undo
-               lyxerr << "getParFromID(), id: " << id << endl;
-               return end;
-       }
-
-       for (; it != end; ++it)
-               if (it->id() == id)
-                       return it;
-
-       return end;
-}
-
-
-ParIterator Buffer::getParFromID(int const id)
-{
-       ParIterator it = par_iterator_begin();
-       ParIterator const end = par_iterator_end();
-
        if (id < 0) {
                // John says this is called with id == -1 from undo
                lyxerr << "getParFromID(), id: " << id << endl;
-               return end;
+               return doc_iterator_end(inset());
        }
 
-       for (; it != end; ++it)
-               if (it->id() == id)
+       for (DocIterator it = doc_iterator_begin(inset()); !it.atEnd(); it.forwardPar())
+               if (it.paragraph().id() == id)
                        return it;
 
-       return end;
+       return doc_iterator_end(inset());
 }
 
 
 bool Buffer::hasParWithID(int const id) const
 {
-       ParConstIterator const it = getParFromID(id);
-       return it != par_iterator_end();
+       return !getParFromID(id).atEnd();
 }
 
 
 ParIterator Buffer::par_iterator_begin()
 {
-       return lyx::par_iterator_begin(inset());
+       return ParIterator(doc_iterator_begin(inset()));
 }
 
 
 ParIterator Buffer::par_iterator_end()
 {
-       return lyx::par_iterator_end(inset());
+       return ParIterator(doc_iterator_end(inset()));
 }
 
 
@@ -1754,31 +1728,33 @@ MacroData const * Buffer::getBufferMacro(docstring const & name,
        // find macros in included files
        Impl::PositionScopeBufferMap::const_iterator it
        = greatest_below(d->position_to_children, pos);
-       if (it != d->position_to_children.end()) {
-               while (true) {
-                       // do we know something better (i.e. later) already?
-                       if (it->first < bestPos )               
-                               break;
+       if (it == d->position_to_children.end())
+               // no children before
+               return bestData;
 
-                       // scope ends behind pos?
-                       if (pos < it->second.first) {
-                               // look for macro in external file
-                               d->macro_lock = true;
-                               MacroData const * data
-                               = it->second.second->getMacro(name, false);
-                               d->macro_lock = false;
-                               if (data) {
-                                       bestPos = it->first;
-                                       bestData = data;                               
-                                       break;
-                               }
-                       }
-                       
-                       // try previous file if there is one
-                       if (it == d->position_to_children.begin())
+       while (true) {
+               // do we know something better (i.e. later) already?
+               if (it->first < bestPos )
+                       break;
+
+               // scope ends behind pos?
+               if (pos < it->second.first) {
+                       // look for macro in external file
+                       d->macro_lock = true;
+                       MacroData const * data
+                       = it->second.second->getMacro(name, false);
+                       d->macro_lock = false;
+                       if (data) {
+                               bestPos = it->first;
+                               bestData = data;
                                break;
-                       --it;
+                       }
                }
+
+               // try previous file if there is one
+               if (it == d->position_to_children.begin())
+                       break;
+               --it;
        }
                
        // return the best macro we have found
@@ -1899,7 +1875,7 @@ void Buffer::updateEnvironmentMacros(DocIterator & it,
                                if (!child)
                                        continue;                               
 
-                               // register it, but only when it is
+                               // register its position, but only when it is
                                // included first in the buffer
                                if (d->children_positions.find(child)
                                    == d->children_positions.end())
@@ -2009,8 +1985,8 @@ void Buffer::updateMacroInstances() const
 {
        LYXERR(Debug::MACROS, "updateMacroInstances for "
                << d->filename.onlyFileName());
-       ParConstIterator it = par_iterator_begin();
-       ParConstIterator end = par_iterator_end();
+       DocIterator it = doc_iterator_begin(inset());
+       DocIterator end = doc_iterator_end(inset());
        for (; it != end; it.forwardPos()) {
                // look for MathData cells in InsetMathNest insets
                Inset * inset = it.nextInset();
@@ -2336,6 +2312,9 @@ void Buffer::autoSave() const
 
 void Buffer::resetChildDocuments(bool close_them) const
 {
+       if (text().empty())
+               return;
+
        for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) {
                if (it->lyxCode() != INCLUDE_CODE)
                        continue;