mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-05 17:40:15 +02:00
MG: added icons to unitdependencies
git-svn-id: trunk@3342 -
This commit is contained in:
parent
1d4aa7e976
commit
4be5bbcd27
@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
Abstract:
|
Abstract:
|
||||||
Defines the TUnitDependenciesView form.
|
Defines the TUnitDependenciesView form.
|
||||||
|
The Unit Dependencies shows the used units in a treeview.
|
||||||
|
|
||||||
}
|
}
|
||||||
unit UnitDependencies;
|
unit UnitDependencies;
|
||||||
@ -43,19 +44,20 @@ uses
|
|||||||
{$IFDEF IDE_MEM_CHECK}
|
{$IFDEF IDE_MEM_CHECK}
|
||||||
MemCheck,
|
MemCheck,
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
Classes, SysUtils, Forms, Dialogs, Buttons, ComCtrls, StdCtrls,
|
Classes, SysUtils, Controls, Forms, Dialogs, Buttons, ComCtrls, StdCtrls,
|
||||||
CodeToolManager, CodeCache, EnvironmentOpts, LResources, IDEOptionDefs,
|
CodeToolManager, CodeCache, EnvironmentOpts, LResources, IDEOptionDefs,
|
||||||
LazarusIDEStrConsts, InputHistory;
|
LazarusIDEStrConsts, InputHistory, IDEProcs, Graphics;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
{ TUnitNode }
|
{ TUnitNode }
|
||||||
|
|
||||||
TUnitNodeFlag = (
|
TUnitNodeFlag = (
|
||||||
unfImplementation,// this unit was used in an implementation uses section
|
unfImplementation, // this unit was used in an implementation uses section
|
||||||
unfCircle, // this unit is the parent of itself
|
unfCircle, // this unit is the parent of itself
|
||||||
unfFileNotFound, // this unit file was not found
|
unfForbiddenCircle,// forbidden circle
|
||||||
unfParseError // error parsing the source
|
unfFileNotFound, // this unit file was not found
|
||||||
|
unfParseError // error parsing the source
|
||||||
);
|
);
|
||||||
TUnitNodeFlags = set of TUnitNodeFlag;
|
TUnitNodeFlags = set of TUnitNodeFlag;
|
||||||
|
|
||||||
@ -102,6 +104,7 @@ type
|
|||||||
procedure AddChild(const AFilename: string; ACodeBuffer: TCodeBuffer;
|
procedure AddChild(const AFilename: string; ACodeBuffer: TCodeBuffer;
|
||||||
InImplementation: boolean);
|
InImplementation: boolean);
|
||||||
procedure UpdateSourceType;
|
procedure UpdateSourceType;
|
||||||
|
function ForbiddenCircle: boolean;
|
||||||
public
|
public
|
||||||
constructor Create;
|
constructor Create;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
@ -111,7 +114,9 @@ type
|
|||||||
procedure CreateGrandChildren;
|
procedure CreateGrandChildren;
|
||||||
function FindParentWithCodeBuffer(ACodeBuffer: TCodeBuffer): TUnitNode;
|
function FindParentWithCodeBuffer(ACodeBuffer: TCodeBuffer): TUnitNode;
|
||||||
function HasChildren: boolean;
|
function HasChildren: boolean;
|
||||||
|
function ImageIndex: integer;
|
||||||
function IsImplementationNode: boolean;
|
function IsImplementationNode: boolean;
|
||||||
|
function StateImageIndex: integer;
|
||||||
property ChildCount: integer read FChildCount;
|
property ChildCount: integer read FChildCount;
|
||||||
property CodeBuffer: TCodeBuffer read FCodeBuffer write SetCodeBuffer;
|
property CodeBuffer: TCodeBuffer read FCodeBuffer write SetCodeBuffer;
|
||||||
property Filename: string read FFilename write SetFilename;
|
property Filename: string read FFilename write SetFilename;
|
||||||
@ -130,6 +135,8 @@ type
|
|||||||
{ TUnitDependenciesView }
|
{ TUnitDependenciesView }
|
||||||
|
|
||||||
TUnitDependenciesView = class(TForm)
|
TUnitDependenciesView = class(TForm)
|
||||||
|
SrcTypeImageList: TImageList;
|
||||||
|
FlagImageList: TImageList;
|
||||||
UnitHistoryList: TComboBox;
|
UnitHistoryList: TComboBox;
|
||||||
SelectUnitButton: TBitBtn;
|
SelectUnitButton: TBitBtn;
|
||||||
UnitTreeView: TTreeView;
|
UnitTreeView: TTreeView;
|
||||||
@ -164,6 +171,7 @@ const
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
|
||||||
{ TUnitDependenciesView }
|
{ TUnitDependenciesView }
|
||||||
|
|
||||||
procedure TUnitDependenciesView.UnitDependenciesViewResize(Sender: TObject);
|
procedure TUnitDependenciesView.UnitDependenciesViewResize(Sender: TObject);
|
||||||
@ -264,6 +272,16 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TUnitDependenciesView.Create(TheOwner: TComponent);
|
constructor TUnitDependenciesView.Create(TheOwner: TComponent);
|
||||||
|
|
||||||
|
procedure AddResImg(ImgList: TImageList; const ResName: string);
|
||||||
|
var Pixmap: TPixmap;
|
||||||
|
begin
|
||||||
|
Pixmap:=TPixmap.Create;
|
||||||
|
Pixmap.TransparentColor:=clWhite;
|
||||||
|
Pixmap.LoadFromLazarusResource(ResName);
|
||||||
|
ImgList.Add(Pixmap,nil)
|
||||||
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
ALayout: TIDEWindowLayout;
|
ALayout: TIDEWindowLayout;
|
||||||
begin
|
begin
|
||||||
@ -275,6 +293,31 @@ begin
|
|||||||
ALayout.Form:=TForm(Self);
|
ALayout.Form:=TForm(Self);
|
||||||
ALayout.Apply;
|
ALayout.Apply;
|
||||||
|
|
||||||
|
SrcTypeImageList:=TImageList.Create(Self);
|
||||||
|
with SrcTypeImageList do begin
|
||||||
|
Name:='SrcTypeImageList';
|
||||||
|
Width:=22;
|
||||||
|
Height:=22;
|
||||||
|
AddResImg(SrcTypeImageList,'srctype_unknown_22x22');
|
||||||
|
AddResImg(SrcTypeImageList,'srctype_unit_22x22');
|
||||||
|
AddResImg(SrcTypeImageList,'srctype_program_22x22');
|
||||||
|
AddResImg(SrcTypeImageList,'srctype_library_22x22');
|
||||||
|
AddResImg(SrcTypeImageList,'srctype_package_22x22');
|
||||||
|
AddResImg(SrcTypeImageList,'srctype_filenotfound_22x22');
|
||||||
|
AddResImg(SrcTypeImageList,'srctype_parseerror_22x22');
|
||||||
|
end;
|
||||||
|
|
||||||
|
FlagImageList:=TImageList.Create(Self);
|
||||||
|
with FlagImageList do begin
|
||||||
|
Name:='FlagImageList';
|
||||||
|
Width:=22;
|
||||||
|
Height:=22;
|
||||||
|
AddResImg(SrcTypeImageList,'interface_unit_22x22.xpm');
|
||||||
|
AddResImg(SrcTypeImageList,'implementation_unit_22x22.xpm');
|
||||||
|
AddResImg(SrcTypeImageList,'forbidden_unit_circle_22x22.xpm');
|
||||||
|
AddResImg(SrcTypeImageList,'allowed_unit_circle_22x22.xpm');
|
||||||
|
end;
|
||||||
|
|
||||||
UnitHistoryList:=TComboBox.Create(Self);
|
UnitHistoryList:=TComboBox.Create(Self);
|
||||||
with UnitHistoryList do begin
|
with UnitHistoryList do begin
|
||||||
Name:='UnitHistoryList';
|
Name:='UnitHistoryList';
|
||||||
@ -282,6 +325,7 @@ begin
|
|||||||
Left:=0;
|
Left:=0;
|
||||||
Top:=0;
|
Top:=0;
|
||||||
Width:=Parent.ClientWidth-Left;
|
Width:=Parent.ClientWidth-Left;
|
||||||
|
Enabled:=false;
|
||||||
Visible:=true;
|
Visible:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -293,6 +337,7 @@ begin
|
|||||||
Top:=UnitHistoryList.Top+UnitHistoryList.Height+2;
|
Top:=UnitHistoryList.Top+UnitHistoryList.Height+2;
|
||||||
Width:=25;
|
Width:=25;
|
||||||
Caption:='...';
|
Caption:='...';
|
||||||
|
Enabled:=false;
|
||||||
Visible:=true;
|
Visible:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -305,6 +350,7 @@ begin
|
|||||||
Width:=100;
|
Width:=100;
|
||||||
Height:=SelectUnitButton.Height;
|
Height:=SelectUnitButton.Height;
|
||||||
Caption:='Refresh';
|
Caption:='Refresh';
|
||||||
|
Enabled:=false;
|
||||||
Visible:=true;
|
Visible:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -318,6 +364,8 @@ begin
|
|||||||
Height:=Parent.ClientHeight-Top;
|
Height:=Parent.ClientHeight-Top;
|
||||||
OnExpanding:=@UnitTreeViewExpanding;
|
OnExpanding:=@UnitTreeViewExpanding;
|
||||||
OnCollapsing:=@UnitTreeViewCollapsing;
|
OnCollapsing:=@UnitTreeViewCollapsing;
|
||||||
|
Images:=SrcTypeImageList;
|
||||||
|
StateImages:=FlagImageList;
|
||||||
Visible:=true;
|
Visible:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -373,12 +421,19 @@ begin
|
|||||||
TreeNode.Text:=ShortFilename;
|
TreeNode.Text:=ShortFilename;
|
||||||
TreeNode.Data:=Self;
|
TreeNode.Data:=Self;
|
||||||
TreeNode.HasChildren:=HasChildren;
|
TreeNode.HasChildren:=HasChildren;
|
||||||
|
TreeNode.ImageIndex:=ImageIndex;
|
||||||
|
TreeNode.StateIndex:=StateImageIndex;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TUnitNode.CreateShortFilename;
|
procedure TUnitNode.CreateShortFilename;
|
||||||
begin
|
begin
|
||||||
ShortFilename:=Filename;
|
ShortFilename:=Filename;
|
||||||
|
if (Parent<>nil) and (FilenameIsAbsolute(Parent.Filename))
|
||||||
|
and (FilenameIsAbsolute(Filename)) then begin
|
||||||
|
ShortFilename:=ExtractRelativePath(ExtractFilePath(Parent.Filename),
|
||||||
|
Filename);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TUnitNode.UnbindFromParent;
|
procedure TUnitNode.UnbindFromParent;
|
||||||
@ -409,6 +464,7 @@ begin
|
|||||||
if Parent.FirstChild=nil then Parent.FFirstChild:=Self;
|
if Parent.FirstChild=nil then Parent.FFirstChild:=Self;
|
||||||
if PrevSibling<>nil then PrevSibling.FNextSibling:=Self;
|
if PrevSibling<>nil then PrevSibling.FNextSibling:=Self;
|
||||||
Inc(Parent.FChildCount);
|
Inc(Parent.FChildCount);
|
||||||
|
CreateShortFilename;
|
||||||
|
|
||||||
if Parent.TreeNode<>nil then begin
|
if Parent.TreeNode<>nil then begin
|
||||||
Parent.TreeNode.HasChildren:=true;
|
Parent.TreeNode.HasChildren:=true;
|
||||||
@ -428,8 +484,11 @@ begin
|
|||||||
NewNode.CodeBuffer:=ACodeBuffer;
|
NewNode.CodeBuffer:=ACodeBuffer;
|
||||||
NewNode.Filename:=AFilename;
|
NewNode.Filename:=AFilename;
|
||||||
if ACodeBuffer<>nil then begin
|
if ACodeBuffer<>nil then begin
|
||||||
if FindParentWithCodeBuffer(ACodeBuffer)<>nil then
|
if FindParentWithCodeBuffer(ACodeBuffer)<>nil then begin
|
||||||
Include(NewNode.FFlags,unfCircle);
|
Include(NewNode.FFlags,unfCircle);
|
||||||
|
if ForbiddenCircle then
|
||||||
|
Include(NewNode.FFlags,unfForbiddenCircle);
|
||||||
|
end;
|
||||||
end else begin
|
end else begin
|
||||||
Include(NewNode.FFlags,unfFileNotFound);
|
Include(NewNode.FFlags,unfFileNotFound);
|
||||||
end;
|
end;
|
||||||
@ -441,15 +500,38 @@ end;
|
|||||||
procedure TUnitNode.UpdateSourceType;
|
procedure TUnitNode.UpdateSourceType;
|
||||||
var
|
var
|
||||||
SourceKeyWord: string;
|
SourceKeyWord: string;
|
||||||
|
ASrcType: TUnitNodeSourceType;
|
||||||
begin
|
begin
|
||||||
FSourceType:=unstUnknown;
|
FSourceType:=unstUnknown;
|
||||||
if CodeBuffer=nil then exit;
|
if CodeBuffer=nil then exit;
|
||||||
SourceKeyWord:=CodeToolBoss.GetSourceType(CodeBuffer,false);
|
SourceKeyWord:=CodeToolBoss.GetSourceType(CodeBuffer,false);
|
||||||
for FSourceType:=Low(TUnitNodeSourceType) to High(TUnitNodeSourceType) do
|
for ASrcType:=Low(TUnitNodeSourceType) to High(TUnitNodeSourceType) do
|
||||||
if AnsiCompareText(SourceKeyWord,UnitNodeSourceTypeNames[FSourceType])=0
|
if AnsiCompareText(SourceKeyWord,UnitNodeSourceTypeNames[ASrcType])=0
|
||||||
then
|
then
|
||||||
exit;
|
FSourceType:=ASrcType;
|
||||||
FSourceType:=unstUnknown;
|
if TreeNode<>nil then begin
|
||||||
|
TreeNode.ImageIndex:=ImageIndex;
|
||||||
|
TreeNode.StateIndex:=StateImageIndex;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TUnitNode.ForbiddenCircle: boolean;
|
||||||
|
var
|
||||||
|
ParentNode, CurNode: TUnitNode;
|
||||||
|
begin
|
||||||
|
CurNode:=Self;
|
||||||
|
ParentNode:=Parent;
|
||||||
|
while ParentNode<>nil do begin
|
||||||
|
if ParentNode.CodeBuffer=CodeBuffer then begin
|
||||||
|
// circle detected
|
||||||
|
if unfImplementation in CurNode.Flags then begin
|
||||||
|
Result:=true;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
CurNode:=ParentNode;
|
||||||
|
ParentNode:=ParentNode.Parent;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TUnitNode.Create;
|
constructor TUnitNode.Create;
|
||||||
@ -532,10 +614,50 @@ begin
|
|||||||
Result:=FChildCount>0;
|
Result:=FChildCount>0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TUnitNode.ImageIndex: integer;
|
||||||
|
begin
|
||||||
|
case SourceType of
|
||||||
|
unstUnit: Result:=1;
|
||||||
|
unstProgram: Result:=2;
|
||||||
|
unstLibrary: Result:=3;
|
||||||
|
unstPackage: Result:=4;
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
if unfFileNotFound in Flags then
|
||||||
|
Result:=5
|
||||||
|
else if unfParseError in Flags then
|
||||||
|
Result:=6
|
||||||
|
else
|
||||||
|
Result:=0;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function TUnitNode.IsImplementationNode: boolean;
|
function TUnitNode.IsImplementationNode: boolean;
|
||||||
begin
|
begin
|
||||||
Result:=unfImplementation in FFlags;
|
Result:=unfImplementation in FFlags;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TUnitNode.StateImageIndex: integer;
|
||||||
|
begin
|
||||||
|
if not (unfCircle in Flags) then begin
|
||||||
|
if not (unfImplementation in Flags) then begin
|
||||||
|
Result:=0; // normal used unit
|
||||||
|
end else begin
|
||||||
|
Result:=1; // unit used in implementation section
|
||||||
|
end;
|
||||||
|
end else begin
|
||||||
|
if not (unfForbiddenCircle in Flags) then begin
|
||||||
|
Result:=2; // allowed unit circle
|
||||||
|
end else begin
|
||||||
|
Result:=3; // forbidden unit circle
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
initialization
|
||||||
|
{$I unitdependencies.lrs}
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -1264,14 +1264,14 @@ function TTreeNode.DisplayStateIconLeft: integer;
|
|||||||
begin
|
begin
|
||||||
Result:=DisplayIconLeft;
|
Result:=DisplayIconLeft;
|
||||||
if (TreeView<>nil) and (TreeView.Images<>nil) then
|
if (TreeView<>nil) and (TreeView.Images<>nil) then
|
||||||
inc(Result,TreeView.Images.Width);
|
inc(Result,TreeView.Images.Width+2);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TTreeNode.DisplayTextLeft: integer;
|
function TTreeNode.DisplayTextLeft: integer;
|
||||||
begin
|
begin
|
||||||
Result:=DisplayStateIconLeft;
|
Result:=DisplayStateIconLeft;
|
||||||
if (TreeView<>nil) and (TreeView.StateImages<>nil) then
|
if (TreeView<>nil) and (TreeView.StateImages<>nil) then
|
||||||
inc(Result,TreeView.StateImages.Width);
|
inc(Result,TreeView.StateImages.Width+2);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TTreeNode.DisplayTextRight: integer;
|
function TTreeNode.DisplayTextRight: integer;
|
||||||
@ -4000,14 +4000,14 @@ begin
|
|||||||
else
|
else
|
||||||
ImgIndex:=Node.SelectedIndex;
|
ImgIndex:=Node.SelectedIndex;
|
||||||
if (ImgIndex>=0) and (ImgIndex<Images.Count) then
|
if (ImgIndex>=0) and (ImgIndex<Images.Count) then
|
||||||
Images.Draw(Canvas,x,NodeRect.Top,ImgIndex,true);
|
Images.Draw(Canvas,x+1,NodeRect.Top,ImgIndex,true);
|
||||||
inc(x,Images.Width);
|
inc(x,Images.Width+2);
|
||||||
end;
|
end;
|
||||||
// draw state icon
|
// draw state icon
|
||||||
if (StateImages<>nil) and PaintImages then begin
|
if (StateImages<>nil) and PaintImages then begin
|
||||||
if (Node.StateIndex>=0) and (Node.StateIndex<StateImages.Count) then
|
if (Node.StateIndex>=0) and (Node.StateIndex<StateImages.Count) then
|
||||||
StateImages.Draw(Canvas,x,NodeRect.Top,Node.StateIndex,true);
|
StateImages.Draw(Canvas,x+1,NodeRect.Top,Node.StateIndex,true);
|
||||||
inc(x,StateImages.Width);
|
inc(x,StateImages.Width+2);
|
||||||
end;
|
end;
|
||||||
// draw text
|
// draw text
|
||||||
if NodeSelected and (FSelectedColor<>clNone) then begin
|
if NodeSelected and (FSelectedColor<>clNone) then begin
|
||||||
@ -4269,6 +4269,8 @@ begin
|
|||||||
Images.RegisterChanges(FImageChangeLink);
|
Images.RegisterChanges(FImageChangeLink);
|
||||||
Images.FreeNotification(Self);
|
Images.FreeNotification(Self);
|
||||||
//SetImageList(Images.Handle, TVSIL_NORMAL)
|
//SetImageList(Images.Handle, TVSIL_NORMAL)
|
||||||
|
if DefaultItemHeight<Images.Height+2 then
|
||||||
|
DefaultItemHeight:=Images.Height+2;
|
||||||
end;
|
end;
|
||||||
//else SetImageList(0, TVSIL_NORMAL);
|
//else SetImageList(0, TVSIL_NORMAL);
|
||||||
Invalidate;
|
Invalidate;
|
||||||
@ -4284,6 +4286,8 @@ begin
|
|||||||
StateImages.RegisterChanges(FStateChangeLink);
|
StateImages.RegisterChanges(FStateChangeLink);
|
||||||
StateImages.FreeNotification(Self);
|
StateImages.FreeNotification(Self);
|
||||||
//SetImageList(StateImages.Handle, TVSIL_STATE)
|
//SetImageList(StateImages.Handle, TVSIL_STATE)
|
||||||
|
if DefaultItemHeight<StateImages.Height+2 then
|
||||||
|
DefaultItemHeight:=StateImages.Height+2;
|
||||||
end;
|
end;
|
||||||
//else SetImageList(0, TVSIL_STATE);
|
//else SetImageList(0, TVSIL_STATE);
|
||||||
Invalidate;
|
Invalidate;
|
||||||
|
Loading…
Reference in New Issue
Block a user