Visual AST editing with drag'n'drop 1s Version

This commit is contained in:
Michael Schimmel
2025-11-30 16:00:00 +01:00
parent cd0f2ffde3
commit 438baa3609
10 changed files with 917 additions and 565 deletions
+10 -9
View File
@@ -119,7 +119,7 @@ type
FCurrUnboundAst: IAstNode;
FCurrExec: TCompiledFunction;
FEnvironment: TAstEnvironment;
FWorkspace: TAstWorkspace;
FWorkspace: TWorkspace; // Changed to TWorkspace
FController: TAstEditorController; // The UI Controller
FScriptUpdate: Boolean;
FTriggerTest: TAstEnvironment;
@@ -159,13 +159,15 @@ begin
FEnvironment := TAstEnvironment.Construct(TAst.CreateScope(nil));
// 2. Initialize Workspace
FWorkspace := TAstWorkspace.Create(Panel2);
// TWorkspace is now a simple viewport control
FWorkspace := TWorkspace.Create(Panel2);
FWorkspace.Parent := Panel2;
FWorkspace.Align := TAlignLayout.Client;
FWorkspace.ClipChildren := true;
FWorkspace.OnMouseDown := WorkspaceMouseDown;
// 3. Initialize Controller (connects Env and Workspace)
// The Controller will manage the nodes inside FWorkspace.World
FController := TAstEditorController.Create(FEnvironment, FWorkspace);
// 4. Register the SMA factory into the environment
@@ -295,6 +297,7 @@ begin
exit;
// Use the Controller to build, validate and show the UI
// The controller internally clears FWorkspace.World and adds nodes there.
FController.SetRoot(FCurrUnboundAst);
end;
@@ -419,8 +422,9 @@ end;
procedure TForm1.ClearButtonClick(Sender: TObject);
begin
FWorkspace.DeleteChildren;
FWorkspace.Repaint;
// Clear content of world (not workspace itself, as it has the root layer)
FWorkspace.World.DeleteChildren;
FWorkspace.World.Repaint;
end;
procedure TForm1.CompilerStageBoxChange(Sender: TObject);
@@ -886,8 +890,8 @@ procedure TForm1.UpdateScript;
begin
PrintScript(FCurrUnboundAst);
FWorkspace.DeleteChildren;
ShowVizualization(14, 14);
// Clear and redraw via Controller
FController.SetRoot(FCurrUnboundAst);
end;
procedure TForm1.WorkspaceMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
@@ -897,9 +901,6 @@ begin
ShowVizualization(X, Y);
end;
// ... Copy of the rest of the file logic (Save, Load, Dump, etc.) ...
// To ensure completeness, here are the remaining methods:
procedure TForm1.SaveUserLibButtonClick(Sender: TObject);
var
rootNode: IAstNode;