using Avalonia; using Avalonia.Controls; using Avalonia.Input; using Avalonia.Interactivity; using Avalonia.Media; using Nonemm.Session; namespace Nonemm.App.Windows; /// The calls waiting to be worked, next one at the top and ringed. Each is /// coloured by what working it would bring, the way every other window colours /// a station. Double-click one to bring it to the top, right-click to drop it. public sealed partial class CallStackWindow : RefreshableWindow { private readonly AppSession session; private readonly int radioNumber; public CallStackWindow(AppSession session, int radioNumber = 1) { this.session = session; this.radioNumber = radioNumber; InitializeComponent(); Refresh(); } private OperatingPosition? Radio => session.Positions.FirstOrDefault(p => p.RadioNumber == radioNumber); public override void Refresh() { Calls.Children.Clear(); if (Radio is not { } position) { return; } ClearButton.IsEnabled = !position.Stack.IsEmpty; foreach (string call in position.Stack.Calls) { Calls.Children.Add(Row(position, call, isNext: call == position.Stack.Top)); } } private Control Row(OperatingPosition position, string call, bool isNext) { TextBlock text = new() { Text = call, FontFamily = new FontFamily("monospace"), FontSize = 14, Foreground = Verdicts.Colour(position.JudgeCall(call)), }; Border row = new() { CornerRadius = new CornerRadius(9), BorderThickness = new Thickness(1), BorderBrush = isNext ? text.Foreground : Brushes.Transparent, Padding = new Thickness(6, 1), Margin = new Thickness(0, 0, 0, 2), Cursor = new Cursor(StandardCursorType.Hand), Child = text, }; row.PointerPressed += (_, e) => { if (e.GetCurrentPoint(row).Properties.IsRightButtonPressed) { position.Stack.Remove(call); position.Session.NotifyChanged(); } }; row.DoubleTapped += (_, _) => { position.Stack.MoveToTop(call); position.Session.NotifyChanged(); }; return row; } private void OnClear(object? sender, RoutedEventArgs e) { if (Radio is not { } position) { return; } position.Stack.Clear(); position.Session.NotifyChanged(); } }