2001-07-13 11:50:39 +00:00
|
|
|
/**
|
|
|
|
* \file FormSpellchecker.C
|
2002-09-05 15:14:23 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2001-07-13 11:50:39 +00:00
|
|
|
*
|
2002-09-05 14:10:50 +00:00
|
|
|
* \author Edwin Leuven
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS
|
2001-07-13 11:50:39 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2002-09-09 09:49:47 +00:00
|
|
|
#include "Tooltips.h"
|
2001-07-13 11:50:39 +00:00
|
|
|
#include "xformsBC.h"
|
2001-07-17 09:00:17 +00:00
|
|
|
#include "xforms_helpers.h"
|
2001-07-13 11:50:39 +00:00
|
|
|
#include "ControlSpellchecker.h"
|
|
|
|
#include "FormSpellchecker.h"
|
2002-06-13 13:43:51 +00:00
|
|
|
#include "forms/form_spellchecker.h"
|
2002-10-25 09:16:22 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
2002-06-13 13:43:51 +00:00
|
|
|
#include FORMS_H_LOCATION
|
2001-07-13 11:50:39 +00:00
|
|
|
|
2002-06-13 13:43:51 +00:00
|
|
|
typedef FormCB<ControlSpellchecker, FormDB<FD_spellchecker> > base_class;
|
2001-07-13 11:50:39 +00:00
|
|
|
|
2002-10-25 09:16:22 +00:00
|
|
|
|
2002-08-12 14:28:43 +00:00
|
|
|
FormSpellchecker::FormSpellchecker()
|
2002-09-09 09:49:47 +00:00
|
|
|
: base_class(_("Spellchecker"))
|
2002-08-04 23:15:42 +00:00
|
|
|
{}
|
2001-07-13 11:50:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
void FormSpellchecker::build()
|
|
|
|
{
|
2002-06-13 13:43:51 +00:00
|
|
|
dialog_.reset(build_spellchecker(this));
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-07-13 11:50:39 +00:00
|
|
|
// Manage the buttons
|
2002-03-12 14:11:15 +00:00
|
|
|
bc().setCancel(dialog_->button_close);
|
2002-10-25 09:16:22 +00:00
|
|
|
|
|
|
|
// disable for read-only documents
|
2002-03-12 14:11:15 +00:00
|
|
|
bc().addReadOnly(dialog_->button_replace);
|
2002-10-25 09:16:22 +00:00
|
|
|
|
|
|
|
// trigger an input event for cut&paste with middle mouse button.
|
|
|
|
setPrehandler(dialog_->input_replacement);
|
|
|
|
|
|
|
|
fl_set_input_return(dialog_->input_replacement, FL_RETURN_CHANGED);
|
|
|
|
|
|
|
|
// callback for double click in browser
|
|
|
|
fl_set_browser_dblclick_callback(dialog_->browser_suggestions,
|
|
|
|
C_FormBaseInputCB, 2);
|
|
|
|
|
|
|
|
// do not allow setting of slider by the mouse
|
|
|
|
fl_deactivate_object(dialog_->slider_progress);
|
2002-09-09 09:49:47 +00:00
|
|
|
|
|
|
|
// set up the tooltips
|
|
|
|
string str = _("Type replacement for unknown word "
|
|
|
|
" or select from suggestions.");
|
2002-10-25 09:16:22 +00:00
|
|
|
tooltips().init(dialog_->input_replacement, str);
|
2002-09-09 09:49:47 +00:00
|
|
|
str = _("List of replacement suggestions from dictionary.");
|
2002-10-25 09:16:22 +00:00
|
|
|
tooltips().init(dialog_->browser_suggestions, str);
|
2002-09-09 09:49:47 +00:00
|
|
|
str = _("Start the spellingchecker.");
|
|
|
|
tooltips().init(dialog_->button_start, str);
|
|
|
|
str = _("Replace unknown word.");
|
|
|
|
tooltips().init(dialog_->button_replace, str);
|
|
|
|
str = _("Ignore unknown word.");
|
|
|
|
tooltips().init(dialog_->button_ignore, str);
|
|
|
|
str = _("Accept unknown word as known in this session.");
|
|
|
|
tooltips().init(dialog_->button_accept, str);
|
|
|
|
str = _("Add unknown word to personal dictionary.");
|
|
|
|
tooltips().init(dialog_->button_add, str);
|
2002-10-25 09:16:22 +00:00
|
|
|
str = _("Shows word count and progress on spell check.");
|
|
|
|
tooltips().init(dialog_->slider_progress, str);
|
2001-07-13 11:50:39 +00:00
|
|
|
}
|
|
|
|
|
2002-10-25 09:16:22 +00:00
|
|
|
|
2001-07-13 11:50:39 +00:00
|
|
|
void FormSpellchecker::update()
|
|
|
|
{
|
2002-10-25 09:16:22 +00:00
|
|
|
// clear input fields
|
|
|
|
fl_set_input(dialog_->input_replacement, "");
|
|
|
|
fl_set_object_label(dialog_->text_unknown, "");
|
|
|
|
fl_clear_browser(dialog_->browser_suggestions);
|
|
|
|
|
|
|
|
// reset dialog and buttons into start condition
|
|
|
|
input(0, 0);
|
|
|
|
|
|
|
|
// reset slider to zero count
|
|
|
|
fl_set_slider_value(dialog_->slider_progress, 0.0);
|
|
|
|
fl_set_object_label(dialog_->slider_progress, "0 %");
|
2001-07-13 11:50:39 +00:00
|
|
|
}
|
|
|
|
|
2002-10-25 09:16:22 +00:00
|
|
|
|
|
|
|
ButtonPolicy::SMInput FormSpellchecker::input(FL_OBJECT * ob, long ob_value)
|
2001-07-13 11:50:39 +00:00
|
|
|
{
|
2002-10-25 09:16:22 +00:00
|
|
|
if (!ob || ob == dialog_->button_start) {
|
|
|
|
static bool running = false;
|
|
|
|
|
|
|
|
// update running status of spellingchecker
|
|
|
|
running = !running && ob == dialog_->button_start;
|
|
|
|
|
|
|
|
// modify text of Start/Stop button according to running status
|
|
|
|
string const labeltext = running ? _("Stop") : _("Start");
|
|
|
|
fl_set_object_label(dialog_->button_start, labeltext.c_str());
|
|
|
|
fl_set_button_shortcut(dialog_->button_start, "#S", 1);
|
|
|
|
fl_show_object(dialog_->button_start);
|
|
|
|
|
|
|
|
// adjust tooltips to modified Start/Stop button
|
|
|
|
string const str = (running ? _("Stop the spellingchecker.") :
|
|
|
|
_("Start the spellingchecker."));
|
|
|
|
tooltips().init(dialog_->button_start, str);
|
|
|
|
|
|
|
|
// enable buttons according to running status
|
|
|
|
setEnabled(dialog_->button_replace, running);
|
|
|
|
setEnabled(dialog_->button_ignore, running);
|
|
|
|
setEnabled(dialog_->button_accept, running);
|
|
|
|
setEnabled(dialog_->button_add, running);
|
|
|
|
setEnabled(dialog_->browser_suggestions, running);
|
|
|
|
setEnabled(dialog_->input_replacement, running);
|
|
|
|
|
|
|
|
// call controller if Start/Stop button is pressed
|
|
|
|
if (ob) {
|
|
|
|
if (running)
|
|
|
|
controller().check();
|
|
|
|
else
|
|
|
|
controller().stop();
|
|
|
|
}
|
2002-01-15 15:31:19 +00:00
|
|
|
|
2002-10-25 09:16:22 +00:00
|
|
|
} else if (ob == dialog_->button_replace) {
|
|
|
|
string const tmp = getString(dialog_->input_replacement);
|
|
|
|
controller().replace(tmp);
|
2002-01-15 15:31:19 +00:00
|
|
|
|
2002-10-25 09:16:22 +00:00
|
|
|
} else if (ob == dialog_->button_ignore) {
|
2001-07-13 11:50:39 +00:00
|
|
|
controller().check();
|
2002-01-15 15:31:19 +00:00
|
|
|
|
2002-10-25 09:16:22 +00:00
|
|
|
} else if (ob == dialog_->button_accept) {
|
2001-07-13 11:50:39 +00:00
|
|
|
controller().ignoreAll();
|
2002-01-15 15:31:19 +00:00
|
|
|
|
2002-10-25 09:16:22 +00:00
|
|
|
} else if (ob == dialog_->button_add) {
|
2001-07-13 11:50:39 +00:00
|
|
|
controller().insert();
|
2002-01-15 15:31:19 +00:00
|
|
|
|
2002-10-25 09:16:22 +00:00
|
|
|
} else if (ob == dialog_->browser_suggestions) {
|
|
|
|
string const tmp = getString(dialog_->browser_suggestions);
|
2002-01-15 15:31:19 +00:00
|
|
|
if (tmp.empty())
|
2002-01-08 10:05:53 +00:00
|
|
|
return ButtonPolicy::SMI_NOOP;
|
|
|
|
|
2002-10-25 09:16:22 +00:00
|
|
|
if (ob_value != 2) {
|
2002-01-15 15:31:19 +00:00
|
|
|
// single-click
|
|
|
|
// place the chosen string in the input as feedback
|
2002-10-25 09:16:22 +00:00
|
|
|
fl_set_input(dialog_->input_replacement, tmp.c_str());
|
2002-01-15 15:31:19 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
// double-click
|
2001-07-13 11:50:39 +00:00
|
|
|
controller().replace(tmp);
|
2002-01-15 15:31:19 +00:00
|
|
|
// reset the browser so that the following
|
|
|
|
// single-click callback doesn't do anything
|
2002-10-25 09:16:22 +00:00
|
|
|
fl_deselect_browser(dialog_->browser_suggestions);
|
2001-07-13 11:50:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-25 09:16:22 +00:00
|
|
|
// update slider with word count and progress
|
|
|
|
double const wordcount = controller().getCount();
|
2002-10-25 11:07:18 +00:00
|
|
|
int const progress = controller().getProgress();
|
|
|
|
if (wordcount > 0.0 && progress > 0) {
|
2002-10-25 09:16:22 +00:00
|
|
|
double const total = 100.0 * wordcount / progress;
|
|
|
|
|
|
|
|
fl_set_slider_bounds(dialog_->slider_progress, 0.0, total);
|
|
|
|
fl_set_slider_value(dialog_->slider_progress, wordcount);
|
|
|
|
fl_set_object_label(dialog_->slider_progress,
|
|
|
|
(tostr(progress) + " %").c_str());
|
|
|
|
}
|
|
|
|
|
2001-07-13 11:50:39 +00:00
|
|
|
return ButtonPolicy::SMI_VALID;
|
|
|
|
}
|
|
|
|
|
2002-10-25 09:16:22 +00:00
|
|
|
|
2001-07-13 11:50:39 +00:00
|
|
|
void FormSpellchecker::partialUpdate(int id)
|
|
|
|
{
|
2001-07-17 09:00:17 +00:00
|
|
|
switch (id) {
|
2002-10-25 09:16:22 +00:00
|
|
|
case 1: // set suggestions
|
2002-10-25 11:07:18 +00:00
|
|
|
{
|
2001-07-13 11:50:39 +00:00
|
|
|
string w = controller().getWord();
|
2002-10-25 09:16:22 +00:00
|
|
|
fl_set_input(dialog_->input_replacement, w.c_str());
|
|
|
|
fl_set_object_label(dialog_->text_unknown, w.c_str());
|
|
|
|
fl_clear_browser(dialog_->browser_suggestions);
|
2002-02-16 15:59:55 +00:00
|
|
|
while (!(w = controller().getSuggestion()).empty()) {
|
2002-10-25 09:16:22 +00:00
|
|
|
fl_add_browser_line(dialog_->browser_suggestions, w.c_str());
|
2001-07-13 11:50:39 +00:00
|
|
|
}
|
2002-10-25 11:07:18 +00:00
|
|
|
}
|
|
|
|
break;
|
2002-10-25 09:16:22 +00:00
|
|
|
case 2: // end of spell checking
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-10-25 09:16:22 +00:00
|
|
|
// reset dialog and buttons into start condition
|
|
|
|
input(0, 0);
|
2001-07-13 11:50:39 +00:00
|
|
|
|
2002-10-25 09:16:22 +00:00
|
|
|
// set slider 'finished' status
|
|
|
|
fl_set_slider_bounds(dialog_->slider_progress, 0.0, controller().getCount());
|
|
|
|
fl_set_slider_value(dialog_->slider_progress, controller().getCount());
|
|
|
|
fl_set_object_label(dialog_->slider_progress, "100 %");
|
2002-09-09 09:49:47 +00:00
|
|
|
|
2002-10-25 09:16:22 +00:00
|
|
|
break;
|
2002-09-09 09:49:47 +00:00
|
|
|
}
|
2001-07-17 09:00:17 +00:00
|
|
|
}
|