Browse Source

Fixed not clearing layers on empty doc bug, save doc prompt and more

flabbet 4 years ago
parent
commit
94dc19caab

+ 1 - 1
PixiEditor/Helpers/Converters/LayersToStructuredLayersConverter.cs

@@ -15,7 +15,7 @@ namespace PixiEditor.Helpers.Converters
                 return new StructuredLayerTree(layers, structure).RootDirectoryItems;
             }
 
-            return Binding.DoNothing;
+            return new StructuredLayerTree(null, null);
         }
 
         public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)

+ 3 - 0
PixiEditor/Models/DataHolders/Document/Document.Layers.cs

@@ -322,6 +322,7 @@ namespace PixiEditor.Models.DataHolders
             UndoManager.SquashUndoChanges(2, "Removed active layers");
 
             SetNextLayerAsActive(firstIndex);
+
         }
 
         public void AddLayerStructureToUndo(ObservableCollection<GuidStructureItem> oldLayerStructureGroups)
@@ -657,6 +658,8 @@ namespace PixiEditor.Models.DataHolders
                 {
                     SetNextLayerAsActive(index);
                 }
+
+                LayersChanged?.Invoke(this, new LayersChangedEventArgs(layerGuid, LayerAction.Remove));
             }
         }
 

+ 12 - 1
PixiEditor/Models/Layers/GuidStructureItem.cs

@@ -76,6 +76,17 @@ namespace PixiEditor.Models.Layers
             }
         }
 
+        private bool isVisible = true;
+
+        public bool IsVisible
+        {
+            get => isVisible;
+            set
+            {
+                SetProperty(ref isVisible, value);
+            }
+        }
+
         public GuidStructureItem(
             string name,
             Guid startLayerGuid,
@@ -111,7 +122,7 @@ namespace PixiEditor.Models.Layers
         {
             GuidStructureItem item = new(Name, StartLayerGuid, EndLayerGuid, Array.Empty<GuidStructureItem>(), null)
             {
-                GroupGuid = this.GroupGuid,
+                GroupGuid = GroupGuid,
                 IsExpanded = isExpanded,
                 IsRenaming = isRenaming
             };

+ 5 - 0
PixiEditor/Models/Layers/StructuredLayerTree.cs

@@ -16,6 +16,11 @@ namespace PixiEditor.Models.Layers
 
         public StructuredLayerTree(ObservableCollection<Layer> layers, LayerStructure structure)
         {
+            if(layers == null || structure == null)
+            {
+                return;
+            }
+
             if (structure.Groups == null || structure.Groups.Count == 0)
             {
                 RootDirectoryItems.AddRange(layers);

+ 5 - 5
PixiEditor/Styles/DarkScrollBarStyle.xaml

@@ -87,7 +87,7 @@
         <Setter Property="Template">
             <Setter.Value>
                 <ControlTemplate TargetType="{x:Type Thumb}">
-                    <Border CornerRadius="4" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0"  Width="8" Margin="8,0,-2,0"/>
+                    <Border CornerRadius="4" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0"  Width="Auto" Margin="8,0,-2,0"/>
                 </ControlTemplate>
             </Setter.Value>
         </Setter>
@@ -119,9 +119,9 @@
     <ControlTemplate x:Key="HorizontalScrollBar" TargetType="{x:Type ScrollBar}">
         <Grid>
             <Grid.ColumnDefinitions>
-                <ColumnDefinition MaxWidth="18"/>
-                <ColumnDefinition Width="0.00001*"/>
-                <ColumnDefinition MaxWidth="18"/>
+                <ColumnDefinition MaxWidth="2"/>
+                <ColumnDefinition Width="1*"/>
+                <ColumnDefinition MaxWidth="2"/>
             </Grid.ColumnDefinitions>
             <Border Grid.ColumnSpan="3" CornerRadius="2" Background="Transparent"/>
             <RepeatButton Grid.Column="0"  Style="{StaticResource ScrollBarLineButton}" Width="18" Command="ScrollBar.LineLeftCommand" Content="M 4 0 L 4 8 L 0 4 Z" />
@@ -130,7 +130,7 @@
                     <RepeatButton Style="{StaticResource ScrollBarPageButton}" Command="ScrollBar.PageLeftCommand" />
                 </Track.DecreaseRepeatButton>
                 <Track.Thumb>
-                    <Thumb Style="{StaticResource ScrollBarThumb}" Margin="0,1,0,1" Background="{StaticResource NormalBrush}" BorderBrush="{StaticResource NormalBorderBrush}" />
+                    <Thumb Height="10" Style="{StaticResource ScrollBarThumb}" Margin="0,1,0,1" Background="{StaticResource NormalBrush}" BorderBrush="{StaticResource NormalBorderBrush}" />
                 </Track.Thumb>
                 <Track.IncreaseRepeatButton>
                     <RepeatButton Style="{StaticResource ScrollBarPageButton}" Command="ScrollBar.PageRightCommand" />

+ 5 - 2
PixiEditor/Styles/TreeViewStyle.xaml

@@ -63,7 +63,6 @@
     <Style x:Key="TreeViewItemStyle" TargetType="{x:Type TreeViewItem}">
         <Setter Property="Background" Value="Transparent"/>
         <Setter Property="HorizontalContentAlignment" Value="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
-        <Setter Property="VerticalContentAlignment" Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
         <Setter Property="Padding" Value="0,0,0,0"/>
         <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
         <Setter Property="FocusVisualStyle" Value="{StaticResource TreeViewItemFocusVisual}"/>
@@ -120,7 +119,11 @@
     </Style>
 
     <Style TargetType="{x:Type TreeViewItem}" BasedOn="{StaticResource TreeViewItemStyle}">
-        <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
+        <Style.Triggers>
+            <Trigger Property="HasItems" Value="True">
+                <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
+            </Trigger>
+        </Style.Triggers>
         <Setter Property="HorizontalContentAlignment" Value="Stretch" />
     </Style>
 

+ 9 - 1
PixiEditor/ViewModels/SubViewModels/Main/LayersViewModel.cs

@@ -69,7 +69,7 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
 
         public bool CanDeleteSelected(object parameter)
         {
-            return parameter is not null and (Layer or LayerGroup);
+            return (parameter is not null and(Layer or LayerGroup)) || (Owner.BitmapManager?.ActiveDocument?.ActiveLayer != null);
         }
 
         public void DeleteSelected(object parameter)
@@ -78,6 +78,10 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
             {
                 DeleteLayer(Owner.BitmapManager.ActiveDocument.Layers.IndexOf(layer));
             }
+            else if (Owner.BitmapManager.ActiveDocument.ActiveLayer != null)
+            {
+                DeleteLayer(Owner.BitmapManager.ActiveDocument.Layers.IndexOf(Owner.BitmapManager.ActiveDocument.ActiveLayer));
+            }
             else if(parameter is LayerGroup group)
             {
                 DeleteGroup(group.GroupGuid);
@@ -301,6 +305,10 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
             {
                 Owner.BitmapManager.ActiveDocument.UpdateLayersColor();
             }
+            else
+            {
+                Owner.BitmapManager.ActiveDocument.ChangesSaved = false;
+            }
         }
     }
 }

+ 0 - 1
PixiEditor/Views/Dialogs/ResizeDocumentPopup.xaml.cs

@@ -22,7 +22,6 @@ namespace PixiEditor.Views
             DataContext = this;
         }
 
-
         public int NewHeight
         {
             get => (int) GetValue(NewHeightProperty);