ide: start resolving foreign references (works only when referenced form is already loaded)

git-svn-id: trunk@14798 -
This commit is contained in:
paul 2008-04-10 08:44:50 +00:00
parent ea223b758a
commit 09b6731e09
4 changed files with 64 additions and 16 deletions

View File

@ -48,7 +48,7 @@ uses
MemCheck, MemCheck,
{$ENDIF} {$ENDIF}
Classes, SysUtils, AvgLvlTree, TypInfo, LCLProc, LResources, Forms, Controls, Classes, SysUtils, AvgLvlTree, TypInfo, LCLProc, LResources, Forms, Controls,
LCLIntf, Dialogs, JITForm, ComponentReg, IDEProcs; LCLIntf, Dialogs, JITForm, ComponentReg, IDEProcs, BasePkgManager;
type type
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -808,7 +808,11 @@ end;
function TJITComponentList.OnFindGlobalComponent( function TJITComponentList.OnFindGlobalComponent(
const AName: AnsiString): TComponent; const AName: AnsiString): TComponent;
begin begin
Result:=Application.FindComponent(AName); // Paul: Do we need search by application?
Result := Application.FindComponent(AName);
if Result = nil then
Result := PkgBoss.FindReferencedRootComponent(CurReadJITComponent, AName);
// DebugLn(dbgsName(CurReadJITComponent), ' FIND global component ', AName, ' ', dbgsName(Result));
end; end;
procedure TJITComponentList.InitReading(BinStream: TStream; procedure TJITComponentList.InitReading(BinStream: TStream;

View File

@ -641,6 +641,7 @@ type
function ProjectUnitWithUnitname(const AnUnitName: string): TUnitInfo; function ProjectUnitWithUnitname(const AnUnitName: string): TUnitInfo;
function UnitWithEditorIndex(Index:integer): TUnitInfo; function UnitWithEditorIndex(Index:integer): TUnitInfo;
function UnitWithComponent(AComponent: TComponent): TUnitInfo; function UnitWithComponent(AComponent: TComponent): TUnitInfo;
function UnitWithComponentName(AComponentName: String): TUnitInfo;
function UnitComponentInheritingFrom(AClass: TComponentClass; function UnitComponentInheritingFrom(AClass: TComponentClass;
Ignore: TUnitInfo): TUnitInfo; Ignore: TUnitInfo): TUnitInfo;
function UnitUsingComponentUnit(ComponentUnit: TUnitInfo): TUnitInfo; function UnitUsingComponentUnit(ComponentUnit: TUnitInfo): TUnitInfo;
@ -3619,13 +3620,20 @@ begin
end; end;
Function TProject.UnitWithComponent(AComponent: TComponent) : TUnitInfo; function TProject.UnitWithComponent(AComponent: TComponent): TUnitInfo;
begin begin
Result:=fFirst[uilWithComponent]; Result:=fFirst[uilWithComponent];
while (Result<>nil) and (Result.Component<>AComponent) do while (Result<>nil) and (Result.Component<>AComponent) do
Result:=Result.fNext[uilWithComponent]; Result:=Result.fNext[uilWithComponent];
end; end;
function TProject.UnitWithComponentName(AComponentName: String): TUnitInfo;
begin
Result := fFirst[uilPartOfProject];
while (Result<>nil) and (SysUtils.CompareText(Result.ComponentName, AComponentName) <> 0) do
Result := Result.fNext[uilPartOfProject];
end;
function TProject.UnitComponentInheritingFrom(AClass: TComponentClass; function TProject.UnitComponentInheritingFrom(AClass: TComponentClass;
Ignore: TUnitInfo): TUnitInfo; Ignore: TUnitInfo): TUnitInfo;
begin begin

View File

@ -144,6 +144,8 @@ type
Proc: TGetStringProc); virtual; abstract; Proc: TGetStringProc); virtual; abstract;
function FindUsableComponent(CurRoot: TPersistent; function FindUsableComponent(CurRoot: TPersistent;
const ComponentPath: string): TComponent; virtual; abstract; const ComponentPath: string): TComponent; virtual; abstract;
function FindReferencedRootComponent(CurRoot: TPersistent;
const ComponentName: string): TComponent; virtual; abstract;
end; end;
var var

View File

@ -306,6 +306,8 @@ type
Proc: TGetStringProc); override; Proc: TGetStringProc); override;
function FindUsableComponent(CurRoot: TPersistent; function FindUsableComponent(CurRoot: TPersistent;
const ComponentPath: string): TComponent; override; const ComponentPath: string): TComponent; override;
function FindReferencedRootComponent(CurRoot: TPersistent;
const ComponentName: string): TComponent; override;
end; end;
@ -3876,32 +3878,36 @@ var
function MainUnitInfo: TUnitInfo; function MainUnitInfo: TUnitInfo;
begin begin
if not FMainUnitInfoValid then begin if not FMainUnitInfoValid then
begin
if CurRoot is TComponent then if CurRoot is TComponent then
FMainUnitInfo:=Project1.UnitWithComponent(TComponent(CurRoot)); FMainUnitInfo := Project1.UnitWithComponentName(TComponent(CurRoot).Name);
FMainUnitInfoValid:=true; FMainUnitInfoValid := True;
end; end;
Result:=FMainUnitInfo; Result := FMainUnitInfo;
end; end;
function MainOwner: TObject; function MainOwner: TObject;
var var
Owners: TFPList; Owners: TFPList;
begin begin
if not FMainOwnerValid then begin if not FMainOwnerValid then
if MainUnitInfo<>nil then begin begin
if MainUnitInfo <> nil then
begin
if MainUnitInfo.IsPartOfProject then if MainUnitInfo.IsPartOfProject then
FMainOwner:=Project1 FMainOwner := Project1
else begin else
Owners:=GetOwnersOfUnit(MainUnitInfo.Filename); begin
if (Owners<>nil) and (Owners.Count>0) then Owners := GetOwnersOfUnit(MainUnitInfo.Filename);
FMainOwner:=TObject(Owners[0]); if (Owners <> nil) and (Owners.Count > 0) then
FMainOwner := TObject(Owners[0]);
Owners.Free; Owners.Free;
end; end;
end; end;
FMainOwnerValid:=true; FMainOwnerValid := True;
end; end;
Result:=FMainOwner; Result := FMainOwner;
end; end;
procedure CheckUnit(AnUnitInfo: TUnitInfo); procedure CheckUnit(AnUnitInfo: TUnitInfo);
@ -4029,6 +4035,34 @@ begin
end; end;
end; end;
function TPkgManager.FindReferencedRootComponent(CurRoot: TPersistent; const ComponentName: string): TComponent;
var
UnitList: TFPList;
ARoot: TComponent;
i: integer;
begin
//DebugLn(['search ', ComponentName, ' CurRoot = ', dbgsName(CurRoot)]);
Result := nil;
UnitList := GetUsableComponentUnits(CurRoot);
if UnitList = nil then
Exit;
try
for i := 0 to UnitList.Count - 1 do
begin
ARoot := TUnitInfo(UnitList[i]).Component;
//DebugLn(dbgsName(ARoot));
if (ARoot <> nil) and (SysUtils.CompareText(ComponentName, ARoot.Name) = 0) then
begin
Result := ARoot;
break;
end;
end;
finally
UnitList.Free;
end;
//DebugLn('search end');
end;
function TPkgManager.FindUsableComponent(CurRoot: TPersistent; function TPkgManager.FindUsableComponent(CurRoot: TPersistent;
const ComponentPath: string): TComponent; const ComponentPath: string): TComponent;