using System.Windows; using System.Windows.Input; using Chronos.Ui.Visuals; namespace Chronos.App.Editor; /// /// Runs a command after every finished edit of the crop box on a (a drag released, a key /// press), with the as its parameter (owner review 1, R5). /// public static class CropCommit { public static readonly DependencyProperty CommandProperty = DependencyProperty.RegisterAttached( "Command", typeof(ICommand), typeof(CropCommit), new PropertyMetadata(null, OnCommandChanged)); public static ICommand? GetCommand(DependencyObject d) => (ICommand?)d.GetValue(CommandProperty); public static void SetCommand(DependencyObject d, ICommand? value) => d.SetValue(CommandProperty, value); private static void OnCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (d is not PreviewViewport viewport) return; viewport.CropEditCompleted -= OnEditCompleted; if (e.NewValue is not null) viewport.CropEditCompleted += OnEditCompleted; } private static void OnEditCompleted(object sender, CropEditEventArgs e) { if (GetCommand((DependencyObject)sender) is { } command && command.CanExecute(e)) command.Execute(e); } }