Ignore:
Timestamp:
Aug 27, 2018, 8:33:25 AM (6 years ago)
Author:
chronos
Message:
  • Added: Save to CSV action for document check report.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormCheck.pas

    r198 r199  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   ExtCtrls, ComCtrls, Menus, UAcronym, URegistry, Registry, UCommon, fgl;
     9  ExtCtrls, ComCtrls, Menus, ActnList, UAcronym, URegistry, Registry, UCommon,
     10  fgl;
    1011
    1112type
     
    2324    function AddNew(Message: string; Position: TPoint;
    2425      Kind: TReportType = rtNone): TReportItem;
     26    procedure SaveToCsv(FileName: string);
    2527  end;
    2628
     
    2830
    2931  TFormCheck = class(TForm)
     32    AGoToLocation: TAction;
     33    ASaveToCsv: TAction;
     34    ActionList1: TActionList;
    3035    ButtonLoadFromFile: TButton;
    3136    ButtonAcronymsContent: TButton;
     
    4348    ListViewReport: TListView;
    4449    MemoDocument: TMemo;
     50    MenuItem1: TMenuItem;
    4551    MenuItemGoTo: TMenuItem;
    4652    OpenDialog1: TOpenDialog;
     
    4955    Panel2: TPanel;
    5056    PopupMenuReport: TPopupMenu;
     57    SaveDialog1: TSaveDialog;
    5158    Splitter1: TSplitter;
    5259    TabSheetSource: TTabSheet;
    5360    TabSheetReport: TTabSheet;
     61    procedure AGoToLocationExecute(Sender: TObject);
     62    procedure ASaveToCsvExecute(Sender: TObject);
    5463    procedure ButtonAcronymsSummaryClick(Sender: TObject);
    5564    procedure ButtonAcronymsContentClick(Sender: TObject);
     
    119128  SContentAcronyms = 'Content acronyms';
    120129  SAcronymUsedBeforeDefined = 'Acronym %s used before it was defined.';
     130  SCSVFilter = 'CSV file (.csv)|*.csv|Any file|*.*';
    121131
    122132const
     
    133143  Result.Kind := Kind;
    134144  Add(Result);
     145end;
     146
     147procedure TReportItems.SaveToCsv(FileName: string);
     148var
     149  I: Integer;
     150  F: TStringList;
     151  Line: TStringList;
     152begin
     153  F := TStringList.Create;
     154  Line := TStringList.Create;
     155  Line.StrictDelimiter := True;
     156  try
     157    Line.Clear;
     158    for I := 0 to Count - 1 do
     159    with TReportItem(Items[I]) do begin
     160      Line.Clear;
     161      if Position <> Point(0, 0) then
     162        Line.Add(IntToStr(Position.X) + ', ' + IntToStr(Position.Y))
     163        else Line.Add('');
     164      Line.Add(ReportTypeString[Kind]);
     165      Line.Add(Message);
     166      F.Add(Line.CommaText);
     167    end;
     168    F.SaveToFile(FileName);
     169  finally
     170    F.Free;
     171    Line.Free;
     172  end;
    135173end;
    136174
     
    205243procedure TFormCheck.MenuItemGoToClick(Sender: TObject);
    206244begin
    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;
     245
    213246end;
    214247
     
    238271  finally
    239272    FreeAndNil(FormAcronyms);
     273  end;
     274end;
     275
     276procedure TFormCheck.ASaveToCsvExecute(Sender: TObject);
     277begin
     278  SaveDialog1.InitialDir := ExtractFileDir(LastDocumentFileName);
     279  SaveDialog1.DefaultExt := '.csv';
     280  SaveDialog1.FileName := ExtractFileNameWithoutExt(ExtractFileName(LastDocumentFileName)) + SaveDialog1.DefaultExt;
     281  SaveDialog1.Filter := SCSVFilter;
     282  if SaveDialog1.Execute then begin
     283    ReportItems.SaveToCsv(SaveDialog1.FileName);
     284  end;
     285end;
     286
     287procedure TFormCheck.AGoToLocationExecute(Sender: TObject);
     288begin
     289  if Assigned(ListViewReport.Selected) then
     290  with TReportItem(ListViewReport.Selected.Data) do
     291  if Position <> Point(0, 0) then begin
     292    MemoDocument.CaretPos := Position;
     293    TabSheetSource.Show;
    240294  end;
    241295end;
     
    389443          if HasMeaning1 or HasMeaning2 then begin
    390444            // If plural acronym then try to remove ending 's' character from the meaning
    391             if Plural then ReportItems.AddNew(Format(SPluralAcronym, [Acronym]), Point(0, 0));
     445            if Plural then ReportItems.AddNew(Format(SPluralAcronym, [Acronym]), Point(0, 0), rtNote);
    392446            if Plural and (Length(Meaning) >= 1) and (Meaning[Length(Meaning)] = 's') then begin
    393447              Meaning := Copy(Meaning, 1, Length(Meaning) - 1);
Note: See TracChangeset for help on using the changeset viewer.