Ignore:
Timestamp:
May 19, 2015, 3:06:26 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-Chart/fHunSpell.pas

    r1700 r1719  
    4545    OpenDialog1: TOpenDialog;
    4646    SpellCheck1: TskaHunSpellChecker;
    47     Edit1: TEdit;
     47    edtDictionary: TEdit;
    4848    btnSelectDict: TBitBtn;
    4949    lblOpenMedURL: TLabel;
     
    5454    lstSuggestions: TListBox;
    5555    Label4: TLabel;
    56     Edit2: TEdit;
     56    edtMisSpelt: TEdit;
    5757    btnReplaceWith: TButton;
    5858    btnChangeAll: TButton;
     
    6161    btnIgnoreAll: TButton;
    6262    btnIgnoreOnce: TButton;
    63     btnCancel: TButton;
     63    btnAbort: TButton;
    6464    btnAbout: TButton;
    6565    pnlAbout: TPanel;
    6666    Button1: TButton;
    6767    btnUndo: TButton;
     68    cbIgnoreAllCaps: TCheckBox;
     69    cbIgnoreDigit: TCheckBox;
    6870    procedure FormCreate(Sender: TObject);
    6971    procedure btnIgnoreOnceClick(Sender: TObject);
     
    7476    procedure FormActivate(Sender: TObject);
    7577    procedure btnSelectDictClick(Sender: TObject);
    76     procedure Edit1Enter(Sender: TObject);
     78    procedure edtDictionaryEnter(Sender: TObject);
    7779    procedure btnReplaceWithClick(Sender: TObject);
    7880    procedure btnAddToDictionaryClick(Sender: TObject);
    7981    procedure FormShow(Sender: TObject);
    8082    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    81     procedure btnCancelClick(Sender: TObject);
     83    procedure btnAbortClick(Sender: TObject);
    8284    procedure lblOpenMedURLClick(Sender: TObject);
    8385    procedure btnAboutClick(Sender: TObject);
     
    8890    procedure RichEdit1KeyDown(Sender: TObject; var Key: Word;
    8991      Shift: TShiftState);
     92    procedure lstSuggestionsDblClick(Sender: TObject);
     93    procedure SpellCheck1StateChange(const Sender: TObject;
     94      const State: TSpellState);
     95    procedure SpellCheck1Abort(Sender: TObject);
     96    procedure SpellCheck1Start(Sender: TObject);
     97    procedure cbIgnoreAllCapsClick(Sender: TObject);
     98    procedure cbIgnoreDigitClick(Sender: TObject);
     99    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    90100  private
    91101    { Private declarations }
    92102    NoEngineOpted: Boolean;
    93103    FSourceControl: TCustomMemo;
    94     WaitForUser: Boolean;
    95104    procedure GoToURL(const aURL: String);
     105    procedure UpdateGUI;
    96106  public
    97107    { Public declarations }
     
    104114  end;
    105115
     116  Resourcestring
     117    TX_AFF_NOT_FOUND      = 'Correspong AFF file named not found!'
     118                          + #13
     119                          + '  Specify dictionary file whose *.aff is also '
     120                          + 'present in same directory.' ;
     121    TX_DIC_FILE_NOT_FOUND = 'Dictionary File for SpellCheck Engine not found!';
     122    TX_SPELL_COMPLETE     = 'Spell Check Complete';
     123    TX_SPELL_CANCELLED    = 'Spell Check Aborted'
     124                          + #13
     125                          + 'No Changes applied to the original text!';
     126
     127 Const
     128   DefaultDicFile =  'dict\en-US-OpenMedSpel.dic';
     129
    106130 var
    107131  frmHunSpell: TfrmHunSpell;
     
    130154 procedure TfrmHunSpell.FormShow(Sender: TObject);
    131155begin
    132  if SpellCheck1.SpellCheckState = ssNotStarted then
     156 if SpellCheck1.SpellCheckState = ssReady then
    133157   SpellCheck1.CheckSpelling;
    134 
    135158 try
    136159   if lstSuggestions.Count > 0 then
    137160     btnChange.SetFocus;
    138161 except
    139 
    140162 end;
    141163end;
     
    153175end;
    154176
     177procedure TfrmHunSpell.lstSuggestionsDblClick(Sender: TObject);
     178begin
     179  inherited;
     180  btnChangeClick(sender);
     181end;
     182
    155183procedure TfrmHunSpell.RichEdit1KeyDown(Sender: TObject; var Key: Word;
    156184  Shift: TShiftState);
    157185begin
    158186  inherited;
    159   SpellCheck1.ManualChangeStart;
     187  if SpellCheck1.SpellCheckState = ssChecking then
     188    SpellCheck1.ManualChangeStart;
    160189end;
    161190
     
    164193begin
    165194  inherited;
    166   SpellCheck1.ManualChangeDone;
     195  if SpellCheck1.SpellCheckState in [ssCancelled, ssCompleted] then
     196   SpellCheck1.Reopen;
     197
     198 if SpellCheck1.SpellCheckState = ssChecking then
     199    SpellCheck1.ManualChangeDone;
     200end;
     201
     202procedure TfrmHunSpell.SpellCheck1Abort(Sender: TObject);
     203begin
     204  inherited;
     205  UpdateGUI;
     206end;
     207
     208procedure TfrmHunSpell.SpellCheck1Start(Sender: TObject);
     209begin
     210  inherited;
     211  UpdateGUI;
     212end;
     213
     214procedure TfrmHunSpell.SpellCheck1StateChange(const Sender: TObject;
     215  const State: TSpellState);
     216begin
     217  inherited;
     218  if State = ssCompleted then
     219    ShowMessage(TX_SPELL_COMPLETE);
     220  UpdateGUI;
     221end;
     222
     223procedure TfrmHunSpell.UpdateGUI;
     224var
     225  Checking: Boolean;
     226begin
     227  if  csDestroying in componentstate then
     228     exit;
     229  Checking := SpellCheck1.SpellCheckState = ssChecking;
     230  pnlMisSpelled.Visible := Checking;
     231  pnlMisSpelled.Enabled := Checking;
     232  btnClose.Visible := not Checking;
    167233end;
    168234
     
    185251end;
    186252
    187 procedure TfrmHunSpell.btnCancelClick(Sender: TObject);
     253procedure TfrmHunSpell.btnAbortClick(Sender: TObject);
    188254begin
    189255//popup 508 compliant confirmation/warning box if isModified
    190   if SpellCheck1.AbortSpellCheck(False) then
     256  if SpellCheck1.AbortSpellCheck(True) then
    191257  begin
    192258     Close;
     
    207273procedure TfrmHunSpell.btnCloseClick(Sender: TObject);
    208274begin
    209  close;
     275  close;
    210276end;
    211277
     
    232298    if not FileExists(aff) then
    233299    begin
    234       ShowMessage('Correspong AFF file named "'+ aff + '" not found!' + #13 + '  Specify dictionary file whose *.aff is also present in same directory.');
     300      ShowMessage(TX_AFF_NOT_FOUND);
    235301      OpenDialog1.FileName := '';
    236302      btnSelectDictClick(self);
     
    240306      if SpellCheck1.SpellCheckState = ssChecking then
    241307        SpellCheck1.AbortSpellCheck(False);
    242       Edit1.Text := OpenDialog1.FileName;
    243       SpellCheck1.DictionaryFileName := OpenDialog1.FileName;
     308      edtDictionary.Text := OpenDialog1.FileName;
     309      SpellCheck1.DictionaryFileName := edtDictionary.Text;
    244310      SpellCheck1.AffixFileName := aff;
    245311      SpellCheck1.Open;
    246       WaitForUser := False;
    247       SpellCheck1.CheckSpelling;
    248312    end;
    249313  end;
     
    262326end;
    263327
    264 procedure TfrmHunSpell.Edit1Enter(Sender: TObject);
     328procedure TfrmHunSpell.cbIgnoreAllCapsClick(Sender: TObject);
     329begin
     330  inherited;
     331  if SpellCheck1.IgnoreAllCaps <> cbIgnoreAllCaps.Checked then
     332    SpellCheck1.IgnoreAllCaps := cbIgnoreAllCaps.Checked;
     333end;
     334
     335procedure TfrmHunSpell.cbIgnoreDigitClick(Sender: TObject);
     336begin
     337  inherited;
     338  if SpellCheck1.IgnoreWordWithDigits <> cbIgnoreDigit.Checked then
     339    SpellCheck1.IgnoreWordWithDigits := cbIgnoreDigit.Checked;
     340end;
     341
     342procedure TfrmHunSpell.edtDictionaryEnter(Sender: TObject);
    265343begin
    266344  btnSelectDict.SetFocus;
     
    274352     NoEngineOpted := True;
    275353  end;
     354  if cbIgnoreAllCaps.Checked <> SpellCheck1.IgnoreAllCaps then
     355    cbIgnoreAllCaps.Checked := SpellCheck1.IgnoreAllCaps;
     356
     357  if cbIgnoreDigit.Checked <> SpellCheck1.IgnoreWordWithDigits then
     358    cbIgnoreDigit.Checked := SpellCheck1.IgnoreWordWithDigits;
    276359end;
    277360
     
    283366    if Assigned(FSourceControl) then
    284367      FSourceControl.Text := RichEdit1.Text;
     368  end;
     369  {else
     370  ShowMsg(TX_SPELL_CANCELLED + CRLF + TX_NO_CORRECTIONS,
     371                                              TShow508MessageIcon(1), smbOK) ;}
     372end;
     373
     374procedure TfrmHunSpell.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
     375begin
     376  inherited;
     377
     378  CanClose := (SpellCheck1.SpellCheckState <> ssChecking)
     379               or (SpellCheck1.AbortSpellCheck(True));
     380  if CanClose then
     381     ModalResult := mrCancel;
     382end;
     383
     384procedure TfrmHunSpell.FormCreate(Sender: TObject);
     385var
     386  dicFile: String;
     387  function affFile: String;
     388  begin
     389    Result := ChangeFileExt(dicFile, '.aff');
     390  end;
     391begin
     392  if (SpellCheck1.DictionaryFileName <>  '') then
     393      dicFile := SpellCheck1.DictionaryFileName
     394  else
     395      dicFile := ExtractFilePath(Application.ExeName)+ DefaultDicFile;
     396
     397  if (FileExists(dicFile)) and (FileExists(affFile)) then
     398  begin
     399      SpellCheck1.AffixFileName := affFile;
     400      edtDictionary.Text := SpellCheck1.DictionaryFileName;
    285401  end
    286402  else
    287         ShowMsg(TX_SPELL_CANCELLED + CRLF + TX_NO_CORRECTIONS,TShow508MessageIcon(1), smbOK) ;
    288 end;
    289 
    290 procedure TfrmHunSpell.FormCreate(Sender: TObject);
    291 begin
    292   if FileExists(ExtractFilePath(Application.ExeName)+'\dict\en-US-OpenMedSpel.dic')
    293     and FileExists(ExtractFilePath(Application.ExeName)+'\dict\en-US-OpenMedSpel.aff') then
    294   begin
    295     SpellCheck1.AffixFileName := ExtractFilePath(Application.ExeName)+'\dict\en-US-OpenMedSpel.aff';
    296     SpellCheck1.DictionaryFileName := ExtractFilePath(Application.ExeName)+'\dict\en-US-OpenMedSpel.dic';
    297     Edit1.Text := SpellCheck1.DictionaryFileName;
    298     SpellCheck1.Active := True;
    299   end
    300   else
    301     Edit1.Text := 'Dictionary File for SpellCheck Engine not found!';
    302    
     403    edtDictionary.Text := TX_Dic_File_Not_Found;
     404
     405  if edtDictionary.Text = TX_Dic_File_Not_Found then
     406    btnSelectDictClick(self);
    303407  SpellCheck1.SourceTextControl := RichEdit1;
    304408  SpellCheck1.SuggestionList := lstSuggestions;
    305   SpellCheck1.MisSpeltWord := Edit2;
    306   SpellCheck1.btnClose := btnClose;
     409  SpellCheck1.MisSpeltWord := edtMisSpelt;
     410  SpellCheck1.Active :=  (SpellCheck1.DictionaryFileName <>  '')
     411                                                      and FileExists(dicFile);
    307412end;
    308413
Note: See TracChangeset for help on using the changeset viewer.