Ignore:
Timestamp:
May 19, 2015, 2:49:23 PM (9 years ago)
Author:
healthsevak
Message:

Added few options to SpellChecker which persists beyond current session

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cprs/branches/HealthSevak-CPRS/CPRS-Lib/Hans SpellCheck/skaSpellCheck.pas

    r1715 r1718  
    8181    FOnAbort  : TNotifyEvent;
    8282    FOnStateChange  : TStateChangeEvent;
     83    FIgnoreWordWdigits: boolean;
     84    FIgnoreCaps: boolean;
    8385
    8486    function AddCustomWord(aWord: String; isInternal: Boolean = False): Boolean;
     
    8688    Function CurrentWordDetail(WithPosition: Boolean= True): String;
    8789    function GetActive: Boolean;
     90    procedure GetOptions;
    8891    function GetStatus: TSpellState;
    8992    procedure Initialize;
     
    9396    procedure SetDictFileName(const Value: string);
    9497    procedure SetHighLightEdit(const Value: TEdit);
     98    procedure SetOptions;
    9599    procedure SetSourceEdit(const Value: TRichEdit);
    96100    Function ShowMisSpelledWord:boolean;
     
    100104    procedure SaveForUndo(const Ignoring: Boolean=False);
    101105    procedure InformStatusChange;
     106    procedure SetIgnoreCaps(const Value: boolean);
     107    procedure SetIgnoreWordWdigits(const Value: boolean);
    102108  public
    103109    constructor Create(AOwner: TComponent); overload; override;
     
    129135    property Active: Boolean read GetActive write SetActive;
    130136    property AffixFileName: string read FAffixFileName write SetAffixFileName;
     137    property IgnoreAllCaps: boolean read FIgnoreCaps write SetIgnoreCaps default true;
     138    property IgnoreWordWithDigits:boolean read FIgnoreWordWdigits write SetIgnoreWordWdigits default true;
    131139    property CustDictionaryFile: String read FCustom write SetCustomDict;
    132140    property DictionaryFileName:string read FDictFileName write SetDictFileName;
     
    162170    CurrentMe: TskaHunSpellChecker;
    163171implementation
    164    uses messages, Dialogs, RichEdit, SHFolder,  uHunSpellLib;
     172   uses messages, Dialogs, RichEdit, SHFolder,  uHunSpellLib, Registry;
    165173
    166174procedure Register;
     
    184192                                                  [mbYes, mbNo],0, mbNo) = 6);
    185193
    186   if Result and (FUndoList.Count > 0) then
    187   begin
     194  if Result  then
     195  begin
     196    if FUndoList.Count > 0 then
    188197       SourceTextControl.Text := FUndoList[0];
    189        FUndoList.Clear;
    190        FUndoList.Add(SourceTextControl.Text);
    191   end;
     198    FUndoList.Clear;
     199    FUndoList.Add(SourceTextControl.Text);
    192200   FIgnore.Clear;
    193201   FStatus := ssCancelled;
     
    195203   if Assigned(OnAbort) then
    196204     OnAbort(Self);
     205  end;
    197206end;
    198207
     
    363372   FUndoList := TStringList.Create;
    364373
     374   if csDesigning in componentState then
     375   begin
     376   IgnoreAllCaps := True;
     377   IgnoreWordWithDigits := True;
     378   end
     379   else
     380     GetOptions;
     381
    365382   FStatus := ssInActive;
    366383   WaitForUser := False;
     
    380397  Result := '$$' + CurrentWord + '$$';
    381398  if WithPosition then
    382     Result := '$$' + IntToStr(FoundAt+1) + Result;
     399    Result :='$$' + IntToStr(CurrentLine) + '$$' + IntToStr(FoundAt+1) + Result;
    383400end;
    384401
     
    396413    except
    397414    end;
     415    SetOptions;
    398416  finally
    399417    FCustDict.Free;
     
    410428begin
    411429  Result := (FpointerHunLib <> nil);
     430end;
     431
     432procedure TskaHunSpellChecker.GetOptions;
     433var
     434reg:TRegistry;
     435begin
     436 reg:=TRegistry.Create;
     437 try
     438 reg.RootKey := HKEY_CURRENT_USER;
     439
     440 //first get the dicationary file name
     441  Reg.OpenKey('\software\'+ ChangeFileExt(Application.ExeName,'') + '\skaHunSpellCheckOptions',True);
     442  if reg.ValueExists('DicFileName')  then
     443    DictionaryFileName:=Reg.readString('DicFileName')
     444  else
     445    Reg.WriteString('DicFileName',DictionaryFileName);
     446
     447 //IgnoreAllCaps  ?
     448 if reg.ValueExists('IgnoreAllCaps')  then
     449    IgnoreAllCaps:=Reg.readBool('IgnoreAllCaps')
     450  else
     451    Reg.WriteBool('IgnoreAllCaps',IgnoreAllCaps);
     452
     453
     454  //IgnoreWordsWithDigits  ?
     455 if reg.ValueExists('IgnoreWordWithDigits')  then
     456    IgnoreWordWithDigits:=Reg.readBool('IgnoreWordWithDigits')
     457  else
     458    Reg.WriteBool('IgnoreWordWithDigits',IgnoreWordWithDigits);
     459
     460 finally
     461    Reg.Free;
     462 end;
     463
    412464end;
    413465
     
    472524     TextOut(dcForHndl, VisPoint.x, VisPoint.y, pchar(CurrentWord), WordLength);
    473525   end;
     526
     527   function WordIsIgnorable: Boolean;
     528   var
     529     i: Integer;
     530   begin
     531     if IgnoreAllCaps then
     532     begin
     533       Result := True;
     534        for i := 1 to WordLength do
     535        begin
     536          Result := Result and (ord(CurrentWord[i]) in [65..90]);
     537        end;
     538        if Result then
     539          exit;
     540     end;
     541
     542
     543
     544     if IgnoreWordWithDigits then
     545     begin
     546       Result := False;
     547        for i := 1 to WordLength do
     548        begin
     549          Result := Result or (ord(CurrentWord[i]) in [48..57]);
     550          if Result then
     551            break;
     552        end;
     553     end;
     554   end;
    474555begin
    475556  Result := False;
     
    529610        WordPos           := i-WordLength;
    530611        CurrentWord          := copy(CurrentText, WordPos, WordLength);
    531         If ((FIgnore.IndexOf(CurrentWordDetail(True))< 0)  //SingelIgnore
     612       // if WordIsCorrect then
     613       if (((FIgnore.IndexOf(CurrentWordDetail(True))< 0)  //SingelIgnore
    532614              and (FIgnore.IndexOf(CurrentWordDetail(False))< 0) //IgnoreAll
    533               and (IsMisspelled(CurrentWord))) Then
     615              and (IsMisspelled(CurrentWord))))
     616              and (not WordIsIgnorable) then
     617
    534618        begin
    535619           GetSuggestions(CurrentWord, SuggestionList.Items);
     
    764848end;
    765849
     850procedure TskaHunSpellChecker.SetIgnoreCaps(const Value: boolean);
     851begin
     852  if (FIgnoreCaps = Value) then
     853    exit;
     854
     855  FIgnoreCaps := Value;
     856  if SpellCheckState = ssChecking then
     857    ReStart;
     858end;
     859
     860procedure TskaHunSpellChecker.SetIgnoreWordWdigits(const Value: boolean);
     861begin
     862  if (FIgnoreWordWdigits = Value) then
     863    exit;
     864
     865  FIgnoreWordWdigits := Value;
     866  if SpellCheckState = ssChecking then
     867    ReStart;
     868
     869end;
     870
     871procedure TskaHunSpellChecker.SetOptions;
     872var
     873reg:TRegistry;
     874begin
     875 reg:=TRegistry.Create;
     876 try
     877 reg.RootKey := HKEY_CURRENT_USER;
     878
     879
     880  Reg.OpenKey('\software\'+ ChangeFileExt(Application.ExeName,'') + '\skaHunSpellCheckOptions',True);
     881
     882  //first save the dicationary file name
     883  Reg.WriteString('DicFileName',DictionaryFileName);
     884
     885 //IgnoreAllCaps  ?
     886 Reg.WriteBool('IgnoreAllCaps',IgnoreAllCaps);
     887
     888
     889  //IgnoreWordsWithDigits  ?
     890 Reg.WriteBool('IgnoreWordWithDigits',IgnoreWordWithDigits);
     891
     892 finally
     893    Reg.Free;
     894 end;
     895end;
     896
    766897Function RichEditWndProc(handle:HWnd;uMsg,wParam,lParam:longint):longint stdcall;
    767898begin
Note: See TracChangeset for help on using the changeset viewer.