using Avalonia.Input; using PixiEditor.AvaloniaUI.Models.Commands.Attributes.Commands; using PixiEditor.AvaloniaUI.Models.Commands.Attributes.Evaluators; namespace PixiEditor.AvaloniaUI.ViewModels.SubViewModels; [Command.Group("PixiEditor.Undo", "UNDO")] internal class UndoViewModel : SubViewModel { public UndoViewModel(ViewModelMain owner) : base(owner) { } /// /// Redo last action. /// [Command.Basic("PixiEditor.Undo.Redo", "REDO", "REDO_DESCRIPTIVE", CanExecute = "PixiEditor.Undo.CanRedo", Key = Key.Y, Modifiers = KeyModifiers.Control, IconPath = "Redo.png", MenuItemPath = "EDIT/REDO", MenuItemOrder = 1)] public void Redo() { var doc = Owner.DocumentManagerSubViewModel.ActiveDocument; if (doc is null || (!doc.UpdateableChangeActive && !doc.HasSavedRedo)) return; doc.Operations.Redo(); } /// /// Undo last action. /// [Command.Basic("PixiEditor.Undo.Undo", "UNDO", "UNDO_DESCRIPTIVE", CanExecute = "PixiEditor.Undo.CanUndo", Key = Key.Z, Modifiers = KeyModifiers.Control, IconPath = "Undo.png", MenuItemPath = "EDIT/UNDO", MenuItemOrder = 0)] public void Undo() { var doc = Owner.DocumentManagerSubViewModel.ActiveDocument; if (doc is null || (!doc.UpdateableChangeActive && !doc.HasSavedUndo)) return; doc.Operations.Undo(); } /// /// Returns true if undo can be done. /// /// CommandParameter. /// True if can undo. [Evaluator.CanExecute("PixiEditor.Undo.CanUndo")] public bool CanUndo() { var doc = Owner.DocumentManagerSubViewModel.ActiveDocument; if (doc is null) return false; return doc.UpdateableChangeActive || doc.HasSavedUndo; } /// /// Returns true if redo can be done. /// /// CommandProperty. /// True if can redo. [Evaluator.CanExecute("PixiEditor.Undo.CanRedo")] public bool CanRedo() { var doc = Owner.DocumentManagerSubViewModel.ActiveDocument; if (doc is null) return false; return doc.UpdateableChangeActive || doc.HasSavedRedo; } }