Added round rectangle, cicle and triangle.
Applied Antialias on most of elements.
This commit is contained in:
80
Progrart.Core/Graphics/Circle.cs
Normal file
80
Progrart.Core/Graphics/Circle.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using Jint;
|
||||
using Jint.Native;
|
||||
using Progrart.Core.JSExecution;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Progrart.Core.Graphics
|
||||
{
|
||||
public class Circle : BaseElement
|
||||
{
|
||||
|
||||
float StrokeWidth;
|
||||
SKPoint Position;
|
||||
float Size;
|
||||
SKColorF Color;
|
||||
bool IsStroke;
|
||||
SKShader? shader = null;
|
||||
public override void SetupProperties(Engine engine)
|
||||
{
|
||||
base.SetupProperties(engine);
|
||||
if (__object != null)
|
||||
{
|
||||
{
|
||||
JsObject point = new JsObject(engine);
|
||||
point.Set("x", 0);
|
||||
point.Set("y", 0);
|
||||
__object.Set("Position", point);
|
||||
}
|
||||
__object.Set("StrokeWidth", 1);
|
||||
__object.Set("Size", 1);
|
||||
__object.Set("IsStroke", true);
|
||||
__object.Set("Color", ProgrartFunctions.color(engine, 1, 1, 1, 1));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
public override void LoadProperties()
|
||||
{
|
||||
if (__object is not null)
|
||||
{
|
||||
StrokeWidth = (float)__object.Get("StrokeWidth").AsNumber();
|
||||
Size = (float)__object.Get("Size").AsNumber();
|
||||
IsStroke = (bool)__object.Get("IsStroke").AsBoolean();
|
||||
{
|
||||
if (__object.Get("Position") is JsObject Start)
|
||||
{
|
||||
this.Position = ProgrartConversion.ObtainSKPointFromJsObject(Start);
|
||||
}
|
||||
}
|
||||
{
|
||||
if (__object.Get("Color") is JsObject Color)
|
||||
{
|
||||
this.Color = ProgrartConversion.ObtainSKColorFFromJsObject(Color);
|
||||
}
|
||||
}
|
||||
|
||||
if (__object.Get("Shader") is JsObject shaderObj)
|
||||
shader = ProgrartConversion.ObtainFromJsObject(shaderObj);
|
||||
}
|
||||
}
|
||||
public override void Render(RenderContext context)
|
||||
{
|
||||
base.Render(context);
|
||||
LoadProperties();
|
||||
SKPoint pos = context.TranslatePoint(Position);
|
||||
float Size = context.TranslateSize(this.Size);
|
||||
context.DrawingCore.canvas.DrawCircle(
|
||||
pos.X, pos.Y,
|
||||
Size,
|
||||
new SKPaint()
|
||||
{
|
||||
ColorF = Color,
|
||||
StrokeWidth = context.TranslateSize(StrokeWidth),
|
||||
Shader = shader,
|
||||
IsStroke = IsStroke,
|
||||
IsAntialias = true
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,7 +78,8 @@ namespace Progrart.Core.Graphics
|
||||
{
|
||||
ColorF = Color,
|
||||
StrokeWidth = context.TranslateSize(Size),
|
||||
Shader = shader
|
||||
Shader = shader,
|
||||
IsAntialias = true
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -74,7 +74,6 @@ namespace Progrart.Core.Graphics
|
||||
LoadProperties();
|
||||
SKPoint FinalStartPos = context.TranslatePoint(Start);
|
||||
SKPoint FinalEndPos = context.TranslatePoint(Size);
|
||||
Trace.WriteLine($"Draw Rectangle from {FinalStartPos} to {FinalEndPos} using {Color} with size of {StrokeWidth}.");
|
||||
context.DrawingCore.canvas.DrawRect(
|
||||
FinalStartPos.X, FinalStartPos.Y,
|
||||
FinalEndPos.X, FinalEndPos.Y,
|
||||
@@ -83,7 +82,8 @@ namespace Progrart.Core.Graphics
|
||||
ColorF = Color,
|
||||
StrokeWidth = context.TranslateSize(StrokeWidth),
|
||||
Shader = shader,
|
||||
IsStroke = true
|
||||
IsStroke = IsStroke,
|
||||
IsAntialias = true
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
100
Progrart.Core/Graphics/RoundRectangle.cs
Normal file
100
Progrart.Core/Graphics/RoundRectangle.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using Jint;
|
||||
using Jint.Native;
|
||||
using Progrart.Core.JSExecution;
|
||||
using SkiaSharp;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Progrart.Core.Graphics
|
||||
{
|
||||
public class RoundRectangle : BaseElement
|
||||
{
|
||||
|
||||
float StrokeWidth;
|
||||
float rx;
|
||||
float ry;
|
||||
SKPoint Start;
|
||||
SKPoint Size;
|
||||
SKColorF Color;
|
||||
bool IsStroke;
|
||||
SKShader? shader = null;
|
||||
public override void SetupProperties(Engine engine)
|
||||
{
|
||||
base.SetupProperties(engine);
|
||||
if (__object != null)
|
||||
{
|
||||
{
|
||||
JsObject point = new JsObject(engine);
|
||||
point.Set("x", 0);
|
||||
point.Set("y", 0);
|
||||
__object.Set("Position", point);
|
||||
}
|
||||
__object.Set("StrokeWidth", 1);
|
||||
__object.Set("rx", 0);
|
||||
__object.Set("ry", 0);
|
||||
__object.Set("IsStroke", true);
|
||||
__object.Set("Color", ProgrartFunctions.color(engine, 1, 1, 1, 1));
|
||||
{
|
||||
JsObject point = new JsObject(engine);
|
||||
point.Set("x", 0);
|
||||
point.Set("y", 0);
|
||||
__object.Set("Size", point);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
public override void LoadProperties()
|
||||
{
|
||||
if (__object is not null)
|
||||
{
|
||||
StrokeWidth = (float)__object.Get("StrokeWidth").AsNumber();
|
||||
rx = (float)__object.Get("rx").AsNumber();
|
||||
ry = (float)__object.Get("ry").AsNumber();
|
||||
IsStroke = (bool)__object.Get("IsStroke").AsBoolean();
|
||||
{
|
||||
if (__object.Get("Position") is JsObject Start)
|
||||
{
|
||||
this.Start = ProgrartConversion.ObtainSKPointFromJsObject(Start);
|
||||
}
|
||||
}
|
||||
{
|
||||
if (__object.Get("Size") is JsObject End)
|
||||
{
|
||||
this.Size = ProgrartConversion.ObtainSKPointFromJsObject(End);
|
||||
}
|
||||
}
|
||||
{
|
||||
if (__object.Get("Color") is JsObject Color)
|
||||
{
|
||||
this.Color = ProgrartConversion.ObtainSKColorFFromJsObject(Color);
|
||||
}
|
||||
}
|
||||
|
||||
if (__object.Get("Shader") is JsObject shaderObj)
|
||||
shader = ProgrartConversion.ObtainFromJsObject(shaderObj);
|
||||
}
|
||||
}
|
||||
public override void Render(RenderContext context)
|
||||
{
|
||||
base.Render(context);
|
||||
LoadProperties();
|
||||
SKPoint Position = context.TranslatePoint(Start);
|
||||
SKPoint Size = context.TranslatePoint(this.Size);
|
||||
float rx = context.TranslateSize(this.rx);
|
||||
float ry = context.TranslateSize(this.ry);
|
||||
Trace.WriteLine($"Draw Rectangle from {Position} to {Size} using {Color} with size of {StrokeWidth}.");
|
||||
context.DrawingCore.canvas.DrawRoundRect(
|
||||
Position.X, Position.Y,
|
||||
Size.X, Size.Y, rx, ry,
|
||||
new SKPaint()
|
||||
{
|
||||
ColorF = Color,
|
||||
StrokeWidth = context.TranslateSize(StrokeWidth),
|
||||
Shader = shader,
|
||||
IsStroke = IsStroke,
|
||||
IsAntialias = true
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
110
Progrart.Core/Graphics/Triangle.cs
Normal file
110
Progrart.Core/Graphics/Triangle.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
using Jint;
|
||||
using Jint.Native;
|
||||
using Progrart.Core.JSExecution;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Progrart.Core.Graphics
|
||||
{
|
||||
public class Triangle : BaseElement
|
||||
{
|
||||
float StrokeWidth;
|
||||
SKPoint Vertex0;
|
||||
SKPoint Vertex1;
|
||||
SKPoint Vertex2;
|
||||
SKColorF Color;
|
||||
bool IsStroke;
|
||||
SKShader? shader = null;
|
||||
public override void SetupProperties(Engine engine)
|
||||
{
|
||||
base.SetupProperties(engine);
|
||||
if (__object != null)
|
||||
{
|
||||
{
|
||||
JsObject point = new JsObject(engine);
|
||||
point.Set("x", 0);
|
||||
point.Set("y", 0);
|
||||
__object.Set("Vertex0", point);
|
||||
}
|
||||
{
|
||||
JsObject point = new JsObject(engine);
|
||||
point.Set("x", 0);
|
||||
point.Set("y", 0);
|
||||
__object.Set("Vertex1", point);
|
||||
}
|
||||
{
|
||||
JsObject point = new JsObject(engine);
|
||||
point.Set("x", 0);
|
||||
point.Set("y", 0);
|
||||
__object.Set("Vertex2", point);
|
||||
}
|
||||
__object.Set("StrokeWidth", 1);
|
||||
__object.Set("IsStroke", true);
|
||||
__object.Set("Color", ProgrartFunctions.color(engine, 1, 1, 1, 1));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
public override void LoadProperties()
|
||||
{
|
||||
if (__object is not null)
|
||||
{
|
||||
StrokeWidth = (float)__object.Get("StrokeWidth").AsNumber();
|
||||
IsStroke = (bool)__object.Get("IsStroke").AsBoolean();
|
||||
{
|
||||
if (__object.Get("Vertex0") is JsObject Start)
|
||||
{
|
||||
this.Vertex0 = ProgrartConversion.ObtainSKPointFromJsObject(Start);
|
||||
}
|
||||
}
|
||||
{
|
||||
if (__object.Get("Vertex1") is JsObject Start)
|
||||
{
|
||||
this.Vertex1 = ProgrartConversion.ObtainSKPointFromJsObject(Start);
|
||||
}
|
||||
}
|
||||
{
|
||||
if (__object.Get("Vertex2") is JsObject Start)
|
||||
{
|
||||
this.Vertex2 = ProgrartConversion.ObtainSKPointFromJsObject(Start);
|
||||
}
|
||||
}
|
||||
{
|
||||
if (__object.Get("Color") is JsObject Color)
|
||||
{
|
||||
this.Color = ProgrartConversion.ObtainSKColorFFromJsObject(Color);
|
||||
}
|
||||
}
|
||||
|
||||
if (__object.Get("Shader") is JsObject shaderObj)
|
||||
shader = ProgrartConversion.ObtainFromJsObject(shaderObj);
|
||||
}
|
||||
}
|
||||
public override void Render(RenderContext context)
|
||||
{
|
||||
base.Render(context);
|
||||
LoadProperties();
|
||||
var v0 = context.TranslatePoint(Vertex0);
|
||||
var v1 = context.TranslatePoint(Vertex1);
|
||||
var v2 = context.TranslatePoint(Vertex2);
|
||||
using var p = new SKPath();
|
||||
p.MoveTo(v0);
|
||||
p.MoveTo(v0);
|
||||
//p.LineTo(v0);
|
||||
p.LineTo(v1);
|
||||
p.LineTo(v2);
|
||||
p.LineTo(v0);
|
||||
p.Close();
|
||||
|
||||
context.DrawingCore.canvas.DrawPath(p,
|
||||
new SKPaint()
|
||||
{
|
||||
ColorF = Color,
|
||||
StrokeWidth = context.TranslateSize(StrokeWidth),
|
||||
Shader = shader,
|
||||
IsStroke = IsStroke,
|
||||
IsAntialias = true
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,15 @@ namespace Progrart.Core.JSExecution
|
||||
Engine = new Engine();
|
||||
JsObject _obj = new JsObject(Engine);
|
||||
Engine.SetValue("math", _obj);
|
||||
Random r = new Random();
|
||||
_obj.Set("random", JsObject.FromObject(Engine, new Func<double>(() =>
|
||||
{
|
||||
return r.NextDouble();
|
||||
})));
|
||||
_obj.Set("seed", JsObject.FromObject(Engine, new Action<JsNumber>((n) =>
|
||||
{
|
||||
r = new Random((int)n.AsNumber());
|
||||
})));
|
||||
_obj.Set("abs", JsObject.FromObject(Engine, (object)MathFunctions.abs));
|
||||
_obj.Set("sin", JsObject.FromObject(Engine, (object)MathFunctions.sin));
|
||||
_obj.Set("cos", JsObject.FromObject(Engine, (object)MathFunctions.cos));
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
using Jint;
|
||||
using Jint.Native;
|
||||
using Jint.Native.Function;
|
||||
using Jint.Native.Json;
|
||||
using Progrart.Core.Graphics;
|
||||
using Progrart.Core.Storage;
|
||||
using System.Diagnostics;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Progrart.Core.JSExecution
|
||||
{
|
||||
@@ -35,6 +32,9 @@ namespace Progrart.Core.JSExecution
|
||||
engine.Engine.SetValue("visual_root", visual_root);
|
||||
engine.Engine.SetValue("line", line);
|
||||
engine.Engine.SetValue("rectangle", rectangle);
|
||||
engine.Engine.SetValue("roundrect", roundrect);
|
||||
engine.Engine.SetValue("triangle", triangle);
|
||||
engine.Engine.SetValue("circle", circle);
|
||||
engine.Engine.SetValue("color4", color4);
|
||||
engine.Engine.SetValue("color3", color3);
|
||||
engine.Engine.SetValue("color_hex", color_hex);
|
||||
@@ -62,14 +62,14 @@ namespace Progrart.Core.JSExecution
|
||||
public JsObject color_hex(JsString colorString)
|
||||
{
|
||||
byte[] bytes = Convert.FromHexString(colorString.AsString());
|
||||
if (bytes.Length == 4)
|
||||
if (bytes.Length == 3)
|
||||
return ProgrartFunctions.color(engine.Engine
|
||||
, colorFloat(bytes[0])
|
||||
, colorFloat(bytes[1])
|
||||
, colorFloat(bytes[2])
|
||||
);
|
||||
else
|
||||
if (bytes.Length == 3)
|
||||
if (bytes.Length == 4)
|
||||
return ProgrartFunctions.color(engine.Engine
|
||||
, colorFloat(bytes[0])
|
||||
, colorFloat(bytes[1])
|
||||
@@ -82,16 +82,12 @@ namespace Progrart.Core.JSExecution
|
||||
{
|
||||
return ProgrartFunctions.CreateVisualRoot(this);
|
||||
}
|
||||
public JsObject line()
|
||||
{
|
||||
//return ProgrartFunctions.CreateLine(this);
|
||||
return ProgrartFunctions.CreateElement<Line>(this);
|
||||
}
|
||||
public JsObject rectangle()
|
||||
{
|
||||
//return ProgrartFunctions.CreateLine(this);
|
||||
return ProgrartFunctions.CreateElement<Rectangle>(this);
|
||||
}
|
||||
public JsObject line() => ProgrartFunctions.CreateElement<Line>(this);
|
||||
public JsObject rectangle() => ProgrartFunctions.CreateElement<Rectangle>(this);
|
||||
public JsObject roundrect() => ProgrartFunctions.CreateElement<RoundRectangle>(this);
|
||||
public JsObject circle() => ProgrartFunctions.CreateElement<Circle>(this);
|
||||
public JsObject triangle() => ProgrartFunctions.CreateElement<Triangle>(this);
|
||||
|
||||
public RenderContext RenderImage(int Scale, string script, ExecuteArguments arguments)
|
||||
{
|
||||
float width = 1;
|
||||
@@ -106,7 +102,7 @@ namespace Progrart.Core.JSExecution
|
||||
{
|
||||
height = (float)(js_height.AsNumber());
|
||||
}
|
||||
RenderContext renderContext = new((int)(width * Scale), (int)(width * Scale), StorageProvider)
|
||||
RenderContext renderContext = new((int)(width * Scale), (int)(height * Scale), StorageProvider)
|
||||
{
|
||||
LogicalW = width,
|
||||
LogicalH = height
|
||||
|
||||
@@ -29,6 +29,8 @@ namespace Progrart.Core
|
||||
public RenderContext(int W, int H, IStorageProvider StorageProvider)
|
||||
{
|
||||
DrawingCore = new PrimitiveDrawingCore(W, H, StorageProvider);
|
||||
LogicalW=W;
|
||||
LogicalH=H;
|
||||
}
|
||||
}
|
||||
[Serializable]
|
||||
|
||||
@@ -1,31 +1,38 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<!--If you are willing to use platform-specific APIs, use conditional compilation.
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<!--If you are willing to use platform-specific APIs, use conditional compilation.
|
||||
See https://docs.avaloniaui.net/docs/guides/platforms/platform-specific-code/dotnet for more details.-->
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<PublishAot>true</PublishAot>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
<ApplicationIcon>progrart_app_icon.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
<ApplicationIcon>progrart_app_icon.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="progrart_app_icon.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="progrart_app_icon.ico" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia.Desktop" />
|
||||
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
|
||||
<PackageReference Include="Avalonia.Diagnostics">
|
||||
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
|
||||
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<TrimmerRootAssembly Include="Progrart" />
|
||||
<TrimmerRootAssembly Include="Progrart.Core" />
|
||||
<TrimmerRootAssembly Include="Jint" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Progrart\Progrart.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia.Desktop" />
|
||||
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
|
||||
<PackageReference Include="Avalonia.Diagnostics">
|
||||
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
|
||||
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Progrart\Progrart.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -10,6 +10,7 @@ using AvaloniaEdit.TextMate;
|
||||
using Progrart.Commands;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using System.Xml;
|
||||
@@ -19,81 +20,79 @@ namespace Progrart.Controls;
|
||||
|
||||
public partial class BaseEditor : UserControl
|
||||
{
|
||||
RegistryOptions? _registryOptions;
|
||||
TextMate.Installation? _textMateInstallation;
|
||||
public string Text
|
||||
{
|
||||
get => CodeEditBox.Text;
|
||||
set => CodeEditBox.Text = value;
|
||||
}
|
||||
public Func<Task>? onSaveCmd;
|
||||
public BaseEditor()
|
||||
{
|
||||
InitializeComponent();
|
||||
RegistryOptions? _registryOptions;
|
||||
TextMate.Installation? _textMateInstallation;
|
||||
public string Text
|
||||
{
|
||||
get => CodeEditBox.Text;
|
||||
set => CodeEditBox.Text = value;
|
||||
}
|
||||
public Func<Task>? onSaveCmd;
|
||||
public BaseEditor()
|
||||
{
|
||||
InitializeComponent();
|
||||
var uri = new Uri("avares://Progrart/Assets/Styles/JavaScript.xml");
|
||||
|
||||
if (AssetLoader.Exists(uri))
|
||||
{
|
||||
using (Stream stream = AssetLoader.Open(uri))
|
||||
if (AssetLoader.Exists(uri))
|
||||
{
|
||||
using (XmlReader reader = XmlReader.Create(stream))
|
||||
{
|
||||
var xshd = HighlightingLoader.LoadXshd(reader);
|
||||
CodeEditBox.SyntaxHighlighting = HighlightingLoader.Load(xshd, HighlightingManager.Instance);
|
||||
}
|
||||
using Stream stream = AssetLoader.Open(uri);
|
||||
using XmlReader reader = XmlReader.Create(stream);
|
||||
var xshd = HighlightingLoader.LoadXshd(reader);
|
||||
CodeEditBox.SyntaxHighlighting = HighlightingLoader.Load(xshd, HighlightingManager.Instance);
|
||||
}
|
||||
if (!OperatingSystem.IsBrowser())
|
||||
{
|
||||
{
|
||||
var _textEditor = CodeEditBox;
|
||||
_registryOptions = new RegistryOptions(ThemeName.DarkPlus);
|
||||
_textMateInstallation = _textEditor.InstallTextMate(_registryOptions);
|
||||
_textMateInstallation.SetGrammar(_registryOptions.GetScopeByLanguageId(_registryOptions.GetLanguageByExtension(".js").Id));
|
||||
}
|
||||
}
|
||||
if (!OperatingSystem.IsBrowser())
|
||||
{
|
||||
var _textEditor = CodeEditBox;
|
||||
_registryOptions = new RegistryOptions(ThemeName.DarkPlus);
|
||||
_textMateInstallation = _textEditor.InstallTextMate(_registryOptions);
|
||||
_textMateInstallation.SetGrammar(_registryOptions.GetScopeByLanguageId(_registryOptions.GetLanguageByExtension(".js").Id));
|
||||
}
|
||||
var saveBinding = new KeyBinding
|
||||
{
|
||||
Gesture = new KeyGesture(Key.S, KeyModifiers.Control),
|
||||
Command = new GenericCommand() { onExecute = (_) => Task.Run(Save) }
|
||||
};
|
||||
var saveBinding = new KeyBinding
|
||||
{
|
||||
Gesture = new KeyGesture(Key.S, KeyModifiers.Control),
|
||||
Command = new GenericCommand() { onExecute = (_) => Task.Run(Save) }
|
||||
};
|
||||
|
||||
CodeEditBox.KeyBindings.Add(saveBinding);
|
||||
}
|
||||
async Task Save()
|
||||
{
|
||||
if (onSaveCmd is not null)
|
||||
await onSaveCmd.Invoke();
|
||||
}
|
||||
public void SetGrammerByExtension(string extension_name)
|
||||
{
|
||||
if (OperatingSystem.IsBrowser())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_textMateInstallation?.SetGrammar(
|
||||
_registryOptions?.GetScopeByLanguageId(
|
||||
_registryOptions.GetLanguageByExtension(extension_name).Id
|
||||
)
|
||||
);
|
||||
CodeEditBox.KeyBindings.Add(saveBinding);
|
||||
}
|
||||
async Task Save()
|
||||
{
|
||||
if (onSaveCmd is not null)
|
||||
await onSaveCmd.Invoke();
|
||||
}
|
||||
public void SetGrammerByExtension(string extension_name)
|
||||
{
|
||||
if (OperatingSystem.IsBrowser())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_textMateInstallation?.SetGrammar(
|
||||
_registryOptions?.GetScopeByLanguageId(
|
||||
_registryOptions.GetLanguageByExtension(extension_name).Id
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void Copy_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||
{
|
||||
CodeEditBox.Copy();
|
||||
}
|
||||
private void Copy_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||
{
|
||||
CodeEditBox.Copy();
|
||||
}
|
||||
|
||||
private void Paste_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||
{
|
||||
CodeEditBox.Paste();
|
||||
}
|
||||
private void Paste_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||
{
|
||||
CodeEditBox.Paste();
|
||||
}
|
||||
|
||||
private void Cut_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||
{
|
||||
CodeEditBox.Cut();
|
||||
}
|
||||
private void Cut_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||
{
|
||||
CodeEditBox.Cut();
|
||||
}
|
||||
|
||||
private void Find_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||
{
|
||||
private void Find_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||
{
|
||||
CodeEditBox.SearchPanel.Open();
|
||||
|
||||
}
|
||||
|
||||
@@ -8,15 +8,21 @@ using Progrart.Controls.TabSystem;
|
||||
using Progrart.Dialogs;
|
||||
using Progrart.Icons;
|
||||
using Progrart.Pages;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Progrart.Controls;
|
||||
|
||||
public partial class FileItem : UserControl
|
||||
{
|
||||
IStorageItem currentItem;
|
||||
IStorageItem? currentItem;
|
||||
bool isOpen = false;
|
||||
string extension = "";
|
||||
public FileItem()
|
||||
{
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
public FileItem(IStorageItem storageItem)
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -159,11 +165,18 @@ public partial class FileItem : UserControl
|
||||
{
|
||||
if (page is ITabPage editor)
|
||||
{
|
||||
if (page is IEditorPage editor_page)
|
||||
try
|
||||
{
|
||||
editor_page.LoadDocument(file);
|
||||
if (page is IEditorPage editor_page)
|
||||
{
|
||||
editor_page.LoadDocument(file);
|
||||
}
|
||||
EditorProvider.OpenEditor(editor);
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Trace.WriteLine(e);
|
||||
}
|
||||
EditorProvider.OpenEditor(editor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,20 @@ public partial class TabButton : UserControl
|
||||
{
|
||||
public string? Title { get => MainButton.Content as string; set => MainButton.Content = value; }
|
||||
public string? TooltipText { get => ToolTip.GetTip(MainButton) as string; set => ToolTip.SetTip(MainButton, value); }
|
||||
public ITabPage page;
|
||||
public TabHost Host;
|
||||
public ITabPage? page=null;
|
||||
public TabHost? Host=null;
|
||||
public TabButton()
|
||||
{
|
||||
InitializeComponent();
|
||||
MainButton.Click += (_, _) =>
|
||||
{
|
||||
Host?.SelectButton(this);
|
||||
};
|
||||
CloseButton.Click += (_, _) =>
|
||||
{
|
||||
Host?.RemoveButton(this);
|
||||
};
|
||||
}
|
||||
public TabButton(ITabPage page, TabHost host)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
@@ -11,6 +11,7 @@ using Progrart.Core.Storage;
|
||||
using Progrart.Pages;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -111,14 +112,28 @@ public partial class ProgrartEditorPage : UserControl, ITabPage, IEditorPage
|
||||
Trace.WriteLine($"File:{file.TryGetLocalPath() ?? "null"}");
|
||||
Task.Run(async () =>
|
||||
{
|
||||
using var stream = await file.OpenReadAsync();
|
||||
using StreamReader sr = new StreamReader(stream);
|
||||
var text = await sr.ReadToEndAsync();
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
try
|
||||
{
|
||||
CodeEditor.Text = text;
|
||||
lastSave = text;
|
||||
});
|
||||
using var stream = await file.OpenReadAsync();
|
||||
using StreamReader sr = new StreamReader(stream);
|
||||
var text = await sr.ReadToEndAsync();
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
CodeEditor.Text = text;
|
||||
lastSave = text;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Trace.WriteLine(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Trace.WriteLine(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,38 +1,39 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AvaloniaResource Include="Assets\**" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<TrimmerRootAssembly Include="Progrart" />
|
||||
<AvaloniaResource Include="Assets\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Assets\Styles\JavaScript.xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Remove="Assets\Styles\JavaScript.xml" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia" />
|
||||
<PackageReference Include="Avalonia.AvaloniaEdit" />
|
||||
<PackageReference Include="Avalonia.Themes.Fluent" />
|
||||
<PackageReference Include="Avalonia.Fonts.Inter" />
|
||||
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
|
||||
<PackageReference Include="Avalonia.Diagnostics">
|
||||
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
|
||||
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="AvaloniaEdit.TextMate" />
|
||||
<PackageReference Include="Deadpikle.AvaloniaProgressRing" />
|
||||
<PackageReference Include="DialogHost.Avalonia" />
|
||||
<PackageReference Include="PanAndZoom" />
|
||||
<!--<PackageReference Include="Devolutions.AvaloniaTheme.DevExpress" />
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia" />
|
||||
<PackageReference Include="Avalonia.AvaloniaEdit" />
|
||||
<PackageReference Include="Avalonia.Themes.Fluent" />
|
||||
<PackageReference Include="Avalonia.Fonts.Inter" />
|
||||
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
|
||||
<PackageReference Include="Avalonia.Diagnostics">
|
||||
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
|
||||
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="AvaloniaEdit.TextMate" />
|
||||
<PackageReference Include="Deadpikle.AvaloniaProgressRing" />
|
||||
<PackageReference Include="DialogHost.Avalonia" />
|
||||
<PackageReference Include="PanAndZoom" />
|
||||
<!--<PackageReference Include="Devolutions.AvaloniaTheme.DevExpress" />
|
||||
<PackageReference Include="Devolutions.AvaloniaTheme.MacOS" />-->
|
||||
</ItemGroup>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Progrart.Core\Progrart.Core.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Progrart.Core\Progrart.Core.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user