Browse Source

Fixed saving

flabbet 1 year ago
parent
commit
968ef41658

BIN
src/PixiEditor/Data/BetaExampleFiles/Tree.pixi


+ 19 - 16
src/PixiEditor/ViewModels/Document/DocumentViewModel.cs

@@ -6,6 +6,7 @@ using System.IO;
 using System.Linq;
 using System.Linq;
 using Avalonia;
 using Avalonia;
 using Avalonia.Media.Imaging;
 using Avalonia.Media.Imaging;
+using Avalonia.Threading;
 using ChunkyImageLib;
 using ChunkyImageLib;
 using ChunkyImageLib.DataHolders;
 using ChunkyImageLib.DataHolders;
 using ChunkyImageLib.Operations;
 using ChunkyImageLib.Operations;
@@ -456,9 +457,9 @@ internal partial class DocumentViewModel : PixiObservableObject, IDocument
         void AddAnimationData(AnimationDataBuilder? data, Dictionary<int, Guid> mappedIds,
         void AddAnimationData(AnimationDataBuilder? data, Dictionary<int, Guid> mappedIds,
             Dictionary<int, Guid> mappedKeyFrameIds)
             Dictionary<int, Guid> mappedKeyFrameIds)
         {
         {
-            if(data is null)
+            if (data is null)
                 return;
                 return;
-            
+
             acc.AddActions(new SetFrameRate_Action(data.FrameRate));
             acc.AddActions(new SetFrameRate_Action(data.FrameRate));
             foreach (var keyFrame in data.KeyFrameGroups)
             foreach (var keyFrame in data.KeyFrameGroups)
             {
             {
@@ -474,7 +475,6 @@ internal partial class DocumentViewModel : PixiObservableObject, IDocument
 
 
                         acc.AddFinishedActions();
                         acc.AddFinishedActions();
                     }
                     }
-
                 }
                 }
             }
             }
         }
         }
@@ -507,13 +507,16 @@ internal partial class DocumentViewModel : PixiObservableObject, IDocument
             {
             {
                 for (int j = 0; j < sizeInChunks.Y; j++)
                 for (int j = 0; j < sizeInChunks.Y; j++)
                 {
                 {
-                    var maybeChunk = Renderer.RenderChunk(new(i, j), ChunkResolution.Full, frameTime);
-                    if (maybeChunk.IsT1)
-                        continue;
-                    using Chunk chunk = maybeChunk.AsT0;
-                    finalSurface.DrawingSurface.Canvas.DrawSurface(
-                        chunk.Surface.DrawingSurface,
-                        i * ChunkyImage.FullChunkSize, j * ChunkyImage.FullChunkSize);
+                    Dispatcher.UIThread.Invoke(() =>
+                    {
+                        var maybeChunk = Renderer.RenderChunk(new(i, j), ChunkResolution.Full, frameTime);
+                        if (maybeChunk.IsT1)
+                            return;
+                        using Chunk chunk = maybeChunk.AsT0;
+                        finalSurface.DrawingSurface.Canvas.DrawSurface(
+                            chunk.Surface.DrawingSurface,
+                            i * ChunkyImage.FullChunkSize, j * ChunkyImage.FullChunkSize);
+                    });
                 }
                 }
             }
             }
 
 
@@ -831,8 +834,8 @@ internal partial class DocumentViewModel : PixiObservableObject, IDocument
     {
     {
         if (AnimationDataViewModel.KeyFrames.Count == 0)
         if (AnimationDataViewModel.KeyFrames.Count == 0)
             return [];
             return [];
-        
-        if(token.IsCancellationRequested)
+
+        if (token.IsCancellationRequested)
             return [];
             return [];
 
 
         int firstFrame = AnimationDataViewModel.FirstFrame;
         int firstFrame = AnimationDataViewModel.FirstFrame;
@@ -840,13 +843,13 @@ internal partial class DocumentViewModel : PixiObservableObject, IDocument
         int lastFrame = firstFrame + framesCount;
         int lastFrame = firstFrame + framesCount;
 
 
         Image[] images = new Image[framesCount];
         Image[] images = new Image[framesCount];
-        
+
         // TODO: Multi-threading
         // TODO: Multi-threading
         for (int i = firstFrame; i < lastFrame; i++)
         for (int i = firstFrame; i < lastFrame; i++)
         {
         {
             if (token.IsCancellationRequested)
             if (token.IsCancellationRequested)
                 return [];
                 return [];
-            
+
             double normalizedTime = (double)(i - firstFrame) / framesCount;
             double normalizedTime = (double)(i - firstFrame) / framesCount;
             KeyFrameTime frameTime = new KeyFrameTime(i, normalizedTime);
             KeyFrameTime frameTime = new KeyFrameTime(i, normalizedTime);
             var surface = TryRenderWholeImage(frameTime);
             var surface = TryRenderWholeImage(frameTime);
@@ -887,9 +890,9 @@ internal partial class DocumentViewModel : PixiObservableObject, IDocument
         {
         {
             if (token.IsCancellationRequested)
             if (token.IsCancellationRequested)
                 return;
                 return;
-            
+
             KeyFrameTime frameTime = new KeyFrameTime(i, (double)(i - firstFrame) / framesCount);
             KeyFrameTime frameTime = new KeyFrameTime(i, (double)(i - firstFrame) / framesCount);
-            
+
             var surface = TryRenderWholeImage(frameTime);
             var surface = TryRenderWholeImage(frameTime);
             if (surface.IsT0)
             if (surface.IsT0)
             {
             {

+ 15 - 6
src/PixiEditor/ViewModels/SubViewModels/FileViewModel.cs

@@ -161,7 +161,8 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
     }
     }
 
 
     [Command.Basic("PixiEditor.File.OpenFileFromClipboard", "OPEN_FILE_FROM_CLIPBOARD",
     [Command.Basic("PixiEditor.File.OpenFileFromClipboard", "OPEN_FILE_FROM_CLIPBOARD",
-        "OPEN_FILE_FROM_CLIPBOARD_DESCRIPTIVE", CanExecute = "PixiEditor.Clipboard.HasImageInClipboard", AnalyticsTrack = true)]
+        "OPEN_FILE_FROM_CLIPBOARD_DESCRIPTIVE", CanExecute = "PixiEditor.Clipboard.HasImageInClipboard",
+        AnalyticsTrack = true)]
     public async Task OpenFromClipboard()
     public async Task OpenFromClipboard()
     {
     {
         var images = await ClipboardController.GetImagesFromClipboard();
         var images = await ClipboardController.GetImagesFromClipboard();
@@ -231,7 +232,7 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
 
 
         AddDocumentViewModelToTheSystem(document);
         AddDocumentViewModelToTheSystem(document);
         AddRecentlyOpened(document.FullFilePath);
         AddRecentlyOpened(document.FullFilePath);
-        
+
         var fileSize = new FileInfo(path).Length;
         var fileSize = new FileInfo(path).Length;
         Analytics.SendOpenFile(PixiFileType.PixiFile, fileSize, document.SizeBindable);
         Analytics.SendOpenFile(PixiFileType.PixiFile, fileSize, document.SizeBindable);
     }
     }
@@ -280,7 +281,8 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
         }
         }
         else
         else
         {
         {
-            CrashHelper.SendExceptionInfoToWebhook(new InvalidFileTypeException(default, $"Invalid file type '{fileType}'"));
+            CrashHelper.SendExceptionInfoToWebhook(new InvalidFileTypeException(default,
+                $"Invalid file type '{fileType}'"));
         }
         }
     }
     }
 
 
@@ -423,13 +425,20 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
                         await Exporter.TrySaveUsingDataFromDialog(doc, info.FilePath, info.ChosenFormat,
                         await Exporter.TrySaveUsingDataFromDialog(doc, info.FilePath, info.ChosenFormat,
                             info.ExportConfig,
                             info.ExportConfig,
                             job);
                             job);
-                    
+
                     if (result.result == SaveResult.Success)
                     if (result.result == SaveResult.Success)
-                        IOperatingSystem.Current.OpenFolder(result.finalPath);
+                    {
+                        Dispatcher.UIThread.Post(() =>
+                        {
+                            IOperatingSystem.Current.OpenFolder(result.finalPath);
+                        });
+                    }
                     else
                     else
+                    {
                         ShowSaveError((DialogSaveResult)result.result);
                         ShowSaveError((DialogSaveResult)result.result);
+                    }
                 });
                 });
-                
+
                 await dialog.ShowDialog();
                 await dialog.ShowDialog();
             }
             }
         }
         }