45 lines
1.8 KiB
C#
45 lines
1.8 KiB
C#
using PLCSharp.Models;
|
|
using System.Threading;
|
|
using System.Windows;
|
|
|
|
namespace PLCSharp.VVMs.Workflows;
|
|
|
|
public partial class ScriptReviewWindow : Window
|
|
{
|
|
private ScriptReviewWindow(ProjectChange change, string root)
|
|
{
|
|
InitializeComponent();
|
|
WorkflowTitle.Text = $"工作流 · {change.Name}";
|
|
Location.Text = System.IO.Path.Combine(root, change.Path);
|
|
CheckResult.Text = string.Join("\n", new[] { "编译通过(仅检查,未运行)" }.Concat(
|
|
change.Review.Diagnostics.Select(d => $"{d.Code} ({d.Line},{d.Column}) {d.Message}")));
|
|
CodeDiff.Text = change.Review.Diff;
|
|
Loaded += (_, _) => CancelChange.Focus();
|
|
}
|
|
|
|
private void Approve(object sender, RoutedEventArgs e) => DialogResult = true;
|
|
|
|
public static bool Confirm(ProjectChange change, string root, Window owner)
|
|
{
|
|
var window = new ScriptReviewWindow(change, root);
|
|
if (owner != null) { window.Owner = owner; window.WindowStartupLocation = WindowStartupLocation.CenterOwner; }
|
|
return window.ShowDialog() == true;
|
|
}
|
|
|
|
public static bool ConfirmOffline(ProjectChange change, string root)
|
|
{
|
|
if (!Environment.UserInteractive) throw new InvalidOperationException("脚本保存需要交互式 Windows 桌面。");
|
|
var result = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
|
|
var thread = new Thread(() =>
|
|
{
|
|
try { result.SetResult(Confirm(change, root, null)); }
|
|
catch (Exception ex) { result.SetException(ex); }
|
|
finally { System.Windows.Threading.Dispatcher.CurrentDispatcher.InvokeShutdown(); }
|
|
}) { IsBackground = true };
|
|
thread.SetApartmentState(ApartmentState.STA);
|
|
thread.Start();
|
|
return result.Task.GetAwaiter().GetResult();
|
|
}
|
|
}
|
|
|