mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-16 07:40:33 +01:00
IDEIntf: collection form delete: notify, component tree: delete node on deleting event
This commit is contained in:
parent
8422fcbcb5
commit
d0c5c1575e
@ -13,8 +13,8 @@ uses
|
||||
// IdeIntf
|
||||
ObjInspStrConsts, PropEditUtils, IDEImagesIntf, IDEWindowIntf;
|
||||
|
||||
|
||||
type
|
||||
|
||||
{ TCollectionPropertyEditorForm }
|
||||
|
||||
TCollectionPropertyEditorForm = class(TForm)
|
||||
@ -128,6 +128,7 @@ procedure TCollectionPropertyEditorForm.actDelExecute(Sender: TObject);
|
||||
var
|
||||
I : Integer;
|
||||
NewItemIndex: Integer;
|
||||
Item: TCollectionItem;
|
||||
begin
|
||||
if Collection = nil then Exit;
|
||||
|
||||
@ -159,7 +160,11 @@ begin
|
||||
// unselect all items in OI (collections can act strange on delete)
|
||||
ClearSelectionInObjectInspector;
|
||||
// now delete
|
||||
Collection.Items[I].Free;
|
||||
Item:=Collection.Items[I];
|
||||
GlobalDesignHook.PersistentDeleting(Item);
|
||||
Item.Free;
|
||||
GlobalDesignHook.PersistentDeleted(Item);
|
||||
Item:=nil;
|
||||
// update listbox after whatever happened
|
||||
FillCollectionListBox;
|
||||
// set NewItemIndex
|
||||
|
||||
@ -46,6 +46,7 @@ type
|
||||
TComponentTreeView = class(TCustomTreeView)
|
||||
private
|
||||
FComponentList: TBackupComponentList;
|
||||
FIdleConnected: boolean;
|
||||
FOnParentAcceptsChild: TCTVParentAcceptsChildEvent;
|
||||
FOnSetParent: TCTVSetParentEvent;
|
||||
FPropertyEditorHook: TPropertyEditorHook;
|
||||
@ -68,7 +69,11 @@ type
|
||||
function IterateTree(ANode: TTreeNode; APers: TPersistent): TTreeNode;
|
||||
procedure NodeCollapsed(Sender: TObject; Node: TTreeNode);
|
||||
procedure NodeExpanded(Sender: TObject; Node: TTreeNode);
|
||||
procedure OnIdle(Sender: TObject; var Done: Boolean);
|
||||
procedure OnPersistentDeleted(APersistent: TPersistent);
|
||||
procedure OnPersistentDeleting(APersistent: TPersistent);
|
||||
procedure RestoreExpand(ANode: TTreeNode);
|
||||
procedure SetIdleConnected(const AValue: boolean);
|
||||
procedure SetPropertyEditorHook(AValue: TPropertyEditorHook);
|
||||
procedure SetSelection(NewSelection: TPersistentSelectionList);
|
||||
procedure UpdateCompNode(ANode: TTreeNode);
|
||||
@ -85,6 +90,7 @@ type
|
||||
out AnInsertMarkNode: TTreeNode;
|
||||
out AnInsertMarkType: TTreeViewInsertMarkType);
|
||||
procedure DoModified;
|
||||
property IdleBuildNodes: boolean read FIdleConnected write SetIdleConnected;
|
||||
public
|
||||
constructor Create(TheOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
@ -644,7 +650,18 @@ end;
|
||||
procedure TComponentTreeView.SetPropertyEditorHook(AValue: TPropertyEditorHook);
|
||||
begin
|
||||
if FPropertyEditorHook=AValue then exit;
|
||||
if FPropertyEditorHook<>nil then
|
||||
begin
|
||||
FPropertyEditorHook.RemoveHandlerPersistentDeleting(@OnPersistentDeleting);
|
||||
FPropertyEditorHook.RemoveHandlerPersistentDeleted(@OnPersistentDeleted);
|
||||
end;
|
||||
|
||||
FPropertyEditorHook:=AValue;
|
||||
if FPropertyEditorHook<>nil then
|
||||
begin
|
||||
FPropertyEditorHook.AddHandlerPersistentDeleting(@OnPersistentDeleting);
|
||||
FPropertyEditorHook.AddHandlerPersistentDeleted(@OnPersistentDeleted);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TComponentTreeView.GetSelection: TPersistentSelectionList;
|
||||
@ -674,6 +691,7 @@ destructor TComponentTreeView.Destroy;
|
||||
var
|
||||
Enumer: TPointerToPointerEnumerator;
|
||||
begin
|
||||
IdleBuildNodes:=false;
|
||||
Enumer := FRoot2CollapasedMap.GetEnumerator;
|
||||
while Enumer.MoveNext do
|
||||
FreeAndNil(TObject(Enumer.Current^.Value)); // Free the CollapsedComp TAVLTrees.
|
||||
@ -696,6 +714,28 @@ begin
|
||||
DebugLn(['TComponentTreeView.NodeExpanded: Removing node ', TPersistent(Node.Data), ' failed.']);
|
||||
end;
|
||||
|
||||
procedure TComponentTreeView.OnIdle(Sender: TObject; var Done: Boolean);
|
||||
begin
|
||||
BuildComponentNodes(true);
|
||||
end;
|
||||
|
||||
procedure TComponentTreeView.OnPersistentDeleted(APersistent: TPersistent);
|
||||
begin
|
||||
OnPersistentDeleting(APersistent);
|
||||
end;
|
||||
|
||||
procedure TComponentTreeView.OnPersistentDeleting(APersistent: TPersistent);
|
||||
var
|
||||
Node: TTreeNode;
|
||||
begin
|
||||
Node:=IterateTree(Items.GetFirstNode,APersistent);
|
||||
if Node=nil then exit;
|
||||
BeginUpdate;
|
||||
Node.Free;
|
||||
IdleBuildNodes:=true;
|
||||
EndUpdate;
|
||||
end;
|
||||
|
||||
function TComponentTreeView.AddOrGetPersNode(AParentNode: TTreeNode;
|
||||
APers: TPersistent; ACapt: String): TTreeNode;
|
||||
var
|
||||
@ -753,6 +793,7 @@ var
|
||||
RootObject: TPersistent;
|
||||
RootNode: TTreeNode;
|
||||
begin
|
||||
IdleBuildNodes:=false;
|
||||
OnCollapsed:=nil; // Don't handle these events while the tree builds.
|
||||
OnExpanded:=nil;
|
||||
BeginUpdate;
|
||||
@ -797,6 +838,16 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TComponentTreeView.SetIdleConnected(const AValue: boolean);
|
||||
begin
|
||||
if FIdleConnected=AValue then Exit;
|
||||
if FIdleConnected then
|
||||
Application.RemoveOnIdleHandler(@OnIdle);
|
||||
FIdleConnected:=AValue;
|
||||
if FIdleConnected then
|
||||
Application.AddOnIdleHandler(@OnIdle);
|
||||
end;
|
||||
|
||||
procedure TComponentTreeView.ChangeNode(ANode: TTreeNode);
|
||||
// Change ZOrder of the given node or delete it.
|
||||
var
|
||||
@ -831,6 +882,7 @@ function TComponentTreeView.IterateTree(ANode: TTreeNode; APers: TPersistent): T
|
||||
// Returns the node that was changed.
|
||||
begin
|
||||
Result := Nil;
|
||||
if ANode=nil then exit;
|
||||
if TObject(ANode.Data)=APers then
|
||||
begin
|
||||
ChangeNode(ANode);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user