浏览代码

Duplicating fix

Krzysztof Krysiński 1 月之前
父节点
当前提交
a46bc8403f
共有 1 个文件被更改,包括 7 次插入1 次删除
  1. 7 1
      src/PixiEditor/ViewModels/SubViewModels/BrushesViewModel.cs

+ 7 - 1
src/PixiEditor/ViewModels/SubViewModels/BrushesViewModel.cs

@@ -157,7 +157,7 @@ internal class BrushesViewModel : SubViewModel<ViewModelMain>
     [Command.Internal("PixiEditor.Brushes.Duplicate", "DUPLICATE_BRUSH")]
     public void DuplicateBrush(BrushViewModel brushViewModel)
     {
-        if (brushViewModel == null || brushViewModel.IsReadOnly || brushViewModel.Brush == null)
+        if (brushViewModel == null || !brushViewModel.IsDuplicable || brushViewModel.Brush == null)
             return;
 
         if (File.Exists(brushViewModel.Brush.FilePath))
@@ -170,6 +170,12 @@ internal class BrushesViewModel : SubViewModel<ViewModelMain>
             File.Copy(brushViewModel.Brush.FilePath, newFilePath);
             Owner.DocumentManagerSubViewModel.OpenDocument(newFilePath);
         }
+        else if(brushViewModel.Brush.Document is DocumentViewModel dvm)
+        {
+            string uniqueName = FileHelper.GetUniqueFileName(
+                Path.Combine(Paths.PathToBrushesFolder, $"{brushViewModel.Brush.Name}_clone.pixi"));
+            Exporter.TrySave(dvm, uniqueName, new ExportConfig(dvm.SizeBindable), null);
+        }
     }
 
     [Command.Basic("PixiEditor.Brushes.OpenBrushesFolder", "OPEN_BRUSHES_FOLDER", "OPEN_BRUSHES_FOLDER_DESCRIPTIVE",