Browse Source

Made sample extension work

Krzysztof Krysiński 1 year ago
parent
commit
72bb32fd5d

+ 2 - 4
src/PixiEditor.AvaloniaUI/Models/AppExtensions/Services/WindowProvider.cs

@@ -1,5 +1,6 @@
 using System.Collections.Generic;
 using System.Linq;
+using PixiEditor.AvaloniaUI.Views.Dialogs;
 using PixiEditor.Extensions;
 using PixiEditor.Extensions.Windowing;
 
@@ -23,10 +24,7 @@ public class WindowProvider : IWindowProvider
 
     public PopupWindow CreatePopupWindow(string title, object body)
     {
-        //TODO: Implement BasicPopup
-        //return new PopupWindow(new BasicPopup { Title = title, Body = body });
-
-        return null;
+        return new PopupWindow(new PixiEditorPopup() { Title = title, Content = body });
     }
 
     public PopupWindow OpenWindow(WindowType type)

+ 25 - 2
src/PixiEditor.AvaloniaUI/Models/Localization/LocalizationProvider.cs

@@ -177,8 +177,31 @@ internal class LocalizationProvider : ILocalizationProvider
     private IDictionary<string, string> ReadLocaleFile(string localePath)
     {
         JsonSerializer serializer = new();
-        using Stream stream = AssetLoader.Open(new Uri(localePath));
-        return serializer.Deserialize<Dictionary<string, string>>(new JsonTextReader(new StreamReader(stream)));
+        Stream stream = null;
+        if (!localePath.StartsWith("avares://"))
+        {
+            if (!File.Exists(localePath))
+            {
+                throw new FileNotFoundException("Locale file not found.", localePath);
+            }
+
+            stream = File.OpenRead(localePath);
+        }
+        else
+        {
+            Uri uri = new Uri(localePath);
+            if (!AssetLoader.Exists(uri))
+            {
+                throw new FileNotFoundException("Locale file not found.", localePath);
+            }
+
+            stream = AssetLoader.Open(new Uri(localePath));
+        }
+
+        var result = serializer.Deserialize<Dictionary<string, string>>(new JsonTextReader(new StreamReader(stream)));
+        stream.Dispose();
+
+        return result;
     }
 
     private string GetLocalePath(LanguageData languageData)

+ 11 - 2
src/PixiEditor.AvaloniaUI/Views/Dialogs/PixiEditorPopup.cs

@@ -1,15 +1,19 @@
-using System.Windows.Input;
+using System.Threading.Tasks;
+using System.Windows.Input;
 using Avalonia;
 using Avalonia.Controls;
 using Avalonia.Controls.Primitives;
 using Avalonia.Styling;
 using CommunityToolkit.Mvvm.Input;
 using PixiEditor.AvaloniaUI.Helpers.Extensions;
+using PixiEditor.Extensions;
 
 namespace PixiEditor.AvaloniaUI.Views.Dialogs;
 
-public partial class PixiEditorPopup : Window, IStyleable
+public partial class PixiEditorPopup : Window, IStyleable, IPopupWindow
 {
+    public string UniqueId => "PixiEditor.Popup";
+
     public static readonly StyledProperty<bool> CanMinimizeProperty = AvaloniaProperty.Register<PixiEditorPopup, bool>(
         nameof(CanMinimize), defaultValue: true);
 
@@ -49,6 +53,11 @@ public partial class PixiEditorPopup : Window, IStyleable
         Show(MainWindow.Current);
     }
 
+    public async Task<bool?> ShowDialog()
+    {
+        return await ShowDialog<bool?>(MainWindow.Current);
+    }
+
     [RelayCommand]
     public void SetResultAndCloseCommand()
     {

+ 0 - 12
src/PixiEditor.AvaloniaUI/Views/Main/ViewportControls/Viewport.axaml

@@ -333,18 +333,6 @@
                         </Grid.Resources>
                         <visuals:GridLines Scale="{Binding Zoombox.Scale}" IsVisible="{Binding Zoombox.Scale, Converter={StaticResource ThresholdVisibilityConverter}}"
                                            Rows="{Binding Document.Width}" Columns="{Binding Document.Height}"/>
-                        <!--<Rectangle Focusable="False" IsVisible="{Binding Zoombox.Scale, Converter={StaticResource ThresholdVisibilityConverter}}">
-                            <Rectangle.Fill>
-                                <VisualBrush DestinationRect="{Binding Document.Width, Converter={converters:IntToViewportRectConverter}, ConverterParameter=vertical}"
-                                            TileMode="Tile">
-                                    <VisualBrush.Visual>
-                                        <
-                                        <Line StartPoint="0, 0" EndPoint="0, 1" Stroke="Black"
-                                              StrokeThickness="}"/>
-                                    </VisualBrush.Visual>
-                                </VisualBrush>
-                            </Rectangle.Fill>
-                        </Rectangle>-->
                     </Grid>
                     <Rectangle Stroke="{DynamicResource ThemeBackgroundBrush1}" Opacity=".8" ZIndex="2"
                                IsVisible="{Binding Document.ReferenceLayerViewModel.IsVisibleBindable}">

+ 6 - 3
src/SampleExtension/SampleExtension.cs

@@ -1,4 +1,7 @@
-using PixiEditor.Extensions;
+using Avalonia.Controls;
+using Avalonia.Layout;
+using Avalonia.Media;
+using PixiEditor.Extensions;
 
 namespace SampleExtension;
 
@@ -10,12 +13,12 @@ public class SampleExtension : Extension
 
     protected override void OnInitialized()
     {
-        /*var popup = Api.WindowProvider.CreatePopupWindow("Hello World!", new TextBlock
+        var popup = Api.WindowProvider.CreatePopupWindow("Hello World!", new TextBlock
         {
             Text = "Hello World!", Foreground = Brushes.White,
             HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center
         });
         Api.PaletteProvider.RegisterDataSource(new TestPaletteDataSource());
-        popup.ShowDialog();*/
+        popup.ShowDialog();
     }
 }

+ 2 - 2
src/SampleExtension/SampleExtension.csproj

@@ -1,10 +1,10 @@
 <Project Sdk="Microsoft.NET.Sdk">
 
     <PropertyGroup>
-        <TargetFramework>net8.0-windows</TargetFramework>
+        <TargetFramework>net8.0</TargetFramework>
         <ImplicitUsings>enable</ImplicitUsings>
         <Nullable>enable</Nullable>
-      <OutputPath>..\PixiEditor\bin\Debug\net7.0-windows\Extensions</OutputPath>
+      <OutputPath>..\PixiEditor.AvaloniaUI.Desktop\bin\Debug\net8.0\Extensions</OutputPath>
     </PropertyGroup>
 
     <ItemGroup>