From f069ee909475035bb5978fef8fe98bf38dd4f2fa Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Wed, 4 Jun 2025 17:01:46 +0800 Subject: [PATCH] Show more info in file & folder tooltip --- .../Search/ResultManager.cs | 27 ++++++++-- .../Views/PreviewPanel.xaml.cs | 52 +++++++++++++++++-- 2 files changed, 72 insertions(+), 7 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs index 5c4accdc0..426d51918 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs @@ -163,7 +163,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search }, Score = score, TitleToolTip = Main.Context.API.GetTranslation("plugin_explorer_plugin_ToolTipOpenDirectory"), - SubTitleToolTip = path, + SubTitleToolTip = Settings.DisplayMoreInformationInToolTip ? GetMoreInfoToolTip(path, ResultType.Folder) : path, ContextData = new SearchResult { Type = ResultType.Folder, FullPath = path, WindowsIndexed = windowsIndexed } }; } @@ -269,7 +269,6 @@ namespace Flow.Launcher.Plugin.Explorer.Search bool isMedia = IsMedia(Path.GetExtension(filePath)); var title = Path.GetFileName(filePath); - /* Preview Detail */ var result = new Result @@ -318,7 +317,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search return true; }, TitleToolTip = Main.Context.API.GetTranslation("plugin_explorer_plugin_ToolTipOpenContainingFolder"), - SubTitleToolTip = filePath, + SubTitleToolTip = Settings.DisplayMoreInformationInToolTip ? GetMoreInfoToolTip(filePath, ResultType.File) : filePath, ContextData = new SearchResult { Type = ResultType.File, FullPath = filePath, WindowsIndexed = windowsIndexed } }; return result; @@ -349,6 +348,28 @@ namespace Flow.Launcher.Plugin.Explorer.Search _ = Task.Run(() => EverythingApi.IncrementRunCounterAsync(fileOrFolder)); } + private static string GetMoreInfoToolTip(string filePath, ResultType type) + { + switch (type) + { + 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"), + filePath, folderSize, folderCreatedAt, folderModifiedAt, Environment.NewLine); + case ResultType.File: + var fileSize = PreviewPanel.GetFileSize(filePath); + var fileCreatedAt = PreviewPanel.GetFileCreatedAt(filePath, Settings.PreviewPanelDateFormat, Settings.PreviewPanelTimeFormat, Settings.ShowFileAgeInPreviewPanel); + var fileModifiedAt = PreviewPanel.GetFileLastModifiedAt(filePath, Settings.PreviewPanelDateFormat, Settings.PreviewPanelTimeFormat, Settings.ShowFileAgeInPreviewPanel); + return string.Format(Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info"), + filePath, fileSize, fileCreatedAt, fileModifiedAt, Environment.NewLine); + default: + return filePath; + } + } + private static readonly string[] MediaExtensions = { ".jpg", ".png", ".avi", ".mkv", ".bmp", ".gif", ".wmv", ".mp3", ".flac", ".mp4" }; } diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs index d8715530c..cd462be69 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs @@ -65,12 +65,12 @@ public partial class PreviewPanel : UserControl, INotifyPropertyChanged if (Settings.ShowCreatedDateInPreviewPanel) { - CreatedAt = GetCreatedAt(filePath, Settings.PreviewPanelDateFormat, Settings.PreviewPanelTimeFormat, Settings.ShowFileAgeInPreviewPanel); + CreatedAt = GetFileCreatedAt(filePath, Settings.PreviewPanelDateFormat, Settings.PreviewPanelTimeFormat, Settings.ShowFileAgeInPreviewPanel); } if (Settings.ShowModifiedDateInPreviewPanel) { - LastModifiedAt = GetLastModifiedAt(filePath, Settings.PreviewPanelDateFormat, Settings.PreviewPanelTimeFormat, Settings.ShowFileAgeInPreviewPanel); + LastModifiedAt = GetFileLastModifiedAt(filePath, Settings.PreviewPanelDateFormat, Settings.PreviewPanelTimeFormat, Settings.ShowFileAgeInPreviewPanel); } _ = LoadImageAsync(); @@ -87,7 +87,7 @@ public partial class PreviewPanel : UserControl, INotifyPropertyChanged return ResultManager.ToReadableSize(fileInfo.Length, 2); } - public static string GetCreatedAt(string filePath, string previewPanelDateFormat, string previewPanelTimeFormat, bool showFileAgeInPreviewPanel) + public static string GetFileCreatedAt(string filePath, string previewPanelDateFormat, string previewPanelTimeFormat, bool showFileAgeInPreviewPanel) { var createdDate = File.GetCreationTime(filePath); var formattedDate = createdDate.ToString( @@ -100,7 +100,7 @@ public partial class PreviewPanel : UserControl, INotifyPropertyChanged return result; } - public static string GetLastModifiedAt(string filePath, string previewPanelDateFormat, string previewPanelTimeFormat, bool showFileAgeInPreviewPanel) + public static string GetFileLastModifiedAt(string filePath, string previewPanelDateFormat, string previewPanelTimeFormat, bool showFileAgeInPreviewPanel) { var lastModifiedDate = File.GetLastWriteTime(filePath); var formattedDate = lastModifiedDate.ToString( @@ -113,6 +113,50 @@ public partial class PreviewPanel : UserControl, INotifyPropertyChanged return result; } + public static string GetFolderSize(string folderPath) + { + var directoryInfo = new DirectoryInfo(folderPath); + long size = 0; + try + { + foreach (var file in directoryInfo.GetFiles("*", SearchOption.AllDirectories)) + { + size += file.Length; + } + } + catch (Exception) + { + return string.Empty; + } + return ResultManager.ToReadableSize(size, 2); + } + + public static string GetFolderCreatedAt(string folderPath, string previewPanelDateFormat, string previewPanelTimeFormat, bool showFileAgeInPreviewPanel) + { + var createdDate = Directory.GetCreationTime(folderPath); + var formattedDate = createdDate.ToString( + $"{previewPanelDateFormat} {previewPanelTimeFormat}", + CultureInfo.CurrentCulture + ); + + var result = formattedDate; + if (showFileAgeInPreviewPanel) result = $"{GetFileAge(createdDate)} - {formattedDate}"; + return result; + } + + public static string GetFolderLastModifiedAt(string folderPath, string previewPanelDateFormat, string previewPanelTimeFormat, bool showFileAgeInPreviewPanel) + { + var lastModifiedDate = Directory.GetLastWriteTime(folderPath); + var formattedDate = lastModifiedDate.ToString( + $"{previewPanelDateFormat} {previewPanelTimeFormat}", + CultureInfo.CurrentCulture + ); + + var result = formattedDate; + if (showFileAgeInPreviewPanel) result = $"{GetFileAge(lastModifiedDate)} - {formattedDate}"; + return result; + } + private static string GetFileAge(DateTime fileDateTime) { var now = DateTime.Now;