Browse Source

Merge pull request #960 from PixiEditor/file-associations-fix

File associations fix
Krzysztof Krysiński 2 months ago
parent
commit
0f442e17a9
29 changed files with 52 additions and 87 deletions
  1. 1 1
      src/Drawie
  2. 1 1
      src/PixiDocks
  3. 3 0
      src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/StructureNode.cs
  4. 3 40
      src/PixiEditor.MacOs/MacOperatingSystem.cs
  5. 0 2
      src/PixiEditor.OperatingSystem/IOperatingSystem.cs
  6. 1 1
      src/PixiEditor.UI.Common/Accents/Base.axaml
  7. BIN
      src/PixiEditor.UI.Common/Fonts/FiraSans-Black.ttf
  8. BIN
      src/PixiEditor.UI.Common/Fonts/FiraSans-BlackItalic.ttf
  9. BIN
      src/PixiEditor.UI.Common/Fonts/FiraSans-Bold.ttf
  10. BIN
      src/PixiEditor.UI.Common/Fonts/FiraSans-BoldItalic.ttf
  11. BIN
      src/PixiEditor.UI.Common/Fonts/FiraSans-ExtraBold.ttf
  12. BIN
      src/PixiEditor.UI.Common/Fonts/FiraSans-ExtraBoldItalic.ttf
  13. BIN
      src/PixiEditor.UI.Common/Fonts/FiraSans-ExtraLight.ttf
  14. BIN
      src/PixiEditor.UI.Common/Fonts/FiraSans-ExtraLightItalic.ttf
  15. BIN
      src/PixiEditor.UI.Common/Fonts/FiraSans-Italic.ttf
  16. BIN
      src/PixiEditor.UI.Common/Fonts/FiraSans-Light.ttf
  17. BIN
      src/PixiEditor.UI.Common/Fonts/FiraSans-LightItalic.ttf
  18. BIN
      src/PixiEditor.UI.Common/Fonts/FiraSans-Medium.ttf
  19. BIN
      src/PixiEditor.UI.Common/Fonts/FiraSans-MediumItalic.ttf
  20. BIN
      src/PixiEditor.UI.Common/Fonts/FiraSans-Regular.ttf
  21. BIN
      src/PixiEditor.UI.Common/Fonts/FiraSans-SemiBold.ttf
  22. BIN
      src/PixiEditor.UI.Common/Fonts/FiraSans-SemiBoldItalic.ttf
  23. BIN
      src/PixiEditor.UI.Common/Fonts/FiraSans-Thin.ttf
  24. BIN
      src/PixiEditor.UI.Common/Fonts/FiraSans-ThinItalic.ttf
  25. 0 8
      src/PixiEditor.UI.Common/Fonts/FiraSans.axaml
  26. 2 11
      src/PixiEditor.UI.Common/PixiEditor.UI.Common.csproj
  27. 24 5
      src/PixiEditor/Initialization/ClassicDesktopEntry.cs
  28. 11 11
      src/PixiEditor/Models/Rendering/SceneRenderer.cs
  29. 6 7
      src/PixiEditor/ViewModels/SubViewModels/ColorsViewModel.cs

+ 1 - 1
src/Drawie

@@ -1 +1 @@
-Subproject commit e1f7b5c978357058469cae0458211057d9f4cbe8
+Subproject commit 6a22e1b5affd0906a949f97b755ae588eda7980a

+ 1 - 1
src/PixiDocks

@@ -1 +1 @@
-Subproject commit 8c9a1f874ec8d1f7cd773a1f6b044deb0343ad1a
+Subproject commit c6778bd7a33f799263a64d4b39404e1aa05e9dd0

+ 3 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/StructureNode.cs

@@ -5,6 +5,7 @@ using PixiEditor.ChangeableDocument.ChangeInfos.Properties;
 using PixiEditor.ChangeableDocument.Helpers;
 using PixiEditor.ChangeableDocument.Helpers;
 using PixiEditor.ChangeableDocument.Rendering;
 using PixiEditor.ChangeableDocument.Rendering;
 using Drawie.Backend.Core;
 using Drawie.Backend.Core;
+using Drawie.Backend.Core.Bridge;
 using Drawie.Backend.Core.ColorsImpl;
 using Drawie.Backend.Core.ColorsImpl;
 using Drawie.Backend.Core.Numerics;
 using Drawie.Backend.Core.Numerics;
 using Drawie.Backend.Core.Surfaces;
 using Drawie.Backend.Core.Surfaces;
@@ -246,6 +247,7 @@ public abstract class StructureNode : RenderNode, IReadOnlyStructureNode, IRende
 
 
         VecI targetSize = img.LatestSize;
         VecI targetSize = img.LatestSize;
 
 
+        var ctx = DrawingBackendApi.Current.RenderingDispatcher.EnsureContext();
         renderSurface = RequestTexture(textureId, targetSize, processingColorSpace, false);
         renderSurface = RequestTexture(textureId, targetSize, processingColorSpace, false);
 
 
         int saved = renderSurface.DrawingSurface.Canvas.Save();
         int saved = renderSurface.DrawingSurface.Canvas.Save();
@@ -263,6 +265,7 @@ public abstract class StructureNode : RenderNode, IReadOnlyStructureNode, IRende
         }
         }
 
 
         renderSurface.DrawingSurface.Canvas.RestoreToCount(saved);
         renderSurface.DrawingSurface.Canvas.RestoreToCount(saved);
+        ctx?.Dispose();
     }
     }
 
 
     protected void ApplyRasterClip(DrawingSurface toClip, DrawingSurface clipSource)
     protected void ApplyRasterClip(DrawingSurface toClip, DrawingSurface clipSource)

+ 3 - 40
src/PixiEditor.MacOs/MacOperatingSystem.cs

@@ -10,11 +10,10 @@ public sealed class MacOperatingSystem : IOperatingSystem
     public string Name { get; } = "MacOS";
     public string Name { get; } = "MacOS";
 
 
     public string AnalyticsId => "macOS";
     public string AnalyticsId => "macOS";
-    
+
     public IInputKeys InputKeys { get; } = new MacOsInputKeys();
     public IInputKeys InputKeys { get; } = new MacOsInputKeys();
     public IProcessUtility ProcessUtility { get; } = new MacOsProcessUtility();
     public IProcessUtility ProcessUtility { get; } = new MacOsProcessUtility();
 
 
-    private List<Uri> activationUris;
 
 
     public string ExecutableExtension { get; } = string.Empty;
     public string ExecutableExtension { get; } = string.Empty;
 
 
@@ -28,45 +27,9 @@ public sealed class MacOperatingSystem : IOperatingSystem
         ProcessUtility.ShellExecute(Path.GetDirectoryName(path));
         ProcessUtility.ShellExecute(Path.GetDirectoryName(path));
     }
     }
 
 
-    public bool HandleNewInstance(Dispatcher? dispatcher, Action<string, bool> openInExistingAction, IApplicationLifetime lifetime)
+    public bool HandleNewInstance(Dispatcher? dispatcher, Action<string, bool> openInExistingAction,
+        IApplicationLifetime lifetime)
     {
     {
-        StringBuilder args = new StringBuilder();
-        
-        if(activationUris != null)
-        {
-            foreach (var uri in activationUris)
-            {
-                args.Append('"');
-                args.Append(uri.AbsolutePath);
-                args.Append('"');
-                args.Append(' ');
-            }
-        }
-        
-        dispatcher.Invoke(() => openInExistingAction(args.ToString(), true));
         return true;
         return true;
     }
     }
-
-    public void HandleActivatedWithFile(FileActivatedEventArgs fileActivatedEventArgs)
-    {
-        if(activationUris == null)
-        {
-            activationUris = [];
-        }
-        
-        foreach (var file in fileActivatedEventArgs.Files)
-        {
-           activationUris.Add(file.Path);
-        }
-    }
-
-    public void HandleActivatedWithUri(ProtocolActivatedEventArgs openUriEventArgs)
-    {
-        if(activationUris == null)
-        {
-            activationUris = [];
-        }
-        
-        activationUris.Add(openUriEventArgs.Uri);
-    }
 }
 }

+ 0 - 2
src/PixiEditor.OperatingSystem/IOperatingSystem.cs

@@ -33,6 +33,4 @@ public interface IOperatingSystem
     public void OpenUri(string uri);
     public void OpenUri(string uri);
     public void OpenFolder(string path);
     public void OpenFolder(string path);
     public bool HandleNewInstance(Dispatcher? dispatcher, Action<string, bool> openInExistingAction, IApplicationLifetime lifetime);
     public bool HandleNewInstance(Dispatcher? dispatcher, Action<string, bool> openInExistingAction, IApplicationLifetime lifetime);
-    public void HandleActivatedWithFile(FileActivatedEventArgs fileActivatedEventArgs);
-    public void HandleActivatedWithUri(ProtocolActivatedEventArgs openUriEventArgs);
 }
 }

+ 1 - 1
src/PixiEditor.UI.Common/Accents/Base.axaml

@@ -239,7 +239,7 @@
             <SolidColorBrush x:Key="DockThemeControlBackgroundBrush" Color="{DynamicResource ThemeBackground1Color}" />
             <SolidColorBrush x:Key="DockThemeControlBackgroundBrush" Color="{DynamicResource ThemeBackground1Color}" />
             <system:Double x:Key="DockFontSizeNormal">12</system:Double>
             <system:Double x:Key="DockFontSizeNormal">12</system:Double>
 
 
-            <FontFamily x:Key="ContentControlThemeFontFamily">avares://PixiEditor.UI.Common/Fonts#FiraSans, $Default</FontFamily>
+            <FontFamily x:Key="ContentControlThemeFontFamily">Arial</FontFamily>
             <system:Double x:Key="FontSizeSmall">10</system:Double>
             <system:Double x:Key="FontSizeSmall">10</system:Double>
             <system:Double x:Key="FontSizeNormal">12</system:Double>
             <system:Double x:Key="FontSizeNormal">12</system:Double>
             <system:Double x:Key="FontSizeLarge">16</system:Double>
             <system:Double x:Key="FontSizeLarge">16</system:Double>

BIN
src/PixiEditor.UI.Common/Fonts/FiraSans-Black.ttf


BIN
src/PixiEditor.UI.Common/Fonts/FiraSans-BlackItalic.ttf


BIN
src/PixiEditor.UI.Common/Fonts/FiraSans-Bold.ttf


BIN
src/PixiEditor.UI.Common/Fonts/FiraSans-BoldItalic.ttf


BIN
src/PixiEditor.UI.Common/Fonts/FiraSans-ExtraBold.ttf


BIN
src/PixiEditor.UI.Common/Fonts/FiraSans-ExtraBoldItalic.ttf


BIN
src/PixiEditor.UI.Common/Fonts/FiraSans-ExtraLight.ttf


BIN
src/PixiEditor.UI.Common/Fonts/FiraSans-ExtraLightItalic.ttf


BIN
src/PixiEditor.UI.Common/Fonts/FiraSans-Italic.ttf


BIN
src/PixiEditor.UI.Common/Fonts/FiraSans-Light.ttf


BIN
src/PixiEditor.UI.Common/Fonts/FiraSans-LightItalic.ttf


BIN
src/PixiEditor.UI.Common/Fonts/FiraSans-Medium.ttf


BIN
src/PixiEditor.UI.Common/Fonts/FiraSans-MediumItalic.ttf


BIN
src/PixiEditor.UI.Common/Fonts/FiraSans-Regular.ttf


BIN
src/PixiEditor.UI.Common/Fonts/FiraSans-SemiBold.ttf


BIN
src/PixiEditor.UI.Common/Fonts/FiraSans-SemiBoldItalic.ttf


BIN
src/PixiEditor.UI.Common/Fonts/FiraSans-Thin.ttf


BIN
src/PixiEditor.UI.Common/Fonts/FiraSans-ThinItalic.ttf


+ 0 - 8
src/PixiEditor.UI.Common/Fonts/FiraSans.axaml

@@ -1,8 +0,0 @@
-<Styles xmlns="https://github.com/avaloniaui"
-                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
-    <Styles.Resources>
-        <ResourceDictionary>
-            <FontFamily x:Key="FiraSans">avares://PixiEditor.UI.Common/Fonts#FiraSans</FontFamily>
-        </ResourceDictionary>
-    </Styles.Resources>
-</Styles>

+ 2 - 11
src/PixiEditor.UI.Common/PixiEditor.UI.Common.csproj

@@ -7,10 +7,8 @@
     </PropertyGroup>
     </PropertyGroup>
 
 
     <ItemGroup>
     <ItemGroup>
-      <AvaloniaResource Include="Assets\*"/>
-      <None Remove="Assets\Animations\LoadingIndicator.json" />
-      <AvaloniaResource Include="Assets\Animations\LoadingIndicator.json" />
-      <AvaloniaResource Include="Fonts\PixiPerfect.ttf" />
+      <AvaloniaResource Include="Assets/**"/>
+      <AvaloniaResource Include="Fonts/**"/>
     </ItemGroup>
     </ItemGroup>
 
 
     <ItemGroup>
     <ItemGroup>
@@ -19,11 +17,4 @@
       <PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.0.5" />
       <PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.0.5" />
       <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
       <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
     </ItemGroup>
     </ItemGroup>
-
-    <ItemGroup>
-      <Compile Update="Controls\SizeInput.axaml.cs">
-        <DependentUpon>SizeInput.axaml</DependentUpon>
-        <SubType>Code</SubType>
-      </Compile>
-    </ItemGroup>
 </Project>
 </Project>

+ 24 - 5
src/PixiEditor/Initialization/ClassicDesktopEntry.cs

@@ -7,6 +7,7 @@ using System.Threading.Tasks;
 using Avalonia;
 using Avalonia;
 using Avalonia.Controls;
 using Avalonia.Controls;
 using Avalonia.Controls.ApplicationLifetimes;
 using Avalonia.Controls.ApplicationLifetimes;
+using Avalonia.Platform.Storage;
 using Avalonia.Threading;
 using Avalonia.Threading;
 using Avalonia.Xaml.Interactivity;
 using Avalonia.Xaml.Interactivity;
 using PixiEditor.Extensions.Runtime;
 using PixiEditor.Extensions.Runtime;
@@ -48,13 +49,26 @@ internal class ClassicDesktopEntry
 
 
     private void ActivableOnActivated(object? sender, ActivatedEventArgs e)
     private void ActivableOnActivated(object? sender, ActivatedEventArgs e)
     {
     {
+        // TODO: Handle activation more generically. This only is handled by macos btw.
+        if (desktop.MainWindow is not MainWindow mainWindow) return;
         if (e.Kind == ActivationKind.File && e is FileActivatedEventArgs fileActivatedEventArgs)
         if (e.Kind == ActivationKind.File && e is FileActivatedEventArgs fileActivatedEventArgs)
         {
         {
-            IOperatingSystem.Current.HandleActivatedWithFile(fileActivatedEventArgs);
+            foreach (var storageItem in fileActivatedEventArgs.Files)
+            {
+                string? file = storageItem.TryGetLocalPath();
+                if (file != null && File.Exists(file))
+                {
+                    mainWindow.DataContext.FileSubViewModel.OpenFromPath(file);
+                }
+            }
         }
         }
         else if (e.Kind == ActivationKind.OpenUri && e is ProtocolActivatedEventArgs openUriEventArgs)
         else if (e.Kind == ActivationKind.OpenUri && e is ProtocolActivatedEventArgs openUriEventArgs)
         {
         {
-            IOperatingSystem.Current.HandleActivatedWithUri(openUriEventArgs);
+            var uri = openUriEventArgs.Uri;
+            if (uri.Scheme == "lospec-palette")
+            {
+                Dispatcher.UIThread.InvokeAsync(async () => await mainWindow.DataContext.ColorsSubViewModel.ImportLospecPalette(uri.AbsoluteUri));
+            }
         }
         }
     }
     }
 
 
@@ -90,7 +104,7 @@ internal class ClassicDesktopEntry
 
 
             return;
             return;
         }
         }
-        
+
 #if !STEAM && !DEBUG
 #if !STEAM && !DEBUG
         if (!HandleNewInstance(Dispatcher.UIThread))
         if (!HandleNewInstance(Dispatcher.UIThread))
         {
         {
@@ -119,7 +133,8 @@ internal class ClassicDesktopEntry
 
 
         NumberInput.AttachGlobalBehaviors += AttachGlobalShortcutBehavior;
         NumberInput.AttachGlobalBehaviors += AttachGlobalShortcutBehavior;
 
 
-        ExtensionLoader extensionLoader = new ExtensionLoader([Paths.InstallDirExtensionPackagesPath, Paths.LocalExtensionPackagesPath], Paths.UserExtensionsPath);
+        ExtensionLoader extensionLoader = new ExtensionLoader(
+            [Paths.InstallDirExtensionPackagesPath, Paths.LocalExtensionPackagesPath], Paths.UserExtensionsPath);
         //TODO: fetch from extension store
         //TODO: fetch from extension store
         extensionLoader.AddOfficialExtension("pixieditor.founderspack",
         extensionLoader.AddOfficialExtension("pixieditor.founderspack",
             new OfficialExtensionData("supporter-pack.snk", AdditionalContentProduct.SupporterPack));
             new OfficialExtensionData("supporter-pack.snk", AdditionalContentProduct.SupporterPack));
@@ -222,10 +237,14 @@ internal class ClassicDesktopEntry
                         new LocalizedString("SESSION_UNSAVED_DATA", "Shutdown"),
                         new LocalizedString("SESSION_UNSAVED_DATA", "Shutdown"),
                         $"Shutdown");
                         $"Shutdown");
 
 
-                    if (confirmation != ConfirmationType.Yes)
+                    if (confirmation == ConfirmationType.Yes)
                     {
                     {
                         desktop.Shutdown();
                         desktop.Shutdown();
                     }
                     }
+                    else
+                    {
+                        e.Cancel = true;
+                    }
                 });
                 });
             });
             });
         }
         }

+ 11 - 11
src/PixiEditor/Models/Rendering/SceneRenderer.cs

@@ -56,15 +56,13 @@ internal class SceneRenderer : IDisposable
             var rendered = RenderGraph(target, resolution, targetOutput, finalGraph);
             var rendered = RenderGraph(target, resolution, targetOutput, finalGraph);
             cachedTextures[adjustedTargetOutput] = rendered;
             cachedTextures[adjustedTargetOutput] = rendered;
         }
         }
-        else
-        {
-            var cachedTexture = cachedTextures[adjustedTargetOutput];
-            Matrix3X3 matrixDiff = SolveMatrixDiff(target, cachedTexture);
-            int saved = target.Canvas.Save();
-            target.Canvas.SetMatrix(matrixDiff);
-            target.Canvas.DrawSurface(cachedTexture.DrawingSurface, 0, 0);
-            target.Canvas.RestoreToCount(saved);
-        }
+
+        var cachedTexture = cachedTextures[adjustedTargetOutput];
+        Matrix3X3 matrixDiff = SolveMatrixDiff(target, cachedTexture);
+        int saved = target.Canvas.Save();
+        target.Canvas.SetMatrix(matrixDiff);
+        target.Canvas.DrawSurface(cachedTexture.DrawingSurface, 0, 0);
+        target.Canvas.RestoreToCount(saved);
     }
     }
 
 
     private Texture RenderGraph(DrawingSurface target, ChunkResolution resolution, string? targetOutput,
     private Texture RenderGraph(DrawingSurface target, ChunkResolution resolution, string? targetOutput,
@@ -263,7 +261,8 @@ internal class SceneRenderer : IDisposable
 
 
             double finalOpacity = onionOpacity * alphaFalloffMultiplier * (animationData.OnionFrames - i + 1);
             double finalOpacity = onionOpacity * alphaFalloffMultiplier * (animationData.OnionFrames - i + 1);
 
 
-            RenderContext onionContext = new(target, frame, resolution, renderOutputSize, Document.Size, Document.ProcessingColorSpace,
+            RenderContext onionContext = new(target, frame, resolution, renderOutputSize, Document.Size,
+                Document.ProcessingColorSpace,
                 finalOpacity);
                 finalOpacity);
             onionContext.TargetOutput = targetOutput;
             onionContext.TargetOutput = targetOutput;
             finalGraph.Execute(onionContext);
             finalGraph.Execute(onionContext);
@@ -279,7 +278,8 @@ internal class SceneRenderer : IDisposable
             }
             }
 
 
             double finalOpacity = onionOpacity * alphaFalloffMultiplier * (animationData.OnionFrames - i + 1);
             double finalOpacity = onionOpacity * alphaFalloffMultiplier * (animationData.OnionFrames - i + 1);
-            RenderContext onionContext = new(target, frame, resolution, renderOutputSize, Document.Size, Document.ProcessingColorSpace,
+            RenderContext onionContext = new(target, frame, resolution, renderOutputSize, Document.Size,
+                Document.ProcessingColorSpace,
                 finalOpacity);
                 finalOpacity);
             onionContext.TargetOutput = targetOutput;
             onionContext.TargetOutput = targetOutput;
             finalGraph.Execute(onionContext);
             finalGraph.Execute(onionContext);

+ 6 - 7
src/PixiEditor/ViewModels/SubViewModels/ColorsViewModel.cs

@@ -166,7 +166,9 @@ internal class ColorsViewModel : SubViewModel<ViewModelMain>, IColorsHandler
 
 
     private async void OwnerOnStartupEvent()
     private async void OwnerOnStartupEvent()
     {
     {
-        await ImportLospecPalette();
+        var args = StartupArgs.Args;
+        var lospecPaletteArg = args.FirstOrDefault(x => x.StartsWith("lospec-palette://"));
+        await ImportLospecPalette(lospecPaletteArg);
     }
     }
 
 
     [Commands_Command.Basic("PixiEditor.Colors.OpenPaletteBrowser", "OPEN_PALETTE_BROWSER", "OPEN_PALETTE_BROWSER",
     [Commands_Command.Basic("PixiEditor.Colors.OpenPaletteBrowser", "OPEN_PALETTE_BROWSER", "OPEN_PALETTE_BROWSER",
@@ -177,17 +179,14 @@ internal class ColorsViewModel : SubViewModel<ViewModelMain>, IColorsHandler
         PalettesBrowser.Open();
         PalettesBrowser.Open();
     }
     }
 
 
-    private async Task ImportLospecPalette()
+    public async Task ImportLospecPalette(string? uri)
     {
     {
-        var args = StartupArgs.Args;
-        var lospecPaletteArg = args.FirstOrDefault(x => x.StartsWith("lospec-palette://"));
-
-        if (lospecPaletteArg != null)
+        if (uri != null)
         {
         {
             var browser = PalettesBrowser.Open();
             var browser = PalettesBrowser.Open();
 
 
             browser.IsFetching = true;
             browser.IsFetching = true;
-            var palette = await LospecPaletteFetcher.FetchPalette(lospecPaletteArg.Split(@"://")[1].Replace("/", ""));
+            var palette = await LospecPaletteFetcher.FetchPalette(uri.Split(@"://")[1].Replace("/", ""));
             if (palette != null)
             if (palette != null)
             {
             {
                 if (LocalPalettesFetcher.PaletteExists(palette.Name))
                 if (LocalPalettesFetcher.PaletteExists(palette.Name))