Browse Source

Merge branch 'flyui-hyperlink' into release-pipelines

flabbet 8 months ago
parent
commit
92c003499d

+ 2 - 2
src/PixiEditor.Beta/BetaExtension.cs

@@ -6,9 +6,9 @@ public class BetaExtension : PixiEditorExtension
 {
     public override void OnInitialized()
     {
-        if (Api.Preferences.GetPreference<bool>("BetaWelcomeShown"))
+        //if (Api.Preferences.GetPreference<bool>("BetaWelcomeShown"))
         {
-            return;
+         //   return;
         }
 
         WelcomeMessage welcomeMessage = new();

+ 11 - 6
src/PixiEditor.Beta/WelcomeMessageState.cs

@@ -5,15 +5,17 @@ namespace PixiEditor.Beta;
 
 public class WelcomeMessageState : State
 {
-    private const string Body = @"
-We are extremely exicted to share this version to you, early testers. Before you jump in and test all the new things,
-we have a few things to note:
+    private const string Body1 = @"
+We are extremely excited to share this version with you, early testers. Before you jump in and test all the new things, we have a few things to note:
 
 - This is a very early version of PixiEditor 2.0. Not every feature promised in the roadmap is
   implemented yet. 
+
 - App is not production ready! Expect bugs, crashes, unfinished features, placeholders and other signs of development.
-- Your feedback is the most important thing of this beta, please take a moment to report any issues and suggestions on PixiEditor Forum.
-(forum.pixieditor.net)
+";
+    
+private const string Body2 = "- Your feedback is the most important thing of this beta, please take a moment to report any issues and suggestions on PixiEditor Forum.";
+private const string Body3 = @"
 - We are collecting anonymous usage data to fix bugs, crashes and performance issues. This data will help us to improve the app. During the beta 
 there is no option to opt-out. No personal data is collected.
 
@@ -35,7 +37,10 @@ I understand that:
                     new Center(new Text("Welcome to the open beta of PixiEditor 2.0!", TextWrap.Wrap,
                         FontStyle.Normal,
                         fontSize: 24)),
-                    new Text(Body, TextWrap.Wrap, fontSize: 16),
+                    new Text(Body1, TextWrap.Wrap, fontSize: 16),
+                    new Hyperlink("https://forum.pixieditor.net", Body2,
+                        fontSize: 16, textWrap: TextWrap.Wrap),
+                    new Text(Body3, TextWrap.Wrap, fontSize: 16),
                     new CheckBox(
                         new Text("The app may be unstable, crash or freeze", fontSize: 16,
                             fontStyle: FontStyle.Italic),

+ 27 - 0
src/PixiEditor.Extensions.Sdk/Api/FlyUI/Hyperlink.cs

@@ -0,0 +1,27 @@
+using PixiEditor.Extensions.CommonApi.FlyUI.Properties;
+
+namespace PixiEditor.Extensions.Sdk.Api.FlyUI;
+
+public class Hyperlink : Text
+{
+    public string Url { get; set; }
+
+    public Hyperlink(string url, string text, TextWrap textWrap = TextWrap.None, FontStyle fontStyle = FontStyle.Normal,
+        double fontSize = 12) : base(text, textWrap, fontStyle, fontSize)
+    {
+        Url = url;
+    }
+
+    public override CompiledControl BuildNative()
+    {
+        CompiledControl hyperlink = new CompiledControl(UniqueId, "Hyperlink");
+        hyperlink.AddProperty(Value);
+        hyperlink.AddProperty(TextWrap);
+        hyperlink.AddProperty(FontStyle);
+        hyperlink.AddProperty(FontSize);
+        hyperlink.AddProperty(Url);
+
+        BuildPendingEvents(hyperlink);
+        return hyperlink;
+    }
+}

+ 45 - 0
src/PixiEditor.Extensions/FlyUI/Elements/Hyperlink.cs

@@ -0,0 +1,45 @@
+using System.Collections.Immutable;
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Data;
+using PixiEditor.Extensions.CommonApi.FlyUI;
+using PixiEditor.Extensions.CommonApi.FlyUI.Properties;
+
+namespace PixiEditor.Extensions.FlyUI.Elements;
+
+public class Hyperlink : Text
+{
+    public string Url { get; set; }
+
+    public Hyperlink(string text, string url, TextWrap textWrap = TextWrap.None, FontStyle fontStyle = FontStyle.Normal,
+        double fontSize = 12) : base(text, textWrap, fontStyle, fontSize)
+    {
+        Url = url;
+    }
+
+    public override Control BuildNative()
+    {
+        TextBlock hyperlink = (TextBlock)base.BuildNative();
+
+        Binding urlBinding = new Binding() { Source = this, Path = nameof(Url), };
+
+        hyperlink.Bind(UI.Hyperlink.UrlProperty, urlBinding);
+
+        return hyperlink;
+    }
+
+    public override IEnumerable<object> GetProperties()
+    {
+        yield return Value;
+        yield return TextWrap;
+        yield return FontStyle;
+        yield return FontSize;
+        yield return Url;
+    }
+
+    public override void DeserializeProperties(ImmutableList<object> values)
+    {
+        base.DeserializeProperties(values);
+        Url = (string)values[4];
+    }
+}

+ 12 - 1
src/PixiEditor.Extensions/FlyUI/Elements/LayoutBuilder.cs

@@ -1,4 +1,5 @@
 using System.Collections.Immutable;
+using System.Reflection;
 using System.Text;
 using Avalonia.Controls;
 using PixiEditor.Extensions.CommonApi.FlyUI;
@@ -165,10 +166,20 @@ public class LayoutBuilder
 
         var constructorWithParams = typeToSpawn.GetConstructors()[0];
         var parameters = constructorWithParams.GetParameters();
-        var parameterValues = parameters.Select(x => x.DefaultValue).ToArray();
+        var parameterValues = parameters.Select(x => x.HasDefaultValue ? x.DefaultValue : TryGetDefault(x)).ToArray(); 
         return (ILayoutElement<Control>)Activator.CreateInstance(typeToSpawn, parameterValues);
     }
 
+    private static object? TryGetDefault(ParameterInfo x)
+    {
+        if (x.ParameterType == typeof(string))
+        {
+            return string.Empty;
+        }
+        
+        return Activator.CreateInstance(x.ParameterType);
+    }
+
     private void RemoveChildren(IChildHost childHost)
     {
         foreach (var child in childHost)

+ 2 - 2
src/PixiEditor.Extensions/FlyUI/Elements/Text.cs

@@ -70,7 +70,7 @@ public class Text : StatelessElement, IPropertyDeserializable
         return textBlock;
     }
 
-    IEnumerable<object> IPropertyDeserializable.GetProperties()
+    public virtual IEnumerable<object> GetProperties()
     {
         yield return Value;
         yield return TextWrap;
@@ -78,7 +78,7 @@ public class Text : StatelessElement, IPropertyDeserializable
         yield return FontSize;
     }
 
-    void IPropertyDeserializable.DeserializeProperties(ImmutableList<object> values)
+    public virtual void DeserializeProperties(ImmutableList<object> values)
     {
         Value = (string)values.ElementAtOrDefault(0);
         TextWrap = (TextWrap)values.ElementAtOrDefault(1);

+ 1 - 0
src/PixiEditor.Extensions/PixiEditor.Extensions.csproj

@@ -24,5 +24,6 @@
       <ProjectReference Include="..\Drawie\src\Drawie.Backend.Core\Drawie.Backend.Core.csproj" />
       <ProjectReference Include="..\Drawie\src\Drawie.Numerics\Drawie.Numerics.csproj" />
       <ProjectReference Include="..\PixiEditor.Extensions.CommonApi\PixiEditor.Extensions.CommonApi.csproj" />
+      <ProjectReference Include="..\PixiEditor.OperatingSystem\PixiEditor.OperatingSystem.csproj" />
     </ItemGroup>
 </Project>

+ 5 - 5
src/PixiEditor/Helpers/UI/Hyperlink.cs → src/PixiEditor.Extensions/UI/Hyperlink.cs

@@ -4,7 +4,7 @@ using Avalonia.Controls;
 using Avalonia.Input;
 using PixiEditor.OperatingSystem;
 
-namespace PixiEditor.Helpers.UI;
+namespace PixiEditor.Extensions.UI;
 
 public class Hyperlink : AvaloniaObject
 {
@@ -36,11 +36,11 @@ public class Hyperlink : AvaloniaObject
 
     static Hyperlink()
     {
-        UrlProperty.Changed.Subscribe(OnUrlSet);
-        CommandProperty.Changed.Subscribe(OnCommandSet);
+        UrlProperty.Changed.AddClassHandler<TextBlock>(OnUrlSet);
+        CommandProperty.Changed.AddClassHandler<TextBlock>(OnCommandSet);
     }
 
-    private static void OnUrlSet(AvaloniaPropertyChangedEventArgs e)
+    private static void OnUrlSet(TextBlock textBlock, AvaloniaPropertyChangedEventArgs e)
     {
         if (e.Sender is TextBlock tb)
         {
@@ -59,7 +59,7 @@ public class Hyperlink : AvaloniaObject
         }
     }
 
-    private static void OnCommandSet(AvaloniaPropertyChangedEventArgs e)
+    private static void OnCommandSet(TextBlock textBlock, AvaloniaPropertyChangedEventArgs e)
     {
         if (e.Sender is TextBlock tb)
         {

+ 7 - 7
src/PixiEditor/Views/Dialogs/AboutPopup.axaml

@@ -29,7 +29,7 @@
                     </Ellipse.Fill>
                 </Ellipse>
                 <Label  Margin="10 0 0 0" FontSize="14">
-                    <TextBlock ui1:Hyperlink.Url="https://github.com/flabbet" >
+                    <TextBlock ui:Hyperlink.Url="https://github.com/flabbet" >
                         <Run Text="Krzysztof Krysiński (flabbet)"/>
                         <Run Text="{DynamicResource icon-link}" Classes="pixi-icon"/>
                     </TextBlock>
@@ -42,7 +42,7 @@
                     </Ellipse.Fill>
                 </Ellipse>
                 <Label Margin="10 0 0 0" FontSize="14">
-                    <TextBlock ui1:Hyperlink.Url="https://github.com/equbuxu" >
+                    <TextBlock ui:Hyperlink.Url="https://github.com/equbuxu" >
                         <Run Text="Egor Mozgovoy (Equbuxu)"/>
                         <Run Text="{DynamicResource icon-link}" Classes="pixi-icon"/>
                     </TextBlock>
@@ -55,7 +55,7 @@
                     </Ellipse.Fill>
                 </Ellipse>
                 <Label Margin="10 0 0 0" FontSize="14">
-                    <TextBlock ui1:Hyperlink.Url="https://github.com/CPKreuz" >
+                    <TextBlock ui:Hyperlink.Url="https://github.com/CPKreuz" >
                         <Run Text="Philip Kreuz (cpk)"/>
                         <Run Text="{DynamicResource icon-link}" Classes="pixi-icon"/>
                     </TextBlock>
@@ -63,7 +63,7 @@
             </StackPanel>
 
             <Label Margin="20 10 0 0" FontSize="14">
-                <TextBlock ui1:Hyperlink.Url="https://github.com/PixiEditor/PixiEditor/graphs/contributors">
+                <TextBlock ui:Hyperlink.Url="https://github.com/PixiEditor/PixiEditor/graphs/contributors">
                     <Run ui:Translator.Key="OTHER_AWESOME_CONTRIBUTORS" />
                     <Run Text="{DynamicResource icon-link}" Classes="pixi-icon"/>
                 </TextBlock>
@@ -72,21 +72,21 @@
             <Separator Margin="0 10 0 0"/>
 
             <Label Margin="20 10 0 0" FontSize="14">
-                <TextBlock ui1:Hyperlink.Url="LICENSE">
+                <TextBlock ui:Hyperlink.Url="LICENSE">
                     <Run ui:Translator.Key="LICENSE"/>
                     <Run Text="{DynamicResource icon-link}" Classes="pixi-icon"/>
                 </TextBlock>
             </Label>
 
             <Label Margin="20 10 0 0" FontSize="14">
-                <TextBlock ui1:Hyperlink.Url="Third Party Licenses">
+                <TextBlock ui:Hyperlink.Url="Third Party Licenses">
                     <Run ui:Translator.Key="THIRD_PARTY_LICENSES"/>
                     <Run Text="{DynamicResource icon-link}" Classes="pixi-icon"/>
                 </TextBlock>
             </Label>
 
             <Label Margin="20 10 0 0" FontSize="14">
-                <TextBlock ui1:Hyperlink.Url="https://pixieditor.net/docs/introduction">
+                <TextBlock ui:Hyperlink.Url="https://pixieditor.net/docs/introduction">
                     <Run ui:Translator.Key="DOCUMENTATION" />
                     <Run Text="{DynamicResource icon-link}" Classes="pixi-icon"/>
                 </TextBlock>

+ 1 - 1
src/PixiEditor/Views/Dialogs/Debugging/Localization/LocalizationDebugWindow.axaml

@@ -128,7 +128,7 @@
                         <Border Background="{Binding SelectedLanguage.StatusBrush}" CornerRadius="2" />
                         <TextBlock Grid.Column="1"
                                    ui:Translator.LocalizedString="{Binding SelectedLanguage.StatusText}" Margin="5,0" />
-                        <TextBlock ui1:Hyperlink.Command="{Binding CopySelectedUpdatedCommand}" Grid.Column="2" ui:Translator.TooltipKey="COPY_TO_CLIPBOARD">
+                        <TextBlock ui:Hyperlink.Command="{Binding CopySelectedUpdatedCommand}" Grid.Column="2" ui:Translator.TooltipKey="COPY_TO_CLIPBOARD">
                             <Run
                                 Text="{Binding SelectedLanguage.UpdatedLocal, Mode=OneWay, StringFormat='g'}" />
                             <Run Text=" &#xe855;" FontFamily="{DynamicResource Feather}" />

+ 3 - 3
src/PixiEditor/Views/Dialogs/ShortcutsPopup.axaml

@@ -33,10 +33,10 @@
         <DockPanel>
             <TextBlock Margin="10"
                        HorizontalAlignment="Left" DockPanel.Dock="Bottom"
-                       ui1:Hyperlink.Command="{commands1:Command PixiEditor.Window.OpenSettingsWindow, UseProvided=True}">
-                <ui1:Hyperlink.CommandParameter>
+                       ui:Hyperlink.Command="{commands1:Command PixiEditor.Window.OpenSettingsWindow, UseProvided=True}">
+                <ui:Hyperlink.CommandParameter>
                         <system:Int32>2</system:Int32>
-                    </ui1:Hyperlink.CommandParameter>
+                    </ui:Hyperlink.CommandParameter>
                     <Run ui:Translator.Key="EDIT"/>
                     <Run Text="{DynamicResource icon-link}" Classes="pixi-icon"/>
             </TextBlock>

+ 2 - 1
src/PixiEditor/Views/NewsFeed/NewsItem.axaml

@@ -7,6 +7,7 @@
              xmlns:ui="clr-namespace:PixiEditor.Helpers.UI"
              xmlns:asyncImageLoader="clr-namespace:AsyncImageLoader;assembly=AsyncImageLoader.Avalonia"
              xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters"
+             xmlns:ui1="clr-namespace:PixiEditor.Extensions.UI;assembly=PixiEditor.Extensions"
              mc:Ignorable="d" Name="newsItem"
              d:DesignHeight="300" d:DesignWidth="300">
     <Border Background="{DynamicResource ThemeBackgroundBrush1}" CornerRadius="5">
@@ -26,7 +27,7 @@
                        Text="{Binding ElementName=newsItem, Path=News.ResolvedIcon}" />
                 <Label VerticalAlignment="Center" HorizontalAlignment="Center">
                     <TextBlock Width="200" TextTrimming="CharacterEllipsis" MaxHeight="50"
-                               ui:Hyperlink.Url="{Binding ElementName=newsItem, Path=News.Url}"
+                               ui1:Hyperlink.Url="{Binding ElementName=newsItem, Path=News.Url}"
                                TextWrapping="Wrap">
                         <Run Text="{Binding ElementName=newsItem, Path=News.Title}" />
                         <Run Text="{DynamicResource icon-link}" Classes="pixi-icon" />

+ 1 - 1
src/PixiEditor/Views/Windows/PalettesBrowser.axaml

@@ -115,7 +115,7 @@
                                TextAlignment="Center" />
                     <TextBlock Margin="0 10 0 0">
                         <TextBlock ui:Translator.Key="LOSPEC_LINK_TEXT"
-                                   ui1:Hyperlink.Url="https://lospec.com/palette-list" />
+                                   ui:Hyperlink.Url="https://lospec.com/palette-list" />
                     </TextBlock>
                     <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" 
                                FontSize="128" Text="{DynamicResource icon-search}" Classes="pixi-icon"