V18 / 8d896b8a86e5
ApprovalWindow.cs
Interfaces/Gui/LilithDesktop/ApprovalWindow.cs
Unchanged from the preceding versionCS
using System.Text.Json;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace Lilith.Desktop;
internal sealed class ApprovalWindow : Window
{
internal ApprovalWindow(Window owner,JsonElement proposal,Func<bool,Task> decide)
{
Owner=owner;Title="Lilith — Review approval";Width=720;Height=640;MinWidth=420;MinHeight=350;
WindowStartupLocation=WindowStartupLocation.CenterOwner;Background=new SolidColorBrush(Color.FromRgb(11,16,14));Foreground=Brushes.White;
var layout=new DockPanel{Margin=new Thickness(24)};Content=layout;
var heading=new TextBlock{Text=proposal.GetProperty("Title").GetString(),FontSize=23,Foreground=new SolidColorBrush(Color.FromRgb(214,246,117)),Margin=new Thickness(0,0,0,16)};
DockPanel.SetDock(heading,Dock.Top);layout.Children.Add(heading);
var footer=new StackPanel{Margin=new Thickness(0,16,0,0)};DockPanel.SetDock(footer,Dock.Bottom);layout.Children.Add(footer);
var status=new TextBlock{Text="Review the exact prepared change before deciding. Closing this window leaves it pending.",TextWrapping=TextWrapping.Wrap,Margin=new Thickness(0,0,0,12)};footer.Children.Add(status);
var actions=new StackPanel{Orientation=Orientation.Horizontal};footer.Children.Add(actions);
var approve=new Button{Content="Approve this change",Padding=new Thickness(18,10,18,10),Background=heading.Foreground,Foreground=Brushes.Black};
var reject=new Button{Content="Reject",Padding=new Thickness(18,10,18,10),Margin=new Thickness(12,0,0,0)};actions.Children.Add(approve);actions.Children.Add(reject);
var review=new TextBox{Text=JsonSerializer.Serialize(proposal.GetProperty("Review"),new JsonSerializerOptions{WriteIndented=true}),IsReadOnly=true,TextWrapping=TextWrapping.Wrap,VerticalScrollBarVisibility=ScrollBarVisibility.Auto,Background=new SolidColorBrush(Color.FromRgb(17,24,20)),Foreground=Brushes.White,FontFamily=new FontFamily("Consolas"),Padding=new Thickness(14)};layout.Children.Add(review);
bool working=false;
async Task Decide(bool yes)
{
if(working)return;working=true;approve.IsEnabled=reject.IsEnabled=false;status.Text="Applying your decision…";
try{await decide(yes);working=false;Close();}
catch(Exception ex){status.Text=ex.Message;working=false;approve.IsEnabled=reject.IsEnabled=true;}
}
approve.Click+=async(_,_)=>await Decide(true);reject.Click+=async(_,_)=>await Decide(false);
Closing+=(_,e)=>{if(working)e.Cancel=true;};
}
}