]> git.lyx.org Git - lyx.git/blobdiff - src/buffer_funcs.C
Fix my breakage. Sorry guys.
[lyx.git] / src / buffer_funcs.C
index 2f41213184713f006c812cc18a806e95ec0ffe36..8bd78d70ed1f3cd6d934aa3d8f2bdddfbdf98aaf 100644 (file)
@@ -17,6 +17,7 @@
 #include "buffer.h"
 #include "bufferlist.h"
 #include "bufferparams.h"
+#include "dociterator.h"
 #include "errorlist.h"
 #include "gettext.h"
 #include "LaTeX.h"
@@ -49,8 +50,10 @@ extern BufferList bufferlist;
 
 namespace {
 
-bool readFile(Buffer * b, string const & s)
+bool readFile(Buffer * const b, string const & s)
 {
+       BOOST_ASSERT(b);
+
        // File information about normal file
        FileInfo fileN(s);
        if (!fileN.exist()) {
@@ -69,9 +72,10 @@ bool readFile(Buffer * b, string const & s)
            && fileE.getModificationTime() > fileN.getModificationTime())
        {
                string const file = MakeDisplayPath(s, 20);
-               string text = bformat(_("An emergency save of the document "
-                                       "%1$s exists.\n\n"
-                                       "Recover emergency save?"), file);
+               string const text =
+                       bformat(_("An emergency save of the document "
+                                 "%1$s exists.\n\n"
+                                 "Recover emergency save?"), file);
                switch (Alert::prompt(_("Load emergency save?"), text, 0, 2,
                                      _("&Recover"),  _("&Load Original"),
                                      _("&Cancel")))
@@ -95,9 +99,10 @@ bool readFile(Buffer * b, string const & s)
            && fileA.getModificationTime() > fileN.getModificationTime())
        {
                string const file = MakeDisplayPath(s, 20);
-               string text = bformat(_("The backup of the document "
-                                       "%1$s is newer.\n\nLoad the "
-                                       "backup instead?"), file);
+               string const text =
+                       bformat(_("The backup of the document "
+                                 "%1$s is newer.\n\nLoad the "
+                                 "backup instead?"), file);
                switch (Alert::prompt(_("Load backup?"), text, 0, 2,
                                      _("&Load backup"), _("Load &original"),
                                      _("&Cancel") ))
@@ -124,6 +129,8 @@ bool readFile(Buffer * b, string const & s)
 
 bool loadLyXFile(Buffer * b, string const & s)
 {
+       BOOST_ASSERT(b);
+
        switch (IsFileWriteable(s)) {
        case 0:
                b->setReadonly(true);
@@ -138,8 +145,9 @@ bool loadLyXFile(Buffer * b, string const & s)
                string const file = MakeDisplayPath(s, 20);
                // Here we probably should run
                if (LyXVC::file_not_found_hook(s)) {
-                       string text = bformat(_("Do you want to retrieve the document"
-                               " %1$s from version control?"), file);
+                       string const text =
+                               bformat(_("Do you want to retrieve the document"
+                                         " %1$s from version control?"), file);
                        int const ret = Alert::prompt(_("Retrieve from version control?"),
                                text, 0, 1, _("&Retrieve"), _("&Cancel"));
 
@@ -158,10 +166,11 @@ bool loadLyXFile(Buffer * b, string const & s)
 
 
 Buffer * newFile(string const & filename, string const & templatename,
-                bool isNamed)
+                bool const isNamed)
 {
        // get a free buffer
        Buffer * b = bufferlist.newBuffer(filename);
+       BOOST_ASSERT(b);
 
        string tname;
        // use defaults.lyx as a default template if it exists.
@@ -228,3 +237,25 @@ string const BufferFormat(Buffer const & buffer)
        else
                return "latex";
 }
+
+
+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())
+                   && !isDeletedText(dit.paragraph(), dit.pos())) {
+                       if (!inword) {
+                               ++count;
+                               inword = true;
+                       }
+               } else if (inword)
+                       inword = false;
+       }
+
+       return count;
+}