diff --git a/Flow.Launcher.Plugin/Result.cs b/Flow.Launcher.Plugin/Result.cs
index 87b9a8b18..ea79386b3 100644
--- a/Flow.Launcher.Plugin/Result.cs
+++ b/Flow.Launcher.Plugin/Result.cs
@@ -129,21 +129,6 @@ namespace Flow.Launcher.Plugin
/// default: 0
public int Score { get; set; }
- ///
- /// File Size
- ///
- public string FileSize { get; set; } = string.Empty;
-
- ///
- /// Created
- ///
- public string FileCreated { get; set; } = string.Empty;
-
- ///
- /// Last Modified Date File
- ///
- public string LastModifed { get; set; } = string.Empty;
-
///
/// A list of indexes for the characters to be highlighted in Title
///
@@ -220,9 +205,6 @@ namespace Flow.Launcher.Plugin
TitleHighlightData = TitleHighlightData,
OriginQuery = OriginQuery,
PluginDirectory = PluginDirectory,
- FileCreated = FileCreated,
- FileSize = FileSize,
- LastModifed = LastModifed
};
}
@@ -318,8 +300,6 @@ namespace Flow.Launcher.Plugin
IsMedia = false,
PreviewDelegate = null,
};
-
-
}
}
}
diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml
index a234ea4be..7abeb47c1 100644
--- a/Flow.Launcher/MainWindow.xaml
+++ b/Flow.Launcher/MainWindow.xaml
@@ -492,82 +492,6 @@
x:Name="PreviewSubTitle"
Style="{DynamicResource PreviewItemSubTitleStyle}"
Text="{Binding Result.SubTitle}" />
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -583,4 +507,4 @@
-
\ No newline at end of file
+
diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs
index 60e4a31b4..a1cd67fe4 100644
--- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs
+++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs
@@ -8,14 +8,15 @@ using System.Threading.Tasks;
using System.Windows;
using Flow.Launcher.Plugin.Explorer.Search.Everything;
using System.Windows.Input;
-using System.Windows.Shapes;
using Path = System.IO.Path;
-using System.Globalization;
+using System.Windows.Controls;
+using Flow.Launcher.Plugin.Explorer.Views;
namespace Flow.Launcher.Plugin.Explorer.Search
{
public static class ResultManager
{
+ private static readonly string[] SizeUnits = { "B", "KB", "MB", "GB", "TB" };
private static PluginInitContext Context;
private static Settings Settings { get; set; }
@@ -175,36 +176,28 @@ namespace Flow.Launcher.Plugin.Explorer.Search
};
}
- private static string ToReadableSize(long pDrvSize, int pi)
+ internal static string ToReadableSize(long sizeOnDrive, int pi)
{
- int mok = 0;
- double drvSize = pDrvSize;
- string uom = "Byte"; // Unit Of Measurement
+ var unitIndex = 0;
+ double readableSize = sizeOnDrive;
- while (drvSize > 1024.0)
+ while (readableSize > 1024.0 && unitIndex < SizeUnits.Length - 1)
{
- drvSize /= 1024.0;
- mok++;
+ readableSize /= 1024.0;
+ unitIndex++;
}
- if (mok == 1)
- uom = "KB";
- else if (mok == 2)
- uom = "MB";
- else if (mok == 3)
- uom = "GB";
- else if (mok == 4)
- uom = "TB";
+ var unit = SizeUnits[unitIndex] ?? "";
- var returnStr = $"{Convert.ToInt32(drvSize)}{uom}";
- if (mok != 0)
+ var returnStr = $"{Convert.ToInt32(readableSize)} {unit}";
+ if (unitIndex != 0)
{
returnStr = pi switch
{
- 1 => $"{drvSize:F1}{uom}",
- 2 => $"{drvSize:F2}{uom}",
- 3 => $"{drvSize:F3}{uom}",
- _ => $"{Convert.ToInt32(drvSize)}{uom}"
+ 1 => $"{readableSize:F1} {unit}",
+ 2 => $"{readableSize:F2} {unit}",
+ 3 => $"{readableSize:F3} {unit}",
+ _ => $"{Convert.ToInt32(readableSize)} {unit}"
};
}
@@ -242,17 +235,8 @@ namespace Flow.Launcher.Plugin.Explorer.Search
var title = Path.GetFileName(filePath);
-
+
/* Preview Detail */
- long fileSize = new System.IO.FileInfo(filePath).Length;
- string fileSizStr = ToReadableSize(fileSize, 2);
-
- DateTime created = System.IO.File.GetCreationTime(filePath);
- string createdStr = created.ToString("yy-M-dd ddd hh:mm", CultureInfo.CurrentCulture);
- DateTime lastModified = System.IO.File.GetLastWriteTime(filePath);
- string lastModifiedStr = lastModified.ToString("yy-M-dd ddd hh:mm", CultureInfo.CurrentCulture);
-
-
var result = new Result
{
@@ -263,10 +247,8 @@ namespace Flow.Launcher.Plugin.Explorer.Search
AutoCompleteText = GetAutoCompleteText(title, query, filePath, ResultType.File),
TitleHighlightData = StringMatcher.FuzzySearch(query.Search, title).MatchData,
Score = score,
- FileSize = fileSizStr,
- FileCreated = createdStr,
- LastModifed = lastModifiedStr,
CopyText = filePath,
+ PreviewPanel = new Lazy(() => new PreviewPanel(filePath)),
Action = c =>
{
try
diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml b/Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml
new file mode 100644
index 000000000..ded9a97ab
--- /dev/null
+++ b/Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml
@@ -0,0 +1,137 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs
new file mode 100644
index 000000000..aa9d33fe1
--- /dev/null
+++ b/Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs
@@ -0,0 +1,64 @@
+using System;
+using System.ComponentModel;
+using System.Globalization;
+using System.IO;
+using System.Runtime.CompilerServices;
+using System.Threading.Tasks;
+using System.Windows.Controls;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using Flow.Launcher.Infrastructure.Image;
+using Flow.Launcher.Plugin.Explorer.Search;
+
+namespace Flow.Launcher.Plugin.Explorer.Views;
+
+#nullable enable
+
+public partial class PreviewPanel : UserControl, INotifyPropertyChanged
+{
+ private string FilePath { get; }
+ public string FileSize { get; }
+ public string CreatedAt { get; }
+ public string LastModifiedAt { get; }
+ private ImageSource _previewImage = new BitmapImage();
+
+ public ImageSource PreviewImage
+ {
+ get => _previewImage;
+ private set
+ {
+ _previewImage = value;
+ OnPropertyChanged();
+ }
+ }
+
+ public PreviewPanel(string filePath)
+ {
+ InitializeComponent();
+
+ FilePath = filePath;
+
+ var fileSize = new FileInfo(filePath).Length;
+ FileSize = ResultManager.ToReadableSize(fileSize, 2);
+
+ DateTime created = File.GetCreationTime(filePath);
+ CreatedAt = created.ToString("yy-M-dd ddd hh:mm", CultureInfo.CurrentCulture);
+
+ DateTime lastModified = File.GetLastWriteTime(filePath);
+ LastModifiedAt = lastModified.ToString("yy-M-dd ddd hh:mm", CultureInfo.CurrentCulture);
+
+ _ = LoadImageAsync();
+ }
+
+ private async Task LoadImageAsync()
+ {
+ PreviewImage = await ImageLoader.LoadAsync(FilePath, true).ConfigureAwait(false);
+ }
+
+ public event PropertyChangedEventHandler? PropertyChanged;
+
+ protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
+ {
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+ }
+}