Changeset 1718 for cprs/branches


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

Location:
cprs/branches/HealthSevak-CPRS/CPRS-Lib/Hans SpellCheck
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • cprs/branches/HealthSevak-CPRS/CPRS-Lib/Hans SpellCheck/Demo/fHunSpell.dfm

    r1715 r1718  
    1616  OnActivate = FormActivate
    1717  OnClose = FormClose
     18  OnCloseQuery = FormCloseQuery
    1819  OnCreate = FormCreate
    1920  PixelsPerInch = 96
     
    197198  object RichEdit1: TRichEdit
    198199    Left = 3
    199     Top = 57
     200    Top = 76
    200201    Width = 726
    201     Height = 205
     202    Height = 186
    202203    Lines.Strings = (
    203204      'Type orr Paste heree the text '
     
    228229    OnClick = btnCloseClick
    229230  end
     231  object cbIgnoreAllCaps: TCheckBox
     232    Left = 131
     233    Top = 54
     234    Width = 178
     235    Height = 17
     236    Caption = 'Ignore words in &UpperCase'
     237    TabOrder = 6
     238    OnClick = cbIgnoreAllCapsClick
     239  end
     240  object cbIgnoreDigit: TCheckBox
     241    Left = 339
     242    Top = 53
     243    Width = 166
     244    Height = 17
     245    Caption = 'Ignore words with &digits'
     246    TabOrder = 7
     247    OnClick = cbIgnoreDigitClick
     248  end
    230249  object OpenDialog1: TOpenDialog
    231250    DefaultExt = '*.Dict'
  • cprs/branches/HealthSevak-CPRS/CPRS-Lib/Hans SpellCheck/Demo/fHunSpell.pas

    r1715 r1718  
    6262    btnAbort: TButton;
    6363    btnUndo: TButton;
     64    cbIgnoreAllCaps: TCheckBox;
     65    cbIgnoreDigit: TCheckBox;
    6466    procedure FormCreate(Sender: TObject);
    6567    procedure btnIgnoreOnceClick(Sender: TObject);
     
    8890    procedure lblDictionariesURLClick(Sender: TObject);
    8991    procedure lstSuggestionsDblClick(Sender: TObject);
     92    procedure cbIgnoreAllCapsClick(Sender: TObject);
     93    procedure cbIgnoreDigitClick(Sender: TObject);
     94    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    9095  private
    9196    { Private declarations }
     
    296301end;
    297302
     303procedure TfrmHunSpell.cbIgnoreAllCapsClick(Sender: TObject);
     304begin
     305  if SpellCheck1.IgnoreAllCaps <> cbIgnoreAllCaps.Checked then
     306    SpellCheck1.IgnoreAllCaps := cbIgnoreAllCaps.Checked;
     307end;
     308
     309procedure TfrmHunSpell.cbIgnoreDigitClick(Sender: TObject);
     310begin
     311  if SpellCheck1.IgnoreWordWithDigits <> cbIgnoreDigit.Checked then
     312    SpellCheck1.IgnoreWordWithDigits := cbIgnoreDigit.Checked;
     313end;
     314
    298315procedure TfrmHunSpell.edtDictionaryEnter(Sender: TObject);
    299316begin
     
    308325     NoEngineOpted := True;
    309326  end;
     327
     328  if cbIgnoreAllCaps.Checked <> SpellCheck1.IgnoreAllCaps then
     329    cbIgnoreAllCaps.Checked := SpellCheck1.IgnoreAllCaps;
     330
     331  if cbIgnoreDigit.Checked <> SpellCheck1.IgnoreWordWithDigits then
     332    cbIgnoreDigit.Checked := SpellCheck1.IgnoreWordWithDigits;
    310333end;
    311334
     
    320343  else
    321344        ShowMessage(TX_SPELL_CANCELLED) ;  }
     345end;
     346
     347procedure TfrmHunSpell.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
     348begin
     349  CanClose := (SpellCheck1.SpellCheckState <> ssChecking)
     350               or (SpellCheck1.AbortSpellCheck(True));
     351  if CanClose then
     352     ModalResult := mrCancel;
    322353end;
    323354
  • cprs/branches/HealthSevak-CPRS/CPRS-Lib/Hans SpellCheck/skaHunSpellChecker.dproj

    r1715 r1718  
    3838     
    3939     
    40      
    41      
    42      
    4340      <Excluded_Packages Name="C:\Documents and Settings\All Users\Documents\RAD Studio\5.0\Bpl\XWB_R2007.bpl">VistA RPC Broker Runtime Package</Excluded_Packages>
    4441      <Excluded_Packages Name="E:\WVEHR\branches\HealthSevak-CPRS\BDK50\Packages\XWB_D2007.bpl">File E:\WVEHR\branches\HealthSevak-CPRS\BDK50\Packages\XWB_D2007.bpl not found</Excluded_Packages>
     
    5148      <MainSource>MainSource</MainSource>
    5249    </DelphiCompile>
    53     <DCCReference Include="Demo\rtl.dcp" />
    54     <DCCReference Include="Demo\vcl.dcp" />
     50    <DCCReference Include="C:\Documents and Settings\sunil\rtl.dcp" />
     51    <DCCReference Include="C:\Documents and Settings\sunil\vcl.dcp" />
    5552    <DCCReference Include="skaSpellCheck.pas" />
    5653    <DCCReference Include="uHunSpellLib.pas" />
  • 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.