Browse Source

Layers and animations delete context

flabbet 1 year ago
parent
commit
555d8fa9e3

+ 1 - 0
src/PixiEditor.AvaloniaUI/Models/Handlers/IKeyFrameHandler.cs

@@ -7,6 +7,7 @@ internal interface IKeyFrameHandler
     public Surface? PreviewSurface { get; set; }
     public Surface? PreviewSurface { get; set; }
     public int StartFrameBindable { get; }
     public int StartFrameBindable { get; }
     public int DurationBindable { get; }
     public int DurationBindable { get; }
+    public bool IsSelected { get; set; }
     public Guid LayerGuid { get; }
     public Guid LayerGuid { get; }
     public Guid Id { get; }
     public Guid Id { get; }
     public bool IsVisible { get; }
     public bool IsVisible { get; }

+ 12 - 1
src/PixiEditor.AvaloniaUI/ViewModels/Dock/LayersDockViewModel.cs

@@ -1,5 +1,6 @@
 using Avalonia.Media;
 using Avalonia.Media;
 using PixiDocks.Core.Docking;
 using PixiDocks.Core.Docking;
+using PixiDocks.Core.Docking.Events;
 using PixiEditor.AvaloniaUI.Helpers.Converters;
 using PixiEditor.AvaloniaUI.Helpers.Converters;
 using PixiEditor.AvaloniaUI.ViewModels.Document;
 using PixiEditor.AvaloniaUI.ViewModels.Document;
 using PixiEditor.Extensions.Common.Localization;
 using PixiEditor.Extensions.Common.Localization;
@@ -7,7 +8,7 @@ using PixiEditor.UI.Common.Fonts;
 
 
 namespace PixiEditor.AvaloniaUI.ViewModels.Dock;
 namespace PixiEditor.AvaloniaUI.ViewModels.Dock;
 
 
-internal class LayersDockViewModel : DockableViewModel
+internal class LayersDockViewModel : DockableViewModel, IDockableSelectionEvents
 {
 {
     public const string TabId = "Layers";
     public const string TabId = "Layers";
     public override string Id => TabId;
     public override string Id => TabId;
@@ -41,4 +42,14 @@ internal class LayersDockViewModel : DockableViewModel
     {
     {
         ActiveDocument = e.NewDocument;
         ActiveDocument = e.NewDocument;
     }
     }
+
+    void IDockableSelectionEvents.OnSelected()
+    {
+        documentManager.Owner.ShortcutController.OverwriteContext(GetType());
+    }
+
+    void IDockableSelectionEvents.OnDeselected()
+    {
+        documentManager.Owner.ShortcutController.ClearContext(GetType());
+    }
 }
 }

+ 13 - 2
src/PixiEditor.AvaloniaUI/ViewModels/Dock/TimelineDockViewModel.cs

@@ -1,10 +1,11 @@
-using PixiEditor.AvaloniaUI.ViewModels.Document;
+using PixiDocks.Core.Docking.Events;
+using PixiEditor.AvaloniaUI.ViewModels.Document;
 using PixiEditor.Extensions.Common.Localization;
 using PixiEditor.Extensions.Common.Localization;
 using PixiEditor.UI.Common.Fonts;
 using PixiEditor.UI.Common.Fonts;
 
 
 namespace PixiEditor.AvaloniaUI.ViewModels.Dock;
 namespace PixiEditor.AvaloniaUI.ViewModels.Dock;
 
 
-internal class TimelineDockViewModel : DockableViewModel
+internal class TimelineDockViewModel : DockableViewModel, IDockableSelectionEvents
 {
 {
     public const string TabId = "Timeline";
     public const string TabId = "Timeline";
 
 
@@ -26,4 +27,14 @@ internal class TimelineDockViewModel : DockableViewModel
         DocumentManagerSubViewModel = documentManagerViewModel;
         DocumentManagerSubViewModel = documentManagerViewModel;
         TabCustomizationSettings.Icon = PixiPerfectIcons.ToIcon(PixiPerfectIcons.Timeline);
         TabCustomizationSettings.Icon = PixiPerfectIcons.ToIcon(PixiPerfectIcons.Timeline);
     }
     }
+
+    void IDockableSelectionEvents.OnSelected()
+    {
+        documentManagerSubViewModel.Owner.ShortcutController?.OverwriteContext(GetType());
+    }
+
+    void IDockableSelectionEvents.OnDeselected()
+    {
+        documentManagerSubViewModel.Owner.ShortcutController?.ClearContext(GetType());
+    }
 }
 }

+ 12 - 0
src/PixiEditor.AvaloniaUI/ViewModels/Document/AnimationDataViewModel.cs

@@ -18,8 +18,11 @@ internal class AnimationDataViewModel : ObservableObject, IAnimationHandler
     public DocumentViewModel Document { get; }
     public DocumentViewModel Document { get; }
     protected DocumentInternalParts Internals { get; }
     protected DocumentInternalParts Internals { get; }
     public IReadOnlyCollection<IKeyFrameHandler> KeyFrames => keyFrames;
     public IReadOnlyCollection<IKeyFrameHandler> KeyFrames => keyFrames;
+    
+    public IReadOnlyCollection<IKeyFrameHandler> AllKeyFrames => allKeyFrames;
 
 
     private KeyFrameCollection keyFrames = new KeyFrameCollection();
     private KeyFrameCollection keyFrames = new KeyFrameCollection();
+    private List<IKeyFrameHandler> allKeyFrames = new List<IKeyFrameHandler>();
 
 
     public int ActiveFrameBindable
     public int ActiveFrameBindable
     {
     {
@@ -148,6 +151,11 @@ internal class AnimationDataViewModel : ObservableObject, IAnimationHandler
         }
         }
 
 
         keyFrames.NotifyCollectionChanged(NotifyCollectionChangedAction.Add, (KeyFrameViewModel)keyFrame);
         keyFrames.NotifyCollectionChanged(NotifyCollectionChangedAction.Add, (KeyFrameViewModel)keyFrame);
+
+        if (!allKeyFrames.Contains(keyFrame))
+        {
+            allKeyFrames.Add(keyFrame);
+        }
     }
     }
 
 
     public void RemoveKeyFrame(Guid keyFrameId)
     public void RemoveKeyFrame(Guid keyFrameId)
@@ -157,6 +165,8 @@ internal class AnimationDataViewModel : ObservableObject, IAnimationHandler
             parent.Children.Remove(frame);
             parent.Children.Remove(frame);
             keyFrames.NotifyCollectionChanged(NotifyCollectionChangedAction.Remove, (KeyFrameViewModel)frame);
             keyFrames.NotifyCollectionChanged(NotifyCollectionChangedAction.Remove, (KeyFrameViewModel)frame);
         });
         });
+        
+        allKeyFrames.RemoveAll(x => x.Id == keyFrameId);
     }
     }
 
 
     public void AddSelectedKeyFrame(Guid keyFrameId)
     public void AddSelectedKeyFrame(Guid keyFrameId)
@@ -194,6 +204,8 @@ internal class AnimationDataViewModel : ObservableObject, IAnimationHandler
                 parent.Children.Remove(frame);
                 parent.Children.Remove(frame);
                 framesToRemove.Add((KeyFrameViewModel)frame);
                 framesToRemove.Add((KeyFrameViewModel)frame);
             });
             });
+            
+            allKeyFrames.RemoveAll(x => x.Id == keyFrame);
         }
         }
         
         
         keyFrames.NotifyCollectionChanged(NotifyCollectionChangedAction.Remove, framesToRemove);
         keyFrames.NotifyCollectionChanged(NotifyCollectionChangedAction.Remove, framesToRemove);

+ 9 - 5
src/PixiEditor.AvaloniaUI/ViewModels/SubViewModels/AnimationsViewModel.cs

@@ -1,7 +1,9 @@
-using ChunkyImageLib;
+using Avalonia.Input;
+using ChunkyImageLib;
 using PixiEditor.AnimationRenderer.Core;
 using PixiEditor.AnimationRenderer.Core;
 using PixiEditor.AvaloniaUI.Models.Commands.Attributes.Commands;
 using PixiEditor.AvaloniaUI.Models.Commands.Attributes.Commands;
 using PixiEditor.AvaloniaUI.Models.IO;
 using PixiEditor.AvaloniaUI.Models.IO;
+using PixiEditor.AvaloniaUI.ViewModels.Dock;
 using PixiEditor.AvaloniaUI.ViewModels.Document;
 using PixiEditor.AvaloniaUI.ViewModels.Document;
 using PixiEditor.DrawingApi.Core.Surface;
 using PixiEditor.DrawingApi.Core.Surface;
 using PixiEditor.DrawingApi.Core.Surface.ImageData;
 using PixiEditor.DrawingApi.Core.Surface.ImageData;
@@ -40,15 +42,17 @@ internal class AnimationsViewModel : SubViewModel<ViewModelMain>
         activeDocument.Operations.SetActiveFrame(newFrame);
         activeDocument.Operations.SetActiveFrame(newFrame);
     }
     }
     
     
-    [Command.Basic("PixiEditor.Animation.DeleteKeyFrames", "Delete key frames", "Delete key frames")]
-    public void DeleteKeyFrames(IList<KeyFrameViewModel> keyFrames)
+    [Command.Basic("PixiEditor.Animation.DeleteKeyFrames", "DELETE_KEY_FRAMES", "DELETE_KEY_FRAMES_DESCRIPTIVE",
+        ShortcutContext = typeof(TimelineDockViewModel), Key = Key.Delete)]
+    public void DeleteKeyFrames()
     {
     {
         var activeDocument = Owner.DocumentManagerSubViewModel.ActiveDocument;
         var activeDocument = Owner.DocumentManagerSubViewModel.ActiveDocument;
+        var selected = activeDocument.AnimationDataViewModel.AllKeyFrames.Where(x => x.IsSelected).ToArray();
 
 
-        if (activeDocument is null)
+        if (activeDocument is null || selected.Length == 0)
             return;
             return;
         
         
-        List<Guid> keyFrameIds = keyFrames.Select(x => x.Id).ToList();
+        List<Guid> keyFrameIds = selected.Select(x => x.Id).ToList();
         
         
         for(int i = 0; i < keyFrameIds.Count; i++)
         for(int i = 0; i < keyFrameIds.Count; i++)
         {
         {

+ 4 - 1
src/PixiEditor.AvaloniaUI/ViewModels/SubViewModels/LayersViewModel.cs

@@ -55,7 +55,10 @@ internal class LayersViewModel : SubViewModel<ViewModelMain>
         return true;
         return true;
     }
     }
 
 
-    [Command.Basic("PixiEditor.Layer.DeleteSelected", "LAYER_DELETE_SELECTED", "LAYER_DELETE_SELECTED_DESCRIPTIVE", CanExecute = "PixiEditor.Layer.CanDeleteSelected", 
+    [Command.Basic("PixiEditor.Layer.DeleteSelected", "LAYER_DELETE_SELECTED", 
+        "LAYER_DELETE_SELECTED_DESCRIPTIVE", 
+        CanExecute = "PixiEditor.Layer.CanDeleteSelected", Key = Key.Delete, 
+        ShortcutContext = typeof(LayersDockViewModel),
         Icon = PixiPerfectIcons.Trash)]
         Icon = PixiPerfectIcons.Trash)]
     public void DeleteSelected()
     public void DeleteSelected()
     {
     {