IDEIntf: Tweak Object Inspector such that TFlowPanelControl items cannot be added and deleted in an incorrect way (issue #34286).

git-svn-id: trunk@59133 -
This commit is contained in:
wp 2018-09-22 17:48:14 +00:00
parent 495496eec3
commit 94c1307bb0
4 changed files with 71 additions and 4 deletions

View File

@ -784,6 +784,7 @@ type
procedure SetShowRestricted(const AValue: Boolean);
procedure SetShowStatusBar(const AValue: Boolean);
protected
function CanDeleteSelection: Boolean;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyUp(var Key: Word; Shift: TShiftState); override;
procedure Resize; override;
@ -4949,11 +4950,28 @@ begin
end;
end;
function TObjectInspectorDlg.CanDeleteSelection: Boolean;
var
persistent: TPersistent;
intf: IObjInspInterface;
i: Integer;
begin
Result := true;
for i:=0 to ComponentTree.Selection.Count - 1 do begin
persistent := ComponentTree.Selection[i];
if persistent.GetInterface(GUID_ObjInspInterface, intf) and not intf.AllowDelete then
begin
Result := false;
exit;
end;
end;
end;
procedure TObjectInspectorDlg.ComponentTreeKeyDown(Sender: TObject;
var Key: Word; Shift: TShiftState);
begin
if (Shift = []) and (Key = VK_DELETE) and
(Selection.Count > 0) and
(Selection.Count > 0) and CanDeleteSelection and
(MessageDlg(oiscDelete, mtConfirmation,[mbYes, mbNo],0) = mrYes) then
begin
DeletePopupmenuItemClick(nil);
@ -5707,7 +5725,11 @@ var
procedure AddCollectionEditorMenuItems({%H-}ACollection: TCollection);
var
Item: TMenuItem;
intf: IObjInspInterface;
begin
if ACollection.GetInterface(GUID_ObjInspInterface, intf) and not intf.AllowAdd then
exit;
Item := NewItem(oisAddCollectionItem, 0, False, True,
@CollectionAddItem, 0, ComponentEditorMIPrefix+'0');
MainPopupMenu.Items.Insert(0, Item);

View File

@ -34,6 +34,8 @@ interface
// {$DEFINE ASSERT_IS_ON}
{$ENDIF}
{$INTERFACES CORBA}
uses
Classes, SysUtils, TypInfo, Types, Laz_AVL_Tree,
// LCL
@ -79,7 +81,15 @@ const
// Mac and iOS use Meta instead of Ctrl for those shortcuts
ssModifier = {$if defined(darwin) or defined(macos) or defined(iphonesim)} ssMeta {$else} ssCtrl {$endif};
GUID_ObjInspInterface = '{37417989-8C8F-4A2D-9D26-0FA377E8D8CC}';
type
IObjInspInterface = interface
[GUID_ObjInspInterface]
function AllowAdd: Boolean;
function AllowDelete: Boolean;
end;
TWinControl = class;
TControl = class;
TWinControlClass = class of TWinControl;

View File

@ -1168,7 +1168,7 @@ type
waAvoid, // try not to wrap after this control, if the control is already at the beginning of the row, wrap though
waForbid); // never wrap after this control
TFlowPanelControl = class(TCollectionItem)
TFlowPanelControl = class(TCollectionItem, IObjInspInterface)
private
FControl: TControl;
FWrapAfter: TWrapAfter;
@ -1180,13 +1180,17 @@ type
procedure AssignTo(Dest: TPersistent); override;
function FPCollection: TFlowPanelControlList;
function FPOwner: TCustomFlowPanel;
public
// These methods are used by the Object Inspector only
function AllowAdd: Boolean;
function AllowDelete: Boolean;
published
property Control: TControl read FControl write SetControl;
property WrapAfter: TWrapAfter read FWrapAfter write SetWrapAfter;
property Index;
end;
TFlowPanelControlList = class(TOwnedCollection)
TFlowPanelControlList = class(TOwnedCollection, IObjInspInterface)
private
function GetItem(Index: Integer): TFlowPanelControl;
procedure SetItem(Index: Integer; const AItem: TFlowPanelControl);
@ -1200,8 +1204,11 @@ type
constructor Create(AOwner: TPersistent);
public
function IndexOf(AControl: TControl): Integer;
property Items[Index: Integer]: TFlowPanelControl read GetItem write SetItem; default;
public
// These methods are used by the Object Inspector only
function AllowAdd: Boolean;
function AllowDelete: Boolean;
end;
TCustomFlowPanel = class(TCustomPanel)

View File

@ -56,6 +56,16 @@ begin
Item.FControl := AControl;
end;
function TFlowPanelControlList.AllowAdd: Boolean;
begin
Result := false;
end;
function TFlowPanelControlList.AllowDelete: Boolean;
begin
Result := false;
end;
function TFlowPanelControlList.FPOwner: TCustomFlowPanel;
begin
Result := TCustomFlowPanel(GetOwner);
@ -108,6 +118,16 @@ begin
inherited AssignTo(Dest);
end;
function TFlowPanelControl.AllowAdd: Boolean;
begin
Result := false;
end;
function TFlowPanelControl.AllowDelete: Boolean;
begin
Result := false;
end;
function TFlowPanelControl.FPCollection: TFlowPanelControlList;
begin
Result := Collection as TFlowPanelControlList;
@ -131,6 +151,8 @@ begin
if FControl = aControl then Exit;
Assert(FControl = nil);
FControl := aControl;
if FControl <> nil then
FControl.Parent := FPOwner;
end;
procedure TFlowPanelControl.SetIndex(Value: Integer);
@ -178,6 +200,8 @@ var
for I := BStartControl to BEndControl do
begin
xControl := FControlList[I].Control;
if xControl = nil then
Continue;
if not xControl.Visible and not (csDesigning in ComponentState) then
Continue;
@ -239,6 +263,8 @@ begin
for I := 0 to FControlList.Count-1 do
begin
xControl := FControlList[I].Control;
if xControl = nil then
Continue;
xConBS := xControl.BorderSpacing;
if not xControl.Visible and not (csDesigning in ComponentState) then
continue;
@ -341,6 +367,8 @@ begin
for I := 0 to FControlList.Count-1 do
begin
xControl := FControlList[I].Control;
if xControl = nil then
continue;
xConBS := xControl.BorderSpacing;
if not xControl.Visible and not (csDesigning in ComponentState) then
continue;