Example of LS-speller implementation
Posted: Sat Apr 01, 2006 10:00 pm
hi all,
here an example of the implementation of LS-speller for tRichViewEdit.
The dialog of LS-speller is not used, but a normal popup-menu. The popupmenu is (partial) dynamically extended with suggested words, in case of a misspelling. The popupmenu can also contain the "actions" add word to dictionary and ignore word (stored in a local ignorelist). Upon add or ignore the complete document is re-scanned. The popup menu can of course also hold the normal items, like cut / paste etc.
have fun,
Stef Mientki
here an example of the implementation of LS-speller for tRichViewEdit.
The dialog of LS-speller is not used, but a normal popup-menu. The popupmenu is (partial) dynamically extended with suggested words, in case of a misspelling. The popupmenu can also contain the "actions" add word to dictionary and ignore word (stored in a local ignorelist). Upon add or ignore the complete document is re-scanned. The popup menu can of course also hold the normal items, like cut / paste etc.
have fun,
Stef Mientki
Code: Select all
procedure TForm3.RichViewEdit1SpellingCheck(Sender: TCustomRichView;
const AWord: String; StyleNo: Integer; var Misspelled: Boolean);
(*******************************************************************************
*******************************************************************************)
begin
misspelled:=false;
if spellchecker_ignorelist.IndexOf(Aword)>=0 then exit;
misspelled:=not(spellchecker1.IsKnownWord(Aword,Spellchecker1.Language));
end;
procedure TForm3.SpellLanguageComboBox1Change(Sender: TObject);
(*******************************************************************************
*******************************************************************************)
begin
//total
RichViewEdit1.StartLiveSpelling;
end;
procedure TForm3.PopupMenu1Popup(Sender: TObject);
(*******************************************************************************
*******************************************************************************)
var
aword :string;
alist :tstringlist;
i :integer;
newitem :tmenuitem;
style :integer;
misspelled :boolean;
begin
//remove all previous suggestions
with PopupMenu1 do
begin
for i:=items.count-1 downto 0 do
if items[i].Tag>0 then items.Delete(i);
end;
if richviewedit1.GetCurrentMisspelling(true,aword,style) then
begin
alist:=tstringlist.Create;
//we've to call IsKnownWord, otherwise the last error typed word is tested
spellchecker1.IsKnownWord(Aword,Spellchecker1.Language);
spellchecker1.GetVariants(Aword,alist,Spellchecker1.Language);
for i:=0 to alist.count-1 do
begin
NewItem:=TMenuItem.Create(PopupMenu1);
NewItem.Caption:=alist[i];
NewItem.Tag:=i+1;
NewItem.OnClick:=N27.OnClick;
PopupMenu1.Items.Insert(i,NewItem);
end;
alist.Free;
end;
end;
procedure TForm3.N27Click(Sender: TObject);
(*******************************************************************************
*******************************************************************************)
begin
// if it's an item from the list and the selection exists,
// replace the word
if (tmenuitem(sender).Tag>0) and richviewedit1.SelectionExists then
begin
richviewedit1.DeleteSelection;
richviewedit1.InsertText(tmenuitem(sender).Caption,false);
end;
end;
procedure TForm3.AddToDictionary1Click(Sender: TObject);
(*******************************************************************************
*******************************************************************************)
var
aword :string;
style :integer;
begin
if richviewedit1.GetCurrentMisspelling(true,aword,style) then
begin
spellchecker1.AddWord(aword,Spellchecker1.Language);
RichViewEdit1.StartLiveSpelling;
end;
end;
procedure TForm3.IgnoreWord1Click(Sender: TObject);
(*******************************************************************************
*******************************************************************************)
var
aword :string;
style :integer;
begin
if richviewedit1.GetCurrentMisspelling(true,aword,style) then
begin
spellchecker_ignorelist.add(aword);
RichViewEdit1.StartLiveSpelling;
end;
end;