mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Move the additional explorer plugin functionality into the explorer plugin itself
This commit is contained in:
parent
fa0d42e5ce
commit
696ae7e20d
5 changed files with 220 additions and 133 deletions
|
|
@ -129,21 +129,6 @@ namespace Flow.Launcher.Plugin
|
|||
/// <value>default: 0</value>
|
||||
public int Score { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// File Size
|
||||
/// </summary>
|
||||
public string FileSize { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Created
|
||||
/// </summary>
|
||||
public string FileCreated { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Last Modified Date File
|
||||
/// </summary>
|
||||
public string LastModifed { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// A list of indexes for the characters to be highlighted in Title
|
||||
/// </summary>
|
||||
|
|
@ -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,
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -492,82 +492,6 @@
|
|||
x:Name="PreviewSubTitle"
|
||||
Style="{DynamicResource PreviewItemSubTitleStyle}"
|
||||
Text="{Binding Result.SubTitle}" />
|
||||
<StackPanel Orientation="Vertical">
|
||||
<StackPanel.Style>
|
||||
<Style TargetType="{x:Type StackPanel}">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding ElementName=SizeValue, UpdateSourceTrigger=PropertyChanged, Path=Text}" Value="{x:Static sys:String.Empty}">
|
||||
<Setter Property="Height" Value="0" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</StackPanel.Style>
|
||||
<Separator Margin="0,0,0,0" Style="{DynamicResource PreviewSep}" />
|
||||
<Grid Margin="0,10,0,0" VerticalAlignment="Center">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="100" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock
|
||||
Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
Margin="0"
|
||||
VerticalAlignment="Top"
|
||||
Style="{DynamicResource PreviewItemSubTitleStyle}"
|
||||
Text="{DynamicResource FileSize}"
|
||||
TextWrapping="Wrap" />
|
||||
<TextBlock
|
||||
Name="SizeValue"
|
||||
Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
Margin="0"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"
|
||||
Style="{DynamicResource PreviewItemSubTitleStyle}"
|
||||
Text="{Binding Result.FileSize}"
|
||||
TextWrapping="Wrap" />
|
||||
<TextBlock
|
||||
Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Margin="0"
|
||||
VerticalAlignment="Top"
|
||||
Style="{DynamicResource PreviewItemSubTitleStyle}"
|
||||
Text="{DynamicResource Created}"
|
||||
TextWrapping="Wrap" />
|
||||
<TextBlock
|
||||
Grid.Row="1"
|
||||
Grid.Column="1"
|
||||
Margin="0"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"
|
||||
Style="{DynamicResource PreviewItemSubTitleStyle}"
|
||||
Text="{Binding Result.FileCreated}"
|
||||
TextWrapping="Wrap" />
|
||||
|
||||
<TextBlock
|
||||
Grid.Row="2"
|
||||
Grid.Column="0"
|
||||
Margin="0"
|
||||
VerticalAlignment="Top"
|
||||
Style="{DynamicResource PreviewItemSubTitleStyle}"
|
||||
Text="{DynamicResource LastModified}"
|
||||
TextWrapping="Wrap" />
|
||||
<TextBlock
|
||||
Grid.Row="2"
|
||||
Grid.Column="1"
|
||||
Margin="0"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"
|
||||
Style="{DynamicResource PreviewItemSubTitleStyle}"
|
||||
Text="{Binding Result.LastModifed}"
|
||||
TextWrapping="Wrap" />
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
|
@ -583,4 +507,4 @@
|
|||
</StackPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Window>
|
||||
</Window>
|
||||
|
|
|
|||
|
|
@ -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<UserControl>(() => new PreviewPanel(filePath)),
|
||||
Action = c =>
|
||||
{
|
||||
try
|
||||
|
|
|
|||
137
Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml
Normal file
137
Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
<UserControl x:Class="Flow.Launcher.Plugin.Explorer.Views.PreviewPanel"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:sys="clr-namespace:System;assembly=System.Runtime"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="300" d:DesignWidth="300">
|
||||
<Grid Margin="20 0 10 0" VerticalAlignment="Stretch">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel Grid.Row="0" VerticalAlignment="Center">
|
||||
<Image
|
||||
Margin="0 16 0 0"
|
||||
Source="{Binding PreviewImage, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"
|
||||
HorizontalAlignment="Stretch"
|
||||
StretchDirection="DownOnly">
|
||||
<Image.Style>
|
||||
<Style TargetType="Image">
|
||||
<Setter Property="MaxWidth" Value="96" />
|
||||
<Setter Property="MaxHeight" Value="320" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding UseBigThumbnail}" Value="True">
|
||||
<Setter Property="MaxWidth" Value="{Binding ElementName=Preview, Path=ActualWidth}" />
|
||||
<Setter Property="MaxHeight" Value="{Binding ElementName=Preview, Path=ActualHeight}" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Image.Style>
|
||||
</Image>
|
||||
<TextBlock
|
||||
Margin="0 6 0 16"
|
||||
HorizontalAlignment="Stretch"
|
||||
Style="{DynamicResource PreviewItemTitleStyle}"
|
||||
Text="{Binding Result.Title}"
|
||||
TextAlignment="Center"
|
||||
TextWrapping="Wrap" />
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Row="1">
|
||||
<StackPanel.Style>
|
||||
<Style TargetType="StackPanel">
|
||||
<Style.Triggers>
|
||||
<DataTrigger
|
||||
Binding="{Binding Result.SubTitle.Length}"
|
||||
Value="0">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</StackPanel.Style>
|
||||
<Separator Style="{DynamicResource PreviewSep}" />
|
||||
<TextBlock
|
||||
Style="{DynamicResource PreviewItemSubTitleStyle}"
|
||||
Text="{Binding Result.SubTitle}" />
|
||||
<StackPanel Orientation="Vertical">
|
||||
<StackPanel.Style>
|
||||
<Style TargetType="StackPanel">
|
||||
<Style.Triggers>
|
||||
<DataTrigger
|
||||
Binding="{Binding ElementName=SizeValue, Path=Text}"
|
||||
Value="{x:Static sys:String.Empty}">
|
||||
<Setter Property="Height" Value="0" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</StackPanel.Style>
|
||||
<Separator Margin="0" Style="{DynamicResource PreviewSep}" />
|
||||
<Grid Margin="0 10 0 0" VerticalAlignment="Center">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="100" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock
|
||||
Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
Margin="0"
|
||||
VerticalAlignment="Top"
|
||||
Style="{DynamicResource PreviewItemSubTitleStyle}"
|
||||
Text="{DynamicResource FileSize}"
|
||||
TextWrapping="Wrap" />
|
||||
<TextBlock
|
||||
Name="SizeValue"
|
||||
Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
Margin="0"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"
|
||||
Style="{DynamicResource PreviewItemSubTitleStyle}"
|
||||
Text="{Binding FileSize, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"
|
||||
TextWrapping="Wrap" />
|
||||
<TextBlock
|
||||
Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Margin="0"
|
||||
VerticalAlignment="Top"
|
||||
Style="{DynamicResource PreviewItemSubTitleStyle}"
|
||||
Text="{DynamicResource Created}"
|
||||
TextWrapping="Wrap" />
|
||||
<TextBlock
|
||||
Grid.Row="1"
|
||||
Grid.Column="1"
|
||||
Margin="0"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"
|
||||
Style="{DynamicResource PreviewItemSubTitleStyle}"
|
||||
Text="{Binding CreatedAt, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"
|
||||
TextWrapping="Wrap" />
|
||||
|
||||
<TextBlock
|
||||
Grid.Row="2"
|
||||
Grid.Column="0"
|
||||
Margin="0"
|
||||
VerticalAlignment="Top"
|
||||
Style="{DynamicResource PreviewItemSubTitleStyle}"
|
||||
Text="{DynamicResource LastModified}"
|
||||
TextWrapping="Wrap" />
|
||||
<TextBlock
|
||||
Grid.Row="2"
|
||||
Grid.Column="1"
|
||||
Margin="0"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"
|
||||
Style="{DynamicResource PreviewItemSubTitleStyle}"
|
||||
Text="{Binding LastModifiedAt, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"
|
||||
TextWrapping="Wrap" />
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue