Converter: add a setting for putting a comment after a replaced function.

git-svn-id: trunk@40580 -
This commit is contained in:
juha 2013-03-17 23:33:03 +00:00
parent 62e85ec021
commit 22cf9232b4
3 changed files with 138 additions and 116 deletions

View File

@ -436,7 +436,7 @@ var
end;
function GetComment(const aStr: string; aPossibleStartPos: integer): string;
// Extract and return a possible comment.
// Extract and return a possible comment from replacement function definition.
var
CommChBeg, CommBeg, CommEnd, i: Integer; // Start and end of comment.
begin
@ -476,10 +476,13 @@ begin
// Replace only if the params match somehow, so eg. a variable is not replaced.
if (FuncInfo.Params.Count>0) or (ReplacementParams.Count=0) then begin
NewFunc:=InsertParams2Replacement(FuncInfo);
Comment:=GetComment(FuncInfo.ReplFunc, PossibleCommentPos);
// Separate function body
NewFunc:=Format('%s%s { *Converted from %s* %s }',
[NewFunc, FuncInfo.InclSemiColon, FuncInfo.FuncName, Comment]);
NewFunc:=NewFunc+FuncInfo.InclSemiColon;
if fCTLink.fSettings.FuncReplaceComment then
NewFunc:=NewFunc+' { *Converted from '+FuncInfo.FuncName+'* }';
Comment:=GetComment(FuncInfo.ReplFunc, PossibleCommentPos);
if Comment<>'' then // Possible comment from the configuration
NewFunc:=NewFunc+' { ' +Comment+' }';
// Old function call with params for IDE message output.
s:=copy(fCTLink.CodeTool.Src, FuncInfo.StartPos, FuncInfo.EndPos-FuncInfo.StartPos);
s:=StringReplace(s, LineEnding, '', [rfReplaceAll]);

View File

@ -1,14 +1,14 @@
object ConvertSettingsForm: TConvertSettingsForm
Left = 315
Height = 355
Height = 361
Top = 127
Width = 599
Width = 577
ActiveControl = ProjectPathEdit
Caption = 'Convert Delphi unit, project or package '
ClientHeight = 355
ClientWidth = 599
Constraints.MinHeight = 300
Constraints.MinWidth = 400
ClientHeight = 361
ClientWidth = 577
Constraints.MinHeight = 328
Constraints.MinWidth = 544
OnCreate = FormCreate
OnDestroy = FormDestroy
Position = poScreenCenter
@ -17,10 +17,10 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideLeft.Control = Owner
AnchorSideRight.Control = UnitReplaceDivider
Left = 9
Height = 21
Height = 23
Hint = 'Directory where project''s main file must be'
Top = 32
Width = 330
Width = 293
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 9
BorderSpacing.Right = 9
@ -32,9 +32,9 @@ object ConvertSettingsForm: TConvertSettingsForm
EditLabel.AnchorSideRight.Side = asrBottom
EditLabel.AnchorSideBottom.Control = ProjectPathEdit
EditLabel.Left = 9
EditLabel.Height = 13
EditLabel.Top = 12
EditLabel.Width = 330
EditLabel.Height = 15
EditLabel.Top = 10
EditLabel.Width = 293
EditLabel.Caption = 'Project Path:'
EditLabel.ParentColor = False
LabelSpacing = 7
@ -48,10 +48,10 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideTop.Control = TargetGroupBox
AnchorSideTop.Side = asrBottom
Left = 12
Height = 17
Height = 20
Hint = 'Creates a Backup directory under project directory'
Top = 166
Width = 159
Top = 177
Width = 214
BorderSpacing.Left = 3
BorderSpacing.Top = 9
Caption = 'Make backup of changed files'
@ -63,9 +63,9 @@ object ConvertSettingsForm: TConvertSettingsForm
end
object ButtonPanel1: TButtonPanel
Left = 6
Height = 34
Top = 315
Width = 587
Height = 41
Top = 314
Width = 565
OKButton.Name = 'OKButton'
OKButton.DefaultCaption = True
HelpButton.Name = 'HelpButton'
@ -84,10 +84,10 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideTop.Control = BackupCheckBox
AnchorSideTop.Side = asrBottom
Left = 12
Height = 17
Height = 20
Hint = 'Separate form files allow different properties'
Top = 188
Width = 185
Top = 202
Width = 245
BorderSpacing.Top = 5
Caption = 'Keep converted files open in editor'
ParentShowHint = False
@ -95,7 +95,7 @@ object ConvertSettingsForm: TConvertSettingsForm
TabOrder = 3
end
object UnitReplaceDivider: TDividerBevel
Left = 348
Left = 311
Height = 17
Top = 9
Width = 239
@ -114,7 +114,7 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = UnitReplaceDivider
AnchorSideRight.Side = asrBottom
Left = 348
Left = 311
Height = 17
Top = 65
Width = 239
@ -131,7 +131,7 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideLeft.Control = UnitReplaceDivider
AnchorSideTop.Control = UnitReplaceDivider
AnchorSideTop.Side = asrBottom
Left = 349
Left = 312
Height = 25
Hint = 'Unit names in uses section of a source unit'
Top = 27
@ -150,7 +150,7 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = UnitReplaceDivider
AnchorSideRight.Side = asrBottom
Left = 348
Left = 311
Height = 17
Top = 121
Width = 239
@ -167,7 +167,7 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideLeft.Control = TypeReplaceDivider
AnchorSideTop.Control = TypeReplaceDivider
AnchorSideTop.Side = asrBottom
Left = 349
Left = 312
Height = 25
Hint = 'Unknown types in form file (DFM/LFM)'
Top = 139
@ -186,7 +186,7 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = UnitReplaceDivider
AnchorSideRight.Side = asrBottom
Left = 348
Left = 311
Height = 17
Top = 177
Width = 239
@ -205,13 +205,13 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = UnitReplaceDivider
AnchorSideRight.Side = asrBottom
Left = 348
Left = 311
Height = 17
Top = 233
Top = 249
Width = 239
Caption = 'Coordinate Offsets'
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 39
BorderSpacing.Top = 55
Font.Style = [fsBold]
ParentFont = False
ParentShowHint = False
@ -222,7 +222,7 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideLeft.Control = FuncReplaceDivider
AnchorSideTop.Control = FuncReplaceDivider
AnchorSideTop.Side = asrBottom
Left = 349
Left = 312
Height = 25
Hint = 'Some Delphi functions can be replaced with a LCL function'
Top = 195
@ -239,10 +239,10 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideLeft.Control = CoordOffsDivider
AnchorSideTop.Control = CoordOffsDivider
AnchorSideTop.Side = asrBottom
Left = 349
Left = 312
Height = 25
Hint = 'Some Delphi functions can be replaced with a LCL function'
Top = 251
Top = 267
Width = 75
BorderSpacing.Left = 1
BorderSpacing.Top = 1
@ -257,15 +257,15 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideTop.Control = ProjectPathEdit
AnchorSideTop.Side = asrBottom
Left = 9
Height = 93
Height = 102
Hint = 'xxx'
Top = 64
Width = 165
Top = 66
Width = 218
AutoSize = True
BorderSpacing.Top = 11
Caption = 'Target'
ClientHeight = 75
ClientWidth = 161
ClientHeight = 84
ClientWidth = 210
ParentShowHint = False
ShowHint = True
TabOrder = 8
@ -274,9 +274,9 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideTop.Control = CrossPlatformCheckBox
AnchorSideTop.Side = asrBottom
Left = 6
Height = 17
Top = 29
Width = 88
Height = 20
Top = 32
Width = 120
BorderSpacing.Top = 6
BorderSpacing.Right = 6
Caption = 'Support Delphi'
@ -291,9 +291,9 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideTop.Side = asrBottom
AnchorSideRight.Side = asrBottom
Left = 6
Height = 17
Top = 52
Width = 149
Height = 20
Top = 58
Width = 198
BorderSpacing.Top = 6
BorderSpacing.Right = 6
BorderSpacing.Bottom = 6
@ -307,9 +307,9 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideLeft.Control = TargetGroupBox
AnchorSideTop.Control = TargetGroupBox
Left = 6
Height = 17
Height = 20
Top = 6
Width = 89
Width = 118
BorderSpacing.Left = 6
BorderSpacing.Top = 6
BorderSpacing.Right = 6
@ -324,12 +324,12 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = UnitReplaceButton
AnchorSideTop.Side = asrCenter
Left = 447
Height = 21
Top = 29
Left = 410
Height = 27
Top = 26
Width = 136
BorderSpacing.Left = 23
ItemHeight = 13
ItemHeight = 0
Style = csDropDownList
TabOrder = 9
end
@ -337,12 +337,12 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideLeft.Control = UnitReplaceComboBox
AnchorSideTop.Control = UnknownPropsDivider
AnchorSideTop.Side = asrBottom
Left = 447
Height = 21
Left = 410
Height = 27
Top = 84
Width = 136
BorderSpacing.Top = 2
ItemHeight = 13
ItemHeight = 0
Style = csDropDownList
TabOrder = 10
end
@ -351,12 +351,12 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = FuncReplaceButton
AnchorSideTop.Side = asrCenter
Left = 447
Height = 21
Top = 197
Left = 410
Height = 27
Top = 194
Width = 136
BorderSpacing.Left = 23
ItemHeight = 13
ItemHeight = 0
Style = csDropDownList
TabOrder = 11
end
@ -365,12 +365,12 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = CoordOffsButton
AnchorSideTop.Side = asrCenter
Left = 447
Height = 21
Top = 253
Left = 410
Height = 27
Top = 266
Width = 136
BorderSpacing.Left = 23
ItemHeight = 13
ItemHeight = 0
Style = csDropDownList
TabOrder = 12
end
@ -379,12 +379,12 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = TypeReplaceButton
AnchorSideTop.Side = asrCenter
Left = 447
Height = 21
Top = 141
Left = 410
Height = 27
Top = 138
Width = 136
BorderSpacing.Left = 23
ItemHeight = 13
ItemHeight = 0
Style = csDropDownList
TabOrder = 13
end
@ -393,9 +393,9 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = KeepFileOpenCheckBox
AnchorSideTop.Side = asrBottom
Left = 142
Left = 182
Height = 20
Top = 229
Top = 246
Width = 102
BorderSpacing.Left = 6
BorderSpacing.Top = 24
@ -407,9 +407,9 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideTop.Control = ScanProgressBar
AnchorSideTop.Side = asrCenter
Left = 12
Height = 13
Top = 233
Width = 124
Height = 15
Top = 249
Width = 164
Caption = 'Scanning parent directory'
ParentColor = False
end
@ -419,9 +419,9 @@ object ConvertSettingsForm: TConvertSettingsForm
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = ScanProgressBar
AnchorSideRight.Side = asrBottom
Left = 142
Left = 182
Height = 25
Top = 250
Top = 267
Width = 102
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 1
@ -429,4 +429,16 @@ object ConvertSettingsForm: TConvertSettingsForm
OnClick = StopScanButtonClick
TabOrder = 15
end
object FuncReplaceCommentCB: TCheckBox
AnchorSideLeft.Control = FuncReplaceButton
AnchorSideTop.Control = FuncReplaceButton
AnchorSideTop.Side = asrBottom
Left = 312
Height = 20
Top = 225
Width = 230
BorderSpacing.Top = 5
Caption = 'Add comment after replacement'
TabOrder = 16
end
end

View File

@ -56,11 +56,12 @@ type
fConfigStorage: TConfigStorage;
fSettingsForm: TConvertSettingsForm;
// Actual user settings.
fBackupFiles: boolean;
fKeepFileOpen: boolean;
fCrossPlatform: boolean;
fSupportDelphi: boolean;
fSameDfmFile: boolean;
fBackupFiles: Boolean;
fKeepFileOpen: Boolean;
fCrossPlatform: Boolean;
fSupportDelphi: Boolean;
fSameDfmFile: Boolean;
fFuncReplaceComment: Boolean;
// Modes for replacements:
fUnitsReplaceMode: TReplaceModeLong;
fPropReplaceMode: TReplaceModeLong;
@ -88,16 +89,16 @@ type
// Lazarus file name based on Delphi file name, keep suffix.
function DelphiToLazFilename(const DelphiFilename: string;
LowercaseFilename: boolean): string; overload;
LowercaseFilename: Boolean): string; overload;
// Lazarus file name based on Delphi file name with new suffix.
function DelphiToLazFilename(const DelphiFilename, LazExt: string;
LowercaseFilename: boolean): string; overload;
LowercaseFilename: Boolean): string; overload;
// Create Lazarus file name and copy/rename from Delphi file, keep suffix.
function RenameDelphiToLazFile(const DelphiFilename: string;
out LazFilename: string; LowercaseFilename: boolean): TModalResult; overload;
out LazFilename: string; LowercaseFilename: Boolean): TModalResult; overload;
// Create Lazarus file name and copy/rename from Delphi file with new suffix.
function RenameDelphiToLazFile(const DelphiFilename, LazExt: string;
out LazFilename: string; LowercaseFilename: boolean): TModalResult; overload;
out LazFilename: string; LowercaseFilename: Boolean): TModalResult; overload;
function RenameFile(const SrcFilename, DestFilename: string): TModalResult;
function BackupFile(const AFilename: string): TModalResult;
@ -106,11 +107,12 @@ type
property MainPath: String read fMainPath;
property BackupPath: String read GetBackupPath;
property Enabled: Boolean read fEnabled write SetEnabled;
property BackupFiles: boolean read fBackupFiles;
property KeepFileOpen: boolean read fKeepFileOpen;
property CrossPlatform: boolean read fCrossPlatform;
property SupportDelphi: boolean read fSupportDelphi;
property SameDfmFile: boolean read fSameDfmFile;
property BackupFiles: Boolean read fBackupFiles;
property KeepFileOpen: Boolean read fKeepFileOpen;
property CrossPlatform: Boolean read fCrossPlatform;
property SupportDelphi: Boolean read fSupportDelphi;
property SameDfmFile: Boolean read fSameDfmFile;
property FuncReplaceComment: Boolean read fFuncReplaceComment;
property UnitsReplaceMode: TReplaceModeLong read fUnitsReplaceMode;
property PropReplaceMode: TReplaceModeLong read fPropReplaceMode;
property TypeReplaceMode: TReplaceModeAllow read fTypeReplaceMode;
@ -127,6 +129,7 @@ type
{ TConvertSettingsForm }
TConvertSettingsForm = class(TForm)
FuncReplaceCommentCB: TCheckBox;
StopScanButton: TBitBtn;
CoordOffsComboBox: TComboBox;
ScanLabel: TLabel;
@ -394,8 +397,9 @@ begin
fCrossPlatform :=fConfigStorage.GetValue('CrossPlatform', true);
fSupportDelphi :=fConfigStorage.GetValue('SupportDelphi', false);
fSameDfmFile :=fConfigStorage.GetValue('SameDfmFile', false);
fFuncReplaceComment :=fConfigStorage.GetValue('FuncReplaceComment', true);
fUnitsReplaceMode:=TReplaceModeLong(fConfigStorage.GetValue('UnitsReplaceMode', 2));
fPropReplaceMode:=TReplaceModeLong(fConfigStorage.GetValue('UnknownPropsMode', 2));
fPropReplaceMode :=TReplaceModeLong(fConfigStorage.GetValue('UnknownPropsMode', 2));
fTypeReplaceMode:=TReplaceModeAllow(fConfigStorage.GetValue('TypeReplaceMode', 1));
fFuncReplaceMode:=TReplaceModeShort(fConfigStorage.GetValue('FuncReplaceMode', 1));
fCoordOffsMode :=TReplaceModeShort(fConfigStorage.GetValue('CoordOffsMode', 1));
@ -615,11 +619,12 @@ end;
destructor TConvertSettings.Destroy;
begin
// Save possibly modified settings to ConfigStorage.
fConfigStorage.SetDeleteValue('BackupFiles', fBackupFiles, true);
fConfigStorage.SetDeleteValue('KeepFileOpen', fKeepFileOpen, false);
fConfigStorage.SetDeleteValue('CrossPlatform', fCrossPlatform, true);
fConfigStorage.SetDeleteValue('SupportDelphi', fSupportDelphi, false);
fConfigStorage.SetDeleteValue('SameDfmFile', fSameDfmFile, false);
fConfigStorage.SetDeleteValue('BackupFiles', fBackupFiles, true);
fConfigStorage.SetDeleteValue('KeepFileOpen', fKeepFileOpen, false);
fConfigStorage.SetDeleteValue('CrossPlatform', fCrossPlatform, true);
fConfigStorage.SetDeleteValue('SupportDelphi', fSupportDelphi, false);
fConfigStorage.SetDeleteValue('SameDfmFile', fSameDfmFile, false);
fConfigStorage.SetDeleteValue('FuncReplaceComment',fFuncReplaceComment, true);
fConfigStorage.SetDeleteValue('UnitsReplaceMode', integer(fUnitsReplaceMode), 2);
fConfigStorage.SetDeleteValue('UnknownPropsMode', integer(fPropReplaceMode), 2);
fConfigStorage.SetDeleteValue('TypeReplaceMode', integer(fTypeReplaceMode), 1);
@ -656,26 +661,28 @@ begin
Caption:=fTitle + ' - ' + ExtractFileName(fMainFilename);
ProjectPathEdit.Text:=fMainPath;
// Settings --> UI. Loaded from ConfigSettings earlier.
BackupCheckBox.Checked :=fBackupFiles;
KeepFileOpenCheckBox.Checked :=fKeepFileOpen;
CrossPlatformCheckBox.Checked :=fCrossPlatform;
SupportDelphiCheckBox.Checked :=fSupportDelphi;
SameDfmCheckBox.Checked :=fSameDfmFile;
UnitReplaceComboBox.ItemIndex :=integer(fUnitsReplaceMode);
UnknownPropsComboBox.ItemIndex :=integer(fPropReplaceMode);
TypeReplaceComboBox.ItemIndex :=integer(fTypeReplaceMode);
FuncReplaceComboBox.ItemIndex :=integer(fFuncReplaceMode);
CoordOffsComboBox.ItemIndex :=integer(fCoordOffsMode);
BackupCheckBox.Checked :=fBackupFiles;
KeepFileOpenCheckBox.Checked :=fKeepFileOpen;
CrossPlatformCheckBox.Checked :=fCrossPlatform;
SupportDelphiCheckBox.Checked :=fSupportDelphi;
SameDfmCheckBox.Checked :=fSameDfmFile;
FuncReplaceCommentCB.Checked :=fFuncReplaceComment;
UnitReplaceComboBox.ItemIndex :=integer(fUnitsReplaceMode);
UnknownPropsComboBox.ItemIndex :=integer(fPropReplaceMode);
TypeReplaceComboBox.ItemIndex :=integer(fTypeReplaceMode);
FuncReplaceComboBox.ItemIndex :=integer(fFuncReplaceMode);
CoordOffsComboBox.ItemIndex :=integer(fCoordOffsMode);
SupportDelphiCheckBoxChange(SupportDelphiCheckBox);
SameDfmCheckBoxChange(SameDfmCheckBox);
Result:=ShowModal; // Let the user change settings in a form.
if Result=mrOK then begin // The thread will finished before the form closes.
// UI --> Settings. Will be saved to ConfigSettings later.
fBackupFiles :=BackupCheckBox.Checked;
fKeepFileOpen :=KeepFileOpenCheckBox.Checked;
fCrossPlatform :=CrossPlatformCheckBox.Checked;
fSupportDelphi :=SupportDelphiCheckBox.Checked;
fSameDfmFile :=SameDfmCheckBox.Checked;
fBackupFiles :=BackupCheckBox.Checked;
fKeepFileOpen :=KeepFileOpenCheckBox.Checked;
fCrossPlatform :=CrossPlatformCheckBox.Checked;
fSupportDelphi :=SupportDelphiCheckBox.Checked;
fSameDfmFile :=SameDfmCheckBox.Checked;
fFuncReplaceComment:=FuncReplaceCommentCB.Checked;
fUnitsReplaceMode:=TReplaceModeLong(UnitReplaceComboBox.ItemIndex);
fPropReplaceMode :=TReplaceModeLong(UnknownPropsComboBox.ItemIndex);
fTypeReplaceMode :=TReplaceModeAllow(TypeReplaceComboBox.ItemIndex);
@ -689,13 +696,13 @@ begin
end;
function TConvertSettings.DelphiToLazFilename(const DelphiFilename: string;
LowercaseFilename: boolean): string;
LowercaseFilename: Boolean): string;
begin
Result:=DelphiToLazFilename(DelphiFilename,'',LowercaseFilename);
end;
function TConvertSettings.DelphiToLazFilename(const DelphiFilename, LazExt: string;
LowercaseFilename: boolean): string;
LowercaseFilename: Boolean): string;
var
RelPath, SubPath, fn: string;
begin
@ -711,13 +718,13 @@ begin
end;
function TConvertSettings.RenameDelphiToLazFile(const DelphiFilename: string;
out LazFilename: string; LowercaseFilename: boolean): TModalResult;
out LazFilename: string; LowercaseFilename: Boolean): TModalResult;
begin
Result:=RenameDelphiToLazFile(DelphiFilename,'',LazFilename,LowercaseFilename);
end;
function TConvertSettings.RenameDelphiToLazFile(const DelphiFilename, LazExt: string;
out LazFilename: string; LowercaseFilename: boolean): TModalResult;
out LazFilename: string; LowercaseFilename: Boolean): TModalResult;
var
RelPath, SubPath, fn: string;
begin
@ -869,7 +876,7 @@ end;
procedure TConvertSettingsForm.SupportDelphiCheckBoxChange(Sender: TObject);
var
Chk: boolean;
Chk: Boolean;
begin
Chk:=(Sender as TCheckBox).Checked;
SameDfmCheckBox.Enabled:=Chk;
@ -879,7 +886,7 @@ end;
procedure TConvertSettingsForm.SameDfmCheckBoxChange(Sender: TObject);
var
Chk: boolean;
Chk: Boolean;
begin
Chk:=(Sender as TCheckBox).Checked;
if Chk then