Converter: show settings dialog only once when converting many unit files. Improve settings GUI.

git-svn-id: trunk@41735 -
This commit is contained in:
juha 2013-06-16 23:42:42 +00:00
parent 96e7696f47
commit d4936c7bdc
4 changed files with 258 additions and 258 deletions

View File

@ -120,8 +120,6 @@ type
// wrapping either one unit or whole project / package conversion.
TConvertDelphiPBase = class
private
// Original unit's, project's or package's file name, .pas .lpi .lpk .dpr .dpk
fOrigFilename: string;
fSettings: TConvertSettings;
fErrorMsg: string;
// IsConsoleApp is only updated for TConvertDelphiProjPack.
@ -139,6 +137,7 @@ type
protected
function EndConvert(AStatus: TModalResult): Boolean;
public
constructor Create(const ADescription: string);
constructor Create(const AFilename, ADescription: string);
destructor Destroy; override;
public
@ -152,7 +151,7 @@ type
private
DirectoryTemplate: TDefineTemplate;
public
constructor Create(const AFilename: string);
constructor Create(aFiles: TStrings);
destructor Destroy; override;
function Convert: TModalResult;
end;
@ -822,14 +821,18 @@ end;
{ TConvertDelphiPBase }
constructor TConvertDelphiPBase.Create(const AFilename, ADescription: string);
constructor TConvertDelphiPBase.Create(const ADescription: string);
begin
inherited Create;
fOrigFilename:=AFilename;
fSettings:=TConvertSettings.Create(ADescription);
fSettings.MainFilename:=fOrigFilename;
fIsConsoleApp:=False; // Default = GUI app.
fPrevSelectedPath:=fSettings.MainPath;
end;
constructor TConvertDelphiPBase.Create(const AFilename, ADescription: string);
begin
Create(ADescription);
fSettings.MainFilenames.Add(AFilename);
fPrevSelectedPath:=AFilename;
end;
destructor TConvertDelphiPBase.Destroy;
@ -866,12 +869,21 @@ end;
{ TConvertDelphiUnit }
constructor TConvertDelphiUnit.Create(const AFilename: string);
constructor TConvertDelphiUnit.Create(aFiles: TStrings);
var
MacroName, s: String;
i: Integer;
begin
inherited Create(AFilename, lisConvDelphiConvertDelphiUnit);
inherited Create(lisConvDelphiConvertDelphiUnit);
// Add the list of files if they exist.
for i := 0 to aFiles.Count-1 do begin
s:=CleanAndExpandFilename(aFiles[i]);
if FileExistsUTF8(s) then begin
fSettings.MainFilenames.Add(s);
if (i=0) and (fPrevSelectedPath='') then
fPrevSelectedPath:=s;
end;
end;
// use a template for compiler mode delphi for a single directory
DirectoryTemplate:=TDefineTemplate.Create('Delphi unit conversion',
'Mode Delphi for single unit conversion', '', fSettings.MainPath, da_Directory);
@ -890,36 +902,45 @@ end;
function TConvertDelphiUnit.Convert: TModalResult;
var
DelphiUnit: TDelphiUnit;
i: Integer;
begin
DelphiUnit := TDelphiUnit.Create(Self, fOrigFilename, []);
try
Result:=fSettings.RunForm(Nil);
if Result=mrOK then begin
Result:=fSettings.RunForm(Nil);
if Result=mrOK then begin
try
try
fSettings.ClearLog;
with DelphiUnit do
try
Result:=CopyAndLoadFile;
if Result<>mrOK then Exit;
Result:=ConvertUnitFile;
if Result<>mrOK then Exit;
Result:=SaveCodeBufferToFile(fPascalBuffer,fLazUnitFilename);
if Result<>mrOK then Exit;
Result:=ConvertFormFile;
if Result<>mrOK then Exit;
Result:=LazarusIDE.DoSaveEditorFile(fLazUnitFilename,[]);
except
on e: EDelphiConverterError do begin
fErrorMsg:=e.Message;
for i:=0 to fSettings.MainFilenames.Count-1 do begin
Application.ProcessMessages;
if i>0 then
fSettings.AddLogLine('');
DelphiUnit := TDelphiUnit.Create(Self, fSettings.MainFilenames[i], []);
with DelphiUnit do
try
Result:=CopyAndLoadFile;
if Result<>mrOK then Exit;
Result:=ConvertUnitFile;
if Result<>mrOK then Exit;
Result:=SaveCodeBufferToFile(fPascalBuffer,fLazUnitFilename);
if Result<>mrOK then Exit;
Result:=ConvertFormFile;
if Result<>mrOK then Exit;
Result:=LazarusIDE.DoSaveEditorFile(fLazUnitFilename,[]);
finally
DelphiUnit.Free;
end;
else begin
fErrorMsg:=CodeToolBoss.ErrorMessage;
end;
Result:=mrAbort;
end;
except
on e: EDelphiConverterError do begin
fErrorMsg:=e.Message;
end;
else begin
fErrorMsg:=CodeToolBoss.ErrorMessage;
end;
Result:=mrAbort;
end;
finally
EndConvert(Result);
end;
finally
EndConvert(Result);
DelphiUnit.Free;
end;
end;
@ -963,7 +984,7 @@ var
StartTime, EndTime: TDateTime;
s: string;
begin
if CompareFileExt(fOrigFilename,'.dproj',false)=0 then begin
if CompareFileExt(fSettings.MainFilename,'.dproj',false)=0 then begin
fErrorMsg:=
'.dproj file is not supported yet. The file is used by Delphi 2007 and newer.'+
' Please select a .dpr file for projects or .dpk file for packages.';
@ -980,15 +1001,15 @@ begin
StartTime:=Now;
fSettings.ClearLog;
// create/open lazarus project or package file
fLazPMainFilename:=fSettings.DelphiToLazFilename(fOrigFilename, fLazPMainSuffix, false);
fLazPMainFilename:=fSettings.DelphiToLazFilename(fSettings.MainFilename,
fLazPMainSuffix, false);
// Find Delphi project / package file name
if CompareFileExt(fOrigFilename,fDelphiPSuffix,false)=0 then
fDelphiPFilename:=fOrigFilename
if CompareFileExt(fSettings.MainFilename,fDelphiPSuffix,false)=0 then
fDelphiPFilename:=fSettings.MainFilename
else
fDelphiPFilename:=ChangeFileExt(fOrigFilename,fDelphiPSuffix);
fDelphiPFilename:=ChangeFileExt(fSettings.MainFilename,fDelphiPSuffix);
if not FileExistsUTF8(fDelphiPFilename) then
fDelphiPFilename:=FindDiskFileCaseInsensitive(fOrigFilename);
fDelphiPFilename:=FindDiskFileCaseInsensitive(fSettings.MainFilename);
// ? fDelphiPFilename:=CodeToolBoss.DirectoryCachePool.FindDiskFilename(fDelphiPFilename);
// Actual conversion.
@ -1018,9 +1039,9 @@ begin
Result:=CreateInstance;
if Result<>mrOK then exit;
// Create main source file (.lpr/.lpk) (only copy, no conversion)
fMainUnitConverter:=TDelphiUnit.Create(Self, fOrigFilename,[]);
fMainUnitConverter:=TDelphiUnit.Create(Self, fSettings.MainFilename,[]);
if fSettings.SupportDelphi then
fMainUnitConverter.LazFileExt:=ExtractFileExt(fOrigFilename)
fMainUnitConverter.LazFileExt:=ExtractFileExt(fSettings.MainFilename)
else
fMainUnitConverter.LazFileExt:=fLazPSuffix; // '.lpr' or ''
Result:=fMainUnitConverter.CopyAndLoadFile;
@ -1575,7 +1596,8 @@ begin
FoundUnits, MisUnits, NormalUnits) then
begin
LazarusIDE.DoJumpToCodeToolBossError;
fErrorMsg:='Problems when trying to find all units from project file '+fOrigFilename;
fErrorMsg:='Problems when trying to find all units from project file '
+fSettings.MainFilename;
exit(mrCancel);
end;
try // Add all units to the project
@ -1914,7 +1936,8 @@ begin
FoundUnits, MisUnits, NormalUnits) then
begin
LazarusIDE.DoJumpToCodeToolBossError;
fErrorMsg:='Problems when trying to find all units from package file '+fOrigFilename;
fErrorMsg:='Problems when trying to find all units from package file '
+fSettings.MainFilename;
exit(mrCancel);
end;
try

View File

@ -1,56 +1,25 @@
object ConvertSettingsForm: TConvertSettingsForm
Left = 315
Height = 380
Height = 400
Top = 127
Width = 577
ActiveControl = ProjectPathEdit
Width = 671
Caption = 'Convert Delphi unit, project or package '
ClientHeight = 380
ClientWidth = 577
Constraints.MinHeight = 328
ClientHeight = 400
ClientWidth = 671
Constraints.MinHeight = 377
Constraints.MinWidth = 544
OnCreate = FormCreate
OnDestroy = FormDestroy
Position = poScreenCenter
LCLVersion = '1.1'
object ProjectPathEdit: TLabeledEdit
AnchorSideLeft.Control = Owner
AnchorSideRight.Control = UnitReplaceDivider
Left = 9
Height = 21
Hint = 'Directory where project''s main file must be'
Top = 32
Width = 293
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 9
BorderSpacing.Right = 9
BorderStyle = bsNone
Color = clBtnFace
EditLabel.AnchorSideLeft.Control = ProjectPathEdit
EditLabel.AnchorSideTop.Side = asrCenter
EditLabel.AnchorSideRight.Control = ProjectPathEdit
EditLabel.AnchorSideRight.Side = asrBottom
EditLabel.AnchorSideBottom.Control = ProjectPathEdit
EditLabel.Left = 9
EditLabel.Height = 15
EditLabel.Top = 10
EditLabel.Width = 293
EditLabel.Caption = 'Project Path:'
EditLabel.ParentColor = False
LabelSpacing = 7
ParentShowHint = False
ReadOnly = True
ShowHint = True
TabOrder = 0
end
object BackupCheckBox: TCheckBox
AnchorSideLeft.Control = DelphiDefineCheckBox
AnchorSideTop.Control = DelphiDefineCheckBox
AnchorSideTop.Side = asrBottom
Left = 12
Left = 15
Height = 21
Hint = 'Creates a Backup directory under project directory'
Top = 195
Top = 238
Width = 211
BorderSpacing.Top = 3
Caption = 'Make backup of changed files'
@ -58,13 +27,13 @@ object ConvertSettingsForm: TConvertSettingsForm
ParentShowHint = False
ShowHint = True
State = cbChecked
TabOrder = 1
TabOrder = 0
end
object ButtonPanel1: TButtonPanel
Left = 6
Height = 41
Top = 333
Width = 565
Top = 353
Width = 659
OKButton.Name = 'OKButton'
OKButton.DefaultCaption = True
HelpButton.Name = 'HelpButton'
@ -75,32 +44,32 @@ object ConvertSettingsForm: TConvertSettingsForm
CancelButton.Name = 'CancelButton'
CancelButton.DefaultCaption = True
CancelButton.OnClick = CancelButtonClick
TabOrder = 2
TabOrder = 1
ShowButtons = [pbOK, pbCancel, pbHelp]
end
object KeepFileOpenCheckBox: TCheckBox
AnchorSideLeft.Control = BackupCheckBox
AnchorSideTop.Control = BackupCheckBox
AnchorSideTop.Side = asrBottom
Left = 12
Left = 15
Height = 21
Hint = 'Separate form files allow different properties'
Top = 219
Top = 262
Width = 242
BorderSpacing.Top = 3
Caption = 'Keep converted files open in editor'
ParentShowHint = False
ShowHint = True
TabOrder = 3
TabOrder = 2
end
object UnitReplaceDivider: TDividerBevel
Left = 311
AnchorSideTop.Control = InputPathLabel
Left = 396
Height = 17
Top = 9
Width = 239
Width = 262
Caption = 'Unit Replacements'
Anchors = [akTop, akRight]
BorderSpacing.Top = 9
Font.Style = [fsBold]
ParentFont = False
ParentShowHint = False
@ -113,10 +82,10 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = UnitReplaceDivider
AnchorSideRight.Side = asrBottom
Left = 311
Left = 396
Height = 17
Top = 65
Width = 239
Width = 262
Caption = 'Unknown properties'
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 39
@ -130,18 +99,18 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideLeft.Control = UnitReplaceDivider
AnchorSideTop.Control = UnitReplaceDivider
AnchorSideTop.Side = asrBottom
Left = 312
Left = 397
Height = 25
Hint = 'Unit names in uses section of a source unit'
Top = 27
Width = 75
Width = 118
BorderSpacing.Left = 1
BorderSpacing.Top = 1
Caption = 'Edit'
OnClick = UnitReplaceButtonClick
ParentShowHint = False
ShowHint = True
TabOrder = 4
TabOrder = 3
end
object TypeReplaceDivider: TDividerBevel
AnchorSideLeft.Control = UnitReplaceDivider
@ -149,10 +118,10 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = UnitReplaceDivider
AnchorSideRight.Side = asrBottom
Left = 311
Left = 396
Height = 17
Top = 121
Width = 239
Width = 262
Caption = 'Type Replacements'
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 39
@ -166,18 +135,21 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideLeft.Control = TypeReplaceDivider
AnchorSideTop.Control = TypeReplaceDivider
AnchorSideTop.Side = asrBottom
Left = 312
AnchorSideRight.Control = UnitReplaceButton
AnchorSideRight.Side = asrBottom
Left = 397
Height = 25
Hint = 'Unknown types in form file (DFM/LFM)'
Top = 139
Width = 75
Width = 118
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 1
BorderSpacing.Top = 1
Caption = 'Edit'
OnClick = TypeReplaceButtonClick
ParentShowHint = False
ShowHint = True
TabOrder = 5
TabOrder = 4
end
object FuncReplaceDivider: TDividerBevel
AnchorSideLeft.Control = UnitReplaceDivider
@ -185,10 +157,10 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = UnitReplaceDivider
AnchorSideRight.Side = asrBottom
Left = 311
Left = 396
Height = 17
Top = 177
Width = 239
Width = 262
Caption = 'Function Replacements'
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 39
@ -204,10 +176,10 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = UnitReplaceDivider
AnchorSideRight.Side = asrBottom
Left = 311
Left = 396
Height = 17
Top = 249
Width = 239
Width = 262
Caption = 'Coordinate Offsets'
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 55
@ -221,53 +193,60 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideLeft.Control = FuncReplaceDivider
AnchorSideTop.Control = FuncReplaceDivider
AnchorSideTop.Side = asrBottom
Left = 312
AnchorSideRight.Control = UnitReplaceButton
AnchorSideRight.Side = asrBottom
Left = 397
Height = 25
Hint = 'Some Delphi functions can be replaced with a LCL function'
Top = 195
Width = 75
Width = 118
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 1
BorderSpacing.Top = 1
Caption = 'Edit'
OnClick = FuncReplaceButtonClick
ParentShowHint = False
ShowHint = True
TabOrder = 6
TabOrder = 5
end
object CoordOffsButton: TBitBtn
AnchorSideLeft.Control = CoordOffsDivider
AnchorSideTop.Control = CoordOffsDivider
AnchorSideTop.Side = asrBottom
Left = 312
AnchorSideRight.Control = UnitReplaceButton
AnchorSideRight.Side = asrBottom
Left = 397
Height = 25
Hint = 'Some Delphi functions can be replaced with a LCL function'
Top = 267
Width = 75
Width = 118
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 1
BorderSpacing.Top = 1
Caption = 'Edit'
OnClick = CoordOffsButtonClick
ParentShowHint = False
ShowHint = True
TabOrder = 7
TabOrder = 6
end
object TargetGroupBox: TGroupBox
AnchorSideLeft.Control = ProjectPathEdit
AnchorSideTop.Control = ProjectPathEdit
AnchorSideLeft.Control = InputPathListBox
AnchorSideTop.Control = InputPathListBox
AnchorSideTop.Side = asrBottom
Left = 9
Left = 12
Height = 98
Hint = 'xxx'
Top = 64
Top = 107
Width = 211
Anchors = [akLeft, akBottom]
AutoSize = True
BorderSpacing.Top = 11
BorderSpacing.Top = 7
Caption = 'Target'
ClientHeight = 79
ClientWidth = 207
ParentShowHint = False
ShowHint = True
TabOrder = 8
TabOrder = 7
object SupportDelphiCheckBox: TCheckBox
AnchorSideLeft.Control = CrossPlatformCheckBox
AnchorSideTop.Control = CrossPlatformCheckBox
@ -323,91 +302,97 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = UnitReplaceButton
AnchorSideTop.Side = asrCenter
Left = 410
Left = 530
Height = 25
Top = 27
Width = 136
BorderSpacing.Left = 23
Width = 129
BorderSpacing.Left = 15
ItemHeight = 0
Style = csDropDownList
TabOrder = 9
TabOrder = 8
end
object UnknownPropsComboBox: TComboBox
AnchorSideLeft.Control = UnitReplaceComboBox
AnchorSideTop.Control = UnknownPropsDivider
AnchorSideTop.Side = asrBottom
Left = 410
AnchorSideRight.Control = UnitReplaceComboBox
AnchorSideRight.Side = asrBottom
Left = 530
Height = 25
Top = 84
Width = 136
Width = 129
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 2
ItemHeight = 0
Style = csDropDownList
TabOrder = 9
end
object FuncReplaceComboBox: TComboBox
AnchorSideLeft.Control = UnitReplaceComboBox
AnchorSideTop.Control = FuncReplaceButton
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = UnitReplaceComboBox
AnchorSideRight.Side = asrBottom
Left = 530
Height = 25
Top = 195
Width = 129
Anchors = [akTop, akLeft, akRight]
ItemHeight = 0
Style = csDropDownList
TabOrder = 10
end
object FuncReplaceComboBox: TComboBox
AnchorSideLeft.Control = FuncReplaceButton
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = FuncReplaceButton
object CoordOffsComboBox: TComboBox
AnchorSideLeft.Control = UnitReplaceComboBox
AnchorSideTop.Control = CoordOffsButton
AnchorSideTop.Side = asrCenter
Left = 410
AnchorSideRight.Control = UnitReplaceComboBox
AnchorSideRight.Side = asrBottom
Left = 530
Height = 25
Top = 195
Width = 136
BorderSpacing.Left = 23
Top = 267
Width = 129
Anchors = [akTop, akLeft, akRight]
ItemHeight = 0
Style = csDropDownList
TabOrder = 11
end
object CoordOffsComboBox: TComboBox
AnchorSideLeft.Control = CoordOffsButton
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = CoordOffsButton
object TypeReplaceComboBox: TComboBox
AnchorSideLeft.Control = UnitReplaceComboBox
AnchorSideTop.Control = TypeReplaceButton
AnchorSideTop.Side = asrCenter
Left = 410
AnchorSideRight.Control = UnitReplaceComboBox
AnchorSideRight.Side = asrBottom
Left = 530
Height = 25
Top = 267
Width = 136
BorderSpacing.Left = 23
Top = 139
Width = 129
Anchors = [akTop, akLeft, akRight]
ItemHeight = 0
Style = csDropDownList
TabOrder = 12
end
object TypeReplaceComboBox: TComboBox
AnchorSideLeft.Control = TypeReplaceButton
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = TypeReplaceButton
AnchorSideTop.Side = asrCenter
Left = 410
Height = 25
Top = 139
Width = 136
BorderSpacing.Left = 23
ItemHeight = 0
Style = csDropDownList
TabOrder = 13
end
object ScanProgressBar: TProgressBar
AnchorSideLeft.Control = ScanLabel
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = KeepFileOpenCheckBox
AnchorSideTop.Side = asrBottom
Left = 182
Left = 185
Height = 20
Top = 259
Top = 298
Width = 102
BorderSpacing.Left = 6
BorderSpacing.Top = 19
BorderSpacing.Top = 15
Style = pbstMarquee
TabOrder = 14
TabOrder = 13
end
object ScanLabel: TLabel
AnchorSideLeft.Control = BackupCheckBox
AnchorSideTop.Control = ScanProgressBar
AnchorSideTop.Side = asrCenter
Left = 12
Left = 15
Height = 15
Top = 262
Top = 301
Width = 164
Caption = 'Scanning parent directory'
ParentColor = False
@ -418,42 +403,67 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = ScanProgressBar
AnchorSideRight.Side = asrBottom
Left = 182
Left = 185
Height = 25
Top = 280
Top = 319
Width = 102
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 1
Caption = 'Stop'
OnClick = StopScanButtonClick
TabOrder = 15
TabOrder = 14
end
object FuncReplaceCommentCB: TCheckBox
AnchorSideLeft.Control = FuncReplaceButton
AnchorSideTop.Control = FuncReplaceButton
AnchorSideTop.Side = asrBottom
Left = 312
Left = 397
Height = 21
Top = 225
Width = 227
BorderSpacing.Top = 5
Caption = 'Add comment after replacement'
TabOrder = 16
TabOrder = 15
end
object DelphiDefineCheckBox: TCheckBox
AnchorSideLeft.Control = TargetGroupBox
AnchorSideTop.Control = TargetGroupBox
AnchorSideTop.Side = asrBottom
Left = 12
Left = 15
Height = 21
Hint = 'Separate form files allow different properties'
Top = 171
Top = 214
Width = 217
BorderSpacing.Left = 3
BorderSpacing.Top = 9
Caption = 'Add defines simulating Delphi7'
ParentShowHint = False
ShowHint = True
TabOrder = 16
end
object InputPathLabel: TLabel
Left = 12
Height = 15
Top = 9
Width = 93
Caption = 'InputPathLabel'
ParentColor = False
end
object InputPathListBox: TListBox
AnchorSideLeft.Control = InputPathLabel
AnchorSideTop.Control = InputPathLabel
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = UnitReplaceDivider
AnchorSideBottom.Control = TargetGroupBox
Left = 12
Height = 75
Top = 25
Width = 375
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Top = 1
BorderSpacing.Right = 9
BorderSpacing.Bottom = 1
ItemHeight = 0
TabOrder = 17
end
end

View File

@ -52,8 +52,7 @@ type
fTitle: String; // Used for form caption.
fLog: TStringList;
// Unit, Project or Package top file and path.
fMainFilename: String;
fMainPath: String;
fMainFilenames: TStringList;
// Persistent storage in XML or some other format.
fConfigStorage: TConfigStorage;
fSettingsForm: TConvertSettingsForm;
@ -83,8 +82,9 @@ type
fCoordOffsets: TVisualOffsets;
// Getter / setter:
function GetBackupPath: String;
function GetMainFilename: String;
function GetMainPath: String;
procedure SetEnabled(const AValue: Boolean);
procedure SetMainFilename(const AValue: String);
public
constructor Create(const ATitle: string);
destructor Destroy; override;
@ -108,8 +108,9 @@ type
function AddLogLine(const ALine: string): integer;
function SaveLog: Boolean;
public
property MainFilename: String read fMainFilename write SetMainFilename;
property MainPath: String read fMainPath;
property MainFilenames: TStringlist read fMainFilenames;
property MainFilename: String read GetMainFilename;
property MainPath: String read GetMainPath;
property BackupPath: String read GetBackupPath;
property Enabled: Boolean read fEnabled write SetEnabled;
property DelphiDefine: Boolean read fDelphiDefine;
@ -137,6 +138,8 @@ type
TConvertSettingsForm = class(TForm)
FuncReplaceCommentCB: TCheckBox;
DelphiDefineCheckBox: TCheckBox;
InputPathLabel: TLabel;
InputPathListBox: TListBox;
StopScanButton: TBitBtn;
CoordOffsComboBox: TComboBox;
ScanLabel: TLabel;
@ -160,7 +163,6 @@ type
ButtonPanel1: TButtonPanel;
TypeReplaceButton: TBitBtn;
UnitReplaceButton: TBitBtn;
ProjectPathEdit: TLabeledEdit;
CoordOffsButton: TBitBtn;
procedure SameDfmCheckBoxChange(Sender: TObject);
procedure StopScanButtonClick(Sender: TObject);
@ -389,8 +391,7 @@ var
begin
fTitle:=ATitle;
fLog:=TStringList.Create;
fMainFilename:='';
fMainPath:='';
fMainFilenames:=TStringList.Create;
fEnabled:=True;
fSettingsForm:=Nil;
fOmitProjUnits:=TStringToStringTree.Create(false);
@ -652,6 +653,7 @@ begin
fReplaceTypes.Free;
fReplaceUnits.Free;
fOmitProjUnits.Free;
fMainFilenames.Free;
fLog.Free;
inherited Destroy;
end;
@ -669,8 +671,8 @@ begin
end
else
ThreadTerminated(nil); // Hide controls dealing with scanning
Caption:=fTitle + ' - ' + ExtractFileName(fMainFilename);
ProjectPathEdit.Text:=fMainPath;
Caption:=fTitle + ' - ' + ExtractFileName(MainFilename);
InputPathListBox.Items.Assign(fMainFilenames);
// Settings --> UI. Loaded from ConfigSettings earlier.
DelphiDefineCheckBox.Checked :=fDelphiDefine;
BackupCheckBox.Checked :=fBackupFiles;
@ -719,7 +721,7 @@ function TConvertSettings.DelphiToLazFilename(const DelphiFilename, LazExt: stri
var
RelPath, SubPath, fn: string;
begin
RelPath:=FileUtil.CreateRelativePath(DelphiFilename, fMainPath);
RelPath:=FileUtil.CreateRelativePath(DelphiFilename, MainPath);
SubPath:=ExtractFilePath(RelPath);
if LazExt='' then // Include ext in filename if not defined.
fn:=ExtractFileName(RelPath)
@ -727,7 +729,7 @@ begin
fn:=ExtractFileNameOnly(RelPath);
if LowercaseFilename then
fn:=LowerCase(fn);
Result:=fMainPath+SubPath+fn+LazExt;
Result:=MainPath+SubPath+fn+LazExt;
end;
function TConvertSettings.RenameDelphiToLazFile(const DelphiFilename: string;
@ -741,7 +743,7 @@ function TConvertSettings.RenameDelphiToLazFile(const DelphiFilename, LazExt: st
var
RelPath, SubPath, fn: string;
begin
RelPath:=FileUtil.CreateRelativePath(DelphiFilename, fMainPath);
RelPath:=FileUtil.CreateRelativePath(DelphiFilename, MainPath);
SubPath:=ExtractFilePath(RelPath);
if LazExt='' then // Include ext in filename if not defined.
fn:=ExtractFileName(RelPath)
@ -754,7 +756,7 @@ begin
Result:=BackupFile(DelphiFilename); // Save before rename.
if Result<>mrOK then exit;
end;
LazFilename:=fMainPath+SubPath+fn+LazExt;
LazFilename:=MainPath+SubPath+fn+LazExt;
Result:=RenameFileWithErrorDialogs(DelphiFilename,LazFilename,[mbAbort]);
end;
@ -792,7 +794,7 @@ var
aFilename: String;
Code: TCodeBuffer;
begin
aFilename:=fMainPath+'AutomaticConversion.log';
aFilename:=MainPath+'AutomaticConversion.log';
Code:=CodeToolBoss.CreateFile(aFilename);
Code.Assign(fLog);
Result:=SaveCodeBuffer(Code)=mrOk;
@ -800,25 +802,29 @@ begin
IDEMessagesWindow.AddMsg('This log was saved to '+aFilename, '', -1);
end;
procedure TConvertSettings.SetMainFilename(const AValue: String);
begin
fMainFilename:=AValue;
fMainPath:=ExtractFilePath(AValue);
end;
function TConvertSettings.GetBackupPath: String;
const
BackupPathName='ConverterBackup';
begin
Result:='';
if fBackupFiles then begin
Result:=fMainPath+BackupPathName+PathDelim;
Result:=MainPath+BackupPathName+PathDelim;
// Create backup path if needed.
if not DirectoryExistsUTF8(Result) then
CreateDirUTF8(Result);
end;
end;
function TConvertSettings.GetMainFilename: String;
begin
Result:=fMainFilenames[0];
end;
function TConvertSettings.GetMainPath: String;
begin
Result:=ExtractFilePath(fMainFilenames[0]);
end;
procedure TConvertSettings.SetEnabled(const AValue: Boolean);
begin
if fEnabled=AValue then exit;
@ -843,9 +849,9 @@ end;
procedure TConvertSettingsForm.FormCreate(Sender: TObject);
begin
ProjectPathEdit.Text:='';
ProjectPathEdit.EditLabel.Caption:=lisProjectPath;
ProjectPathEdit.Hint:=lisProjectPathHint;
InputPathLabel.Caption:=lisProjectPath;
InputPathListBox.Clear;
InputPathListBox.Hint:=lisProjectPathHint;
DelphiDefineCheckBox.Caption:=lisAddDelphiDefine;
DelphiDefineCheckBox.Hint:=lisAddDelphiDefineHint;
BackupCheckBox.Caption:=lisBackupChangedFiles;
@ -979,6 +985,5 @@ begin
EditCoordOffsets(fSettings.CoordOffsets, lisConvCoordOffs);
end;
end.

View File

@ -952,7 +952,6 @@ type
// conversion
function DoConvertDFMtoLFM: TModalResult;
function DoConvertDelphiUnit(const DelphiFilename: string; CanAbort: boolean): TModalResult;
function DoConvertDelphiProject(const DelphiFilename: string): TModalResult;
function DoConvertDelphiPackage(const DelphiFilename: string): TModalResult;
@ -4384,18 +4383,12 @@ begin
end;
procedure TMainIDE.mnuToolConvertDelphiUnitClicked(Sender: TObject);
procedure UpdateEnvironment;
begin
SetRecentFilesMenu;
SaveEnvironment;
end;
var
OpenDialog: TOpenDialog;
AFilename: string;
i: Integer;
MultiOpen: Boolean;
OldChange: Boolean;
Converter: TConvertDelphiUnit;
begin
OpenDialog:=TOpenDialog.Create(nil);
try
@ -4405,20 +4398,23 @@ begin
dlgAllFiles+' ('+GetAllFilesMask+')|' + GetAllFilesMask;
OpenDialog.Options:=OpenDialog.Options+[ofAllowMultiSelect];
if InputHistories.LastConvertDelphiUnit<>'' then begin
OpenDialog.InitialDir:=
ExtractFilePath(InputHistories.LastConvertDelphiUnit);
OpenDialog.Filename:=
ExtractFileName(InputHistories.LastConvertDelphiUnit);
OpenDialog.InitialDir:=ExtractFilePath(InputHistories.LastConvertDelphiUnit);
OpenDialog.Filename :=ExtractFileName(InputHistories.LastConvertDelphiUnit);
end;
if OpenDialog.Execute and (OpenDialog.Files.Count>0) then begin
MultiOpen:=OpenDialog.Files.Count>1;
for i := 0 to OpenDialog.Files.Count-1 do begin
AFilename:=CleanAndExpandFilename(OpenDialog.Files.Strings[i]);
if FileExistsUTF8(AFilename)
and (DoConvertDelphiUnit(AFilename,MultiOpen)=mrAbort) then
break;
InputHistories.LastConvertDelphiUnit:=OpenDialog.Files[0];
OldChange:=OpenEditorsOnCodeToolChange;
OpenEditorsOnCodeToolChange:=true;
Converter:=TConvertDelphiUnit.Create(OpenDialog.Files);
try
if Converter.Convert=mrOK then begin
SetRecentFilesMenu;
SaveEnvironment;
end;
finally
Converter.Free;
OpenEditorsOnCodeToolChange:=OldChange;
end;
UpdateEnvironment;
end;
InputHistories.StoreFileDialogSettings(OpenDialog);
finally
@ -4427,13 +4423,6 @@ begin
end;
procedure TMainIDE.mnuToolConvertDelphiProjectClicked(Sender: TObject);
procedure UpdateEnvironment;
begin
SetRecentFilesMenu;
SaveEnvironment;
end;
var
OpenDialog: TOpenDialog;
AFilename: string;
@ -4446,16 +4435,15 @@ begin
lisLazarusProject+' (*.lpr)|*.lpr|'+
dlgAllFiles+' ('+GetAllFilesMask+')|' + GetAllFilesMask;
if InputHistories.LastConvertDelphiProject<>'' then begin
OpenDialog.InitialDir:=
ExtractFilePath(InputHistories.LastConvertDelphiProject);
OpenDialog.Filename:=
ExtractFileName(InputHistories.LastConvertDelphiProject);
OpenDialog.InitialDir:=ExtractFilePath(InputHistories.LastConvertDelphiProject);
OpenDialog.Filename :=ExtractFileName(InputHistories.LastConvertDelphiProject);
end;
if OpenDialog.Execute then begin
AFilename:=CleanAndExpandFilename(OpenDialog.Filename);
if FileExistsUTF8(AFilename) then
DoConvertDelphiProject(AFilename);
UpdateEnvironment;
SetRecentFilesMenu;
SaveEnvironment;
end;
InputHistories.StoreFileDialogSettings(OpenDialog);
finally
@ -4464,13 +4452,6 @@ begin
end;
procedure TMainIDE.mnuToolConvertDelphiPackageClicked(Sender: TObject);
procedure UpdateEnvironment;
begin
SetRecentFilesMenu;
SaveEnvironment;
end;
var
OpenDialog: TOpenDialog;
AFilename: string;
@ -4483,14 +4464,15 @@ begin
dlgAllFiles+' ('+GetAllFilesMask+')|' + GetAllFilesMask;
if InputHistories.LastConvertDelphiPackage<>'' then begin
OpenDialog.InitialDir:=ExtractFilePath(InputHistories.LastConvertDelphiPackage);
OpenDialog.Filename:=ExtractFileName(InputHistories.LastConvertDelphiPackage);
OpenDialog.Filename :=ExtractFileName(InputHistories.LastConvertDelphiPackage);
end;
if OpenDialog.Execute then begin
AFilename:=CleanAndExpandFilename(OpenDialog.Filename);
//debugln('TMainIDE.mnuToolConvertDelphiProjectClicked A ',AFilename);
if FileExistsUTF8(AFilename) then
DoConvertDelphiPackage(AFilename);
UpdateEnvironment;
SetRecentFilesMenu;
SaveEnvironment;
end;
InputHistories.StoreFileDialogSettings(OpenDialog);
finally
@ -7985,26 +7967,7 @@ begin
DoCheckFilesOnDisk;
end;
function TMainIDE.DoConvertDelphiUnit(const DelphiFilename: string;
CanAbort: boolean): TModalResult;
var
OldChange: Boolean;
Converter: TConvertDelphiUnit;
begin
InputHistories.LastConvertDelphiUnit:=DelphiFilename;
OldChange:=OpenEditorsOnCodeToolChange;
OpenEditorsOnCodeToolChange:=true;
Converter := TConvertDelphiUnit.Create(DelphiFilename);
try
Result:=Converter.Convert;
finally
Converter.Free;
OpenEditorsOnCodeToolChange:=OldChange;
end;
end;
function TMainIDE.DoConvertDelphiProject(const DelphiFilename: string
): TModalResult;
function TMainIDE.DoConvertDelphiProject(const DelphiFilename: string): TModalResult;
var
OldChange: Boolean;
Converter: TConvertDelphiProject;
@ -8021,8 +7984,7 @@ begin
end;
end;
function TMainIDE.DoConvertDelphiPackage(const DelphiFilename: string
): TModalResult;
function TMainIDE.DoConvertDelphiPackage(const DelphiFilename: string): TModalResult;
var
OldChange: Boolean;
Converter: TConvertDelphiPackage;