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. // Units that are found and will be added to project and converted.
fUnitsToAddToProject: TStringList; fUnitsToAddToProject: TStringList;
fSettings: TConvertSettings; fSettings: TConvertSettings;
fDoneScan: Boolean;
procedure OnIdle(Sender: TObject; var Done: Boolean);
function ConvertSub: TModalResult; function ConvertSub: TModalResult;
procedure CleanUpCompilerOptionsSearchPaths(Options: TBaseCompilerOptions); procedure CleanUpCompilerOptionsSearchPaths(Options: TBaseCompilerOptions);
procedure SetCompilerModeForDefineTempl(DefTempl: TDefineTemplate); procedure SetCompilerModeForDefineTempl(DefTempl: TDefineTemplate);
@ -871,8 +873,6 @@ begin
fAllMissingUnits.Sorted:=true; fAllMissingUnits.Sorted:=true;
fUnitsToAddToProject:=TStringList.Create; fUnitsToAddToProject:=TStringList.Create;
fPrevSelectedPath:=fSettings.MainPath; fPrevSelectedPath:=fSettings.MainPath;
// Scan unit files a level above project path. Used later for missing units.
CacheUnitsInPath(TrimFilename(fSettings.MainPath+'../'));
end; end;
destructor TConvertDelphiPBase.Destroy; destructor TConvertDelphiPBase.Destroy;
@ -885,13 +885,24 @@ begin
inherited Destroy; inherited Destroy;
end; 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. // Creates or updates a lazarus project (.lpi+.lpr) or package.
function TConvertDelphiPBase.Convert: TModalResult; function TConvertDelphiPBase.Convert: TModalResult;
begin begin
IDEMessagesWindow.Clear; IDEMessagesWindow.Clear;
Application.AddOnIdleHandler(@OnIdle, False);
// Get settings from user. // Get settings from user.
Result:=fSettings.RunForm; 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 // create/open lazarus project or package file
fLazPFilename:=fSettings.DelphiToLazFilename(fOrigPFilename, fLazPSuffix, false); fLazPFilename:=fSettings.DelphiToLazFilename(fOrigPFilename, fLazPSuffix, false);

View File

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

View File

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