Browse Source

Improved search control styling

CPKreuz 1 year ago
parent
commit
f0d1e7acd7

+ 48 - 1
src/PixiEditor.AvaloniaUI/Models/Commands/Search/FileSearchResult.cs

@@ -1,8 +1,12 @@
 using System.IO;
 using System.IO;
 using Avalonia;
 using Avalonia;
 using Avalonia.Controls;
 using Avalonia.Controls;
+using Avalonia.Controls.Documents;
+using Avalonia.Markup.Xaml.MarkupExtensions;
 using Avalonia.Media;
 using Avalonia.Media;
+using Avalonia.Styling;
 using PixiEditor.AvaloniaUI.Helpers.Converters;
 using PixiEditor.AvaloniaUI.Helpers.Converters;
+using PixiEditor.AvaloniaUI.Views;
 
 
 namespace PixiEditor.AvaloniaUI.Models.Commands.Search;
 namespace PixiEditor.AvaloniaUI.Models.Commands.Search;
 
 
@@ -15,7 +19,7 @@ internal class FileSearchResult : SearchResult
 
 
     public override string Text => asReferenceLayer ? $"As reference: ...\\{Path.GetFileName(FilePath)}" : $"...\\{Path.GetFileName(FilePath)}";
     public override string Text => asReferenceLayer ? $"As reference: ...\\{Path.GetFileName(FilePath)}" : $"...\\{Path.GetFileName(FilePath)}";
 
 
-    public override AvaloniaObject Description => new TextBlock { Text = FilePath, FontSize = 16 };
+    public override AvaloniaObject Description => GetDescription();
 
 
     public override bool CanExecute => !asReferenceLayer ||
     public override bool CanExecute => !asReferenceLayer ||
                 CommandController.Current.Commands["PixiEditor.Clipboard.PasteReferenceLayerFromPath"].Methods.CanExecute(FilePath);
                 CommandController.Current.Commands["PixiEditor.Clipboard.PasteReferenceLayerFromPath"].Methods.CanExecute(FilePath);
@@ -48,4 +52,47 @@ internal class FileSearchResult : SearchResult
             }
             }
         }
         }
     }
     }
+
+    private TextBlock GetDescription()
+    {
+        var path = FilePath;
+        
+        var text = new TextBlock { Inlines = new InlineCollection(), FontSize = 14, TextTrimming = TextTrimming.CharacterEllipsis };
+
+        string[] split = path.Split(Path.DirectorySeparatorChar);
+        bool hasEllipsis = false;
+
+        for (var i = 0; i < split.Length; i++)
+        {
+            if (i > 3 && i < split.Length - 3)
+            {
+                if (!hasEllipsis)
+                {
+                    text.Inlines.Add("…"); // Horizontal Ellipsis
+                    text.Inlines.Add(GetSeparator());
+                    hasEllipsis = true;
+                    
+                }
+
+                continue;
+            }
+
+            string part = split[i];
+            text.Inlines.Add(part.Replace(":", string.Empty));
+            
+            if (i != split.Length - 1)
+            {
+                text.Inlines.Add(GetSeparator());
+            }
+        }
+
+        return text;
+
+        Run GetSeparator()
+        {
+            var separator = new Run(" › ") { FontWeight = FontWeight.Light }; // Single Right-Pointing Angle Quotation Mark
+
+            return separator;
+        }
+    }
 }
 }

+ 2 - 1
src/PixiEditor.AvaloniaUI/Views/Main/CommandSearch/CommandSearchControl.axaml

@@ -21,6 +21,7 @@
         <TextBox Text="{Binding SearchTerm, Mode=TwoWay, ElementName=uc}"
         <TextBox Text="{Binding SearchTerm, Mode=TwoWay, ElementName=uc}"
                  FontSize="17"
                  FontSize="17"
                  Padding="5"
                  Padding="5"
+                 CornerRadius="5,5,0,0"
                  x:Name="textBox">
                  x:Name="textBox">
             <Interaction.Behaviors>
             <Interaction.Behaviors>
                 <behaviours:TextBoxFocusBehavior SelectOnMouseClick="{Binding SelectAll, ElementName=uc, Mode=OneWay}" />
                 <behaviours:TextBoxFocusBehavior SelectOnMouseClick="{Binding SelectAll, ElementName=uc, Mode=OneWay}" />
@@ -47,7 +48,7 @@
                         <ItemsControl.ItemTemplate>
                         <ItemsControl.ItemTemplate>
                             <DataTemplate DataType="search:SearchResult">
                             <DataTemplate DataType="search:SearchResult">
                                 <Button Padding="5" Height="40" BorderThickness="0" Background="{DynamicResource ThemeBackgroundBrush}"
                                 <Button Padding="5" Height="40" BorderThickness="0" Background="{DynamicResource ThemeBackgroundBrush}"
-                                        Command="{Binding ButtonClickedCommand, ElementName=uc}"
+                                        Command="{Binding ButtonClickedCommand, ElementName=uc}" CornerRadius="0"
                                         CommandParameter="{Binding}"
                                         CommandParameter="{Binding}"
                                         HorizontalContentAlignment="Stretch"
                                         HorizontalContentAlignment="Stretch"
                                         IsEnabled="{Binding CanExecute}"
                                         IsEnabled="{Binding CanExecute}"