From e10b91af6d2c33d4bddb55f6308df37cbd3eb941 Mon Sep 17 00:00:00 2001 From: mattias Date: Fri, 21 Jun 2013 08:01:30 +0000 Subject: [PATCH] cody: unit deps: expand uses sections git-svn-id: trunk@41774 - --- components/codetools/ide/codyunitdepwnd.lfm | 145 ++++++------- components/codetools/ide/codyunitdepwnd.pas | 216 +++++++++++++++----- 2 files changed, 233 insertions(+), 128 deletions(-) diff --git a/components/codetools/ide/codyunitdepwnd.lfm b/components/codetools/ide/codyunitdepwnd.lfm index 2268234ddd..3c3536d131 100644 --- a/components/codetools/ide/codyunitdepwnd.lfm +++ b/components/codetools/ide/codyunitdepwnd.lfm @@ -1,7 +1,7 @@ object UnitDependenciesWindow: TUnitDependenciesWindow - Left = 1177 + Left = 497 Height = 440 - Top = 154 + Top = 150 Width = 620 Caption = 'UnitDependenciesWindow' ClientHeight = 440 @@ -12,7 +12,7 @@ object UnitDependenciesWindow: TUnitDependenciesWindow LCLVersion = '1.1' object MainPageControl: TPageControl Left = 0 - Height = 407 + Height = 414 Top = 0 Width = 620 ActivePage = UnitsTabSheet @@ -21,26 +21,26 @@ object UnitDependenciesWindow: TUnitDependenciesWindow TabOrder = 0 object UnitsTabSheet: TTabSheet Caption = 'UnitsTabSheet' - ClientHeight = 378 - ClientWidth = 616 + ClientHeight = 375 + ClientWidth = 614 object ScopePanel: TPanel Left = 0 - Height = 59 + Height = 47 Top = 0 - Width = 616 + Width = 614 Align = alTop AutoSize = True - ClientHeight = 59 - ClientWidth = 616 + ClientHeight = 47 + ClientWidth = 614 TabOrder = 0 object SearchCustomFilesCheckBox: TCheckBox AnchorSideLeft.Control = ScopePanel AnchorSideTop.Control = SearchCustomFilesComboBox AnchorSideTop.Side = asrCenter Left = 3 - Height = 24 + Height = 18 Top = 4 - Width = 181 + Width = 201 BorderSpacing.Around = 2 Caption = 'SearchCustomFilesCheckBox' OnChange = SearchCustomFilesCheckBoxChange @@ -54,10 +54,10 @@ object UnitDependenciesWindow: TUnitDependenciesWindow AnchorSideTop.Side = asrCenter AnchorSideRight.Control = ScopePanel AnchorSideRight.Side = asrBottom - Left = 562 - Height = 27 + Left = 543 + Height = 20 Top = 3 - Width = 53 + Width = 70 Anchors = [akTop, akRight] AutoSize = True Caption = 'Browse' @@ -69,10 +69,10 @@ object UnitDependenciesWindow: TUnitDependenciesWindow AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = ScopePanel AnchorSideRight.Control = SearchCustomFilesBrowseButton - Left = 186 - Height = 27 + Left = 206 + Height = 21 Top = 3 - Width = 374 + Width = 335 Anchors = [akTop, akLeft, akRight] BorderSpacing.Around = 2 ItemHeight = 0 @@ -85,9 +85,9 @@ object UnitDependenciesWindow: TUnitDependenciesWindow AnchorSideTop.Control = SearchCustomFilesComboBox AnchorSideTop.Side = asrBottom Left = 3 - Height = 24 - Top = 32 - Width = 141 + Height = 18 + Top = 26 + Width = 153 BorderSpacing.Around = 2 Caption = 'SearchPkgsCheckBox' OnChange = SearchPkgsCheckBoxChange @@ -98,10 +98,10 @@ object UnitDependenciesWindow: TUnitDependenciesWindow AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = SearchPkgsCheckBox AnchorSideTop.Side = asrCenter - Left = 161 - Height = 24 - Top = 32 - Width = 156 + Left = 173 + Height = 18 + Top = 26 + Width = 167 BorderSpacing.Left = 15 BorderSpacing.Around = 2 Caption = 'SearchSrcEditCheckBox' @@ -113,22 +113,22 @@ object UnitDependenciesWindow: TUnitDependenciesWindow end object AllUnitsGroupBox: TGroupBox Left = 0 - Height = 319 - Top = 59 + Height = 328 + Top = 47 Width = 248 Align = alLeft Caption = 'AllUnitsGroupBox' - ClientHeight = 302 - ClientWidth = 244 + ClientHeight = 306 + ClientWidth = 240 TabOrder = 1 object AllUnitsShowGroupNodesSpeedButton: TSpeedButton AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = AllUnitsFilterEdit AnchorSideTop.Side = asrCenter AnchorSideRight.Control = AllUnitsShowDirsSpeedButton - Left = 198 + Left = 194 Height = 22 - Top = 1 + Top = 0 Width = 23 AllowAllUp = True Anchors = [akTop, akRight] @@ -143,9 +143,9 @@ object UnitDependenciesWindow: TUnitDependenciesWindow AnchorSideTop.Side = asrCenter AnchorSideRight.Control = AllUnitsGroupBox AnchorSideRight.Side = asrBottom - Left = 221 + Left = 217 Height = 22 - Top = 1 + Top = 0 Width = 23 AllowAllUp = True Anchors = [akTop, akRight] @@ -159,9 +159,9 @@ object UnitDependenciesWindow: TUnitDependenciesWindow AnchorSideTop.Control = AllUnitsGroupBox AnchorSideRight.Control = AllUnitsShowGroupNodesSpeedButton Left = 0 - Height = 25 + Height = 22 Top = 0 - Width = 198 + Width = 194 Anchors = [akTop, akLeft, akRight] OnChange = AllUnitsFilterEditChange OnEnter = AllUnitsFilterEditEnter @@ -173,9 +173,9 @@ object UnitDependenciesWindow: TUnitDependenciesWindow AnchorSideTop.Control = AllUnitsSearchEdit AnchorSideTop.Side = asrCenter AnchorSideRight.Control = AllUnitsSearchPrevSpeedButton - Left = 198 + Left = 194 Height = 22 - Top = 278 + Top = 284 Width = 23 Anchors = [akTop, akRight] OnClick = AllUnitsSearchNextSpeedButtonClick @@ -187,9 +187,9 @@ object UnitDependenciesWindow: TUnitDependenciesWindow AnchorSideTop.Side = asrCenter AnchorSideRight.Control = AllUnitsGroupBox AnchorSideRight.Side = asrBottom - Left = 221 + Left = 217 Height = 22 - Top = 278 + Top = 284 Width = 23 Anchors = [akTop, akRight] OnClick = AllUnitsSearchPrevSpeedButtonClick @@ -204,9 +204,9 @@ object UnitDependenciesWindow: TUnitDependenciesWindow AnchorSideRight.Side = asrBottom AnchorSideBottom.Control = AllUnitsSearchEdit Left = 0 - Height = 252 - Top = 25 - Width = 244 + Height = 262 + Top = 22 + Width = 240 Anchors = [akTop, akLeft, akRight, akBottom] DefaultItemHeight = 18 HotTrack = True @@ -229,9 +229,9 @@ object UnitDependenciesWindow: TUnitDependenciesWindow AnchorSideBottom.Control = AllUnitsGroupBox AnchorSideBottom.Side = asrBottom Left = 0 - Height = 25 - Top = 277 - Width = 198 + Height = 22 + Top = 284 + Width = 194 Anchors = [akLeft, akRight, akBottom] OnChange = AllUnitsSearchEditChange OnEnter = AllUnitsSearchEditEnter @@ -242,27 +242,27 @@ object UnitDependenciesWindow: TUnitDependenciesWindow end object UnitsSplitter: TSplitter Left = 248 - Height = 319 - Top = 59 + Height = 328 + Top = 47 Width = 5 end object SelectedUnitsGroupBox: TGroupBox Left = 253 - Height = 319 - Top = 59 - Width = 363 + Height = 328 + Top = 47 + Width = 361 Align = alClient Caption = 'SelectedUnitsGroupBox' - ClientHeight = 302 - ClientWidth = 359 + ClientHeight = 306 + ClientWidth = 353 TabOrder = 3 object SelUnitsSearchNextSpeedButton: TSpeedButton AnchorSideTop.Control = SelUnitsSearchEdit AnchorSideTop.Side = asrCenter AnchorSideRight.Control = SelUnitsSearchPrevSpeedButton - Left = 313 + Left = 307 Height = 22 - Top = 278 + Top = 284 Width = 23 Anchors = [akTop, akRight] OnClick = SelUnitsSearchNextSpeedButtonClick @@ -274,9 +274,9 @@ object UnitDependenciesWindow: TUnitDependenciesWindow AnchorSideTop.Side = asrCenter AnchorSideRight.Control = SelectedUnitsGroupBox AnchorSideRight.Side = asrBottom - Left = 336 + Left = 330 Height = 22 - Top = 278 + Top = 284 Width = 23 Anchors = [akTop, akRight] OnClick = SelUnitsSearchPrevSpeedButtonClick @@ -289,9 +289,9 @@ object UnitDependenciesWindow: TUnitDependenciesWindow AnchorSideBottom.Control = SelectedUnitsGroupBox AnchorSideBottom.Side = asrBottom Left = 0 - Height = 25 - Top = 277 - Width = 313 + Height = 22 + Top = 284 + Width = 307 Anchors = [akLeft, akRight, akBottom] OnChange = SelUnitsSearchEditChange OnEnter = SelUnitsSearchEditEnter @@ -306,9 +306,9 @@ object UnitDependenciesWindow: TUnitDependenciesWindow AnchorSideRight.Side = asrBottom AnchorSideBottom.Control = SelUnitsSearchEdit Left = 0 - Height = 277 + Height = 284 Top = 0 - Width = 359 + Width = 353 Anchors = [akTop, akLeft, akRight, akBottom] DefaultItemHeight = 18 HotTrack = True @@ -319,6 +319,7 @@ object UnitDependenciesWindow: TUnitDependenciesWindow ShowHint = True ShowRoot = False TabOrder = 1 + OnExpanding = SelUnitsTreeViewExpanding OnMouseDown = UnitsTreeViewMouseDown OnShowHint = UnitsTreeViewShowHint Options = [tvoAutoItemHeight, tvoHideSelection, tvoHotTrack, tvoKeepCollapsedNodes, tvoReadOnly, tvoRightClickSelect, tvoShowButtons, tvoShowLines, tvoToolTips, tvoThemedDraw] @@ -342,12 +343,12 @@ object UnitDependenciesWindow: TUnitDependenciesWindow end object StatusPanel: TPanel Left = 0 - Height = 33 - Top = 407 + Height = 26 + Top = 414 Width = 620 Align = alBottom AutoSize = True - ClientHeight = 33 + ClientHeight = 26 ClientWidth = 620 TabOrder = 1 object ProgressBar1: TProgressBar @@ -357,18 +358,18 @@ object UnitDependenciesWindow: TUnitDependenciesWindow AnchorSideTop.Side = asrCenter AnchorSideRight.Control = RefreshButton AnchorSideBottom.Side = asrBottom - Left = 69 + Left = 77 Height = 20 - Top = 6 - Width = 451 + Top = 3 + Width = 425 Anchors = [akTop, akLeft, akRight] TabOrder = 0 end object RefreshButton: TButton - Left = 522 - Height = 27 + Left = 504 + Height = 20 Top = 3 - Width = 95 + Width = 113 Align = alRight AutoSize = True BorderSpacing.Around = 2 @@ -381,9 +382,9 @@ object UnitDependenciesWindow: TUnitDependenciesWindow AnchorSideTop.Control = RefreshButton AnchorSideTop.Side = asrCenter Left = 7 - Height = 15 - Top = 9 - Width = 56 + Height = 16 + Top = 5 + Width = 64 BorderSpacing.Left = 6 BorderSpacing.Right = 6 Caption = 'StatsLabel' diff --git a/components/codetools/ide/codyunitdepwnd.pas b/components/codetools/ide/codyunitdepwnd.pas index 8b430392e1..4beffe5e86 100644 --- a/components/codetools/ide/codyunitdepwnd.pas +++ b/components/codetools/ide/codyunitdepwnd.pas @@ -24,14 +24,10 @@ IDE Window showing dependencies of units and packages. ToDo: - - delay update pages when not visible - - update pages when becoming visible - - additional files as start units - - check if package unit is used + - check all OnIdle to set Done:=not IdleConnected - view: - mark units with implementation uses section - - selected units - - expand node: show connected units + - every second: write parsed units - resourcestrings } unit CodyUnitDepWnd; @@ -73,6 +69,7 @@ type Typ: TUDNodeType; Identifier: string; // GroupName, Directory, Filename Group: string; + HasChildren: boolean; end; { TUDNode } @@ -146,6 +143,8 @@ type procedure AllUnitsShowDirsSpeedButtonClick(Sender: TObject); procedure AllUnitsShowGroupNodesSpeedButtonClick(Sender: TObject); procedure RefreshButtonClick(Sender: TObject); + procedure SelUnitsTreeViewExpanding(Sender: TObject; Node: TTreeNode; + var AllowExpansion: Boolean); procedure UnitsTreeViewShowHint(Sender: TObject; HintInfo: PHintInfo); procedure UnitsTreeViewMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); @@ -187,11 +186,15 @@ type fSelUnitsTVSearchStartNode: TTreeNode; function CreateAllUnitsTree: TUDNode; function CreateSelUnitsTree: TUDNode; + procedure AddUsesSubNodes(UDNode: TUDNode); procedure CreateTVNodes(TV: TTreeView; - ParentTVNode: TTreeNode; ParentUDNode: TUDNode); + ParentTVNode: TTreeNode; ParentUDNode: TUDNode; Expand: boolean); procedure FreeUsesGraph; procedure SelectNextSearchTV(TV: TTreeView; StartTVNode: TTreeNode; SearchNext, SkipStart: boolean); + function FindNextTVNode(StartNode: TTreeNode; + LowerSearch: string; SearchNext, SkipStart: boolean): TTreeNode; + function FindUnitTVNodeWithFilename(TV: TTreeView; aFilename: string): TTreeNode; procedure SetCurrentUnit(AValue: TUGUnit); procedure SetIdleConnected(AValue: boolean); procedure CreateGroups; @@ -213,8 +216,6 @@ type procedure UpdateSelUnitsTreeView; procedure UpdateAllUnitsTreeViewSearch; procedure UpdateSelUnitsTreeViewSearch; - function FindNextTVNode(StartNode: TTreeNode; - LowerSearch: string; SearchNext, SkipStart: boolean): TTreeNode; function GetImgIndex(Node: TUDNode): integer; function NodeTextToUnit(NodeText: string): TUGUnit; function UGUnitToNodeText(UGUnit: TUGUnit): string; @@ -335,6 +336,7 @@ begin fImgIndexPackage := IDEImages.LoadImage(16, 'pkg_required'); fImgIndexDirectory := IDEImages.LoadImage(16, 'pkg_files'); AllUnitsTreeView.Images:=IDEImages.Images_16; + SelUnitsTreeView.Images:=IDEImages.Images_16; Caption:='Unit Dependencies'; RefreshButton.Caption:='Refresh'; @@ -399,8 +401,38 @@ begin StartParsing; end; +procedure TUnitDependenciesWindow.SelUnitsTreeViewExpanding(Sender: TObject; + Node: TTreeNode; var AllowExpansion: Boolean); +var + UDNode: TUDNode; +begin + if Node.Count>0 then exit; + if not (TObject(Node.Data) is TUDNode) then exit; + UDNode:=TUDNode(Node.Data); + if UDNode.Typ=udnUnit then begin + AddUsesSubNodes(UDNode); + CreateTVNodes(SelUnitsTreeView,Node,UDNode,false); + AllowExpansion:=true; + end; +end; + procedure TUnitDependenciesWindow.UnitsTreeViewShowHint(Sender: TObject; HintInfo: PHintInfo); + + procedure CountUses(List: TFPList; out IntfCnt, ImplCnt: integer); + var + i: Integer; + begin + IntfCnt:=0; + ImplCnt:=0; + if List=nil then exit; + for i:=0 to List.Count-1 do + if TUGUses(List[i]).InImplementation then + inc(ImplCnt) + else + inc(IntfCnt); + end; + var TV: TTreeView; TVNode: TTreeNode; @@ -408,6 +440,11 @@ var UDNode: TUDNode; Filename: String; s: String; + UGUnit: TUGUnit; + UsedByIntf: Integer; + UsedByImpl: Integer; + UsesIntf: integer; + UsesImpl: integer; begin TV:=Sender as TTreeView; p:=HintInfo^.CursorPos; @@ -417,6 +454,21 @@ begin Filename:=GetFilename(UDNode); if Filename='' then exit; s:='File: '+Filename; + if UDNode.Typ=udnUnit then begin + UGUnit:=UsesGraph.GetUnit(Filename,false); + if UGUnit<>nil then begin + CountUses(UGUnit.UsesUnits,UsesIntf,UsesImpl); + CountUses(UGUnit.UsedByUnits,UsedByIntf,UsedByImpl); + if UsesIntf>0 then + s+=LineEnding+'Interface Uses: '+IntToStr(UsesIntf); + if UsesImpl>0 then + s+=LineEnding+'Implementation Uses: '+IntToStr(UsesImpl); + if UsedByIntf>0 then + s+=LineEnding+'Used by Interfaces: '+IntToStr(UsedByIntf); + if UsedByImpl>0 then + s+=LineEnding+'Used by Implementations: '+IntToStr(UsedByImpl); + end; + end; HintInfo^.HintStr:=s; end; @@ -531,6 +583,7 @@ begin UpdateSelUnitsTreeViewSearch else IdleConnected:=false; + Done:=not IdleConnected; end; procedure TUnitDependenciesWindow.SearchPkgsCheckBoxChange(Sender: TObject); @@ -953,6 +1006,33 @@ begin end; function TUnitDependenciesWindow.CreateSelUnitsTree: TUDNode; +var + RootNode: TUDNode; + SelTVNode: TTreeNode; + SelUDNode: TUDNode; + UDNode: TUDNode; +begin + RootNode:=TUDNode.Create; + SelTVNode:=AllUnitsTreeView.GetFirstMultiSelected; + if SelTVNode=nil then + SelTVNode:=AllUnitsTreeView.Selected; + //debugln(['TUnitDependenciesWindow.CreateSelUnitsTree SelTVNode=',SelTVNode<>nil]); + while SelTVNode<>nil do begin + if TObject(SelTVNode.Data) is TUDNode then begin + SelUDNode:=TUDNode(SelTVNode.Data); + if SelUDNode.Typ=udnUnit then begin + UDNode:=RootNode.GetNode(udnUnit,SelUDNode.NodeText,true); + UDNode.Identifier:=SelUDNode.Identifier; + UDNode.Group:=SelUDNode.Group; + AddUsesSubNodes(UDNode); + end; + end; + SelTVNode:=SelTVNode.GetNextMultiSelected; + end; + Result:=RootNode; +end; + +procedure TUnitDependenciesWindow.AddUsesSubNodes(UDNode: TUDNode); procedure AddUses(ParentUDNode: TUDNode; UsesList: TFPList; NodeTyp: TUDNodeType); @@ -967,6 +1047,7 @@ function TUnitDependenciesWindow.CreateSelUnitsTree: TUDNode; Filename: String; UDNode: TUDNode; GroupName: String; + Cnt: Integer; begin if ParentUDNode=nil then exit; if UsesList=nil then exit; @@ -974,20 +1055,31 @@ function TUnitDependenciesWindow.CreateSelUnitsTree: TUDNode; then exit; InImplementation:=(NodeTyp in [udnImplementation,udnUsedByImplementation]); UsedBy:=(NodeTyp in [udnUsedByInterface,udnUsedByImplementation]); - SectionUDNode:=nil; + + // count the number of uses + Cnt:=0; + for i:=0 to UsesList.Count-1 do begin + UGUses:=TUGUses(UsesList[i]); + if UGUses.InImplementation<>InImplementation then continue; + inc(Cnt); + end; + if Cnt=0 then exit; + + // create a section node + NodeText:=IntToStr(Cnt); + case NodeTyp of + udnInterface: NodeText:=Format('interface uses: %s',[NodeText]); + udnImplementation: NodeText:=Format('implementation uses: %s',[NodeText]); + udnUsedByInterface: NodeText:=Format('used by interfaces: %s',[NodeText]); + udnUsedByImplementation: NodeText:=Format('used by implementations: %s',[NodeText]); + else exit; + end; + SectionUDNode:=ParentUDNode.GetNode(NodeTyp,NodeText,true); + + // create unit nodes for i:=0 to UsesList.Count-1 do begin UGUses:=TUGUses(UsesList[i]); if UGUses.InImplementation<>InImplementation then continue; - if SectionUDNode=nil then begin - case NodeTyp of - udnInterface: NodeText:='interface uses'; - udnImplementation: NodeText:='implementation uses'; - udnUsedByInterface: NodeText:='used by interfaces'; - udnUsedByImplementation: NodeText:='used by implementations'; - else NodeText:=''; - end; - SectionUDNode:=ParentUDNode.GetNode(NodeTyp,NodeText,true); - end; if UsedBy then OtherUnit:=TUGGroupUnit(UGUses.Owner) else @@ -1001,44 +1093,25 @@ function TUnitDependenciesWindow.CreateSelUnitsTree: TUDNode; else GroupName:=GroupNone; UDNode.Group:=GroupName; + UDNode.HasChildren:= + ((OtherUnit.UsedByUnits<>nil) and (OtherUnit.UsedByUnits.Count>0)) + or ((OtherUnit.UsesUnits<>nil) and (OtherUnit.UsesUnits.Count>0)); end; end; var - RootNode: TUDNode; - SelTVNode: TTreeNode; - SelUDNode: TUDNode; - UDNode: TUDNode; Filename: String; UGUnit: TUGGroupUnit; begin - RootNode:=TUDNode.Create; - SelTVNode:=AllUnitsTreeView.GetFirstMultiSelected; - if SelTVNode=nil then - SelTVNode:=AllUnitsTreeView.Selected; - //debugln(['TUnitDependenciesWindow.CreateSelUnitsTree SelTVNode=',SelTVNode<>nil]); - while SelTVNode<>nil do begin - if TObject(SelTVNode.Data) is TUDNode then begin - SelUDNode:=TUDNode(SelTVNode.Data); - if SelUDNode.Typ=udnUnit then begin - UDNode:=RootNode.GetNode(udnUnit,SelUDNode.NodeText,true); - UDNode.Identifier:=SelUDNode.Identifier; - UDNode.Group:=SelUDNode.Group; - - // add connected units - Filename:=UDNode.Identifier; - UGUnit:=TUGGroupUnit(UsesGraph.GetUnit(Filename,false)); - if UGUnit<>nil then begin - AddUses(UDNode,UGUnit.UsesUnits,udnInterface); - AddUses(UDNode,UGUnit.UsesUnits,udnImplementation); - AddUses(UDNode,UGUnit.UsedByUnits,udnUsedByInterface); - AddUses(UDNode,UGUnit.UsedByUnits,udnUsedByImplementation); - end; - end; - end; - SelTVNode:=SelTVNode.GetNextMultiSelected; + // add connected units + Filename:=UDNode.Identifier; + UGUnit:=TUGGroupUnit(UsesGraph.GetUnit(Filename,false)); + if UGUnit<>nil then begin + AddUses(UDNode,UGUnit.UsesUnits,udnInterface); + AddUses(UDNode,UGUnit.UsesUnits,udnImplementation); + AddUses(UDNode,UGUnit.UsedByUnits,udnUsedByInterface); + AddUses(UDNode,UGUnit.UsedByUnits,udnUsedByImplementation); end; - Result:=RootNode; end; procedure TUnitDependenciesWindow.SelectNextSearchTV(TV: TTreeView; @@ -1114,7 +1187,8 @@ begin for j:=0 to Pkg.FileCount-1 do begin PkgFile:=Pkg.Files[j]; if PkgFile.Removed then continue; - // ToDo: check if unit is used + if not (PkgFile.FileType in PkgFileRealUnitTypes) then continue; + if not PkgFile.InUses then continue; aFilename:=PkgFile.GetFullFilename; if FilenameIsAbsolute(AFilename) and FilenameIsPascalUnit(AFilename) then @@ -1416,7 +1490,7 @@ begin end; procedure TUnitDependenciesWindow.CreateTVNodes(TV: TTreeView; - ParentTVNode: TTreeNode; ParentUDNode: TUDNode); + ParentTVNode: TTreeNode; ParentUDNode: TUDNode; Expand: boolean); var AVLNode: TAVLTreeNode; UDNode: TUDNode; @@ -1431,8 +1505,9 @@ begin TVNode.Data:=UDNode; TVNode.ImageIndex:=GetImgIndex(UDNode); TVNode.SelectedIndex:=TVNode.ImageIndex; - CreateTVNodes(TV,TVNode,UDNode); - TVNode.Expanded:=true; + TVNode.HasChildren:=UDNode.HasChildren; + CreateTVNodes(TV,TVNode,UDNode,Expand); + TVNode.Expanded:=Expand and (TVNode.Count>0); AVLNode:=ParentUDNode.ChildNodes.FindSuccessor(AVLNode); end; end; @@ -1451,6 +1526,7 @@ procedure TUnitDependenciesWindow.UpdateAllUnitsTreeView; var TV: TTreeView; OldExpanded: TTreeNodeExpandedState; + SrcEdit: TSourceEditorInterface; begin Exclude(FFlags,udwNeedUpdateAllUnitsTreeView); TV:=AllUnitsTreeView; @@ -1466,7 +1542,7 @@ begin TV.Items.Clear; // create nodes FAllUnitsRootUDNode:=CreateAllUnitsTree; - CreateTVNodes(TV,nil,FAllUnitsRootUDNode); + CreateTVNodes(TV,nil,FAllUnitsRootUDNode,true); // restore old expanded state if OldExpanded<>nil then begin OldExpanded.Apply(TV); @@ -1474,6 +1550,16 @@ begin end; // update search UpdateAllUnitsTreeViewSearch; + // select a unit + if TV.Selected=nil then begin + SrcEdit:=SourceEditorManagerIntf.ActiveEditor; + if SrcEdit<>nil then + TV.Selected:=FindUnitTVNodeWithFilename(TV,SrcEdit.FileName); + end; + if (TV.Selected=nil) and (LazarusIDE.ActiveProject<>nil) + and (LazarusIDE.ActiveProject.MainFile<>nil) then + TV.Selected:=FindUnitTVNodeWithFilename(TV,LazarusIDE.ActiveProject.MainFile.Filename); + TV.EndUpdate; end; @@ -1491,7 +1577,7 @@ begin TV.Items.Clear; // create nodes FSelUnitsRootUDNode:=CreateSelUnitsTree; - CreateTVNodes(TV,nil,FSelUnitsRootUDNode); + CreateTVNodes(TV,nil,FSelUnitsRootUDNode,true); // update search UpdateSelUnitsTreeViewSearch; TV.EndUpdate; @@ -1526,6 +1612,24 @@ begin end; end; +function TUnitDependenciesWindow.FindUnitTVNodeWithFilename(TV: TTreeView; + aFilename: string): TTreeNode; +var + i: Integer; + UDNode: TUDNode; +begin + for i:=0 to TV.Items.Count-1 do begin + Result:=TV.Items[i]; + if TObject(Result.Data) is TUDNode then begin + UDNode:=TUDNode(Result.Data); + if (UDNode.Typ in [udnDirectory,udnUnit]) + and (CompareFilenames(UDNode.Identifier,aFilename)=0) then + exit; + end; + end; + Result:=nil; +end; + function TUnitDependenciesWindow.GetImgIndex(Node: TUDNode): integer; begin case Node.Typ of