Browse Source

Folder Factory

Krzysztof Krysiński 1 year ago
parent
commit
4eaa9c1f65

+ 1 - 1
src/PixiEditor.Avalonia/PixiEditor.AvaloniaUI/Models/DocumentModels/ActionAccumulator.cs

@@ -126,7 +126,7 @@ internal class ActionAccumulator
             // unlock bitmaps
             // unlock bitmaps
             foreach (var lockedFramebuffer in lockedFramebuffers)
             foreach (var lockedFramebuffer in lockedFramebuffers)
             {
             {
-                lockedFramebuffer.Dispose();
+                lockedFramebuffer?.Dispose();
             }
             }
 
 
             lockedFramebuffers.Clear();
             lockedFramebuffers.Clear();

+ 13 - 1
src/PixiEditor.Avalonia/PixiEditor.AvaloniaUI/ViewModels/Dock/PixiEditorDocumentDock.cs

@@ -1,4 +1,5 @@
-using CommunityToolkit.Mvvm.Input;
+using System.Collections.Specialized;
+using CommunityToolkit.Mvvm.Input;
 using Dock.Model.Avalonia.Controls;
 using Dock.Model.Avalonia.Controls;
 using PixiEditor.AvaloniaUI.ViewModels.Document;
 using PixiEditor.AvaloniaUI.ViewModels.Document;
 using PixiEditor.AvaloniaUI.ViewModels.SubViewModels;
 using PixiEditor.AvaloniaUI.ViewModels.SubViewModels;
@@ -12,9 +13,20 @@ internal class PixiEditorDocumentDock : DocumentDock
     public PixiEditorDocumentDock(FileViewModel manager)
     public PixiEditorDocumentDock(FileViewModel manager)
     {
     {
         this.manager = manager;
         this.manager = manager;
+        manager.Owner.DocumentManagerSubViewModel.Documents.CollectionChanged += Documents_CollectionChanged;
         CreateDocument = new RelayCommand(CreateDockDocument);
         CreateDocument = new RelayCommand(CreateDockDocument);
     }
     }
 
 
+    private void Documents_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
+    {
+        DocumentViewModel documentVm = e.NewItems[^1] as DocumentViewModel;
+        var document = new DockDocumentViewModel(documentVm) { Title = documentVm.FileName };
+
+        Factory?.AddDockable(this, document);
+        Factory?.SetActiveDockable(document);
+        Factory?.SetFocusedDockable(this, document);
+    }
+
     private void CreateDockDocument()
     private void CreateDockDocument()
     {
     {
         if (!CanCreateDocument)
         if (!CanCreateDocument)

+ 2 - 1
src/PixiEditor.Avalonia/PixiEditor.AvaloniaUI/ViewModels/Document/DocumentViewModel.cs

@@ -159,7 +159,7 @@ internal partial class DocumentViewModel : ObservableObject, IDocument
     ITransformHandler IDocument.TransformHandler => TransformViewModel;
     ITransformHandler IDocument.TransformHandler => TransformViewModel;
     ILineOverlayHandler IDocument.LineToolOverlayHandler => LineToolOverlayViewModel;
     ILineOverlayHandler IDocument.LineToolOverlayHandler => LineToolOverlayViewModel;
     public ILayerHandlerFactory LayerHandlerFactory { get; }
     public ILayerHandlerFactory LayerHandlerFactory { get; }
-    IFolderHandlerFactory IDocument.FolderHandlerFactory { get; }
+    public IFolderHandlerFactory FolderHandlerFactory { get; }
     IReferenceLayerHandler IDocument.ReferenceLayerHandler => ReferenceLayerViewModel;
     IReferenceLayerHandler IDocument.ReferenceLayerHandler => ReferenceLayerViewModel;
 
 
 
 
@@ -173,6 +173,7 @@ internal partial class DocumentViewModel : ObservableObject, IDocument
         Operations = new DocumentOperationsModule(this, Internals);
         Operations = new DocumentOperationsModule(this, Internals);
 
 
         LayerHandlerFactory = new LayerHandlerFactory(this);
         LayerHandlerFactory = new LayerHandlerFactory(this);
+        FolderHandlerFactory = new FolderHandlerFactory(this);
 
 
         StructureRoot = new FolderViewModel(this, Internals, Internals.Tracker.Document.StructureRoot.GuidValue);
         StructureRoot = new FolderViewModel(this, Internals, Internals.Tracker.Document.StructureRoot.GuidValue);
 
 

+ 21 - 0
src/PixiEditor.Avalonia/PixiEditor.AvaloniaUI/ViewModels/Document/FolderHandlerFactory.cs

@@ -0,0 +1,21 @@
+using PixiEditor.AvaloniaUI.Helpers;
+using PixiEditor.AvaloniaUI.Models.DocumentModels;
+using PixiEditor.AvaloniaUI.Models.Handlers;
+
+namespace PixiEditor.AvaloniaUI.ViewModels.Document;
+
+internal class FolderHandlerFactory : IFolderHandlerFactory
+{
+    public DocumentViewModel Document { get; }
+    IDocument IFolderHandlerFactory.Document => Document;
+
+    public FolderHandlerFactory(DocumentViewModel document)
+    {
+        Document = document;
+    }
+
+    public IFolderHandler CreateFolderHandler(DocumentInternalParts helper, Guid infoGuidValue)
+    {
+        return new FolderViewModel(Document, helper, infoGuidValue);
+    }
+}

+ 1 - 1
src/PixiEditor.Avalonia/PixiEditor.AvaloniaUI/ViewModels/Document/LayerHandlerFactory.cs

@@ -7,7 +7,7 @@ namespace PixiEditor.AvaloniaUI.ViewModels.Document;
 internal class LayerHandlerFactory : ILayerHandlerFactory
 internal class LayerHandlerFactory : ILayerHandlerFactory
 {
 {
     public DocumentViewModel Document { get; }
     public DocumentViewModel Document { get; }
-    IDocument ILayerHandlerFactory.Document { get; }
+    IDocument ILayerHandlerFactory.Document => Document;
 
 
     public LayerHandlerFactory(DocumentViewModel document)
     public LayerHandlerFactory(DocumentViewModel document)
     {
     {