IDE: Workaround to refresh values of CollectionPropertyEditor when control of same class is selected. Issue #38910

git-svn-id: trunk@65134 -
This commit is contained in:
michl 2021-05-25 20:51:17 +00:00
parent 4b4a0c7d92
commit a2d9e364aa
2 changed files with 47 additions and 1 deletions

View File

@ -44,11 +44,13 @@ type
procedure FillCollectionListBox; procedure FillCollectionListBox;
procedure ClearSelectionInObjectInspector; procedure ClearSelectionInObjectInspector;
procedure SelectInObjectInspector(ForceUpdate: Boolean); procedure SelectInObjectInspector(ForceUpdate: Boolean);
procedure SelectionChanged(NewOwnerPersistent: TPersistent);
procedure Modified; procedure Modified;
protected protected
procedure UpdateCaption; procedure UpdateCaption;
procedure PersistentAdded({%H-}APersistent: TPersistent; {%H-}Select: boolean); procedure PersistentAdded({%H-}APersistent: TPersistent; {%H-}Select: boolean);
procedure ComponentRenamed(AComponent: TComponent); procedure ComponentRenamed(AComponent: TComponent);
procedure GlobalSetSelection(const ASelection: TPersistentSelectionList);
procedure PersistentDeleting(APersistent: TPersistent); procedure PersistentDeleting(APersistent: TPersistent);
procedure RefreshPropertyValues; procedure RefreshPropertyValues;
public public
@ -66,7 +68,7 @@ implementation
{$R *.lfm} {$R *.lfm}
uses uses
PropEdits; PropEdits, FormEditingIntf, ObjectInspector;
type type
TPersistentAccess = class(TPersistent) TPersistentAccess = class(TPersistent)
@ -253,6 +255,18 @@ begin
UpdateCaption; UpdateCaption;
end; end;
procedure TCollectionPropertyEditorForm.GlobalSetSelection(const ASelection: TPersistentSelectionList);
begin
// When a control of the same class is changed in OI or Designer, the properties
// of the current control has to be shown. See issue #38910
if not Visible then Exit;
if not Assigned(ASelection) then Exit;
if ASelection.Count = 0 then Exit;
if ASelection[0] = OwnerPersistent then Exit;
if ASelection[0].ClassType <> OwnerPersistent.ClassType then Exit;
SelectionChanged(ASelection[0]);
end;
procedure TCollectionPropertyEditorForm.PersistentDeleting(APersistent: TPersistent); procedure TCollectionPropertyEditorForm.PersistentDeleting(APersistent: TPersistent);
begin begin
// For some reason this is called only when the whole collection is deleted, // For some reason this is called only when the whole collection is deleted,
@ -345,6 +359,22 @@ begin
end; end;
end; end;
procedure TCollectionPropertyEditorForm.SelectionChanged(NewOwnerPersistent: TPersistent);
var
AGrid: TOICustomPropertyGrid;
AEditor: TPropertyEditor;
NewCollection: TCollection;
begin
// DebugLn('TCollectionPropertyEditorForm.SelectionChanged Old: ', DbgSName(OwnerPersistent), ' New: ', DbgSName(NewOwnerPersistent));
AGrid := FormEditingHook.GetCurrentObjectInspector.GridControl[oipgpProperties];
AEditor := AGrid.PropertyEditorByName(PropertyName);
if not Assigned(AEditor) then Exit;
NewCollection := TCollection(AEditor.GetObjectValue);
if NewCollection = nil then
raise Exception.Create('NewCollection=nil');
SetCollection(NewCollection, NewOwnerPersistent, PropertyName);
end;
procedure TCollectionPropertyEditorForm.SetCollection(NewCollection: TCollection; procedure TCollectionPropertyEditorForm.SetCollection(NewCollection: TCollection;
NewOwnerPersistent: TPersistent; const NewPropName: String); NewOwnerPersistent: TPersistent; const NewPropName: String);
begin begin
@ -365,6 +395,7 @@ begin
GlobalDesignHook.AddHandlerComponentRenamed(@ComponentRenamed); GlobalDesignHook.AddHandlerComponentRenamed(@ComponentRenamed);
GlobalDesignHook.AddHandlerPersistentDeleting(@PersistentDeleting); GlobalDesignHook.AddHandlerPersistentDeleting(@PersistentDeleting);
GlobalDesignHook.AddHandlerRefreshPropertyValues(@RefreshPropertyValues); GlobalDesignHook.AddHandlerRefreshPropertyValues(@RefreshPropertyValues);
GlobalDesignHook.AddHandlerSetSelection(@GlobalSetSelection);
end; end;
end; end;

View File

@ -470,6 +470,7 @@ type
function MouseToIndex(y: integer; MustExist: boolean): integer; function MouseToIndex(y: integer; MustExist: boolean): integer;
function PropertyPath(Index: integer):string; function PropertyPath(Index: integer):string;
function PropertyPath(Row: TOIPropertyGridRow):string; function PropertyPath(Row: TOIPropertyGridRow):string;
function PropertyEditorByName(const PropName: string): TPropertyEditor;
function TopMax: integer; function TopMax: integer;
procedure BuildPropertyList(OnlyIfNeeded: Boolean = False; FocusEditor: Boolean = True); procedure BuildPropertyList(OnlyIfNeeded: Boolean = False; FocusEditor: Boolean = True);
procedure Clear; procedure Clear;
@ -1436,6 +1437,20 @@ begin
end; end;
end; end;
function TOICustomPropertyGrid.PropertyEditorByName(const PropName: string): TPropertyEditor;
var
AOIPropertyGridRow: TOIPropertyGridRow;
i: Integer;
begin
Result := nil;
for i := 0 to FRows.Count - 1 do
begin
AOIPropertyGridRow := TOIPropertyGridRow(FRows[i]);
if Assigned(AOIPropertyGridRow.Editor) and (AOIPropertyGridRow.Editor.GetName = PropName) then
Exit(AOIPropertyGridRow.Editor);
end;
end;
function TOICustomPropertyGrid.RealDefaultItemHeight: integer; function TOICustomPropertyGrid.RealDefaultItemHeight: integer;
begin begin
Result := FDefaultItemHeight; Result := FDefaultItemHeight;