47 行
1.7 KiB
C#
47 行
1.7 KiB
C#
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<PluginDetailsAttribute>() ?? new();
|
|
|
|
public UndoTreeCommandPlugin() : this(() => Active)
|
|
{
|
|
}
|
|
|
|
internal UndoTreeCommandPlugin(Func<UndoTreeViewModel?> 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<PluginCommandBase> Commands { get; }
|
|
|
|
sealed record CommandId(string Key) : ICommandId<NoParameter>;
|
|
|
|
sealed class MoveCommand(UndoTreeMove move, Func<string> name, Key key, Func<UndoTreeViewModel?> active) : PluginCommand
|
|
{
|
|
public override string Name => $"{Texts.UndoTree}: {name()}";
|
|
|
|
public override ICommandId<NoParameter> 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);
|
|
}
|
|
}
|