]> git.lyx.org Git - lyx.git/blobdiff - src/buffer_funcs.cpp
Kornel's gcc compile fix.
[lyx.git] / src / buffer_funcs.cpp
index 861413dcd96245679e8e807ffcec3050e6bad551..ee52fc68ec0f687c533e90209e988f3ec7568887 100644 (file)
@@ -28,7 +28,6 @@
 #include "LyX.h"
 #include "TextClass.h"
 #include "Paragraph.h"
-#include "paragraph_funcs.h"
 #include "ParagraphList.h"
 #include "ParagraphParameters.h"
 #include "ParIterator.h"
@@ -57,12 +56,15 @@ namespace lyx {
 namespace Alert = frontend::Alert;
 
 
-Buffer * checkAndLoadLyXFile(FileName const & filename)
+Buffer * checkAndLoadLyXFile(FileName const & filename, bool const acceptDirty)
 {
        // File already open?
        Buffer * checkBuffer = theBufferList().getBuffer(filename);
        if (checkBuffer) {
-               if (checkBuffer->isClean())
+               // sometimes (when setting the master buffer from a child)
+               // we accept a dirty buffer right away (otherwise we'd get
+               // an infinite loop (bug 5514)
+               if (checkBuffer->isClean() || acceptDirty)
                        return checkBuffer;
                docstring const file = makeDisplayPath(filename.absFilename(), 20);
                docstring text = bformat(_(
@@ -165,41 +167,68 @@ Buffer * newUnnamedFile(string const & templatename, FileName const & path)
        return newFile(filename.absFilename(), templatename, false);
 }
 
-
+/* 
+ * FIXME : merge with countChars. The structures of the two functions
+ * are similar but, unfortunately, they seem to have a different
+ * notion of what to count. Since nobody ever complained about that,
+ * this proves (again) that any number beats no number ! (JMarc)
+ */
 int countWords(DocIterator const & from, DocIterator const & to)
 {
        int count = 0;
        bool inword = false;
-       for (DocIterator dit = from ; dit != to ; dit.forwardPos()) {
-               // Copied and adapted from isLetter() in ControlSpellChecker
-               if (dit.inTexted()
-                   && dit.pos() != dit.lastpos()
-                   && dit.paragraph().isLetter(dit.pos())
-                   && !dit.paragraph().isDeleted(dit.pos())) {
-                       if (!inword) {
+       for (DocIterator dit = from ; dit != to ; ) {
+               if (!dit.inTexted()) {
+                       dit.forwardPos();
+                       continue;
+               }
+               
+               Paragraph const & par = dit.paragraph();
+               pos_type const pos = dit.pos();
+               
+               // Copied and adapted from isWordSeparator() in Paragraph
+               if (pos != dit.lastpos() && !par.isDeleted(pos)) {
+                       Inset const * ins = par.getInset(pos);
+                       if (ins && !ins->producesOutput()) {
+                               //skip this inset
+                               ++dit.top().pos();
+                               continue;
+                       }
+                       if (par.isWordSeparator(pos)) 
+                               inword = false;
+                       else if (!inword) {
                                ++count;
                                inword = true;
                        }
-               } else if (inword)
-                       inword = false;
+               }
+               dit.forwardPos();
        }
 
        return count;
 }
 
 
-int countChars(DocIterator const & from, DocIterator const & to, bool with_blanks)
+int countChars(DocIterator const & from, DocIterator const & to, 
+              bool with_blanks)
 {
        int chars = 0;
        int blanks = 0;
-       for (DocIterator dit = from ; dit != to ; dit.forwardPos()) {
-
-               if (!dit.inTexted()) continue;
+       for (DocIterator dit = from ; dit != to ; ) {
+               if (!dit.inTexted()) {
+                       dit.forwardPos();
+                       continue;
+               }
+               
                Paragraph const & par = dit.paragraph();
                pos_type const pos = dit.pos();
-
+               
                if (pos != dit.lastpos() && !par.isDeleted(pos)) {
                        if (Inset const * ins = par.getInset(pos)) {
+                               if (!ins->producesOutput()) {
+                                       //skip this inset
+                                       ++dit.top().pos();
+                                       continue;
+                               }
                                if (ins->isLetter())
                                        ++chars;
                                else if (with_blanks && ins->isSpace())
@@ -212,6 +241,7 @@ int countChars(DocIterator const & from, DocIterator const & to, bool with_blank
                                        ++blanks;
                        }
                }
+               dit.forwardPos();
        }
 
        return chars + blanks;