#include "buffer.h"
#include "bufferlist.h"
#include "bufferparams.h"
+#include "dociterator.h"
#include "errorlist.h"
#include "gettext.h"
#include "LaTeX.h"
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()) {
&& 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")))
&& 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") ))
bool loadLyXFile(Buffer * b, string const & s)
{
+ BOOST_ASSERT(b);
+
switch (IsFileWriteable(s)) {
case 0:
b->setReadonly(true);
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"));
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.
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;
+}