IDE: Update ComponentList after component visibility in Palette changed. Issue #23541.

This commit is contained in:
Juha 2021-11-24 03:31:08 +02:00
parent 163a3a2018
commit cbc97e5a03
3 changed files with 69 additions and 47 deletions

View File

@ -190,9 +190,10 @@ type
{ TBaseComponentPalette }
TComponentPaletteHandlerType = (
cphtUpdateVisible, // Visibility of component palette icons is recomputed
cphtVoteVisibility, // Visibility of component palette icons is recomputed
cphtComponentAdded, // Typically selection is changed after component was added.
cphtSelectionChanged
cphtSelectionChanged,
cphtUpdated
);
TComponentSelectionMode = (
@ -281,14 +282,17 @@ type
procedure DoAfterComponentAdded(ALookupRoot, AComponent: TComponent;
ARegisteredComponent: TRegisteredComponent); virtual;
procedure DoAfterSelectionChanged;
procedure DoAfterUpdate;
procedure RemoveAllHandlersOfObject(AnObject: TObject);
procedure AddHandlerUpdateVisible(const OnUpdateCompVisibleEvent: TUpdateCompVisibleEvent;
AsLast: boolean = false);
procedure RemoveHandlerUpdateVisible(OnUpdateCompVisibleEvent: TUpdateCompVisibleEvent);
procedure AddHandlerVoteVisibility(const OnUpdateCompVisibleEvent: TUpdateCompVisibleEvent;
AsLast: boolean = false);
procedure RemoveHandlerVoteVisibility(OnUpdateCompVisibleEvent: TUpdateCompVisibleEvent);
procedure AddHandlerComponentAdded(OnComponentAddedEvent: TComponentAddedEvent);
procedure RemoveHandlerComponentAdded(OnComponentAddedEvent: TComponentAddedEvent);
procedure AddHandlerSelectionChanged(OnSelectionChangedEvent: TPaletteHandlerEvent);
procedure RemoveHandlerSelectionChanged(OnSelectionChangedEvent: TPaletteHandlerEvent);
procedure AddHandlerUpdated(OnUpdateEvent: TPaletteHandlerEvent);
procedure RemoveHandlerUpdated(OnUpdateEvent: TPaletteHandlerEvent);
public
property Pages: TBaseComponentPageList read fPages;
property Comps: TRegisteredCompList read fComps;
@ -1173,6 +1177,7 @@ procedure TBaseComponentPalette.Update(ForceUpdateAll: Boolean);
begin
fUserOrder.SortPagesAndCompsUserOrder;
CreatePagesFromUserOrder;
DoAfterUpdate;
end;
procedure TBaseComponentPalette.IterateRegisteredClasses(Proc: TGetComponentClassEvent);
@ -1198,9 +1203,9 @@ begin
Vote:=1;
if HideControls and AComponent.ComponentClass.InheritsFrom(TControl) then
Dec(Vote);
i:=FHandlers[cphtUpdateVisible].Count;
while FHandlers[cphtUpdateVisible].NextDownIndex(i) do
TUpdateCompVisibleEvent(FHandlers[cphtUpdateVisible][i])(AComponent,Vote);
i:=FHandlers[cphtVoteVisibility].Count;
while FHandlers[cphtVoteVisibility].NextDownIndex(i) do
TUpdateCompVisibleEvent(FHandlers[cphtVoteVisibility][i])(AComponent,Vote);
Result:=Vote>0;
AComponent.Visible:=Result;
end;
@ -1224,6 +1229,15 @@ begin
TPaletteHandlerEvent(FHandlers[cphtSelectionChanged][i])();
end;
procedure TBaseComponentPalette.DoAfterUpdate;
var
i: Integer;
begin
i:=FHandlers[cphtUpdated].Count;
while FHandlers[cphtUpdated].NextDownIndex(i) do
TPaletteHandlerEvent(FHandlers[cphtUpdated][i])();
end;
procedure TBaseComponentPalette.RemoveAllHandlersOfObject(AnObject: TObject);
var
HandlerType: TComponentPaletteHandlerType;
@ -1235,16 +1249,16 @@ end;
// Add / Remove handlers
// UpdateVisible
procedure TBaseComponentPalette.AddHandlerUpdateVisible(
procedure TBaseComponentPalette.AddHandlerVoteVisibility(
const OnUpdateCompVisibleEvent: TUpdateCompVisibleEvent; AsLast: boolean);
begin
AddHandler(cphtUpdateVisible,TMethod(OnUpdateCompVisibleEvent),AsLast);
AddHandler(cphtVoteVisibility,TMethod(OnUpdateCompVisibleEvent),AsLast);
end;
procedure TBaseComponentPalette.RemoveHandlerUpdateVisible(
procedure TBaseComponentPalette.RemoveHandlerVoteVisibility(
OnUpdateCompVisibleEvent: TUpdateCompVisibleEvent);
begin
RemoveHandler(cphtUpdateVisible,TMethod(OnUpdateCompVisibleEvent));
RemoveHandler(cphtVoteVisibility,TMethod(OnUpdateCompVisibleEvent));
end;
// ComponentAdded
@ -1273,5 +1287,17 @@ begin
RemoveHandler(cphtSelectionChanged,TMethod(OnSelectionChangedEvent));
end;
procedure TBaseComponentPalette.AddHandlerUpdated(
OnUpdateEvent: TPaletteHandlerEvent);
begin
AddHandler(cphtUpdated,TMethod(OnUpdateEvent));
end;
procedure TBaseComponentPalette.RemoveHandlerUpdated(
OnUpdateEvent: TPaletteHandlerEvent);
begin
RemoveHandler(cphtUpdated,TMethod(OnUpdateEvent));
end;
end.

View File

@ -7,11 +7,10 @@ object ComponentListForm: TComponentListForm
ClientHeight = 467
ClientWidth = 300
KeyPreview = True
OnActivate = FormActivate
OnClose = FormClose
OnKeyDown = FormKeyDown
OnShow = FormShow
LCLVersion = '1.9.0.0'
LCLVersion = '2.3.0.0'
object PageControl: TPageControl
Left = 0
Height = 397

View File

@ -74,7 +74,6 @@ type
TreeFilterEd: TTreeFilterEdit;
SelectionToolButton: TSpeedButton;
procedure chbKeepOpenChange(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ListTreeSelectionChanged(Sender: TObject);
procedure miCollapseAllClick(Sender: TObject);
@ -102,9 +101,9 @@ type
FAddCompNewLeft, FAddCompNewTop: Integer;
FAddCompNewParent: TComponent;
procedure ClearSelection;
procedure SelectionWasChanged;
procedure ComponentWasAdded({%H-}ALookupRoot, {%H-}AComponent: TComponent;
{%H-}ARegisteredComponent: TRegisteredComponent);
procedure SelectionWasChanged;
procedure DoComponentInheritence(Comp: TRegisteredComponent);
procedure UpdateComponents;
procedure UpdateButtonState;
@ -158,14 +157,26 @@ begin
begin
UpdateComponents;
TreeFilterEd.InvalidateFilter;
IDEComponentPalette.AddHandlerSelectionChanged(@SelectionWasChanged);
IDEComponentPalette.AddHandlerComponentAdded(@ComponentWasAdded);
IDEComponentPalette.AddHandlerSelectionChanged(@SelectionWasChanged);
IDEComponentPalette.AddHandlerUpdated(@UpdateComponents);
end;
chbKeepOpen.Checked := EnvironmentOptions.ComponentListKeepOpen;
PageControl.PageIndex := EnvironmentOptions.ComponentListPageIndex;
PageControlChange(Nil);
end;
destructor TComponentListForm.Destroy;
begin
if Assigned(IDEComponentPalette) then begin
IDEComponentPalette.RemoveHandlerUpdated(@UpdateComponents);
IDEComponentPalette.RemoveHandlerSelectionChanged(@SelectionWasChanged);
IDEComponentPalette.RemoveHandlerComponentAdded(@ComponentWasAdded);
end;
ComponentListForm := nil;
inherited Destroy;
end;
procedure TComponentListForm.AddSelectedComponent;
var
AComponent: TRegisteredComponent;
@ -214,14 +225,6 @@ begin
EnvironmentOptions.ComponentListKeepOpen := chbKeepOpen.Checked;
end;
destructor TComponentListForm.Destroy;
begin
if Assigned(IDEComponentPalette) then
IDEComponentPalette.RemoveHandlerComponentAdded(@ComponentWasAdded);
ComponentListForm := nil;
inherited Destroy;
end;
procedure TComponentListForm.FormShow(Sender: TObject);
begin
//DebugLn(['*** TComponentListForm.FormShow, Parent=', Parent, ', Parent.Parent=', ParentParent]);
@ -238,12 +241,6 @@ begin
PageControl.AnchorSideBottom.Side := asrBottom;
end;
procedure TComponentListForm.FormActivate(Sender: TObject);
begin
if Assigned(IDEComponentPalette) and (IDEComponentPalette.ChangeStamp<>PrevChangeStamp) then
UpdateComponents;
end;
procedure TComponentListForm.ClearSelection;
begin
ListTree.Selected := Nil;
@ -265,22 +262,6 @@ begin
aTree.Selected.MakeVisible;
end;
procedure TComponentListForm.SelectionWasChanged;
begin
SelectionToolButton.Down := (IDEComponentPalette.Selected = nil);
// ToDo: Select the component in active treeview.
if FIgnoreSelection then
Exit;
if ListTree.IsVisible then
SelectTreeComp(ListTree)
else if PalletteTree.IsVisible then
SelectTreeComp(PalletteTree)
else if InheritanceTree.IsVisible then
SelectTreeComp(InheritanceTree)
end;
function GetSelectedTreeComp(aTree: TTreeView): TRegisteredComponent;
begin
if Assigned(aTree.Selected) then
@ -312,6 +293,20 @@ begin
UpdateButtonState;
end;
procedure TComponentListForm.SelectionWasChanged;
begin
SelectionToolButton.Down := (IDEComponentPalette.Selected = nil);
// ToDo: Select the component in active treeview.
if FIgnoreSelection then
Exit;
if ListTree.IsVisible then
SelectTreeComp(ListTree)
else if PalletteTree.IsVisible then
SelectTreeComp(PalletteTree)
else if InheritanceTree.IsVisible then
SelectTreeComp(InheritanceTree)
end;
procedure TComponentListForm.UpdateButtonState;
begin
OKButton.Enabled := Assigned(GetSelectedComponent);
@ -410,12 +405,14 @@ begin
for i := 0 to IDEComponentPalette.Pages.Count-1 do
begin
Pg := IDEComponentPalette.Pages[i];
if not Pg.Visible then Continue;
Comps := IDEComponentPalette.RefUserCompsForPage(Pg.PageName);
// Palette layout Page header
ParentNode := PalletteTree.Items.AddChild(nil, Pg.PageName);
// Iterate components of one page
for j := 0 to Comps.Count-1 do begin
Comp := Comps[j];
if not Comp.Visible then Continue;
// Flat list item
AListNode := ListTree.Items.AddChildObject(Nil, Comp.ComponentClass.ClassName, Comp);
// Palette layout item