From 85c038719e7aff30c03d3ac857a03f7b9a104ab9 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Wed, 4 Jun 2025 17:12:53 +0800 Subject: [PATCH] Support custom preview panel for folder results --- .../Search/ResultManager.cs | 8 ++------ .../Views/PreviewPanel.xaml.cs | 14 +++++++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs index 426d51918..27206f9ea 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs @@ -99,10 +99,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search AutoCompleteText = GetAutoCompleteText(title, query, path, ResultType.Folder), TitleHighlightData = Context.API.FuzzySearch(query.Search, title).MatchData, CopyText = path, - Preview = new Result.PreviewInfo - { - FilePath = path, - }, + PreviewPanel = new Lazy(() => new PreviewPanel(Settings, path, ResultType.Folder)), Action = c => { if (c.SpecialKeyState.ToModifierKeys() == ModifierKeys.Alt) @@ -286,7 +283,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search TitleHighlightData = Context.API.FuzzySearch(query.Search, title).MatchData, Score = score, CopyText = filePath, - PreviewPanel = new Lazy(() => new PreviewPanel(Settings, filePath)), + PreviewPanel = new Lazy(() => new PreviewPanel(Settings, filePath, ResultType.File)), Action = c => { if (c.SpecialKeyState.ToModifierKeys() == ModifierKeys.Alt) @@ -354,7 +351,6 @@ namespace Flow.Launcher.Plugin.Explorer.Search { case ResultType.Folder: var folderSize = PreviewPanel.GetFolderSize(filePath); - if (string.IsNullOrEmpty(folderSize)) folderSize = Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info_unknown"); var folderCreatedAt = PreviewPanel.GetFolderCreatedAt(filePath, Settings.PreviewPanelDateFormat, Settings.PreviewPanelTimeFormat, Settings.ShowFileAgeInPreviewPanel); var folderModifiedAt = PreviewPanel.GetFolderLastModifiedAt(filePath, Settings.PreviewPanelDateFormat, Settings.PreviewPanelTimeFormat, Settings.ShowFileAgeInPreviewPanel); return string.Format(Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info"), diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs index cd462be69..13339fa45 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs @@ -50,7 +50,7 @@ public partial class PreviewPanel : UserControl, INotifyPropertyChanged ? Visibility.Visible : Visibility.Collapsed; - public PreviewPanel(Settings settings, string filePath) + public PreviewPanel(Settings settings, string filePath, ResultType type) { InitializeComponent(); @@ -60,17 +60,21 @@ public partial class PreviewPanel : UserControl, INotifyPropertyChanged if (Settings.ShowFileSizeInPreviewPanel) { - FileSize = GetFileSize(filePath); + FileSize = type == ResultType.File ? GetFileSize(filePath) : GetFolderSize(filePath); } if (Settings.ShowCreatedDateInPreviewPanel) { - CreatedAt = GetFileCreatedAt(filePath, Settings.PreviewPanelDateFormat, Settings.PreviewPanelTimeFormat, Settings.ShowFileAgeInPreviewPanel); + CreatedAt = type == ResultType.File ? + GetFileCreatedAt(filePath, Settings.PreviewPanelDateFormat, Settings.PreviewPanelTimeFormat, Settings.ShowFileAgeInPreviewPanel) : + GetFolderCreatedAt(filePath, Settings.PreviewPanelDateFormat, Settings.PreviewPanelTimeFormat, Settings.ShowFileAgeInPreviewPanel); } if (Settings.ShowModifiedDateInPreviewPanel) { - LastModifiedAt = GetFileLastModifiedAt(filePath, Settings.PreviewPanelDateFormat, Settings.PreviewPanelTimeFormat, Settings.ShowFileAgeInPreviewPanel); + LastModifiedAt = type == ResultType.File ? + GetFileLastModifiedAt(filePath, Settings.PreviewPanelDateFormat, Settings.PreviewPanelTimeFormat, Settings.ShowFileAgeInPreviewPanel) : + GetFolderLastModifiedAt(filePath, Settings.PreviewPanelDateFormat, Settings.PreviewPanelTimeFormat, Settings.ShowFileAgeInPreviewPanel); } _ = LoadImageAsync(); @@ -126,7 +130,7 @@ public partial class PreviewPanel : UserControl, INotifyPropertyChanged } catch (Exception) { - return string.Empty; + return Main.Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info_unknown"); } return ResultManager.ToReadableSize(size, 2); }