]> git.lyx.org Git - lyx.git/blobdiff - src/buffer_funcs.C
Fix bug 2404
[lyx.git] / src / buffer_funcs.C
index 67129e04c1c14d212a8668e57e835fc8b51890ad..a306de412efbce0716e08b1f3e0d13519da27e2d 100644 (file)
@@ -33,6 +33,7 @@
 #include "lyxvc.h"
 #include "texrow.h"
 #include "vc-backend.h"
+#include "toc.h"
 
 #include "frontends/Alert.h"
 
 #include "support/fs_extras.h"
 #include "support/lyxlib.h"
 
+#include <iostream>
+
 #include <boost/bind.hpp>
 #include <boost/filesystem/operations.hpp>
 
+using namespace std;
+
 using lyx::pit_type;
 using lyx::support::bformat;
 using lyx::support::libFileSearch;
@@ -189,7 +194,8 @@ Buffer * newFile(string const & filename, string const & templatename,
                        string const file = makeDisplayPath(tname, 50);
                        string const text  = bformat(_("The specified document template\n%1$s\ncould not be read."), file);
                        Alert::error(_("Could not read template"), text);
-                       // no template, start with empty buffer
+                       bufferlist.release(b);
+                       return 0;
                }
        }
 
@@ -225,15 +231,15 @@ void bufferErrors(Buffer const & buf, TeXErrors const & terr)
                                                          pos_end);
                } while (found && id_start == id_end && pos_start == pos_end);
 
-               buf.error(ErrorItem(cit->error_desc, cit->error_text,
-                                   id_start, pos_start, pos_end));
+               buf.addError(ErrorItem(cit->error_desc,
+                       cit->error_text, id_start, pos_start, pos_end));
        }
 }
 
 
 void bufferErrors(Buffer const & buf, ErrorList const & el)
 {
-       for_each(el.begin(), el.end(), bind(ref(buf.error), _1));
+       buf.setErrorList(el);
 }
 
 
@@ -346,8 +352,8 @@ bool needEnumCounterReset(ParIterator const & it)
 }
 
 
-// set the counter of a paragraph. This includes the labels
-void setCounter(Buffer const & buf, ParIterator & it)
+// set the label of a paragraph. This includes the counters.
+void setLabel(Buffer const & buf, ParIterator & it)
 {
        Paragraph & par = *it;
        BufferParams const & bufparams = buf.params();
@@ -496,17 +502,26 @@ void setCounter(Buffer const & buf, ParIterator & it)
                }
 
                par.params().labelString(s);
-       } else
+       } else if (layout->labeltype == LABEL_NO_LABEL)
+               par.params().labelString(string());
+       else
                par.params().labelString(buf.B_(layout->labelstring()));
 }
 
 } // anon namespace
 
 
-bool needsUpdateCounters(Buffer const & buf, ParIterator & it)
+bool updateCurrentLabel(Buffer const & buf, 
+       ParIterator & it)       
 {
-       switch (it->layout()->labeltype) {
+    if (it == par_iterator_end(buf.inset()))
+        return false;
+
+//     if (it.lastpit == 0 && LyXText::isMainText())
+//             return false;
 
+       switch (it->layout()->labeltype) {
+               
        case LABEL_NO_LABEL:
        case LABEL_MANUAL:
        case LABEL_BIBLIO:
@@ -514,24 +529,53 @@ bool needsUpdateCounters(Buffer const & buf, ParIterator & it)
        case LABEL_CENTERED_TOP_ENVIRONMENT:
        case LABEL_STATIC:
        case LABEL_ITEMIZE:
-               setCounter(buf, it);
-               return false;
+               setLabel(buf, it);
+               return true;
 
        case LABEL_SENSITIVE:
        case LABEL_COUNTER:
        // do more things with enumerate later
        case LABEL_ENUMERATE:
-               return true;
+               return false;
        }
+
+       // This is dead code which get rid of a warning:
+       return true;
 }
 
 
-void updateCounters(Buffer const & buf)
+void updateLabels(Buffer const & buf, 
+       ParIterator & from, ParIterator & to)
 {
-       // start over
+       for (ParIterator it = from; it != to; ++it) {
+               if (it.pit() > it.lastpit())
+                       return;
+               if (!updateCurrentLabel (buf, it)) {
+                       updateLabels(buf);
+                       return;
+               }
+       }
+}
+
+
+void updateLabels(Buffer const & buf, 
+       ParIterator & iter)
+{
+       if (updateCurrentLabel(buf, iter))
+               return;
+
+       updateLabels(buf);
+}
+
+
+void updateLabels(Buffer const & buf)
+{
+       // start over the counters
        buf.params().getLyXTextClass().counters().reset();
+       
+       ParIterator const end = par_iterator_end(buf.inset());
 
-       for (ParIterator it = par_iterator_begin(buf.inset()); it; ++it) {
+       for (ParIterator it = par_iterator_begin(buf.inset()); it != end; ++it) {
                // reduce depth if necessary
                if (it.pit()) {
                        Paragraph const & prevpar = it.plist()[it.pit() - 1];
@@ -541,8 +585,10 @@ void updateCounters(Buffer const & buf)
                        it->params().depth(0);
 
                // set the counter for this paragraph
-               setCounter(buf, it);
+               setLabel(buf, it);
        }
+
+       lyx::toc::updateToc(buf);
 }