mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-31 10:20:40 +02:00
Converter: Don't replace Windows unit if target is "Windows only".
git-svn-id: trunk@26369 -
This commit is contained in:
parent
bb6938322a
commit
4825567e0d
@ -712,6 +712,7 @@ var
|
|||||||
UnitNames: TStringList;
|
UnitNames: TStringList;
|
||||||
|
|
||||||
procedure RenameOrRemoveUnit(AOldName, ANewName: string);
|
procedure RenameOrRemoveUnit(AOldName, ANewName: string);
|
||||||
|
// Replace a unit name with a new name or remove it if there is no new name.
|
||||||
var
|
var
|
||||||
x: Integer;
|
x: Integer;
|
||||||
begin
|
begin
|
||||||
@ -727,13 +728,35 @@ var
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function GetMissingUnits: TModalResult;
|
||||||
|
// Get missing unit by codetools.
|
||||||
|
var
|
||||||
|
CTResult: Boolean;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
Result:=mrOk;
|
||||||
|
CTResult:=CodeToolBoss.FindMissingUnits(fPascalBuffer,fMissingUnits,true);
|
||||||
|
if not CTResult then begin
|
||||||
|
IDEMessagesWindow.AddMsg('Error="'+CodeToolBoss.ErrorMessage+'"','',-1);
|
||||||
|
Result:=mrCancel;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
// Remove Windows unit from the list if target is "Windows only".
|
||||||
|
if fSettings.Target=ctLazarusWin then begin
|
||||||
|
for i:=fMissingUnits.Count-1 downto 0 do
|
||||||
|
if LowerCase(fMissingUnits[i])='windows' then begin
|
||||||
|
fMissingUnits.Delete(i);
|
||||||
|
Break;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
UnitUpdater: TStringMapUpdater;
|
UnitUpdater: TStringMapUpdater;
|
||||||
MapToEdit: TStringToStringTree;
|
MapToEdit: TStringToStringTree;
|
||||||
Node: TAVLTreeNode;
|
Node: TAVLTreeNode;
|
||||||
Item: PStringToStringTreeItem;
|
Item: PStringToStringTreeItem;
|
||||||
ConvTool: TConvDelphiCodeTool;
|
ConvTool: TConvDelphiCodeTool;
|
||||||
CTResult: Boolean;
|
|
||||||
i: Integer;
|
i: Integer;
|
||||||
UnitN, s: string;
|
UnitN, s: string;
|
||||||
begin
|
begin
|
||||||
@ -745,26 +768,19 @@ begin
|
|||||||
UnitNames:=nil; // Will be created in ConvTool.UsesSectionsToUnitnames.
|
UnitNames:=nil; // Will be created in ConvTool.UsesSectionsToUnitnames.
|
||||||
fMissingUnits:=nil; // Will be created in CodeToolBoss.FindMissingUnits.
|
fMissingUnits:=nil; // Will be created in CodeToolBoss.FindMissingUnits.
|
||||||
try
|
try
|
||||||
|
Result:=GetMissingUnits;
|
||||||
|
if (Result<>mrOK) or (fMissingUnits=nil) or (fMissingUnits.Count=0) then exit;
|
||||||
|
|
||||||
// Collect all unit names from uses sections.
|
// Collect all unit names from uses sections.
|
||||||
UnitNames:=ConvTool.UsesSectionsToUnitnames;
|
UnitNames:=ConvTool.UsesSectionsToUnitnames;
|
||||||
UnitNames.Sorted:=true;
|
UnitNames.Sorted:=true;
|
||||||
// find missing units
|
|
||||||
CTResult:=CodeToolBoss.FindMissingUnits(fPascalBuffer,fMissingUnits,true);
|
|
||||||
if not CTResult then begin
|
|
||||||
IDEMessagesWindow.AddMsg('Error="'+CodeToolBoss.ErrorMessage+'"','',-1);
|
|
||||||
Result:=mrCancel;
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
// no missing units -> good
|
|
||||||
if (fMissingUnits=nil) or (fMissingUnits.Count=0) then exit;
|
|
||||||
|
|
||||||
// Find replacements for missing units from settings.
|
// Find replacements for missing units from settings.
|
||||||
for i:=fMissingUnits.Count-1 downto 0 do begin
|
for i:=fMissingUnits.Count-1 downto 0 do begin
|
||||||
UnitN:=fMissingUnits[i];
|
UnitN:=fMissingUnits[i];
|
||||||
if UnitUpdater.FindReplacement(UnitN, s) then begin
|
if UnitUpdater.FindReplacement(UnitN, s) then begin
|
||||||
// Don't replace Windows with LCL units in a console application.
|
// Don't replace Windows unit with LCL units in a console application.
|
||||||
if Assigned(fOwnerConverter) and fOwnerConverter.fIsConsoleApp and
|
if (LowerCase(UnitN)='windows') and
|
||||||
(LowerCase(UnitN)='windows') then
|
Assigned(fOwnerConverter) and fOwnerConverter.fIsConsoleApp then
|
||||||
s:='';
|
s:='';
|
||||||
if fSettings.AutoReplaceUnits then
|
if fSettings.AutoReplaceUnits then
|
||||||
RenameOrRemoveUnit(UnitN, s) // Automatic rename / remove.
|
RenameOrRemoveUnit(UnitN, s) // Automatic rename / remove.
|
||||||
@ -791,13 +807,8 @@ begin
|
|||||||
ConvTool.RemoveUnits;
|
ConvTool.RemoveUnits;
|
||||||
// Find missing units again. Some replacements may not be valid.
|
// Find missing units again. Some replacements may not be valid.
|
||||||
fMissingUnits.Clear;
|
fMissingUnits.Clear;
|
||||||
CTResult:=CodeToolBoss.FindMissingUnits(fPascalBuffer,fMissingUnits,true);
|
Result:=GetMissingUnits;
|
||||||
if not CTResult then begin
|
if (Result<>mrOK) or (fMissingUnits.Count=0) then exit;
|
||||||
IDEMessagesWindow.AddMsg('Error="'+CodeToolBoss.ErrorMessage+'"','',-1);
|
|
||||||
Result:=mrCancel;
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
if fMissingUnits.Count=0 then exit;
|
|
||||||
|
|
||||||
if Assigned(fOwnerConverter) then begin
|
if Assigned(fOwnerConverter) then begin
|
||||||
// Try to find from subdirectories scanned earlier.
|
// Try to find from subdirectories scanned earlier.
|
||||||
@ -805,7 +816,6 @@ begin
|
|||||||
// Comment out automatically units that were commented in other files.
|
// Comment out automatically units that were commented in other files.
|
||||||
if CommentAutomatically=0 then exit;
|
if CommentAutomatically=0 then exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Interactive dialog for searching unit.
|
// Interactive dialog for searching unit.
|
||||||
Result:=AskUnitPathFromUser;
|
Result:=AskUnitPathFromUser;
|
||||||
if Result<>mrOK then exit;
|
if Result<>mrOK then exit;
|
||||||
|
Loading…
Reference in New Issue
Block a user