Ast editor unit refactoring
This commit is contained in:
@@ -27,16 +27,16 @@ const
|
||||
cMinNodeHeight = 10;
|
||||
|
||||
type
|
||||
TAuraNode = class; // Forward declaration
|
||||
TAstViewNode = class; // Forward declaration
|
||||
|
||||
// This aggregate interface encapsulates all node-specific logic.
|
||||
IAuraNodeHandler = interface
|
||||
IAstViewNodeHandler = interface
|
||||
// Gets the original logical AST node
|
||||
function GetAstNode: IAstNode;
|
||||
// Creates the specific FMX UI for this node
|
||||
procedure BuildUI(OwnerNode: TAuraNode);
|
||||
procedure BuildUI(OwnerNode: TAstViewNode);
|
||||
// Reconstructs the logical AST node from the FMX UI state
|
||||
function ReconstructAst(OwnerNode: TAuraNode): IAstNode;
|
||||
function ReconstructAst(OwnerNode: TAstViewNode): IAstNode;
|
||||
// The original logical AST node
|
||||
property Node: IAstNode read GetAstNode;
|
||||
end;
|
||||
@@ -45,15 +45,15 @@ type
|
||||
{$region 'private'}
|
||||
function GetExprDepth: Integer;
|
||||
function GetParentControl: TControl;
|
||||
function GetWorkspace: TAuraWorkspace;
|
||||
function GetWorkspace: TAstWorkspace;
|
||||
{$endregion}
|
||||
|
||||
function Clone(ParentControl: TControl; ExprDepth: Integer): IAstVisualizer;
|
||||
function CallAccept(const Node: IAstNode): TAuraNode;
|
||||
function CallAccept(const Node: IAstNode): TAstViewNode;
|
||||
|
||||
property ExprDepth: Integer read GetExprDepth;
|
||||
property ParentControl: TControl read GetParentControl;
|
||||
property Workspace: TAuraWorkspace read GetWorkspace;
|
||||
property Workspace: TAstWorkspace read GetWorkspace;
|
||||
end;
|
||||
|
||||
// Defines the layout direction for children within TAutoFitControl
|
||||
@@ -88,7 +88,7 @@ type
|
||||
end;
|
||||
|
||||
// A movable panel with a custom-painted border. Content (like title) is added externally.
|
||||
TAuraNode = class(TAutoFitControl)
|
||||
TAstViewNode = class(TAutoFitControl)
|
||||
private
|
||||
FBackgroundColor: TAlphaColor;
|
||||
FIsDragging: Boolean;
|
||||
@@ -98,7 +98,7 @@ type
|
||||
FBorderRadius: Single;
|
||||
FFrameless: Boolean;
|
||||
FVisualizer: IAstVisualizer;
|
||||
FHandler: IAuraNodeHandler;
|
||||
FHandler: IAstViewNodeHandler;
|
||||
|
||||
// --- Visual State Fields ---
|
||||
FErrorMessage: string;
|
||||
@@ -124,14 +124,14 @@ type
|
||||
procedure SetupNode;
|
||||
|
||||
public
|
||||
constructor Create(const AVisualizer: IAstVisualizer; const AHandler: IAuraNodeHandler); reintroduce;
|
||||
constructor Create(const AVisualizer: IAstVisualizer; const AHandler: IAstViewNodeHandler); reintroduce;
|
||||
destructor Destroy; override;
|
||||
|
||||
procedure AfterConstruction; override;
|
||||
|
||||
function AddLabel(Parent: TControl; const Txt: String): TLabel;
|
||||
function AddContainer(Parent: TControl; Orientation: TLayoutOrientation; Alignment: TLayoutAlignment): TAutoFitControl;
|
||||
function AddExpr(Parent: TControl; const Title: String; const Node: IAstNode): TAuraNode;
|
||||
function AddExpr(Parent: TControl; const Title: String; const Node: IAstNode): TAstViewNode;
|
||||
|
||||
function CreateAst: IAstNode;
|
||||
|
||||
@@ -181,14 +181,14 @@ type
|
||||
end;
|
||||
|
||||
// Helper base class to reduce boilerplate in specific handlers
|
||||
TBaseNodeHandler<T: IAstNode> = class(TInterfacedObject, IAuraNodeHandler)
|
||||
TBaseNodeHandler<T: IAstNode> = class(TInterfacedObject, IAstViewNodeHandler)
|
||||
protected
|
||||
FNode: T;
|
||||
function GetAstNode: IAstNode;
|
||||
public
|
||||
constructor Create(const ANode: T);
|
||||
procedure BuildUI(OwnerNode: TAuraNode); virtual; abstract;
|
||||
function ReconstructAst(OwnerNode: TAuraNode): IAstNode; virtual; abstract;
|
||||
procedure BuildUI(OwnerNode: TAstViewNode); virtual; abstract;
|
||||
function ReconstructAst(OwnerNode: TAstViewNode): IAstNode; virtual; abstract;
|
||||
end;
|
||||
|
||||
implementation
|
||||
@@ -383,9 +383,9 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TAuraNode }
|
||||
{ TAstViewNode }
|
||||
|
||||
constructor TAuraNode.Create(const AVisualizer: IAstVisualizer; const AHandler: IAuraNodeHandler);
|
||||
constructor TAstViewNode.Create(const AVisualizer: IAstVisualizer; const AHandler: IAstViewNodeHandler);
|
||||
begin
|
||||
inherited Create(AVisualizer.Workspace);
|
||||
|
||||
@@ -423,13 +423,13 @@ begin
|
||||
BackgroundColor := c;
|
||||
end;
|
||||
|
||||
destructor TAuraNode.Destroy;
|
||||
destructor TAstViewNode.Destroy;
|
||||
begin
|
||||
FHandler := nil;
|
||||
inherited;
|
||||
end;
|
||||
|
||||
function TAuraNode.AddContainer(Parent: TControl; Orientation: TLayoutOrientation; Alignment: TLayoutAlignment): TAutoFitControl;
|
||||
function TAstViewNode.AddContainer(Parent: TControl; Orientation: TLayoutOrientation; Alignment: TLayoutAlignment): TAutoFitControl;
|
||||
begin
|
||||
Result := TAutoFitControl.Create(Self);
|
||||
Result.Parent := Parent;
|
||||
@@ -438,7 +438,7 @@ begin
|
||||
Result.HitTest := False;
|
||||
end;
|
||||
|
||||
function TAuraNode.AddExpr(Parent: TControl; const Title: String; const Node: IAstNode): TAuraNode;
|
||||
function TAstViewNode.AddExpr(Parent: TControl; const Title: String; const Node: IAstNode): TAstViewNode;
|
||||
begin
|
||||
var cont := AddContainer(Parent, loHorizontal, laCenter);
|
||||
|
||||
@@ -448,7 +448,7 @@ begin
|
||||
Result := FVisualizer.Clone(cont, FVisualizer.ExprDepth + 1).CallAccept(Node);
|
||||
end;
|
||||
|
||||
function TAuraNode.AddLabel(Parent: TControl; const Txt: String): TLabel;
|
||||
function TAstViewNode.AddLabel(Parent: TControl; const Txt: String): TLabel;
|
||||
begin
|
||||
Result := TLabel.Create(Self);
|
||||
Result.Parent := Parent;
|
||||
@@ -468,13 +468,13 @@ begin
|
||||
Result.ApplyStyleLookup;
|
||||
end;
|
||||
|
||||
procedure TAuraNode.AfterConstruction;
|
||||
procedure TAstViewNode.AfterConstruction;
|
||||
begin
|
||||
inherited;
|
||||
SetupNode;
|
||||
end;
|
||||
|
||||
function TAuraNode.CreateAst: IAstNode;
|
||||
function TAstViewNode.CreateAst: IAstNode;
|
||||
begin
|
||||
if Assigned(FHandler) then
|
||||
Result := FHandler.ReconstructAst(Self)
|
||||
@@ -482,7 +482,7 @@ begin
|
||||
Result := TAst.Nop;
|
||||
end;
|
||||
|
||||
function TAuraNode.GetNode: IAstNode;
|
||||
function TAstViewNode.GetNode: IAstNode;
|
||||
begin
|
||||
if Assigned(FHandler) then
|
||||
Result := FHandler.Node
|
||||
@@ -490,7 +490,7 @@ begin
|
||||
Result := nil;
|
||||
end;
|
||||
|
||||
procedure TAuraNode.SetErrorMessage(const Value: string);
|
||||
procedure TAstViewNode.SetErrorMessage(const Value: string);
|
||||
begin
|
||||
if FErrorMessage <> Value then
|
||||
begin
|
||||
@@ -500,7 +500,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TAuraNode.SetTypeInfoText(const Value: string);
|
||||
procedure TAstViewNode.SetTypeInfoText(const Value: string);
|
||||
begin
|
||||
if FTypeInfoText <> Value then
|
||||
begin
|
||||
@@ -510,7 +510,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TAuraNode.UpdateVisualState;
|
||||
procedure TAstViewNode.UpdateVisualState;
|
||||
begin
|
||||
if FErrorMessage <> '' then
|
||||
begin
|
||||
@@ -529,7 +529,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TAuraNode.Paint;
|
||||
procedure TAstViewNode.Paint;
|
||||
var
|
||||
rect: TRectF;
|
||||
effBorderColor: TAlphaColor;
|
||||
@@ -595,7 +595,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TAuraNode.SetBorderColor(const Value: TAlphaColor);
|
||||
procedure TAstViewNode.SetBorderColor(const Value: TAlphaColor);
|
||||
begin
|
||||
if FBorderColor <> Value then
|
||||
begin
|
||||
@@ -604,7 +604,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TAuraNode.SetBorderRadius(const Value: Single);
|
||||
procedure TAstViewNode.SetBorderRadius(const Value: Single);
|
||||
begin
|
||||
if FBorderRadius <> Value then
|
||||
begin
|
||||
@@ -613,7 +613,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TAuraNode.SetBorderWidth(const Value: Single);
|
||||
procedure TAstViewNode.SetBorderWidth(const Value: Single);
|
||||
begin
|
||||
if FBorderWidth <> Value then
|
||||
begin
|
||||
@@ -622,7 +622,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TAuraNode.SetFrameless(const Value: Boolean);
|
||||
procedure TAstViewNode.SetFrameless(const Value: Boolean);
|
||||
begin
|
||||
if FFrameless <> Value then
|
||||
begin
|
||||
@@ -631,7 +631,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TAuraNode.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Single);
|
||||
procedure TAstViewNode.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Single);
|
||||
begin
|
||||
inherited;
|
||||
if Button = TMouseButton.mbLeft then
|
||||
@@ -649,7 +649,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TAuraNode.MouseMove(Shift: TShiftState; X, Y: Single);
|
||||
procedure TAstViewNode.MouseMove(Shift: TShiftState; X, Y: Single);
|
||||
begin
|
||||
inherited;
|
||||
|
||||
@@ -666,7 +666,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TAuraNode.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Single);
|
||||
procedure TAstViewNode.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Single);
|
||||
begin
|
||||
inherited;
|
||||
if (Button = TMouseButton.mbLeft) and (FIsDragging) then
|
||||
@@ -678,13 +678,13 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TAuraNode.SetBackgroundColor(const Value: TAlphaColor);
|
||||
procedure TAstViewNode.SetBackgroundColor(const Value: TAlphaColor);
|
||||
begin
|
||||
FBackgroundColor := Value;
|
||||
Repaint;
|
||||
end;
|
||||
|
||||
procedure TAuraNode.SetupNode;
|
||||
procedure TAstViewNode.SetupNode;
|
||||
begin
|
||||
if Assigned(FHandler) then
|
||||
FHandler.BuildUI(Self);
|
||||
|
||||
Reference in New Issue
Block a user