PoChecker: reload last used file on start.

git-svn-id: trunk@46274 -
This commit is contained in:
bart 2014-09-21 16:53:18 +00:00
parent 12755f715c
commit cd5a2ec6c4
2 changed files with 119 additions and 71 deletions

View File

@ -40,8 +40,7 @@ type
TPoCheckerForm = class(TForm) TPoCheckerForm = class(TForm)
private private
PoFamily: TPoFamily; PoFamily: TPoFamily;
FChosenMasterName: string; FSelectedPoName: String;
FChosenChildName: string;
FPoCheckerSettings: TPoCheckerSettings; FPoCheckerSettings: TPoCheckerSettings;
procedure OnTestStart(const ATestName, APoFileName: string); procedure OnTestStart(const ATestName, APoFileName: string);
procedure OnTestEnd(const ATestName: string; const ErrorCount: integer); procedure OnTestEnd(const ATestName: string; const ErrorCount: integer);
@ -51,9 +50,11 @@ type
procedure SetTestTypeCheckBoxes(TestTypes: TPoTestTypes); procedure SetTestTypeCheckBoxes(TestTypes: TPoTestTypes);
procedure SetTestOptionCheckBoxes(TestOptions: TPoTestOptions); procedure SetTestOptionCheckBoxes(TestOptions: TPoTestOptions);
procedure ShowError(const Msg: string); procedure ShowError(const Msg: string);
function TrySelectFile: boolean; function TrySelectFile(out Filename: String): Boolean;
function TryCreatePoFamily(Filename: String): Boolean;
procedure RunSelectedTests; procedure RunSelectedTests;
procedure ClearAndDisableStatusPanel; procedure ClearAndDisableStatusPanel;
procedure SetSelectedPoName(AFilename: String);
published published
IgnoreFuzzyCheckBox: TCheckBox; IgnoreFuzzyCheckBox: TCheckBox;
UnselectAllBtn: TButton; UnselectAllBtn: TButton;
@ -148,7 +149,14 @@ begin
//DebugLn(' ',DbgS(FPoCheckerSettings.TestTypes)); //DebugLn(' ',DbgS(FPoCheckerSettings.TestTypes));
SetTestTypeCheckBoxes(FPoCheckerSettings.TestTypes); SetTestTypeCheckBoxes(FPoCheckerSettings.TestTypes);
SetTestOptionCheckBoxes(FPoCheckerSettings.TestOptions); SetTestOptionCheckBoxes(FPoCheckerSettings.TestOptions);
if (FPoCheckerSettings.LastSelectedFile <> '') then
begin
//debugln('Trying to load ',FPoCheckerSettings.LastSelectedFile);
if TryCreatePoFamily(FPoCheckerSettings.LastSelectedFile) then
SetSelectedPoName(FPoCheckerSettings.LastSelectedFile)
else
SetSelectedPoName('');
end;
end; end;
@ -159,6 +167,7 @@ begin
if Assigned(FPoCheckerSettings) then if Assigned(FPoCheckerSettings) then
begin begin
FPoCheckerSettings.SaveSettingsOnExit := True; //ToDo: create a checkbox for this FPoCheckerSettings.SaveSettingsOnExit := True; //ToDo: create a checkbox for this
FPoCheckerSettings.LastSelectedFile := FSelectedPoName;
FPoCheckerSettings.TestTypes := GetTestTypesFromListBox; FPoCheckerSettings.TestTypes := GetTestTypesFromListBox;
FPoCheckerSettings.TestOptions := GetTestOptions; FPoCheckerSettings.TestOptions := GetTestOptions;
FPoCheckerSettings.SaveConfig; FPoCheckerSettings.SaveConfig;
@ -168,22 +177,16 @@ end;
procedure TPoCheckerForm.OpenBtnClick(Sender: TObject); procedure TPoCheckerForm.OpenBtnClick(Sender: TObject);
var
Fn: String;
begin begin
if TrySelectFile then if TrySelectFile(Fn) then
begin begin
RunBtn.Enabled := True; SetSelectedPoName(Fn);
TestListBox.Enabled := True;
SelectAllBtn.Enabled := True;
SelectBasicBtn.Enabled := True;
UnselectAllBtn.Enabled := True;
end end
else else
begin begin
RunBtn.Enabled := False; SetSelectedPoName('');
TestListBox.Enabled := False;
SelectAllBtn.Enabled := False;
SelectBasicBtn.Enabled := False;
UnselectAllBtn.Enabled := False;
end; end;
end; end;
@ -310,72 +313,76 @@ begin
end; end;
function TPoCheckerForm.TrySelectFile: boolean; function TPoCheckerForm.TrySelectFile(out Filename: String): boolean;
var
Fn: string;
ShortFn: string;
OK: boolean;
begin begin
NoErrLabel.Visible := False; NoErrLabel.Visible := False;
OK := False; Result := False;
Filename := '';
if OpenDialog.Execute then if OpenDialog.Execute then
begin begin
Fn := OpenDialog.FileName; Filename := OpenDialog.FileName;
ShortFn := ExtractFileName(Fn); Result := TryCreatePoFamily(Filename);
if IsMasterPoName(Fn) then end;
end;
function TPoCheckerForm.TryCreatePoFamily(Filename: String): Boolean;
var
ChosenMasterName, ChosenChildName, ShortFn: String;
begin
Result := False;
ShortFn := ExtractFileName(Filename);
if IsMasterPoName(Filename) then
begin
ChosenMasterName := Filename;
ChosenChildName := '';
end
else
begin //not a mastername, may be a child
ChosenChildName := Filename;
ChosenMasterName := ExtractMasterNameFromChildName(Filename);
if (ChosenMasterName = '') then
begin begin
FChosenMasterName := Fn; ChosenMasterName := '';
FChosenChildName := ''; ChosenChildName := '';
ShowError(Format(sNotAProperFileName, [ShortFn]));
end end
else else
begin //not a mastername, may be a child if not FileExistsUtf8(ChosenMasterName) then
FChosenChildName := Fn;
FChosenMasterName := ExtractMasterNameFromChildName(Fn);
if (FChosenMasterName = '') then
begin
FChosenMasterName := '';
FChosenChildName := '';
ShowError(Format(sNotAProperFileName, [ShortFn]));
end
else
if not FileExistsUtf8(FChosenMasterName) then
begin
ShowError(Format(sCannotFindMaster,
[ExtractFileName(FChosenMasterName), ShortFn]));
FChosenMasterName := '';
FChosenChildName := '';
end;
end;
OK := (FChosenMasterName <> '');
if OK then
begin begin
if Assigned(PoFamily) then ShowError(Format(sCannotFindMaster,
PoFamily.Free; [ExtractFileName(ChosenMasterName), ShortFn]));
try ChosenMasterName := '';
PoFamily := TPoFamily.Create(FChosenMasterName, FChosenChildName); ChosenChildName := '';
PoFamily.OnTestStart := @OnTestStart; end;
PoFamily.OnTestEnd := @OnTestEnd; end;
except Result := (ChosenMasterName <> '');
on E: Exception do if Result then
begin
if Assigned(PoFamily) then
PoFamily.Free;
try
PoFamily := TPoFamily.Create(ChosenMasterName, ChosenChildName);
PoFamily.OnTestStart := @OnTestStart;
PoFamily.OnTestEnd := @OnTestEnd;
except
on E: Exception do
begin
Result := False;
ShowError(Format(sErrorOnCreate, [E.Message]));
if Assigned(PoFamily) then
begin begin
OK := False; try
ShowError(Format(sErrorOnCreate, [E.Message])); PoFamily.Free;
if Assigned(PoFamily) then except
begin on E: Exception do
try begin
PoFamily.Free; ShowError(Format(sErrorOnCleanUp, [E.Message]));
except
on E: Exception do
begin
ShowError(Format(sErrorOnCleanUp, [E.Message]));
end;
end; end;
end; end;
end; end;
end; end;
end; end;
end; end;
Result := OK;
end; end;
@ -400,8 +407,8 @@ begin
try try
StatusPanel.Enabled := True; StatusPanel.Enabled := True;
if (not (ptoFindAllChildren in TestOptions)) and Assigned(PoFamily.Child) and if (not (ptoFindAllChildren in TestOptions)) and Assigned(PoFamily.Child) and
(PoFamily.ChildName <> FChosenChildName) then (PoFamily.ChildName <> FSelectedPoName) then
PoFamily.ChildName := FChosenChildName; PoFamily.ChildName := FSelectedPoName;
PoFamily.RunTests(TestTypes, TestOptions, ErrorCount, WarningCount, SL); PoFamily.RunTests(TestTypes, TestOptions, ErrorCount, WarningCount, SL);
debugln('RunSelectedTests: ', Format(sTotalErrors, [ErrorCount])); debugln('RunSelectedTests: ', Format(sTotalErrors, [ErrorCount]));
debugln(' ', Format(sTotalWarnings, [WarningCount])); debugln(' ', Format(sTotalWarnings, [WarningCount]));
@ -439,6 +446,30 @@ begin
StatusPanel.Enabled := False; StatusPanel.Enabled := False;
end; end;
procedure TPoCheckerForm.SetSelectedPoName(AFilename: String);
begin
if (FSelectedPoName = AFilename) then Exit;
FSelectedPoName := AFilename;
if (AFilename <> '') then
begin
RunBtn.Enabled := True;
TestListBox.Enabled := True;
SelectAllBtn.Enabled := True;
SelectBasicBtn.Enabled := True;
UnselectAllBtn.Enabled := True;
Caption := sGUIPoFileCheckingTool + ' [' + ExtractFileName(AFilename) + ']';
end
else
begin
RunBtn.Enabled := False;
TestListBox.Enabled := False;
SelectAllBtn.Enabled := False;
SelectBasicBtn.Enabled := False;
UnselectAllBtn.Enabled := False;
Caption := sGUIPoFileCheckingTool;
end;
end;
function SameItem(Item1, Item2: TPoFileItem): boolean; function SameItem(Item1, Item2: TPoFileItem): boolean;
begin begin

View File

@ -27,10 +27,13 @@ type
FSaveSettingsOnExit: Boolean; FSaveSettingsOnExit: Boolean;
FMasterPoList: TStrings; FMasterPoList: TStrings;
FChildrenPoList: TStrings; FChildrenPoList: TStrings;
FLastSelectedFile: String;
function LoadLastSelectedFile: String;
function LoadTestTypes: TPoTestTypes; function LoadTestTypes: TPoTestTypes;
function LoadTestOptions: TPoTestOptions; function LoadTestOptions: TPoTestOptions;
procedure LoadMasterPoList(List: TStrings); procedure LoadMasterPoList(List: TStrings);
procedure LoadChildrenPoList(List: TStrings); procedure LoadChildrenPoList(List: TStrings);
procedure SaveLastSelectedFile;
procedure SaveTestTypes; procedure SaveTestTypes;
procedure SaveTestOptions; procedure SaveTestOptions;
procedure SaveMasterPoList; procedure SaveMasterPoList;
@ -49,6 +52,7 @@ type
property TestOptions: TPoTestOptions read FTestOptions write FTestOptions; property TestOptions: TPoTestOptions read FTestOptions write FTestOptions;
property MasterPoList: TStrings read FMasterPoList write FMasterPoList; property MasterPoList: TStrings read FMasterPoList write FMasterPoList;
property ChildrenPoList: TStrings read FChildrenPoList write FChildrenPoList; property ChildrenPoList: TStrings read FChildrenPoList write FChildrenPoList;
property LastSelectedFile: String read FLastSelectedFile write FLastSelectedFile;
end; end;
function DbgS(PoTestTypes: TPoTestTypes): String; overload; function DbgS(PoTestTypes: TPoTestTypes): String; overload;
@ -107,10 +111,11 @@ const
); );
pLoadSettings = 'General/LoadSettings/'; pLoadSettings = 'General/LoadSettings/';
pLastSelected = 'LastSelected/';
pTestTypes = 'TestTypes/'; pTestTypes = 'TestTypes/';
pTestOptions = 'TestOptions/'; pTestOptions = 'TestOptions/';
pMasterPoFiles = 'MasterPoFiles'; pMasterPoFiles = 'MasterPoFiles/';
pChildrenPoFiles = 'ChildrenPoFiles'; pChildrenPoFiles = 'ChildrenPoFiles/';
function DbgS(PoTestTypes: TPoTestTypes): String; overload; function DbgS(PoTestTypes: TPoTestTypes): String; overload;
var var
@ -138,6 +143,11 @@ begin
Result := Result + ']'; Result := Result + ']';
end; end;
function TPoCheckerSettings.LoadLastSelectedFile: String;
begin
Result := FConfig.GetValue(pLastSelected+'Value','');
end;
function TPoCheckerSettings.LoadTestTypes: TPoTestTypes; function TPoCheckerSettings.LoadTestTypes: TPoTestTypes;
var var
tt: TPoTestType; tt: TPoTestType;
@ -180,6 +190,11 @@ begin
List.Clear; List.Clear;
end; end;
procedure TPoCheckerSettings.SaveLastSelectedFile;
begin
FConfig.SetDeleteValue(pLastSelected+'Value',FLastSelectedFile,'');
end;
procedure TPoCheckerSettings.SaveTestTypes; procedure TPoCheckerSettings.SaveTestTypes;
var var
tt: TPoTestType; tt: TPoTestType;
@ -233,7 +248,7 @@ begin
FFilename := 'pochecker.xml'; FFilename := 'pochecker.xml';
FConfig := GetIDEConfigStorage(FFilename, True); FConfig := GetIDEConfigStorage(FFilename, True);
{$endif} {$endif}
DebugLn('TPoCheckerSettings.Create: FConfig = ',DbgSName(FConfig)); //DebugLn('TPoCheckerSettings.Create: FConfig = ',DbgSName(FConfig));
except except
Debugln('PoCheckerSettings.Create: failed to create ConfigStorage:'); Debugln('PoCheckerSettings.Create: failed to create ConfigStorage:');
Debugln(' - Filename = ',FFilename); Debugln(' - Filename = ',FFilename);
@ -255,6 +270,7 @@ begin
begin begin
FTestTypes := LoadTestTypes; FTestTypes := LoadTestTypes;
FTestOptions := LoadTestOptions; FTestOptions := LoadTestOptions;
FLastSelectedFile := LoadLastSelectedFile;
LoadMasterPoList(FMasterPoList); LoadMasterPoList(FMasterPoList);
LoadChildrenPoList(FChildrenPoList); LoadChildrenPoList(FChildrenPoList);
end; end;
@ -272,6 +288,7 @@ begin
FConfig.SetValue(pLoadSettings+'Value',FSaveSettingsOnExit); FConfig.SetValue(pLoadSettings+'Value',FSaveSettingsOnExit);
if FSaveSettingsOnExit then if FSaveSettingsOnExit then
begin begin
SaveLastSelectedFile;
SaveTestTypes; SaveTestTypes;
SaveTestOptions; SaveTestOptions;
SaveMasterPoList; SaveMasterPoList;