1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
|
unit ResultDlg;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
Buttons, ClipBrd, LCLType, LCLProc, ComCtrls, Menus, SynEdit,
SynHighlighterPo, PoFamilies, PoFamilyLists, GraphStat, PoCheckerConsts,
PoCheckerSettings, Types;
type
{ TResultDlgForm }
TResultDlgForm = class(TForm)
GraphStatBtn: TBitBtn;
CopyMenuItem: TMenuItem;
SaveAsMenuItem: TMenuItem;
MemoPopupMenu: TPopupMenu;
StatMemo: TSynEdit;
ResultPageControl: TPageControl;
CloseBtn: TBitBtn;
Panel1: TPanel;
SaveDialog: TSaveDialog;
FLog: TStringList;
FStatLog: TStringList;
FDupLog: TStringList;
LogMemo: TSynEdit;
GeneralTabSheet: TTabSheet;
StatisticsTabSheet: TTabSheet;
DuplicatesTabSheet: TTabSheet;
DupMemo: TSynEdit;
procedure CopyMenuItemClick(Sender: TObject);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FormShow(Sender: TObject);
procedure GraphStatBtnClick(Sender: TObject);
procedure SaveAsMenuItemClick(Sender: TObject);
private
PoHL: TSynPoSyn;
FPoFamilyList: TPoFamilyList;
FPoFamilyStats: TPoFamilyStats;
FSettings: TPoCheckerSettings;
procedure GetCurrentMemo(var CurrentMemo: TSynEdit);
procedure LoadConfig;
procedure SaveConfig;
public
// The following fields keep translation statistics calculated when tests were performed.
// They will allow to avoid recalculation of these values in GraphStat form.
FTotalTranslated: Integer;
FTotalUntranslated: Integer;
FTotalFuzzy: Integer;
FTotalPercTranslated: Double;
FTestOptions: TPoTestOptions;
property Log: TStringList read FLog write FLog;
property StatLog: TStringList read FStatLog write FStatLog;
property DupLog: TStringList read FDupLog write FDupLog;
property PoFamilyList: TPoFamilyList read FPoFamilyList write FPoFamilyList;
property PoFamilyStats: TPoFamilyStats read FPoFamilyStats write FPoFamilyStats;
property Settings: TPoCheckerSettings read FSettings write FSettings;
end;
implementation
{$R *.lfm}
{ TResultDlgForm }
procedure TResultDlgForm.FormCreate(Sender: TObject);
begin
Caption := sResults;
GeneralTabSheet.Caption := sGeneralInfo;
StatisticsTabSheet.Caption := sTranslationStatistics;
DuplicatesTabSheet.Caption := sDuplicateOriginalsTab;
CopyMenuItem.Caption := sCopy;
SaveAsMenuItem.Caption := sSaveAs;
LogMemo.Lines.Clear;
StatMemo.Lines.Clear;
FLog := TStringList.Create;
FStatLog := TStringList.Create;
FDupLog := TStringList.Create;
PoHL := TSynPoSyn.Create(Self);
LogMemo.Highlighter := PoHL;
GraphStatBtn.Caption := sShowStatGraph;
FTotalTranslated := 0;
FTotalUntranslated := 0;
FTotalFuzzy := 0;
end;
procedure TResultDlgForm.FormClose(Sender: TObject;
var CloseAction: TCloseAction);
begin
FLog.Clear;
FStatLog.Clear;
FDupLog.Clear;
end;
procedure TResultDlgForm.CopyMenuItemClick(Sender: TObject);
var
CurMemo: TSynEdit;
begin
GetCurrentMemo(CurMemo);
if CurMemo <> nil then
ClipBoard.AsText := CurMemo.Text;
end;
procedure TResultDlgForm.FormDestroy(Sender: TObject);
begin
FLog.Free;
FStatLog.Free;
FDupLog.Free;
SaveConfig;
end;
procedure TResultDlgForm.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
CurMemo: TSynEdit;
begin
GetCurrentMemo(CurMemo);
if (Key = VK_Tab) and (Shift = []) and (Assigned(CurMemo) and CurMemo.Focused) then
begin
//Workaroud: cannot tab out of LogMemo/StatMemo
GraphStatBtn.SetFocus;
//debugln('Tab');
Key := 0;
end;
end;
procedure TResultDlgForm.FormShow(Sender: TObject);
begin
LogMemo.Lines.Assign(FLog);
StatMemo.Lines.Assign(FStatLog);
DupMemo.Lines.Assign(FDupLog);
GraphStatBtn.Visible := (PoFamilyStats <> nil) and (PoFamilyStats.Count > 0);
LoadConfig;
WindowState := Settings.ResultsFormWindowState;
end;
procedure TResultDlgForm.GraphStatBtnClick(Sender: TObject);
var
mr: TModalResult;
begin
GraphStatForm := TGraphStatForm.Create(nil);
try
GraphStatForm.PoFamilyList := Self.PoFamilyList;
GraphStatForm.PoFamilyStats := Self.PoFamilyStats;
GraphStatForm.Settings := Self.Settings;
if not (ptoFindAllChildren in FTestOptions) then
begin
GraphStatForm.TranslatedLabel.Caption := Format(sTranslatedStringsTotal, [
IntToStr(FTotalTranslated), FTotalPercTranslated]);
GraphStatForm.UnTranslatedLabel.Caption := Format(sUntranslatedStringsTotal
, [IntToStr(FTotalUntranslated)]);
GraphStatForm.FuzzyLabel.Caption := Format(sFuzzyStringsTotal, [IntToStr(
FTotalFuzzy)]);
end
else
begin
GraphStatForm.TranslatedLabel.Caption := sTranslatedStrings;
GraphStatForm.UnTranslatedLabel.Caption := sUntranslatedStrings;
GraphStatForm.FuzzyLabel.Caption := sFuzzyStrings;
end;
mr := GraphStatForm.ShowModal;
if mr = mrOpenEditorFile then ModalResult := mr; // To inform pocheckermain
finally
FreeAndNil(GraphStatForm);
end;
end;
procedure TResultDlgForm.SaveAsMenuItemClick(Sender: TObject);
var
CurMemo: TSynEdit;
begin
GetCurrentMemo(CurMemo);
if (CurMemo <> nil) and (SaveDialog.Execute) then
begin
try
CurMemo.Lines.SaveToFile(SaveDialog.FileName);
except
on E: EStreamError do MessageDlg('POChecker',Format(sSaveError,[SaveDialog.FileName]),mtError, [mbOk],0);
end;
end;
end;
procedure TResultDlgForm.GetCurrentMemo(var CurrentMemo: TSynEdit);
begin
case ResultPageControl.PageIndex of
0: CurrentMemo := LogMemo;
1: CurrentMemo := StatMemo;
2: CurrentMemo := DupMemo;
else
CurrentMemo := nil;
end;
end;
procedure TResultDlgForm.LoadConfig;
var
ARect: TRect;
begin
if not Assigned(FSettings) then Exit;
ARect := FSettings.ResultsFormGeometry;
//debugln('TResultDlgForm.LoadConfig: ARect = ',dbgs(ARect));
if not IsDefaultRect(ARect) and IsValidRect(ARect) then
begin
ARect := FitToRect(ARect, Screen.WorkAreaRect);
BoundsRect := ARect;
end;
if Settings.DisableAntialiasing then
begin
LogMemo.Font.Quality := fqNonAntialiased;
StatMemo.Font.Quality := fqNonAntialiased;
DupMemo.Font.Quality := fqNonAntialiased;
end
else
begin
LogMemo.Font.Quality := fqDefault;
StatMemo.Font.Quality := fqDefault;
DupMemo.Font.Quality := fqDefault;
end;
end;
procedure TResultDlgForm.SaveConfig;
begin
//debugln('TResultDlgForm.SaveConfig: BoundsRect = ',dbgs(BoundsRect));
if not Assigned(FSettings) then Exit;
Settings.ResultsFormWindowState := WindowState;
if (WindowState = wsNormal) then
Settings.ResultsFormGeometry := BoundsRect
else
Settings.ResultsFormGeometry := Rect(RestoredLeft, RestoredTop, RestoredLeft + RestoredWidth, RestoredTop + RestoredHeight);
end;
end.
|