+2004-12-22 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
+
+ * ui/stdmenus.ui: add entry for words-count
+
2004-12-17 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* Makefile.am: honor the textrm_*.xpm renaming.
Menu "tools"
Item "Spellchecker...|S" "dialog-show spellchecker"
OptItem "Thesaurus...|T" "thesaurus-entry"
+ Item "Count Words|W" "words-count"
OptItem "Check TeX|h" "buffer-chktex"
Item "TeX Information...|I" "dialog-show texinfo"
Separator
case LFUN_MARK_ON:
case LFUN_SETMARK:
case LFUN_CENTER:
+ case LFUN_WORDS_COUNT:
flag.enabled(true);
break;
bv_->center();
break;
+ case LFUN_WORDS_COUNT: {
+ DocIterator from, to;
+ if (cur.selection()) {
+ from = cur.selectionBegin();
+ to = cur.selectionEnd();
+ } else {
+ from = doc_iterator_begin(bv_->buffer()->inset());
+ to = doc_iterator_end(bv_->buffer()->inset());
+ }
+ int const count = countWords(from, to);
+ string message;
+ if (count != 1) {
+ if (cur.selection())
+ message = bformat(_("%1$s words in selection."),
+ tostr(count));
+ else
+ message = bformat(_("%1$s words in document."),
+ tostr(count));
+ }
+ else {
+ if (cur.selection())
+ message = _("One word in selection.");
+ else
+ message = _("One word in document.");
+ }
+
+ Alert::information(_("Count words"), message);
+ }
+ break;
default:
return false;
}
+2004-12-22 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
+
+ * buffer_funcs.C (countWords): new function. Counts words between
+ two iterators.
+
+ * BufferView_pimpl.C (getStatus, dispatch): handle
+ LFUN_WORDS_COUNT.
+
+ * LyXAction.C (init):
+ * lfuns.h: add LFUN_WORDS_COUNT.
+
2004-12-19 Angus Leeming <leeming@lyx.org>
* buffer.C (save): s/slashify_path/internal_path/.
{ LFUN_INSET_REFRESH, "", Noop },
{ LFUN_NEXTBUFFER, "buffer-next", ReadOnly },
{ LFUN_PREVIOUSBUFFER, "buffer-previous", ReadOnly },
+ { LFUN_WORDS_COUNT, "words-count", ReadOnly },
{ LFUN_NOACTION, "", Noop }
};
#include "buffer.h"
#include "bufferlist.h"
#include "bufferparams.h"
+#include "dociterator.h"
#include "errorlist.h"
#include "gettext.h"
#include "LaTeX.h"
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;
+}
+
class Buffer;
-class TeXErrors;
+class DocIterator;
class ErrorList;
+class TeXErrors;
/**
* Loads a LyX file \c filename into \c Buffer
///
void bufferErrors(Buffer const &, ErrorList const &);
+/// Count the number of words in the text between these two iterators
+int countWords(DocIterator const & from, DocIterator const & to);
+
+
#endif // BUFFER_FUNCS_H
LFUN_INSET_REFRESH,
LFUN_NEXTBUFFER,
LFUN_PREVIOUSBUFFER,
+ // 270
+ LFUN_WORDS_COUNT,
LFUN_LASTACTION // end of the table
};
(xforms): replace the Combox code with a native xforms widget, for eventual
inclusion in the xforms library itself.
+
+Add a basic Word Count feature.