mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
implement Word counting (bug 728)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9402 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
f1e9f57553
commit
a839021d22
@ -1,3 +1,7 @@
|
||||
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.
|
||||
|
@ -402,6 +402,7 @@ Menuset
|
||||
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
|
||||
|
@ -958,6 +958,7 @@ FuncStatus BufferView::Pimpl::getStatus(FuncRequest const & cmd)
|
||||
case LFUN_MARK_ON:
|
||||
case LFUN_SETMARK:
|
||||
case LFUN_CENTER:
|
||||
case LFUN_WORDS_COUNT:
|
||||
flag.enabled(true);
|
||||
break;
|
||||
|
||||
@ -1130,6 +1131,35 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
|
||||
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;
|
||||
}
|
||||
|
@ -1,3 +1,14 @@
|
||||
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/.
|
||||
|
@ -339,6 +339,7 @@ void LyXAction::init()
|
||||
{ LFUN_INSET_REFRESH, "", Noop },
|
||||
{ LFUN_NEXTBUFFER, "buffer-next", ReadOnly },
|
||||
{ LFUN_PREVIOUSBUFFER, "buffer-previous", ReadOnly },
|
||||
{ LFUN_WORDS_COUNT, "words-count", ReadOnly },
|
||||
{ LFUN_NOACTION, "", Noop }
|
||||
};
|
||||
|
||||
|
@ -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"
|
||||
@ -228,3 +229,26 @@ 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;
|
||||
}
|
||||
|
||||
|
@ -16,8 +16,9 @@
|
||||
|
||||
|
||||
class Buffer;
|
||||
class TeXErrors;
|
||||
class DocIterator;
|
||||
class ErrorList;
|
||||
class TeXErrors;
|
||||
|
||||
/**
|
||||
* Loads a LyX file \c filename into \c Buffer
|
||||
@ -38,4 +39,8 @@ void bufferErrors(Buffer const &, TeXErrors const &);
|
||||
///
|
||||
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
|
||||
|
@ -352,6 +352,8 @@ enum kb_action {
|
||||
LFUN_INSET_REFRESH,
|
||||
LFUN_NEXTBUFFER,
|
||||
LFUN_PREVIOUSBUFFER,
|
||||
// 270
|
||||
LFUN_WORDS_COUNT,
|
||||
|
||||
LFUN_LASTACTION // end of the table
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user