Просмотр исходного кода

Always allow pasting reference

CPKreuz 2 лет назад
Родитель
Сommit
335f8fab91

+ 3 - 3
src/PixiEditor/Models/Commands/Search/FileSearchResult.cs

@@ -16,7 +16,7 @@ internal class FileSearchResult : SearchResult
     public override string Description => FilePath;
 
     public override bool CanExecute => !asReferenceLayer ||
-                CommandController.Current.Commands["PixiEditor.Layer.PasteReferenceLayerFromPath"].Methods.CanExecute(FilePath);
+                CommandController.Current.Commands["PixiEditor.Clipboard.PasteReferenceLayerFromPath"].Methods.CanExecute(FilePath);
 
     public override ImageSource Icon => icon;
 
@@ -38,10 +38,10 @@ internal class FileSearchResult : SearchResult
         }
         else
         {
-            var command = CommandController.Current.Commands["PixiEditor.Layer.PasteReferenceLayerFromPath"];
+            var command = CommandController.Current.Commands["PixiEditor.Clipboard.PasteReferenceLayerFromPath"];
             if (command.Methods.CanExecute(FilePath))
             {
-                CommandController.Current.Commands["PixiEditor.Layer.PasteReferenceLayerFromPath"].Methods
+                CommandController.Current.Commands["PixiEditor.Clipboard.PasteReferenceLayerFromPath"].Methods
                     .Execute(FilePath);
             }
         }

+ 35 - 2
src/PixiEditor/ViewModels/SubViewModels/Main/ClipboardViewModel.cs

@@ -1,11 +1,12 @@
-using System.Diagnostics.CodeAnalysis;
-using System.Text.RegularExpressions;
+using System.Collections.Immutable;
 using System.Windows;
 using System.Windows.Input;
 using System.Windows.Media;
+using PixiEditor.DrawingApi.Core.Numerics;
 using PixiEditor.Helpers;
 using PixiEditor.Models.Commands.Attributes.Commands;
 using PixiEditor.Models.Controllers;
+using PixiEditor.Models.IO;
 
 namespace PixiEditor.ViewModels.SubViewModels.Main;
 #nullable enable
@@ -36,6 +37,38 @@ internal class ClipboardViewModel : SubViewModel<ViewModelMain>
         ClipboardController.TryPasteFromClipboard(Owner.DocumentManagerSubViewModel.ActiveDocument, pasteAsNewLayer);
     }
     
+    [Command.Basic("PixiEditor.Clipboard.PasteReferenceLayer", "Paste reference layer", "Paste reference layer from clipboard", CanExecute = "PixiEditor.Clipboard.CanPaste", IconPath = "Commands/PixiEditor/Clipboard/Paste.png")]
+    public void PasteReferenceLayer(DataObject data)
+    {
+        var doc = Owner.DocumentManagerSubViewModel.ActiveDocument;
+
+        var surface = (data == null ? ClipboardController.GetImagesFromClipboard() : ClipboardController.GetImage(data)).First();
+        using var image = surface.image;
+        
+        var bitmap = surface.image.ToWriteableBitmap();
+
+        byte[] pixels = new byte[bitmap.PixelWidth * bitmap.PixelHeight * 4];
+        bitmap.CopyPixels(pixels, bitmap.PixelWidth * 4, 0);
+
+        doc.Operations.ImportReferenceLayer(
+            pixels.ToImmutableArray(),
+            surface.image.Size);
+    }
+    
+    [Command.Internal("PixiEditor.Clipboard.PasteReferenceLayerFromPath")]
+    public void PasteReferenceLayer(string path)
+    {
+        var doc = Owner.DocumentManagerSubViewModel.ActiveDocument;
+
+        var bitmap = Importer.GetPreviewBitmap(path);
+        byte[] pixels = new byte[bitmap.PixelWidth * bitmap.PixelHeight * 4];
+        bitmap.CopyPixels(pixels, bitmap.PixelWidth * 4, 0);
+
+        doc.Operations.ImportReferenceLayer(
+            pixels.ToImmutableArray(),
+            new VecI(bitmap.PixelWidth, bitmap.PixelHeight));
+    }
+
     [Command.Basic("PixiEditor.Clipboard.PasteColor", false, "Paste color", "Paste color from clipboard", CanExecute = "PixiEditor.Clipboard.CanPasteColor", IconEvaluator = "PixiEditor.Clipboard.PasteColorIcon")]
     [Command.Basic("PixiEditor.Clipboard.PasteColorAsSecondary", true, "Paste color as secondary", "Paste color as secondary from clipboard", CanExecute = "PixiEditor.Clipboard.CanPasteColor", IconEvaluator = "PixiEditor.Clipboard.PasteColorIcon")]
     public void PasteColor(bool secondary)

+ 0 - 38
src/PixiEditor/ViewModels/SubViewModels/Main/LayersViewModel.cs

@@ -1,23 +1,17 @@
 using System.Collections.Immutable;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
 using System.Windows;
 using System.Windows.Input;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
-using ChunkyImageLib;
-using ChunkyImageLib.DataHolders;
 using Microsoft.Win32;
 using PixiEditor.ChangeableDocument.Enums;
 using PixiEditor.DrawingApi.Core.Numerics;
-using PixiEditor.Helpers;
 using PixiEditor.Models.Commands.Attributes.Commands;
 using PixiEditor.Models.Controllers;
 using PixiEditor.Models.Dialogs;
 using PixiEditor.Models.Enums;
 using PixiEditor.Models.IO;
 using PixiEditor.ViewModels.SubViewModels.Document;
-using PixiEditor.Views.Dialogs;
 
 namespace PixiEditor.ViewModels.SubViewModels.Main;
 #nullable enable
@@ -379,38 +373,6 @@ internal class LayersViewModel : SubViewModel<ViewModelMain>
             size);
     }
 
-    [Command.Basic("PixiEditor.Layer.PasteReferenceLayer", "Paste reference layer", "Paste reference layer from clipboard", IconPath = "Commands/PixiEditor/Clipboard/Paste.png", CanExecute = "PixiEditor.Layer.ReferenceLayerDoesntExistAndHasClipboardContent")]
-    public void PasteReferenceLayer(DataObject data)
-    {
-        var doc = Owner.DocumentManagerSubViewModel.ActiveDocument;
-
-        var surface = (data == null ? ClipboardController.GetImagesFromClipboard() : ClipboardController.GetImage(data)).First();
-        using var image = surface.image;
-        
-        var bitmap = surface.image.ToWriteableBitmap();
-
-        byte[] pixels = new byte[bitmap.PixelWidth * bitmap.PixelHeight * 4];
-        bitmap.CopyPixels(pixels, bitmap.PixelWidth * 4, 0);
-
-        doc.Operations.ImportReferenceLayer(
-            pixels.ToImmutableArray(),
-            surface.image.Size);
-    }
-    
-    [Command.Internal("PixiEditor.Layer.PasteReferenceLayerFromPath", CanExecute = "PixiEditor.Layer.ReferenceLayerDoesntExist")]
-    public void PasteReferenceLayer(string path)
-    {
-        var doc = Owner.DocumentManagerSubViewModel.ActiveDocument;
-
-        var bitmap = Importer.GetPreviewBitmap(path);
-        byte[] pixels = new byte[bitmap.PixelWidth * bitmap.PixelHeight * 4];
-        bitmap.CopyPixels(pixels, bitmap.PixelWidth * 4, 0);
-
-        doc.Operations.ImportReferenceLayer(
-            pixels.ToImmutableArray(),
-            new VecI(bitmap.PixelWidth, bitmap.PixelHeight));
-    }
-
     private string OpenReferenceLayerFilePicker()
     {
         var imagesFilter = new FileTypeDialogDataSet(FileTypeDialogDataSet.SetKind.Images).GetFormattedTypes();

+ 1 - 1
src/PixiEditor/Views/UserControls/Layers/ReferenceLayer.xaml.cs

@@ -26,7 +26,7 @@ internal partial class ReferenceLayer : UserControl
 
     public ReferenceLayer()
     {
-        command = CommandController.Current.Commands["PixiEditor.Layer.PasteReferenceLayer"];
+        command = CommandController.Current.Commands["PixiEditor.Clipboard.PasteReferenceLayer"];
         InitializeComponent();
     }