unit uDesignerSelectionProtector;
//////////////////////////////////////
/// Designer Selection Protector ///
/// **************************** ///
/// (c) 2017 Dennis Göhlert a.o. ///
//////////////////////////////////////
interface
uses
DesignIntf, DesignEditors,
System.Classes,
Vcl.Controls;
type
TDesignerSelectionProtector =
class(TSelectionEditor)
private
class procedure HideChildren(
const ADesigner: IDesigner;
const AControl: TWinControl);
static;
class procedure ViewChildren(
const ADesigner: IDesigner;
const AControl: TWinControl);
static;
private type
TDesignerSelectionProc =
procedure (
const ADesigner: IDesigner;
const AControl: TWinControl);
TDesignerSelectionAction =
record
Verb:
String;
Proc: TDesignerSelectionProc;
end;
protected const
FActions:
array [0 .. 1]
of TDesignerSelectionAction = (
(
Verb: '
Hide children';
Proc: TDesignerSelectionProtector.HideChildren
), (
Verb: '
View children';
Proc: TDesignerSelectionProtector.ViewChildren
)
);
public
procedure ExecuteVerb(
Index: Integer;
const List: IDesignerSelections);
override;
function GetVerb(
Index: Integer):
String;
override;
function GetVerbCount: Integer;
override;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterSelectionEditor(TWinControl, TDesignerSelectionProtector);
end;
{ TDesignerSelectionLocker }
procedure TDesignerSelectionProtector.ExecuteVerb(
Index: Integer;
const List: IDesignerSelections);
var
LSelectionIndex: Integer;
LSelection: TPersistent;
begin
inherited;
for LSelectionIndex := 0
to Pred(List.Count)
do
begin
LSelection := List[LSelectionIndex];
if LSelection
is TWinControl
then
begin
FActions[
Index].Proc(Designer, LSelection
as TWinControl);
end;
end;
Designer.Modified;
end;
function TDesignerSelectionProtector.GetVerb(
Index: Integer):
String;
begin
Result := FActions[
Index].Verb;
end;
function TDesignerSelectionProtector.GetVerbCount: Integer;
begin
Result := Length(FActions);
end;
class procedure TDesignerSelectionProtector.HideChildren(
const ADesigner: IDesigner;
const AControl: TWinControl);
var
LIndex: Integer;
begin
for LIndex := 0
to Pred(AControl.ControlCount)
do
begin
AControl.Controls[LIndex].SetDesignVisible(False);
end;
end;
class procedure TDesignerSelectionProtector.ViewChildren(
const ADesigner: IDesigner;
const AControl: TWinControl);
var
LIndex: Integer;
begin
for LIndex := 0
to Pred(AControl.ControlCount)
do
begin
AControl.Controls[LIndex].SetDesignVisible(True);
end;
end;
end.