Converter: Let Delphi use missing units instead of commenting them out.

git-svn-id: trunk@24184 -
This commit is contained in:
juha 2010-03-23 16:14:33 +00:00
parent 7b2852cad0
commit 07f218abd9
5 changed files with 52 additions and 38 deletions

View File

@ -149,8 +149,8 @@ end;
function TConvDelphiCodeTool.AddDelphiAndLCLSections: boolean; function TConvDelphiCodeTool.AddDelphiAndLCLSections: boolean;
// add, remove and rename units for desired target. // add, remove and rename units for desired target.
var var
WinOnlyUnits: TStringList; // Windows and LCL specific units. DelphiOnlyUnits: TStringList; // Delphi specific units.
LclOnlyUnits: TStringList; LclOnlyUnits: TStringList; // LCL specific units.
UsesNode: TCodeTreeNode; UsesNode: TCodeTreeNode;
Junk: TAtomPosition; Junk: TAtomPosition;
IsWinUnit, IsVariantUnit: Boolean; IsWinUnit, IsVariantUnit: Boolean;
@ -158,7 +158,7 @@ var
InsPos, i: Integer; InsPos, i: Integer;
begin begin
Result:=false; Result:=false;
WinOnlyUnits:=TStringList.Create; DelphiOnlyUnits:=TStringList.Create;
LclOnlyUnits:=TStringList.Create; LclOnlyUnits:=TStringList.Create;
try try
fCodeTool.BuildTree(true); fCodeTool.BuildTree(true);
@ -185,27 +185,39 @@ begin
// Don't do anything. Delphi units work for Lazarus under Windows. // Don't do anything. Delphi units work for Lazarus under Windows.
end; end;
ctLazarusAndDelphi: begin ctLazarusAndDelphi: begin
// Make separate sections for LCL and Windows units. // Make separate sections for LCL and Delphi units.
if IsWinUnit then begin if IsWinUnit then begin
WinOnlyUnits.Append('Windows'); DelphiOnlyUnits.Append('Windows');
LclOnlyUnits.Append('LCLIntf'); LclOnlyUnits.Append('LCLIntf');
LclOnlyUnits.Append('LCLType'); LclOnlyUnits.Append('LCLType');
LclOnlyUnits.Append('LMessages'); LclOnlyUnits.Append('LMessages');
fCodeTool.RemoveUnitFromUsesSection(UsesNode, 'WINDOWS', fSrcCache); fCodeTool.RemoveUnitFromUsesSection(UsesNode, 'WINDOWS', fSrcCache);
end; end;
if IsVariantUnit then begin if IsVariantUnit then begin
WinOnlyUnits.Append('Variants'); DelphiOnlyUnits.Append('Variants');
fCodeTool.BuildTree(true);
UsesNode:=fCodeTool.FindMainUsesSection;
fCodeTool.MoveCursorToUsesStart(UsesNode);
fCodeTool.RemoveUnitFromUsesSection(UsesNode, 'VARIANTS', fSrcCache); fCodeTool.RemoveUnitFromUsesSection(UsesNode, 'VARIANTS', fSrcCache);
end; end;
if (LclOnlyUnits.Count>0) or (WinOnlyUnits.Count>0) then begin // Now the missing units are not commented but used by Delphi instead.
// Add Windows and LCL sections for output. for i:=0 to fUnitsToComment.Count-1 do begin
s:=UpperCaseStr(fUnitsToComment[i]);
fCodeTool.BuildTree(true);
UsesNode:=fCodeTool.FindMainUsesSection;
fCodeTool.MoveCursorToUsesStart(UsesNode);
fCodeTool.RemoveUnitFromUsesSection(UsesNode, s, fSrcCache);
end;
DelphiOnlyUnits.AddStrings(fUnitsToComment);
if (LclOnlyUnits.Count>0) or (DelphiOnlyUnits.Count>0) then begin
// Add LCL and Delphi sections for output.
nl:=fSrcCache.BeautifyCodeOptions.LineEnd; nl:=fSrcCache.BeautifyCodeOptions.LineEnd;
s:='{$IFDEF LCL}'+nl+' '; s:='{$IFDEF LCL}'+nl+' ';
for i:=0 to LclOnlyUnits.Count-1 do for i:=0 to LclOnlyUnits.Count-1 do
s:=s+LclOnlyUnits[i]+', '; s:=s+LclOnlyUnits[i]+', ';
s:=s+nl+'{$ELSE}'+nl+' '; s:=s+nl+'{$ELSE}'+nl+' ';
for i:=0 to WinOnlyUnits.Count-1 do for i:=0 to DelphiOnlyUnits.Count-1 do
s:=s+WinOnlyUnits[i]+', '; s:=s+DelphiOnlyUnits[i]+', ';
s:=s+nl+'{$ENDIF}'; s:=s+nl+'{$ENDIF}';
// Now add the lines using codetools. // Now add the lines using codetools.
if not fSrcCache.Replace(gtEmptyLine,gtNewLine,InsPos,InsPos,s) then exit; if not fSrcCache.Replace(gtEmptyLine,gtNewLine,InsPos,InsPos,s) then exit;
@ -216,7 +228,7 @@ begin
Result:=true; Result:=true;
finally finally
LclOnlyUnits.Free; LclOnlyUnits.Free;
WinOnlyUnits.Free; DelphiOnlyUnits.Free;
end; end;
end; end;
@ -303,7 +315,7 @@ var
begin begin
Result:=false; Result:=false;
if Assigned(fUnitsToRemove) then begin if Assigned(fUnitsToRemove) then begin
for i := 0 to fUnitsToRemove.Count-1 do for i:=0 to fUnitsToRemove.Count-1 do
if not fCodeTool.RemoveUnitFromAllUsesSections(fUnitsToRemove[i], fSrcCache) then if not fCodeTool.RemoveUnitFromAllUsesSections(fUnitsToRemove[i], fSrcCache) then
exit; exit;
end; end;
@ -327,7 +339,7 @@ var
begin begin
Result:=false; Result:=false;
if Assigned(fUnitsToAdd) then if Assigned(fUnitsToAdd) then
for i := 0 to fUnitsToAdd.Count-1 do for i:=0 to fUnitsToAdd.Count-1 do
if not fCodeTool.AddUnitToMainUsesSection(fUnitsToAdd[i],'',fSrcCache) then if not fCodeTool.AddUnitToMainUsesSection(fUnitsToAdd[i],'',fSrcCache) then
exit; exit;
Result:=true; Result:=true;
@ -336,11 +348,14 @@ end;
function TConvDelphiCodeTool.CommentOutUnits: boolean; function TConvDelphiCodeTool.CommentOutUnits: boolean;
// Comment out missing units // Comment out missing units
begin begin
Result:=false; // If units are used by Delphi (IFDEF block) -> don't comment.
if Assigned(fUnitsToComment) and (fUnitsToComment.Count>0) then if fTarget<>ctLazarusAndDelphi then begin
if not fCodeTool.CommentUnitsInUsesSections(fUnitsToComment, fSrcCache) then Result:=false;
exit; if Assigned(fUnitsToComment) and (fUnitsToComment.Count>0) then
if not fCodeTool.CommentUnitsInUsesSections(fUnitsToComment, fSrcCache) then
exit;
// IDEMessagesWindow.AddMsg('Error="'+CodeToolBoss.ErrorMessage+'"','',-1); // IDEMessagesWindow.AddMsg('Error="'+CodeToolBoss.ErrorMessage+'"','',-1);
end;
Result:=true; Result:=true;
end; end;

View File

@ -41,10 +41,10 @@ uses
// IDEIntf // IDEIntf
ComponentReg, IDEMsgIntf, MainIntf, LazIDEIntf, PackageIntf, ProjectIntf, ComponentReg, IDEMsgIntf, MainIntf, LazIDEIntf, PackageIntf, ProjectIntf,
// IDE // IDE
IDEProcs, MissingUnits, Project, DialogProcs, //CheckLFMDlg, IDEProcs, Project, DialogProcs,
EditorOptions, CompilerOptions, PackageDefs, PackageSystem, EditorOptions, CompilerOptions, PackageDefs, PackageSystem,
PackageEditor, BasePkgManager, LazarusIDEStrConsts, PackageEditor, BasePkgManager, LazarusIDEStrConsts,
ConvertSettings, ConvCodeTool, MissingPropertiesDlg; ConvertSettings, ConvCodeTool, MissingUnits, MissingPropertiesDlg;
const const
SettingDelphiModeTemplName = 'Setting Delphi Mode'; SettingDelphiModeTemplName = 'Setting Delphi Mode';
@ -639,7 +639,6 @@ begin
LfmFixer.Settings:=fSettings; LfmFixer.Settings:=fSettings;
LfmFixer.RootMustBeClassInIntf:=true; LfmFixer.RootMustBeClassInIntf:=true;
LfmFixer.ObjectsMustExists:=true; LfmFixer.ObjectsMustExists:=true;
// was: if RepairLFMBuffer(...,true,true)<>mrOk
if LfmFixer.Repair<>mrOk then begin if LfmFixer.Repair<>mrOk then begin
LazarusIDE.DoJumpToCompilerMessage(-1,true); LazarusIDE.DoJumpToCompilerMessage(-1,true);
exit(mrAbort); exit(mrAbort);
@ -755,7 +754,8 @@ begin
// ask user what to do // ask user what to do
repeat repeat
TryAgain:=False; TryAgain:=False;
Result:=AskMissingUnits(fMissingUnits, ExtractFileName(fLazUnitFilename)); Result:=AskMissingUnits(fMissingUnits, ExtractFileName(fLazUnitFilename),
fSettings.Target=ctLazarusAndDelphi);
case Result of case Result of
// mrOK means: comment out. // mrOK means: comment out.
mrOK: begin mrOK: begin

View File

@ -142,6 +142,8 @@ begin
fReplaceProps['TCoolBar']:='TPanel'; fReplaceProps['TCoolBar']:='TPanel';
fReplaceProps['TRichEdit']:='TMemo'; fReplaceProps['TRichEdit']:='TMemo';
fReplaceProps['TDBRichEdit']:='TDBMemo'; fReplaceProps['TDBRichEdit']:='TDBMemo';
fReplaceProps['TPNGObject']:='TPortableNetworkGraphic';
fReplaceProps['TTntForm']:='TForm';
end; end;
destructor TConvertSettings.Destroy; destructor TConvertSettings.Destroy;

View File

@ -42,19 +42,6 @@ uses
CompilerOptions, CompilerOptions,
PackageDefs, Project, DialogProcs, IDEProcs, LazarusIDEStrConsts; PackageDefs, Project, DialogProcs, IDEProcs, LazarusIDEStrConsts;
const
// Copied from LazarusIDEStrConsts, remove later...
lisMissingUnitsComment = 'Comment Out';
lisMissingUnitsSearch = 'Search Unit Path';
lisTheseUnitsWereNotFound = 'These units were not found:';
lisMissingUnitsChoices = 'Your choices are:';
lisMissingUnitsInfo1 = '1) Comment out the missing units (ignore them).';
lisMissingUnitsInfo2 = '2) Select a unit path which will be added to project settings.';
lisMissingUnitsInfo3 = '3) Abort now, fix the unit path or install packages and try again.';
lisUnitNotFound = 'A unit not found in';
lisUnitsNotFound2 = 'Units not found in';
type type
{ TMissingUnitsDialog } { TMissingUnitsDialog }
@ -81,14 +68,16 @@ type
var var
MissingUnitsDialog: TMissingUnitsDialog; MissingUnitsDialog: TMissingUnitsDialog;
function AskMissingUnits(AMissingUnits: TStrings; AMainUnitName: string): TModalResult; function AskMissingUnits(AMissingUnits: TStrings; AMainUnitName: string;
ATargetDelphi: boolean): TModalResult;
implementation implementation
{$R *.lfm} {$R *.lfm}
function AskMissingUnits(AMissingUnits: TStrings; AMainUnitName: string): TModalResult; function AskMissingUnits(AMissingUnits: TStrings; AMainUnitName: string;
ATargetDelphi: boolean): TModalResult;
var var
UNFDialog: TMissingUnitsDialog; UNFDialog: TMissingUnitsDialog;
UnitsTitle, UnitsCommaList: string; UnitsTitle, UnitsCommaList: string;
@ -113,12 +102,18 @@ begin
UNFDialog:=TMissingUnitsDialog.Create(nil); UNFDialog:=TMissingUnitsDialog.Create(nil);
with UNFDialog do begin with UNFDialog do begin
Caption:=UnitsTitle; Caption:=UnitsTitle;
CommentButton.Caption:=lisMissingUnitsComment;
SearchButton.Caption:=lisMissingUnitsSearch; SearchButton.Caption:=lisMissingUnitsSearch;
MissingUnitsInfoLabel.Caption:=lisTheseUnitsWereNotFound; MissingUnitsInfoLabel.Caption:=lisTheseUnitsWereNotFound;
UnitNamesLabel.Caption:=UnitsCommaList; UnitNamesLabel.Caption:=UnitsCommaList;
ChoicesLabel.Caption:=lisMissingUnitsChoices; ChoicesLabel.Caption:=lisMissingUnitsChoices;
Info1Label.Caption:=lisMissingUnitsInfo1; if ATargetDelphi then begin
CommentButton.Caption:=lisMissingUnitsForDelphi;
Info1Label.Caption:=lisMissingUnitsInfo1b;
end
else begin
CommentButton.Caption:=lisMissingUnitsComment;
Info1Label.Caption:=lisMissingUnitsInfo1;
end;
Info2Label.Caption:=lisMissingUnitsInfo2; Info2Label.Caption:=lisMissingUnitsInfo2;
Info3Label.Caption:=lisMissingUnitsInfo3; Info3Label.Caption:=lisMissingUnitsInfo3;
Result:=ShowModal; Result:=ShowModal;

View File

@ -438,10 +438,12 @@ resourcestring
lisUnableToWriteFileError = 'Unable to write file %s%s%s%sError: %s'; lisUnableToWriteFileError = 'Unable to write file %s%s%s%sError: %s';
lisErrorCreatingLrs = 'Error creating lrs'; lisErrorCreatingLrs = 'Error creating lrs';
lisMissingUnitsComment = 'Comment Out'; lisMissingUnitsComment = 'Comment Out';
lisMissingUnitsForDelphi = 'For Delphi only';
lisMissingUnitsSearch = 'Search Unit Path'; lisMissingUnitsSearch = 'Search Unit Path';
lisTheseUnitsWereNotFound = 'These units were not found:'; lisTheseUnitsWereNotFound = 'These units were not found:';
lisMissingUnitsChoices = 'Your choices are:'; lisMissingUnitsChoices = 'Your choices are:';
lisMissingUnitsInfo1 = '1) Comment out the missing units (ignore them).'; lisMissingUnitsInfo1 = '1) Comment out the missing units (ignore them).';
lisMissingUnitsInfo1b = '1) Use the units only for Delphi.';
lisMissingUnitsInfo2 = '2) Select a unit path which will be added to project settings.'; lisMissingUnitsInfo2 = '2) Select a unit path which will be added to project settings.';
lisMissingUnitsInfo3 = '3) Abort now, fix the unit path or install packages and try again.'; lisMissingUnitsInfo3 = '3) Abort now, fix the unit path or install packages and try again.';
lisUnitNotFound = 'A unit not found in'; lisUnitNotFound = 'A unit not found in';