Il 26/09/2014 18:51, Bart ha scritto:
Feel free to commit it, I will probably not interfere with my work.
I'll be working on the mainform most of the time now (and the settings unit).
Please find here enclosed my proposed patch for Pochecker.
I've implemented the opening in the IDE editor (which brought a number
of consequences), but I've also made some improvements.
What I've done:
1) cosmetic: adding an AntialiasingMode := amOn to the canvas in
TGraphStatForm.CreateBitmap, the Qt image is much better (Qt has
antialiasing support). Other widgetsets are unaffected.
2) In order to be able to open the file, I needed its full name, so I've
been forced to add a new property to Tstat, and then pass its value to
TStat.Create.
3) If you open the file in the IDE editor, you have still two modal
windows and the main window open, in front of the Editor Window, and you
don't get any visual feedback that a new editor window has been opened.
I introduced a custom Modal Result mrOpenEditorFile, so that the modal
windows are closed, and the main window is minimized.
4) Once you're done editing you may want to check again, but this
requires that Pochecker is visible in the Task Bar: the property
ShowInTaskBar must be set to stAlways to make sure that it's accessible
from the task bar in all platforms.
5) If after editing and saving your file(s) you click a second time on
"Run Selected Tests" you'd like to see the current situation, not the
previous one. Therefore I've added a boolean FNewRun, to know if a call
to TryCreatePoFamily is required before running the tests.
6) At startup the last choices are remembered, but not by the OpenFile
dialog. Therefore I've set the InitialDir of the dialog to the one of
the last file, which is usually a much better starting point than the
defaults.
7) Trying to use the tool I realized that another feature was missing:
GraphStat provided only information about the
Translated/Untranslated/Fuzzy, but didn't tell a thing about errors.
Therefore I've added another property to Tstat, and filled it properly
(TStat.Create, etc). Then I've added a red question mark to the pie
image when the errors are > 0, and I've added the number of errors to
the hint.
If you like what I've done, but it creates conflicts with your changes,
let me know if you prefer that I take care of adapting my patch to the
current situation.
Giuliano
--
Giuliano Colla
Project planning question: when it's 90% done, are we halfway or not yet?
Index: pocheckerconsts.pas
===================================================================
--- pocheckerconsts.pas (revisione 46344)
+++ pocheckerconsts.pas (copia locale)
@@ -3,6 +3,7 @@
{$mode objfpc}{$H+}
interface
+uses Controls;
resourcestring
//Main form
@@ -40,7 +41,8 @@
sFuzzy = 'Fuzzy';
sStatHint = '%3d Translated (%3.1f%%)' + LineEnding +
'%3d UnTranslated (%3.1f%%)' + LineEnding +
- '%3d Fuzzy (%3.1f%%)';
+ '%3d Fuzzy (%3.1f%%)' + LineEnding +
+ '%d Errors';
//PoFamiles
sOriginal = 'Original';
@@ -78,6 +80,12 @@
sPercTranslated = '%s: %4.1f%% translated strings.';
sPercUntranslated = '%s: %4.1f%% untranslated strings.';
sPercFuzzy = '%s: %4.1f%% fuzzy strings.';
+ //GraphStat
+ sOpenFile = 'Open file %s in Ide Editor?';
+ SOpenFail = 'Unable to open file %s';
+const
+ mrOpenEditorFile = mrNone+100;
+
implementation
end.
Index: resultdlg.lfm
===================================================================
--- resultdlg.lfm (revisione 46344)
+++ resultdlg.lfm (copia locale)
@@ -27,10 +27,10 @@
object CloseBtn: TBitBtn
AnchorSideRight.Control = Panel1
AnchorSideRight.Side = asrBottom
- Left = 657
- Height = 26
+ Left = 651
+ Height = 27
Top = 12
- Width = 75
+ Width = 81
Anchors = [akRight]
AutoSize = True
BorderSpacing.Right = 10
@@ -41,10 +41,10 @@
end
object SaveBtn: TBitBtn
AnchorSideRight.Control = CloseBtn
- Left = 544
- Height = 26
+ Left = 524
+ Height = 27
Top = 12
- Width = 103
+ Width = 117
Anchors = [akRight]
AutoSize = True
BorderSpacing.Around = 10
@@ -90,10 +90,10 @@
end
object CopyBtn: TBitBtn
AnchorSideRight.Control = SaveBtn
- Left = 393
- Height = 26
+ Left = 357
+ Height = 27
Top = 12
- Width = 141
+ Width = 157
Anchors = [akRight]
AutoSize = True
BorderSpacing.Around = 10
@@ -139,10 +139,10 @@
end
object GraphStatBtn: TBitBtn
AnchorSideRight.Control = CopyBtn
- Left = 226
- Height = 26
+ Left = 162
+ Height = 27
Top = 12
- Width = 157
+ Width = 185
Anchors = [akRight]
AutoSize = True
Caption = 'Show statistics graph'
@@ -198,7 +198,7 @@
ParentColor = False
ParentFont = False
TabOrder = 0
- Gutter.Width = 21
+ Gutter.Width = 23
Gutter.MouseActions = <
item
ClickCount = ccAny
@@ -743,7 +743,7 @@
LineHighlightColor.FrameEdges = sfeAround
inline SynLeftGutterPartList1: TSynGutterPartList
object SynGutterLineNumber1: TSynGutterLineNumber
- Width = 17
+ Width = 19
MouseActions = <>
MarkupInfo.Background = clBtnFace
MarkupInfo.Foreground = clNone
Index: resultdlg.pp
===================================================================
--- resultdlg.pp (revisione 46344)
+++ resultdlg.pp (copia locale)
@@ -93,11 +93,14 @@
end;
procedure TResultDlgForm.GraphStatBtnClick(Sender: TObject);
+var
+ mr: TModalResult;
begin
GraphStatForm := TGraphStatForm.Create(nil);
GraphStatForm.PoFamilyStats := Self.PoFamilyStats;
- GraphStatForm.ShowModal;
+ mr := GraphStatForm.ShowModal;
FreeAndNil(GraphStatForm);
+ if mr = mrOpenEditorFile then ModalResult:= mr; // To inform pocheckermain
end;
procedure TResultDlgForm.SaveBtnClick(Sender: TObject);
Index: pocheckermain.lfm
===================================================================
--- pocheckermain.lfm (revisione 46344)
+++ pocheckermain.lfm (copia locale)
@@ -8,6 +8,7 @@
ClientWidth = 581
OnCreate = FormCreate
OnDestroy = FormDestroy
+ ShowInTaskBar = stAlways
LCLVersion = '1.3'
Visible = True
object TestListBox: TCheckListBox
@@ -15,22 +16,23 @@
AnchorSideTop.Control = SelectTestLabel
AnchorSideTop.Side = asrBottom
Left = 201
- Height = 154
- Top = 29
+ Height = 152
+ Top = 31
Width = 373
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Top = 6
Enabled = False
ItemHeight = 0
TabOrder = 0
+ TopIndex = -1
end
object SelectTestLabel: TLabel
AnchorSideLeft.Control = OpenBtn
AnchorSideLeft.Side = asrBottom
Left = 201
- Height = 15
+ Height = 17
Top = 8
- Width = 93
+ Width = 135
BorderSpacing.Left = 9
Caption = 'Select test types'
Font.Style = [fsBold]
@@ -114,9 +116,9 @@
TabOrder = 3
object CurTestHeaderLabel: TLabel
Left = 8
- Height = 15
+ Height = 17
Top = 8
- Width = 68
+ Width = 90
Caption = 'Current Test:'
ParentColor = False
end
@@ -125,9 +127,9 @@
AnchorSideTop.Control = CurTestHeaderLabel
AnchorSideTop.Side = asrBottom
Left = 8
- Height = 15
- Top = 23
- Width = 81
+ Height = 17
+ Top = 25
+ Width = 103
Caption = 'Current po-file:'
ParentColor = False
end
@@ -136,10 +138,10 @@
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = CurTestHeaderLabel
AnchorSideTop.Side = asrCenter
- Left = 82
- Height = 15
+ Left = 104
+ Height = 17
Top = 8
- Width = 69
+ Width = 88
BorderSpacing.Around = 6
Caption = 'CurTestLabel'
ParentColor = False
@@ -149,10 +151,10 @@
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = CurPoHeaderLabel
AnchorSideTop.Side = asrCenter
- Left = 95
- Height = 15
- Top = 23
- Width = 61
+ Left = 117
+ Height = 17
+ Top = 25
+ Width = 76
BorderSpacing.Around = 6
Caption = 'CurPoLabel'
ParentColor = False
@@ -160,9 +162,9 @@
end
object NoErrLabel: TLabel
Left = 8
- Height = 25
- Top = 262
- Width = 146
+ Height = 23
+ Top = 264
+ Width = 172
Anchors = [akLeft, akBottom]
Caption = 'No errors found'
Font.Color = clGreen
@@ -176,9 +178,9 @@
AnchorSideTop.Control = SelectBasicBtn
AnchorSideTop.Side = asrBottom
Left = 201
- Height = 19
+ Height = 22
Top = 220
- Width = 156
+ Width = 197
BorderSpacing.Top = 6
Caption = 'Find all translated PO files'
TabOrder = 4
@@ -230,9 +232,9 @@
AnchorSideTop.Control = FindAllPOsCheckBox
AnchorSideTop.Side = asrBottom
Left = 201
- Height = 19
- Top = 245
- Width = 152
+ Height = 22
+ Top = 248
+ Width = 190
BorderSpacing.Top = 6
Caption = 'sIgnoreFuzzyTranslations'
TabOrder = 8
Index: pocheckermain.pp
===================================================================
--- pocheckermain.pp (revisione 46344)
+++ pocheckermain.pp (copia locale)
@@ -41,6 +41,7 @@
private
PoFamily: TPoFamily;
FSelectedPoName: String;
+ FNewRun: boolean;
FPoCheckerSettings: TPoCheckerSettings;
procedure OnTestStart(const ATestName, APoFileName: string);
procedure OnTestEnd(const ATestName: string; const ErrorCount: integer);
@@ -169,12 +170,15 @@
begin
SetSelectedPoName('');
end;
+ FNewRun:= False;
end;
procedure TPoCheckerForm.RunBtnClick(Sender: TObject);
begin
+ if FNewRun then TryCreatePoFamily(FSelectedPoName);
RunSelectedTests;
+ FNewRun:= True;
end;
procedure TPoCheckerForm.SelectAllBtnClick(Sender: TObject);
@@ -374,6 +378,7 @@
ErrorCount, WarningCount: integer;
SL: TStrings;
ResultDlg: TResultDlgForm;
+ mr: TModalResult;
begin
TestTypes := GetTestTypesFromListBox;
if (TestTypes = []) then
@@ -385,6 +390,7 @@
NoErrLabel.Visible := False;
Application.ProcessMessages;
SL := TStringList.Create;
+ mr := mrNone;
try
StatusPanel.Enabled := True;
if (not (ptoFindAllChildren in TestOptions)) and Assigned(PoFamily.Child) and
@@ -406,7 +412,7 @@
ResultDlg.PoFamilyStats := PoFamily.PoFamilyStats
else
ResultDlg.PoFamilyStats := nil;
- ResultDlg.ShowModal;
+ mr := ResultDlg.ShowModal;
finally
ResultDlg.Free;
end;
@@ -417,6 +423,7 @@
SL.Free;
ClearAndDisableStatusPanel;
end;
+ if mr = mrOpenEditorFile then WindowState:= wsMinimized;
end;
@@ -439,6 +446,7 @@
SelectBasicBtn.Enabled := True;
UnselectAllBtn.Enabled := True;
Caption := sGUIPoFileCheckingTool + ' [' + ExtractFileName(AFilename) + ']';
+ OpenDialog.InitialDir:= ExtractFileDir(AFilename);
end
else
begin
Index: pofamilies.pp
===================================================================
--- pofamilies.pp (revisione 46344)
+++ pofamilies.pp (copia locale)
@@ -68,7 +68,7 @@
procedure CheckMissingIdentifiers(out ErrorCount: Integer; ErrorLog: TStrings);
procedure CheckMismatchedOriginals(out ErrorCount: Integer; ErrorLog: TStrings);
procedure CheckDuplicateOriginals(out WarningCount: Integer; ErrorLog: TStrings);
- procedure CheckStatistics;
+ procedure CheckStatistics(ErrorCnt: Integer);
public
procedure RunTests(const TestTypes: TPoTestTypes; const TestOptions: TPoTestOptions;
@@ -92,17 +92,21 @@
TStat = class
private
FPoName: String;
+ FFullName: String;
FNrTotal: Integer;
FNrTranslated: Integer;
FNrUnTranslated: Integer;
FNrFuzzy: Integer;
+ FNrErrors: Integer;
public
- constructor Create(APoName: String; ANrTotal, ANrTranslated, ANrUntranslated, ANrFuzzy: Integer);
+ constructor Create(APoName,AFullName: String; ANrTotal, ANrTranslated, ANrUntranslated, ANrFuzzy,ANrErrors: Integer);
property PoName: string read FPoName;
+ property Name: string read FFullName;
property NrTotal: Integer read FNrTotal;
property NrTranslated: Integer read FNrTranslated;
property NrUnTranslated: Integer read FNrUnTranslated;
property NrFuzzy: Integer read FNrFuzzy;
+ property NrErrors: Integer read FNrErrors;
function PercTranslated: Double; inline;
function PercUnTranslated: Double; inline;
function PercFuzzy: Double; inline;
@@ -118,7 +122,7 @@
function GetItems(Index: Integer): TStat;
public
procedure Clear;
- procedure Add(AName: String; ANrTotal, ANrTranslated, ANrUnTranslated, ANrFuzzy: Integer);
+ procedure Add(AName,AFullName: String ;ANrTotal, ANrTranslated, ANrUnTranslated, ANrFuzzy,ANrErrors: Integer);
constructor Create;
destructor Destroy; override;
procedure AddStatisticsToLog(ALog: TStrings);
@@ -319,13 +323,15 @@
{ TStat }
-constructor TStat.Create(APoName: String; ANrTotal, ANrTranslated, ANrUntranslated, ANrFuzzy: Integer);
+constructor TStat.Create(APoName,AFullName: String; ANrTotal, ANrTranslated, ANrUntranslated, ANrFuzzy,ANrErrors: Integer);
begin
FPoName := APoName;
+ FFullName:= AFullName;
FNrTotal := ANrTotal;
FNrTranslated := ANrTranslated;
FNrUntranslated := ANrUntranslated;
FNrFuzzy := ANrFuzzy;
+ FNrErrors:= ANrErrors;
end;
function TStat.PercTranslated: Double;
@@ -375,9 +381,9 @@
FList.Clear;
end;
-procedure TPoFamilyStats.Add(AName: String; ANrTotal, ANrTranslated, ANrUnTranslated, ANrFuzzy: Integer);
+procedure TPoFamilyStats.Add(AName,AFullName: String; ANrTotal, ANrTranslated, ANrUnTranslated, ANrFuzzy,ANrErrors: Integer);
begin
- FList.Add(TStat.Create(AName, ANrTotal, ANrTranslated, ANrUntranslated, ANrFuzzy));
+ FList.Add(TStat.Create(AName, AFullName, ANrTotal, ANrTranslated, ANrUntranslated, ANrFuzzy,ANrErrors));
end;
constructor TPoFamilyStats.Create;
@@ -752,7 +758,7 @@
//debugln('TPoFamily.CheckDuplicateOriginals: ',Dbgs(WarningCount),' Errors');
end;
-procedure TPoFamily.CheckStatistics;
+procedure TPoFamily.CheckStatistics(ErrorCnt: Integer);
var
i: Integer;
CPoItem: TPOFileItem;
@@ -785,7 +791,7 @@
NrTotal := NrTranslated + NrUntranslated + NrFuzzy;
if (NrTotal > 0) then
begin
- FPoFamilyStats.Add(ShortChildName, NrTotal, NrTranslated, NrUntranslated, NrFuzzy);
+ FPoFamilyStats.Add(ShortChildName,ChildName, NrTotal, NrTranslated, NrUntranslated, NrFuzzy,ErrorCnt);
end;
DoTestEnd(PoTestTypeNames[pttCheckFormatArgs], 0);
//debugln('TPoFamily.CheckIncompatibleFormatArgs: ',Dbgs(ErrorCount),' Errors');
@@ -801,7 +807,7 @@
out ErrorCount, WarningCount: Integer; ErrorLog: TStrings);
var
SL: TStringList;
- CurrErrCnt, CurrWarnCnt: Integer;
+ CurrErrCnt, CurrWarnCnt,ThisErrCnt: Integer;
i: Integer;
CurrChildName: String;
S: String;
@@ -891,6 +897,7 @@
//then iterate all Children
for i := 0 to SL.Count - 1 do
begin
+ ThisErrCnt:= 0;
CurrChildName := SL.Strings[i];
//debugln('TPoFamily.RunTests: setting ChildName to ',CurrChildName);
SetChildName(CurrChildName);
@@ -899,12 +906,14 @@
begin
CheckNrOfItems(CurrErrCnt, ErrorLog);
ErrorCount := CurrErrCnt + ErrorCount;
+ ThisErrCnt := ThisErrCnt + CurrErrCnt;
end;
if (pttCheckFormatArgs in TestTypes) then
begin
CheckFormatArgs(CurrErrCnt, ErrorLog, (ptoIgnoreFuzzyStrings in TestOptions));
ErrorCount := CurrErrCnt + ErrorCount;
+ ThisErrCnt := ThisErrCnt + CurrErrCnt;
end;
@@ -912,19 +921,21 @@
begin
CheckMissingIdentifiers(CurrErrCnt, ErrorLog);
ErrorCount := CurrErrCnt + ErrorCount;
+ ThisErrCnt := ThisErrCnt + CurrErrCnt;
end;
if (pttCheckMismatchedOriginals in TestTypes) then
begin
CheckMismatchedOriginals(CurrErrCnt, ErrorLog);
ErrorCount := CurrErrCnt + ErrorCount;
+ ThisErrCnt := ThisErrCnt + CurrErrCnt;
end;
//Always run this as the last test please
if (pttCheckStatistics in TestTypes) then
begin
- CheckStatistics;
+ CheckStatistics(ThisErrCnt);
end;
{
if (ptt in TestTypes) then
Index: graphstat.lfm
===================================================================
--- graphstat.lfm (revisione 46344)
+++ graphstat.lfm (copia locale)
@@ -41,25 +41,25 @@
end
object TranslatedLabel: TLabel
Left = 104
- Height = 15
+ Height = 17
Top = 17
- Width = 100
+ Width = 105
Caption = 'TranslatedLabel'
ParentColor = False
end
object UnTranslatedLabel: TLabel
Left = 104
- Height = 15
+ Height = 17
Top = 36
- Width = 118
+ Width = 122
Caption = 'UnTranslatedLabel'
ParentColor = False
end
object FuzzyLabel: TLabel
Left = 104
- Height = 15
+ Height = 17
Top = 55
- Width = 70
+ Width = 75
Caption = 'FuzzyLabel'
ParentColor = False
end
@@ -79,5 +79,6 @@
TabOrder = 1
ViewStyle = vsIcon
OnMouseMove = ListViewMouseMove
+ OnMouseUp = ListViewMouseUp
end
end
Index: graphstat.pp
===================================================================
--- graphstat.pp (revisione 46344)
+++ graphstat.pp (copia locale)
@@ -6,6 +6,7 @@
uses
Classes, SysUtils, Types, FileUtil, Forms, Controls, Graphics, Dialogs,
+ {$ifndef POCHECKERSTANDALONE} LazIDEIntf, {$endif}
ExtCtrls, PoFamilies, PoCheckerConsts, LCLProc, StdCtrls, ComCtrls;
@@ -32,6 +33,8 @@
procedure FormShow(Sender: TObject);
procedure ListViewMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
+ procedure ListViewMouseUp(Sender: TObject; Button: TMouseButton;
+ Shift: TShiftState; X, Y: Integer);
private
{ private declarations }
FPoFamilyStats: TPoFamilyStats;
@@ -99,7 +102,7 @@
AStat := FPoFamilyStats.Items[Index];
ListView.Hint := Format(sStatHint,[AStat.NrTranslated, AStat.PercTranslated,
AStat.NrUnTranslated, AStat.PercUnTranslated,
- AStat.NrFuzzy, AStat.PercFuzzy]);
+ AStat.NrFuzzy, AStat.PercFuzzy,AStat.NrErrors]);
end
else
begin
@@ -109,7 +112,41 @@
end;
+procedure TGraphStatForm.ListViewMouseUp(Sender: TObject; Button: TMouseButton;
+ Shift: TShiftState; X, Y: Integer);
+{$ifndef POCHECKERSTANDALONE}
+var
+ anItem: TListItem;
+ anIndex: Integer;
+ AStat: TStat;
+ PageIndex,WindowIndex: Integer;
+ OpenFlags: TOpenFlags;
+ mr: TModalResult;
+{$endif}
+begin
+ {$ifndef POCHECKERSTANDALONE}
+ anItem := Listview.GetItemAt(X, Y);
+ if Assigned(anItem) then begin
+ anIndex := anItem.Index;
+ AStat := FPoFamilyStats.Items[anIndex];
+ PageIndex:= -1;
+ WindowIndex:= -1;
+ OpenFlags:= [ofOnlyIfExists,ofAddToRecent,ofRegularFile,ofConvertMacros];
+ mr := LazarusIde.DoOpenEditorFile(AStat.Name,PageIndex,WindowIndex,OpenFlags);
+ if mr = mrOk then begin
+ if MessageDlg('PoChecker',Format(sOpenFile,[AStat.PoName]),
+ mtConfirmation,mbOKCancel,0) = mrOk then begin
+ ModalResult:= mrOpenEditorFile; //To let caller know what we want to do
+ end;
+ end
+ else ShowMessage(Format(SOpenFail,[AStat.Name]));
+ end;
+ {$else}
+ Exit;
+ {$endif}
+end;
+
procedure TGraphStatForm.FormCreate(Sender: TObject);
begin
Caption := sGrapStatFormCaption;
@@ -143,13 +180,16 @@
function TGraphStatForm.CreateBitmap(AStat: TStat): TBitmap;
const
FullCircle = 16 * 360;
+ QMark = ' ? ';
var
Bmp: TBitmap;
Translated16Angle, UnTranslated16Angle, Fuzzy16Angle: Integer;
PieRect: TRect;
+ TextSize: TSize;
begin
Bmp := TBitmap.Create;
Bmp.SetSize(BmpWH,BmpWH);
+ Bmp.Canvas.AntialiasingMode:= amOn; // currently effective only with Qt
PieRect := Rect(0,0,BmpWH, BmpWH);
with Bmp do
begin
@@ -188,6 +228,17 @@
else
Canvas.RadialPie(PieRect.Left,PieRect.Top,PieRect.Right,PieRect.Bottom,Translated16Angle+UnTranslated16Angle,Fuzzy16Angle);
end;
+ if AStat.NrErrors <> 0 then begin
+ Bmp.Canvas.Font := Font;
+ Canvas.Font.Size := BmpWH div 6;
+ Canvas.Font.Style:= [fsBold];
+ Canvas.Font.Color:= clRed;
+ TextSize := Bmp.Canvas.TextExtent(QMark);
+ Canvas.Brush.Color:= clBlack;
+ Canvas.Rectangle(0,PieRect.Bottom-TextSize.cy-4,TextSize.cx+4,PieRect.Bottom);
+ Canvas.Brush.Color:= clYellow;
+ Canvas.TextOut(2,PieRect.Bottom-TextSize.cy-2,QMark);
+ end;
end;
Result := Bmp;
end;
--
_______________________________________________
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus