Răsfoiți Sursa

Made DocumentViewModel constructor private, use DocumentViewModel.Build to create a document

CPKreuz 2 ani în urmă
părinte
comite
445ef8bb5a

+ 1 - 1
src/PixiEditor/ViewModels/SubViewModels/Document/DocumentViewModel.cs

@@ -155,7 +155,7 @@ internal partial class DocumentViewModel : NotifyableObject
 
     private DocumentInternalParts Internals { get; }
 
-    public DocumentViewModel()
+    private DocumentViewModel()
     {
         Internals = new DocumentInternalParts(this);
         Tools = new DocumentToolsModule(this, Internals);

+ 10 - 8
src/PixiEditor/ViewModels/SubViewModels/Main/FileViewModel.cs

@@ -80,14 +80,16 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
 
     public DocumentViewModel NewDocument(VecI size, bool addBaseLayer = true)
     {
-        DocumentViewModel doc = new DocumentViewModel();
-        Owner.DocumentManagerSubViewModel.Documents.Add(doc);
-
-        if (doc.SizeBindable != size)
-            doc.Operations.ResizeCanvas(size, ResizeAnchor.TopLeft);
-        if (addBaseLayer)
-            doc.Operations.CreateStructureMember(StructureMemberType.Layer);
-        doc.Operations.ClearUndo();
+        var doc = DocumentViewModel.Build(d =>
+        {
+            d.WithSize(size.X, size.Y);
+
+            if (addBaseLayer)
+            {
+                d.WithLayer(l => l.WithName("Base Layer").WithSurface(new Surface(size)));
+            }
+        });
+
         doc.MarkAsSaved();
         Owner.WindowSubViewModel.CreateNewViewport(doc);
         Owner.WindowSubViewModel.MakeDocumentViewportActive(doc);