mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-23 01:19:37 +02:00
Merge branch 'Designer/Editors/Collection/Hooks' into 'main'
IdeIntf: Notify on addition/removal of items in the Collection property editor. Issue #41586 See merge request freepascal.org/lazarus/lazarus!461
This commit is contained in:
commit
62f4d6f436
@ -111,11 +111,13 @@ begin
|
||||
end;
|
||||
|
||||
procedure TCollectionPropertyEditorForm.actAddExecute(Sender: TObject);
|
||||
var
|
||||
lItem: TCollectionItem;
|
||||
begin
|
||||
if Collection = nil then Exit;
|
||||
Collection.Add;
|
||||
|
||||
FillCollectionListBox;
|
||||
lItem := Collection.Add;
|
||||
// notify about addition (this also call its own handler)
|
||||
GlobalDesignHook.PersistentAdded(lItem, true);
|
||||
if CollectionListBox.Items.Count > 0 then
|
||||
CollectionListBox.ItemIndex := CollectionListBox.Items.Count - 1;
|
||||
SelectInObjectInspector(True);
|
||||
@ -128,6 +130,7 @@ procedure TCollectionPropertyEditorForm.actDelExecute(Sender: TObject);
|
||||
var
|
||||
I : Integer;
|
||||
NewItemIndex: Integer;
|
||||
lItem: TCollectionItem;
|
||||
begin
|
||||
if Collection = nil then Exit;
|
||||
|
||||
@ -158,10 +161,9 @@ begin
|
||||
//debugln('TCollectionPropertyEditorForm.DeleteClick A NewItemIndex=',dbgs(NewItemIndex),' ItemIndex=',dbgs(CollectionListBox.ItemIndex),' CollectionListBox.Items.Count=',dbgs(CollectionListBox.Items.Count),' Collection.Count=',dbgs(Collection.Count));
|
||||
// unselect all items in OI (collections can act strange on delete)
|
||||
ClearSelectionInObjectInspector;
|
||||
// now delete
|
||||
Collection.Items[I].Free;
|
||||
// update listbox after whatever happened
|
||||
FillCollectionListBox;
|
||||
// now delete (this also call its own handler)
|
||||
lItem := Collection.Items[I];
|
||||
GlobalDesignHook.DeletePersistent(TPersistent(lItem));
|
||||
// set NewItemIndex
|
||||
if NewItemIndex < CollectionListBox.Items.Count then
|
||||
begin
|
||||
@ -264,14 +266,18 @@ end;
|
||||
|
||||
procedure TCollectionPropertyEditorForm.PersistentDeleting(APersistent: TPersistent);
|
||||
begin
|
||||
// For some reason this is called only when the whole collection is deleted,
|
||||
// for example when changing to another project. Thus clear the whole collection.
|
||||
DebugLn(['TCollectionPropertyEditorForm.PersistentDeleting: APersistent=', APersistent,
|
||||
', OwnerPersistent=', OwnerPersistent]);
|
||||
SetCollection(nil, nil, '');
|
||||
Hide;
|
||||
UpdateButtons;
|
||||
UpdateCaption;
|
||||
if APersistent = OwnerPersistent then
|
||||
begin
|
||||
SetCollection(nil, nil, '');
|
||||
end
|
||||
else if APersistent is TCollectionItem then
|
||||
begin
|
||||
if TCollectionItem(APersistent).Collection = Collection then
|
||||
begin
|
||||
TCollectionItem(APersistent).Collection := nil;
|
||||
FillCollectionListBox;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCollectionPropertyEditorForm.RefreshPropertyValues;
|
||||
|
Loading…
Reference in New Issue
Block a user