mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Show more info in file & folder tooltip
This commit is contained in:
parent
16551396b9
commit
f069ee9094
2 changed files with 72 additions and 7 deletions
|
|
@ -163,7 +163,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
||||||
},
|
},
|
||||||
Score = score,
|
Score = score,
|
||||||
TitleToolTip = Main.Context.API.GetTranslation("plugin_explorer_plugin_ToolTipOpenDirectory"),
|
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 }
|
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));
|
bool isMedia = IsMedia(Path.GetExtension(filePath));
|
||||||
var title = Path.GetFileName(filePath);
|
var title = Path.GetFileName(filePath);
|
||||||
|
|
||||||
|
|
||||||
/* Preview Detail */
|
/* Preview Detail */
|
||||||
|
|
||||||
var result = new Result
|
var result = new Result
|
||||||
|
|
@ -318,7 +317,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
TitleToolTip = Main.Context.API.GetTranslation("plugin_explorer_plugin_ToolTipOpenContainingFolder"),
|
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 }
|
ContextData = new SearchResult { Type = ResultType.File, FullPath = filePath, WindowsIndexed = windowsIndexed }
|
||||||
};
|
};
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -349,6 +348,28 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
||||||
_ = Task.Run(() => EverythingApi.IncrementRunCounterAsync(fileOrFolder));
|
_ = 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" };
|
private static readonly string[] MediaExtensions = { ".jpg", ".png", ".avi", ".mkv", ".bmp", ".gif", ".wmv", ".mp3", ".flac", ".mp4" };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,12 +65,12 @@ public partial class PreviewPanel : UserControl, INotifyPropertyChanged
|
||||||
|
|
||||||
if (Settings.ShowCreatedDateInPreviewPanel)
|
if (Settings.ShowCreatedDateInPreviewPanel)
|
||||||
{
|
{
|
||||||
CreatedAt = GetCreatedAt(filePath, Settings.PreviewPanelDateFormat, Settings.PreviewPanelTimeFormat, Settings.ShowFileAgeInPreviewPanel);
|
CreatedAt = GetFileCreatedAt(filePath, Settings.PreviewPanelDateFormat, Settings.PreviewPanelTimeFormat, Settings.ShowFileAgeInPreviewPanel);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings.ShowModifiedDateInPreviewPanel)
|
if (Settings.ShowModifiedDateInPreviewPanel)
|
||||||
{
|
{
|
||||||
LastModifiedAt = GetLastModifiedAt(filePath, Settings.PreviewPanelDateFormat, Settings.PreviewPanelTimeFormat, Settings.ShowFileAgeInPreviewPanel);
|
LastModifiedAt = GetFileLastModifiedAt(filePath, Settings.PreviewPanelDateFormat, Settings.PreviewPanelTimeFormat, Settings.ShowFileAgeInPreviewPanel);
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = LoadImageAsync();
|
_ = LoadImageAsync();
|
||||||
|
|
@ -87,7 +87,7 @@ public partial class PreviewPanel : UserControl, INotifyPropertyChanged
|
||||||
return ResultManager.ToReadableSize(fileInfo.Length, 2);
|
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 createdDate = File.GetCreationTime(filePath);
|
||||||
var formattedDate = createdDate.ToString(
|
var formattedDate = createdDate.ToString(
|
||||||
|
|
@ -100,7 +100,7 @@ public partial class PreviewPanel : UserControl, INotifyPropertyChanged
|
||||||
return result;
|
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 lastModifiedDate = File.GetLastWriteTime(filePath);
|
||||||
var formattedDate = lastModifiedDate.ToString(
|
var formattedDate = lastModifiedDate.ToString(
|
||||||
|
|
@ -113,6 +113,50 @@ public partial class PreviewPanel : UserControl, INotifyPropertyChanged
|
||||||
return result;
|
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)
|
private static string GetFileAge(DateTime fileDateTime)
|
||||||
{
|
{
|
||||||
var now = DateTime.Now;
|
var now = DateTime.Now;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue