소스 검색

Search improvements

CPKreuz 2 년 전
부모
커밋
146a0b62e8

+ 14 - 2
src/PixiEditor/Models/Commands/Search/ColorSearchResult.cs

@@ -1,4 +1,7 @@
-using System.Windows.Media;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using System.Windows.Media;
 
 namespace PixiEditor.Models.Commands.Search;
 
@@ -13,7 +16,11 @@ internal class ColorSearchResult : SearchResult
 
     public override string Text => text;
 
-    public override string Description => $"{color} rgba({color.R}, {color.G}, {color.B}, {color.A})";
+    public override FrameworkElement Description => new TextBlock(new Run($"{color} rgba({color.R}, {color.G}, {color.B}, {color.A})"))
+    {
+        FontSize = 16,
+        TextDecorations = GetDecoration(new Pen(new SolidColorBrush(color.ToOpaqueMediaColor()), 1))
+    };
 
     //public override bool CanExecute => !requiresDocument || (requiresDocument && ViewModelMain.Current.BitmapManager.ActiveDocument != null);
     public override bool CanExecute => !isPalettePaste || ViewModelMain.Current.DocumentManagerSubViewModel.ActiveDocument != null;
@@ -55,4 +62,9 @@ internal class ColorSearchResult : SearchResult
         drawing.Geometry = geometry;
         return new DrawingImage(drawing);
     }
+    
+    private static TextDecorationCollection GetDecoration(Pen pen) => new()
+    {
+        new TextDecoration(TextDecorationLocation.Underline, pen, 0, TextDecorationUnit.Pixel, TextDecorationUnit.Pixel)
+    };
 }

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

@@ -1,4 +1,6 @@
 using System.IO;
+using System.Windows;
+using System.Windows.Controls;
 using System.Windows.Media;
 using PixiEditor.Helpers.Converters;
 
@@ -13,7 +15,7 @@ internal class FileSearchResult : SearchResult
 
     public override string Text => asReferenceLayer ? $"As reference: ...\\{Path.GetFileName(FilePath)}" : $"...\\{Path.GetFileName(FilePath)}";
 
-    public override string Description => FilePath;
+    public override FrameworkElement Description => new TextBlock { Text = FilePath, FontSize = 16 };
 
     public override bool CanExecute => !asReferenceLayer ||
                 CommandController.Current.Commands["PixiEditor.Clipboard.PasteReferenceLayerFromPath"].Methods.CanExecute(FilePath);

+ 2 - 1
src/PixiEditor/Models/Commands/Search/SearchResult.cs

@@ -1,4 +1,5 @@
 using System.Text.RegularExpressions;
+using System.Windows;
 using System.Windows.Documents;
 using System.Windows.Media;
 using PixiEditor.Helpers;
@@ -19,7 +20,7 @@ internal abstract class SearchResult : NotifyableObject
 
     public abstract string Text { get; }
 
-    public virtual string Description { get; }
+    public virtual FrameworkElement Description { get; }
 
     public abstract bool CanExecute { get; }
 

+ 2 - 2
src/PixiEditor/Views/UserControls/CommandSearch/CommandSearchControl.xaml

@@ -134,8 +134,8 @@
             </Grid>
         </Border>
         <Border Grid.Row="2" BorderThickness="1" BorderBrush="{StaticResource BrighterAccentColor}"
-                CornerRadius="0,0,5,5" Background="{StaticResource AccentColor}">
-            <TextBlock Margin="5" FontSize="16" Text="{Binding SelectedResult.Description, ElementName=uc, FallbackValue=''}" />
+                CornerRadius="0,0,5,5" Background="{StaticResource AccentColor}" Padding="3">
+            <ContentPresenter Content="{Binding SelectedResult.Description, Mode=OneWay, ElementName=uc}"/>
         </Border>
     </Grid>
 </UserControl>

+ 1 - 0
src/PixiEditor/Views/UserControls/CommandSearch/CommandSearchControl.xaml.cs

@@ -60,6 +60,7 @@ internal partial class CommandSearchControl : UserControl, INotifyPropertyChange
             if (value is not null)
                 value.IsSelected = true;
             selectedResult = value;
+            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(SelectedResult)));
         }
     }