Browse Source

Fixed save indicator

Krzysztof Krysiński 1 year ago
parent
commit
2587a7b1c6

+ 1 - 1
src/PixiEditor.AvaloniaUI/Models/DocumentModels/DocumentUpdater.cs

@@ -36,7 +36,7 @@ internal class DocumentUpdater
     public void AfterUndoBoundaryPassed()
     {
         //TODO: Make sure AllChangesSaved trigger raise property changed itself
-        //doc.OnPropertyChanged(nameof(doc.AllChangesSaved));
+        doc.UpdateSavedState();
     }
 
     /// <summary>

+ 1 - 0
src/PixiEditor.AvaloniaUI/Models/Handlers/IDocument.cs

@@ -50,4 +50,5 @@ internal interface IDocument : IHandler
     public void SetSize(VecI infoSize);
     public Color PickColor(VecD controllerLastPrecisePosition, DocumentScope scope, bool includeReference, bool includeCanvas, bool isTopMost);
     public List<Guid> ExtractSelectedLayers(bool includeFoldersWithMask = false);
+    public void UpdateSavedState();
 }

+ 1 - 0
src/PixiEditor.AvaloniaUI/Styles/PixiEditor.Controls.axaml

@@ -9,6 +9,7 @@
                 <MergeResourceInclude Source="avares://PixiEditor.AvaloniaUI/Styles/Buttons/DialogButtonTheme.axaml"/>
                 <MergeResourceInclude Source="avares://PixiEditor.AvaloniaUI/Styles/Templates/ShortcutBoxTemplate.axaml"/>
                 <MergeResourceInclude Source="avares://PixiEditor.AvaloniaUI/Styles/Templates/ReferenceLayerOverlay.axaml"/>
+                <MergeResourceInclude Source="avares://PixiEditor.AvaloniaUI/Styles/Templates/DocumentTabTemplate.axaml"/>
             </ResourceDictionary.MergedDictionaries>
         </ResourceDictionary>
     </Styles.Resources>

+ 25 - 0
src/PixiEditor.AvaloniaUI/Styles/Templates/DocumentTabTemplate.axaml

@@ -0,0 +1,25 @@
+<ResourceDictionary xmlns="https://github.com/avaloniaui"
+                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+                    xmlns:controls="clr-namespace:PixiDocks.Avalonia.Controls"
+                    xmlns:docking="clr-namespace:PixiDocks.Core.Docking;assembly=PixiDocks.Core"
+                    xmlns:dock="clr-namespace:PixiEditor.AvaloniaUI.ViewModels.Dock">
+
+    <DataTemplate DataType="dock:DocumentTabCustomizationSettings" x:Key="{x:Type dock:DocumentTabCustomizationSettings}">
+        <DockPanel LastChildFill="False" Margin="5, 0">
+            <Image IsVisible="{Binding !!Icon}" Source="{Binding Icon}"
+                   VerticalAlignment="Center"
+                   RenderOptions.BitmapInterpolationMode="None"
+                   DockPanel.Dock="Left" Width="16" Height="16"/>
+            <TextBlock Padding="5" DockPanel.Dock="Left" Foreground="{DynamicResource ThemeForegroundBrush}"
+                       VerticalAlignment="Center"
+                       Text="{Binding $parent[ContentControl].Tag.Title, FallbackValue=TITLE}"/>
+            <Ellipse Width="5" Height="5" Fill="White" IsVisible="{Binding !IsSaved}"/>
+            <Button Classes="CloseTabButton"
+                    Height="16" Width="16" Margin="5, 0, 0, 0"
+                    VerticalAlignment="Center"
+                    Command="{Binding $parent[ContentControl].Tag.CloseDockable}"
+                    IsVisible="{Binding ShowCloseButton}"
+                    IsEnabled="{Binding $parent[ContentControl].Tag.CanClose}"/>
+        </DockPanel>
+    </DataTemplate>
+</ResourceDictionary>

+ 18 - 0
src/PixiEditor.AvaloniaUI/ViewModels/Dock/DocumentTabCustomizationSettings.cs

@@ -0,0 +1,18 @@
+using PixiDocks.Core.Docking;
+
+namespace PixiEditor.AvaloniaUI.ViewModels.Dock;
+
+public class DocumentTabCustomizationSettings : TabCustomizationSettings
+{
+    private bool isSaved;
+    public bool IsSaved
+    {
+        get => isSaved;
+        set => SetField(ref isSaved, value);
+    }
+
+    public DocumentTabCustomizationSettings(object? icon = null, bool showCloseButton = false, bool isSaved = true) : base(icon, showCloseButton)
+    {
+        IsSaved = isSaved;
+    }
+}

+ 5 - 0
src/PixiEditor.AvaloniaUI/ViewModels/Document/DocumentViewModel.cs

@@ -611,6 +611,11 @@ internal partial class DocumentViewModel : PixiObservableObject, IDocument
         return result;
     }
 
+    public void UpdateSavedState()
+    {
+        OnPropertyChanged(nameof(AllChangesSaved));
+    }
+
     private void ExtractSelectedLayers(FolderViewModel folder, List<Guid> list,
         bool includeFoldersWithMask)
     {

+ 15 - 2
src/PixiEditor.AvaloniaUI/ViewModels/SubViewModels/ViewportWindowViewModel.cs

@@ -6,6 +6,7 @@ using PixiDocks.Core.Docking;
 using PixiDocks.Core.Docking.Events;
 using PixiEditor.AvaloniaUI.Helpers.UI;
 using PixiEditor.AvaloniaUI.Models.DocumentModels;
+using PixiEditor.AvaloniaUI.ViewModels.Dock;
 using PixiEditor.AvaloniaUI.ViewModels.Document;
 using PixiEditor.AvaloniaUI.Views.Visuals;
 using PixiEditor.DrawingApi.Core.Numerics;
@@ -24,7 +25,9 @@ internal class ViewportWindowViewModel : SubViewModel<WindowViewModel>, IDockabl
     public string Title => $"{Document.FileName}{Index}";
     public bool CanFloat => true;
     public bool CanClose => true;
-    public TabCustomizationSettings TabCustomizationSettings { get; } = new(showCloseButton: true);
+    public DocumentTabCustomizationSettings TabCustomizationSettings { get; } = new DocumentTabCustomizationSettings(showCloseButton: true);
+
+    TabCustomizationSettings IDockableContent.TabCustomizationSettings => TabCustomizationSettings;
 
     private bool _closeRequested;
     private string _index = "";
@@ -72,8 +75,18 @@ internal class ViewportWindowViewModel : SubViewModel<WindowViewModel>, IDockabl
 
     private void DocumentOnPropertyChanged(object? sender, PropertyChangedEventArgs e)
     {
-        if(e.PropertyName == nameof(DocumentViewModel.FileName))
+        if (e.PropertyName == nameof(DocumentViewModel.FileName))
+        {
             OnPropertyChanged(nameof(Title));
+        }
+        else if (e.PropertyName == nameof(DocumentViewModel.PreviewSurface))
+        {
+            TabCustomizationSettings.Icon = new SurfaceImage(Document.PreviewSurface);
+        }
+        else if (e.PropertyName == nameof(DocumentViewModel.AllChangesSaved))
+        {
+            TabCustomizationSettings.IsSaved = Document.AllChangesSaved;
+        }
     }
 
     ~ViewportWindowViewModel()