mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-05 07:38:15 +02:00
started codeexplorer
git-svn-id: trunk@4289 -
This commit is contained in:
parent
d1bd70761c
commit
d261f58365
@ -15,12 +15,12 @@ interface
|
||||
|
||||
uses
|
||||
MemCheck,
|
||||
CodeToolManager, CustomCodeTool, PascalParserTool, FindDeclarationTool,
|
||||
StdCodeTools, MethodJumpTool, EventCodeTool, CodeCompletionTool, LinkScanner,
|
||||
FindDeclarationCache, BasicCodeTools, CodeTree, CodeAtom, SourceChanger,
|
||||
CodeToolMemManager, CodeCache, KeywordFuncLists, SourceLog, ExprEval,
|
||||
DefineTemplates, FileProcs, AVL_Tree, CodeToolsStrConsts,
|
||||
MultiKeyWordListTool, ResourceCodeTool, CodeToolsStructs;
|
||||
CodeToolManager, CustomCodeTool, PascalParserTool, PascalReaderTool,
|
||||
FindDeclarationTool, StdCodeTools, MethodJumpTool, EventCodeTool,
|
||||
CodeCompletionTool, LinkScanner, FindDeclarationCache, BasicCodeTools,
|
||||
CodeTree, CodeAtom, SourceChanger, CodeToolMemManager, CodeCache,
|
||||
KeywordFuncLists, SourceLog, ExprEval, DefineTemplates, FileProcs, AVL_Tree,
|
||||
CodeToolsStrConsts, MultiKeyWordListTool, ResourceCodeTool, CodeToolsStructs;
|
||||
|
||||
|
||||
implementation
|
||||
@ -30,6 +30,9 @@ end.
|
||||
{ =============================================================================
|
||||
|
||||
$Log$
|
||||
Revision 1.14 2003/06/19 16:36:35 mattias
|
||||
started codeexplorer
|
||||
|
||||
Revision 1.13 2003/03/02 09:04:02 mattias
|
||||
added make resourcestring dialog, not finished
|
||||
|
||||
|
@ -212,11 +212,13 @@ type
|
||||
function GetUnitLinksForDirectory(const Directory: string): string;
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
// syntax checking (true on syntax is ok)
|
||||
|
||||
// code exploring
|
||||
function Explore(Code: TCodeBuffer; var ACodeTool: TCodeTool;
|
||||
WithStatements: boolean): boolean;
|
||||
function CheckSyntax(Code: TCodeBuffer; var NewCode: TCodeBuffer;
|
||||
var NewX, NewY, NewTopLine: integer; var ErrorMsg: string): boolean;
|
||||
|
||||
|
||||
// compiler directives
|
||||
function GuessMisplacedIfdefEndif(Code: TCodeBuffer; X,Y: integer;
|
||||
var NewCode: TCodeBuffer;
|
||||
@ -240,7 +242,7 @@ type
|
||||
function GuessUnclosedBlock(Code: TCodeBuffer; X,Y: integer;
|
||||
var NewCode: TCodeBuffer;
|
||||
var NewX, NewY, NewTopLine: integer): boolean;
|
||||
|
||||
|
||||
// method jumping
|
||||
function JumpToMethod(Code: TCodeBuffer; X,Y: integer;
|
||||
var NewCode: TCodeBuffer;
|
||||
@ -258,7 +260,7 @@ type
|
||||
function GetIdentifierAt(Code: TCodeBuffer; X,Y: integer;
|
||||
var Identifier: string): boolean;
|
||||
|
||||
// resource string sections
|
||||
// resourcestring sections
|
||||
function GatherResourceStringSections(
|
||||
Code: TCodeBuffer; X,Y: integer;
|
||||
CodePositions: TCodeXYPositions): boolean;
|
||||
@ -739,6 +741,22 @@ begin
|
||||
Result:=Evaluator[ExternalMacroStart+'UnitLinks'];
|
||||
end;
|
||||
|
||||
function TCodeToolManager.Explore(Code: TCodeBuffer;
|
||||
var ACodeTool: TCodeTool; WithStatements: boolean): boolean;
|
||||
begin
|
||||
Result:=false;
|
||||
ACodeTool:=nil;
|
||||
try
|
||||
if InitCurCodeTool(Code) then begin
|
||||
ACodeTool:=FCurCodeTool;
|
||||
FCurCodeTool.Explore(WithStatements);
|
||||
Result:=true;
|
||||
end;
|
||||
except
|
||||
on e: Exception do Result:=HandleException(e);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TCodeToolManager.InitCurCodeTool(Code: TCodeBuffer): boolean;
|
||||
var MainCode: TCodeBuffer;
|
||||
begin
|
||||
@ -839,16 +857,10 @@ function TCodeToolManager.CheckSyntax(Code: TCodeBuffer;
|
||||
var NewCode: TCodeBuffer; var NewX, NewY, NewTopLine: integer;
|
||||
var ErrorMsg: string): boolean;
|
||||
// returns true on syntax correct
|
||||
var
|
||||
ACodeTool: TCodeTool;
|
||||
begin
|
||||
Result:=false;
|
||||
try
|
||||
if InitCurCodeTool(Code) then begin
|
||||
FCurCodeTool.BuildTree(false);
|
||||
Result:=true;
|
||||
end;
|
||||
except
|
||||
on e: Exception do Result:=HandleException(e);
|
||||
end;
|
||||
Result:=Explore(Code,ACodeTool,true);
|
||||
NewCode:=ErrorCode;
|
||||
NewX:=ErrorColumn;
|
||||
NewY:=ErrorLine;
|
||||
|
@ -21,7 +21,7 @@
|
||||
Author: Mattias Gaertner
|
||||
|
||||
Abstract:
|
||||
TFindDeclarationTool enhances the TPascalParserTool with the ability
|
||||
TFindDeclarationTool enhances the TPascalReaderTool with the ability
|
||||
to find the source position or code tree node of a declaration.
|
||||
|
||||
|
||||
@ -78,7 +78,8 @@ uses
|
||||
{$ENDIF}
|
||||
Classes, SysUtils, CodeToolsStrConsts, CodeTree, CodeAtom, CustomCodeTool,
|
||||
SourceLog, KeywordFuncLists, BasicCodeTools, LinkScanner, CodeCache, AVL_Tree,
|
||||
TypInfo, PascalParserTool, FileProcs, DefineTemplates, FindDeclarationCache;
|
||||
TypInfo, PascalParserTool, PascalReaderTool, FileProcs, DefineTemplates,
|
||||
FindDeclarationCache;
|
||||
|
||||
type
|
||||
TFindDeclarationTool = class;
|
||||
@ -459,7 +460,7 @@ type
|
||||
|
||||
{ TFindDeclarationTool }
|
||||
|
||||
TFindDeclarationTool = class(TPascalParserTool)
|
||||
TFindDeclarationTool = class(TPascalReaderTool)
|
||||
private
|
||||
FInterfaceIdentifierCache: TInterfaceIdentifierCache;
|
||||
FOnFindUsedUnit: TOnFindUsedUnit;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -46,9 +46,9 @@ uses
|
||||
MemCheck,
|
||||
{$ENDIF}
|
||||
Classes, SysUtils, CodeToolsStrConsts, CodeTree, CodeAtom,
|
||||
IdentCompletionTool, PascalParserTool, SourceLog, KeywordFuncLists,
|
||||
BasicCodeTools, LinkScanner, CodeCache, AVL_Tree, TypInfo, SourceChanger,
|
||||
CustomCodeTool, CodeToolsStructs;
|
||||
IdentCompletionTool, PascalReaderTool, PascalParserTool, SourceLog,
|
||||
KeywordFuncLists, BasicCodeTools, LinkScanner, CodeCache, AVL_Tree, TypInfo,
|
||||
SourceChanger, CustomCodeTool, CodeToolsStructs;
|
||||
|
||||
type
|
||||
TStandardCodeTool = class(TIdentCompletionTool)
|
||||
@ -59,12 +59,14 @@ type
|
||||
function ReadForwardTilAnyBracketClose: boolean;
|
||||
function ReadBackwardTilAnyBracketClose: boolean;
|
||||
public
|
||||
// explore the code
|
||||
function Explore(WithStatements: boolean): boolean;
|
||||
|
||||
// source name e.g. 'unit UnitName;'
|
||||
function GetSourceNamePos(var NamePos: TAtomPosition): boolean;
|
||||
function GetSourceName: string;
|
||||
function GetCachedSourceName: string;
|
||||
function RenameSource(const NewName: string;
|
||||
SourceChangeCache: TSourceChangeCache): boolean;
|
||||
SourceChangeCache: TSourceChangeCache): boolean;
|
||||
|
||||
// uses sections
|
||||
function FindUnitInUsesSection(UsesNode: TCodeTreeNode;
|
||||
@ -234,24 +236,11 @@ end;
|
||||
|
||||
{ TStandardCodeTool }
|
||||
|
||||
function TStandardCodeTool.GetSourceNamePos(
|
||||
var NamePos: TAtomPosition): boolean;
|
||||
begin
|
||||
Result:=false;
|
||||
BuildTree(true);
|
||||
NamePos.StartPos:=-1;
|
||||
if Tree.Root=nil then exit;
|
||||
MoveCursorToNodeStart(Tree.Root);
|
||||
ReadNextAtom; // read source type 'program', 'unit' ...
|
||||
ReadNextAtom; // read name
|
||||
NamePos:=CurPos;
|
||||
Result:=(NamePos.StartPos<=SrcLen);
|
||||
end;
|
||||
|
||||
function TStandardCodeTool.GetSourceName: string;
|
||||
var NamePos: TAtomPosition;
|
||||
begin
|
||||
Result:='';
|
||||
BuildTree(true);
|
||||
if not GetSourceNamePos(NamePos) then exit;
|
||||
CachedSourceName:=copy(Src,NamePos.StartPos,NamePos.EndPos-NamePos.StartPos);
|
||||
Result:=CachedSourceName;
|
||||
@ -284,6 +273,7 @@ function TStandardCodeTool.RenameSource(const NewName: string;
|
||||
var NamePos: TAtomPosition;
|
||||
begin
|
||||
Result:=false;
|
||||
BuildTree(true);
|
||||
if (not GetSourceNamePos(NamePos)) or (NamePos.StartPos<1) or (NewName='')
|
||||
or (Length(NewName)>255) then exit;
|
||||
SourceChangeCache.MainScanner:=Scanner;
|
||||
@ -1486,7 +1476,7 @@ function TStandardCodeTool.GatherResourceStringSections(
|
||||
function SearchInUsesSection(UsesNode: TCodeTreeNode): boolean;
|
||||
var
|
||||
InAtom, UnitNameAtom: TAtomPosition;
|
||||
NewCodeTool: TPascalParserTool;
|
||||
NewCodeTool: TPascalReaderTool;
|
||||
ANode: TCodeTreeNode;
|
||||
NewCaret: TCodeXYPosition;
|
||||
begin
|
||||
@ -2581,6 +2571,30 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TStandardCodeTool.Explore(WithStatements: boolean): boolean;
|
||||
|
||||
procedure ExploreNode(ANode: TCodeTreeNode);
|
||||
begin
|
||||
if ANode=nil then exit;
|
||||
case ANode.Desc of
|
||||
ctnClass,ctnClassInterface:
|
||||
BuildSubTreeForClass(ANode);
|
||||
ctnProcedure,ctnProcedureHead:
|
||||
BuildSubTreeForProcHead(ANode);
|
||||
ctnBeginBlock:
|
||||
if WithStatements then
|
||||
BuildSubTreeForBeginBlock(ANode);
|
||||
end;
|
||||
ExploreNode(ANode.FirstChild);
|
||||
ExploreNode(ANode.NextBrother);
|
||||
end;
|
||||
|
||||
begin
|
||||
Result:=true;
|
||||
BuildTree(false);
|
||||
ExploreNode(Tree.Root);
|
||||
end;
|
||||
|
||||
|
||||
end.
|
||||
|
||||
|
@ -38,6 +38,7 @@ uses
|
||||
|
||||
type
|
||||
TNonModalIDEWindow = (
|
||||
// empty/none/undefined
|
||||
nmiwNone,
|
||||
nmiwMainIDEName,
|
||||
nmiwSourceNoteBookName,
|
||||
@ -47,6 +48,7 @@ type
|
||||
nmiwClipbrdHistoryName,
|
||||
nmiwPkgGraphExplorer,
|
||||
nmiwProjectInspector,
|
||||
// debugger
|
||||
nmiwDbgOutput,
|
||||
nmiwBreakPoints,
|
||||
nmiwWatches,
|
||||
@ -62,7 +64,7 @@ const
|
||||
'SourceNotebook',
|
||||
'MessagesView',
|
||||
'UnitDependencies',
|
||||
'CodeExplorer',
|
||||
'CodeExplorerView',
|
||||
'ClipBrdHistory',
|
||||
'PkgGraphExplorer',
|
||||
'ProjectInspector',
|
||||
|
@ -946,7 +946,6 @@ begin
|
||||
itmViewCodeExplorer := TMenuItem.Create(Self);
|
||||
itmViewCodeExplorer.Name:='itmViewCodeExplorer';
|
||||
itmViewCodeExplorer.Caption := lisMenuViewCodeExplorer;
|
||||
itmViewCodeExplorer.Enabled := false;
|
||||
mnuView.Add(itmViewCodeExplorer);
|
||||
|
||||
mnuView.Add(CreateMenuSeparator);
|
||||
|
@ -45,8 +45,9 @@ uses
|
||||
MemCheck,
|
||||
{$ENDIF}
|
||||
Classes, SysUtils, Controls, Forms, Dialogs, Buttons, ComCtrls, StdCtrls,
|
||||
CodeToolManager, CodeCache, EnvironmentOpts, LResources, IDEOptionDefs,
|
||||
LazarusIDEStrConsts, InputHistory, IDEProcs, Graphics, LCLType, FileCtrl;
|
||||
Graphics, LCLType, FileCtrl, LResources,
|
||||
CodeToolManager, CodeCache,
|
||||
EnvironmentOpts, IDEOptionDefs, LazarusIDEStrConsts, InputHistory, IDEProcs;
|
||||
|
||||
type
|
||||
|
||||
|
@ -38,9 +38,9 @@ unit ComCtrls;
|
||||
interface
|
||||
|
||||
uses
|
||||
SysUtils, Classes, LCLStrConsts, Controls, Forms, LclLinux, LCLType, LCLProc,
|
||||
StdCtrls, ExtCtrls, vclGlobals, lMessages, Menus, ImgList, GraphType,
|
||||
Graphics, ToolWin, CommCtrl, Buttons, Math;
|
||||
SysUtils, Classes, LCLStrConsts, LCLLinux, LCLType, LCLProc, AvgLvlTree,
|
||||
Controls, Forms, StdCtrls, ExtCtrls, vclGlobals, LMessages, Menus, ImgList,
|
||||
GraphType, Graphics, ToolWin, CommCtrl, Buttons, Math;
|
||||
|
||||
type
|
||||
TStatusPanelStyle = (psText, psOwnerDraw);
|
||||
@ -600,6 +600,7 @@ type
|
||||
property OnMouseUp;
|
||||
end;
|
||||
|
||||
|
||||
{ TToolBar }
|
||||
|
||||
const
|
||||
@ -1206,7 +1207,8 @@ type
|
||||
property Top: integer read GetTop;
|
||||
end;
|
||||
|
||||
{ TTreeNodes }
|
||||
|
||||
{ TTreeNodes }
|
||||
|
||||
PNodeCache = ^TNodeCache;
|
||||
TNodeCache = record
|
||||
@ -1296,7 +1298,7 @@ type
|
||||
read GetTopLvlItems write SetTopLvlItems;
|
||||
end;
|
||||
|
||||
{ TCustomTreeView }
|
||||
{ TCustomTreeView }
|
||||
|
||||
TTreeViewState = (
|
||||
tvsScrollbarChanged,
|
||||
@ -1699,6 +1701,35 @@ type
|
||||
property OnStartDrag;
|
||||
property Items;
|
||||
end;
|
||||
|
||||
|
||||
{ TTreeNodeExpandedState }
|
||||
{ class to store and restore the expanded state of a TTreeView
|
||||
The nodes are identified by their Text property.
|
||||
|
||||
Usage example:
|
||||
// save old expanded state
|
||||
OldExpanded:=TTreeNodeExpandedState.Create(ATreeView);
|
||||
... change a lot of nodes ...
|
||||
// restore old expanded state
|
||||
OldExpanded.Apply(ATreeView);
|
||||
OldExpanded.Free;
|
||||
}
|
||||
|
||||
TTreeNodeExpandedState = class
|
||||
NodeText: string;
|
||||
Childs: TAvgLvlTree;
|
||||
constructor Create(FirstTreeNode: TTreeNode);
|
||||
constructor Create(TreeView: TCustomTreeView);
|
||||
destructor Destroy; override;
|
||||
procedure Clear;
|
||||
procedure CreateChildNodes(FirstTreeNode: TTreeNode);
|
||||
procedure Apply(FirstTreeNode: TTreeNode);
|
||||
procedure Apply(TreeView: TCustomTreeView);
|
||||
end;
|
||||
|
||||
function CompareExpandedNodes(Data1, Data2: Pointer): integer;
|
||||
function CompareTextWithExpandedNode(Key, Data: Pointer): integer;
|
||||
|
||||
function InitCommonControl(CC: Integer): Boolean;
|
||||
procedure CheckCommonControl(CC: Integer);
|
||||
@ -1769,6 +1800,9 @@ end.
|
||||
{ =============================================================================
|
||||
|
||||
$Log$
|
||||
Revision 1.79 2003/06/19 16:36:35 mattias
|
||||
started codeexplorer
|
||||
|
||||
Revision 1.78 2003/06/18 11:21:06 mattias
|
||||
fixed taborder=0, implemented TabOrder Editor
|
||||
|
||||
|
@ -27,8 +27,9 @@ begin
|
||||
FCanvas := TControlCanvas.Create;
|
||||
TControlCanvas(FCanvas).Control := Self;
|
||||
Color := clBtnFace;
|
||||
Height:=20;
|
||||
Anchors:=[akLeft,akRight,akBottom];
|
||||
Align := alBottom;
|
||||
Height:=20;
|
||||
end;
|
||||
|
||||
|
||||
|
@ -38,7 +38,25 @@ const
|
||||
// maximum scroll range
|
||||
//MAX_SCROLL = 32767;
|
||||
|
||||
function CompareExpandedNodes(Data1, Data2: Pointer): integer;
|
||||
var
|
||||
Node1: TTreeNodeExpandedState;
|
||||
Node2: TTreeNodeExpandedState;
|
||||
begin
|
||||
Node1:=TTreeNodeExpandedState(Data1);
|
||||
Node2:=TTreeNodeExpandedState(Data2);
|
||||
Result:=AnsiCompareText(Node1.NodeText,Node2.NodeText);
|
||||
end;
|
||||
|
||||
function CompareTextWithExpandedNode(Key, Data: Pointer): integer;
|
||||
var
|
||||
NodeText: String;
|
||||
Node: TTreeNodeExpandedState;
|
||||
begin
|
||||
NodeText:=String(Key);
|
||||
Node:=TTreeNodeExpandedState(Data);
|
||||
Result:=AnsiCompareText(NodeText,Node.NodeText);
|
||||
end;
|
||||
|
||||
procedure TreeViewError(const Msg: string);
|
||||
begin
|
||||
@ -81,6 +99,75 @@ begin
|
||||
Result:=-1;
|
||||
end;
|
||||
|
||||
{ TTreeNodeExpandedState }
|
||||
|
||||
constructor TTreeNodeExpandedState.Create(FirstTreeNode: TTreeNode);
|
||||
begin
|
||||
CreateChildNodes(FirstTreeNode);
|
||||
end;
|
||||
|
||||
constructor TTreeNodeExpandedState.Create(TreeView: TCustomTreeView);
|
||||
begin
|
||||
CreateChildNodes(TreeView.Items.GetFirstNode);
|
||||
end;
|
||||
|
||||
destructor TTreeNodeExpandedState.Destroy;
|
||||
begin
|
||||
Clear;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TTreeNodeExpandedState.Clear;
|
||||
begin
|
||||
if Childs<>nil then begin
|
||||
Childs.FreeAndClear;
|
||||
FreeThenNil(Childs);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TTreeNodeExpandedState.CreateChildNodes(FirstTreeNode: TTreeNode);
|
||||
var
|
||||
ChildNode: TTreeNode;
|
||||
NewExpandedNode: TTreeNodeExpandedState;
|
||||
begin
|
||||
if (FirstTreeNode<>nil) and (FirstTreeNode.Parent<>nil) then
|
||||
NodeText:=FirstTreeNode.Parent.Text
|
||||
else
|
||||
NodeText:='';
|
||||
Clear;
|
||||
ChildNode:=FirstTreeNode;
|
||||
while ChildNode<>nil do begin
|
||||
if ChildNode.Expanded then begin
|
||||
if Childs=nil then Childs:=TAvgLvlTree.Create(@CompareExpandedNodes);
|
||||
NewExpandedNode:=TTreeNodeExpandedState.Create(ChildNode.GetFirstChild);
|
||||
Childs.Add(NewExpandedNode);
|
||||
end;
|
||||
ChildNode:=ChildNode.GetNextSibling;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TTreeNodeExpandedState.Apply(FirstTreeNode: TTreeNode);
|
||||
var
|
||||
ChildNode: TTreeNode;
|
||||
ANode: TAvgLvlTreeNode;
|
||||
ChildNodeText: String;
|
||||
begin
|
||||
if Childs=nil then exit;
|
||||
ChildNode:=FirstTreeNode;
|
||||
while ChildNode<>nil do begin
|
||||
ChildNodeText:=ChildNode.Text;
|
||||
ANode:=Childs.FindKey(PChar(ChildNodeText),@CompareTextWithExpandedNode);
|
||||
ChildNode.Expanded:=ANode<>nil;
|
||||
if ANode<>nil then
|
||||
TTreeNodeExpandedState(ANode.Data).Apply(ChildNode.GetFirstChild);
|
||||
ChildNode:=ChildNode.GetNextSibling;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TTreeNodeExpandedState.Apply(TreeView: TCustomTreeView);
|
||||
begin
|
||||
Apply(TreeView.Items.GetFirstNode);
|
||||
end;
|
||||
|
||||
{ TTreeNode }
|
||||
|
||||
|
@ -103,97 +103,6 @@ implementation
|
||||
|
||||
uses Math;
|
||||
|
||||
type
|
||||
TExpandedNode = class
|
||||
NodeText: string;
|
||||
Childs: TAVLTree;
|
||||
constructor Create(FirstTreeNode: TTreeNode);
|
||||
destructor Destroy; override;
|
||||
procedure Clear;
|
||||
procedure CreateChildNodes(FirstTreeNode: TTreeNode);
|
||||
procedure Apply(FirstTreeNode: TTreeNode);
|
||||
end;
|
||||
|
||||
function CompareExpandedNodes(Data1, Data2: Pointer): integer;
|
||||
var
|
||||
Node1: TExpandedNode;
|
||||
Node2: TExpandedNode;
|
||||
begin
|
||||
Node1:=TExpandedNode(Data1);
|
||||
Node2:=TExpandedNode(Data2);
|
||||
Result:=AnsiCompareText(Node1.NodeText,Node2.NodeText);
|
||||
end;
|
||||
|
||||
function CompareTextWithExpandedNode(Key, Data: Pointer): integer;
|
||||
var
|
||||
NodeText: String;
|
||||
Node: TExpandedNode;
|
||||
begin
|
||||
NodeText:=String(Key);
|
||||
Node:=TExpandedNode(Data);
|
||||
Result:=AnsiCompareText(NodeText,Node.NodeText);
|
||||
end;
|
||||
|
||||
{ TExpandedNode }
|
||||
|
||||
constructor TExpandedNode.Create(FirstTreeNode: TTreeNode);
|
||||
begin
|
||||
CreateChildNodes(FirstTreeNode);
|
||||
end;
|
||||
|
||||
destructor TExpandedNode.Destroy;
|
||||
begin
|
||||
Clear;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TExpandedNode.Clear;
|
||||
begin
|
||||
if Childs<>nil then begin
|
||||
Childs.FreeAndClear;
|
||||
FreeThenNil(Childs);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TExpandedNode.CreateChildNodes(FirstTreeNode: TTreeNode);
|
||||
var
|
||||
ChildNode: TTreeNode;
|
||||
NewExpandedNode: TExpandedNode;
|
||||
begin
|
||||
if (FirstTreeNode<>nil) and (FirstTreeNode.Parent<>nil) then
|
||||
NodeText:=FirstTreeNode.Parent.Text
|
||||
else
|
||||
NodeText:='';
|
||||
Clear;
|
||||
ChildNode:=FirstTreeNode;
|
||||
while ChildNode<>nil do begin
|
||||
if ChildNode.Expanded then begin
|
||||
if Childs=nil then Childs:=TAVLTree.Create(@CompareExpandedNodes);
|
||||
NewExpandedNode:=TExpandedNode.Create(ChildNode.GetFirstChild);
|
||||
Childs.Add(NewExpandedNode);
|
||||
end;
|
||||
ChildNode:=ChildNode.GetNextSibling;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TExpandedNode.Apply(FirstTreeNode: TTreeNode);
|
||||
var
|
||||
ChildNode: TTreeNode;
|
||||
ANode: TAVLTreeNode;
|
||||
ChildNodeText: String;
|
||||
begin
|
||||
if Childs=nil then exit;
|
||||
ChildNode:=FirstTreeNode;
|
||||
while ChildNode<>nil do begin
|
||||
ChildNodeText:=ChildNode.Text;
|
||||
ANode:=Childs.FindKey(PChar(ChildNodeText),@CompareTextWithExpandedNode);
|
||||
ChildNode.Expanded:=ANode<>nil;
|
||||
if ANode<>nil then
|
||||
TExpandedNode(ANode.Data).Apply(ChildNode.GetFirstChild);
|
||||
ChildNode:=ChildNode.GetNextSibling;
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TPkgGraphExplorer }
|
||||
|
||||
procedure TPkgGraphExplorer.PkgGraphExplorerResize(Sender: TObject);
|
||||
@ -534,7 +443,7 @@ var
|
||||
NextViewNode: TTreeNode;
|
||||
HiddenNode: TAVLTreeNode;
|
||||
CurPkg: TLazPackage;
|
||||
OldExpanded: TExpandedNode;
|
||||
OldExpanded: TTreeNodeExpandedState;
|
||||
begin
|
||||
// rebuild internal sorted packages
|
||||
fSortedPackages.Clear;
|
||||
@ -544,7 +453,7 @@ begin
|
||||
// rebuild the TreeView
|
||||
PkgTreeView.BeginUpdate;
|
||||
// save old expanded state
|
||||
OldExpanded:=TExpandedNode.Create(PkgTreeView.Items.GetFirstNode);
|
||||
OldExpanded:=TTreeNodeExpandedState.Create(PkgTreeView);
|
||||
// create first level
|
||||
CurIndex:=0;
|
||||
HiddenNode:=fSortedPackages.FindLowest;
|
||||
@ -569,7 +478,7 @@ begin
|
||||
ViewNode:=NextViewNode;
|
||||
end;
|
||||
// restore old expanded state
|
||||
OldExpanded.Apply(PkgTreeView.Items.GetFirstNode);
|
||||
OldExpanded.Apply(PkgTreeView);
|
||||
OldExpanded.Free;
|
||||
// completed
|
||||
PkgTreeView.EndUpdate;
|
||||
|
Loading…
Reference in New Issue
Block a user