Skip to content

Commit 155eecd

Browse files
committed
Expose part functions to helper
1 parent 93c2b1b commit 155eecd

File tree

1 file changed

+36
-20
lines changed

1 file changed

+36
-20
lines changed

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

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,33 +60,17 @@ public PreviewPanel(Settings settings, string filePath)
6060

6161
if (Settings.ShowFileSizeInPreviewPanel)
6262
{
63-
var fileSize = new FileInfo(filePath).Length;
64-
FileSize = ResultManager.ToReadableSize(fileSize, 2);
63+
FileSize = GetFileSize(filePath);
6564
}
6665

6766
if (Settings.ShowCreatedDateInPreviewPanel)
6867
{
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;
68+
CreatedAt = GetCreatedAt(filePath, Settings.PreviewPanelDateFormat, Settings.PreviewPanelTimeFormat, Settings.ShowFileAgeInPreviewPanel);
7869
}
7970

8071
if (Settings.ShowModifiedDateInPreviewPanel)
8172
{
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;
73+
LastModifiedAt = GetLastModifiedAt(filePath, Settings.PreviewPanelDateFormat, Settings.PreviewPanelTimeFormat, Settings.ShowFileAgeInPreviewPanel);
9074
}
9175

9276
_ = LoadImageAsync();
@@ -96,7 +80,39 @@ private async Task LoadImageAsync()
9680
{
9781
PreviewImage = await Main.Context.API.LoadImageAsync(FilePath, true).ConfigureAwait(false);
9882
}
99-
83+
84+
public static string GetFileSize(string filePath)
85+
{
86+
var fileInfo = new FileInfo(filePath);
87+
return ResultManager.ToReadableSize(fileInfo.Length, 2);
88+
}
89+
90+
public static string GetCreatedAt(string filePath, string previewPanelDateFormat, string previewPanelTimeFormat, bool showFileAgeInPreviewPanel)
91+
{
92+
var createdDate = File.GetCreationTime(filePath);
93+
var formattedDate = createdDate.ToString(
94+
$"{previewPanelDateFormat} {previewPanelTimeFormat}",
95+
CultureInfo.CurrentCulture
96+
);
97+
98+
var result = formattedDate;
99+
if (showFileAgeInPreviewPanel) result = $"{GetFileAge(createdDate)} - {formattedDate}";
100+
return result;
101+
}
102+
103+
public static string GetLastModifiedAt(string filePath, string previewPanelDateFormat, string previewPanelTimeFormat, bool showFileAgeInPreviewPanel)
104+
{
105+
var lastModifiedDate = File.GetLastWriteTime(filePath);
106+
var formattedDate = lastModifiedDate.ToString(
107+
$"{previewPanelDateFormat} {previewPanelTimeFormat}",
108+
CultureInfo.CurrentCulture
109+
);
110+
111+
var result = formattedDate;
112+
if (showFileAgeInPreviewPanel) result = $"{GetFileAge(lastModifiedDate)} - {formattedDate}";
113+
return result;
114+
}
115+
100116
private static string GetFileAge(DateTime fileDateTime)
101117
{
102118
var now = DateTime.Now;

0 commit comments

Comments
 (0)