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

View File

@ -33,20 +33,18 @@ interface
uses uses
Classes, SysUtils, LCLType, Forms, Controls, Graphics, StdCtrls, ExtCtrls, Classes, SysUtils, LCLType, Forms, Controls, Graphics, StdCtrls, ExtCtrls,
ComCtrls, ButtonPanel, Menus, LazarusIDEStrConsts, ComponentReg, ComCtrls, ButtonPanel, Menus, LazarusIDEStrConsts, ComponentReg, PackageDefs,
PackageDefs, IDEImagesIntf, TreeFilterEdit, fgl; IDEImagesIntf, TreeFilterEdit, FormEditingIntf;
type type
TRegisteredCompList = specialize TFPGList<TRegisteredComponent>;
{ TComponentListForm } { TComponentListForm }
TComponentListForm = class(TForm) TComponentListForm = class(TForm)
imPalette: TImageList; imListPalette: TImageList;
imInheritance: TImageList;
ListTree: TTreeView; ListTree: TTreeView;
ButtonPanel: TButtonPanel; ButtonPanel: TButtonPanel;
MenuItem1: TMenuItem;
miCollapse: TMenuItem; miCollapse: TMenuItem;
miCollapseAll: TMenuItem; miCollapseAll: TMenuItem;
miExpand: TMenuItem; miExpand: TMenuItem;
@ -56,14 +54,14 @@ type
PageControl: TPageControl; PageControl: TPageControl;
FilterPanel: TPanel; FilterPanel: TPanel;
PalletteTree: TTreeView; PalletteTree: TTreeView;
InheritanceTree: TTreeView;
pnPaletteTree: TPanel; pnPaletteTree: TPanel;
Panel6: TPanel; Panel6: TPanel;
Panel7: TPanel; Panel7: TPanel;
pmPalette: TPopupMenu; pmCollapseExpand: TPopupMenu;
TabSheetPaletteTree: TTabSheet; TabSheetPaletteTree: TTabSheet;
TabSheetInheritance: TTabSheet; TabSheetInheritance: TTabSheet;
TabSheetList: TTabSheet; TabSheetList: TTabSheet;
InheritanceTree: TTreeView;
TreeFilterEd: TTreeFilterEdit; TreeFilterEd: TTreeFilterEdit;
procedure FormActivate(Sender: TObject); procedure FormActivate(Sender: TObject);
procedure FormShow(Sender: TObject); procedure FormShow(Sender: TObject);
@ -74,11 +72,8 @@ type
procedure OKButtonClick(Sender: TObject); procedure OKButtonClick(Sender: TObject);
procedure ComponentsDblClick(Sender: TObject); procedure ComponentsDblClick(Sender: TObject);
procedure ComponentsClick(Sender: TObject); procedure ComponentsClick(Sender: TObject);
//procedure ComponentsListboxDrawItem(Control: TWinControl; Index: Integer;
// ARect: TRect; State: TOwnerDrawState);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure TreeCustomDrawItem(Sender: TCustomTreeView; procedure pmCollapseExpandPopup(Sender: TObject);
Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
procedure TreeFilterEdAfterFilter(Sender: TObject); procedure TreeFilterEdAfterFilter(Sender: TObject);
procedure PageControlChange(Sender: TObject); procedure PageControlChange(Sender: TObject);
procedure TreeKeyPress(Sender: TObject; var Key: char); procedure TreeKeyPress(Sender: TObject; var Key: char);
@ -122,9 +117,14 @@ begin
TabSheetInheritance.Caption := lisCmpLstInheritance; TabSheetInheritance.Caption := lisCmpLstInheritance;
ButtonPanel.OKButton.Caption := lisUseAndClose; ButtonPanel.OKButton.Caption := lisUseAndClose;
ListTree.Images:=IDEImages.Images_24; imListPalette.Width := ComponentPaletteImageWidth;
InheritanceTree.Images:=ListTree.Images; imListPalette.Height := ComponentPaletteImageHeight;
PalletteTree.Images:= imPalette; imInheritance.Width := ComponentPaletteImageWidth;
imInheritance.Height := ComponentPaletteImageHeight;
ListTree.Images := imListPalette;
PalletteTree.Images := imListPalette;
InheritanceTree.Images := imInheritance;
PrevPageIndex := -1; PrevPageIndex := -1;
PageControl.ActivePage := TabSheetList; PageControl.ActivePage := TabSheetList;
if Assigned(IDEComponentPalette) then if Assigned(IDEComponentPalette) then
@ -222,6 +222,7 @@ var
Node: TTreeNode; Node: TTreeNode;
ClssName: string; ClssName: string;
i, Ind: Integer; i, Ind: Integer;
CurIcon: TCustomBitmap;
begin begin
PalList := TStringList.Create; PalList := TStringList.Create;
try try
@ -248,7 +249,17 @@ begin
if ClssName <> Comp.ComponentClass.ClassName then if ClssName <> Comp.ComponentClass.ClassName then
Node := InheritanceTree.Items.AddChild(Node, ClssName) Node := InheritanceTree.Items.AddChild(Node, ClssName)
else else
begin
Node := InheritanceTree.Items.AddChildObject(Node, ClssName, Comp); 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); FClassList.AddObject(ClssName, Node);
end; end;
end; end;
@ -264,7 +275,8 @@ var
Comps: TStringList; Comps: TStringList;
Comp: TRegisteredComponent; Comp: TRegisteredComponent;
ParentNode: TTreeNode; ParentNode: TTreeNode;
ANode: TTreeNode; AListNode: TTreeNode;
APaletteNode: TTreeNode;
i, j: Integer; i, j: Integer;
CurIcon: TCustomBitmap; CurIcon: TCustomBitmap;
begin begin
@ -281,6 +293,8 @@ begin
FClassList.Sorted := true; FClassList.Sorted := true;
FClassList.CaseSensitive := false; FClassList.CaseSensitive := false;
FClassList.Duplicates := dupIgnore; FClassList.Duplicates := dupIgnore;
// ParentInheritence := InheritanceTree.Items.Add(nil, 'TComponent');
// FClassList.AddObject('TComponent', ParentInheritence);
// Iterate all pages // Iterate all pages
for i := 0 to IDEComponentPalette.Pages.Count-1 do for i := 0 to IDEComponentPalette.Pages.Count-1 do
begin begin
@ -292,16 +306,18 @@ begin
for j := 0 to Comps.Count-1 do begin for j := 0 to Comps.Count-1 do begin
Comp := Comps.Objects[j] as TRegisteredComponent; Comp := Comps.Objects[j] as TRegisteredComponent;
// Flat list item // Flat list item
ListTree.Items.AddChildObject(Nil, Comps[j], Comp); AListNode := ListTree.Items.AddChildObject(Nil, Comps[j], Comp);
// Palette layout item // Palette layout item
ANode := PalletteTree.Items.AddChildObject(ParentNode, Comps[j], Comp); APaletteNode := PalletteTree.Items.AddChildObject(ParentNode, Comps[j], Comp);
CurIcon := nil; CurIcon := nil;
if (Comp is TPkgComponent) then if (Comp is TPkgComponent) then
CurIcon := TPkgComponent(Comp).Icon; CurIcon := TPkgComponent(Comp).Icon;
if CurIcon <> nil then if CurIcon <> nil then
begin begin
ANode.ImageIndex := imPalette.Add(CurIcon, nil); AListNode.ImageIndex := imListPalette.Add(CurIcon, nil);
ANode.SelectedIndex := ANode.ImageIndex; AListNode.SelectedIndex := AListNode.ImageIndex;
APaletteNode.ImageIndex := AListNode.ImageIndex;
APaletteNode.SelectedIndex := AListNode.ImageIndex;
end; end;
// Component inheritence item // Component inheritence item
DoComponentInheritence(Comp); DoComponentInheritence(Comp);
@ -320,53 +336,6 @@ begin
end; end;
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); procedure TComponentListForm.TreeFilterEdAfterFilter(Sender: TObject);
begin begin
UpdateButtonState; UpdateButtonState;
@ -455,37 +424,55 @@ end;
procedure TComponentListForm.miCollapseAllClick(Sender: TObject); procedure TComponentListForm.miCollapseAllClick(Sender: TObject);
begin begin
PalletteTree.FullCollapse; TreeFilterEd.FilteredTreeview.FullCollapse;
end; end;
procedure TComponentListForm.miCollapseClick(Sender: TObject); procedure TComponentListForm.miCollapseClick(Sender: TObject);
var var
Node: TTreeNode; Node: TTreeNode;
begin begin
Node := PalletteTree.Selected; Node := TreeFilterEd.FilteredTreeview.Selected;
if Node = nil then if Node = nil then
Exit; Exit;
if Node.Level > 0 then if (Node.Level > 0) and (Node.HasChildren = False) then
Node := Node.Parent; Node := Node.Parent;
Node.Collapse(True); Node.Collapse(True);
end; end;
procedure TComponentListForm.miExpandAllClick(Sender: TObject); procedure TComponentListForm.miExpandAllClick(Sender: TObject);
begin begin
PalletteTree.FullExpand; TreeFilterEd.FilteredTreeview.FullExpand;
end; end;
procedure TComponentListForm.miExpandClick(Sender: TObject); procedure TComponentListForm.miExpandClick(Sender: TObject);
var var
Node: TTreeNode; Node: TTreeNode;
begin begin
Node := PalletteTree.Selected; Node := TreeFilterEd.FilteredTreeview.Selected;
if Node = nil then if Node = nil then
Exit; Exit;
if Node.Level > 0 then if (Node.Level > 0) and (Node.HasChildren = False) then
Node := Node.Parent; Node := Node.Parent;
Node.Expand(True); Node.Expand(True);
end; 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. end.