using System.Windows; using System.Windows.Input; using Chronos.Ui.Visuals; namespace Chronos.App.Editor; /// Runs a command after every finished edit of a (add, move, delete, nudge). public static class CurveCommit { public static readonly DependencyProperty CommandProperty = DependencyProperty.RegisterAttached( "Command", typeof(ICommand), typeof(CurveCommit), 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 CurveEditor editor) return; editor.EditCompleted -= OnEditCompleted; if (e.NewValue is not null) editor.EditCompleted += OnEditCompleted; } private static void OnEditCompleted(object sender, RoutedEventArgs e) { if (GetCommand((DependencyObject)sender) is { } command && command.CanExecute(null)) command.Execute(null); } }