From 2e04a02ac4c79898c09a6b78ee36c13ba4ee88da Mon Sep 17 00:00:00 2001 From: juha Date: Fri, 26 Feb 2010 20:00:42 +0000 Subject: [PATCH] Added convert target radiobuttons and Lazarus for Windows target. git-svn-id: trunk@23799 - --- .gitattributes | 4 +- converter/convcodetool.pas | 94 +++++++++---------- converter/convertdelphi.pas | 4 +- converter/convertsettings.lfm | 54 ++++++++--- converter/convertsettings.pas | 13 ++- ...{missingunitsunit.lfm => missingunits.lfm} | 0 ...{missingunitsunit.pas => missingunits.pas} | 2 +- 7 files changed, 100 insertions(+), 71 deletions(-) rename converter/{missingunitsunit.lfm => missingunits.lfm} (100%) rename converter/{missingunitsunit.pas => missingunits.pas} (99%) diff --git a/.gitattributes b/.gitattributes index d0f5351b07..8d0675c92e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2211,8 +2211,8 @@ converter/convertdelphi.pas svneol=native#text/plain converter/convertsettings.lfm svneol=native#text/plain converter/convertsettings.pas svneol=native#text/plain converter/lazxmlforms.pas svneol=native#text/plain -converter/missingunitsunit.lfm svneol=native#text/plain -converter/missingunitsunit.pas svneol=native#text/plain +converter/missingunits.lfm svneol=native#text/plain +converter/missingunits.pas svneol=native#text/plain debian/README.Debian svneol=native#text/plain debian/README.source svneol=native#text/plain debian/changelog svneol=native#text/plain diff --git a/converter/convcodetool.pas b/converter/convcodetool.pas index bafb7ea78e..6f77c8a3e1 100644 --- a/converter/convcodetool.pas +++ b/converter/convcodetool.pas @@ -13,7 +13,8 @@ uses CodeToolManager, StdCodeTools, CodeTree, CodeAtom, FindDeclarationTool, PascalReaderTool, PascalParserTool, CodeBeautifier, ExprEval, KeywordFuncLists, BasicCodeTools, LinkScanner, - CodeCache, SourceChanger, CustomCodeTool, CodeToolsStructs, EventCodeTool; + CodeCache, SourceChanger, CustomCodeTool, CodeToolsStructs, EventCodeTool, + ConvertSettings; type @@ -28,7 +29,7 @@ type fHasFormFile: boolean; fFormFileRename: boolean; fLowerCaseRes: boolean; - fKeepDelphiCompat: boolean; + fTarget: TConvertTarget; // List of units to remove. fUnitsToRemove: TStringList; // Units to rename. Map of unit name -> real unit name. @@ -54,7 +55,7 @@ type property FormFileRename: boolean read fFormFileRename write fFormFileRename; property HasFormFile: boolean read fHasFormFile write fHasFormFile; property LowerCaseRes: boolean read fLowerCaseRes write fLowerCaseRes; - property KeepDelphiCompat: boolean read fKeepDelphiCompat write fKeepDelphiCompat; + property Target: TConvertTarget read fTarget write fTarget; property UnitsToRemove: TStringList read fUnitsToRemove write fUnitsToRemove; property UnitsToRename: TStringToStringTree read fUnitsToRename write fUnitsToRename; property UnitsToAdd: TStringList read fUnitsToAdd write fUnitsToAdd; @@ -72,7 +73,7 @@ begin fAsk:=true; fLowerCaseRes:=false; fFormFileRename:=false; - fKeepDelphiCompat:=false; + fTarget:=ctLazarus; fUnitsToComment:=nil; fUnitsToRename:=nil; // Initialize codetools. (Copied from TCodeToolManager.) @@ -113,11 +114,8 @@ end; function TConvDelphiCodeTool.Convert: TModalResult; // add {$mode delphi} directive -// remove windows unit and add LResources, LCLIntf // remove {$R *.dfm} or {$R *.xfm} directive // Change {$R *.RES} to {$R *.res} if needed -// add initialization -// add {$i unit.lrs} directive // TODO: fix delphi ambiguousities like incomplete proc implementation headers begin Result:=mrCancel; @@ -149,6 +147,7 @@ begin end; function TConvDelphiCodeTool.AddDelphiAndLCLSections: boolean; +// add, remove and rename units for desired target. var WinOnlyUnits: TStringList; // Windows and LCL specific units. LclOnlyUnits: TStringList; @@ -170,45 +169,46 @@ begin InsPos:=fCodeTool.CurPos.StartPos; IsWinUnit:=fCodeTool.FindUnitInUsesSection(UsesNode,'WINDOWS',Junk,Junk); IsVariantUnit:=fCodeTool.FindUnitInUsesSection(UsesNode,'VARIANTS',Junk,Junk); - if fKeepDelphiCompat then begin - // Make separate sections for LCL and Windows units. - if IsWinUnit then begin - WinOnlyUnits.Append('Windows'); - LclOnlyUnits.Append('LCLIntf'); - LclOnlyUnits.Append('LCLType'); - LclOnlyUnits.Append('LMessages'); - fCodeTool.RemoveUnitFromUsesSection(UsesNode, 'WINDOWS', fSrcCache); - end; - if IsVariantUnit then - WinOnlyUnits.Append('Variants'); - if fHasFormFile then - LclOnlyUnits.Append('LResources'); - if (LclOnlyUnits.Count>0) or (WinOnlyUnits.Count>0) then begin - // Add Windows and LCL sections for output. - nl:=fSrcCache.BeautifyCodeOptions.LineEnd; - s:='{$IFDEF LCL}'+nl+' '; - for i:=0 to LclOnlyUnits.Count-1 do - s:=s+LclOnlyUnits[i]+', '; - s:=s+nl+'{$ELSE}'+nl+' '; - for i:=0 to WinOnlyUnits.Count-1 do - s:=s+WinOnlyUnits[i]+', '; - s:=s+nl+'{$ENDIF}'; - // Now add the lines using codetools. - if not fSrcCache.Replace(gtEmptyLine,gtNewLine,InsPos,InsPos,s) then exit; - end; - end - else begin - // One way conversion: just add, replace and remove units. - if IsWinUnit then begin - fUnitsToRemove.Append('WINDOWS'); - fUnitsToAdd.Append('LCLIntf'); - fUnitsToAdd.Append('LCLType'); - fUnitsToAdd.Append('LMessages'); - end; - if IsVariantUnit then - fUnitsToRemove.Append('VARIANTS'); - if fHasFormFile then - fUnitsToAdd.Append('LResources'); + case fTarget of + ctLazarus: begin + // One way conversion: just add, replace and remove units. + if IsWinUnit then begin + fUnitsToRemove.Append('WINDOWS'); + fUnitsToAdd.Append('LCLIntf'); + fUnitsToAdd.Append('LCLType'); + fUnitsToAdd.Append('LMessages'); + end; + if IsVariantUnit then + fUnitsToRemove.Append('VARIANTS'); + end; + ctLazarusWin: begin + // Don't do anything. Delphi units work for Lazarus under Windows. + end; + ctLazarusAndDelphi: begin + // Make separate sections for LCL and Windows units. + if IsWinUnit then begin + WinOnlyUnits.Append('Windows'); + LclOnlyUnits.Append('LCLIntf'); + LclOnlyUnits.Append('LCLType'); + LclOnlyUnits.Append('LMessages'); + fCodeTool.RemoveUnitFromUsesSection(UsesNode, 'WINDOWS', fSrcCache); + end; + if IsVariantUnit then + WinOnlyUnits.Append('Variants'); + if (LclOnlyUnits.Count>0) or (WinOnlyUnits.Count>0) then begin + // Add Windows and LCL sections for output. + nl:=fSrcCache.BeautifyCodeOptions.LineEnd; + s:='{$IFDEF LCL}'+nl+' '; + for i:=0 to LclOnlyUnits.Count-1 do + s:=s+LclOnlyUnits[i]+', '; + s:=s+nl+'{$ELSE}'+nl+' '; + for i:=0 to WinOnlyUnits.Count-1 do + s:=s+WinOnlyUnits[i]+', '; + s:=s+nl+'{$ENDIF}'; + // Now add the lines using codetools. + if not fSrcCache.Replace(gtEmptyLine,gtNewLine,InsPos,InsPos,s) then exit; + end; + end; end; end; Result:=true; @@ -236,7 +236,7 @@ begin ReadNextAtom; // semicolon InsertPos:=CurPos.EndPos; nl:=fSrcCache.BeautifyCodeOptions.LineEnd; - if fKeepDelphiCompat then + if fTarget=ctLazarusAndDelphi then fSrcCache.Replace(gtEmptyLine,gtEmptyLine,InsertPos,InsertPos, '{$IFDEF LCL}'+nl+' {$MODE Delphi}'+nl+'{$ENDIF}') else diff --git a/converter/convertdelphi.pas b/converter/convertdelphi.pas index 1d7ae20dda..ff5d81ba29 100644 --- a/converter/convertdelphi.pas +++ b/converter/convertdelphi.pas @@ -41,7 +41,7 @@ uses // IDEIntf ComponentReg, IDEMsgIntf, MainIntf, LazIDEIntf, PackageIntf, ProjectIntf, // IDE - IDEProcs, MissingUnitsUnit, Project, DialogProcs, CheckLFMDlg, + IDEProcs, MissingUnits, Project, DialogProcs, CheckLFMDlg, EditorOptions, CompilerOptions, PackageDefs, PackageSystem, PackageEditor, BasePkgManager, LazarusIDEStrConsts, ConvertSettings, ConvCodeTool; @@ -613,7 +613,7 @@ begin ConvTool.LowerCaseRes:=FileExistsUTF8(ChangeFileExt(fLazUnitFilename, '.res')); ConvTool.HasFormFile:=DfmFilename<>''; ConvTool.FormFileRename:=fSettings.FormFileRename and (DfmFilename<>''); - ConvTool.KeepDelphiCompat:=fSettings.KeepDelphiCompatible; + ConvTool.Target:=fSettings.Target; ConvTool.UnitsToRemove:=fUnitsToRemove; ConvTool.UnitsToRename:=fUnitsToRename; ConvTool.UnitsToAdd:=fUnitsToAdd; diff --git a/converter/convertsettings.lfm b/converter/convertsettings.lfm index 1dd430473e..3eee31d8c3 100644 --- a/converter/convertsettings.lfm +++ b/converter/convertsettings.lfm @@ -1,7 +1,7 @@ object ConvertSettingsForm: TConvertSettingsForm Left = 209 Height = 400 - Top = 89 + Top = 111 Width = 581 Caption = 'Convert Delphi unit, project or package ' ClientHeight = 400 @@ -14,13 +14,13 @@ object ConvertSettingsForm: TConvertSettingsForm AnchorSideTop.Control = SettingsGroupBox AnchorSideTop.Side = asrBottom Left = 0 - Height = 156 - Top = 171 + Height = 165 + Top = 187 Width = 581 Anchors = [akTop, akLeft, akRight, akBottom] BorderSpacing.Top = 3 Caption = 'Missing Properties and Components' - ClientHeight = 134 + ClientHeight = 143 ClientWidth = 571 TabOrder = 0 object MissingComponentCheckBox: TCheckBox @@ -63,18 +63,17 @@ object ConvertSettingsForm: TConvertSettingsForm end object SettingsGroupBox: TGroupBox Left = 0 - Height = 120 + Height = 136 Top = 48 Width = 581 Anchors = [akTop, akLeft, akRight] - Caption = 'Conversion Settings' - ClientHeight = 98 + ClientHeight = 126 ClientWidth = 571 TabOrder = 1 object BackupCheckBox: TCheckBox - Left = 11 + Left = 291 Height = 23 - Top = 15 + Top = 11 Width = 189 Caption = 'Make backup of changed files' Checked = True @@ -83,20 +82,22 @@ object ConvertSettingsForm: TConvertSettingsForm end object DelphiCompatibleCheckBox: TCheckBox AnchorSideTop.Control = BackupCheckBox - Left = 11 + Left = 347 Height = 23 - Top = 44 + Top = 107 Width = 215 + Anchors = [akLeft] BorderSpacing.Top = 29 Caption = 'Try to keep files Delphi compatible' OnChange = DelphiCompatibleCheckBoxChange TabOrder = 1 + Visible = False end object FormFileRenameCheckBox: TCheckBox - AnchorSideTop.Control = DelphiCompatibleCheckBox - Left = 11 + AnchorSideTop.Control = BackupCheckBox + Left = 291 Height = 23 - Top = 73 + Top = 40 Width = 185 BorderSpacing.Top = 29 Caption = 'Rename form file .dfm to .lfm' @@ -104,6 +105,31 @@ object ConvertSettingsForm: TConvertSettingsForm State = cbChecked TabOrder = 2 end + object TargetRadioGroup: TRadioGroup + Left = 3 + Height = 112 + Top = 3 + Width = 264 + AutoFill = True + Caption = 'Target' + ChildSizing.LeftRightSpacing = 6 + ChildSizing.TopBottomSpacing = 6 + ChildSizing.EnlargeHorizontal = crsHomogenousChildResize + ChildSizing.EnlargeVertical = crsHomogenousChildResize + ChildSizing.ShrinkHorizontal = crsScaleChilds + ChildSizing.ShrinkVertical = crsScaleChilds + ChildSizing.Layout = cclLeftToRightThenTopToBottom + ChildSizing.ControlsPerLine = 1 + ClientHeight = 90 + ClientWidth = 254 + ItemIndex = 0 + Items.Strings = ( + 'Lazarus/LCL' + 'Lazarus/LCL for Windows only' + 'Both Lazarus/LCL and Delphi' + ) + TabOrder = 3 + end end object BtnPanel: TPanel Left = 0 diff --git a/converter/convertsettings.pas b/converter/convertsettings.pas index 79abb7de2f..c765490c22 100644 --- a/converter/convertsettings.pas +++ b/converter/convertsettings.pas @@ -30,11 +30,13 @@ unit ConvertSettings; interface uses - Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, + Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, EditBtn, Buttons, ExtCtrls, DialogProcs; type + TConvertTarget = (ctLazarus, ctLazarusWin, ctLazarusAndDelphi); + { TConvertSettings } TConvertSettings = class @@ -45,7 +47,7 @@ type fMainPath: String; // Actual user settings. fBackupFiles: boolean; - fKeepDelphiCompatible: boolean; + fTarget: TConvertTarget; fFormFileRename: boolean; fAutoMissingProperties: boolean; fAutoMissingComponents: boolean; @@ -78,7 +80,7 @@ type property BackupPath: String read GetBackupPath; property BackupFiles: boolean read fBackupFiles; - property KeepDelphiCompatible: boolean read fKeepDelphiCompatible; + property Target: TConvertTarget read fTarget; property FormFileRename: boolean read fFormFileRename; property AutoMissingProperties: boolean read fAutoMissingProperties; property AutoMissingComponents: boolean read fAutoMissingComponents; @@ -91,6 +93,7 @@ type BackupCheckBox: TCheckBox; FormFileRenameCheckBox: TCheckBox; MainPathEdit: TLabeledEdit; + TargetRadioGroup: TRadioGroup; ReplacementCompsButton: TBitBtn; btnCancel: TBitBtn; btnOK: TBitBtn; @@ -147,7 +150,7 @@ begin // ToDo: Load from XML. // Settings --> UI. BackupCheckBox.Checked :=fBackupFiles; - DelphiCompatibleCheckBox.Checked:=fKeepDelphiCompatible; + TargetRadioGroup.ItemIndex :=integer(fTarget); FormFileRenameCheckBox.Checked :=fFormFileRename; MissingPropertyCheckBox.Checked :=fAutoMissingProperties; MissingComponentCheckBox.Checked:=fAutoMissingComponents; @@ -156,7 +159,7 @@ begin if Result=mrOK then begin // UI --> Settings. fBackupFiles :=BackupCheckBox.Checked; - fKeepDelphiCompatible :=DelphiCompatibleCheckBox.Checked; + fTarget :=TConvertTarget(TargetRadioGroup.ItemIndex); fFormFileRename :=FormFileRenameCheckBox.Checked; fAutoMissingProperties:=MissingPropertyCheckBox.Checked; fAutoMissingComponents:=MissingComponentCheckBox.Checked; diff --git a/converter/missingunitsunit.lfm b/converter/missingunits.lfm similarity index 100% rename from converter/missingunitsunit.lfm rename to converter/missingunits.lfm diff --git a/converter/missingunitsunit.pas b/converter/missingunits.pas similarity index 99% rename from converter/missingunitsunit.pas rename to converter/missingunits.pas index ddb289dd44..284b27b201 100644 --- a/converter/missingunitsunit.pas +++ b/converter/missingunits.pas @@ -24,7 +24,7 @@ A form asking what the user about what to do with missing units in uses section. Used by ConvertDelphi unit. } -unit MissingUnitsUnit; +unit MissingUnits; {$mode objfpc}{$H+}