Edwin's spellchecker3 patch

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2261 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2001-07-17 09:00:17 +00:00
parent 5c40a062b2
commit 188ec04f70
10 changed files with 96 additions and 97 deletions

View File

@ -1,3 +1,7 @@
2001-07-17 Edwin Leuven <leuven@fee.uva.nl>
* sp_spell.C: repair language selection for pspell
2001-07-12 Lars Gullik Bjønnes <larsbj@birdstep.com>
* lyxfunc.h: change more methods to begin with lower char.

View File

@ -1,3 +1,11 @@
2001-07-17 Angus Leeming <a.leeming@ic.ac.uk>
* ControlSpellchecker.[Ch]: remove d-tor.
2001-07-17 Edwin Leuven <leuven@fee.uva.nl>
* ControlSpellchecker.[Ch]: remove member quit() and some cleaning
2001-07-16 Juergen Vigna <jug@sad.it>
* ControlSpellchecker.C (show): use the lyxrc.use_pspell flag (if

View File

@ -54,34 +54,16 @@
using SigC::slot;
ControlSpellchecker::ControlSpellchecker(LyXView & lv, Dialogs & d)
: ControlDialog<ControlConnectBD>(lv, d)
: ControlDialog<ControlConnectBD>(lv, d),
rtl_(false), newval_(0.0), oldval_(0), newvalue_(0), count_(0),
stop_(false), result_(SpellBase::ISP_UNKNOWN), speller_(0)
{
d_.showSpellchecker.connect(SigC::slot(this, &ControlSpellchecker::show));
rtl_ = false;
word_ = "";
newval_ = 0.0;
oldval_ = 0;
newvalue_ = 0;
count_ = 0;
message_ = "";
stop_ = false;
result_ = SpellBase::ISP_UNKNOWN;
speller_ = 0;
}
ControlSpellchecker::~ControlSpellchecker()
void ControlSpellchecker::setParams()
{
}
void ControlSpellchecker::show()
{
if (isBufferDependent() && !lv_.view()->available())
return;
if (!speller_) {
// create spell object
string tmp;
@ -111,24 +93,12 @@ void ControlSpellchecker::show()
if (speller_->error() != 0) {
message_ = speller_->error();
// show error message
view().partialUpdate(2);
hide();
clearParams();
return;
}
}
bc().readOnly(isReadonly());
view().show();
}
void ControlSpellchecker::hide()
{
delete speller_;
speller_ = 0;
disconnect();
view().hide();
}
@ -139,8 +109,9 @@ void ControlSpellchecker::check()
while (result_!=SpellBase::ISP_MISSED && !stop_) {
word_ = lv_.view()->nextWord(newval_);
if (word_.empty()) {
quit();
clearParams();
break;
}
@ -154,7 +125,7 @@ void ControlSpellchecker::check()
view().partialUpdate(0);
}
if (!speller_->alive()) quit();
if (!speller_->alive()) clearParams();
result_ = speller_->check(word_);
}
@ -223,31 +194,35 @@ void ControlSpellchecker::ignoreAll()
void ControlSpellchecker::stop()
{
stop_ = true;
lv_.view()->endOfSpellCheck();
}
void ControlSpellchecker::quit()
void ControlSpellchecker::clearParams()
{
if (!speller_) return;
if (speller_->alive()) {
speller_->close();
message_ = tostr(count_);
if (count_ != 1) {
message_ += _(" words checked.");
} else {
message_ += _(" word checked.");
}
message_ = "\n" + message_;
message_ = _("Spellchecking completed! ") + message_;
} else {
speller_->cleanUp();
message_ = _("The spell checker has died for some reason.\n"
"Maybe it has been killed.");
}
lv_.view()->endOfSpellCheck();
delete speller_;
// hide dialog, disconnect and delete speller
hide();
lv_.view()->endOfSpellCheck();
// show closing message
view().partialUpdate(2);
@ -262,6 +237,7 @@ void ControlSpellchecker::quit()
message_ = "";
stop_ = false;
result_ = SpellBase::ISP_UNKNOWN;
speller_ = 0;
}
@ -269,5 +245,3 @@ void ControlSpellchecker::options()
{
lv_.getDialogs()->showSpellcheckerPreferences();
}

View File

@ -29,9 +29,6 @@ public:
///
ControlSpellchecker(LyXView &, Dialogs &);
///
~ControlSpellchecker();
/// replace word with replacement
void replace(string const &);
@ -44,9 +41,6 @@ public:
/// ignore all occurances of word
void ignoreAll();
/// quit spellchecker
void quit();
/// stop checking
void stop();
@ -75,10 +69,9 @@ public:
private:
/// set the params before show or update
void show();
void setParams();
/// clean-up on hide.
void hide();
void clearParams();
/// not needed.
virtual void apply() {}
@ -112,5 +105,3 @@ private:
};
#endif // CONTROLSPELLCHECKER_H

View File

@ -13,6 +13,7 @@
#endif
#include "xformsBC.h"
#include "xforms_helpers.h"
#include "ControlSpellchecker.h"
#include "FormSpellchecker.h"
#include "form_spellchecker.h"
@ -36,6 +37,7 @@ void FormSpellchecker::build()
bc().addReadOnly(dialog_->ignore);
bc().addReadOnly(dialog_->start);
bc().addReadOnly(dialog_->stop);
bc().addReadOnly(dialog_->browser);
}
void FormSpellchecker::update()
@ -45,9 +47,15 @@ void FormSpellchecker::update()
fl_set_object_label(dialog_->text, w.c_str());
fl_clear_browser(dialog_->browser);
fl_set_slider_value(dialog_->slider, 0);
clickline_ = -1 ;
}
void FormSpellchecker::hide()
{
clickline_ = -1;
if (form() && form()->visible)
fl_hide_form(form());
}
ButtonPolicy::SMInput FormSpellchecker::input(FL_OBJECT * obj, long)
{
@ -56,16 +64,16 @@ ButtonPolicy::SMInput FormSpellchecker::input(FL_OBJECT * obj, long)
controller().replace(tmp);
} else if (obj == dialog_->start) {
controller().check();
fl_deactivate_object(dialog_->start);
fl_set_object_lcol(dialog_->start, FL_INACTIVE);
stop(false);
} else if (obj == dialog_->stop) {
controller().stop();
stop(true);
} else if (obj == dialog_->ignore) {
controller().check();
} else if (obj == dialog_->accept) {
controller().ignoreAll();
} else if (obj == dialog_->insert) {
controller().insert();
} else if (obj == dialog_->done) {
controller().quit();
} else if (obj == dialog_->options) {
controller().options();
} else if (obj == dialog_->browser) {
@ -84,22 +92,30 @@ ButtonPolicy::SMInput FormSpellchecker::input(FL_OBJECT * obj, long)
void FormSpellchecker::partialUpdate(int id)
{
// set suggestions
if (id==0) {
// set progress bar (always)
switch (id) {
case 0:
// set progress bar
fl_set_slider_value(dialog_->slider,
controller().getProgress());
} else if (id==1) {
break;
case 1:
{
// set suggestions
string w = controller().getWord();
fl_set_input(dialog_->input, w.c_str());
fl_set_object_label(dialog_->text, w.c_str());
fl_clear_browser(dialog_->browser);
while (!(w = controller().getSuggestion()).empty() ) {
while ( !(w = controller().getSuggestion()).empty() ) {
fl_add_browser_line(dialog_->browser, w.c_str());
}
} else if (id==2) {
fl_show_messages(controller().getMessage().c_str());
}
break;
case 2:
// show exit message
fl_show_messages(controller().getMessage().c_str());
hide();
}
}
@ -108,7 +124,14 @@ void FormSpellchecker::showMessage(const char * msg)
fl_show_message(msg, "", "");
}
// note there is a button accept in session
// it is not clear whether this is ingoreall or replaceall
void FormSpellchecker::stop(bool stop)
{
setEnabled(dialog_->start, stop);
setEnabled(dialog_->replace, !stop);
setEnabled(dialog_->ignore, !stop);
setEnabled(dialog_->accept, !stop);
setEnabled(dialog_->insert, !stop);
setEnabled(dialog_->stop, !stop);
setEnabled(dialog_->browser, !stop);
setEnabled(dialog_->input, !stop);
}

View File

@ -28,19 +28,24 @@ public:
private:
/// not needed.
virtual void apply() {}
void apply() {}
/// Build the dialog
virtual void build();
/// not needed.
virtual void update();
void build();
///
void update();
///
void hide();
/// update progress bar and suggestions
/// enable/disable widgets when start/stop
void stop(bool);
/// update progress bar, set suggestions, exit message
void partialUpdate(int);
/// show an error message
void showMessage(const char * msg);
/// line clicked in browser, necessart for double clicking
/// line clicked in browser, necessary for double clicking
int clickline_;
/// Filter the inputs

View File

@ -34,9 +34,10 @@ FD_form_spellchecker * FormSpellchecker::build_spellchecker()
fdui->input = obj = fl_add_input(FL_NORMAL_INPUT, 80, 40, 220, 30, _("Replace"));
fl_set_object_lsize(obj, FL_NORMAL_SIZE);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
fdui->browser = obj = fl_add_browser(FL_SELECT_BROWSER, 80, 70, 220, 150, _("Near\nMisses"));
fdui->browser = obj = fl_add_browser(FL_SELECT_BROWSER, 80, 70, 220, 150, _("Suggestions"));
fl_set_object_lsize(obj, FL_NORMAL_SIZE);
fl_set_object_lalign(obj, FL_ALIGN_LEFT);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
{
char const * const dummy = N_("Spellchecker Options...|#O");
fdui->options = obj = fl_add_button(FL_NORMAL_BUTTON, 310, 210, 220, 30, idex(_(dummy)));
@ -85,7 +86,7 @@ FD_form_spellchecker * FormSpellchecker::build_spellchecker()
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_lsize(obj, FL_NORMAL_SIZE);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
fl_set_object_callback(obj, C_FormBaseCancelCB, 0);
// xgettext:no-c-format
obj = fl_add_box(FL_NO_BOX, 10, 250, 50, 20, _("0 %"));
fl_set_object_lsize(obj, FL_NORMAL_SIZE);

View File

@ -6,6 +6,7 @@
/** Callbacks, globals and object handlers **/
extern "C" void C_FormBaseInputCB(FL_OBJECT *, long);
extern "C" void C_FormBaseCancelCB(FL_OBJECT *, long);
/**** Forms and Objects ****/

View File

@ -76,13 +76,13 @@ alignment: FL_ALIGN_LEFT
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: Near\nMisses
label: Suggestions
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name: browser
callback:
argument:
callback: C_FormBaseInputCB
argument: 0
--------------------
class: FL_BUTTON
@ -207,7 +207,7 @@ shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name: done
callback: C_FormBaseInputCB
callback: C_FormBaseCancelCB
argument: 0
--------------------

View File

@ -74,19 +74,13 @@ extern void sigchldchecker(pid_t pid, int * status);
PSpell::PSpell()
: els(0), sc(0), spell_error_object(0), flag(ISP_UNKNOWN)
{
els = 0;
sc = 0;
spell_error_object = 0;
flag = ISP_UNKNOWN;
}
PSpell::PSpell(BufferParams const & params, string const & lang)
: els(0), sc(0), spell_error_object(0), flag(ISP_UNKNOWN)
{
els = 0;
sc = 0;
spell_error_object = 0;
flag = ISP_UNKNOWN;
initialize(params, lang);
}
@ -102,9 +96,7 @@ PSpell::~PSpell()
void PSpell::initialize(BufferParams const &, string const & lang)
{
PspellConfig * config = new_pspell_config();
string code;
split(lang, code, '_');
config->replace("language-tag", code.c_str());
config->replace("language-tag", lang.c_str());
spell_error_object = new_pspell_manager(config);
if (pspell_error_number(spell_error_object) != 0) {
error_ = pspell_error_message(spell_error_object);