Converter: cache unit paths using OnIdle handler.

git-svn-id: trunk@27384 -
This commit is contained in:
juha 2010-09-16 12:18:59 +00:00
parent 40bf83e108
commit 8e3631c047
3 changed files with 61 additions and 35 deletions

View File

@ -138,6 +138,8 @@ type
// Units that are found and will be added to project and converted.
fUnitsToAddToProject: TStringList;
fSettings: TConvertSettings;
fDoneScan: Boolean;
procedure OnIdle(Sender: TObject; var Done: Boolean);
function ConvertSub: TModalResult;
procedure CleanUpCompilerOptionsSearchPaths(Options: TBaseCompilerOptions);
procedure SetCompilerModeForDefineTempl(DefTempl: TDefineTemplate);
@ -519,7 +521,7 @@ begin
end;
// Create a form file name based on the unit file name.
LfmFilename:=fSettings.DelphiToLazFilename(fOrigUnitFilename, '.lfm',
cdtlufRenameLowercase in fFlags);
cdtlufRenameLowercase in fFlags);
if DfmFilename<>'' then begin
if FileExistsUTF8(LfmFilename) then
if (FileAgeUTF8(LfmFilename)<FileAgeUTF8(DfmFilename)) then
@ -871,8 +873,6 @@ begin
fAllMissingUnits.Sorted:=true;
fUnitsToAddToProject:=TStringList.Create;
fPrevSelectedPath:=fSettings.MainPath;
// Scan unit files a level above project path. Used later for missing units.
CacheUnitsInPath(TrimFilename(fSettings.MainPath+'../'));
end;
destructor TConvertDelphiPBase.Destroy;
@ -885,13 +885,24 @@ begin
inherited Destroy;
end;
procedure TConvertDelphiPBase.OnIdle(Sender: TObject; var Done: Boolean);
begin
if not fDoneScan then begin
CacheUnitsInPath(TrimFilename(fSettings.MainPath+'../'));
fDoneScan:=True;
end;
Done:=True;
end;
// Creates or updates a lazarus project (.lpi+.lpr) or package.
function TConvertDelphiPBase.Convert: TModalResult;
begin
IDEMessagesWindow.Clear;
Application.AddOnIdleHandler(@OnIdle, False);
// Get settings from user.
Result:=fSettings.RunForm;
if Result=mrOK then begin
Application.RemoveOnIdleHandler(@OnIdle);
if (Result=mrOK) and fDoneScan then begin
// create/open lazarus project or package file
fLazPFilename:=fSettings.DelphiToLazFilename(fOrigPFilename, fLazPSuffix, false);

View File

@ -15,7 +15,7 @@ object ConvertSettingsForm: TConvertSettingsForm
object MissingStuffGroupBox: TGroupBox
AnchorSideTop.Control = SettingsGroupBox
AnchorSideTop.Side = asrBottom
AnchorSideBottom.Control = ButtonPanel
AnchorSideBottom.Control = ButtonPanel1
Left = 0
Height = 213
Top = 219
@ -237,7 +237,7 @@ object ConvertSettingsForm: TConvertSettingsForm
State = cbChecked
TabOrder = 3
end
object ButtonPanel: TButtonPanel
object ButtonPanel1: TButtonPanel
Left = 6
Height = 39
Top = 438

View File

@ -39,16 +39,20 @@ type
TConvertTarget = (ctLazarus, ctLazarusWin, ctLazarusAndDelphi);
TConvertSettingsForm = class;
{ TConvertSettings }
TConvertSettings = class
private
fEnabled: Boolean;
fTitle: String; // Used for form caption.
// Unit, Project or Package top file and path.
fMainFilename: String;
fMainPath: String;
// Persistent storage in XML or some other format.
fConfigStorage: TConfigStorage;
fSettingsForm: TConvertSettingsForm;
// Actual user settings.
fBackupFiles: boolean;
fTarget: TConvertTarget;
@ -67,6 +71,7 @@ type
fVisualOffsets: TVisualOffsets;
// Getter / setter:
function GetBackupPath: String;
procedure SetEnabled(const AValue: Boolean);
procedure SetMainFilename(const AValue: String);
public
constructor Create(const ATitle: string);
@ -92,6 +97,7 @@ type
property MainFilename: String read fMainFilename write SetMainFilename;
property MainPath: String read fMainPath;
property BackupPath: String read GetBackupPath;
property Enabled: Boolean read fEnabled write SetEnabled;
property BackupFiles: boolean read fBackupFiles;
property Target: TConvertTarget read fTarget;
@ -113,7 +119,7 @@ type
PropRemoveAutoCheckBox: TCheckBox;
UnitReplaceAutoCheckBox: TCheckBox;
BackupCheckBox: TCheckBox;
ButtonPanel: TButtonPanel;
ButtonPanel1: TButtonPanel;
FuncReplaceEnableCheckBox: TCheckBox;
VisualOffsEnableCheckBox: TCheckBox;
Label1: TLabel;
@ -336,6 +342,8 @@ begin
fTitle:=ATitle;
fMainFilename:='';
fMainPath:='';
fEnabled:=True;
fSettingsForm:=Nil;
fReplaceUnits:=TStringToStringTree.Create(false);
fReplaceTypes:=TStringToStringTree.Create(false);
fReplaceFuncs:=TFuncsAndCategories.Create;
@ -469,35 +477,34 @@ begin
end;
function TConvertSettings.RunForm: TModalResult;
var
SettingsForm: TConvertSettingsForm;
begin
SettingsForm:=TConvertSettingsForm.Create(nil, Self);
with SettingsForm do
fSettingsForm:=TConvertSettingsForm.Create(nil, Self);
try
Caption:=fTitle;
ProjectPathEdit.Text:=fMainPath;
// Settings --> UI. Loaded from ConfigSettings earlier.
BackupCheckBox.Checked :=fBackupFiles;
TargetRadioGroup.ItemIndex :=integer(fTarget);
SameDFMCheckBox.Checked :=fSameDFMFile;
PropRemoveAutoCheckBox.Checked :=fAutoRemoveProperties;
UnitReplaceAutoCheckBox.Checked :=fAutoReplaceUnits;
FuncReplaceEnableCheckBox.Checked:=fEnableReplaceFuncs;
VisualOffsEnableCheckBox.Checked :=fEnableVisualOffs;
Result:=ShowModal; // Let the user change settings in a form.
if Result=mrOK then begin
// UI --> Settings. Will be saved to ConfigSettings later.
fBackupFiles :=BackupCheckBox.Checked;
fTarget :=TConvertTarget(TargetRadioGroup.ItemIndex);
fSameDFMFile :=SameDFMCheckBox.Checked;
fAutoRemoveProperties:=PropRemoveAutoCheckBox.Checked;
fAutoReplaceUnits :=UnitReplaceAutoCheckBox.Checked;
fEnableReplaceFuncs :=FuncReplaceEnableCheckBox.Checked;
fEnableVisualOffs :=VisualOffsEnableCheckBox.Checked;
with fSettingsForm do begin
Caption:=fTitle;
ProjectPathEdit.Text:=fMainPath;
// Settings --> UI. Loaded from ConfigSettings earlier.
BackupCheckBox.Checked :=fBackupFiles;
TargetRadioGroup.ItemIndex :=integer(fTarget);
SameDFMCheckBox.Checked :=fSameDFMFile;
PropRemoveAutoCheckBox.Checked :=fAutoRemoveProperties;
UnitReplaceAutoCheckBox.Checked :=fAutoReplaceUnits;
FuncReplaceEnableCheckBox.Checked:=fEnableReplaceFuncs;
VisualOffsEnableCheckBox.Checked :=fEnableVisualOffs;
Result:=ShowModal; // Let the user change settings in a form.
if Result=mrOK then begin
// UI --> Settings. Will be saved to ConfigSettings later.
fBackupFiles :=BackupCheckBox.Checked;
fTarget :=TConvertTarget(TargetRadioGroup.ItemIndex);
fSameDFMFile :=SameDFMCheckBox.Checked;
fAutoRemoveProperties:=PropRemoveAutoCheckBox.Checked;
fAutoReplaceUnits :=UnitReplaceAutoCheckBox.Checked;
fEnableReplaceFuncs :=FuncReplaceEnableCheckBox.Checked;
fEnableVisualOffs :=VisualOffsEnableCheckBox.Checked;
end;
end;
finally
Free;
FreeAndNil(fSettingsForm);
end;
end;
@ -587,6 +594,14 @@ begin
end;
end;
procedure TConvertSettings.SetEnabled(const AValue: Boolean);
begin
if fEnabled=AValue then exit;
fEnabled:=AValue;
if Assigned(fSettingsForm) then
fSettingsForm.ButtonPanel1.Enabled:=fEnabled; // OKButton
end;
{ TConvertSettingsForm }
@ -610,9 +625,9 @@ begin
BackupCheckBox.Caption:=lisBackupChangedFiles;
BackupCheckBox.Hint:=lisBackupHint;
ButtonPanel.OKButton.Caption:=lisStartConversion;
ButtonPanel.HelpButton.Caption:=lisMenuHelp;
ButtonPanel.CancelButton.Caption:=dlgCancel;
ButtonPanel1.OKButton.Caption:=lisStartConversion;
ButtonPanel1.HelpButton.Caption:=lisMenuHelp;
ButtonPanel1.CancelButton.Caption:=dlgCancel;
SameDFMCheckBox.Caption:=lisConvUseSameDFM;
SameDFMCheckBox.Hint:=lisConvUseSameDFMHint;