Merge pull request #3579 from 01Dri/display-the-File-age-in-preview-panel

Display the file age in preview panel
This commit is contained in:
DB P 2025-05-24 17:14:27 +09:00 committed by GitHub
commit 6333cd362c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 72 additions and 14 deletions

View file

@ -33,6 +33,7 @@
<system:String x:Key="plugin_explorer_previewpanel_display_file_size_checkbox">Size</system:String>
<system:String x:Key="plugin_explorer_previewpanel_display_file_creation_checkbox">Date Created</system:String>
<system:String x:Key="plugin_explorer_previewpanel_display_file_modification_checkbox">Date Modified</system:String>
<system:String x:Key="plugin_explorer_previewpanel_display_file_age_checkbox">File Age</system:String>
<system:String x:Key="plugin_explorer_previewpanel_file_info_label">Display File Info</system:String>
<system:String x:Key="plugin_explorer_previewpanel_date_and_time_format_label">Date and time format</system:String>
<system:String x:Key="plugin_explorer_everything_sort_option">Sort Option:</system:String>
@ -166,4 +167,12 @@
<system:String x:Key="plugin_explorer_native_context_menu_display_context_menu">Display native context menu (experimental)</system:String>
<system:String x:Key="plugin_explorer_native_context_menu_include_patterns_guide">Below you can specify items you want to include in the context menu, they can be partial (e.g. 'pen wit') or complete ('Open with').</system:String>
<system:String x:Key="plugin_explorer_native_context_menu_exclude_patterns_guide">Below you can specify items you want to exclude from context menu, they can be partial (e.g. 'pen wit') or complete ('Open with').</system:String>
<!-- Preview Info -->
<system:String x:Key="Today">Today</system:String>
<system:String x:Key="DaysAgo">{0} days ago</system:String>
<system:String x:Key="OneMonthAgo">1 month ago</system:String>
<system:String x:Key="MonthsAgo">{0} months ago</system:String>
<system:String x:Key="OneYearAgo">1 year ago</system:String>
<system:String x:Key="YearsAgo">{0} years ago</system:String>
</ResourceDictionary>

View file

@ -27,7 +27,6 @@ namespace Flow.Launcher.Plugin.Explorer
public string ExcludedFileTypes { get; set; } = "";
public bool UseLocationAsWorkingDir { get; set; } = false;
public bool ShowInlinedWindowsContextMenu { get; set; } = false;
@ -66,6 +65,9 @@ namespace Flow.Launcher.Plugin.Explorer
public bool ShowCreatedDateInPreviewPanel { get; set; } = true;
public bool ShowModifiedDateInPreviewPanel { get; set; } = true;
public bool ShowFileAgeInPreviewPanel { get; set; } = false;
public string PreviewPanelDateFormat { get; set; } = "yyyy-MM-dd";

View file

@ -169,6 +169,18 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
}
}
public bool ShowFileAgeInPreviewPanel
{
get => Settings.ShowFileAgeInPreviewPanel;
set
{
Settings.ShowFileAgeInPreviewPanel = value;
OnPropertyChanged();
OnPropertyChanged(nameof(ShowPreviewPanelDateTimeChoices));
OnPropertyChanged(nameof(PreviewPanelDateTimeChoicesVisibility));
}
}
public string PreviewPanelDateFormat
{
get => Settings.PreviewPanelDateFormat;

View file

@ -505,6 +505,11 @@
Margin="{StaticResource SettingPanelItemLeftTopBottomMargin}"
Content="{DynamicResource plugin_explorer_previewpanel_display_file_modification_checkbox}"
IsChecked="{Binding ShowModifiedDateInPreviewPanel}" />
<CheckBox
Margin="{StaticResource SettingPanelItemLeftTopBottomMargin}"
Content="{DynamicResource plugin_explorer_previewpanel_display_file_age_checkbox}"
IsChecked="{Binding ShowFileAgeInPreviewPanel}" />
</WrapPanel>
</DockPanel>

View file

@ -1,4 +1,5 @@
using System.ComponentModel;
using System;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Runtime.CompilerServices;
@ -65,22 +66,27 @@ public partial class PreviewPanel : UserControl, INotifyPropertyChanged
if (Settings.ShowCreatedDateInPreviewPanel)
{
CreatedAt = File
.GetCreationTime(filePath)
.ToString(
$"{Settings.PreviewPanelDateFormat} {Settings.PreviewPanelTimeFormat}",
CultureInfo.CurrentCulture
);
DateTime createdDate = File.GetCreationTime(filePath);
string formattedDate = createdDate.ToString(
$"{Settings.PreviewPanelDateFormat} {Settings.PreviewPanelTimeFormat}",
CultureInfo.CurrentCulture
);
string result = formattedDate;
if (Settings.ShowFileAgeInPreviewPanel) result = $"{GetFileAge(createdDate)} - {formattedDate}";
CreatedAt = result;
}
if (Settings.ShowModifiedDateInPreviewPanel)
{
LastModifiedAt = File
.GetLastWriteTime(filePath)
.ToString(
$"{Settings.PreviewPanelDateFormat} {Settings.PreviewPanelTimeFormat}",
CultureInfo.CurrentCulture
);
DateTime lastModifiedDate = File.GetLastWriteTime(filePath);
string formattedDate = lastModifiedDate.ToString(
$"{Settings.PreviewPanelDateFormat} {Settings.PreviewPanelTimeFormat}",
CultureInfo.CurrentCulture
);
string result = formattedDate;
if (Settings.ShowFileAgeInPreviewPanel) result = $"{GetFileAge(lastModifiedDate)} - {formattedDate}";
LastModifiedAt = result;
}
_ = LoadImageAsync();
@ -90,6 +96,30 @@ public partial class PreviewPanel : UserControl, INotifyPropertyChanged
{
PreviewImage = await Main.Context.API.LoadImageAsync(FilePath, true).ConfigureAwait(false);
}
private static string GetFileAge(DateTime fileDateTime)
{
var now = DateTime.Now;
var difference = now - fileDateTime;
if (difference.TotalDays < 1)
return Main.Context.API.GetTranslation("Today");
if (difference.TotalDays < 30)
return string.Format(Main.Context.API.GetTranslation("DaysAgo"), (int)difference.TotalDays);
var monthsDiff = (now.Year - fileDateTime.Year) * 12 + now.Month - fileDateTime.Month;
if (monthsDiff == 1)
return Main.Context.API.GetTranslation("OneMonthAgo");
if (monthsDiff < 12)
return string.Format(Main.Context.API.GetTranslation("MonthsAgo"), monthsDiff);
var yearsDiff = now.Year - fileDateTime.Year;
if (now.Month < fileDateTime.Month || (now.Month == fileDateTime.Month && now.Day < fileDateTime.Day))
yearsDiff--;
return yearsDiff == 1 ? Main.Context.API.GetTranslation("OneYearAgo") :
string.Format(Main.Context.API.GetTranslation("YearsAgo"), yearsDiff);
}
public event PropertyChangedEventHandler? PropertyChanged;