IDEIntf: OI: component treeview: show all owned objects in properties

git-svn-id: trunk@39097 -
This commit is contained in:
mattias 2012-10-16 09:10:38 +00:00
parent efacf7ff55
commit c8fdc3a86e
3 changed files with 40 additions and 31 deletions

View File

@ -83,7 +83,7 @@ type
Added: boolean; Added: boolean;
end; end;
TGetCollectionProc = procedure(ACollection: TCollection) of object; TGetPersistentProc = procedure(APersistent: TPersistent) of object;
{ TComponentWalker } { TComponentWalker }
@ -93,14 +93,14 @@ type
FRootComponent: TComponent; FRootComponent: TComponent;
FNode: TTreeNode; FNode: TTreeNode;
protected protected
procedure GetCollections(AComponent: TComponent; AProc: TGetCollectionProc); procedure GetOwnedPersistents(AComponent: TComponent; AProc: TGetPersistentProc);
public public
constructor Create( constructor Create(
ATreeView: TComponentTreeView; ACandidates: TAvgLvlTree; ATreeView: TComponentTreeView; ACandidates: TAvgLvlTree;
ARootComponent: TComponent; ANode: TTreeNode); ARootComponent: TComponent; ANode: TTreeNode);
procedure Walk(AComponent: TComponent); procedure Walk(AComponent: TComponent);
procedure AddCollection(ACollection: TCollection); procedure AddOwnedPersistent(APersistent: TPersistent);
end; end;
TComponentAccessor = class(TComponent); TComponentAccessor = class(TComponent);
@ -119,21 +119,27 @@ end;
{ TComponentWalker } { TComponentWalker }
procedure TComponentWalker.GetCollections(AComponent: TComponent; AProc: TGetCollectionProc); procedure TComponentWalker.GetOwnedPersistents(AComponent: TComponent;
AProc: TGetPersistentProc);
var var
PropList: PPropList; PropList: PPropList;
i, PropCount: Integer; i, PropCount: Integer;
Obj: TObject; Pers: TPersistent;
PropInfo: PPropInfo;
PropEdit: TPropertyEditorClass;
begin begin
PropCount := GetPropList(AComponent, PropList); PropCount := GetPropList(AComponent, PropList);
try try
for i := 0 to PropCount - 1 do for i := 0 to PropCount - 1 do begin
if (PropList^[i]^.PropType^.Kind = tkClass) then PropInfo:=PropList^[i];
begin if (PropInfo^.PropType^.Kind <> tkClass) then continue;
Obj := GetObjectProp(AComponent, PropList^[i], TCollection); Pers := TPersistent(GetObjectProp(AComponent, PropInfo, TPersistent));
if Assigned(Obj) then if Pers=nil then continue;
AProc(TCollection(Obj)); if GetLookupRootForComponent(Pers)<>FRootComponent then continue;
end; PropEdit:=GetEditorClass(PropInfo,AComponent);
if (PropEdit=nil) then continue;
AProc(Pers);
end;
finally finally
FreeMem(PropList); FreeMem(PropList);
end; end;
@ -172,7 +178,7 @@ begin
FNode.SelectedIndex := FNode.ImageIndex; FNode.SelectedIndex := FNode.ImageIndex;
FNode.MultiSelected := FTreeView.Selection.IndexOf(AComponent) >= 0; FNode.MultiSelected := FTreeView.Selection.IndexOf(AComponent) >= 0;
GetCollections(AComponent, @AddCollection); GetOwnedPersistents(AComponent, @AddOwnedPersistent);
if (csInline in AComponent.ComponentState) or (AComponent.Owner = nil) then if (csInline in AComponent.ComponentState) or (AComponent.Owner = nil) then
Root := AComponent Root := AComponent
@ -185,30 +191,35 @@ begin
FNode.Expanded := True; FNode.Expanded := True;
end; end;
procedure TComponentWalker.AddCollection(ACollection: TCollection); procedure TComponentWalker.AddOwnedPersistent(APersistent: TPersistent);
var var
CollectionNode, ItemNode: TTreeNode; TVNode, ItemNode: TTreeNode;
i: integer; i: integer;
Item: TCollectionItem; Item: TCollectionItem;
ACollection: TCollection;
begin begin
if GetLookupRootForComponent(ACollection) <> FRootComponent then Exit; if GetLookupRootForComponent(APersistent) <> FRootComponent then Exit;
CollectionNode := FTreeView.Items.AddChild(FNode, FTreeView.CreateNodeCaption(ACollection)); TVNode := FTreeView.Items.AddChild(FNode, FTreeView.CreateNodeCaption(APersistent));
CollectionNode.Data := ACollection; TVNode.Data := APersistent;
CollectionNode.ImageIndex := FTreeView.GetImageFor(ACollection); TVNode.ImageIndex := FTreeView.GetImageFor(APersistent);
CollectionNode.SelectedIndex := CollectionNode.ImageIndex; TVNode.SelectedIndex := TVNode.ImageIndex;
CollectionNode.MultiSelected := FTreeView.Selection.IndexOf(ACollection) >= 0; TVNode.MultiSelected := FTreeView.Selection.IndexOf(APersistent) >= 0;
for i := 0 to ACollection.Count - 1 do if APersistent is TCollection then
begin begin
Item := ACollection.Items[i]; ACollection := TCollection(APersistent);
ItemNode := FTreeView.Items.AddChild(CollectionNode, FTreeView.CreateNodeCaption(Item)); for i := 0 to ACollection.Count - 1 do
ItemNode.Data := Item; begin
ItemNode.ImageIndex := FTreeView.GetImageFor(Item); Item := ACollection.Items[i];
ItemNode.SelectedIndex := ItemNode.ImageIndex; ItemNode := FTreeView.Items.AddChild(TVNode, FTreeView.CreateNodeCaption(Item));
ItemNode.MultiSelected := FTreeView.Selection.IndexOf(Item) >= 0; ItemNode.Data := Item;
ItemNode.ImageIndex := FTreeView.GetImageFor(Item);
ItemNode.SelectedIndex := ItemNode.ImageIndex;
ItemNode.MultiSelected := FTreeView.Selection.IndexOf(Item) >= 0;
end;
end; end;
FNode.Expanded := True; FNode.Expanded := True;
end; end;

View File

@ -1,4 +1,3 @@
{ $Id: objectinspector.pp 17395 2008-11-15 03:53:22Z paul $}
{ {
***************************************************************************** *****************************************************************************
* * * *

View File

@ -97,7 +97,6 @@ begin
Result := APersistent; Result := APersistent;
if Result = nil then if Result = nil then
Exit; Exit;
repeat repeat
AOwner := TPersistentAccess(Result).GetOwner; AOwner := TPersistentAccess(Result).GetOwner;
if AOwner <> nil then if AOwner <> nil then