Browse Source

LayersManager is now displaying more properly

Krzysztof Krysiński 1 year ago
parent
commit
33b989cf03

+ 6 - 4
src/PixiEditor.AvaloniaUI/Models/Commands/Attributes/Evaluators/CanExecuteAttribute.cs

@@ -1,20 +1,22 @@
-namespace PixiEditor.AvaloniaUI.Models.Commands.Attributes.Evaluators;
+using PixiEditor.AvaloniaUI.ViewModels.Document;
+
+namespace PixiEditor.AvaloniaUI.Models.Commands.Attributes.Evaluators;
 
 
 internal partial class Evaluator
 internal partial class Evaluator
 {
 {
     [AttributeUsage(AttributeTargets.Property | AttributeTargets.Method, AllowMultiple = true)]
     [AttributeUsage(AttributeTargets.Property | AttributeTargets.Method, AllowMultiple = true)]
     internal class CanExecuteAttribute : EvaluatorAttribute
     internal class CanExecuteAttribute : EvaluatorAttribute
     {
     {
-        public string[] DependentOn { get; }
+        //public string[] DependentOn { get; }
 
 
         public CanExecuteAttribute([InternalName] string name) : base(name)
         public CanExecuteAttribute([InternalName] string name) : base(name)
         {
         {
-            DependentOn = Array.Empty<string>();
+            //DependentOn = new[] { nameof(DocumentManagerViewModel.ActiveDocument) }; // ActiveDocument will be required 99% of the time, so we'll just add it by default
         }
         }
 
 
         public CanExecuteAttribute([InternalName] string name, params string[] dependentOn) : base(name)
         public CanExecuteAttribute([InternalName] string name, params string[] dependentOn) : base(name)
         {
         {
-            DependentOn = dependentOn;
+            //DependentOn = dependentOn;
         }
         }
     }
     }
 }
 }

+ 3 - 2
src/PixiEditor.AvaloniaUI/Models/Commands/CommandController.cs

@@ -165,7 +165,8 @@ internal class CommandController
     {
     {
         foreach (var evaluator in objectsToInvokeOn)
         foreach (var evaluator in objectsToInvokeOn)
         {
         {
-            if (evaluator.Methods.CanExecuteEvaluator.DependentOn != null && evaluator.Methods.CanExecuteEvaluator.DependentOn.Contains(propertyName))
+            //TODO: Check if performance is better with or without this
+            /*if (evaluator.Methods.CanExecuteEvaluator.DependentOn != null && evaluator.Methods.CanExecuteEvaluator.DependentOn.Contains(propertyName))*/
             {
             {
                 evaluator.OnCanExecuteChanged();
                 evaluator.OnCanExecuteChanged();
             }
             }
@@ -473,7 +474,7 @@ internal class CommandController
                                     {
                                     {
                                         Name = attribute.Name,
                                         Name = attribute.Name,
                                         Evaluate = evaluateFunction.Invoke,
                                         Evaluate = evaluateFunction.Invoke,
-                                        DependentOn = canExecuteAttribute.DependentOn
+                                        /*DependentOn = canExecuteAttribute.DependentOn*/
                                     });
                                     });
                                 break;
                                 break;
                             }
                             }

+ 13 - 6
src/PixiEditor.AvaloniaUI/ViewModels/Dock/DockFactory.cs

@@ -13,6 +13,7 @@ internal class DockFactory : Factory
     private DockDock mainLayout;
     private DockDock mainLayout;
     private DocumentDock documentDock;
     private DocumentDock documentDock;
     private ToolDock toolDock;
     private ToolDock toolDock;
+    private ToolDock layersDock;
 
 
     private FileViewModel manager;
     private FileViewModel manager;
 
 
@@ -98,18 +99,21 @@ internal class DockFactory : Factory
 
 
     private IDockable BuildPropertiesDock()
     private IDockable BuildPropertiesDock()
     {
     {
-        IDockable layersDock = BuildLayersDock();
+        layersDock = BuildLayersDock();
         return new ProportionalDock()
         return new ProportionalDock()
         {
         {
             Proportion = 0.15,
             Proportion = 0.15,
-            VisibleDockables = CreateList(layersDock),
+            VisibleDockables = new List<IDockable>()
+            {
+                layersDock,
+            },
             ActiveDockable = layersDock,
             ActiveDockable = layersDock,
         };
         };
     }
     }
 
 
-    private IDockable BuildLayersDock()
+    private ToolDock BuildLayersDock()
     {
     {
-        LayersDockViewModel layersDock = new()
+        LayersDockViewModel layersVm = new(manager.Owner.DocumentManagerSubViewModel)
         {
         {
             Id = "LayersPane",
             Id = "LayersPane",
             Title = "LayersPane",
             Title = "LayersPane",
@@ -119,8 +123,8 @@ internal class DockFactory : Factory
         {
         {
             Id = "LayersPane",
             Id = "LayersPane",
             Title = "LayersPane",
             Title = "LayersPane",
-            VisibleDockables = new List<IDockable>() { layersDock },
-            ActiveDockable = layersDock,
+            VisibleDockables = new List<IDockable>() { layersVm },
+            ActiveDockable = layersVm,
         };
         };
 
 
         return layers;
         return layers;
@@ -134,12 +138,15 @@ internal class DockFactory : Factory
             { "MainLayout", () => mainLayout },
             { "MainLayout", () => mainLayout },
             { "DocumentsPane", () => documentDock },
             { "DocumentsPane", () => documentDock },
             { "ToolsPane", () => toolDock },
             { "ToolsPane", () => toolDock },
+            { "LayersPane", () => layersDock },
         };
         };
 
 
         ContextLocator = new Dictionary<string, Func<object?>>()
         ContextLocator = new Dictionary<string, Func<object?>>()
         {
         {
             { "MainLayout", () => layout },
             { "MainLayout", () => layout },
             { "ToolsPane", () => layout },
             { "ToolsPane", () => layout },
+            { "DocumentsPane", () => layout },
+            { "LayersPane", () => layout },
         };
         };
 
 
         HostWindowLocator = new Dictionary<string, Func<IHostWindow?>>()
         HostWindowLocator = new Dictionary<string, Func<IHostWindow?>>()

+ 30 - 4
src/PixiEditor.AvaloniaUI/ViewModels/Dock/LayersDockViewModel.cs

@@ -1,11 +1,37 @@
-using Dock.Model.Avalonia.Controls;
-using PixiEditor.AvaloniaUI.Views.Layers;
+using Avalonia;
+using Dock.Model.Avalonia.Controls;
+using PixiEditor.AvaloniaUI.ViewModels.Document;
 
 
 namespace PixiEditor.AvaloniaUI.ViewModels.Dock;
 namespace PixiEditor.AvaloniaUI.ViewModels.Dock;
 
 
-public class LayersDockViewModel : Tool
+internal class LayersDockViewModel : Tool
 {
 {
-    public LayersDockViewModel()
+    public static readonly StyledProperty<DocumentManagerViewModel> DocumentManagerProperty = AvaloniaProperty.Register<LayersDockViewModel, DocumentManagerViewModel>(
+        nameof(DocumentManager));
+
+    public DocumentManagerViewModel DocumentManager
+    {
+        get => GetValue(DocumentManagerProperty);
+        set => SetValue(DocumentManagerProperty, value);
+    }
+
+    public static readonly StyledProperty<DocumentViewModel> ActiveDocumentProperty = AvaloniaProperty.Register<LayersDockViewModel, DocumentViewModel>(
+        nameof(ActiveDocument));
+
+    public DocumentViewModel ActiveDocument
+    {
+        get => GetValue(ActiveDocumentProperty);
+        set => SetValue(ActiveDocumentProperty, value);
+    }
+    
+    public LayersDockViewModel(DocumentManagerViewModel documentManager)
+    {
+        DocumentManager = documentManager;
+        DocumentManager.ActiveDocumentChanged += DocumentManager_ActiveDocumentChanged;
+    }
+
+    private void DocumentManager_ActiveDocumentChanged(object? sender, DocumentChangedEventArgs e)
     {
     {
+        ActiveDocument = e.NewDocument;
     }
     }
 }
 }

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

@@ -122,7 +122,7 @@ internal class LayersViewModel : SubViewModel<ViewModelMain>
     [Evaluator.CanExecute("PixiEditor.Layer.CanCreateNewMember")]
     [Evaluator.CanExecute("PixiEditor.Layer.CanCreateNewMember")]
     public bool CanCreateNewMember()
     public bool CanCreateNewMember()
     {
     {
-        return Owner.DocumentManagerSubViewModel.ActiveDocument is { } doc && !doc.UpdateableChangeActive;
+        return Owner.DocumentManagerSubViewModel.ActiveDocument is { UpdateableChangeActive: false };
     }
     }
 
 
     [Command.Internal("PixiEditor.Layer.ToggleLockTransparency", CanExecute = "PixiEditor.Layer.SelectedMemberIsLayer")]
     [Command.Internal("PixiEditor.Layer.ToggleLockTransparency", CanExecute = "PixiEditor.Layer.SelectedMemberIsLayer")]

+ 7 - 7
src/PixiEditor.AvaloniaUI/Views/Layers/LayersManager.axaml

@@ -98,13 +98,13 @@
                     DockPanel.Dock="Left"
                     DockPanel.Dock="Left"
                     Margin="0,0,5,0"
                     Margin="0,0,5,0"
                     Width="80"
                     Width="80"
-                    SelectedBlendMode="{Binding ActiveDocument.SelectedStructureMember.BlendModeBindable, Mode=TwoWay, ElementName=layersManager}" />
+                    SelectedBlendMode="{Binding DataContext.ActiveDocument.SelectedStructureMember.BlendModeBindable, Mode=TwoWay, ElementName=layersManager}" />
                 <input:NumberInput
                 <input:NumberInput
                     Min="0" Max="100"
                     Min="0" Max="100"
                     x:Name="numberInput"
                     x:Name="numberInput"
                     d:Value="100"
                     d:Value="100"
                     DockPanel.Dock="Right"
                     DockPanel.Dock="Right"
-                    IsEnabled="{Binding Path=ActiveDocument, ElementName=layersManager, Converter={converters1:NotNullToVisibilityConverter}}"
+                    IsEnabled="{Binding Path=DataContext.ActiveDocument, ElementName=layersManager, Converter={converters1:NotNullToVisibilityConverter}}"
                     Width="35" Height="20"
                     Width="35" Height="20"
                     Margin="5,0,0,0"
                     Margin="5,0,0,0"
                     VerticalAlignment="Center"
                     VerticalAlignment="Center"
@@ -113,7 +113,7 @@
                         <Binding
                         <Binding
                             Mode="TwoWay"
                             Mode="TwoWay"
                             ElementName="layersManager"
                             ElementName="layersManager"
-                            Path="ActiveDocument.SelectedStructureMember.OpacityBindable"
+                            Path="DataContext.ActiveDocument.SelectedStructureMember.OpacityBindable"
                             Converter="{converters1:MultiplyConverter}">
                             Converter="{converters1:MultiplyConverter}">
                             <Binding.ConverterParameter>
                             <Binding.ConverterParameter>
                                 <sys:Double>100</sys:Double>
                                 <sys:Double>100</sys:Double>
@@ -133,7 +133,7 @@
                     HorizontalAlignment="Stretch">
                     HorizontalAlignment="Stretch">
                     <Interaction.Behaviors>
                     <Interaction.Behaviors>
                         <behaviours:SliderUpdateBehavior
                         <behaviours:SliderUpdateBehavior
-                                Binding="{Binding ElementName=layersManager, Path=ActiveDocument.SelectedStructureMember.OpacityBindable, Mode=OneWay}"
+                                Binding="{Binding ElementName=layersManager, Path=DataContext.ActiveDocument.SelectedStructureMember.OpacityBindable, Mode=OneWay}"
                                 DragStarted="{xaml:Command PixiEditor.Layer.OpacitySliderDragStarted}"
                                 DragStarted="{xaml:Command PixiEditor.Layer.OpacitySliderDragStarted}"
                                 DragValueChanged="{xaml:Command PixiEditor.Layer.OpacitySliderDragged, UseProvided=True}"
                                 DragValueChanged="{xaml:Command PixiEditor.Layer.OpacitySliderDragged, UseProvided=True}"
                                 DragEnded="{xaml:Command PixiEditor.Layer.OpacitySliderDragEnded}"
                                 DragEnded="{xaml:Command PixiEditor.Layer.OpacitySliderDragEnded}"
@@ -147,12 +147,12 @@
         <DockPanel LastChildFill="True" Grid.Row="2" Margin="0, -12, 0, 0">
         <DockPanel LastChildFill="True" Grid.Row="2" Margin="0, -12, 0, 0">
             <layers:ReferenceLayer
             <layers:ReferenceLayer
                 DockPanel.Dock="Bottom"
                 DockPanel.Dock="Bottom"
-                Document="{Binding Path=ActiveDocument, ElementName=layersManager}"
-                IsVisible="{Binding Path=ActiveDocument, ElementName=layersManager, Converter={converters1:NotNullToVisibilityConverter}}"
+                Document="{Binding Path=DataContext.ActiveDocument, ElementName=layersManager}"
+                IsVisible="{Binding Path=DataContext.ActiveDocument, ElementName=layersManager, Converter={converters1:NotNullToVisibilityConverter}}"
                 Background="{DynamicResource ThemeBackgroundBrush}"
                 Background="{DynamicResource ThemeBackgroundBrush}"
                 Grid.Row="3" VerticalAlignment="Bottom"/>
                 Grid.Row="3" VerticalAlignment="Bottom"/>
             <TreeView ItemContainerTheme="{StaticResource TreeViewItemTheme}" DockPanel.Dock="Top" Name="treeView"
             <TreeView ItemContainerTheme="{StaticResource TreeViewItemTheme}" DockPanel.Dock="Top" Name="treeView"
-                      ItemsSource="{Binding ActiveDocument.StructureRoot.Children, ElementName=layersManager}">
+                      ItemsSource="{Binding DataContext.ActiveDocument.StructureRoot.Children, ElementName=layersManager}">
                 <TreeView.ItemsPanel>
                 <TreeView.ItemsPanel>
                     <ItemsPanelTemplate>
                     <ItemsPanelTemplate>
                         <ui:ReversedOrderStackPanel />
                         <ui:ReversedOrderStackPanel />

+ 0 - 1
src/PixiEditor.AvaloniaUI/Views/MainView.axaml

@@ -32,6 +32,5 @@
                            VerticalAlignment="Center"
                            VerticalAlignment="Center"
                            Tools="{Binding Path=ToolsSubViewModel.ToolSet}"/>
                            Tools="{Binding Path=ToolsSubViewModel.ToolSet}"/>
         <DockControl Grid.Row="1" Layout="{Binding LayoutDockSubViewModel.Layout}"/>
         <DockControl Grid.Row="1" Layout="{Binding LayoutDockSubViewModel.Layout}"/>
-        <layers:LayersManager Grid.Row="1" Width="200" Height="400" ActiveDocument="{Binding Path=DocumentManagerSubViewModel.ActiveDocument}"/>
     </Grid>
     </Grid>
 </UserControl>
 </UserControl>

+ 2 - 2
src/PixiEditor.UI.Common/Controls/Dock/Controls/DockControl.axaml

@@ -18,9 +18,9 @@
             <!--<DataTemplate DataType="dmc:IDocumentContent"> This should be added in the application
             <!--<DataTemplate DataType="dmc:IDocumentContent"> This should be added in the application
               <DocumentContentControl />
               <DocumentContentControl />
             </DataTemplate>-->
             </DataTemplate>-->
-            <DataTemplate DataType="dmc:IToolContent">
+            <!--<DataTemplate DataType="dmc:IToolContent">
               <ToolContentControl />
               <ToolContentControl />
-            </DataTemplate>
+            </DataTemplate>-->
             <DataTemplate DataType="dmc:IProportionalDockSplitter">
             <DataTemplate DataType="dmc:IProportionalDockSplitter">
               <ProportionalStackPanelSplitter />
               <ProportionalStackPanelSplitter />
             </DataTemplate>
             </DataTemplate>