using System.Reflection; using System.Windows.Input; using YukkuriMovieMaker.Plugin; using YukkuriMovieMaker.Settings; namespace UndoTree; [PluginDetails(AuthorName = "routersys")] internal sealed class UndoTreeCommandPlugin : ICommandPlugin { internal static UndoTreeViewModel? Active { get; set; } public string Name => Texts.UndoTree; public PluginDetailsAttribute Details => GetType().GetCustomAttribute() ?? new(); public UndoTreeCommandPlugin() : this(() => Active) { } internal UndoTreeCommandPlugin(Func active) => Commands = [ new MoveCommand(UndoTreeMove.PreviousCreated, () => Texts.MoveToPreviousCreated, Key.Left, active), new MoveCommand(UndoTreeMove.NextCreated, () => Texts.MoveToNextCreated, Key.Right, active), new MoveCommand(UndoTreeMove.PreviousBranch, () => Texts.MoveToPreviousBranch, Key.Up, active), new MoveCommand(UndoTreeMove.NextBranch, () => Texts.MoveToNextBranch, Key.Down, active), ]; public IEnumerable Commands { get; } sealed record CommandId(string Key) : ICommandId; sealed class MoveCommand(UndoTreeMove move, Func name, Key key, Func active) : PluginCommand { public override string Name => $"{Texts.UndoTree}: {name()}"; public override ICommandId Id { get; } = new CommandId($"{UndoTreeToolPlugin.Id}.{move}"); public override Key DefaultKey => key; public override ModifierKeys DefaultModifierKeys => ModifierKeys.Alt; public override bool CanExecute() => active()?.CanMove(move) == true; public override void Execute() => active()?.Move(move); } }