mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-05 10:37:58 +02:00
Converter: Improve adding missing units and package dependencies etc. Issue #30895.
git-svn-id: trunk@53841 -
This commit is contained in:
parent
5e8fb9d46e
commit
7328ad5783
@ -228,6 +228,7 @@ begin
|
||||
if not ReplaceFuncCalls(fIsConsoleApp) then exit;
|
||||
finally
|
||||
fCTLink.SrcCache.EndUpdate;
|
||||
fCTLink.SrcCache.Apply;
|
||||
end;
|
||||
Result:=mrOK;
|
||||
end;
|
||||
@ -373,7 +374,6 @@ begin
|
||||
end;
|
||||
CleanPos:=FindCommentEnd(Code.Source, CleanPos, CodeTool.Scanner.NestedComments);
|
||||
until false;
|
||||
//SrcCache.Apply;
|
||||
end;
|
||||
Result:=true;
|
||||
end;
|
||||
|
@ -1411,6 +1411,7 @@ end;
|
||||
function TConvertDelphiProjPack.CheckPackageDep(AUnitName: string): Boolean;
|
||||
// Check if the given unit can be found in existing packages. Add a dependency if found.
|
||||
// This is called only if the unit is reported as missing.
|
||||
// Returns True if a dependency was really added.
|
||||
var
|
||||
Pack: TPkgFile;
|
||||
Dep: TPkgDependency;
|
||||
@ -1451,7 +1452,7 @@ begin
|
||||
if not Result then
|
||||
// Package was not found. Add a message about a package that must be installed.
|
||||
fSettings.AddLogLine(mluWarning,
|
||||
Format(lisConvDelphiPackageRequired, [ADefaultPkgName]));
|
||||
Format(lisConvDelphiPackageRequired, [ADefaultPkgName]));
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
@ -9,7 +9,7 @@ uses
|
||||
|
||||
type
|
||||
|
||||
TAddUnitEvent = procedure (AUnitName: string) of object;
|
||||
TAddUnitEvent = function (AUnitName: string): Boolean of object;
|
||||
TCheckUnitEvent = function (AUnitName: string): Boolean of object;
|
||||
|
||||
// What to do with {$R *.RES} directive, convert to lowercase or delete.
|
||||
|
@ -33,18 +33,18 @@ interface
|
||||
|
||||
uses
|
||||
// FCL+LCL
|
||||
Classes, SysUtils, LCLProc, Forms, Controls, Grids, LResources,
|
||||
LConvEncoding, Graphics, Dialogs, Buttons, StdCtrls, ExtCtrls, contnrs,
|
||||
LazFileUtils, LazUTF8Classes, LCLType, LazUTF8,
|
||||
Classes, SysUtils, contnrs,
|
||||
LCLProc, Forms, Controls, Grids, LResources, Dialogs, Buttons, StdCtrls, ExtCtrls,
|
||||
// LazUtils
|
||||
LazFileUtils, LazUTF8Classes, LazUTF8,
|
||||
// components
|
||||
SynHighlighterLFM, SynEdit, SynEditMiscClasses, LFMTrees,
|
||||
SynHighlighterLFM, SynEdit, SynEditMiscClasses,
|
||||
// codetools
|
||||
CodeCache, CodeToolManager, CodeToolsStructs, CodeCompletionTool,
|
||||
CodeCache, CodeToolManager, CodeToolsStructs, CodeCompletionTool, LFMTrees,
|
||||
// IdeIntf
|
||||
ComponentReg, PackageIntf, IDEWindowIntf, IDEExternToolIntf,
|
||||
IDEExternToolIntf, ComponentReg,
|
||||
// IDE
|
||||
CustomFormEditor, LazarusIDEStrConsts, IDEProcs,
|
||||
EditorOptions, CheckLFMDlg, Project, SourceMarks,
|
||||
LazarusIDEStrConsts, EditorOptions, CheckLFMDlg, Project, SourceMarks,
|
||||
// Converter
|
||||
ConverterTypes, ConvertSettings, ReplaceNamesUnit,
|
||||
ConvCodeTool, FormFileConv, UsedUnits;
|
||||
@ -612,7 +612,8 @@ var
|
||||
begin
|
||||
Result:=mrOK;
|
||||
if not Assigned(fUsedUnitsTool) then Exit;
|
||||
for i := 0 to aMissingTypes.Count-1 do begin
|
||||
for i := 0 to aMissingTypes.Count-1 do
|
||||
begin
|
||||
RegComp:=IDEComponentPalette.FindComponent(aMissingTypes[i]);
|
||||
NeededUnitName:='';
|
||||
if (RegComp<>nil) then begin
|
||||
@ -621,14 +622,17 @@ begin
|
||||
if NeededUnitName='' then
|
||||
NeededUnitName:=RegComp.GetUnitName;
|
||||
end;
|
||||
end else begin
|
||||
end
|
||||
else begin
|
||||
ClassUnitInfo:=Project1.UnitWithComponentClassName(aMissingTypes[i]);
|
||||
if ClassUnitInfo<>nil then
|
||||
NeededUnitName:=ClassUnitInfo.GetUsesUnitName;
|
||||
end;
|
||||
if NeededUnitName<>'' then begin
|
||||
if fUsedUnitsTool.AddUnitImmediately(NeededUnitName) then
|
||||
Result:=mrRetry; // Caller must check LFM validity again
|
||||
if (NeededUnitName<>'')
|
||||
and fUsedUnitsTool.AddUnitImmediately(NeededUnitName) then
|
||||
begin
|
||||
Result:=mrRetry; // Caller must check LFM validity again
|
||||
fUsedUnitsTool.MaybeAddPackageDep(NeededUnitName);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
@ -125,7 +125,6 @@ type
|
||||
fOnCheckPackageDependency: TCheckUnitEvent;
|
||||
fOnCheckUnitForConversion: TCheckUnitEvent;
|
||||
function HasUnit(aUnitName: string): Boolean;
|
||||
procedure MaybeOpenPackage(aUnitName: string);
|
||||
function GetMissingUnitCount: integer;
|
||||
public
|
||||
constructor Create(ACTLink: TCodeToolLink; AFilename: string);
|
||||
@ -135,7 +134,8 @@ type
|
||||
function Remove(aUnit: string): TModalResult;
|
||||
procedure MoveMissingToComment(aAllCommentedUnits: TStrings);
|
||||
function AddUnitImmediately(aUnitName: string): Boolean;
|
||||
procedure AddUnitIfNeeded(aUnitName: string);
|
||||
function AddUnitIfNeeded(aUnitName: string): Boolean;
|
||||
function MaybeAddPackageDep(aUnitName: string): Boolean;
|
||||
function AddThreadSupport: TModalResult;
|
||||
public
|
||||
property Filename: string read fFilename;
|
||||
@ -305,7 +305,7 @@ begin
|
||||
if fOwnerTool.HasUnit(sl[i]) then
|
||||
sl.Delete(i)
|
||||
else
|
||||
fOwnerTool.MaybeOpenPackage(sl[i]);
|
||||
fOwnerTool.MaybeAddPackageDep(sl[i]);
|
||||
end;
|
||||
WillRemove:=sl.Count=0;
|
||||
if not WillRemove then begin
|
||||
@ -645,16 +645,17 @@ begin
|
||||
or fImplUsedUnits.fUnitsToRenameVals.Find(aUnitName, x);
|
||||
end;
|
||||
|
||||
procedure TUsedUnitsTool.MaybeOpenPackage(aUnitName: string);
|
||||
// Open a package containing a unit. Called when the unit is not found.
|
||||
function TUsedUnitsTool.MaybeAddPackageDep(aUnitName: string): Boolean;
|
||||
// Add a dependency to a package containing the unit and open it.
|
||||
// Called when the unit is not found.
|
||||
var
|
||||
s: String;
|
||||
begin
|
||||
Result := False;
|
||||
s:='';
|
||||
if fCTLink.CodeTool.DirectoryCache.FindUnitSourceInCompletePath(aUnitName,s,True) = '' then
|
||||
if Assigned(fOnCheckPackageDependency) then
|
||||
if not fOnCheckPackageDependency(aUnitName) then
|
||||
;
|
||||
Result := not fOnCheckPackageDependency(aUnitName);
|
||||
end;
|
||||
|
||||
function TUsedUnitsTool.ConvertUsed: TModalResult;
|
||||
@ -777,15 +778,19 @@ begin
|
||||
RemoveFromAdded(fImplUsedUnits.fUnitsToAdd);
|
||||
RemoveFromAdded(fMainUsedUnits.fUnitsToAddForLCL);
|
||||
RemoveFromAdded(fImplUsedUnits.fUnitsToAddForLCL);
|
||||
fCTLink.Settings.AddLogLine(mluNote,
|
||||
Format(lisConvAddedUnitToUsesSection, [aUnitName]), fFilename);
|
||||
end;
|
||||
|
||||
procedure TUsedUnitsTool.AddUnitIfNeeded(aUnitName: string);
|
||||
function TUsedUnitsTool.AddUnitIfNeeded(aUnitName: string): Boolean;
|
||||
begin
|
||||
if not HasUnit(aUnitName) then begin
|
||||
Result := not HasUnit(aUnitName);
|
||||
if Result then
|
||||
begin
|
||||
fMainUsedUnits.fUnitsToAdd.Add(aUnitName);
|
||||
fCTLink.Settings.AddLogLine(mluNote,
|
||||
Format(lisConvAddedUnitToUsesSection,[aUnitName]), fFilename);
|
||||
MaybeOpenPackage(aUnitName);
|
||||
Format(lisConvAddedUnitToUsesSection, [aUnitName]), fFilename);
|
||||
MaybeAddPackageDep(aUnitName);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -34,15 +34,16 @@ uses
|
||||
// FCL+LCL
|
||||
Classes, SysUtils, Math, TypInfo, contnrs,
|
||||
LCLProc, LResources, Forms, Controls,
|
||||
Graphics, Dialogs, Buttons, StdCtrls, ExtCtrls,
|
||||
Dialogs, Buttons, StdCtrls, ExtCtrls,
|
||||
// components
|
||||
SynHighlighterLFM, SynEdit, BasicCodeTools, CodeCache, CodeToolManager,
|
||||
SynEditMiscClasses, LFMTrees,
|
||||
// IDEIntf
|
||||
IDEExternToolIntf, PackageIntf, IDEWindowIntf, PropEdits, PropEditUtils,
|
||||
IDEMsgIntf, IDEDialogs, ComponentReg,
|
||||
// IDE
|
||||
IDEExternToolIntf, PackageIntf, IDEWindowIntf, PropEdits, PropEditUtils, IDEMsgIntf,
|
||||
IDEDialogs, ComponentReg,
|
||||
CustomFormEditor, LazarusIDEStrConsts,
|
||||
IDEProcs, IDEOptionDefs, EditorOptions, SourceMarks, JITForms;
|
||||
IDEProcs, EditorOptions, SourceMarks, JITForms;
|
||||
|
||||
type
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user