Save All is now working.
Size is now a relative value in Line.
This commit is contained in:
@@ -77,7 +77,7 @@ namespace Progrart.Core.Graphics
|
||||
new SKPaint()
|
||||
{
|
||||
ColorF = Color,
|
||||
StrokeWidth = Size,
|
||||
StrokeWidth = context.TranslateSize(Size),
|
||||
Shader = shader
|
||||
}
|
||||
);
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Diagnostics;
|
||||
|
||||
namespace Progrart.Core.Graphics
|
||||
{
|
||||
public class Rectangle : BaseElement
|
||||
public class Rectangle : BaseElement
|
||||
{
|
||||
|
||||
float StrokeWidth;
|
||||
@@ -78,7 +78,7 @@ namespace Progrart.Core.Graphics
|
||||
new SKPaint()
|
||||
{
|
||||
ColorF = Color,
|
||||
StrokeWidth = StrokeWidth,
|
||||
StrokeWidth = context.TranslateSize(StrokeWidth),
|
||||
Shader = shader
|
||||
}
|
||||
);
|
||||
|
||||
@@ -82,7 +82,11 @@ namespace Progrart.Core.JSExecution
|
||||
{
|
||||
height = (float)(js_height.AsNumber());
|
||||
}
|
||||
RenderContext renderContext = new RenderContext((int)(width * Scale), (int)(width * Scale));
|
||||
RenderContext renderContext = new RenderContext((int)(width * Scale), (int)(width * Scale))
|
||||
{
|
||||
LogicalW = width,
|
||||
LogicalH = height
|
||||
};
|
||||
ImageRoot imageRoot = new ImageRoot();
|
||||
|
||||
var img = engine.Engine.Call("main");
|
||||
|
||||
@@ -8,6 +8,8 @@ namespace Progrart.Core
|
||||
public PrimitiveDrawingCore DrawingCore { get; }
|
||||
|
||||
public SKCanvas canvas { get => DrawingCore.canvas; }
|
||||
public float LogicalW;
|
||||
public float LogicalH;
|
||||
public RenderContext(PrimitiveDrawingCore core)
|
||||
{
|
||||
this.DrawingCore = core;
|
||||
@@ -20,6 +22,10 @@ namespace Progrart.Core
|
||||
{
|
||||
return TranslatePoint(point.X, point.Y);
|
||||
}
|
||||
public float TranslateSize(float s)
|
||||
{
|
||||
return (float)(s * Math.Sqrt(DrawingCore.Width * DrawingCore.Width + DrawingCore.Height * DrawingCore.Height)/ Math.Sqrt(LogicalH * LogicalH + LogicalW * LogicalW));
|
||||
}
|
||||
public RenderContext(int W, int H)
|
||||
{
|
||||
DrawingCore = new PrimitiveDrawingCore(W, H);
|
||||
|
||||
@@ -6,6 +6,7 @@ using AvaloniaEdit;
|
||||
using AvaloniaEdit.TextMate;
|
||||
using Progrart.Commands;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using TextMateSharp.Grammars;
|
||||
|
||||
@@ -20,7 +21,7 @@ public partial class BaseEditor : UserControl
|
||||
get => CodeEditBox.Text;
|
||||
set => CodeEditBox.Text = value;
|
||||
}
|
||||
public Action? onSaveCmd;
|
||||
public Func<Task>? onSaveCmd;
|
||||
public BaseEditor()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -35,14 +36,15 @@ public partial class BaseEditor : UserControl
|
||||
var saveBinding = new KeyBinding
|
||||
{
|
||||
Gesture = new KeyGesture(Key.S, KeyModifiers.Control),
|
||||
Command = new GenericCommand() { onExecute = (_) => Save() }
|
||||
Command = new GenericCommand() { onExecute = (_) => Task.Run(Save) }
|
||||
};
|
||||
|
||||
CodeEditBox.KeyBindings.Add(saveBinding);
|
||||
}
|
||||
void Save()
|
||||
async Task Save()
|
||||
{
|
||||
onSaveCmd?.Invoke();
|
||||
if (onSaveCmd is not null)
|
||||
await onSaveCmd.Invoke();
|
||||
}
|
||||
public void SetGrammerByExtension(string extension_name)
|
||||
{
|
||||
|
||||
@@ -3,6 +3,8 @@ using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Platform.Storage;
|
||||
using Progrart.Pages;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Progrart.Controls.TabSystem;
|
||||
|
||||
@@ -43,6 +45,16 @@ public partial class TabHost : UserControl
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public async Task Foreach(Func<ITabPage, Task<bool>> handler)
|
||||
{
|
||||
foreach (var item in PageContainer.Children)
|
||||
{
|
||||
if (item is ITabPage page)
|
||||
{
|
||||
if (await handler(page)) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void SelectButton(TabButton button)
|
||||
{
|
||||
foreach (var item in TabContainer.Children)
|
||||
|
||||
@@ -21,7 +21,6 @@ public partial class EditorPage : UserControl, ITabPage, IEditorPage
|
||||
public EditorPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
}
|
||||
|
||||
public bool IsSameFile(IStorageFile file)
|
||||
@@ -78,7 +77,7 @@ public partial class EditorPage : UserControl, ITabPage, IEditorPage
|
||||
});
|
||||
}
|
||||
|
||||
public void Save()
|
||||
public async Task Save()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Progrart.Pages
|
||||
{
|
||||
@@ -63,7 +64,7 @@ namespace Progrart.Pages
|
||||
public interface IEditorPage
|
||||
{
|
||||
void LoadDocument(IStorageFile file);
|
||||
void Save();
|
||||
Task Save();
|
||||
bool IsSameFile(IStorageFile file);
|
||||
void Execute(ExecuteArguments? args = null);
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public partial class ImageViewPage : UserControl, ITabPage, IEditorPage
|
||||
});
|
||||
}
|
||||
|
||||
public void Save()
|
||||
public async Task Save()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -109,12 +109,13 @@ public partial class ProgrartEditorPage : UserControl, ITabPage, IEditorPage
|
||||
});
|
||||
}
|
||||
|
||||
public void Save()
|
||||
public async Task Save()
|
||||
{
|
||||
if (file is not null)
|
||||
{
|
||||
string content = CodeEditor.Text;
|
||||
Task.Run(async () =>
|
||||
string content = "";
|
||||
await Dispatcher.UIThread.InvokeAsync(() => { content = CodeEditor.Text; });
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
using var stream = await file.OpenWriteAsync();
|
||||
stream.SetLength(0);
|
||||
|
||||
@@ -44,7 +44,8 @@
|
||||
<MenuItem Header="_Open">
|
||||
<MenuItem Header="_Project" Name="OpenProjectMenuItem"/>
|
||||
</MenuItem>
|
||||
<MenuItem Header="_Save"/>
|
||||
<MenuItem Header="_Save" Click="MenuItem_Save_Click"/>
|
||||
<MenuItem Header="Save A_ll" Click="MenuItem_SaveAll_Click"/>
|
||||
<MenuItem Header="Save _As"/>
|
||||
</MenuItem>
|
||||
<MenuItem Header="_Tools">
|
||||
|
||||
@@ -9,6 +9,7 @@ using Progrart.Core.JSExecution;
|
||||
using Progrart.Pages;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Progrart.Views;
|
||||
|
||||
@@ -108,23 +109,23 @@ public partial class MainView : UserControl
|
||||
};
|
||||
LeftPanelToggle.IsChecked = true;
|
||||
RunButton.Click += (_, _) =>
|
||||
{
|
||||
Execute();
|
||||
};
|
||||
{
|
||||
Execute();
|
||||
};
|
||||
}
|
||||
|
||||
private void Execute()
|
||||
{
|
||||
if (MainTabHost.GetCurrentPage() is IEditorPage editor)
|
||||
{
|
||||
ExecuteArguments args = new ExecuteArguments();
|
||||
args.data["Scale"] = $"{SizeBox.Value}";
|
||||
args.data["Debug"] = $"{IsDebugBox.IsChecked ?? false}".ToLower();
|
||||
editor.Execute(args);
|
||||
}
|
||||
}
|
||||
private void Execute()
|
||||
{
|
||||
if (MainTabHost.GetCurrentPage() is IEditorPage editor)
|
||||
{
|
||||
ExecuteArguments args = new ExecuteArguments();
|
||||
args.data["Scale"] = $"{SizeBox.Value}";
|
||||
args.data["Debug"] = $"{IsDebugBox.IsChecked ?? false}".ToLower();
|
||||
editor.Execute(args);
|
||||
}
|
||||
}
|
||||
|
||||
private void OutputClear_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||
private void OutputClear_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||
{
|
||||
Output.Text = "";
|
||||
}
|
||||
@@ -161,4 +162,19 @@ public partial class MainView : UserControl
|
||||
editor.Save();
|
||||
}
|
||||
}
|
||||
|
||||
private void MenuItem_Save_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||
{
|
||||
if (MainTabHost.GetCurrentPage() is IEditorPage editor) Task.Run(async () => await editor.Save());
|
||||
}
|
||||
|
||||
private void MenuItem_SaveAll_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||
{
|
||||
Task.Run(async () => await MainTabHost.Foreach(async (page) =>
|
||||
{
|
||||
if (page is IEditorPage editor)
|
||||
await editor.Save();
|
||||
return false;
|
||||
}));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user