Converter: improved GUI and added options for settings. Cleanup.

git-svn-id: trunk@27291 -
This commit is contained in:
juha 2010-09-10 15:04:48 +00:00
parent 65fc15cd3b
commit 4c8d3d791b
6 changed files with 188 additions and 110 deletions

View File

@ -35,7 +35,6 @@ type
fLowerCaseRes: boolean; fLowerCaseRes: boolean;
fDfmDirectiveStart: integer; fDfmDirectiveStart: integer;
fDfmDirectiveEnd: integer; fDfmDirectiveEnd: integer;
fTarget: TConvertTarget;
// List of units to remove. // List of units to remove.
fUnitsToRemove: TStringList; fUnitsToRemove: TStringList;
// Units to rename. Map of unit name -> real unit name. // Units to rename. Map of unit name -> real unit name.
@ -44,8 +43,10 @@ type
fUnitsToComment: TStringList; fUnitsToComment: TStringList;
// Delphi Function names to replace with FCL/LCL functions. // Delphi Function names to replace with FCL/LCL functions.
fDefinedProcNames: TStringList; fDefinedProcNames: TStringList;
fReplaceFuncs: TFuncsAndCategories; // List of TFuncReplacement.
fFuncsToReplace: TObjectList; // List of TFuncReplacement. fFuncsToReplace: TObjectList;
fSettings: TConvertSettings; // Conversion settings.
function AddDelphiAndLCLSections: boolean; function AddDelphiAndLCLSections: boolean;
function AddModeDelphiDirective: boolean; function AddModeDelphiDirective: boolean;
function RenameResourceDirectives: boolean; function RenameResourceDirectives: boolean;
@ -70,11 +71,10 @@ type
property Ask: Boolean read fAsk write fAsk; property Ask: Boolean read fAsk write fAsk;
property HasFormFile: boolean read fHasFormFile write fHasFormFile; property HasFormFile: boolean read fHasFormFile write fHasFormFile;
property LowerCaseRes: boolean read fLowerCaseRes write fLowerCaseRes; property LowerCaseRes: boolean read fLowerCaseRes write fLowerCaseRes;
property Target: TConvertTarget read fTarget write fTarget;
property UnitsToRemove: TStringList read fUnitsToRemove write fUnitsToRemove; property UnitsToRemove: TStringList read fUnitsToRemove write fUnitsToRemove;
property UnitsToRename: TStringToStringTree read fUnitsToRename write fUnitsToRename; property UnitsToRename: TStringToStringTree read fUnitsToRename write fUnitsToRename;
property UnitsToComment: TStringList read fUnitsToComment write fUnitsToComment; property UnitsToComment: TStringList read fUnitsToComment write fUnitsToComment;
property ReplaceFuncs: TFuncsAndCategories read fReplaceFuncs write fReplaceFuncs; property Settings: TConvertSettings read fSettings write fSettings;
end; end;
@ -88,7 +88,6 @@ begin
// Default values for vars. // Default values for vars.
fAsk:=true; fAsk:=true;
fLowerCaseRes:=false; fLowerCaseRes:=false;
fTarget:=ctLazarus;
fUnitsToRemove:=nil; // These are set from outside. fUnitsToRemove:=nil; // These are set from outside.
fUnitsToComment:=nil; fUnitsToComment:=nil;
fUnitsToRename:=nil; fUnitsToRename:=nil;
@ -141,17 +140,18 @@ begin
// these changes can be applied together without rescan // these changes can be applied together without rescan
if not AddModeDelphiDirective then exit; if not AddModeDelphiDirective then exit;
if not RenameResourceDirectives then exit; if not RenameResourceDirectives then exit;
if fSettings.EnableReplaceFuncs then
if not ReplaceFuncCalls(aIsConsoleApp) then exit; if not ReplaceFuncCalls(aIsConsoleApp) then exit;
if not fSrcCache.Apply then exit; if not fSrcCache.Apply then exit;
finally finally
fSrcCache.EndUpdate; fSrcCache.EndUpdate;
end; end;
if fTarget=ctLazarus then begin if fSettings.Target=ctLazarus then begin
// One way conversion -> remove, rename and comment out units. // One way conversion -> remove, rename and comment out units.
if not RemoveUnits then exit; if not RemoveUnits then exit;
if not RenameUnits then exit; if not RenameUnits then exit;
end; end;
if fTarget=ctLazarusAndDelphi then begin if fSettings.Target=ctLazarusAndDelphi then begin
// Support Delphi. Add IFDEF blocks for units. // Support Delphi. Add IFDEF blocks for units.
if not AddDelphiAndLCLSections then exit; if not AddDelphiAndLCLSections then exit;
end end
@ -278,7 +278,7 @@ begin
ReadNextAtom; // semicolon ReadNextAtom; // semicolon
InsertPos:=CurPos.EndPos; InsertPos:=CurPos.EndPos;
nl:=fSrcCache.BeautifyCodeOptions.LineEnd; nl:=fSrcCache.BeautifyCodeOptions.LineEnd;
if fTarget=ctLazarusAndDelphi then if fSettings.Target=ctLazarusAndDelphi then
s:='{$IFDEF FPC}'+nl+' {$MODE Delphi}'+nl+'{$ENDIF}' s:='{$IFDEF FPC}'+nl+' {$MODE Delphi}'+nl+'{$ENDIF}'
else else
s:='{$MODE Delphi}'; s:='{$MODE Delphi}';
@ -323,7 +323,7 @@ begin
if (LowKey='dfm') or (LowKey='xfm') then begin if (LowKey='dfm') or (LowKey='xfm') then begin
// Lowercase existing key. (Future, when the same dfm file can be used) // Lowercase existing key. (Future, when the same dfm file can be used)
// faUseDfm: if Key<>LowKey then NewKey:=LowKey; // faUseDfm: if Key<>LowKey then NewKey:=LowKey;
if fTarget=ctLazarusAndDelphi then begin if fSettings.Target=ctLazarusAndDelphi then begin
// Later IFDEF will be added so that Delphi can still use .dfm. // Later IFDEF will be added so that Delphi can still use .dfm.
fDfmDirectiveStart:=ACleanPos; fDfmDirectiveStart:=ACleanPos;
fDfmDirectiveEnd:=ParamPos+6; fDfmDirectiveEnd:=ParamPos+6;
@ -348,7 +348,7 @@ begin
ACleanPos:=FindCommentEnd(Src, ACleanPos, Scanner.NestedComments); ACleanPos:=FindCommentEnd(Src, ACleanPos, Scanner.NestedComments);
until false; until false;
// if there is already .lfm file, don't add IFDEF for .dfm / .lfm. // if there is already .lfm file, don't add IFDEF for .dfm / .lfm.
if (fTarget=ctLazarusAndDelphi) and (fDfmDirectiveStart<>-1) and not AlreadyIsLfm then if (fSettings.Target=ctLazarusAndDelphi) and (fDfmDirectiveStart<>-1) and not AlreadyIsLfm then
begin begin
// Add IFDEF for .lfm and .dfm allowing Delphi to use .dfm. // Add IFDEF for .lfm and .dfm allowing Delphi to use .dfm.
nl:=fSrcCache.BeautifyCodeOptions.LineEnd; nl:=fSrcCache.BeautifyCodeOptions.LineEnd;
@ -705,14 +705,14 @@ var
with fCodeTool do begin with fCodeTool do begin
while (IdentEndPos<=MaxPos) and (IsIdentChar[Src[IdentEndPos]]) do while (IdentEndPos<=MaxPos) and (IsIdentChar[Src[IdentEndPos]]) do
inc(IdentEndPos); inc(IdentEndPos);
for i:=0 to fReplaceFuncs.Funcs.Count-1 do begin for i:=0 to fSettings.ReplaceFuncs.Funcs.Count-1 do begin
FuncName:=fReplaceFuncs.Funcs[i]; FuncName:=fSettings.ReplaceFuncs.Funcs[i];
if (IdentEndPos-xStart=length(FuncName)) if (IdentEndPos-xStart=length(FuncName))
and (CompareIdentifiers(PChar(Pointer(FuncName)),@Src[xStart])=0) and (CompareIdentifiers(PChar(Pointer(FuncName)),@Src[xStart])=0)
and not fDefinedProcNames.Find(FuncName, x) and not fDefinedProcNames.Find(FuncName, x)
then begin then begin
FuncDefInfo:=fReplaceFuncs.FuncAtInd(i); FuncDefInfo:=fSettings.ReplaceFuncs.FuncAtInd(i);
if fReplaceFuncs.Categories.Find(FuncDefInfo.Category, x) if fSettings.ReplaceFuncs.Categories.Find(FuncDefInfo.Category, x)
and not (aIsConsoleApp and (FuncDefInfo.Category='UTF8Names')) and not (aIsConsoleApp and (FuncDefInfo.Category='UTF8Names'))
then begin then begin
// Create a new replacement object for params, position and other info. // Create a new replacement object for params, position and other info.
@ -1113,7 +1113,6 @@ var
const GrandParentContext, ClassContext: TFindContext): boolean; const GrandParentContext, ClassContext: TFindContext): boolean;
var var
CurLFMNode: TLFMTreeNode; CurLFMNode: TLFMTreeNode;
i: Integer;
begin begin
CurLFMNode:=LFMObject.FirstChild; CurLFMNode:=LFMObject.FirstChild;
while CurLFMNode<>nil do begin while CurLFMNode<>nil do begin

View File

@ -553,8 +553,7 @@ begin
ConvTool.Ask:=Assigned(fOwnerConverter); ConvTool.Ask:=Assigned(fOwnerConverter);
ConvTool.LowerCaseRes:=FileExistsUTF8(ChangeFileExt(fLazUnitFilename, '.res')); ConvTool.LowerCaseRes:=FileExistsUTF8(ChangeFileExt(fLazUnitFilename, '.res'));
ConvTool.HasFormFile:=DfmFilename<>''; ConvTool.HasFormFile:=DfmFilename<>'';
ConvTool.Target:=fSettings.Target; ConvTool.Settings:=fSettings;
ConvTool.ReplaceFuncs:=fSettings.ReplaceFuncs;
ConvTool.UnitsToRemove:=fUnitsToRemove; ConvTool.UnitsToRemove:=fUnitsToRemove;
ConvTool.UnitsToRename:=fUnitsToRename; ConvTool.UnitsToRename:=fUnitsToRename;
ConvTool.UnitsToComment:=fUnitsToComment; ConvTool.UnitsToComment:=fUnitsToComment;

View File

@ -1,10 +1,10 @@
object ConvertSettingsForm: TConvertSettingsForm object ConvertSettingsForm: TConvertSettingsForm
Left = 346 Left = 346
Height = 462 Height = 483
Top = 298 Top = 298
Width = 637 Width = 637
Caption = 'Convert Delphi unit, project or package ' Caption = 'Convert Delphi unit, project or package '
ClientHeight = 462 ClientHeight = 483
ClientWidth = 637 ClientWidth = 637
Constraints.MinHeight = 400 Constraints.MinHeight = 400
OnCreate = FormCreate OnCreate = FormCreate
@ -16,85 +16,126 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
AnchorSideBottom.Control = ButtonPanel AnchorSideBottom.Control = ButtonPanel
Left = 0 Left = 0
Height = 192 Height = 213
Top = 219 Top = 219
Width = 637 Width = 637
Anchors = [akTop, akLeft, akRight, akBottom] Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Top = 3 BorderSpacing.Top = 3
Caption = 'Units, Types and Properties' Caption = 'Replacements'
ClientHeight = 173 ClientHeight = 194
ClientWidth = 633 ClientWidth = 633
TabOrder = 0 TabOrder = 0
object AutoRemovePropCheckBox: TCheckBox object UnitReplaceButton: TBitBtn
Left = 303 Left = 11
Height = 21 Height = 30
Hint = 'If unchecked, there will be interactive dialogs for editing / accepting changes.' Hint = 'Unit names in uses section of a source unit'
Top = 40 Top = 36
Width = 282 Width = 272
Caption = 'Automatic removal of unknown properties' Caption = 'Unit Replacements'
OnClick = UnitReplaceButtonClick
ParentShowHint = False ParentShowHint = False
ShowHint = True ShowHint = True
TabOrder = 0 TabOrder = 0
end end
object UnitReplacementsButton: TBitBtn object TypeReplaceButton: TBitBtn
Left = 11 Left = 11
Height = 30 Height = 30
Hint = 'Unit names in uses section of a source unit' Hint = 'Unknown types in form file (DFM/LFM)'
Top = 12 Top = 76
Width = 272 Width = 272
Caption = 'Unit Replacements' Caption = 'Type Replacements'
OnClick = UnitReplacementsButtonClick OnClick = TypeReplaceButtonClick
ParentShowHint = False ParentShowHint = False
ShowHint = True ShowHint = True
TabOrder = 1 TabOrder = 1
end end
object TypeReplacementsButton: TBitBtn object UnitReplaceAutoCheckBox: TCheckBox
Left = 11 Left = 303
Height = 30 Height = 21
Hint = 'Unknown types in form file (DFM/LFM)' Hint = 'If unchecked, there will be interactive dialogs for editing / accepting changes.'
Top = 52 Top = 41
Width = 272 Width = 161
Caption = 'Type Replacements' Caption = 'Replace automatically'
OnClick = TypeReplacementsButtonClick
ParentShowHint = False ParentShowHint = False
ShowHint = True ShowHint = True
TabOrder = 2 TabOrder = 2
end end
object AutoReplaceUnitsCheckBox: TCheckBox object FuncReplaceButton: TBitBtn
Left = 303 Left = 11
Height = 21 Height = 30
Hint = 'If unchecked, there will be interactive dialogs for editing / accepting changes.' Hint = 'Some Delphi functions can be replaced with a LCL function'
Top = 12 Top = 116
Width = 255 Width = 272
Caption = 'Automatic replacement of unit names' Caption = 'Function Replacements'
OnClick = FuncReplaceButtonClick
ParentShowHint = False ParentShowHint = False
ShowHint = True ShowHint = True
TabOrder = 3 TabOrder = 3
end end
object FuncReplacementsButton: TBitBtn object VisualOffsButton: TBitBtn
Left = 11 Left = 11
Height = 30 Height = 30
Hint = 'Some Delphi functions can be replaced with a LCL function' Hint = 'Some Delphi functions can be replaced with a LCL function'
Top = 132 Top = 156
Width = 272 Width = 272
Caption = 'Function Replacements' Caption = 'Top Coordinate Offsets'
OnClick = FuncReplacementsButtonClick OnClick = VisualOffsButtonClick
ParentShowHint = False ParentShowHint = False
ShowHint = True ShowHint = True
TabOrder = 4 TabOrder = 4
end end
object VisualOffsetsButton: TBitBtn object PropRemoveAutoCheckBox: TCheckBox
Left = 11 Left = 303
Height = 30 Height = 21
Hint = 'Some Delphi functions can be replaced with a LCL function' Hint = 'If unchecked, there will be interactive dialogs for editing / accepting changes.'
Top = 92 Top = 4
Width = 272 Width = 161
Caption = 'Top Coordinate Offsets' Caption = 'Remove automatically'
OnClick = VisualOffsetsButtonClick
ParentShowHint = False ParentShowHint = False
ShowHint = True ShowHint = True
TabOrder = 5 TabOrder = 5
end end
object Label1: TLabel
AnchorSideRight.Control = UnitReplaceButton
AnchorSideRight.Side = asrBottom
Left = 135
Height = 16
Top = 6
Width = 148
Anchors = [akTop, akRight]
Caption = 'Unknown properties'
Font.Color = clBtnShadow
Font.Style = [fsBold]
ParentColor = False
ParentFont = False
end
object TypeReplInfoLabel: TLabel
Left = 303
Height = 16
Top = 84
Width = 67
Caption = 'Interactive'
ParentColor = False
end
object VisualOffsEnableCheckBox: TCheckBox
Left = 303
Height = 21
Top = 161
Width = 65
Caption = 'Enable'
TabOrder = 6
end
object FuncReplaceEnableCheckBox: TCheckBox
Left = 303
Height = 21
Hint = 'If unchecked, there will be interactive dialogs for editing / accepting changes.'
Top = 121
Width = 65
Caption = 'Enable'
ParentShowHint = False
ShowHint = True
TabOrder = 7
end
end end
object SettingsGroupBox: TGroupBox object SettingsGroupBox: TGroupBox
Left = 0 Left = 0
@ -109,7 +150,7 @@ object ConvertSettingsForm: TConvertSettingsForm
Left = 11 Left = 11
Height = 112 Height = 112
Hint = 'Converter adds conditional compilation to support different targets' Hint = 'Converter adds conditional compilation to support different targets'
Top = 3 Top = -1
Width = 272 Width = 272
AutoFill = True AutoFill = True
Caption = 'Target' Caption = 'Target'
@ -140,11 +181,12 @@ object ConvertSettingsForm: TConvertSettingsForm
Left = 303 Left = 303
Height = 21 Height = 21
Hint = 'Separate form files allow different properties' Hint = 'Separate form files allow different properties'
Top = 62 Top = 7
Width = 312 Width = 312
BorderSpacing.Left = 13 BorderSpacing.Left = 13
BorderSpacing.Around = 7 BorderSpacing.Around = 7
Caption = 'Lazarus uses the same DFM form file as Delphi' Caption = 'Lazarus uses the same DFM form file as Delphi'
OnChange = SameDFMCheckBoxChange
ParentShowHint = False ParentShowHint = False
ShowHint = True ShowHint = True
TabOrder = 1 TabOrder = 1
@ -197,7 +239,7 @@ object ConvertSettingsForm: TConvertSettingsForm
object ButtonPanel: TButtonPanel object ButtonPanel: TButtonPanel
Left = 6 Left = 6
Height = 39 Height = 39
Top = 417 Top = 438
Width = 625 Width = 625
OKButton.Name = 'OKButton' OKButton.Name = 'OKButton'
OKButton.Caption = '&OK' OKButton.Caption = '&OK'

View File

@ -53,8 +53,10 @@ type
fBackupFiles: boolean; fBackupFiles: boolean;
fTarget: TConvertTarget; fTarget: TConvertTarget;
fSameDFMFile: boolean; fSameDFMFile: boolean;
fAutoReplaceUnits: boolean;
fAutoRemoveProperties: boolean; fAutoRemoveProperties: boolean;
fAutoReplaceUnits: boolean;
fEnableReplaceFuncs: boolean;
fEnableVisualOffs: boolean;
// Delphi units mapped to Lazarus units, will be replaced or removed. // Delphi units mapped to Lazarus units, will be replaced or removed.
fReplaceUnits: TStringToStringTree; fReplaceUnits: TStringToStringTree;
// Delphi types mapped to Lazarus types, will be replaced. // Delphi types mapped to Lazarus types, will be replaced.
@ -94,8 +96,10 @@ type
property BackupFiles: boolean read fBackupFiles; property BackupFiles: boolean read fBackupFiles;
property Target: TConvertTarget read fTarget; property Target: TConvertTarget read fTarget;
property SameDFMFile: boolean read fSameDFMFile; property SameDFMFile: boolean read fSameDFMFile;
property AutoReplaceUnits: boolean read fAutoReplaceUnits;
property AutoRemoveProperties: boolean read fAutoRemoveProperties; property AutoRemoveProperties: boolean read fAutoRemoveProperties;
property AutoReplaceUnits: boolean read fAutoReplaceUnits;
property EnableReplaceFuncs: boolean read fEnableReplaceFuncs;
property EnableVisualOffs: boolean read fEnableVisualOffs;
property ReplaceUnits: TStringToStringTree read fReplaceUnits; property ReplaceUnits: TStringToStringTree read fReplaceUnits;
property ReplaceTypes: TStringToStringTree read fReplaceTypes; property ReplaceTypes: TStringToStringTree read fReplaceTypes;
property VisualOffsets: TStringToStringTree read fVisualOffsets; property VisualOffsets: TStringToStringTree read fVisualOffsets;
@ -106,23 +110,28 @@ type
{ TConvertSettingsForm } { TConvertSettingsForm }
TConvertSettingsForm = class(TForm) TConvertSettingsForm = class(TForm)
AutoReplaceUnitsCheckBox: TCheckBox; PropRemoveAutoCheckBox: TCheckBox;
UnitReplaceAutoCheckBox: TCheckBox;
BackupCheckBox: TCheckBox; BackupCheckBox: TCheckBox;
ButtonPanel: TButtonPanel; ButtonPanel: TButtonPanel;
VisualOffsetsButton: TBitBtn; FuncReplaceEnableCheckBox: TCheckBox;
TypeReplacementsButton: TBitBtn; VisualOffsEnableCheckBox: TCheckBox;
Label1: TLabel;
TypeReplInfoLabel: TLabel;
VisualOffsButton: TBitBtn;
TypeReplaceButton: TBitBtn;
SameDFMCheckBox: TCheckBox; SameDFMCheckBox: TCheckBox;
ProjectPathEdit: TLabeledEdit; ProjectPathEdit: TLabeledEdit;
TargetRadioGroup: TRadioGroup; TargetRadioGroup: TRadioGroup;
FuncReplacementsButton: TBitBtn; FuncReplaceButton: TBitBtn;
UnitReplacementsButton: TBitBtn; UnitReplaceButton: TBitBtn;
SettingsGroupBox: TGroupBox; SettingsGroupBox: TGroupBox;
MissingStuffGroupBox: TGroupBox; MissingStuffGroupBox: TGroupBox;
AutoRemovePropCheckBox: TCheckBox; procedure FuncReplaceButtonClick(Sender: TObject);
procedure FuncReplacementsButtonClick(Sender: TObject); procedure SameDFMCheckBoxChange(Sender: TObject);
procedure TypeReplacementsButtonClick(Sender: TObject); procedure TypeReplaceButtonClick(Sender: TObject);
procedure VisualOffsetsButtonClick(Sender: TObject); procedure VisualOffsButtonClick(Sender: TObject);
procedure UnitReplacementsButtonClick(Sender: TObject); procedure UnitReplaceButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject); procedure FormDestroy(Sender: TObject);
procedure TargetRadioGroupClick(Sender: TObject); procedure TargetRadioGroupClick(Sender: TObject);
@ -297,6 +306,8 @@ begin
fSameDFMFile :=fConfigStorage.GetValue('SameDFMFile', false); fSameDFMFile :=fConfigStorage.GetValue('SameDFMFile', false);
fAutoReplaceUnits :=fConfigStorage.GetValue('AutoReplaceUnits', true); fAutoReplaceUnits :=fConfigStorage.GetValue('AutoReplaceUnits', true);
fAutoRemoveProperties :=fConfigStorage.GetValue('AutoRemoveProperties', true); fAutoRemoveProperties :=fConfigStorage.GetValue('AutoRemoveProperties', true);
fEnableReplaceFuncs :=fConfigStorage.GetValue('EnableReplaceFuncs', true);
fEnableVisualOffs :=fConfigStorage.GetValue('EnableVisualOffs', true);
LoadStringToStringTree(fConfigStorage, 'UnitReplacements/', fReplaceUnits); LoadStringToStringTree(fConfigStorage, 'UnitReplacements/', fReplaceUnits);
LoadStringToStringTree(fConfigStorage, 'TypeReplacements/', fReplaceTypes); LoadStringToStringTree(fConfigStorage, 'TypeReplacements/', fReplaceTypes);
LoadStringToStringTree(fConfigStorage, 'VisualTopOffsets/', fVisualOffsets); LoadStringToStringTree(fConfigStorage, 'VisualTopOffsets/', fVisualOffsets);
@ -395,8 +406,10 @@ begin
fConfigStorage.SetDeleteValue('BackupFiles', fBackupFiles, true); fConfigStorage.SetDeleteValue('BackupFiles', fBackupFiles, true);
fConfigStorage.SetDeleteValue('ConvertTarget', integer(fTarget), 0); fConfigStorage.SetDeleteValue('ConvertTarget', integer(fTarget), 0);
fConfigStorage.SetDeleteValue('SameDFMFile', fSameDFMFile, false); fConfigStorage.SetDeleteValue('SameDFMFile', fSameDFMFile, false);
fConfigStorage.SetDeleteValue('AutoReplaceUnits', fAutoReplaceUnits, false); fConfigStorage.SetDeleteValue('AutoReplaceUnits', fAutoReplaceUnits, true);
fConfigStorage.SetDeleteValue('AutoRemoveProperties', fAutoRemoveProperties, false); fConfigStorage.SetDeleteValue('AutoRemoveProperties', fAutoRemoveProperties, true);
fConfigStorage.SetDeleteValue('EnableReplaceFuncs', fEnableReplaceFuncs, true);
fConfigStorage.SetDeleteValue('EnableVisualOffs', fEnableVisualOffs, true);
SaveStringToStringTree(fConfigStorage, 'UnitReplacements/', fReplaceUnits); SaveStringToStringTree(fConfigStorage, 'UnitReplacements/', fReplaceUnits);
SaveStringToStringTree(fConfigStorage, 'TypeReplacements/', fReplaceTypes); SaveStringToStringTree(fConfigStorage, 'TypeReplacements/', fReplaceTypes);
SaveStringToStringTree(fConfigStorage, 'VisualTopOffsets/', fVisualOffsets); SaveStringToStringTree(fConfigStorage, 'VisualTopOffsets/', fVisualOffsets);
@ -424,16 +437,20 @@ begin
BackupCheckBox.Checked :=fBackupFiles; BackupCheckBox.Checked :=fBackupFiles;
TargetRadioGroup.ItemIndex :=integer(fTarget); TargetRadioGroup.ItemIndex :=integer(fTarget);
SameDFMCheckBox.Checked :=fSameDFMFile; SameDFMCheckBox.Checked :=fSameDFMFile;
AutoReplaceUnitsCheckBox.Checked :=fAutoReplaceUnits; PropRemoveAutoCheckBox.Checked :=fAutoRemoveProperties;
AutoRemovePropCheckBox.Checked :=fAutoRemoveProperties; UnitReplaceAutoCheckBox.Checked :=fAutoReplaceUnits;
FuncReplaceEnableCheckBox.Checked:=fEnableReplaceFuncs;
VisualOffsEnableCheckBox.Checked :=fEnableVisualOffs;
Result:=ShowModal; // Let the user change settings in a form. Result:=ShowModal; // Let the user change settings in a form.
if Result=mrOK then begin if Result=mrOK then begin
// UI --> Settings. Will be saved to ConfigSettings later. // UI --> Settings. Will be saved to ConfigSettings later.
fBackupFiles :=BackupCheckBox.Checked; fBackupFiles :=BackupCheckBox.Checked;
fTarget :=TConvertTarget(TargetRadioGroup.ItemIndex); fTarget :=TConvertTarget(TargetRadioGroup.ItemIndex);
fSameDFMFile :=SameDFMCheckBox.Checked; fSameDFMFile :=SameDFMCheckBox.Checked;
fAutoReplaceUnits :=AutoReplaceUnitsCheckBox.Checked; fAutoRemoveProperties:=PropRemoveAutoCheckBox.Checked;
fAutoRemoveProperties:=AutoRemovePropCheckBox.Checked; fAutoReplaceUnits :=UnitReplaceAutoCheckBox.Checked;
fEnableReplaceFuncs :=FuncReplaceEnableCheckBox.Checked;
fEnableVisualOffs :=VisualOffsEnableCheckBox.Checked;
end; end;
finally finally
Free; Free;
@ -545,32 +562,44 @@ begin
ProjectPathEdit.Text:=''; ProjectPathEdit.Text:='';
ProjectPathEdit.EditLabel.Caption:=lisProjectPath; ProjectPathEdit.EditLabel.Caption:=lisProjectPath;
ProjectPathEdit.Hint:=lisProjectPathHint; ProjectPathEdit.Hint:=lisProjectPathHint;
BackupCheckBox.Caption:=lisBackupChangedFiles; BackupCheckBox.Caption:=lisBackupChangedFiles;
BackupCheckBox.Hint:=lisBackupHint; BackupCheckBox.Hint:=lisBackupHint;
ButtonPanel.OKButton.Caption:=lisStartConversion; ButtonPanel.OKButton.Caption:=lisStartConversion;
ButtonPanel.HelpButton.Caption:=lisMenuHelp; ButtonPanel.HelpButton.Caption:=lisMenuHelp;
ButtonPanel.CancelButton.Caption:=dlgCancel; ButtonPanel.CancelButton.Caption:=dlgCancel;
SameDFMCheckBox.Caption:=lisConvUseSameDFM;
SameDFMCheckBox.Hint:=lisConvUseSameDFMHint;
MissingStuffGroupBox.Caption:= lisReplacements; //lisConvUnitsTypesProp;
PropRemoveAutoCheckBox.Caption:=lisConvAutoRemove;
PropRemoveAutoCheckBox.Hint:=lisConvAutoHint;
UnitReplaceButton.Caption:=lisConvUnitReplacements;
UnitReplaceButton.Hint:=lisConvUnitReplHint;
UnitReplaceAutoCheckBox.Caption:=lisConvAutoReplace; // lisMenuReplace
UnitReplaceAutoCheckBox.Hint:=lisConvAutoHint;
TypeReplaceButton.Caption:=lisConvTypeReplacements;
TypeReplaceButton.Hint:=lisConvTypeReplHint;
TypeReplInfoLabel.Caption:=lisInteractive;
FuncReplaceButton.Caption:=lisConvFuncReplacements;
FuncReplaceButton.Hint:=lisConvFuncReplHint;
FuncReplaceEnableCheckBox.Caption:=lisEnable;
VisualOffsButton.Caption:=lisConvTopCoordOffs;
VisualOffsButton.Hint:=lisConvTopCoordHint;
VisualOffsEnableCheckBox.Caption:=lisEnable;
TargetRadioGroup.Items.Clear; TargetRadioGroup.Items.Clear;
TargetRadioGroup.Items.Append(lisConvertTarget1); TargetRadioGroup.Items.Append(lisConvertTarget1);
TargetRadioGroup.Items.Append(lisConvertTarget2); TargetRadioGroup.Items.Append(lisConvertTarget2);
TargetRadioGroup.Items.Append(lisConvertTarget3); TargetRadioGroup.Items.Append(lisConvertTarget3);
TargetRadioGroup.ItemIndex:=0; TargetRadioGroup.ItemIndex:=0;
TargetRadioGroup.Hint:=lisConvertTargetHint; TargetRadioGroup.Hint:=lisConvertTargetHint;
SameDFMCheckBox.Caption:=lisConvUseSameDFM;
SameDFMCheckBox.Hint:=lisConvUseSameDFMHint;
MissingStuffGroupBox.Caption:= lisConvUnitsTypesProp;
AutoRemovePropCheckBox.Caption:=lisConvAutoRemoveProp;
AutoRemovePropCheckBox.Hint:=lisConvAutoRemovePropHint;
AutoReplaceUnitsCheckBox.Caption:=lisConvAutoReplaceUnits;
AutoReplaceUnitsCheckBox.Hint:=lisConvAutoReplaceUnitHint;
UnitReplacementsButton.Caption:=lisConvUnitReplacements;
UnitReplacementsButton.Hint:=lisConvUnitReplHint;
TypeReplacementsButton.Caption:=lisConvTypeReplacements;
TypeReplacementsButton.Hint:=lisConvTypeReplHint;
VisualOffsetsButton.Caption:=lisConvTopCoordOffs;
VisualOffsetsButton.Hint:=lisConvTopCoordHint;
FuncReplacementsButton.Caption:=lisConvFuncReplacements;
FuncReplacementsButton.Hint:=lisConvFuncReplHint;
TargetRadioGroupClick(TargetRadioGroup); TargetRadioGroupClick(TargetRadioGroup);
end; end;
@ -585,27 +614,36 @@ var
Trg: TConvertTarget; Trg: TConvertTarget;
begin begin
Trg:=TConvertTarget((Sender as TRadioGroup).ItemIndex); Trg:=TConvertTarget((Sender as TRadioGroup).ItemIndex);
if Trg<>ctLazarusAndDelphi then if Trg<>ctLazarusAndDelphi then begin
SameDFMCheckBox.Checked:=false; SameDFMCheckBox.Checked:=false;
end;
SameDFMCheckBox.Enabled:=Trg=ctLazarusAndDelphi; SameDFMCheckBox.Enabled:=Trg=ctLazarusAndDelphi;
end; end;
procedure TConvertSettingsForm.UnitReplacementsButtonClick(Sender: TObject); procedure TConvertSettingsForm.SameDFMCheckBoxChange(Sender: TObject);
begin
if (Sender as TCheckBox).Checked then
VisualOffsEnableCheckBox.Checked:=False;
end;
// Edit replacements in grids
procedure TConvertSettingsForm.UnitReplaceButtonClick(Sender: TObject);
begin begin
EditMap(fSettings.ReplaceUnits, lisConvUnitsToReplace, lisConvDelphiName, lisConvNewName); EditMap(fSettings.ReplaceUnits, lisConvUnitsToReplace, lisConvDelphiName, lisConvNewName);
end; end;
procedure TConvertSettingsForm.TypeReplacementsButtonClick(Sender: TObject); procedure TConvertSettingsForm.TypeReplaceButtonClick(Sender: TObject);
begin begin
EditMap(fSettings.ReplaceTypes, lisConvTypesToReplace, lisConvDelphiName, lisConvNewName); EditMap(fSettings.ReplaceTypes, lisConvTypesToReplace, lisConvDelphiName, lisConvNewName);
end; end;
procedure TConvertSettingsForm.VisualOffsetsButtonClick(Sender: TObject); procedure TConvertSettingsForm.VisualOffsButtonClick(Sender: TObject);
begin begin
EditMap(fSettings.VisualOffsets, lisConvTopCoordOffs, lisConvParentContainer, lisConvTopCoordOff); EditMap(fSettings.VisualOffsets, lisConvTopCoordOffs, lisConvParentContainer, lisConvTopCoordOff);
end; end;
procedure TConvertSettingsForm.FuncReplacementsButtonClick(Sender: TObject); procedure TConvertSettingsForm.FuncReplaceButtonClick(Sender: TObject);
begin begin
EditFuncReplacements(fSettings.ReplaceFuncs, lisConvFuncsToReplace); EditFuncReplacements(fSettings.ReplaceFuncs, lisConvFuncsToReplace);
end; end;

View File

@ -454,7 +454,7 @@ begin
until (Result in [mrOK, mrCancel]) or (LoopCount=10); until (Result in [mrOK, mrCancel]) or (LoopCount=10);
// Show remaining errors to user. // Show remaining errors to user.
WriteLFMErrors; WriteLFMErrors;
if Result=mrOK then begin if (Result=mrOK) and fSettings.EnableVisualOffs then begin
// Fix top offsets of some components in visual containers // Fix top offsets of some components in visual containers
if ConvTool.CheckTopOffsets(fLFMBuffer, fLFMTree, if ConvTool.CheckTopOffsets(fLFMBuffer, fLFMTree,
fSettings.VisualOffsets, ValueTreeNodes) then fSettings.VisualOffsets, ValueTreeNodes) then

View File

@ -465,11 +465,9 @@ resourcestring
lisConvertTargetHint = 'Converter adds conditional compilation to support different targets'; lisConvertTargetHint = 'Converter adds conditional compilation to support different targets';
lisConvUseSameDFM = 'Lazarus uses the same DFM form file as Delphi'; lisConvUseSameDFM = 'Lazarus uses the same DFM form file as Delphi';
lisConvUseSameDFMHint = 'Separate form files allow different properties'; lisConvUseSameDFMHint = 'Separate form files allow different properties';
lisConvUnitsTypesProp = 'Units, Types and Properties'; lisConvAutoReplace = 'Replace automatically';
lisConvAutoRemoveProp = 'Automatic removal of unknown properties'; lisConvAutoRemove = 'Remove automatically';
lisConvAutoRemovePropHint = 'If unchecked, there will be interactive dialogs for editing / accepting changes'; lisConvAutoHint = 'If unchecked, there will be interactive dialogs for editing / accepting changes';
lisConvAutoReplaceUnits = 'Automatic replacement of unit names';
lisConvAutoReplaceUnitHint = 'If unchecked, there will be interactive dialogs for editing / accepting changes.';
lisConvUnitsToReplace = 'Units to replace'; lisConvUnitsToReplace = 'Units to replace';
lisConvTypesToReplace = 'Types to replace'; lisConvTypesToReplace = 'Types to replace';
lisConvTopCoordOff = 'Top coordinate offset'; lisConvTopCoordOff = 'Top coordinate offset';
@ -488,6 +486,8 @@ resourcestring
lisConvDelphiFunc = 'Delphi Function'; lisConvDelphiFunc = 'Delphi Function';
lisReplacement = 'Replacement'; lisReplacement = 'Replacement';
lisReplacements = 'Replacements'; lisReplacements = 'Replacements';
lisInteractive = 'Interactive';
lisEnable = 'Enable';
lisProperties = 'Properties (replace or delete)'; lisProperties = 'Properties (replace or delete)';
lisTypes = 'Types (not removed if no replacement)'; lisTypes = 'Types (not removed if no replacement)';
lisReplaceRemoveUnknown = 'Fix unknown properties and types'; lisReplaceRemoveUnknown = 'Fix unknown properties and types';