IDE: Improve the List and Inheritance tabs of ComponentList. Issue #27539, patch from Balazs Szekely.

git-svn-id: trunk@47995 -
This commit is contained in:
juha 2015-02-25 21:14:40 +00:00
parent e9dc6f1eff
commit 3555efa582
2 changed files with 111 additions and 107 deletions

View File

@ -1,7 +1,7 @@
object ComponentListForm: TComponentListForm
Left = 667
Left = 560
Height = 467
Top = 292
Top = 216
Width = 300
Caption = 'Components'
ClientHeight = 467
@ -50,41 +50,46 @@ object ComponentListForm: TComponentListForm
Top = 2
Width = 292
Align = alClient
DefaultItemHeight = 18
DefaultItemHeight = 26
Images = imListPalette
Indent = 25
ReadOnly = True
RowSelect = True
ShowButtons = False
ShowLines = False
ShowRoot = False
TabOrder = 0
OnClick = ComponentsClick
OnCustomDrawItem = TreeCustomDrawItem
OnDblClick = ComponentsDblClick
OnKeyPress = TreeKeyPress
Options = [tvoAutoItemHeight, tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips, tvoThemedDraw]
Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRowSelect, tvoToolTips]
end
end
end
object TabSheetPaletteTree: TTabSheet
Caption = 'Palette'
ClientHeight = 374
ClientWidth = 292
ClientHeight = 375
ClientWidth = 296
object pnPaletteTree: TPanel
Left = 0
Height = 374
Height = 375
Top = 0
Width = 292
Width = 296
Align = alClient
BevelOuter = bvNone
BorderWidth = 5
ClientHeight = 374
ClientWidth = 292
ClientHeight = 375
ClientWidth = 296
TabOrder = 0
object PalletteTree: TTreeView
Left = 5
Height = 364
Height = 365
Top = 5
Width = 282
Width = 286
Align = alClient
DefaultItemHeight = 27
Images = imPalette
PopupMenu = pmPalette
DefaultItemHeight = 26
Images = imListPalette
PopupMenu = pmCollapseExpand
ReadOnly = True
RightClickSelect = True
RowSelect = True
@ -99,32 +104,37 @@ object ComponentListForm: TComponentListForm
end
object TabSheetInheritance: TTabSheet
Caption = 'Inheritance'
ClientHeight = 374
ClientWidth = 292
ClientHeight = 375
ClientWidth = 296
object Panel6: TPanel
Left = 0
Height = 374
Height = 375
Top = 0
Width = 292
Width = 296
Align = alClient
BevelOuter = bvNone
BorderWidth = 5
ClientHeight = 374
ClientWidth = 292
ClientHeight = 375
ClientWidth = 296
TabOrder = 0
object InheritanceTree: TTreeView
Left = 5
Height = 364
Height = 365
Top = 5
Width = 282
Width = 286
Align = alClient
DefaultItemHeight = 26
Images = imListPalette
Indent = 20
PopupMenu = pmCollapseExpand
ReadOnly = True
RightClickSelect = True
RowSelect = True
TabOrder = 0
OnClick = ComponentsClick
OnCustomDrawItem = TreeCustomDrawItem
OnDblClick = ComponentsDblClick
OnKeyPress = TreeKeyPress
Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips, tvoNoDoubleClickExpand, tvoThemedDraw]
Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRightClickSelect, tvoRowSelect, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips]
end
end
end
@ -189,15 +199,16 @@ object ComponentListForm: TComponentListForm
ShowButtons = [pbOK]
ShowBevel = False
end
object imPalette: TImageList
Height = 25
Width = 25
left = 84
top = 124
object imListPalette: TImageList
Height = 24
Width = 24
left = 56
top = 112
end
object pmPalette: TPopupMenu
left = 148
top = 124
object pmCollapseExpand: TPopupMenu
OnPopup = pmCollapseExpandPopup
left = 160
top = 112
object miExpand: TMenuItem
Caption = 'Expand'
OnClick = miExpandClick
@ -218,4 +229,10 @@ object ComponentListForm: TComponentListForm
OnClick = miCollapseAllClick
end
end
object imInheritance: TImageList
Height = 24
Width = 24
left = 56
top = 168
end
end

View File

@ -33,20 +33,18 @@ interface
uses
Classes, SysUtils, LCLType, Forms, Controls, Graphics, StdCtrls, ExtCtrls,
ComCtrls, ButtonPanel, Menus, LazarusIDEStrConsts, ComponentReg,
PackageDefs, IDEImagesIntf, TreeFilterEdit, fgl;
ComCtrls, ButtonPanel, Menus, LazarusIDEStrConsts, ComponentReg, PackageDefs,
IDEImagesIntf, TreeFilterEdit, FormEditingIntf;
type
TRegisteredCompList = specialize TFPGList<TRegisteredComponent>;
{ TComponentListForm }
TComponentListForm = class(TForm)
imPalette: TImageList;
imListPalette: TImageList;
imInheritance: TImageList;
ListTree: TTreeView;
ButtonPanel: TButtonPanel;
MenuItem1: TMenuItem;
miCollapse: TMenuItem;
miCollapseAll: TMenuItem;
miExpand: TMenuItem;
@ -56,14 +54,14 @@ type
PageControl: TPageControl;
FilterPanel: TPanel;
PalletteTree: TTreeView;
InheritanceTree: TTreeView;
pnPaletteTree: TPanel;
Panel6: TPanel;
Panel7: TPanel;
pmPalette: TPopupMenu;
pmCollapseExpand: TPopupMenu;
TabSheetPaletteTree: TTabSheet;
TabSheetInheritance: TTabSheet;
TabSheetList: TTabSheet;
InheritanceTree: TTreeView;
TreeFilterEd: TTreeFilterEdit;
procedure FormActivate(Sender: TObject);
procedure FormShow(Sender: TObject);
@ -74,11 +72,8 @@ type
procedure OKButtonClick(Sender: TObject);
procedure ComponentsDblClick(Sender: TObject);
procedure ComponentsClick(Sender: TObject);
//procedure ComponentsListboxDrawItem(Control: TWinControl; Index: Integer;
// ARect: TRect; State: TOwnerDrawState);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure TreeCustomDrawItem(Sender: TCustomTreeView;
Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
procedure pmCollapseExpandPopup(Sender: TObject);
procedure TreeFilterEdAfterFilter(Sender: TObject);
procedure PageControlChange(Sender: TObject);
procedure TreeKeyPress(Sender: TObject; var Key: char);
@ -122,9 +117,14 @@ begin
TabSheetInheritance.Caption := lisCmpLstInheritance;
ButtonPanel.OKButton.Caption := lisUseAndClose;
ListTree.Images:=IDEImages.Images_24;
InheritanceTree.Images:=ListTree.Images;
PalletteTree.Images:= imPalette;
imListPalette.Width := ComponentPaletteImageWidth;
imListPalette.Height := ComponentPaletteImageHeight;
imInheritance.Width := ComponentPaletteImageWidth;
imInheritance.Height := ComponentPaletteImageHeight;
ListTree.Images := imListPalette;
PalletteTree.Images := imListPalette;
InheritanceTree.Images := imInheritance;
PrevPageIndex := -1;
PageControl.ActivePage := TabSheetList;
if Assigned(IDEComponentPalette) then
@ -222,6 +222,7 @@ var
Node: TTreeNode;
ClssName: string;
i, Ind: Integer;
CurIcon: TCustomBitmap;
begin
PalList := TStringList.Create;
try
@ -248,7 +249,17 @@ begin
if ClssName <> Comp.ComponentClass.ClassName then
Node := InheritanceTree.Items.AddChild(Node, ClssName)
else
begin
Node := InheritanceTree.Items.AddChildObject(Node, ClssName, Comp);
CurIcon := nil;
if (Comp is TPkgComponent) then
CurIcon := TPkgComponent(Comp).Icon;
if CurIcon <> nil then
begin
Node.ImageIndex := imInheritance.Add(CurIcon, nil);
Node.SelectedIndex := Node.ImageIndex;
end;
end;
FClassList.AddObject(ClssName, Node);
end;
end;
@ -264,7 +275,8 @@ var
Comps: TStringList;
Comp: TRegisteredComponent;
ParentNode: TTreeNode;
ANode: TTreeNode;
AListNode: TTreeNode;
APaletteNode: TTreeNode;
i, j: Integer;
CurIcon: TCustomBitmap;
begin
@ -281,6 +293,8 @@ begin
FClassList.Sorted := true;
FClassList.CaseSensitive := false;
FClassList.Duplicates := dupIgnore;
// ParentInheritence := InheritanceTree.Items.Add(nil, 'TComponent');
// FClassList.AddObject('TComponent', ParentInheritence);
// Iterate all pages
for i := 0 to IDEComponentPalette.Pages.Count-1 do
begin
@ -292,16 +306,18 @@ begin
for j := 0 to Comps.Count-1 do begin
Comp := Comps.Objects[j] as TRegisteredComponent;
// Flat list item
ListTree.Items.AddChildObject(Nil, Comps[j], Comp);
AListNode := ListTree.Items.AddChildObject(Nil, Comps[j], Comp);
// Palette layout item
ANode := PalletteTree.Items.AddChildObject(ParentNode, Comps[j], Comp);
APaletteNode := PalletteTree.Items.AddChildObject(ParentNode, Comps[j], Comp);
CurIcon := nil;
if (Comp is TPkgComponent) then
CurIcon := TPkgComponent(Comp).Icon;
if CurIcon <> nil then
begin
ANode.ImageIndex := imPalette.Add(CurIcon, nil);
ANode.SelectedIndex := ANode.ImageIndex;
AListNode.ImageIndex := imListPalette.Add(CurIcon, nil);
AListNode.SelectedIndex := AListNode.ImageIndex;
APaletteNode.ImageIndex := AListNode.ImageIndex;
APaletteNode.SelectedIndex := AListNode.ImageIndex;
end;
// Component inheritence item
DoComponentInheritence(Comp);
@ -320,53 +336,6 @@ begin
end;
end;
procedure TComponentListForm.TreeCustomDrawItem(Sender: TCustomTreeView;
Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
var
Comp: TRegisteredComponent;
ARect: TRect;
CurIcon: TCustomBitmap;
Indent, IconWidth, IconHeight, NodeTextHeight: Integer;
begin
DefaultDraw := False;
Indent := (Sender as TTreeView).Indent;
Comp := TRegisteredComponent(Node.Data);
with Sender.Canvas do
begin
if cdsSelected in State then
begin
Brush.Color := clHighlight; //Brush.Style := ...
Font.Color := clHighlightText;
end
else begin
Brush.Color := clDefault;
Font.Color := clDefault;
end;
ARect := Node.DisplayRect(False);
FillRect(ARect);
//Brush.Style := bsClear; //don't paint over the background bitmap.
ARect.Left := ARect.Left + (Node.Level * Indent);
// ARect.Left now points to the left of the image, or text if no image
CurIcon := nil;
if Comp is TPkgComponent then
CurIcon := TPkgComponent(Comp).Icon;
if CurIcon<>nil then
begin
IconWidth := CurIcon.Width;
IconHeight := CurIcon.Height;
ARect.Left := ARect.Left + Indent;
//ARect.Left is now the leftmost portion of the image.
Draw(ARect.Left+(25-IconWidth) div 2,
ARect.Top+(ARect.Bottom-ARect.Top-IconHeight) div 2, CurIcon);
ARect.Left := ARect.Left + IconWidth + 2;
end;
NodeTextHeight := TextHeight(Node.Text);
Inc(ARect.Top, (ARect.Bottom - ARect.Top - NodeTextHeight) div 2);
//Now we are finally in a position to draw the text.
TextOut(ARect.Left, ARect.Top, Node.Text);
end;
end;
procedure TComponentListForm.TreeFilterEdAfterFilter(Sender: TObject);
begin
UpdateButtonState;
@ -455,37 +424,55 @@ end;
procedure TComponentListForm.miCollapseAllClick(Sender: TObject);
begin
PalletteTree.FullCollapse;
TreeFilterEd.FilteredTreeview.FullCollapse;
end;
procedure TComponentListForm.miCollapseClick(Sender: TObject);
var
Node: TTreeNode;
begin
Node := PalletteTree.Selected;
Node := TreeFilterEd.FilteredTreeview.Selected;
if Node = nil then
Exit;
if Node.Level > 0 then
if (Node.Level > 0) and (Node.HasChildren = False) then
Node := Node.Parent;
Node.Collapse(True);
end;
procedure TComponentListForm.miExpandAllClick(Sender: TObject);
begin
PalletteTree.FullExpand;
TreeFilterEd.FilteredTreeview.FullExpand;
end;
procedure TComponentListForm.miExpandClick(Sender: TObject);
var
Node: TTreeNode;
begin
Node := PalletteTree.Selected;
Node := TreeFilterEd.FilteredTreeview.Selected;
if Node = nil then
Exit;
if Node.Level > 0 then
if (Node.Level > 0) and (Node.HasChildren = False) then
Node := Node.Parent;
Node.Expand(True);
end;
procedure TComponentListForm.pmCollapseExpandPopup(Sender: TObject);
var
Node: TTreeNode;
begin
Node := TreeFilterEd.FilteredTreeview.Selected;
if Node = nil then
begin
miExpand.Enabled := False;
miCollapse.Enabled := False;
end
else
begin
miExpand.Enabled := (Node.HasChildren) and (not Node.Expanded);
miCollapse.Enabled := (Node.HasChildren) and (Node.Expanded);
end;
end;
end.