|
@@ -1,4 +1,6 @@
|
|
-using PixiEditor.Extensions.CommonApi.LayoutBuilding.Events;
|
|
|
|
|
|
+using Microsoft.CodeAnalysis.MSBuild;
|
|
|
|
+using PixiEditor.DevTools.CsharpCoding;
|
|
|
|
+using PixiEditor.Extensions.CommonApi.LayoutBuilding.Events;
|
|
using PixiEditor.Extensions.IO;
|
|
using PixiEditor.Extensions.IO;
|
|
using PixiEditor.Extensions.LayoutBuilding.Elements;
|
|
using PixiEditor.Extensions.LayoutBuilding.Elements;
|
|
using PixiEditor.Extensions.Runtime;
|
|
using PixiEditor.Extensions.Runtime;
|
|
@@ -8,11 +10,18 @@ namespace PixiEditor.DevTools.Layouts;
|
|
public class LivePreviewWindowState : State
|
|
public class LivePreviewWindowState : State
|
|
{
|
|
{
|
|
private ExtensionLoader Loader { get; }
|
|
private ExtensionLoader Loader { get; }
|
|
- public string? SelectedLayoutFile { get; set; }
|
|
|
|
|
|
+ private ProjectLoader projectLoader;
|
|
|
|
+ private ProjectCompiler compiler;
|
|
|
|
+ private HotReloader reloader;
|
|
|
|
+
|
|
|
|
+ private LayoutElement? _element;
|
|
|
|
+ public string? SelectedProjectFile { get; set; }
|
|
|
|
|
|
public LivePreviewWindowState()
|
|
public LivePreviewWindowState()
|
|
{
|
|
{
|
|
Loader = new ExtensionLoader(AppDomain.CurrentDomain.BaseDirectory);
|
|
Loader = new ExtensionLoader(AppDomain.CurrentDomain.BaseDirectory);
|
|
|
|
+ reloader = new HotReloader();
|
|
|
|
+ reloader.OnFileChanged += OnFileChanged;
|
|
}
|
|
}
|
|
|
|
|
|
public override LayoutElement BuildElement()
|
|
public override LayoutElement BuildElement()
|
|
@@ -20,22 +29,49 @@ public class LivePreviewWindowState : State
|
|
return new Align(
|
|
return new Align(
|
|
alignment: Alignment.TopLeft,
|
|
alignment: Alignment.TopLeft,
|
|
child: new Column(
|
|
child: new Column(
|
|
- children: new Button(
|
|
|
|
- child: SelectedLayoutFile != null ? new Text($"Selected extension: {SelectedLayoutFile}") : new Text("Select extension"),
|
|
|
|
- onClick: OnClick)
|
|
|
|
|
|
+ new Button(
|
|
|
|
+ child: SelectedProjectFile != null ? new Text($"Selected extension: {SelectedProjectFile}") : new Text("Select extension"),
|
|
|
|
+ onClick: OnClick),
|
|
|
|
+ _element ?? new Text("No layout element selected")
|
|
)
|
|
)
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void OnFileChanged(string obj)
|
|
|
|
+ {
|
|
|
|
+ compiler.Compile();
|
|
|
|
+ SetState(BuildLayoutElement);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void BuildLayoutElement()
|
|
|
|
+ {
|
|
|
|
+ var typeToInit = compiler.LayoutElementTypes.FirstOrDefault();
|
|
|
|
+ if (typeToInit != null)
|
|
|
|
+ {
|
|
|
|
+ var instance = (LayoutElement)Activator.CreateInstance(typeToInit);
|
|
|
|
+ _element = instance;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private void OnClick(ElementEventArgs args)
|
|
private void OnClick(ElementEventArgs args)
|
|
{
|
|
{
|
|
- if (DevToolsExtension.PixiEditorApi.FileSystem.OpenFileDialog(new FileFilter().AddFilter("Layout C# Script", "*.cs"), out string? path))
|
|
|
|
|
|
+ if (DevToolsExtension.PixiEditorApi.FileSystem.OpenFileDialog(new FileFilter().AddFilter("C# project file", "*.csproj"), out string? path))
|
|
{
|
|
{
|
|
SetState(() =>
|
|
SetState(() =>
|
|
{
|
|
{
|
|
- SelectedLayoutFile = path;
|
|
|
|
-
|
|
|
|
|
|
+ SelectedProjectFile = path;
|
|
|
|
+ InitProject();
|
|
});
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private void InitProject()
|
|
|
|
+ {
|
|
|
|
+ projectLoader = new ProjectLoader(SelectedProjectFile);
|
|
|
|
+ projectLoader.LoadProjects();
|
|
|
|
+ compiler = new ProjectCompiler(projectLoader.Workspace, projectLoader.AllProjects);
|
|
|
|
+ reloader.WatchProject(SelectedProjectFile);
|
|
|
|
+ compiler.Compile();
|
|
|
|
+ BuildLayoutElement();
|
|
|
|
+ }
|
|
}
|
|
}
|