Skip to content

Commit 6333cd3

Browse files
authored
Merge pull request #3579 from 01Dri/display-the-File-age-in-preview-panel
Display the file age in preview panel
2 parents 2026bb7 + 62d7256 commit 6333cd3

File tree

5 files changed

+72
-14
lines changed

5 files changed

+72
-14
lines changed

Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<system:String x:Key="plugin_explorer_previewpanel_display_file_size_checkbox">Size</system:String>
3434
<system:String x:Key="plugin_explorer_previewpanel_display_file_creation_checkbox">Date Created</system:String>
3535
<system:String x:Key="plugin_explorer_previewpanel_display_file_modification_checkbox">Date Modified</system:String>
36+
<system:String x:Key="plugin_explorer_previewpanel_display_file_age_checkbox">File Age</system:String>
3637
<system:String x:Key="plugin_explorer_previewpanel_file_info_label">Display File Info</system:String>
3738
<system:String x:Key="plugin_explorer_previewpanel_date_and_time_format_label">Date and time format</system:String>
3839
<system:String x:Key="plugin_explorer_everything_sort_option">Sort Option:</system:String>
@@ -166,4 +167,12 @@
166167
<system:String x:Key="plugin_explorer_native_context_menu_display_context_menu">Display native context menu (experimental)</system:String>
167168
<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>
168169
<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>
170+
171+
<!-- Preview Info -->
172+
<system:String x:Key="Today">Today</system:String>
173+
<system:String x:Key="DaysAgo">{0} days ago</system:String>
174+
<system:String x:Key="OneMonthAgo">1 month ago</system:String>
175+
<system:String x:Key="MonthsAgo">{0} months ago</system:String>
176+
<system:String x:Key="OneYearAgo">1 year ago</system:String>
177+
<system:String x:Key="YearsAgo">{0} years ago</system:String>
169178
</ResourceDictionary>

Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public class Settings
2727

2828
public string ExcludedFileTypes { get; set; } = "";
2929

30-
3130
public bool UseLocationAsWorkingDir { get; set; } = false;
3231

3332
public bool ShowInlinedWindowsContextMenu { get; set; } = false;
@@ -66,6 +65,9 @@ public class Settings
6665
public bool ShowCreatedDateInPreviewPanel { get; set; } = true;
6766

6867
public bool ShowModifiedDateInPreviewPanel { get; set; } = true;
68+
69+
public bool ShowFileAgeInPreviewPanel { get; set; } = false;
70+
6971

7072
public string PreviewPanelDateFormat { get; set; } = "yyyy-MM-dd";
7173

Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,18 @@ public bool ShowModifiedDateInPreviewPanel
169169
}
170170
}
171171

172+
public bool ShowFileAgeInPreviewPanel
173+
{
174+
get => Settings.ShowFileAgeInPreviewPanel;
175+
set
176+
{
177+
Settings.ShowFileAgeInPreviewPanel = value;
178+
OnPropertyChanged();
179+
OnPropertyChanged(nameof(ShowPreviewPanelDateTimeChoices));
180+
OnPropertyChanged(nameof(PreviewPanelDateTimeChoicesVisibility));
181+
}
182+
}
183+
172184
public string PreviewPanelDateFormat
173185
{
174186
get => Settings.PreviewPanelDateFormat;

Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,11 @@
505505
Margin="{StaticResource SettingPanelItemLeftTopBottomMargin}"
506506
Content="{DynamicResource plugin_explorer_previewpanel_display_file_modification_checkbox}"
507507
IsChecked="{Binding ShowModifiedDateInPreviewPanel}" />
508+
509+
<CheckBox
510+
Margin="{StaticResource SettingPanelItemLeftTopBottomMargin}"
511+
Content="{DynamicResource plugin_explorer_previewpanel_display_file_age_checkbox}"
512+
IsChecked="{Binding ShowFileAgeInPreviewPanel}" />
508513
</WrapPanel>
509514
</DockPanel>
510515

Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.ComponentModel;
1+
using System;
2+
using System.ComponentModel;
23
using System.Globalization;
34
using System.IO;
45
using System.Runtime.CompilerServices;
@@ -65,22 +66,27 @@ public PreviewPanel(Settings settings, string filePath)
6566

6667
if (Settings.ShowCreatedDateInPreviewPanel)
6768
{
68-
CreatedAt = File
69-
.GetCreationTime(filePath)
70-
.ToString(
71-
$"{Settings.PreviewPanelDateFormat} {Settings.PreviewPanelTimeFormat}",
72-
CultureInfo.CurrentCulture
73-
);
69+
DateTime createdDate = File.GetCreationTime(filePath);
70+
string formattedDate = createdDate.ToString(
71+
$"{Settings.PreviewPanelDateFormat} {Settings.PreviewPanelTimeFormat}",
72+
CultureInfo.CurrentCulture
73+
);
74+
75+
string result = formattedDate;
76+
if (Settings.ShowFileAgeInPreviewPanel) result = $"{GetFileAge(createdDate)} - {formattedDate}";
77+
CreatedAt = result;
7478
}
7579

7680
if (Settings.ShowModifiedDateInPreviewPanel)
7781
{
78-
LastModifiedAt = File
79-
.GetLastWriteTime(filePath)
80-
.ToString(
81-
$"{Settings.PreviewPanelDateFormat} {Settings.PreviewPanelTimeFormat}",
82-
CultureInfo.CurrentCulture
83-
);
82+
DateTime lastModifiedDate = File.GetLastWriteTime(filePath);
83+
string formattedDate = lastModifiedDate.ToString(
84+
$"{Settings.PreviewPanelDateFormat} {Settings.PreviewPanelTimeFormat}",
85+
CultureInfo.CurrentCulture
86+
);
87+
string result = formattedDate;
88+
if (Settings.ShowFileAgeInPreviewPanel) result = $"{GetFileAge(lastModifiedDate)} - {formattedDate}";
89+
LastModifiedAt = result;
8490
}
8591

8692
_ = LoadImageAsync();
@@ -90,6 +96,30 @@ private async Task LoadImageAsync()
9096
{
9197
PreviewImage = await Main.Context.API.LoadImageAsync(FilePath, true).ConfigureAwait(false);
9298
}
99+
100+
private static string GetFileAge(DateTime fileDateTime)
101+
{
102+
var now = DateTime.Now;
103+
var difference = now - fileDateTime;
104+
105+
if (difference.TotalDays < 1)
106+
return Main.Context.API.GetTranslation("Today");
107+
if (difference.TotalDays < 30)
108+
return string.Format(Main.Context.API.GetTranslation("DaysAgo"), (int)difference.TotalDays);
109+
110+
var monthsDiff = (now.Year - fileDateTime.Year) * 12 + now.Month - fileDateTime.Month;
111+
if (monthsDiff == 1)
112+
return Main.Context.API.GetTranslation("OneMonthAgo");
113+
if (monthsDiff < 12)
114+
return string.Format(Main.Context.API.GetTranslation("MonthsAgo"), monthsDiff);
115+
116+
var yearsDiff = now.Year - fileDateTime.Year;
117+
if (now.Month < fileDateTime.Month || (now.Month == fileDateTime.Month && now.Day < fileDateTime.Day))
118+
yearsDiff--;
119+
120+
return yearsDiff == 1 ? Main.Context.API.GetTranslation("OneYearAgo") :
121+
string.Format(Main.Context.API.GetTranslation("YearsAgo"), yearsDiff);
122+
}
93123

94124
public event PropertyChangedEventHandler? PropertyChanged;
95125

0 commit comments

Comments
 (0)