Remove LYX_LAYOUT_DEFAULT - it is very very old, even klyx doesn't use it.

Commit the multi-language spellcheck patch.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4882 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
John Levon 2002-08-06 22:38:44 +00:00
parent c9f673d506
commit 6b5c9696b6
28 changed files with 275 additions and 143 deletions

View File

@ -19,6 +19,7 @@
#include "commandtags.h" #include "commandtags.h"
#include "insets/inset.h" #include "insets/inset.h"
#include "WordLangTuple.h"
#include <boost/utility.hpp> #include <boost/utility.hpp>
@ -124,8 +125,8 @@ public:
void endOfSpellCheck(); void endOfSpellCheck();
/// ///
void selectLastWord(); void selectLastWord();
/// /// return the next word
string const nextWord(float & value); WordLangTuple const nextWord(float & value);
/// ///
bool gotoLabel(string const & label); bool gotoLabel(string const & label);
/// ///

View File

@ -443,11 +443,11 @@ void BufferView::paste()
/* these functions are for the spellchecker */ /* these functions are for the spellchecker */
string const BufferView::nextWord(float & value) WordLangTuple const BufferView::nextWord(float & value)
{ {
if (!available()) { if (!available()) {
value = 1; value = 1;
return string(); return WordLangTuple();
} }
return text->selectNextWordToSpellcheck(this, value); return text->selectNextWordToSpellcheck(this, value);

View File

@ -1,3 +1,21 @@
2002-08-06 John Levon <levon@movementarian.org>
* WordLangTuple.h: new file for word + language code tuple
* SpellBase.h:
* pspell.h:
* pspell.C:
* ispell.h:
* ispell.C:
* lyxtext.h:
* text.C:
* text2.C:
* BufferView.h:
* BufferView2.C: use WordLangTuple
* layout.h:
* buffer.C: remove very dead LYX_LAYOUT_DEFAULT
2002-08-06 John Levon <levon@movementarian.org> 2002-08-06 John Levon <levon@movementarian.org>
* lyx_main.C: fix cmdline batch handling * lyx_main.C: fix cmdline batch handling

View File

@ -12,6 +12,8 @@
#include "LString.h" // can't forward declare... #include "LString.h" // can't forward declare...
#include "WordLangTuple.h"
class BufferParams; class BufferParams;
/** /**
@ -38,17 +40,17 @@ public:
/// clean up on messy exit /// clean up on messy exit
virtual void cleanUp() = 0; virtual void cleanUp() = 0;
/// check the given word and return the result /// check the given word of the given lang code and return the result
virtual enum Result check(string const &) = 0; virtual enum Result check(WordLangTuple const &) = 0;
/// finish this spellchecker instance /// finish this spellchecker instance
virtual void close() = 0; virtual void close() = 0;
/// insert the given word into the personal dictionary /// insert the given word into the personal dictionary
virtual void insert(string const &) = 0; virtual void insert(WordLangTuple const &) = 0;
/// accept the given word temporarily /// accept the given word temporarily
virtual void accept(string const &) = 0; virtual void accept(WordLangTuple const &) = 0;
/// return the next near miss after a MISSED result /// return the next near miss after a MISSED result
virtual string const nextMiss() = 0; virtual string const nextMiss() = 0;

43
src/WordLangTuple.h Normal file
View File

@ -0,0 +1,43 @@
/**
* \file WordLangTuple.h
* Copyright 2002 the LyX Team
* Read the file COPYING
*
* \author John Levon <levon@movementarian.org>
*/
#ifndef WORD_LANG_TUPLE_H
#define WORD_LANG_TUPLE_H
#include <config.h>
#include "LString.h"
/**
* A word and its given language code ("en_US").
* This is used for spellchecking.
*/
class WordLangTuple {
public:
WordLangTuple() {};
WordLangTuple(string const & w, string const & c)
: word_(w), code_(c) {}
/// return the word
string const word() const {
return word_;
}
/// return its language code
string const lang_code() const {
return code_;
}
private:
/// the word
string word_;
/// language code of word
string code_;
};
#endif // WORD_LANG_TUPLE_H

View File

@ -948,9 +948,8 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
int tmpret = lex.findToken(string_paragraph_separation); int tmpret = lex.findToken(string_paragraph_separation);
if (tmpret == -1) if (tmpret == -1)
++tmpret; ++tmpret;
if (tmpret != LYX_LAYOUT_DEFAULT) params.paragraph_separation =
params.paragraph_separation = static_cast<BufferParams::PARSEP>(tmpret);
static_cast<BufferParams::PARSEP>(tmpret);
} else if (token == "\\defskip") { } else if (token == "\\defskip") {
lex.nextToken(); lex.nextToken();
params.defskip = VSpace(lex.getString()); params.defskip = VSpace(lex.getString());
@ -965,31 +964,29 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
int tmpret = lex.findToken(string_quotes_language); int tmpret = lex.findToken(string_quotes_language);
if (tmpret == -1) if (tmpret == -1)
++tmpret; ++tmpret;
if (tmpret != LYX_LAYOUT_DEFAULT) { InsetQuotes::quote_language tmpl =
InsetQuotes::quote_language tmpl = InsetQuotes::EnglishQ;
InsetQuotes::EnglishQ; switch (tmpret) {
switch (tmpret) { case 0:
case 0: tmpl = InsetQuotes::EnglishQ;
tmpl = InsetQuotes::EnglishQ; break;
break; case 1:
case 1: tmpl = InsetQuotes::SwedishQ;
tmpl = InsetQuotes::SwedishQ; break;
break; case 2:
case 2: tmpl = InsetQuotes::GermanQ;
tmpl = InsetQuotes::GermanQ; break;
break; case 3:
case 3: tmpl = InsetQuotes::PolishQ;
tmpl = InsetQuotes::PolishQ; break;
break; case 4:
case 4: tmpl = InsetQuotes::FrenchQ;
tmpl = InsetQuotes::FrenchQ; break;
break; case 5:
case 5: tmpl = InsetQuotes::DanishQ;
tmpl = InsetQuotes::DanishQ; break;
break;
}
params.quotes_language = tmpl;
} }
params.quotes_language = tmpl;
} else if (token == "\\quotes_times") { } else if (token == "\\quotes_times") {
lex.nextToken(); lex.nextToken();
switch (lex.getInteger()) { switch (lex.getInteger()) {
@ -1029,8 +1026,8 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
int tmpret = lex.findToken(string_orientation); int tmpret = lex.findToken(string_orientation);
if (tmpret == -1) if (tmpret == -1)
++tmpret; ++tmpret;
if (tmpret != LYX_LAYOUT_DEFAULT) params.orientation =
params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret); static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
} else if (token == "\\paperwidth") { } else if (token == "\\paperwidth") {
lex.next(); lex.next();
params.paperwidth = lex.getString(); params.paperwidth = lex.getString();
@ -1173,11 +1170,8 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
} else if (token == "\\align") { } else if (token == "\\align") {
int tmpret = lex.findToken(string_align); int tmpret = lex.findToken(string_align);
if (tmpret == -1) ++tmpret; if (tmpret == -1) ++tmpret;
if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ??? int const tmpret2 = int(pow(2.0, tmpret));
int const tmpret2 = int(pow(2.0, tmpret)); par->params().align(LyXAlignment(tmpret2));
//lyxerr << "Tmpret2 = " << tmpret2 << endl;
par->params().align(LyXAlignment(tmpret2));
}
} else if (token == "\\added_space_top") { } else if (token == "\\added_space_top") {
lex.nextToken(); lex.nextToken();
VSpace value = VSpace(lex.getString()); VSpace value = VSpace(lex.getString());

View File

@ -1,3 +1,8 @@
2002-08-06 John Levon <levon@movementarian.org>
* ControlSpellchecker.C:
* ControlSpellchecker.h: use WordLangTuple
2002-08-06 John Levon <levon@movementarian.org> 2002-08-06 John Levon <levon@movementarian.org>
* ControlSpellchecker.C: show an alert with the * ControlSpellchecker.C: show an alert with the

View File

@ -91,7 +91,7 @@ void ControlSpellchecker::check()
while ((res == SpellBase::OK || res == SpellBase::IGNORE) && !stop_) { while ((res == SpellBase::OK || res == SpellBase::IGNORE) && !stop_) {
word_ = lv_.view()->nextWord(newval_); word_ = lv_.view()->nextWord(newval_);
if (word_.empty()) { if (word_.word().empty()) {
clearParams(); clearParams();
break; break;
} }
@ -99,19 +99,23 @@ 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_); newvalue_ = int(100.0 * newval_);
if (newvalue_!= oldval_) { if (newvalue_!= oldval_) {
oldval_ = newvalue_; oldval_ = newvalue_;
// set progress bar // set progress bar
view().partialUpdate(0); view().partialUpdate(0);
} }
if (!speller_->alive()) clearParams(); if (!speller_->alive()) {
clearParams();
stop();
return;
}
res = speller_->check(word_); res = speller_->check(word_);
} }
if (!stop_ && !word_.empty()) if (!stop_ && !word_.word().empty())
lv_.view()->selectLastWord(); lv_.view()->selectLastWord();
// set suggestions // set suggestions
@ -124,6 +128,8 @@ void ControlSpellchecker::check()
void ControlSpellchecker::replace(string const & replacement) void ControlSpellchecker::replace(string const & replacement)
{ {
lv_.view()->replaceWord(replacement); lv_.view()->replaceWord(replacement);
// fix up the count
--count_;
check(); check();
} }
@ -155,7 +161,7 @@ string ControlSpellchecker::getSuggestion()
string ControlSpellchecker::getWord() string ControlSpellchecker::getWord()
{ {
string tmp = word_; string tmp = word_.word();
if (rtl_) if (rtl_)
std::reverse(tmp.begin(), tmp.end()); std::reverse(tmp.begin(), tmp.end());
return tmp; return tmp;
@ -214,7 +220,6 @@ void ControlSpellchecker::clearParams()
// reset values to initial // reset values to initial
rtl_ = false; rtl_ = false;
word_.erase();
newval_ = 0.0; newval_ = 0.0;
oldval_ = 0; oldval_ = 0;
newvalue_ = 0; newvalue_ = 0;

View File

@ -21,6 +21,7 @@
#include "ControlDialog_impl.h" #include "ControlDialog_impl.h"
#include "LString.h" #include "LString.h"
#include "WordLangTuple.h"
class SpellBase; class SpellBase;
@ -78,8 +79,8 @@ private:
/// right to left /// right to left
bool rtl_; bool rtl_;
/// current word being checked /// current word being checked and lang code
string word_; WordLangTuple word_;
/// values for progress /// values for progress
float newval_; float newval_;

View File

@ -1,3 +1,16 @@
2002-08-06 John Levon <levon@movementarian.org>
* inset.h:
* inset.C:
* insetcollapsable.h:
* insetcollapsable.C:
* insetert.h:
* insetert.C:
* insettabular.h:
* insettabular.C:
* insettext.h:
* insettext.C: use WordLangTuple for spellcheck
2002-08-06 Angus Leeming <leeming@lyx.org> 2002-08-06 Angus Leeming <leeming@lyx.org>
* insetinclude.C: add a monitor to the previewed image, so that the * insetinclude.C: add a monitor to the previewed image, so that the

View File

@ -359,13 +359,13 @@ LyXCursor const & Inset::cursor(BufferView * bv) const
} }
string const UpdatableInset::selectNextWordToSpellcheck(BufferView *bv, WordLangTuple UpdatableInset::selectNextWordToSpellcheck(BufferView *bv,
float & value) const float & value) const
{ {
// we have to unlock ourself in this function by default! // we have to unlock ourself in this function by default!
bv->unlockInset(const_cast<UpdatableInset *>(this)); bv->unlockInset(const_cast<UpdatableInset *>(this));
value = 0; value = 0;
return string(); return WordLangTuple();
} }

View File

@ -19,6 +19,7 @@
#include "LString.h" #include "LString.h"
#include "commandtags.h" #include "commandtags.h"
#include "frontends/mouse_state.h" #include "frontends/mouse_state.h"
#include "WordLangTuple.h"
#include "LColor.h" #include "LColor.h"
class LyXFont; class LyXFont;
@ -536,7 +537,7 @@ public:
/// ///
virtual bool allowSpellcheck() { return false; } virtual bool allowSpellcheck() { return false; }
/// ///
virtual string const selectNextWordToSpellcheck(BufferView *, float & value) const; virtual WordLangTuple selectNextWordToSpellcheck(BufferView *, float & value) const;
/// ///
virtual void selectSelectedWord(BufferView *) { return; } virtual void selectSelectedWord(BufferView *) { return; }
/// ///

View File

@ -667,14 +667,14 @@ bool InsetCollapsable::searchBackward(BufferView * bv, string const & str,
} }
string const InsetCollapsable::selectNextWordToSpellcheck(BufferView * bv, WordLangTuple InsetCollapsable::selectNextWordToSpellcheck(BufferView * bv,
float & value) const float & value) const
{ {
string const str = inset.selectNextWordToSpellcheck(bv, value); WordLangTuple word = inset.selectNextWordToSpellcheck(bv, value);
if (first_after_edit && str.empty()) if (first_after_edit && word.word().empty())
close(bv); close(bv);
first_after_edit = false; first_after_edit = false;
return str; return word;
} }

View File

@ -176,7 +176,8 @@ public:
void close(BufferView *) const; void close(BufferView *) const;
/// ///
bool allowSpellcheck() { return inset.allowSpellcheck(); } bool allowSpellcheck() { return inset.allowSpellcheck(); }
string const selectNextWordToSpellcheck(BufferView *, float &) const;
WordLangTuple selectNextWordToSpellcheck(BufferView *, float &) const;
void selectSelectedWord(BufferView * bv) { void selectSelectedWord(BufferView * bv) {
inset.selectSelectedWord(bv); inset.selectSelectedWord(bv);

View File

@ -674,11 +674,11 @@ void InsetERT::close(BufferView * bv) const
} }
string const InsetERT::selectNextWordToSpellcheck(BufferView * bv, WordLangTuple InsetERT::selectNextWordToSpellcheck(BufferView * bv,
float &) const float &) const
{ {
bv->unlockInset(const_cast<InsetERT *>(this)); bv->unlockInset(const_cast<InsetERT *>(this));
return string(); return WordLangTuple();
} }

View File

@ -114,7 +114,8 @@ public:
void close(BufferView *) const; void close(BufferView *) const;
/// ///
bool allowSpellcheck() { return false; } bool allowSpellcheck() { return false; }
string const selectNextWordToSpellcheck(BufferView *, float &) const;
WordLangTuple selectNextWordToSpellcheck(BufferView *, float &) const;
/// ///
int ascent(BufferView *, LyXFont const &) const; int ascent(BufferView *, LyXFont const &) const;
/// ///

View File

@ -2675,20 +2675,20 @@ Inset * InsetTabular::getInsetFromID(int id_arg) const
} }
string const WordLangTuple
InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
{ {
nodraw(true); nodraw(true);
if (the_locking_inset) { if (the_locking_inset) {
string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value)); WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
if (!str.empty()) { if (!word.word().empty()) {
nodraw(false); nodraw(false);
return str; return word;
} }
if (tabular->IsLastCell(actcell)) { if (tabular->IsLastCell(actcell)) {
bv->unlockInset(const_cast<InsetTabular *>(this)); bv->unlockInset(const_cast<InsetTabular *>(this));
nodraw(false); nodraw(false);
return string(); return WordLangTuple();
} }
++actcell; ++actcell;
} }
@ -2696,26 +2696,26 @@ InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
UpdatableInset * inset = UpdatableInset * inset =
static_cast<UpdatableInset*>(tabular->GetCellInset(actcell)); static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
inset->edit(bv, 0, 0, mouse_button::none); inset->edit(bv, 0, 0, mouse_button::none);
string const str(selectNextWordInt(bv, value)); WordLangTuple word(selectNextWordInt(bv, value));
nodraw(false); nodraw(false);
if (!str.empty()) if (!word.word().empty())
resetPos(bv); resetPos(bv);
return str; return word;
} }
string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const WordLangTuple InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
{ {
// when entering this function the inset should be ALWAYS locked! // when entering this function the inset should be ALWAYS locked!
lyx::Assert(the_locking_inset); lyx::Assert(the_locking_inset);
string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value)); WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
if (!str.empty()) if (!word.word().empty())
return str; return word;
if (tabular->IsLastCell(actcell)) { if (tabular->IsLastCell(actcell)) {
bv->unlockInset(const_cast<InsetTabular *>(this)); bv->unlockInset(const_cast<InsetTabular *>(this));
return string(); return WordLangTuple();
} }
// otherwise we have to lock the next inset and ask for it's selecttion // otherwise we have to lock the next inset and ask for it's selecttion

View File

@ -216,7 +216,7 @@ public:
LyXCursor const & cursor(BufferView *) const; LyXCursor const & cursor(BufferView *) const;
/// ///
bool allowSpellcheck() { return true; } bool allowSpellcheck() { return true; }
string const selectNextWordToSpellcheck(BufferView *, float & value) const; WordLangTuple selectNextWordToSpellcheck(BufferView *, float & value) const;
void selectSelectedWord(BufferView *); void selectSelectedWord(BufferView *);
void toggleSelection(BufferView *, bool kill_selection); void toggleSelection(BufferView *, bool kill_selection);
/// ///
@ -316,7 +316,7 @@ private:
void getSelection(int & scol, int & ecol, void getSelection(int & scol, int & ecol,
int & srow, int & erow) const; int & srow, int & erow) const;
/// ///
string selectNextWordInt(BufferView *, float & value) const; WordLangTuple selectNextWordInt(BufferView *, float & value) const;
/// ///
bool insertAsciiString(BufferView *, string const & buf, bool usePaste); bool insertAsciiString(BufferView *, string const & buf, bool usePaste);

View File

@ -2581,34 +2581,34 @@ Inset * InsetText::getInsetFromID(int id_arg) const
} }
string const InsetText::selectNextWordToSpellcheck(BufferView * bv, float & value) const WordLangTuple InsetText::selectNextWordToSpellcheck(BufferView * bv, float & value) const
{ {
bool clear = false; bool clear = false;
string str; WordLangTuple word;
if (!lt) { if (!lt) {
lt = getLyXText(bv); lt = getLyXText(bv);
clear = true; clear = true;
} }
if (the_locking_inset) { if (the_locking_inset) {
str = the_locking_inset->selectNextWordToSpellcheck(bv, value); word = the_locking_inset->selectNextWordToSpellcheck(bv, value);
if (!str.empty()) { if (!word.word().empty()) {
value += cy(bv); value += cy(bv);
if (clear) if (clear)
lt = 0; lt = 0;
return str; return word;
} }
// we have to go on checking so move cusor to the next char // we have to go on checking so move cursor to the next char
lt->cursor.pos(lt->cursor.pos() + 1); lt->cursor.pos(lt->cursor.pos() + 1);
} }
str = lt->selectNextWordToSpellcheck(bv, value); word = lt->selectNextWordToSpellcheck(bv, value);
if (str.empty()) if (word.word().empty())
bv->unlockInset(const_cast<InsetText *>(this)); bv->unlockInset(const_cast<InsetText *>(this));
else else
value = cy(bv); value = cy(bv);
if (clear) if (clear)
lt = 0; lt = 0;
return str; return word;
} }

View File

@ -230,7 +230,7 @@ public:
/// ///
bool allowSpellcheck() { return true; } bool allowSpellcheck() { return true; }
/// ///
string const selectNextWordToSpellcheck(BufferView *, WordLangTuple selectNextWordToSpellcheck(BufferView *,
float & value) const; float & value) const;
void selectSelectedWord(BufferView *); void selectSelectedWord(BufferView *);
/// ///

View File

@ -303,13 +303,13 @@ void ISpell::cleanUp()
} }
enum ISpell::Result ISpell::check(string const & word) enum ISpell::Result ISpell::check(WordLangTuple const & word)
{ {
// FIXME Please rewrite to use string. // FIXME Please rewrite to use string.
Result res; Result res;
::fputs(word.c_str(), out); ::fputs(word.word().c_str(), out);
::fputc('\n', out); ::fputc('\n', out);
char buf[1024]; char buf[1024];
@ -374,18 +374,18 @@ void ISpell::close()
} }
void ISpell::insert(string const & word) void ISpell::insert(WordLangTuple const & word)
{ {
::fputc('*', out); // Insert word in personal dictionary ::fputc('*', out); // Insert word in personal dictionary
::fputs(word.c_str(), out); ::fputs(word.word().c_str(), out);
::fputc('\n', out); ::fputc('\n', out);
} }
void ISpell::accept(string const & word) void ISpell::accept(WordLangTuple const & word)
{ {
::fputc('@', out); // Accept in this session ::fputc('@', out); // Accept in this session
::fputs(word.c_str(), out); ::fputs(word.word().c_str(), out);
::fputc('\n', out); ::fputc('\n', out);
} }

View File

@ -30,16 +30,16 @@ public:
virtual void cleanUp(); virtual void cleanUp();
/// check the given word and return the result /// check the given word and return the result
virtual enum Result check(string const & word); virtual enum Result check(WordLangTuple const & word);
/// finish this spellchecker instance /// finish this spellchecker instance
virtual void close(); virtual void close();
/// insert the given word into the personal dictionary /// insert the given word into the personal dictionary
virtual void insert(string const & word); virtual void insert(WordLangTuple const & word);
/// accept the given word temporarily /// accept the given word temporarily
virtual void accept(string const & word); virtual void accept(WordLangTuple const & word);
/// return the next near miss after a MISSED result /// return the next near miss after a MISSED result
virtual string const nextMiss(); virtual string const nextMiss();

View File

@ -12,12 +12,6 @@
#ifndef LAYOUT_H #ifndef LAYOUT_H
#define LAYOUT_H #define LAYOUT_H
enum layout_default {
///
LYX_LAYOUT_DEFAULT = 99
};
/// The different output types /// The different output types
enum OutputType { enum OutputType {
/// ///

View File

@ -21,6 +21,7 @@
#include "layout.h" #include "layout.h"
#include "LColor.h" #include "LColor.h"
#include "insets/inset.h" #include "insets/inset.h"
#include "WordLangTuple.h"
class Buffer; class Buffer;
class BufferParams; class BufferParams;
@ -302,7 +303,7 @@ public:
to the beginning of this word. to the beginning of this word.
With SelectSelectedWord can this be highlighted really With SelectSelectedWord can this be highlighted really
*/ */
string const selectNextWordToSpellcheck(BufferView *, float & value) const; WordLangTuple selectNextWordToSpellcheck(BufferView *, float & value) const;
/// ///
void selectSelectedWord(BufferView *); void selectSelectedWord(BufferView *);
/// returns true if par was empty and was removed /// returns true if par was empty and was removed

View File

@ -28,16 +28,9 @@ extern "C" {
using std::endl; using std::endl;
PSpell::PSpell(BufferParams const &, string const & lang) PSpell::PSpell(BufferParams const &, string const & lang)
: sc(0), els(0), spell_error_object(0), alive_(false) : els(0), spell_error_object(0)
{ {
PspellConfig * config = new_pspell_config(); addManager(lang);
pspell_config_replace(config, "language-tag", lang.c_str());
spell_error_object = new_pspell_manager(config);
if (pspell_error_number(spell_error_object) == 0) {
sc = to_pspell_manager(spell_error_object);
spell_error_object = 0;
alive_ = true;
}
} }
@ -47,6 +40,13 @@ PSpell::~PSpell()
close(); close();
if (els) if (els)
delete_pspell_string_emulation(els); delete_pspell_string_emulation(els);
Managers::iterator it = managers_.begin();
Managers::iterator end = managers_.end();
for (; it != end; ++it) {
delete_pspell_manager(it->second.manager);
delete_pspell_config(it->second.config);
}
} }
@ -59,21 +59,49 @@ void PSpell::cleanUp()
} }
enum PSpell::Result PSpell::check(string const & word) void PSpell::addManager(string const & lang)
{
PspellConfig * config = new_pspell_config();
pspell_config_replace(config, "language-tag", lang.c_str());
PspellCanHaveError * err = new_pspell_manager(config);
if (spell_error_object)
delete_pspell_can_have_error(spell_error_object);
spell_error_object = 0;
if (pspell_error_number(err) == 0) {
Manager m;
m.manager = to_pspell_manager(err);
m.config = config;
managers_[lang] = m;
} else {
spell_error_object = err;
}
}
enum PSpell::Result PSpell::check(WordLangTuple const & word)
{ {
Result res = UNKNOWN; Result res = UNKNOWN;
if (!sc) Managers::iterator it = managers_.find(word.lang_code());
return res; if (it == managers_.end()) {
addManager(word.lang_code());
it = managers_.find(word.lang_code());
// FIXME
if (it == managers_.end())
return res;
}
int word_ok = pspell_manager_check(sc, word.c_str()); PspellManager * m = it->second.manager;
int word_ok = pspell_manager_check(m, word.word().c_str());
lyx::Assert(word_ok != -1); lyx::Assert(word_ok != -1);
if (word_ok) { if (word_ok) {
res = OK; res = OK;
} else { } else {
PspellWordList const * sugs = PspellWordList const * sugs =
pspell_manager_suggest(sc, word.c_str()); pspell_manager_suggest(m, word.word().c_str());
lyx::Assert(sugs != 0); lyx::Assert(sugs != 0);
els = pspell_word_list_elements(sugs); els = pspell_word_list_elements(sugs);
if (pspell_word_list_empty(sugs)) if (pspell_word_list_empty(sugs))
@ -87,22 +115,28 @@ enum PSpell::Result PSpell::check(string const & word)
void PSpell::close() void PSpell::close()
{ {
if (sc) Managers::iterator it = managers_.begin();
pspell_manager_save_all_word_lists(sc); Managers::iterator end = managers_.end();
for (; it != end; ++it) {
pspell_manager_save_all_word_lists(it->second.manager);
}
} }
void PSpell::insert(string const & word) void PSpell::insert(WordLangTuple const & word)
{ {
if (sc) Managers::iterator it = managers_.find(word.lang_code());
pspell_manager_add_to_personal(sc, word.c_str()); if (it != managers_.end())
pspell_manager_add_to_personal(it->second.manager, word.word().c_str());
} }
void PSpell::accept(string const & word) void PSpell::accept(WordLangTuple const & word)
{ {
if (sc) Managers::iterator it = managers_.find(word.lang_code());
pspell_manager_add_to_session(sc, word.c_str()); if (it != managers_.end())
pspell_manager_add_to_session(it->second.manager, word.word().c_str());
} }

View File

@ -10,11 +10,14 @@
#ifndef LYX_PSPELL_H #ifndef LYX_PSPELL_H
#define LYX_PSPELL_H #define LYX_PSPELL_H
#include <map>
#include "SpellBase.h" #include "SpellBase.h"
class PspellManager; class PspellManager;
class PspellStringEmulation; class PspellStringEmulation;
class PspellCanHaveError; class PspellCanHaveError;
class PspellConfig;
class BufferParams; class BufferParams;
@ -28,23 +31,26 @@ public:
virtual ~PSpell(); virtual ~PSpell();
/// return true if the spellchecker instance still exists /**
virtual bool alive() { return alive_; } * return true if the spellchecker instance still exists
* Always true for pspell, since there is no separate process
*/
virtual bool alive() { return true; }
/// clean up on messy exit /// clean up on messy exit
virtual void cleanUp(); virtual void cleanUp();
/// check the given word and return the result /// check the given word and return the result
virtual enum Result check(string const & word); virtual enum Result check(WordLangTuple const &);
/// finish this spellchecker instance /// finish this spellchecker instance
virtual void close(); virtual void close();
/// insert the given word into the personal dictionary /// insert the given word into the personal dictionary
virtual void insert(string const & word); virtual void insert(WordLangTuple const &);
/// accept the given word temporarily /// accept the given word temporarily
virtual void accept(string const & word); virtual void accept(WordLangTuple const &);
/// return the next near miss after a MISSED result /// return the next near miss after a MISSED result
virtual string const nextMiss(); virtual string const nextMiss();
@ -53,14 +59,23 @@ public:
virtual string const error(); virtual string const error();
private: private:
/// main manager /// add a manager of the given language
PspellManager * sc; void addManager(string const & lang);
struct Manager {
PspellManager * manager;
PspellConfig * config;
};
typedef std::map<string, struct Manager> Managers;
/// the managers
Managers managers_;
/// FIXME /// FIXME
PspellStringEmulation * els; PspellStringEmulation * els;
/// FIXME /// FIXME
PspellCanHaveError * spell_error_object; PspellCanHaveError * spell_error_object;
/// initialised properly ?
bool alive_;
}; };
#endif // PSPELL_H #endif // PSPELL_H

View File

@ -2393,19 +2393,19 @@ bool LyXText::selectWordWhenUnderCursor(BufferView * bview,
// This function is only used by the spellchecker for NextWord(). // This function is only used by the spellchecker for NextWord().
// It doesn't handle LYX_ACCENTs and probably never will. // It doesn't handle LYX_ACCENTs and probably never will.
string const LyXText::selectNextWordToSpellcheck(BufferView * bview, WordLangTuple LyXText::selectNextWordToSpellcheck(BufferView * bview,
float & value) const float & value) const
{ {
if (the_locking_inset) { if (the_locking_inset) {
string str = the_locking_inset->selectNextWordToSpellcheck(bview, value); WordLangTuple word = the_locking_inset->selectNextWordToSpellcheck(bview, value);
if (!str.empty()) { if (!word.word().empty()) {
value += float(cursor.y())/float(height); value += float(cursor.y())/float(height);
return str; return word;
} }
// we have to go on checking so move cusor to the next char // we have to go on checking so move cursor to the next char
if (cursor.pos() == cursor.par()->size()) { if (cursor.pos() == cursor.par()->size()) {
if (!cursor.par()->next()) if (!cursor.par()->next())
return str; return word;
cursor.par(cursor.par()->next()); cursor.par(cursor.par()->next());
cursor.pos(0); cursor.pos(0);
} else } else
@ -2457,6 +2457,9 @@ string const LyXText::selectNextWordToSpellcheck(BufferView * bview,
// Start the selection from here // Start the selection from here
selection.cursor = cursor; selection.cursor = cursor;
string lang_code(
getFont(bview->buffer(), cursor.par(), cursor.pos())
.language()->code());
// and find the end of the word (insets like optional hyphens // and find the end of the word (insets like optional hyphens
// and ligature break are part of a word) // and ligature break are part of a word)
while (cursor.pos() < cursor.par()->size() while (cursor.pos() < cursor.par()->size()
@ -2472,7 +2475,7 @@ string const LyXText::selectNextWordToSpellcheck(BufferView * bview,
str += cursor.par()->getChar(i); str += cursor.par()->getChar(i);
} }
} }
return str; return WordLangTuple(str, lang_code);
} }

View File

@ -1092,8 +1092,8 @@ string LyXText::getStringToIndex(BufferView * bview)
// Try implicit word selection // Try implicit word selection
// If there is a change in the language the implicit word selection // If there is a change in the language the implicit word selection
// is disabled. // is disabled.
LyXCursor resetCursor = cursor; LyXCursor const reset_cursor = cursor;
bool implicitSelection = selectWordWhenUnderCursor(bview, PREVIOUS_WORD); bool const implicitSelection = selectWordWhenUnderCursor(bview, PREVIOUS_WORD);
if (!selection.set()) { if (!selection.set()) {
bview->owner()->message(_("Nothing to index!")); bview->owner()->message(_("Nothing to index!"));
@ -1110,7 +1110,7 @@ string LyXText::getStringToIndex(BufferView * bview)
//and cursor is set to the original position. //and cursor is set to the original position.
if (implicitSelection) { if (implicitSelection) {
clearSelection(); clearSelection();
cursor = resetCursor; cursor = reset_cursor;
setCursor(bview, cursor.par(), cursor.pos()); setCursor(bview, cursor.par(), cursor.pos());
selection.cursor = cursor; selection.cursor = cursor;
} }