All checks were successful
Release AstroFrame / packages (push) Successful in 56s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
340 lines
42 KiB
C#
340 lines
42 KiB
C#
using AstroFrame.Engine;
|
|
using Avalonia;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Controls.Templates;
|
|
using Avalonia.Input;
|
|
using Avalonia.Layout;
|
|
using Avalonia.Media;
|
|
using Avalonia.Platform.Storage;
|
|
using Avalonia.Threading;
|
|
using Avalonia.Styling;
|
|
using Avalonia.VisualTree;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
|
|
namespace AstroFrame.Desktop;
|
|
public sealed partial class MainWindow:Window
|
|
{
|
|
Project? project;string projectDirectory="";CancellationTokenSource? cancellation;bool busy,refreshing,saving;
|
|
readonly SemaphoreSlim saveGate=new(1);
|
|
readonly ComboBox sessions=new(){Width=380,MinWidth=290,HorizontalAlignment=HorizontalAlignment.Left};
|
|
readonly ListBox frames=new();
|
|
readonly ComboBox filter=new(){ItemsSource=new[]{"All decisions","REVIEW","REJECT","KEEP","Manual decisions"},SelectedIndex=0,MinWidth=135};
|
|
readonly ComboBox sort=new(){ItemsSource=new[]{"Capture time","Most concerning","Lowest star count","Lowest stellar flux","Highest FWHM"},SelectedIndex=0,MinWidth=155};
|
|
readonly ComboBox metric=new(){ItemsSource=QualityChart.Metrics.Select(x=>x.Name).ToArray(),SelectedIndex=0,MinWidth=145};
|
|
readonly QualityChart chart=new();
|
|
readonly PreviewViewport viewport=new();
|
|
readonly ExposureView preview,comparison;
|
|
readonly Button resetView=Button("Reset view");
|
|
readonly Button inspectElongation=Button("Inspect elongation");
|
|
readonly DispatcherTimer memoryTimer=new(){Interval=TimeSpan.FromSeconds(1)};
|
|
StarInspector? starInspector;
|
|
readonly Border previewPanel,comparisonBorder,previewControls;
|
|
readonly ComboBox previewMode=new(){ItemsSource=new[]{"Frame view","Denoised"},SelectedIndex=0,MinWidth=150};
|
|
readonly Slider displayStretch=new(){Minimum=.08,Maximum=.40,Value=.18};
|
|
readonly StackPanel inspector=new(){Spacing=9};
|
|
readonly Grid previewWorkspace=new(){ColumnDefinitions=new("*,0"),Margin=new(0,8,0,6)};
|
|
readonly Border details=new();
|
|
readonly TextBlock queueTitle=Palette.Label("Exposures",14),position=Palette.Label("",11,Palette.Muted),stretchValue=Palette.Label("0.18",11,Palette.Muted);
|
|
readonly TextBlock exposureName=Palette.Label("",11,Palette.Muted),exposureStatus=Palette.Label("",12);
|
|
readonly TextBlock title=Palette.Label("Light frames",18),subtitle=Palette.Label("Choose a folder to begin",11,Palette.Muted);
|
|
readonly TextBlock status=Palette.Label("",11,Palette.Muted);
|
|
readonly TextBlock memoryUsage=Palette.Label("",11,Palette.Muted);
|
|
readonly TextBlock keep=Palette.Label("—",22,Palette.Keep),review=Palette.Label("—",22,Palette.Review),reject=Palette.Label("—",22,Palette.Reject),integration=Palette.Label("—",22);
|
|
readonly TextBlock keepTime=Palette.Label("",11,Palette.Muted),reviewTime=Palette.Label("",11,Palette.Muted),rejectTime=Palette.Label("",11,Palette.Muted),totalTime=Palette.Label("",11,Palette.Muted);
|
|
readonly ProgressBar progress=new(){Height=5,Minimum=0,Maximum=100,IsVisible=false,Foreground=Palette.Progress,Background=Palette.Line};
|
|
readonly Button analyze=Button("Analyze lights",true),export=Button("Export accepted"),stop=Button("Cancel");
|
|
readonly CheckBox spatial=new(){Content="Spatial overlay",FontSize=12},compare=new(){Content="Compare nearby",FontSize=12};
|
|
// Not persisted: each launch starts comparing against the nearby exposure.
|
|
readonly ComboBox compareTarget=new(){ItemsSource=new[]{"Nearby frame","Best frame"},SelectedIndex=0,MinWidth=120,FontSize=11,IsVisible=false,Margin=new(10,0,0,0)};
|
|
Frame? selected;List<Frame> visible=[];
|
|
readonly Stack<(Frame Frame,Verdict? Verdict,string Note,DateTime? At)> undo=[];
|
|
public MainWindow()
|
|
{
|
|
Background=TransparencyBackgroundFallback=Palette.Background;
|
|
NativeWindowBackground.Apply(this);
|
|
preview=new(viewport);comparison=new(viewport);
|
|
previewPanel=Panel(preview);comparisonBorder=Panel(comparison);
|
|
var displayPanel=new Grid{RowDefinitions=new("Auto,48")};var stretchHeading=new Grid{ColumnDefinitions=new("*,Auto")};stretchHeading.Children.Add(Palette.Label("Preview stretch",11,Palette.Muted));Grid.SetColumn(stretchValue,1);stretchHeading.Children.Add(stretchValue);displayPanel.Children.Add(stretchHeading);
|
|
var stretchRow=new Grid{ColumnDefinitions=new("*,Auto")};displayStretch.MinHeight=44;displayStretch.VerticalAlignment=VerticalAlignment.Center;displayStretch.Margin=new(0,0,12,0);stretchRow.Children.Add(displayStretch);
|
|
var resetStretch=Button("Reset");resetStretch.Padding=new(9,5);resetStretch.FontSize=11;resetStretch.VerticalAlignment=VerticalAlignment.Center;resetStretch.Click+=(_,_)=>displayStretch.Value=.18;Grid.SetColumn(resetStretch,1);stretchRow.Children.Add(resetStretch);Grid.SetRow(stretchRow,1);displayPanel.Children.Add(stretchRow);previewControls=new(){Child=displayPanel};
|
|
// Keep the native slider's input behavior; give its thumb a visible silver face and room for the full circle.
|
|
Styles.Add(new Style(x=>x.OfType<Slider>().Template().OfType<Avalonia.Controls.Primitives.Thumb>()){Setters={new Setter(Avalonia.Controls.Primitives.TemplatedControl.TemplateProperty,new FuncControlTemplate<Avalonia.Controls.Primitives.Thumb>((_,_)=>new Border{Width=20,Height=20,CornerRadius=new(10),Background=Palette.Accent,BorderBrush=Palette.Panel,BorderThickness=new(3),HorizontalAlignment=HorizontalAlignment.Center,VerticalAlignment=VerticalAlignment.Center}))}});
|
|
previewMode.SelectionChanged+=(_,_)=>{preview.SetMode((PreviewMode)Math.Max(0,previewMode.SelectedIndex));comparison.SetMode((PreviewMode)Math.Max(0,previewMode.SelectedIndex));};
|
|
ToolTip.SetTip(previewMode,"Frame: original grayscale preview. Denoised: reduce preview noise while keeping the original stretch parameters. Display options do not change analysis.");
|
|
displayStretch.PropertyChanged+=(_,e)=>{if(e.Property==Slider.ValueProperty){stretchValue.Text=displayStretch.Value.ToString("0.00");preview.Stretch=comparison.Stretch=displayStretch.Value;preview.RefreshDisplay();comparison.RefreshDisplay();}};
|
|
Title="AstroFrame";Width=1450;Height=940;MinWidth=1120;MinHeight=740;Background=Palette.Background;FontFamily="Inter";FontSize=13;
|
|
ExtendClientAreaToDecorationsHint=true;ExtendClientAreaChromeHints=Avalonia.Platform.ExtendClientAreaChromeHints.PreferSystemChrome;ExtendClientAreaTitleBarHeightHint=36;
|
|
Icon=new WindowIcon(Avalonia.Platform.AssetLoader.Open(new Uri("avares://AstroFrame.Desktop/Assets/astroframe.ico")));
|
|
var root=new Grid{RowDefinitions=new("Auto,Auto,*,Auto")};
|
|
var headerSurface=new Grid{RowDefinitions=new("36,38"),Background=Palette.Background};root.Children.Add(headerSurface);
|
|
var titlebar=new Grid{ColumnDefinitions=new("Auto,*"),Background=Brushes.Transparent,Margin=new(18,0,145,0)};
|
|
Win32Properties.SetNonClientHitTestResult(titlebar,Win32Properties.Win32HitTestValue.Caption);
|
|
titlebar.Children.Add(new Image{Source=new Avalonia.Media.Imaging.Bitmap(Avalonia.Platform.AssetLoader.Open(new Uri("avares://AstroFrame.Desktop/Assets/astroframe.png"))),Width=24,Height=24});
|
|
var brand=Palette.Label("AstroFrame",13);brand.FontWeight=FontWeight.SemiBold;brand.Margin=new(9,0,0,0);brand.VerticalAlignment=VerticalAlignment.Center;Grid.SetColumn(brand,1);titlebar.Children.Add(brand);
|
|
titlebar.PointerPressed+=(_,e)=>{if(e.GetCurrentPoint(this).Properties.IsLeftButtonPressed){if(e.ClickCount==2)WindowState=WindowState==WindowState.Maximized?WindowState.Normal:WindowState.Maximized;else BeginMoveDrag(e);e.Handled=true;}};
|
|
headerSurface.Children.Add(titlebar);
|
|
var header=new Grid{ColumnDefinitions=new("*,Auto"),Margin=new(22,0,22,2)};Grid.SetRow(header,1);
|
|
var heading=new StackPanel{Orientation=Orientation.Horizontal,Spacing=12,VerticalAlignment=VerticalAlignment.Center};title.MinWidth=140;title.MaxWidth=330;title.TextTrimming=TextTrimming.CharacterEllipsis;title.VerticalAlignment=subtitle.VerticalAlignment=VerticalAlignment.Center;heading.Children.Add(title);heading.Children.Add(subtitle);header.Children.Add(heading);
|
|
var toolbar=new WrapPanel{Orientation=Orientation.Horizontal,HorizontalAlignment=HorizontalAlignment.Right,VerticalAlignment=VerticalAlignment.Center};
|
|
foreach(var b in new[]{analyze,export,settingsButton}){b.Margin=new(8,1,0,1);toolbar.Children.Add(b);}Grid.SetColumn(toolbar,1);header.Children.Add(toolbar);headerSurface.Children.Add(header);
|
|
var scope=new Grid{ColumnDefinitions=new("*,Auto"),Margin=new(20,7,20,7)};
|
|
sessions.ItemTemplate=new FuncDataTemplate<string>((text,_)=>SessionRow(text??""));sessions.SelectionChanged+=(_,_)=>{if(!refreshing)RefreshFrames();};scope.Children.Add(sessions);
|
|
var stats=new StackPanel{Orientation=Orientation.Horizontal,Spacing=28,VerticalAlignment=VerticalAlignment.Center};
|
|
foreach(var item in new[]{Summary("KEEP",keep,keepTime),Summary("REVIEW",review,reviewTime),Summary("REJECT",reject,rejectTime),Summary("ACCEPTED TIME",integration,totalTime)})stats.Children.Add(item);
|
|
Grid.SetColumn(stats,1);scope.Children.Add(stats);var scopeBorder=new Border{BorderBrush=Palette.Line,BorderThickness=new(0,1,0,1),Child=scope};Grid.SetRow(scopeBorder,1);root.Children.Add(scopeBorder);
|
|
var body=new Grid{ColumnDefinitions=new("280,1.27*,1*"),Margin=new(18,16,18,0)};Grid.SetRow(body,2);
|
|
var queue=new Grid{RowDefinitions=new("Auto,Auto,Auto,*")};
|
|
queueTitle.Margin=new(12,12,12,10);queue.Children.Add(queueTitle);
|
|
var listControls=new StackPanel{Spacing=6,Margin=new(12,0,12,8)};filter.MinWidth=128;filter.FontSize=11;filter.HorizontalAlignment=HorizontalAlignment.Stretch;listControls.Children.Add(filter);
|
|
sort.HorizontalAlignment=HorizontalAlignment.Stretch;sort.FontSize=11;listControls.Children.Add(sort);Grid.SetRow(listControls,1);queue.Children.Add(listControls);
|
|
var columns=new Grid{ColumnDefinitions=new("*,61,48,44"),Margin=new(14,8,14,8)};int ci=0;foreach(string label in new[]{"Time (UTC)","Decision","Stars","FWHM"}){var text=Palette.Label(label,10,Palette.Muted);if(ci>1)text.HorizontalAlignment=HorizontalAlignment.Right;Grid.SetColumn(text,ci++);columns.Children.Add(text);}Grid.SetRow(columns,2);queue.Children.Add(columns);
|
|
frames.Background=Brushes.Transparent;frames.Padding=new(0);frames.ItemTemplate=new FuncDataTemplate<Frame>((f,_)=>f==null?new Border():FrameRow(f));frames.SelectionChanged+=(_,_)=>{if(!refreshing&&frames.SelectedItem is Frame f)Select(f);};Grid.SetRow(frames,3);queue.Children.Add(frames);var queuePanel=Panel(queue);queuePanel.Margin=new(0,0,16,0);body.Children.Add(queuePanel);
|
|
var center=new Grid{RowDefinitions=new("Auto,Auto,*,Auto,Auto,Auto"),Margin=new(0,0,16,0),MinWidth=310};Grid.SetColumn(center,1);body.Children.Add(center);
|
|
var previewHeading=new Grid{ColumnDefinitions=new("*,Auto"),RowDefinitions=new("Auto,Auto"),Margin=new(0,6,0,8)};previewHeading.Children.Add(Palette.Label("Exposure preview",14));position.HorizontalAlignment=HorizontalAlignment.Right;position.VerticalAlignment=VerticalAlignment.Center;Grid.SetColumn(position,1);previewHeading.Children.Add(position);
|
|
var previewActions=new WrapPanel{Margin=new(0,8,0,0)};
|
|
resetView.Padding=new(9,5);resetView.FontSize=11;resetView.Click+=(_,_)=>viewport.Reset();ToolTip.SetTip(resetView,"Reset image zoom and position");previewActions.Children.Add(resetView);
|
|
inspectElongation.Padding=new(9,5);inspectElongation.FontSize=11;inspectElongation.Margin=new(8,0,0,0);inspectElongation.IsEnabled=false;inspectElongation.Click+=(_,_)=>ShowElongation();ToolTip.SetTip(inspectElongation,"Enlarge source stars and highlight their shape, with a matched KEEP frame when available");previewActions.Children.Add(inspectElongation);Grid.SetRow(previewActions,1);Grid.SetColumnSpan(previewActions,2);previewHeading.Children.Add(previewActions);center.Children.Add(previewHeading);
|
|
var viewRow=new Grid{ColumnDefinitions=new("Auto,*,Auto")};previewMode.MinWidth=125;previewMode.FontSize=11;viewRow.Children.Add(previewMode);var switches=new StackPanel{Orientation=Orientation.Horizontal,VerticalAlignment=VerticalAlignment.Center};spatial.Content="Overlay";compare.Content="Compare";spatial.Margin=new(0,0,12,0);switches.Children.Add(spatial);switches.Children.Add(compare);switches.Children.Add(compareTarget);Grid.SetColumn(switches,2);viewRow.Children.Add(switches);Grid.SetRow(viewRow,1);center.Children.Add(viewRow);
|
|
previewWorkspace.Children.Add(previewPanel);Grid.SetColumn(comparisonBorder,1);previewWorkspace.Children.Add(comparisonBorder);comparisonBorder.IsVisible=false;Grid.SetRow(previewWorkspace,2);center.Children.Add(previewWorkspace);
|
|
Grid.SetRow(previewControls,3);center.Children.Add(previewControls);
|
|
var caption=new StackPanel{Spacing=4,Margin=new(0,0,0,12)};exposureName.TextTrimming=TextTrimming.CharacterEllipsis;caption.Children.Add(exposureName);caption.Children.Add(exposureStatus);Grid.SetRow(caption,4);center.Children.Add(caption);
|
|
var decisions=new Grid{ColumnDefinitions=new("*,*,*,Auto")};int decisionColumn=0;
|
|
foreach(var verdict in new[]{Verdict.Keep,Verdict.Review,Verdict.Reject}){var b=Button(verdict.ToString());b.Foreground=Palette.Verdict(verdict);b.Margin=new(0,0,6,0);b.HorizontalAlignment=HorizontalAlignment.Stretch;ToolTip.SetTip(b,$"{verdict} · {(int)verdict+1}");b.Click+=async(_,_)=>await Override(verdict);Grid.SetColumn(b,decisionColumn++);decisions.Children.Add(b);}var resetDecision=Button("Reset");resetDecision.Click+=async(_,_)=>await Override(null,false);Grid.SetColumn(resetDecision,3);decisions.Children.Add(resetDecision);Grid.SetRow(decisions,5);center.Children.Add(decisions);
|
|
var right=new Grid{RowDefinitions=new("2*,3*"),MinWidth=320};Grid.SetColumn(right,2);body.Children.Add(right);
|
|
var graphs=new Grid{RowDefinitions=new("Auto,*"),Margin=new(12)};var graphHeader=new Grid{ColumnDefinitions=new("*,Auto"),Margin=new(0,0,0,8)};var graphTitle=Palette.Label("Quality",14);graphTitle.VerticalAlignment=VerticalAlignment.Center;graphHeader.Children.Add(graphTitle);metric.MaxWidth=205;metric.FontSize=11;Grid.SetColumn(metric,1);graphHeader.Children.Add(metric);graphs.Children.Add(graphHeader);Grid.SetRow(chart,1);graphs.Children.Add(chart);var graphPanel=Panel(graphs);graphPanel.Margin=new(0,0,0,14);right.Children.Add(graphPanel);
|
|
inspector.Margin=new(14);details.Child=new ScrollViewer{Content=inspector,HorizontalScrollBarVisibility=Avalonia.Controls.Primitives.ScrollBarVisibility.Disabled};details.Background=Palette.Panel;details.BorderBrush=Palette.Line;details.BorderThickness=new(.5);details.CornerRadius=new(2);Grid.SetRow(details,1);right.Children.Add(details);root.Children.Add(body);
|
|
var footer=new Grid{RowDefinitions=new("Auto,Auto"),Margin=new(20,7,20,7)};footer.Children.Add(progress);var footerLine=new Grid{ColumnDefinitions=new("*,Auto,Auto")};status.TextTrimming=TextTrimming.CharacterEllipsis;status.VerticalAlignment=VerticalAlignment.Center;footerLine.Children.Add(status);memoryUsage.IsVisible=false;memoryUsage.Margin=new(14,0,14,0);memoryUsage.VerticalAlignment=VerticalAlignment.Center;ToolTip.SetTip(memoryUsage,"AstroFrame process RAM currently resident in physical memory");Grid.SetColumn(memoryUsage,1);footerLine.Children.Add(memoryUsage);stop.IsVisible=false;Grid.SetColumn(stop,2);footerLine.Children.Add(stop);Grid.SetRow(footerLine,1);footer.Children.Add(footerLine);Grid.SetRow(footer,3);root.Children.Add(footer);Content=root;
|
|
memoryTimer.Tick+=(_,_)=>UpdateMemoryUsage();
|
|
analyze.Click+=async(_,_)=>await Analyze();export.Click+=async(_,_)=>await ExportAccepted();stop.Click+=(_,_)=>cancellation?.Cancel();
|
|
filter.SelectionChanged+=(_,_)=>{if(!refreshing)RefreshFrames();};sort.SelectionChanged+=(_,_)=>{if(!refreshing)RefreshFrames();};metric.SelectionChanged+=(_,_)=>{chart.Metric=QualityChart.Metrics[Math.Max(0,metric.SelectedIndex)];chart.InvalidateVisual();};
|
|
chart.FrameClicked+=f=>{if(!visible.Contains(f))filter.SelectedIndex=0;frames.SelectedItem=f;frames.ScrollIntoView(f);Select(f);};
|
|
spatial.IsCheckedChanged+=(_,_)=>{preview.Spatial=comparison.Spatial=spatial.IsChecked==true;preview.InvalidateVisual();comparison.InvalidateVisual();};compare.IsCheckedChanged+=(_,_)=>UpdateComparison();compareTarget.SelectionChanged+=(_,_)=>UpdateComparison();
|
|
ToolTip.SetTip(spatial,"Pink shows the strongest excess sky brightness against the clean session reference, excluding weak background residuals. Grid colors show regional stellar flux. This is supporting evidence, not an exact cloud boundary.");
|
|
KeyDown+=async(_,e)=>
|
|
{
|
|
if(busy||updates.Applying||e.Source is TextBox)return;
|
|
if(e.Key==Key.J){Move(-1);e.Handled=true;}if(e.Key==Key.K){Move(1);e.Handled=true;}
|
|
if(e.Key is Key.D1 or Key.NumPad1){await Override(Verdict.Keep);e.Handled=true;}if(e.Key is Key.D2 or Key.NumPad2){await Override(Verdict.Review);e.Handled=true;}if(e.Key is Key.D3 or Key.NumPad3){await Override(Verdict.Reject);e.Handled=true;}
|
|
if(e.Key==Key.Z&&e.KeyModifiers.HasFlag(KeyModifiers.Control)&&undo.Count>0){var item=undo.Pop();item.Frame.Override=item.Verdict;item.Frame.Note=item.Note;item.Frame.ReviewedAt=item.At;await Save();RefreshFrames(item.Frame);e.Handled=true;}
|
|
};
|
|
Closing+=(_,e)=>{if(busy){e.Cancel=true;cancellation?.Cancel();status.Text="Stopping safely; close again when finished";}};
|
|
Closed+=(_,_)=>{memoryTimer.Stop();starInspector?.Close();preview.Dispose();comparison.Dispose();};ShowEmpty();InitializeUpdates();
|
|
}
|
|
static Button Button(string text,bool primary=false)=>new(){Content=text,Padding=new(12,7),CornerRadius=new(2),Background=primary?Palette.Accent:Palette.Raised,Foreground=primary?Palette.Background:Palette.Text};
|
|
static Border Panel(Control child)=>new(){Background=Palette.Panel,BorderBrush=Palette.Line,BorderThickness=new(.5),CornerRadius=new(2),ClipToBounds=true,Child=child};
|
|
static Control Summary(string label,TextBlock value,TextBlock detail)
|
|
{var s=new StackPanel{Spacing=2};var line=new StackPanel{Orientation=Orientation.Horizontal,Spacing=7};line.Children.Add(value);var caption=Palette.Label(label,9,Palette.Muted);caption.VerticalAlignment=VerticalAlignment.Bottom;caption.Margin=new(0,0,0,4);line.Children.Add(caption);s.Children.Add(line);s.Children.Add(detail);return s;}
|
|
Control SessionRow(string text)
|
|
{
|
|
var parts=text.Split('·',StringSplitOptions.TrimEntries);var s=new StackPanel{Spacing=3,Margin=new(2,2)};s.Children.Add(Palette.Label(parts[0],14));
|
|
if(project!=null){var scoped=project.Frames.Where(f=>text=="All sessions"||f.Session==text).ToArray();string date=parts.Length>1?parts[1]+" UTC · ":"";s.Children.Add(Palette.Label(date+$"{scoped.Length:N0} lights"+(parts.Length>3?" · "+parts[3]:""),10,Palette.Muted));}return s;
|
|
}
|
|
static Control FrameRow(Frame f)
|
|
{
|
|
var g=new Grid{ColumnDefinitions=new("*,61,48,44"),Margin=new(8,13)};var time=new StackPanel{Spacing=3};time.Children.Add(Palette.Label(f.Time.Length>=8?f.Time[^8..]:f.Time,11));time.Children.Add(Palette.Label(f.Time.Length>8?f.Time[..^9]:"",9,Palette.Muted));g.Children.Add(time);
|
|
var badge=Palette.Label(f.Status,10,Palette.Verdict(f.Effective));badge.FontWeight=FontWeight.SemiBold;badge.VerticalAlignment=VerticalAlignment.Center;Grid.SetColumn(badge,1);g.Children.Add(badge);
|
|
var stars=Palette.Label(f.StarCount.ToString("N0"),11);stars.VerticalAlignment=VerticalAlignment.Center;stars.HorizontalAlignment=HorizontalAlignment.Right;Grid.SetColumn(stars,2);g.Children.Add(stars);var width=Palette.Label(f.Fwhm.ToString("0.00"),11,Palette.Muted);width.VerticalAlignment=VerticalAlignment.Center;width.HorizontalAlignment=HorizontalAlignment.Right;Grid.SetColumn(width,3);g.Children.Add(width);ToolTip.SetTip(g,f.Name+(f.Override.HasValue?" · Manual decision":"")+" · "+f.Exposure+" s");return g;
|
|
}
|
|
void ShowEmpty()
|
|
{
|
|
inspector.Children.Clear();inspector.Children.Add(Palette.Label("Analyze a folder of FITS lights to begin.",12,Palette.Muted));
|
|
export.IsEnabled=false;details.IsVisible=false;
|
|
}
|
|
public void LoadProject(string directory)
|
|
{
|
|
project=ProjectStore.Load(directory);projectDirectory=directory;undo.Clear();
|
|
foreach(var f in project.Frames.Where(f=>f.Error==""))
|
|
{var info=new FileInfo(f.Path);if(!info.Exists||info.Length!=f.Length||info.LastWriteTimeUtc.Ticks!=f.Modified){project.Complete=false;f.Warning="Source is missing or changed; reanalyze before export";}}
|
|
int sessionCount=project.Frames.Select(f=>f.Session).Distinct().Count();title.Text=project.Name;subtitle.Text=$"{project.Frames.Count:N0} lights · {sessionCount} "+(sessionCount==1?"session":"sessions");
|
|
refreshing=true;sessions.ItemsSource=new[]{"All sessions"}.Concat(project.Frames.Select(f=>f.Session).Distinct().Order()).ToArray();sessions.SelectedIndex=0;refreshing=false;
|
|
RefreshFrames();status.Text=project.Complete?"":"Incomplete or changed project · reanalyze before exporting";export.IsEnabled=project.Complete;
|
|
// Projects remain saved on disk; each ordinary launch begins with an empty workspace.
|
|
}
|
|
void RefreshFrames(Frame? prefer=null)
|
|
{
|
|
if(project==null)return;refreshing=true;
|
|
var scoped=project.Frames.Where(f=>sessions.SelectedIndex<=0||f.Session==(string?)sessions.SelectedItem).OrderBy(f=>f.Timestamp).ToList();
|
|
keep.Text=scoped.Count(f=>f.Effective==Verdict.Keep).ToString("N0");review.Text=scoped.Count(f=>f.Effective==Verdict.Review).ToString("N0");reject.Text=scoped.Count(f=>f.Effective==Verdict.Reject).ToString("N0");
|
|
string Duration(double seconds)=>TimeSpan.FromSeconds(seconds).TotalHours>=1?$"{seconds/3600:0.0} h":$"{seconds/60:0.0} min";
|
|
keepTime.Text=Duration(scoped.Where(f=>f.Effective==Verdict.Keep).Sum(f=>f.Exposure));reviewTime.Text=Duration(scoped.Where(f=>f.Effective==Verdict.Review).Sum(f=>f.Exposure));rejectTime.Text=Duration(scoped.Where(f=>f.Effective==Verdict.Reject).Sum(f=>f.Exposure));integration.Text=keepTime.Text;totalTime.Text=Duration(scoped.Sum(f=>f.Exposure))+" total";
|
|
chart.Frames=scoped;
|
|
var query=scoped.Where(f=>filter.SelectedIndex switch{1=>f.Effective==Verdict.Review,2=>f.Effective==Verdict.Reject,3=>f.Effective==Verdict.Keep,4=>f.Override!=null,_=>true});
|
|
visible=(sort.SelectedIndex switch{1=>query.OrderBy(f=>f.Score),2=>query.OrderBy(f=>f.StarCount),3=>query.OrderBy(f=>f.Transparency),4=>query.OrderByDescending(f=>f.Fwhm),_=>query.OrderBy(f=>f.Timestamp)}).ToList();
|
|
queueTitle.Text=$"Exposures · {visible.Count:N0}";
|
|
frames.ItemsSource=null;frames.ItemsSource=visible;frames.SelectedItem=prefer!=null&&visible.Contains(prefer)?prefer:visible.FirstOrDefault();refreshing=false;
|
|
if(frames.SelectedItem is Frame f)Select(f);else{selected=null;ShowNoSelection();}
|
|
chart.InvalidateVisual();
|
|
}
|
|
public void CaptureSelection(bool rejected=false)
|
|
{
|
|
if(project==null)return;
|
|
var f=rejected?project.Frames.FirstOrDefault(x=>x.Effective==Verdict.Reject):project.Frames.FirstOrDefault(x=>x.Target.Contains("1432"));
|
|
if(f==null)return;sessions.SelectedItem=f.Session;filter.SelectedIndex=rejected?2:0;spatial.IsChecked=rejected;compare.IsChecked=rejected;frames.SelectedItem=f;Select(f);
|
|
}
|
|
public void CaptureExposure(string filename)
|
|
{
|
|
if(project==null)return;var f=project.Frames.First(x=>x.Name.Contains(filename,StringComparison.OrdinalIgnoreCase));sessions.SelectedItem=f.Session;filter.SelectedIndex=0;spatial.IsChecked=false;compare.IsChecked=false;previewMode.SelectedIndex=0;frames.SelectedItem=f;Select(f);
|
|
}
|
|
public Task WaitForPreviews()=>Task.WhenAll(preview.Loading,comparison.Loading);
|
|
public void CaptureMetric(string name)
|
|
{
|
|
int index=Array.FindIndex(QualityChart.Metrics,m=>m.Name==name);
|
|
if(index<0)throw new ArgumentException("Unknown quality metric",nameof(name));metric.SelectedIndex=index;
|
|
}
|
|
public void CapturePreviewMode(int mode)
|
|
{if(mode<0||mode>1)throw new ArgumentOutOfRangeException(nameof(mode));previewMode.SelectedIndex=mode;}
|
|
public async Task SmokeTest(string report)
|
|
{
|
|
if(project==null)throw new InvalidOperationException("Project not loaded");
|
|
var results=new List<string>();void Check(bool value,string text){if(!value)throw new Exception(text);results.Add("PASS "+text);}
|
|
Width=1120;Height=740;await Task.Delay(150);
|
|
var countText=new FormattedText(queueTitle.Text??"",System.Globalization.CultureInfo.CurrentCulture,FlowDirection.LeftToRight,new Typeface(queueTitle.FontFamily),queueTitle.FontSize,queueTitle.Foreground);
|
|
Check(queueTitle.Bounds.Width>=countText.WidthIncludingTrailingWhitespace,"full project exposure count fits at minimum window size");
|
|
string original=projectDirectory;projectDirectory=System.IO.Path.Combine(System.IO.Path.GetDirectoryName(report)!,"smoke-project");Directory.CreateDirectory(System.IO.Path.Combine(projectDirectory,"previews"));
|
|
project.Frames=project.Frames.Take(40).ToList();
|
|
foreach(var f in project.Frames){var input=ProjectStore.PreviewPath(original,f);if(File.Exists(input))File.Copy(input,ProjectStore.PreviewPath(projectDirectory,f),true);}
|
|
RefreshFrames();Check(visible.Count==40,"all-frame filter");
|
|
foreach(var f in visible.ToArray())Select(f);Check(preview.Parent==previewPanel,"switching 40 exposures retains preview parent");
|
|
compare.IsChecked=true;spatial.IsChecked=true;Select(visible[0]);Select(visible[1]);Check(comparison.Parent==comparisonBorder,"comparison can switch exposures repeatedly");
|
|
var reviewed=visible[1];selected=reviewed;reviewed.Note="Existing label";await Override(Verdict.Reject,false);Check(reviewed.Override==Verdict.Reject,"manual override updates verdict");
|
|
filter.SelectedIndex=2;Check(visible.Contains(reviewed),"reject filter includes manual override");
|
|
var restored=ProjectStore.Load(projectDirectory);Check(restored.Frames.First(f=>f.Id==reviewed.Id).Note=="Existing label","existing notes survive decisions without a note editor");
|
|
selected=reviewed;await Override(null,false);Check(reviewed.Override==null,"reset restores automatic verdict");
|
|
filter.SelectedIndex=0;sort.SelectedIndex=2;Check(visible[0].StarCount==visible.Min(f=>f.StarCount),"metric sorting");
|
|
metric.SelectedIndex=Array.FindIndex(QualityChart.Metrics,m=>m.Name=="Background");Check(chart.Metric.Name=="Background","graph metric switching");
|
|
await WaitForPreviews();Check(preview.HasImage,"latest preview loads after rapid exposure switching");
|
|
previewMode.SelectedIndex=1;displayStretch.Value=.26;await WaitForPreviews();Check(preview.Mode==PreviewMode.Denoised&&Math.Abs(preview.Stretch-.26)<.001,"denoised view and adjustable stretch render without changing classification");
|
|
Width=1120;Height=740;await Task.Delay(100);Check(Bounds.Width>=1120,"minimum window size");
|
|
compare.IsChecked=false;await Task.Delay(100);
|
|
Check(this.GetVisualDescendants().OfType<QualityChart>().Count()==1,"one selectable quality graph");
|
|
Check(preview.Bounds.Height>330,"preview grows into available window height");
|
|
Check(!this.GetVisualDescendants().OfType<Button>().Any(b=>b.Content is string s&&(s=="Manifest"||s=="Open project"||s=="Save note"||s=="Inspect stars")),"removed controls stay absent");
|
|
Check(details.IsVisible&&inspector.GetVisualDescendants().OfType<TextBlock>().Any(t=>t.Text=="MEASUREMENT"),"decision evidence and measurements visible without expanding a panel");
|
|
var thumb=displayStretch.GetVisualDescendants().OfType<Avalonia.Controls.Primitives.Thumb>().First(t=>t.IsVisible);
|
|
var thumbTop=thumb.TranslatePoint(new Point(0,0),displayStretch)!.Value;
|
|
Check(thumbTop.Y>=0&&thumbTop.Y+thumb.Bounds.Height<=displayStretch.Bounds.Height,"stretch thumb fits entirely inside slider");
|
|
Check(frames.TranslatePoint(new Point(0,0),this)!.Value.X<preview.TranslatePoint(new Point(0,0),this)!.Value.X&&preview.TranslatePoint(new Point(0,0),this)!.Value.X<chart.TranslatePoint(new Point(0,0),this)!.Value.X,"exposure list, preview and quality evidence follow Atlas column order");
|
|
var session=sessions.SelectedItem;int previousCount=visible.Count;sessions.SelectedIndex=1;Check(visible.Count<=previousCount&&visible.All(f=>f.Session==(string?)sessions.SelectedItem),"compact session selector scopes exposures");sessions.SelectedItem=session;
|
|
await NativeDesktopChecks.Verify(this,Check);
|
|
File.WriteAllLines(report,results);projectDirectory=original;
|
|
}
|
|
void ShowNoSelection(){selected=null;inspectElongation.IsEnabled=false;inspector.Children.Clear();position.Text="";exposureName.Text="No exposures match this filter";exposureStatus.Text="";details.IsVisible=false;preview.Load(projectDirectory,null);comparison.Load(projectDirectory,null);chart.Selected=null;}
|
|
void Select(Frame f)
|
|
{
|
|
selected=f;chart.Selected=f;chart.InvalidateVisual();details.IsVisible=true;inspector.Children.Clear();
|
|
inspectElongation.IsEnabled=!busy&&f.Measured&&f.Error=="";
|
|
position.Text=$"{visible.IndexOf(f)+1:N0} / {visible.Count:N0}";
|
|
preview.Load(projectDirectory,f,project?.Frames);preview.Spatial=spatial.IsChecked==true;UpdateComparison();
|
|
exposureName.Text=f.Name;ToolTip.SetTip(exposureName,f.Name);exposureStatus.Text=f.Status+" · "+f.Time+" UTC"+(f.Override.HasValue?" · Manual":"");exposureStatus.Foreground=Palette.Verdict(f.Effective);
|
|
inspector.Children.Add(Palette.Label("DECISION EVIDENCE",10,Palette.Muted));
|
|
inspector.Children.Add(new TextBlock{Text=f.Cause,FontSize=14,Foreground=Palette.Text,TextWrapping=TextWrapping.Wrap});
|
|
foreach(var evidence in f.Evidence)
|
|
{
|
|
string summary=evidence.Message.Split(';')[0];int technical=summary.IndexOf(" (");if(technical>=0)summary=summary[..technical];
|
|
var explanation=new TextBlock{Text="• "+summary,TextWrapping=TextWrapping.Wrap,Foreground=evidence.Severity>5?Palette.Review:Palette.Muted,FontSize=12};
|
|
ToolTip.SetTip(explanation,evidence.Message);inspector.Children.Add(explanation);
|
|
}
|
|
var metrics=new Grid{ColumnDefinitions=new("*,Auto,Auto"),RowDefinitions=new("Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto")};
|
|
string[] names=["Cloud structure","Cloud area (%)","Star count","Stellar flux","FWHM","Ellipticity","Background","Noise","Background variation"];
|
|
double[] values=[f.CloudSignificance,100*f.CloudCoverage,f.StarCount,f.Transparency,f.Fwhm,f.Ellipticity,f.Background,f.Noise,f.BackgroundVariation];
|
|
var caption=Palette.Label("MEASUREMENT",10,Palette.Muted);metrics.Children.Add(caption);var vcap=Palette.Label("FRAME",10,Palette.Muted);Grid.SetColumn(vcap,1);metrics.Children.Add(vcap);var bcap=Palette.Label("BASELINE",10,Palette.Muted);bcap.Margin=new(14,0,0,0);Grid.SetColumn(bcap,2);metrics.Children.Add(bcap);
|
|
for(int i=0;i<names.Length;i++){var label=Palette.Label(names[i],12,Palette.Muted);label.Margin=new(0,7,0,0);Grid.SetRow(label,i+1);metrics.Children.Add(label);var value=Palette.Label(values[i].ToString("0.##"),12);value.Margin=new(0,7,0,0);Grid.SetRow(value,i+1);Grid.SetColumn(value,1);metrics.Children.Add(value);var baseline=Palette.Label(f.Baselines.TryGetValue(names[i],out double d)?d.ToString("0.##"):"—",12,Palette.Accent);baseline.Margin=new(14,7,0,0);Grid.SetRow(baseline,i+1);Grid.SetColumn(baseline,2);metrics.Children.Add(baseline);}inspector.Children.Add(Panel(new Border{Padding=new(12),Child=metrics}));
|
|
inspector.Children.Add(Palette.Label($"Matched stars {f.MatchFraction:P0} · reference overlap {f.AdditionalMeasurements.GetValueOrDefault("Reference overlap"):P0}",11,Palette.Muted));
|
|
}
|
|
void UpdateComparison()
|
|
{
|
|
bool show=compare.IsChecked==true;comparisonBorder.IsVisible=show;previewWorkspace.ColumnDefinitions[1].Width=show?new GridLength(1,GridUnitType.Star):new GridLength(0);previewPanel.Margin=show?new(0,0,6,0):new(0);
|
|
bool best=compareTarget.SelectedIndex==1;compareTarget.IsVisible=show;
|
|
preview.Caption=show?"Selected":"";comparison.Caption=show?best?"Best":"Nearby":"";preview.InvalidateVisual();
|
|
comparison.Spatial=spatial.IsChecked==true;
|
|
if(selected==null||project==null||!show){comparison.Load(projectDirectory,null);return;}
|
|
var other=best?BestFrame(project.Frames,selected):project.Frames.Where(f=>f.Session==selected.Session&&f.Id!=selected.Id&&f.Timestamp.HasValue&&selected.Timestamp.HasValue&&f.Error=="").OrderBy(f=>Math.Abs((f.Timestamp!.Value-selected.Timestamp!.Value).TotalSeconds)).FirstOrDefault();
|
|
comparison.Load(projectDirectory,other,project.Frames);ToolTip.SetTip(comparisonBorder,other==null?best?"No other kept, measured exposure in this session":"No comparable nearby exposure":(best?"Best":"Nearby")+" · "+other.Time+" · "+other.Status+(best?$" · score {other.Score:0} · FWHM {other.Fwhm:0.00}":""));
|
|
}
|
|
// Best kept exposure in the same session: highest quality score, then sharpest stars, then strongest stellar flux.
|
|
static Frame? BestFrame(IEnumerable<Frame> frames,Frame selected)
|
|
{
|
|
return frames.Where(f=>f.Session==selected.Session&&f.Id!=selected.Id&&f.Error==""&&f.Measured&&f.Effective==Verdict.Keep&&f.Fwhm>0)
|
|
.OrderByDescending(f=>f.Score).ThenBy(f=>f.Fwhm).ThenByDescending(f=>f.Transparency).ThenBy(f=>f.Timestamp).FirstOrDefault();
|
|
}
|
|
void Move(int step){if(visible.Count==0)return;int index=selected==null?0:visible.IndexOf(selected);var f=visible[Math.Clamp(index+step,0,visible.Count-1)];frames.SelectedItem=f;frames.ScrollIntoView(f);}
|
|
async Task Override(Verdict? verdict,bool advance=true)
|
|
{
|
|
if(selected==null||busy||saving||updates.Applying)return;var f=selected;int index=visible.IndexOf(f);undo.Push((f,f.Override,f.Note,f.ReviewedAt));f.Override=verdict;f.ReviewedAt=DateTime.UtcNow;
|
|
if(!await Save()){var previous=undo.Pop();f.Override=previous.Verdict;f.Note=previous.Note;f.ReviewedAt=previous.At;RefreshFrames(f);status.Text="Review could not be saved; decision restored";return;}
|
|
var next=advance?visible.ElementAtOrDefault(index+1)??visible.ElementAtOrDefault(index-1):f;RefreshFrames(next);status.Text="Manual decision saved · Ctrl+Z to undo";
|
|
}
|
|
async Task<bool> Save()
|
|
{
|
|
if(project==null)return false;await saveGate.WaitAsync();saving=true;analyze.IsEnabled=export.IsEnabled=false;
|
|
try{var p=project;var directory=projectDirectory;await Task.Run(()=>ProjectStore.Save(p,directory));return true;}
|
|
catch(Exception e){await Message("Could not save project",e.Message);return false;}
|
|
finally{saving=false;analyze.IsEnabled=!busy&&!updates.Applying;export.IsEnabled=!busy&&!updates.Applying&&project.Complete;saveGate.Release();}
|
|
}
|
|
async Task<string?> Folder(string title)
|
|
{var result=await StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions{Title=title,AllowMultiple=false});return result.FirstOrDefault()?.TryGetLocalPath();}
|
|
void Busy(bool value)
|
|
{
|
|
busy=value;analyze.IsEnabled=!value;export.IsEnabled=!value&&project?.Complete==true;frames.IsEnabled=sessions.IsEnabled=chart.IsEnabled=filter.IsEnabled=sort.IsEnabled=metric.IsEnabled=!value;inspector.IsEnabled=!value;stop.IsVisible=progress.IsVisible=memoryUsage.IsVisible=value;
|
|
inspectElongation.IsEnabled=!value&&selected?.Measured==true&&selected.Error=="";
|
|
if(value){starInspector?.Close();UpdateMemoryUsage();memoryTimer.Start();}else{memoryTimer.Stop();memoryUsage.Text="";}
|
|
}
|
|
void UpdateMemoryUsage()
|
|
{
|
|
if(!busy)return;using var process=System.Diagnostics.Process.GetCurrentProcess();memoryUsage.Text=$"Memory: {process.WorkingSet64/1048576.0:N0} MB";
|
|
}
|
|
void ShowElongation()
|
|
{
|
|
if(busy||saving||updates.Applying||project==null||selected?.Measured!=true||selected.Error!="")return;
|
|
starInspector?.Close();starInspector=new StarInspector(project,projectDirectory,selected);var opened=starInspector;opened.Closed+=(_,_)=>{if(starInspector==opened)starInspector=null;};opened.Show(this);
|
|
}
|
|
async Task Analyze()
|
|
{
|
|
if(busy||saving||updates.Applying)return;
|
|
string? source=project?.Source;
|
|
if(source!=null)
|
|
{
|
|
bool same=await Confirm("Analyze lights","Reanalyze the current source folder using cached measurements, or choose another folder?","Current source","Choose folder");if(!same)source=null;
|
|
}
|
|
source??=await Folder("Choose a folder containing raw FITS lights");if(source==null||updates.Applying)return;
|
|
if(project?.Source!=source)
|
|
{
|
|
string hash=Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(source)))[..16];
|
|
projectDirectory=System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),"AstroFrame","Projects",hash);
|
|
project=File.Exists(System.IO.Path.Combine(projectDirectory,"project.json"))?ProjectStore.Load(projectDirectory):null;
|
|
}
|
|
Busy(true);cancellation=new();progress.Value=0;
|
|
var analysisProgress=new Progress<ProgressInfo>(p=>{progress.Value=p.Total==0?0:100.0*p.Done/p.Total;status.Text=$"{p.Stage} · {p.Done:N0} / {p.Total:N0} · {p.File}";});
|
|
try
|
|
{
|
|
var previous=project;await Task.Run(async()=>project=await new Analyzer().AnalyzeAsync(source,projectDirectory,previous,analysisProgress,cancellation.Token));LoadProject(projectDirectory);
|
|
}
|
|
catch(OperationCanceledException){if(File.Exists(System.IO.Path.Combine(projectDirectory,"project.json")))LoadProject(projectDirectory);status.Text="Cancelled · completed measurements saved; reanalyze to resume";}
|
|
catch(ResourcePressureException e){if(File.Exists(System.IO.Path.Combine(projectDirectory,"project.json")))LoadProject(projectDirectory);status.Text="Paused safely for RAM pressure · completed measurements saved";await Message("RAM headroom unavailable",e.Message);}
|
|
catch(Exception e){await Message("Analysis could not finish",e.Message);status.Text="Analysis failed · check source folder and project storage";}
|
|
finally{Busy(false);cancellation.Dispose();cancellation=null;}
|
|
}
|
|
async Task ExportAccepted()
|
|
{
|
|
if(project?.Complete!=true||busy||saving||updates.Applying)return;
|
|
var options=new Window{Title="Export accepted lights",Width=470,SizeToContent=SizeToContent.Height,CanResize=false,WindowStartupLocation=WindowStartupLocation.CenterOwner,Background=Palette.Panel};
|
|
var layout=new StackPanel{Margin=new(24),Spacing=14};layout.Children.Add(Palette.Label("Prepare lights for Siril",21));layout.Children.Add(new TextBlock{Text="KEEP frames are included. Originals are opened read-only. Select an empty output folder outside your input tree.",TextWrapping=TextWrapping.Wrap,Foreground=Palette.Muted});
|
|
var scopes=new List<(string Name,List<Frame> Frames)>();
|
|
if(sessions.SelectedIndex>0)scopes.Add(("Selected observing session",project.Frames.Where(f=>f.Session==(string?)sessions.SelectedItem).ToList()));
|
|
foreach(var target in project.Frames.Select(f=>f.Target).Distinct())scopes.Add((target+" · all sessions",project.Frames.Where(f=>f.Target==target).ToList()));
|
|
scopes.Add(("Entire project · separate target folders",project.Frames));
|
|
var scope=new ComboBox{ItemsSource=scopes.Select(x=>x.Name).ToArray(),SelectedIndex=sessions.SelectedIndex>0?0:scopes.Count-1,HorizontalAlignment=HorizontalAlignment.Stretch};layout.Children.Add(Palette.Label("EXPORT SCOPE",10,Palette.Muted));layout.Children.Add(scope);
|
|
var include=new CheckBox{Content="Also include unresolved REVIEW frames",IsChecked=false};var links=new CheckBox{Content="Use hardlinks when available (copy fallback)",IsChecked=true};layout.Children.Add(include);layout.Children.Add(links);layout.Children.Add(new TextBlock{Text="Hardlinks share source bytes. Use Siril to read and process these inputs into separate outputs. Choose copies if another tool may overwrite input files.",FontSize=11,TextWrapping=TextWrapping.Wrap,Foreground=Palette.Muted});var buttons=new WrapPanel();var go=Button("Choose output folder",true);var cancel=Button("Cancel");cancel.Margin=new(8,0,0,0);buttons.Children.Add(go);buttons.Children.Add(cancel);layout.Children.Add(buttons);options.Content=layout;go.Click+=(_,_)=>options.Close(true);cancel.Click+=(_,_)=>options.Close(false);
|
|
if(!await options.ShowDialog<bool>(this))return;string? output=await Folder("Choose an empty output folder for accepted lights");if(output==null||updates.Applying)return;
|
|
var exportProject=new Project{Name=project.Name,Source=project.Source,Complete=project.Complete,Frames=scopes[scope.SelectedIndex].Frames};
|
|
Busy(true);cancellation=new();try{var result=await Export.AcceptedAsync(exportProject,output,include.IsChecked==true,links.IsChecked==true,new Progress<ProgressInfo>(p=>{progress.Value=100.0*p.Done/Math.Max(1,p.Total);status.Text=$"{p.Stage} · {p.Done}/{p.Total}";}),cancellation.Token);status.Text=$"Export complete · {result.Linked} hardlinks, {result.Copied} copies · {output}";}
|
|
catch(OperationCanceledException){status.Text="Export cancelled · completed output files retained; choose a new empty folder to retry";}catch(Exception e){await Message("Export could not finish",e.Message);}finally{Busy(false);cancellation.Dispose();cancellation=null;}
|
|
}
|
|
async Task Message(string heading,string message){await Confirm(heading,message,"OK",null);}
|
|
internal async Task ReportLoadFailure(string message)=>await Message("Could not reopen the last project",message);
|
|
async Task<bool> Confirm(string heading,string message,string yes,string? no)
|
|
{
|
|
var window=new Window{Title=heading,Width=460,SizeToContent=SizeToContent.Height,CanResize=false,WindowStartupLocation=WindowStartupLocation.CenterOwner,Background=Palette.Panel};var layout=new StackPanel{Margin=new(24),Spacing=18};layout.Children.Add(Palette.Label(heading,20));layout.Children.Add(new TextBlock{Text=message,TextWrapping=TextWrapping.Wrap,Foreground=Palette.Muted});var buttons=new WrapPanel();var accept=Button(yes,true);accept.Click+=(_,_)=>window.Close(true);buttons.Children.Add(accept);if(no!=null){var decline=Button(no);decline.Margin=new(8,0,0,0);decline.Click+=(_,_)=>window.Close(false);buttons.Children.Add(decline);}layout.Children.Add(buttons);window.Content=layout;return await window.ShowDialog<bool>(this);
|
|
}
|
|
}
|