From d96ddd3e95bfbbd20b4aef57305b4bcef443fc8a Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Fri, 25 Nov 2022 14:44:08 -0600 Subject: [PATCH] different width for image/video vs other file type --- Flow.Launcher/MainWindow.xaml | 289 +++++++++++---------- Flow.Launcher/ViewModel/ResultViewModel.cs | 67 +++-- 2 files changed, 184 insertions(+), 172 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index 67a7703c1..1207034ae 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -1,5 +1,4 @@ - - - - - - + + + + - - - - - - - - - - - - + + - - - + + - - - - - - - - + - - - - - - - - - - - - + - - - - + + + - - + - + - + - + - - + - + @@ -244,25 +229,21 @@ - - - - - - - - + - - - - + + + - @@ -351,14 +338,16 @@ - - - + + + - @@ -367,52 +356,64 @@ - - - + + + - - - - + - + - - - + + + + + - - + diff --git a/Flow.Launcher/ViewModel/ResultViewModel.cs b/Flow.Launcher/ViewModel/ResultViewModel.cs index fca37a359..1bfaa9c52 100644 --- a/Flow.Launcher/ViewModel/ResultViewModel.cs +++ b/Flow.Launcher/ViewModel/ResultViewModel.cs @@ -20,47 +20,51 @@ namespace Flow.Launcher.ViewModel public ResultViewModel(Result result, Settings settings) { - if (result != null) + Settings = settings; + + if (result == null) { - Result = result; + return; + } + Result = result; - if (Result.Glyph is { FontFamily: not null } glyph) + PreviewExtension = Path.GetExtension(result.PreviewImage ?? result.IcoPath); + + if (Result.Glyph is { FontFamily: not null } glyph) + { + // Checks if it's a system installed font, which does not require path to be provided. + if (glyph.FontFamily.EndsWith(".ttf") || glyph.FontFamily.EndsWith(".otf")) { - // Checks if it's a system installed font, which does not require path to be provided. - if (glyph.FontFamily.EndsWith(".ttf") || glyph.FontFamily.EndsWith(".otf")) + string fontFamilyPath = glyph.FontFamily; + + if (!Path.IsPathRooted(fontFamilyPath)) { - string fontFamilyPath = glyph.FontFamily; + fontFamilyPath = Path.Combine(Result.PluginDirectory, fontFamilyPath); + } - if (!Path.IsPathRooted(fontFamilyPath)) + if (fonts.ContainsKey(fontFamilyPath)) + { + Glyph = glyph with { - fontFamilyPath = Path.Combine(Result.PluginDirectory, fontFamilyPath); - } - - if (fonts.ContainsKey(fontFamilyPath)) - { - Glyph = glyph with - { - FontFamily = fonts[fontFamilyPath] - }; - } - else - { - fontCollection.AddFontFile(fontFamilyPath); - fonts[fontFamilyPath] = $"{Path.GetDirectoryName(fontFamilyPath)}/#{fontCollection.Families[^1].Name}"; - Glyph = glyph with - { - FontFamily = fonts[fontFamilyPath] - }; - } + FontFamily = fonts[fontFamilyPath] + }; } else { - Glyph = glyph; + fontCollection.AddFontFile(fontFamilyPath); + fonts[fontFamilyPath] = $"{Path.GetDirectoryName(fontFamilyPath)}/#{fontCollection.Families[^1].Name}"; + Glyph = glyph with + { + FontFamily = fonts[fontFamilyPath] + }; } } + else + { + Glyph = glyph; + } } - Settings = settings; } private Settings Settings { get; } @@ -165,6 +169,13 @@ namespace Flow.Launcher.ViewModel private set => previewImage = value; } + public string PreviewExtension { get; set; } + + public bool PreviewIsImageOrVideo => PreviewExtension is ".jpg" + or ".png" + or ".gif" + or ".mp4"; + public GlyphInfo Glyph { get; set; } private async Task LoadImageAsync()