mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-23 13:31:49 +00:00
spellcheck cleanup
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8024 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
d0cfc869e8
commit
918df906bb
@ -1,3 +1,8 @@
|
|||||||
|
2003-11-04 Alfredo Braunstein <abraunst@libero.it>
|
||||||
|
|
||||||
|
* ControlSpellchecker.[Ch] (nextWord, check): rewrite of the text
|
||||||
|
handling parts
|
||||||
|
|
||||||
2003-10-27 Juergen Spitzmueller <j.spitzmueller@gmx.de>
|
2003-10-27 Juergen Spitzmueller <j.spitzmueller@gmx.de>
|
||||||
|
|
||||||
* ControlDocument.[Ch]: add method setBranchColor().
|
* ControlDocument.[Ch]: add method setBranchColor().
|
||||||
|
@ -16,11 +16,15 @@
|
|||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
#include "bufferparams.h"
|
#include "bufferparams.h"
|
||||||
#include "BufferView.h"
|
#include "BufferView.h"
|
||||||
|
#include "bufferview_funcs.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "gettext.h"
|
#include "gettext.h"
|
||||||
#include "language.h"
|
#include "language.h"
|
||||||
#include "lyxrc.h"
|
#include "lyxrc.h"
|
||||||
|
|
||||||
|
#include "PosIterator.h"
|
||||||
|
#include "paragraph.h"
|
||||||
|
|
||||||
#include "ispell.h"
|
#include "ispell.h"
|
||||||
#ifdef USE_PSPELL
|
#ifdef USE_PSPELL
|
||||||
# include "pspell.h"
|
# include "pspell.h"
|
||||||
@ -43,7 +47,7 @@ using std::string;
|
|||||||
|
|
||||||
ControlSpellchecker::ControlSpellchecker(LyXView & lv, Dialogs & d)
|
ControlSpellchecker::ControlSpellchecker(LyXView & lv, Dialogs & d)
|
||||||
: ControlDialogBD(lv, d),
|
: ControlDialogBD(lv, d),
|
||||||
newval_(0.0), oldval_(0), newvalue_(0), count_(0)
|
oldval_(0), newvalue_(0), count_(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
@ -67,6 +71,7 @@ void ControlSpellchecker::clearParams()
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
|
||||||
SpellBase * getSpeller(BufferParams const & bp)
|
SpellBase * getSpeller(BufferParams const & bp)
|
||||||
{
|
{
|
||||||
string lang = (lyxrc.isp_use_alt_lang)
|
string lang = (lyxrc.isp_use_alt_lang)
|
||||||
@ -104,7 +109,6 @@ void ControlSpellchecker::startSession()
|
|||||||
speller_.reset(getSpeller(buffer()->params()));
|
speller_.reset(getSpeller(buffer()->params()));
|
||||||
|
|
||||||
// reset values to initial
|
// reset values to initial
|
||||||
newval_ = 0.0;
|
|
||||||
oldval_ = 0;
|
oldval_ = 0;
|
||||||
newvalue_ = 0;
|
newvalue_ = 0;
|
||||||
count_ = 0;
|
count_ = 0;
|
||||||
@ -131,8 +135,6 @@ void ControlSpellchecker::endSession()
|
|||||||
{
|
{
|
||||||
lyxerr[Debug::GUI] << "spell endSession" << endl;
|
lyxerr[Debug::GUI] << "spell endSession" << endl;
|
||||||
|
|
||||||
bufferview()->endOfSpellCheck();
|
|
||||||
|
|
||||||
emergency_exit_ = true;
|
emergency_exit_ = true;
|
||||||
|
|
||||||
if (!speller_.get()) {
|
if (!speller_.get()) {
|
||||||
@ -144,17 +146,61 @@ void ControlSpellchecker::endSession()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
|
||||||
|
bool isLetter(PosIterator & cur)
|
||||||
|
{
|
||||||
|
return !cur.at_end()
|
||||||
|
&& cur.pit()->isLetter(cur.pos())
|
||||||
|
&& !isDeletedText(*cur.pit(), cur.pos());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
WordLangTuple nextWord(PosIterator & cur, PosIterator const & end,
|
||||||
|
int & progress, BufferParams & bp)
|
||||||
|
{
|
||||||
|
// skip until we have real text (will jump paragraphs)
|
||||||
|
for (; cur != end && !isLetter(cur); ++cur, ++progress);
|
||||||
|
|
||||||
|
if (cur == end)
|
||||||
|
return WordLangTuple(string(), string());
|
||||||
|
|
||||||
|
string lang_code = cur.pit()->getFontSettings(bp, cur.pos()).language()->code();
|
||||||
|
string str;
|
||||||
|
// and find the end of the word (insets like optional hyphens
|
||||||
|
// and ligature break are part of a word)
|
||||||
|
for (; cur != end && isLetter(cur); ++cur, ++progress)
|
||||||
|
str += cur.pit()->getChar(cur.pos());
|
||||||
|
|
||||||
|
return WordLangTuple(str, lang_code);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} //namespace anon
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ControlSpellchecker::check()
|
void ControlSpellchecker::check()
|
||||||
{
|
{
|
||||||
lyxerr[Debug::GUI] << "spell check a word" << endl;
|
lyxerr[Debug::GUI] << "spell check a word" << endl;
|
||||||
|
|
||||||
SpellBase::Result res = SpellBase::OK;
|
SpellBase::Result res = SpellBase::OK;
|
||||||
|
|
||||||
// clear any old selection
|
PosIterator cur(*bufferview());
|
||||||
bufferview()->update();
|
PosIterator const beg = buffer()->pos_iterator_begin();
|
||||||
|
PosIterator const end = buffer()->pos_iterator_end();
|
||||||
|
|
||||||
|
int start = distance(beg, cur);
|
||||||
|
int const total = start + distance(cur, end);
|
||||||
|
|
||||||
|
if (cur != buffer()->pos_iterator_begin())
|
||||||
|
for (; cur != end && isLetter(cur); ++cur, ++start);
|
||||||
|
|
||||||
|
|
||||||
while (res == SpellBase::OK || res == SpellBase::IGNORE) {
|
while (res == SpellBase::OK || res == SpellBase::IGNORE) {
|
||||||
word_ = bufferview()->nextWord(newval_);
|
word_ = nextWord(cur, end, start, buffer()->params());
|
||||||
|
|
||||||
// end of document
|
// end of document
|
||||||
if (word_.word().empty())
|
if (word_.word().empty())
|
||||||
@ -163,7 +209,8 @@ void ControlSpellchecker::check()
|
|||||||
++count_;
|
++count_;
|
||||||
|
|
||||||
// Update slider if and only if value has changed
|
// Update slider if and only if value has changed
|
||||||
newvalue_ = int(100.0 * newval_);
|
float progress = total ? float(start)/total : 1;
|
||||||
|
newvalue_ = int(100.0 * progress);
|
||||||
if (newvalue_!= oldval_) {
|
if (newvalue_!= oldval_) {
|
||||||
lyxerr[Debug::GUI] << "Updating spell progress." << endl;
|
lyxerr[Debug::GUI] << "Updating spell progress." << endl;
|
||||||
oldval_ = newvalue_;
|
oldval_ = newvalue_;
|
||||||
@ -183,11 +230,12 @@ void ControlSpellchecker::check()
|
|||||||
}
|
}
|
||||||
|
|
||||||
lyxerr[Debug::GUI] << "Found word \"" << word_.word() << "\"" << endl;
|
lyxerr[Debug::GUI] << "Found word \"" << word_.word() << "\"" << endl;
|
||||||
lyxerr << "Found word \"" << word_.word() << "\"" << endl;
|
|
||||||
|
|
||||||
if (!word_.word().empty()) {
|
if (!word_.word().empty()) {
|
||||||
bufferview()->selectLastWord();
|
int const size = word_.word().size();
|
||||||
bufferview()->fitCursor();
|
advance(cur, -size);
|
||||||
|
bv_funcs::put_selection_at(bufferview(), cur, size, false);
|
||||||
|
advance(cur, size);
|
||||||
} else {
|
} else {
|
||||||
showSummary();
|
showSummary();
|
||||||
endSession();
|
endSession();
|
||||||
|
@ -85,7 +85,6 @@ private:
|
|||||||
WordLangTuple word_;
|
WordLangTuple word_;
|
||||||
|
|
||||||
/// values for progress
|
/// values for progress
|
||||||
float newval_;
|
|
||||||
int oldval_;
|
int oldval_;
|
||||||
int newvalue_;
|
int newvalue_;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user