Converter: A unit was sometimes added to uses section although it was already in "LCL" section of the uses section.

git-svn-id: trunk@30511 -
This commit is contained in:
juha 2011-04-30 13:33:28 +00:00
parent e002cb4bc6
commit 3d7f3c8fe5

View File

@ -56,6 +56,8 @@ type
fUnitsToAddForLCL: TStringList; // List of new units for LCL (not for Delphi). fUnitsToAddForLCL: TStringList; // List of new units for LCL (not for Delphi).
fUnitsToRemove: TStringList; // List of units to remove. fUnitsToRemove: TStringList; // List of units to remove.
fUnitsToRename: TStringToStringTree; // Units to rename. Map old name -> new name. fUnitsToRename: TStringToStringTree; // Units to rename. Map old name -> new name.
fUnitsToRenameKeys: TStringList; // List of keys of the above map.
fUnitsToRenameVals: TStringList; // List of values of the above map.
fUnitsToFixCase: TStringToStringTree;// Like rename but done for every target. fUnitsToFixCase: TStringToStringTree;// Like rename but done for every target.
fUnitsToComment: TStringList; // List of units to be commented. fUnitsToComment: TStringList; // List of units to be commented.
fMissingUnits: TStringList; // Units not found in search path. fMissingUnits: TStringList; // Units not found in search path.
@ -75,10 +77,10 @@ type
destructor Destroy; override; destructor Destroy; override;
procedure CommentAutomatic(ACommentedUnits: TStringList); procedure CommentAutomatic(ACommentedUnits: TStringList);
public public
property MissingUnits: TStringList read fMissingUnits;
property UnitsToRemove: TStringList read fUnitsToRemove; property UnitsToRemove: TStringList read fUnitsToRemove;
property UnitsToRename: TStringToStringTree read fUnitsToRename; property UnitsToRename: TStringToStringTree read fUnitsToRename;
property UnitsToFixCase: TStringToStringTree read fUnitsToFixCase; property UnitsToFixCase: TStringToStringTree read fUnitsToFixCase;
property MissingUnits: TStringList read fMissingUnits;
end; end;
{ TMainUsedUnits } { TMainUsedUnits }
@ -166,6 +168,10 @@ begin
fUnitsToAddForLCL:=TStringList.Create; fUnitsToAddForLCL:=TStringList.Create;
fUnitsToRemove:=TStringList.Create; fUnitsToRemove:=TStringList.Create;
fUnitsToRename:=TStringToStringTree.Create(true); fUnitsToRename:=TStringToStringTree.Create(true);
fUnitsToRenameKeys:=TStringList.Create;
fUnitsToRenameKeys.CaseSensitive:=false;
fUnitsToRenameVals:=TStringList.Create;
fUnitsToRenameVals.CaseSensitive:=false;
fUnitsToFixCase:=TStringToStringTree.Create(true); fUnitsToFixCase:=TStringToStringTree.Create(true);
fUnitsToComment:=TStringList.Create; fUnitsToComment:=TStringList.Create;
fMissingUnits:=TStringList.Create; fMissingUnits:=TStringList.Create;
@ -185,6 +191,8 @@ begin
fMissingUnits.Free; fMissingUnits.Free;
fUnitsToComment.Free; fUnitsToComment.Free;
fUnitsToFixCase.Free; fUnitsToFixCase.Free;
fUnitsToRenameVals.Free;
fUnitsToRenameKeys.Free;
fUnitsToRename.Free; fUnitsToRename.Free;
fUnitsToRemove.Free; fUnitsToRemove.Free;
fUnitsToAddForLCL.Free; fUnitsToAddForLCL.Free;
@ -262,6 +270,8 @@ var
begin begin
if ANewName<>'' then begin if ANewName<>'' then begin
fUnitsToRename[AOldName]:=ANewName; fUnitsToRename[AOldName]:=ANewName;
fUnitsToRenameKeys.Add(AOldName);
fUnitsToRenameVals.Add(ANewName);
IDEMessagesWindow.AddMsg(Format(lisConvDelphiReplacedUnitInUsesSection, IDEMessagesWindow.AddMsg(Format(lisConvDelphiReplacedUnitInUsesSection,
[AOldName, ANewName]), '', -1); [AOldName, ANewName]), '', -1);
// If the unit is not found, open the package containing it. // If the unit is not found, open the package containing it.
@ -328,26 +338,23 @@ var
i, InsPos: Integer; i, InsPos: Integer;
s: string; s: string;
EndChar: char; EndChar: char;
RenameList: TStringList;
UsesNode: TCodeTreeNode; UsesNode: TCodeTreeNode;
ParentBlock: TCodeTreeNode; ParentBlock: TCodeTreeNode;
begin begin
Result:=False; Result:=False;
DelphiOnlyUnits:=TStringList.Create; DelphiOnlyUnits:=TStringList.Create;
LclOnlyUnits:=TStringList.Create; LclOnlyUnits:=TStringList.Create;
RenameList:=TStringList.Create;
try try
// Don't remove the unit names but add to Delphi block instead. // Don't remove the unit names but add to Delphi block instead.
for i:=0 to fUnitsToRemove.Count-1 do for i:=0 to fUnitsToRemove.Count-1 do
if not MoveToDelphi(fUnitsToRemove[i]) then Exit; //TempRemoveUnits.Add(fUnitsToRemove[i]); if not MoveToDelphi(fUnitsToRemove[i]) then Exit;
// ... and don't comment the unit names either. // ... and don't comment the unit names either.
for i:=0 to fUnitsToComment.Count-1 do for i:=0 to fUnitsToComment.Count-1 do
if not MoveToDelphi(fUnitsToComment[i]) then Exit; //TempRemoveUnits.Add(fUnitsToComment[i]); if not MoveToDelphi(fUnitsToComment[i]) then Exit;
// Add replacement units to LCL block. // Add replacement units to LCL block.
fUnitsToRename.GetNames(RenameList); for i:=0 to fUnitsToRenameKeys.Count-1 do begin
for i:=0 to RenameList.Count-1 do begin if not MoveToDelphi(fUnitsToRenameKeys[i]) then Exit;
if not MoveToDelphi(RenameList[i]) then Exit; //TempRemoveUnits.Add(RenameList[i]); LCLOnlyUnits.Add(fUnitsToRename[fUnitsToRenameKeys[i]]);
LCLOnlyUnits.Add(fUnitsToRename[RenameList[i]]);
end; end;
// Additional units for LCL (like Interfaces). // Additional units for LCL (like Interfaces).
LCLOnlyUnits.AddStrings(fUnitsToAddForLCL); LCLOnlyUnits.AddStrings(fUnitsToAddForLCL);
@ -399,7 +406,7 @@ begin
if not fCTLink.SrcCache.Replace(gtNewLine,gtNone,InsPos,InsPos,s) then exit; if not fCTLink.SrcCache.Replace(gtNewLine,gtNone,InsPos,InsPos,s) then exit;
Result:=fCTLink.SrcCache.Apply; Result:=fCTLink.SrcCache.Apply;
finally finally
RenameList.Free; // RenameList.Free;
LclOnlyUnits.Free; LclOnlyUnits.Free;
DelphiOnlyUnits.Free; DelphiOnlyUnits.Free;
end; end;
@ -654,10 +661,24 @@ procedure TUsedUnitsTool.AddUnitIfNeeded(AUnitName: string);
var var
i: Integer; i: Integer;
UnitInFileName: String; UnitInFileName: String;
RenameValFound: Boolean;
begin begin
RenameValFound:=false;
for i := 0 to fMainUsedUnits.fUnitsToRenameVals.Count-1 do
if Pos(AUnitName, fMainUsedUnits.fUnitsToRenameVals[i]) > 0 then begin
RenameValFound:=true;
Break;
end;
if not RenameValFound then
for i := 0 to fImplUsedUnits.fUnitsToRenameVals.Count-1 do
if Pos(AUnitName, fImplUsedUnits.fUnitsToRenameVals[i]) > 0 then begin
RenameValFound:=true;
Break;
end;
if not ( fMainUsedUnits.fExistingUnits.Find(AUnitName, i) or if not ( fMainUsedUnits.fExistingUnits.Find(AUnitName, i) or
fImplUsedUnits.fExistingUnits.Find(AUnitName, i) or fImplUsedUnits.fExistingUnits.Find(AUnitName, i) or
fMainUsedUnits.fUnitsToAdd.Find(AUnitName, i) ) then begin (fMainUsedUnits.fUnitsToAdd.IndexOf(AUnitName) > -1) or RenameValFound)
then begin
fMainUsedUnits.fUnitsToAdd.Add(AUnitName); fMainUsedUnits.fUnitsToAdd.Add(AUnitName);
IDEMessagesWindow.AddMsg('Added unit '+AUnitName+ ' to uses section', '', -1); IDEMessagesWindow.AddMsg('Added unit '+AUnitName+ ' to uses section', '', -1);
// If the unit is not found, open the package containing it. // If the unit is not found, open the package containing it.