]> git.lyx.org Git - lyx.git/blobdiff - src/Buffer.cpp
Clean-up the code with respect to PassThru insets and layouts.
[lyx.git] / src / Buffer.cpp
index 1cd24493fced6dfa250ff89fc2371f39f2b212e7..15e05177f3bad8d2353b54c0fe3c51fab46aeeb3 100644 (file)
@@ -157,15 +157,14 @@ public:
                }
                delete inset;
        }
-
+       
        /// search for macro in local (buffer) table or in children
        MacroData const * getBufferMacro(docstring const & name,
                DocIterator const & pos) const;
 
        /// Update macro table starting with position of it \param it in some
        /// text inset.
-       void updateMacros(DocIterator & it, DocIterator & scope,
-                       bool record_docits = false);
+       void updateMacros(DocIterator & it, DocIterator & scope);
        ///
        void setLabel(ParIterator & it, UpdateType utype) const;
        ///
@@ -289,7 +288,9 @@ public:
        /// If non zero, this buffer is a clone of existing buffer \p cloned_buffer_
        /// This one is useful for preview detached in a thread.
        Buffer const * cloned_buffer_;
-
+       /// are we in the process of exporting this buffer?
+       mutable bool doing_export;
+       
 private:
        /// So we can force access via the accessors.
        mutable Buffer const * parent_buffer;
@@ -322,7 +323,7 @@ Buffer::Impl::Impl(Buffer * owner, FileName const & file, bool readonly_,
          read_only(readonly_), filename(file), file_fully_loaded(false),
          toc_backend(owner), macro_lock(false), timestamp_(0),
          checksum_(0), wa_(0), gui_(0), undo_(*owner), bibinfo_cache_valid_(false),
-         cloned_buffer_(cloned_buffer), parent_buffer(0)
+         cloned_buffer_(cloned_buffer), doing_export(false), parent_buffer(0)
 {
        if (!cloned_buffer_) {
                temppath = createBufferTmpDir();
@@ -1574,7 +1575,7 @@ void Buffer::writeLyXHTMLSource(odocstream & os,
        updateBuffer(UpdateMaster, OutputUpdate);
        checkBibInfoCache();
        d->bibinfo_.makeCitationLabels(*this);
-       updateMacros(true);
+       updateMacros();
        updateMacroInstances();
 
        if (!only_body) {
@@ -2363,6 +2364,7 @@ void Buffer::markClean() const
        // if the .lyx file has been saved, we don't need an
        // autosave
        d->bak_clean = true;
+       d->undo_.markDirty();
 }
 
 
@@ -2666,8 +2668,7 @@ MacroData const * Buffer::getMacro(docstring const & name,
 }
 
 
-void Buffer::Impl::updateMacros(DocIterator & it, DocIterator & scope,
-               bool record_docits)
+void Buffer::Impl::updateMacros(DocIterator & it, DocIterator & scope)
 {
        pit_type const lastpit = it.lastpit();
 
@@ -2721,7 +2722,7 @@ void Buffer::Impl::updateMacros(DocIterator & it, DocIterator & scope,
                                continue;
                        }
 
-                       if (record_docits && iit->inset->asInsetMath()) {
+                       if (doing_export && iit->inset->asInsetMath()) {
                                InsetMath * im = static_cast<InsetMath *>(iit->inset);
                                if (im->asHullInset()) {
                                        InsetMathHull * hull = static_cast<InsetMathHull *>(im);
@@ -2760,7 +2761,7 @@ void Buffer::Impl::updateMacros(DocIterator & it, DocIterator & scope,
 }
 
 
-void Buffer::updateMacros(bool record_docit) const
+void Buffer::updateMacros() const
 {
        if (d->macro_lock)
                return;
@@ -2779,7 +2780,7 @@ void Buffer::updateMacros(bool record_docit) const
        DocIterator it = par_iterator_begin();
        DocIterator outerScope = it;
        outerScope.pit() = outerScope.lastpit() + 2;
-       d->updateMacros(it, outerScope, record_docit);
+       d->updateMacros(it, outerScope);
 }
 
 
@@ -3260,10 +3261,41 @@ string Buffer::getDefaultOutputFormat() const
 }
 
 
+namespace {
+       // helper class, to guarantee this gets reset properly
+       class MarkAsExporting   {
+       public:
+               MarkAsExporting(Buffer const * buf) : buf_(buf) 
+               {
+                       LASSERT(buf_, /* */);
+                       buf_->setExportStatus(true);
+               }
+               ~MarkAsExporting() 
+               {
+                       buf_->setExportStatus(false);
+               }
+       private:
+               Buffer const * const buf_;
+       };
+}
+
+
+void Buffer::setExportStatus(bool e) const
+{
+       d->doing_export = e;    
+}
+
+
+bool Buffer::isExporting() const
+{
+       return d->doing_export;
+}
+
 
 bool Buffer::doExport(string const & format, bool put_in_tempdir,
        bool includeall, string & result_file) const
 {
+       MarkAsExporting exporting(this);
        string backend_format;
        OutputParams runparams(&params().encoding());
        runparams.flavor = OutputParams::LATEX;
@@ -3460,6 +3492,7 @@ bool Buffer::doExport(string const & format, bool put_in_tempdir,
 
 bool Buffer::preview(string const & format, bool includeall) const
 {
+       MarkAsExporting exporting(this);
        string result_file;
        // (1) export with all included children (omit \includeonly)
        if (includeall && !doExport(format, true, true))
@@ -3963,7 +3996,8 @@ int Buffer::spellCheck(DocIterator & from, DocIterator & to,
                if (from == end)
                        break;
                to = from;
-               if (from.paragraph().spellCheck(from.pos(), to.pos(), wl, suggestions)) {
+               SpellChecker::Result res = from.paragraph().spellCheck(from.pos(), to.pos(), wl, suggestions);
+               if (SpellChecker::misspelled(res)) {
                        word_lang = wl;
                        break;
                }