Ignore:
Timestamp:
Aug 23, 2018, 3:38:32 PM (6 years ago)
Author:
chronos
Message:
  • Added: Configurable case sensitivity for comparison in Document check.
  • Modified: Show Document check report as ListView. Show message type in separate column.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormCheck.pas

    r195 r198  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   ExtCtrls, ComCtrls, UAcronym, URegistry, Registry, UCommon;
     9  ExtCtrls, ComCtrls, Menus, UAcronym, URegistry, Registry, UCommon, fgl;
    1010
    1111type
     12  TReportType = (rtNone, rtNote, rtWarning, rtError);
     13
     14  TReportItem = class
     15    Message: string;
     16    Position: TPoint;
     17    Kind: TReportType;
     18  end;
     19
     20  { TReportItems }
     21
     22  TReportItems = class(TFPGObjectList<TReportItem>)
     23    function AddNew(Message: string; Position: TPoint;
     24      Kind: TReportType = rtNone): TReportItem;
     25  end;
    1226
    1327  { TFormCheck }
     
    1832    ButtonAcronymsSummary: TButton;
    1933    ButtonCheck: TButton;
     34    CheckBoxCaseSensitive: TCheckBox;
    2035    EditSummaryStart: TEdit;
    2136    EditSummaryEnd: TEdit;
     
    2641    LabelAcronymCountContent: TLabel;
    2742    LabelAcronymCountSummary: TLabel;
     43    ListViewReport: TListView;
    2844    MemoDocument: TMemo;
    29     MemoReport: TMemo;
     45    MenuItemGoTo: TMenuItem;
    3046    OpenDialog1: TOpenDialog;
    3147    PageControl1: TPageControl;
    3248    Panel1: TPanel;
    3349    Panel2: TPanel;
     50    PopupMenuReport: TPopupMenu;
    3451    Splitter1: TSplitter;
    3552    TabSheetSource: TTabSheet;
     
    4360    procedure FormDestroy(Sender: TObject);
    4461    procedure FormShow(Sender: TObject);
     62    procedure ListViewReportData(Sender: TObject; Item: TListItem);
     63    procedure MenuItemGoToClick(Sender: TObject);
    4564  private
    4665    AcronymDbSummary: TAcronymDb;
     
    6180    procedure ReportDifferencies;
    6281    function WordContainsLetters(Text, Letters: string): Boolean;
     82    function StringEqual(Text1, Text2: string): Boolean;
     83    procedure ReloadReport;
    6384  public
     85    ReportItems: TReportItems;
    6486    procedure UpdateInterface;
    6587    procedure LoadConfig;
     
    7092  FormCheck: TFormCheck;
    7193
     94const
     95  ReportTypeString: array[TReportType] of string = ('', 'Note', 'Warning', 'Error');
     96
    7297
    7398implementation
     
    81106  SAcronymCountContent = 'Content acronym count:';
    82107  SAcronymCountSummary = 'Summary acronym count:';
    83   SDuplicateAcronymContent = 'Warning: Duplicate acronym %s with "%s" in document body.';
    84   SDuplicateAcronymSummary = 'Warning: Duplicate acronym %s with "%s" in acronym summary.';
    85   SMissingAcronymContent = 'Warning: Document body acronym %s with meaning "%s" missing from acronym summary.';
    86   SMissingAcronymSummary = 'Warning: Summary acronym %s with meaning "%s" missing from document body.';
    87   SAcronymContentMultipleMeanings = 'Warning: Content acronym %s has multiple meanings: %s.';
    88   SAcronymSummaryMultipleMeanings = 'Warning: Summary acronym %s has multiple meanings: %s.';
    89   SAcronymWithDifferentMeaning = 'Warning: Acronym %s has different meaning for content "%s" and for summary "%s".';
    90   SAcronymWithDifferentMeaningCount = 'Warning: Acronym %s has different meaning count for content (%d) and for summary (%d).';
    91   SPluralAcronym = 'Note: Acronym %s is defined as plural in document body.';
    92   SPluralAcronymUsed = 'Note: Acronym %s is used as plural in document body.';
     108  SDuplicateAcronymContent = 'Duplicate acronym %s with "%s" in document body.';
     109  SDuplicateAcronymSummary = 'Duplicate acronym %s with "%s" in acronym summary.';
     110  SMissingAcronymContent = 'Document body acronym %s with meaning "%s" missing from acronym summary.';
     111  SMissingAcronymSummary = 'Summary acronym %s with meaning "%s" missing from document body.';
     112  SAcronymContentMultipleMeanings = 'Content acronym %s has multiple meanings: %s.';
     113  SAcronymSummaryMultipleMeanings = 'Summary acronym %s has multiple meanings: %s.';
     114  SAcronymWithDifferentMeaning = 'Acronym %s has different meaning for content "%s" and for summary "%s".';
     115  SAcronymWithDifferentMeaningCount = 'Acronym %s has different meaning count for content (%d) and for summary (%d).';
     116  SPluralAcronym = 'Acronym %s is defined as plural in document body.';
     117  SPluralAcronymUsed = 'Acronym %s is used as plural in document body.';
    93118  SSummaryAcronyms = 'Summary acronyms';
    94119  SContentAcronyms = 'Content acronyms';
     
    98123  MinAcronymLength = 2;
    99124
     125{ TReportItems }
     126
     127function TReportItems.AddNew(Message: string; Position: TPoint;
     128  Kind: TReportType = rtNone): TReportItem;
     129begin
     130  Result := TReportItem.Create;
     131  Result.Message := Message;
     132  Result.Position := Position;
     133  Result.Kind := Kind;
     134  Add(Result);
     135end;
     136
    100137{ TFormCheck }
    101138
    102139procedure TFormCheck.ButtonCheckClick(Sender: TObject);
    103140begin
    104   MemoReport.Lines.Clear;
     141  ReportItems.Clear;
     142  UpdateInterface;
    105143  FindInSummary;
    106144  FindInContent;
    107145  ReportDifferencies;
    108146  UpdateInterface;
     147  ReloadReport;
    109148  TabSheetReport.Show;
    110149end;
     
    132171  Core.CoolTranslator1.TranslateComponentRecursive(Self);
    133172  Core.ThemeManager.UseTheme(Self);
     173  ReportItems := TReportItems.Create;
    134174end;
    135175
    136176procedure TFormCheck.FormDestroy(Sender: TObject);
    137177begin
     178  ReportItems.Free;
    138179  AcronymDbSummary.Free;
    139180  AcronymDbContent.Free;
     
    142183procedure TFormCheck.FormShow(Sender: TObject);
    143184begin
     185  PageControl1.TabIndex := 0;
    144186  Core.PersistentForm1.Load(Self);
    145   if FileExists(LastDocumentFileName) then MemoDocument.Lines.LoadFromFile(LastDocumentFileName);
     187  if FileExists(LastDocumentFileName) then
     188    MemoDocument.Lines.LoadFromFile(LastDocumentFileName);
    146189  UpdateInterface;
     190end;
     191
     192procedure TFormCheck.ListViewReportData(Sender: TObject; Item: TListItem);
     193begin
     194  if Item.Index < ReportItems.Count then
     195    with ReportItems[Item.Index] do begin
     196      if Position <> Point(0, 0) then
     197        Item.Caption := IntToStr(Position.X) + ', ' + IntToStr(Position.Y)
     198        else Item.Caption := '';
     199      Item.Data := ReportItems[Item.Index];
     200      Item.SubItems.Add(ReportTypeString[Kind]);
     201      Item.SubItems.Add(Message);
     202    end;
     203end;
     204
     205procedure TFormCheck.MenuItemGoToClick(Sender: TObject);
     206begin
     207  if Assigned(ListViewReport.Selected) then
     208  with TReportItem(ListViewReport.Selected.Data) do
     209  if Position <> Point(0, 0) then begin
     210    MemoDocument.CaretPos := Position;
     211    TabSheetSource.Show;
     212  end;
    147213end;
    148214
     
    214280              Meaning := Trim(Copy(Line, Pos(' ', Line) + 1, Length(Line)));
    215281              if Assigned(AcronymDbSummary.SearchAcronym(Acronym, Meaning)) then
    216                 MemoReport.Lines.Add(Format(SDuplicateAcronymSummary, [Acronym, Meaning]))
     282                ReportItems.AddNew(Format(SDuplicateAcronymSummary, [Acronym, Meaning]), Point(0, I), rtWarning)
    217283                else AcronymDbSummary.AddAcronym(Acronym, Meaning);
    218284            end;
     
    295361          AllowedSideChar(AcronymCharBefore, AcronymCharAfter) then begin
    296362            // If plural acronym then try to remove ending 's' character from the meaning
    297             if Plural then MemoReport.Lines.Add(Format(SPluralAcronymUsed, [Acronym]));
     363            if Plural then ReportItems.AddNew(Format(SPluralAcronymUsed, [Acronym]), Point(0, 0), rtNote);
    298364
    299365            Acro := AcronymDbContent.Acronyms.SearchByName(Acronym);
    300366            if not Assigned(Acro) then begin
    301               MemoReport.Lines.Add(Format(SAcronymUsedBeforeDefined, [Acronym]));
     367              ReportItems.AddNew(Format(SAcronymUsedBeforeDefined, [Acronym]), Point(0, 0), rtNote);
    302368              AcronymDbContent.AddAcronym(Acronym, '');
    303369            end;
     
    323389          if HasMeaning1 or HasMeaning2 then begin
    324390            // If plural acronym then try to remove ending 's' character from the meaning
    325             if Plural then MemoReport.Lines.Add(Format(SPluralAcronym, [Acronym]));
     391            if Plural then ReportItems.AddNew(Format(SPluralAcronym, [Acronym]), Point(0, 0));
    326392            if Plural and (Length(Meaning) >= 1) and (Meaning[Length(Meaning)] = 's') then begin
    327393              Meaning := Copy(Meaning, 1, Length(Meaning) - 1);
    328394            end;
    329395            if Assigned(AcronymDbContent.SearchAcronym(Acronym, Meaning)) then
    330               MemoReport.Lines.Add(Format(SDuplicateAcronymContent, [Acronym, Meaning]))
     396              ReportItems.AddNew(Format(SDuplicateAcronymContent, [Acronym, Meaning]), Point(0, 0), rtWarning)
    331397              else AcronymDbContent.AddAcronym(Acronym, Meaning);
    332398          end;
     
    511577    Acronym := TAcronym(AcronymDbContent.Acronyms[I]);
    512578    if Acronym.Meanings.Count > 1 then
    513       MemoReport.Lines.Add(Format(SAcronymContentMultipleMeanings, [Acronym.Name, Acronym.Meanings.GetNames]));
     579      ReportItems.AddNew(Format(SAcronymContentMultipleMeanings, [Acronym.Name,
     580        Acronym.Meanings.GetNames]), Point(0, 0), rtWarning);
    514581    Acronym2 := AcronymDbSummary.Acronyms.SearchByName(Acronym.Name);
    515582    if not Assigned(Acronym2) then
     
    517584      Meaning := TAcronymMeaning(Acronym.Meanings[J]);
    518585      if not Assigned(AcronymDbSummary.SearchAcronym(Acronym.Name, Meaning.Name, [sfCaseInsensitive])) then
    519         MemoReport.Lines.Add(Format(SMissingAcronymContent, [Acronym.Name, Meaning.Name]));
     586        ReportItems.AddNew(Format(SMissingAcronymContent, [Acronym.Name, Meaning.Name]), Point(0, 0), rtWarning);
    520587    end;
    521588  end;
     
    525592    Acronym := TAcronym(AcronymDbSummary.Acronyms[I]);
    526593    if Acronym.Meanings.Count > 1 then
    527       MemoReport.Lines.Add(Format(SAcronymSummaryMultipleMeanings, [Acronym.Name, Acronym.Meanings.GetNames]));
     594      ReportItems.AddNew(Format(SAcronymSummaryMultipleMeanings, [Acronym.Name, Acronym.Meanings.GetNames]), Point(0, 0), rtWarning);
    528595    Acronym2 := AcronymDbContent.Acronyms.SearchByName(Acronym.Name);
    529596    if not Assigned(Acronym2) then
     
    531598      Meaning := TAcronymMeaning(Acronym.Meanings[J]);
    532599      if not Assigned(AcronymDbContent.SearchAcronym(Acronym.Name, Meaning.Name, [sfCaseInsensitive])) then
    533         MemoReport.Lines.Add(Format(SMissingAcronymSummary, [Acronym.Name, Meaning.Name]));
     600        ReportItems.AddNew(Format(SMissingAcronymSummary, [Acronym.Name, Meaning.Name]), Point(0, 0), rtWarning);
    534601    end;
    535602  end;
     
    543610        Meaning := TAcronymMeaning(Acronym.Meanings[0]);
    544611        Meaning2 := TAcronymMeaning(Acronym2.Meanings[0]);
    545         if Meaning.Name <> Meaning2.Name then
    546           MemoReport.Lines.Add(Format(SAcronymWithDifferentMeaning, [Acronym.Name, Meaning.Name, Meaning2.Name]));
     612        if not StringEqual(Meaning.Name, Meaning2.Name) then
     613          ReportItems.AddNew(Format(SAcronymWithDifferentMeaning, [Acronym.Name, Meaning2.Name, Meaning.Name]), Point(0, 0), rtWarning);
    547614      end else
    548         MemoReport.Lines.Add(Format(SAcronymWithDifferentMeaningCount, [Acronym.Name, Acronym.Meanings.Count, Acronym2.Meanings.Count]));
     615        ReportItems.AddNew(Format(SAcronymWithDifferentMeaningCount, [Acronym.Name, Acronym2.Meanings.Count, Acronym.Meanings.Count]), Point(0, 0), rtWarning);
    549616    end;
    550617  end;
     
    568635end;
    569636
     637function TFormCheck.StringEqual(Text1, Text2: string): Boolean;
     638begin
     639  if CheckBoxCaseSensitive.Checked then Result := Text1 = Text2
     640    else Result := LowerCase(Text1) = LowerCase(Text2);
     641end;
     642
     643procedure TFormCheck.ReloadReport;
     644begin
     645  ListViewReport.Items.Count := ReportItems.Count;
     646  ListViewReport.Refresh;
     647end;
     648
    570649procedure TFormCheck.UpdateInterface;
    571650begin
     
    582661    EditSummaryStart.Text := ReadStringWithDefault('SummaryStart', 'ACRONYMS AND ABBREVIATIONS');
    583662    EditSummaryEnd.Text := ReadStringWithDefault('SummaryEnd', 'Appendix');
    584     LastDocumentFileName := ReadStringWithDefault('LastDocumentFileName', '')
     663    LastDocumentFileName := ReadStringWithDefault('LastDocumentFileName', '');
     664    CheckBoxCaseSensitive.Checked := ReadBoolWithDefault('CaseSensitiveComparison', False);
    585665  finally
    586666    Free;
     
    597677    WriteString('SummaryEnd', EditSummaryEnd.Text);
    598678    WriteString('LastDocumentFileName', LastDocumentFileName);
     679    WriteBool('CaseSensitiveComparison', CheckBoxCaseSensitive.Checked);
    599680  finally
    600681    Free;
Note: See TracChangeset for help on using the changeset viewer.