From c4c18609b48212e8355c9d6339879e803f0ddf03 Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Fri, 19 Jan 2024 12:12:44 -0600 Subject: [PATCH] main keybinding & svg support --- .../Flow.Launcher.Infrastructure.csproj | 1 + .../Image/ImageCache.cs | 9 +- .../Image/ImageLoader.cs | 19 +- Flow.Launcher/App.axaml | 2 +- Flow.Launcher/Flow.Launcher.csproj | 1 + Flow.Launcher/MainWindow.axaml | 322 ++++++++---------- Flow.Launcher/MainWindow.axaml.cs | 2 +- Flow.Launcher/ResultListBox.axaml | 9 +- Flow.Launcher/SettingWindow.xaml.cs | 2 +- Flow.Launcher/ViewModels/MainViewModel.cs | 12 +- Flow.Launcher/ViewModels/ResultViewModel.cs | 17 +- Flow.Launcher/WelcomeWindow.axaml | 4 +- .../Programs/Win32.cs | 2 +- .../SearchSourceViewModel.cs | 3 +- 14 files changed, 199 insertions(+), 206 deletions(-) diff --git a/Flow.Launcher.Infrastructure/Flow.Launcher.Infrastructure.csproj b/Flow.Launcher.Infrastructure/Flow.Launcher.Infrastructure.csproj index 09f33525f..a2962a04f 100644 --- a/Flow.Launcher.Infrastructure/Flow.Launcher.Infrastructure.csproj +++ b/Flow.Launcher.Infrastructure/Flow.Launcher.Infrastructure.csproj @@ -49,6 +49,7 @@ + all diff --git a/Flow.Launcher.Infrastructure/Image/ImageCache.cs b/Flow.Launcher.Infrastructure/Image/ImageCache.cs index e4d97bae7..009496f30 100644 --- a/Flow.Launcher.Infrastructure/Image/ImageCache.cs +++ b/Flow.Launcher.Infrastructure/Image/ImageCache.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using System.Windows.Media; +using Avalonia.Media; using Avalonia.Media.Imaging; namespace Flow.Launcher.Infrastructure.Image @@ -13,9 +14,9 @@ namespace Flow.Launcher.Infrastructure.Image public class ImageUsage { public int usage; - public Bitmap imageSource; + public IImage imageSource; - public ImageUsage(int usage, Bitmap image) + public ImageUsage(int usage, IImage image) { this.usage = usage; imageSource = image; @@ -37,7 +38,7 @@ namespace Flow.Launcher.Infrastructure.Image } } - public Bitmap this[string path, bool isFullImage = false] + public IImage this[string path, bool isFullImage = false] { get { @@ -89,7 +90,7 @@ namespace Flow.Launcher.Infrastructure.Image Data[(key, isFullImage)].imageSource != null; } - public bool TryGetValue(string key, bool isFullImage, out Bitmap image) + public bool TryGetValue(string key, bool isFullImage, out IImage image) { if (key is not null) { diff --git a/Flow.Launcher.Infrastructure/Image/ImageLoader.cs b/Flow.Launcher.Infrastructure/Image/ImageLoader.cs index fdb58daf0..5a6e483cd 100644 --- a/Flow.Launcher.Infrastructure/Image/ImageLoader.cs +++ b/Flow.Launcher.Infrastructure/Image/ImageLoader.cs @@ -7,7 +7,10 @@ using System.Threading; using System.Threading.Tasks; using System.Windows.Media; using System.Windows.Media.Imaging; +using Avalonia.Media; using Avalonia.Media.Imaging; +using Avalonia.Svg; +using Avalonia.Threading; using Flow.Launcher.Infrastructure.Logger; using Flow.Launcher.Infrastructure.Storage; using static Flow.Launcher.Infrastructure.Http.Http; @@ -91,10 +94,10 @@ namespace Flow.Launcher.Infrastructure.Image } } - private readonly record struct ImageResult(Bitmap image, ImageType imageType) + private readonly record struct ImageResult(IImage image, ImageType imageType) { public ImageType ImageType { get; } = imageType; - public Bitmap Image { get; } = image; + public IImage Image { get; } = image; } private enum ImageType @@ -184,7 +187,7 @@ namespace Flow.Launcher.Infrastructure.Image private static async ValueTask GetThumbnailResult(string path, bool loadFullImage = false) { - Bitmap image; + IImage image; ImageType type = ImageType.Error; if (Directory.Exists(path)) @@ -218,6 +221,12 @@ namespace Flow.Launcher.Infrastructure.Image image = await ImageHelper.LoadFromFile(path, SmallIconSize); } } + else if (extension == ".svg") + { + var source = SvgSource.Load(path, null); + image = Dispatcher.UIThread.Invoke(() => new SvgImage() { Source = source }); + type = ImageType.FullImageFile; + } else { type = ImageType.File; @@ -249,12 +258,12 @@ namespace Flow.Launcher.Infrastructure.Image return ImageCache.ContainsKey(path, loadFullImage); } - public static bool TryGetValue(string path, bool loadFullImage, out Bitmap image) + public static bool TryGetValue(string path, bool loadFullImage, out IImage image) { return ImageCache.TryGetValue(path, loadFullImage, out image); } - public static async ValueTask LoadAsync(string path, bool loadFullImage = false) + public static async ValueTask LoadAsync(string path, bool loadFullImage = false) { var imageResult = await LoadInternalAsync(path, loadFullImage); diff --git a/Flow.Launcher/App.axaml b/Flow.Launcher/App.axaml index d77454f8d..7733ecd15 100644 --- a/Flow.Launcher/App.axaml +++ b/Flow.Launcher/App.axaml @@ -5,7 +5,7 @@ - avares://Flow.Launcher/Resources/#Segoe Fluent Icons + avares://Flow.Launcher/Resources/#Segoe Fluent Icons diff --git a/Flow.Launcher/Flow.Launcher.csproj b/Flow.Launcher/Flow.Launcher.csproj index 7c7f56670..8d7d7fb1b 100644 --- a/Flow.Launcher/Flow.Launcher.csproj +++ b/Flow.Launcher/Flow.Launcher.csproj @@ -101,6 +101,7 @@ + diff --git a/Flow.Launcher/MainWindow.axaml b/Flow.Launcher/MainWindow.axaml index a8af8bf90..6c6efe924 100644 --- a/Flow.Launcher/MainWindow.axaml +++ b/Flow.Launcher/MainWindow.axaml @@ -32,154 +32,122 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -208,7 +176,7 @@ - + @@ -228,14 +196,14 @@ - + + + + + + - - - - - @@ -335,28 +303,28 @@ - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/Flow.Launcher/MainWindow.axaml.cs b/Flow.Launcher/MainWindow.axaml.cs index 70dfb35a0..30500b117 100644 --- a/Flow.Launcher/MainWindow.axaml.cs +++ b/Flow.Launcher/MainWindow.axaml.cs @@ -347,7 +347,7 @@ namespace Flow.Launcher private void OpenWelcomeWindow() { var WelcomeWindow = new WelcomeWindow(_settings); - WelcomeWindow.ShowDialog(this); + WelcomeWindow.Show(this); } private async void PositionReset() diff --git a/Flow.Launcher/ResultListBox.axaml b/Flow.Launcher/ResultListBox.axaml index df4590570..b0169f654 100644 --- a/Flow.Launcher/ResultListBox.axaml +++ b/Flow.Launcher/ResultListBox.axaml @@ -63,12 +63,7 @@ - - - - - - + @@ -97,7 +92,7 @@ x:Name="GlyphIcon" HorizontalAlignment="Center" VerticalAlignment="Center" - FontFamily="{Binding Glyph.FontFamily}" + FontFamily="{StaticResource IconFont}" Text="{Binding Glyph.Glyph}" IsVisible="{Binding ShowGlyph}" /> diff --git a/Flow.Launcher/SettingWindow.xaml.cs b/Flow.Launcher/SettingWindow.xaml.cs index c241b23b7..71b504e26 100644 --- a/Flow.Launcher/SettingWindow.xaml.cs +++ b/Flow.Launcher/SettingWindow.xaml.cs @@ -258,7 +258,7 @@ namespace Flow.Launcher private void OpenWelcomeWindow(object sender, RoutedEventArgs e) { var WelcomeWindow = new WelcomeWindow(settings); - WelcomeWindow.ShowDialog(null); + WelcomeWindow.Show(); } private void OpenLogFolder(object sender, RoutedEventArgs e) { diff --git a/Flow.Launcher/ViewModels/MainViewModel.cs b/Flow.Launcher/ViewModels/MainViewModel.cs index 5c674a756..ed5325e7a 100644 --- a/Flow.Launcher/ViewModels/MainViewModel.cs +++ b/Flow.Launcher/ViewModels/MainViewModel.cs @@ -599,7 +599,17 @@ namespace Flow.Launcher.ViewModel public string PluginIconPath { get; set; } = null; public string OpenResultCommandModifiers => Settings.OpenResultModifiers; - + public string D1Gesture => $"{OpenResultCommandModifiers}+D1"; + public string D2Gesture => $"{OpenResultCommandModifiers}+D2"; + public string D3Gesture => $"{OpenResultCommandModifiers}+D3"; + public string D4Gesture => $"{OpenResultCommandModifiers}+D4"; + public string D5Gesture => $"{OpenResultCommandModifiers}+D5"; + public string D6Gesture => $"{OpenResultCommandModifiers}+D6"; + public string D7Gesture => $"{OpenResultCommandModifiers}+D7"; + public string D8Gesture => $"{OpenResultCommandModifiers}+D8"; + public string D9Gesture => $"{OpenResultCommandModifiers}+D9"; + public string D0Gesture => $"{OpenResultCommandModifiers}+D0"; + public string PreviewHotkey { get diff --git a/Flow.Launcher/ViewModels/ResultViewModel.cs b/Flow.Launcher/ViewModels/ResultViewModel.cs index 393b6261f..7aa4c3f31 100644 --- a/Flow.Launcher/ViewModels/ResultViewModel.cs +++ b/Flow.Launcher/ViewModels/ResultViewModel.cs @@ -9,7 +9,11 @@ using Flow.Launcher.Plugin; using System.IO; using System.Drawing.Text; using System.Collections.Generic; +using Avalonia.Fonts.Inter; +using Avalonia.Media; +using Avalonia.Media.Fonts; using Avalonia.Media.Imaging; +using FontFamily = Avalonia.Media.FontFamily; namespace Flow.Launcher.ViewModel { @@ -17,7 +21,7 @@ namespace Flow.Launcher.ViewModel { private static PrivateFontCollection fontCollection = new(); private static Dictionary fonts = new(); - + public ResultViewModel(Result result, Settings settings) { Settings = settings; @@ -59,14 +63,17 @@ namespace Flow.Launcher.ViewModel } } + LoadImage(); } + private Settings Settings { get; } + public bool ShowOpenResultHotkey => Settings.ShowOpenResultHotkey; - public Bitmap DefaultImage => ImageLoader.LoadingImage; + public IImage DefaultImage => ImageLoader.LoadingImage; public bool ShowDefaultPreview => Result.PreviewPanel != null; @@ -148,9 +155,9 @@ namespace Flow.Launcher.ViewModel ? Result.SubTitle : Result.SubTitleToolTip; - public Task Image { get; set; } + public Task Image { get; set; } - public Task PreviewImage { get; set; } + public Task PreviewImage { get; set; } /// /// Determines if to use the full width of the preview panel @@ -159,7 +166,7 @@ namespace Flow.Launcher.ViewModel public GlyphInfo Glyph { get; set; } - private async Task LoadImageInternalAsync(string imagePath, Result.IconDelegate icon, + private async Task LoadImageInternalAsync(string imagePath, Result.IconDelegate icon, bool loadFullImage) { if (string.IsNullOrEmpty(imagePath) && icon != null) diff --git a/Flow.Launcher/WelcomeWindow.axaml b/Flow.Launcher/WelcomeWindow.axaml index 0d87a37d6..4ca6ff13d 100644 --- a/Flow.Launcher/WelcomeWindow.axaml +++ b/Flow.Launcher/WelcomeWindow.axaml @@ -105,7 +105,7 @@ Margin="8,5,0,5" Content="" DockPanel.Dock="Right" - FontFamily="{StaticResource UIFont}" + FontFamily="{StaticResource IconFont}" FontSize="18" />