]> git.lyx.org Git - lyx.git/blobdiff - src/Buffer.cpp
EmbeddedObjects.lyx, Math.lyx, UserGuide.lyx: Spanish translation updates by Ignacio
[lyx.git] / src / Buffer.cpp
index f73bbb1ba1d5f5ceb30259ebda60c2a261543836..5be6679dca5479e1ea9c3d989919eba9eb629ee9 100644 (file)
 #include <fstream>
 #include <iomanip>
 #include <map>
+#include <set>
 #include <sstream>
 #include <stack>
 #include <vector>
@@ -117,13 +118,15 @@ 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 = 346;  // jspitzm: Swiss German
 
 typedef map<string, bool> DepClean;
 typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
 
 } // namespace anon
 
+class BufferSet : public std::set<Buffer const *> {};
+
 class Buffer::Impl
 {
 public:
@@ -585,7 +588,7 @@ bool Buffer::readDocument(Lexer & lex)
                FileName const master_file = makeAbsPath(params().master,
                           onlyPath(absFileName()));
                if (isLyXFilename(master_file.absFilename())) {
-                       Buffer * master = checkAndLoadLyXFile(master_file);
+                       Buffer * master = checkAndLoadLyXFile(master_file, true);
                        d->parent_buffer = master;
                }
        }
@@ -682,6 +685,8 @@ bool Buffer::readFile(FileName const & filename)
 {
        FileName fname(filename);
 
+       params().compressed = fname.isZippedFile();
+
        // remove dummy empty par
        paragraphs().clear();
        Lexer lex;
@@ -1512,17 +1517,18 @@ bool Buffer::isMultiLingual() const
 
 DocIterator Buffer::getParFromID(int const id) const
 {
+       Buffer * buf = const_cast<Buffer *>(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);
 }
 
 
@@ -1534,25 +1540,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));
 }
 
 
@@ -1682,12 +1688,38 @@ void Buffer::setParent(Buffer const * buffer)
 }
 
 
-Buffer const * Buffer::parent()
+Buffer const * Buffer::parent() const
 {
        return d->parent_buffer;
 }
 
 
+void Buffer::collectRelatives(BufferSet & bufs) const
+{
+       bufs.insert(this);
+       if (parent())
+               parent()->collectRelatives(bufs);
+
+       // loop over children
+       Impl::BufferPositionMap::iterator it = d->children_positions.begin();
+       Impl::BufferPositionMap::iterator end = d->children_positions.end();
+       for (; it != end; ++it)
+               bufs.insert(const_cast<Buffer *>(it->first));
+}
+
+
+std::vector<Buffer const *> Buffer::allRelatives() const
+{
+       BufferSet bufs;
+       collectRelatives(bufs);
+       BufferSet::iterator it = bufs.begin();
+       std::vector<Buffer const *> ret;
+       for (; it != bufs.end(); ++it)
+               ret.push_back(*it);
+       return ret;
+}
+
+
 Buffer const * Buffer::masterBuffer() const
 {
        if (!d->parent_buffer)
@@ -1703,6 +1735,16 @@ bool Buffer::isChild(Buffer * child) const
 }
 
 
+DocIterator Buffer::firstChildPosition(Buffer const * child)
+{
+       Impl::BufferPositionMap::iterator it;
+       it = d->children_positions.find(child);
+       if (it == d->children_positions.end())
+               return DocIterator(this);
+       return it->second;
+}
+
+
 template<typename M>
 typename M::iterator greatest_below(M & m, typename M::key_type const & x)
 {
@@ -1733,11 +1775,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?
@@ -1760,7 +1802,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;
@@ -1885,11 +1927,10 @@ 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<InsetCommand const &>(*iit->inset);
-                               InsetCommandParams const & ip = inset.params();
+                               InsetInclude const & inset
+                                       = static_cast<InsetInclude const &>(*iit->inset);
                                d->macro_lock = true;
-                               Buffer * child = loadIfNeeded(*this, ip);
+                               Buffer * child = inset.loadIfNeeded(*this);
                                d->macro_lock = false;
                                if (!child)
                                        continue;
@@ -1961,8 +2002,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();
@@ -2643,8 +2684,6 @@ 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
 {
        // Use the master text class also for child documents