Add settings for file size and date/time in explorer plugin

This commit is contained in:
Yusyuriv 2024-05-24 09:51:24 +06:00
parent 696ae7e20d
commit 5b561f4dce
No known key found for this signature in database
GPG key ID: A91C52E6F73148E0
7 changed files with 222 additions and 18 deletions

View file

@ -29,6 +29,11 @@
<system:String x:Key="plugin_explorer_manageactionkeywords_header">Customise Action Keywords</system:String>
<system:String x:Key="plugin_explorer_quickaccesslinks_header">Quick Access Links</system:String>
<system:String x:Key="plugin_explorer_everything_setting_header">Everything Setting</system:String>
<system:String x:Key="plugin_explorer_previewpanel_setting_header">Preview Panel</system:String>
<system:String x:Key="plugin_explorer_previewpanel_display_file_size_checkbox">Display file size</system:String>
<system:String x:Key="plugin_explorer_previewpanel_display_file_creation_checkbox">Display file creation date</system:String>
<system:String x:Key="plugin_explorer_previewpanel_display_file_modification_checkbox">Display file modification date</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>
<system:String x:Key="plugin_explorer_everything_installed_path">Everything Path:</system:String>
<system:String x:Key="plugin_explorer_launch_hidden">Launch Hidden</system:String>
@ -133,7 +138,7 @@
<system:String x:Key="flowlauncher_plugin_everything_nonfastsort_warning">Warning: This is not a Fast Sort option, searches may be slow</system:String>
<system:String x:Key="flowlauncher_plugin_everything_search_fullpath">Search Full Path</system:String>
<system:String x:Key="flowlauncher_plugin_everything_click_to_launch_or_install">Click to launch or install Everything</system:String>
<system:String x:Key="flowlauncher_plugin_everything_installing_title">Everything Installation</system:String>
<system:String x:Key="flowlauncher_plugin_everything_installing_subtitle">Installing Everything service. Please wait...</system:String>

View file

@ -248,7 +248,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
TitleHighlightData = StringMatcher.FuzzySearch(query.Search, title).MatchData,
Score = score,
CopyText = filePath,
PreviewPanel = new Lazy<UserControl>(() => new PreviewPanel(filePath)),
PreviewPanel = new Lazy<UserControl>(() => new PreviewPanel(Settings, filePath)),
Action = c =>
{
try

View file

@ -55,6 +55,16 @@ namespace Flow.Launcher.Plugin.Explorer
public bool WarnWindowsSearchServiceOff { get; set; } = true;
public bool ShowFileSizeInPreviewPanel { get; set; } = true;
public bool ShowCreatedDateInPreviewPanel { get; set; } = true;
public bool ShowModifiedDateInPreviewPanel { get; set; } = true;
public string PreviewPanelDateFormat { get; set; } = "yyyy-MM-dd";
public string PreviewPanelTimeFormat { get; set; } = "HH:mm";
private EverythingSearchManager _everythingManagerInstance;
private WindowsIndexSearchManager _windowsIndexSearchManager;
@ -137,7 +147,7 @@ namespace Flow.Launcher.Plugin.Explorer
ContentSearchEngine == ContentIndexSearchEngineOption.Everything;
public bool EverythingSearchFullPath { get; set; } = false;
#endregion
internal enum ActionKeyword

View file

@ -8,6 +8,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Windows;
@ -101,7 +102,107 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
#endregion
#region Preview Panel
public bool ShowFileSizeInPreviewPanel
{
get => Settings.ShowFileSizeInPreviewPanel;
set
{
Settings.ShowFileSizeInPreviewPanel = value;
OnPropertyChanged();
}
}
public bool ShowCreatedDateInPreviewPanel
{
get => Settings.ShowCreatedDateInPreviewPanel;
set
{
Settings.ShowCreatedDateInPreviewPanel = value;
OnPropertyChanged();
OnPropertyChanged(nameof(ShowPreviewPanelDateTimeChoices));
OnPropertyChanged(nameof(PreviewPanelDateTimeChoicesVisibility));
}
}
public bool ShowModifiedDateInPreviewPanel
{
get => Settings.ShowModifiedDateInPreviewPanel;
set
{
Settings.ShowModifiedDateInPreviewPanel = value;
OnPropertyChanged();
OnPropertyChanged(nameof(ShowPreviewPanelDateTimeChoices));
OnPropertyChanged(nameof(PreviewPanelDateTimeChoicesVisibility));
}
}
public string PreviewPanelDateFormat
{
get => Settings.PreviewPanelDateFormat;
set
{
Settings.PreviewPanelDateFormat = value;
OnPropertyChanged();
OnPropertyChanged(nameof(PreviewPanelDateFormatDemo));
}
}
public string PreviewPanelTimeFormat
{
get => Settings.PreviewPanelTimeFormat;
set
{
Settings.PreviewPanelTimeFormat = value;
OnPropertyChanged();
OnPropertyChanged(nameof(PreviewPanelTimeFormatDemo));
}
}
public string PreviewPanelDateFormatDemo => DateTime.Now.ToString(PreviewPanelDateFormat, CultureInfo.CurrentCulture);
public string PreviewPanelTimeFormatDemo => DateTime.Now.ToString(PreviewPanelTimeFormat, CultureInfo.CurrentCulture);
public bool ShowPreviewPanelDateTimeChoices => ShowCreatedDateInPreviewPanel || ShowModifiedDateInPreviewPanel;
public Visibility PreviewPanelDateTimeChoicesVisibility => ShowCreatedDateInPreviewPanel || ShowModifiedDateInPreviewPanel ? Visibility.Visible : Visibility.Collapsed;
public List<string> TimeFormatList { get; } = new()
{
"h:mm",
"hh:mm",
"H:mm",
"HH:mm",
"tt h:mm",
"tt hh:mm",
"h:mm tt",
"hh:mm tt",
"hh:mm:ss tt",
"HH:mm:ss"
};
public List<string> DateFormatList { get; } = new()
{
"dd/MM/yyyy",
"dd/MM/yyyy ddd",
"dd/MM/yyyy, dddd",
"dd-MM-yyyy",
"dd-MM-yyyy ddd",
"dd-MM-yyyy, dddd",
"dd.MM.yyyy",
"dd.MM.yyyy ddd",
"dd.MM.yyyy, dddd",
"MM/dd/yyyy",
"MM/dd/yyyy ddd",
"MM/dd/yyyy, dddd",
"yyyy-MM-dd",
"yyyy-MM-dd ddd",
"yyyy-MM-dd, dddd",
};
#endregion
#region ActionKeyword

View file

@ -348,6 +348,57 @@
</StackPanel>
</StackPanel>
</TabItem>
<TabItem
Width="Auto"
Header="{DynamicResource plugin_explorer_previewpanel_setting_header}"
Style="{DynamicResource ExplorerTabItem}">
<StackPanel Margin="30,20,0,10">
<CheckBox
Content="{DynamicResource plugin_explorer_previewpanel_display_file_size_checkbox}"
IsChecked="{Binding ShowFileSizeInPreviewPanel}" />
<CheckBox
Margin="0,10,0,0"
Content="{DynamicResource plugin_explorer_previewpanel_display_file_creation_checkbox}"
IsChecked="{Binding ShowCreatedDateInPreviewPanel}" />
<CheckBox
Margin="0,10,0,0"
Content="{DynamicResource plugin_explorer_previewpanel_display_file_modification_checkbox}"
IsChecked="{Binding ShowModifiedDateInPreviewPanel}" />
<StackPanel
Margin="0,20,0,0"
IsEnabled="{Binding ShowPreviewPanelDateTimeChoices}"
Visibility="{Binding PreviewPanelDateTimeChoicesVisibility}">
<TextBlock
Text="{DynamicResource plugin_explorer_previewpanel_date_and_time_format_label}"
Foreground="{DynamicResource Color05B}" />
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<ComboBox
Width="200"
ItemsSource="{Binding DateFormatList}"
SelectedItem="{Binding PreviewPanelDateFormat}" />
<TextBlock
Margin="12,0,0,0"
VerticalAlignment="Center"
Text="{Binding PreviewPanelDateFormatDemo}"
Foreground="{DynamicResource Color05B}" />
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<ComboBox
Width="200"
ItemsSource="{Binding TimeFormatList}"
SelectedItem="{Binding PreviewPanelTimeFormat}" />
<TextBlock
Margin="12,0,0,0"
VerticalAlignment="Center"
Text="{Binding PreviewPanelTimeFormatDemo}"
Foreground="{DynamicResource Color05B}" />
</StackPanel>
</StackPanel>
</StackPanel>
</TabItem>
<TabItem
Width="Auto"
Header="{DynamicResource plugin_explorer_everything_setting_header}"

View file

@ -80,7 +80,8 @@
<TextBlock
Grid.Row="0"
Grid.Column="0"
Margin="0"
Margin="0 0 8 0"
Visibility="{Binding FileSizeVisibility, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"
VerticalAlignment="Top"
Style="{DynamicResource PreviewItemSubTitleStyle}"
Text="{DynamicResource FileSize}"
@ -90,15 +91,18 @@
Grid.Row="0"
Grid.Column="1"
Margin="0"
Visibility="{Binding FileSizeVisibility, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"
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"
Margin="0 0 8 0"
Visibility="{Binding CreatedAtVisibility, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"
VerticalAlignment="Top"
Style="{DynamicResource PreviewItemSubTitleStyle}"
Text="{DynamicResource Created}"
@ -107,6 +111,7 @@
Grid.Row="1"
Grid.Column="1"
Margin="0"
Visibility="{Binding CreatedAtVisibility, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Style="{DynamicResource PreviewItemSubTitleStyle}"
@ -116,7 +121,8 @@
<TextBlock
Grid.Row="2"
Grid.Column="0"
Margin="0"
Margin="0 0 8 0"
Visibility="{Binding LastModifiedAtVisibility, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"
VerticalAlignment="Top"
Style="{DynamicResource PreviewItemSubTitleStyle}"
Text="{DynamicResource LastModified}"
@ -125,6 +131,7 @@
Grid.Row="2"
Grid.Column="1"
Margin="0"
Visibility="{Binding LastModifiedAtVisibility, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Style="{DynamicResource PreviewItemSubTitleStyle}"

View file

@ -1,9 +1,9 @@
using System;
using System.ComponentModel;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
@ -17,10 +17,11 @@ namespace Flow.Launcher.Plugin.Explorer.Views;
public partial class PreviewPanel : UserControl, INotifyPropertyChanged
{
private string FilePath { get; }
public string FileSize { get; }
public string CreatedAt { get; }
public string LastModifiedAt { get; }
public string FileSize { get; } = "";
public string CreatedAt { get; } = "";
public string LastModifiedAt { get; } = "";
private ImageSource _previewImage = new BitmapImage();
private Settings Settings { get; }
public ImageSource PreviewImage
{
@ -32,20 +33,49 @@ public partial class PreviewPanel : UserControl, INotifyPropertyChanged
}
}
public PreviewPanel(string filePath)
public Visibility FileSizeVisibility => Settings.ShowFileSizeInPreviewPanel
? Visibility.Visible
: Visibility.Collapsed;
public Visibility CreatedAtVisibility => Settings.ShowCreatedDateInPreviewPanel
? Visibility.Visible
: Visibility.Collapsed;
public Visibility LastModifiedAtVisibility => Settings.ShowModifiedDateInPreviewPanel
? Visibility.Visible
: Visibility.Collapsed;
public PreviewPanel(Settings settings, string filePath)
{
InitializeComponent();
Settings = settings;
FilePath = filePath;
var fileSize = new FileInfo(filePath).Length;
FileSize = ResultManager.ToReadableSize(fileSize, 2);
if (Settings.ShowFileSizeInPreviewPanel)
{
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);
if (Settings.ShowCreatedDateInPreviewPanel)
{
CreatedAt = File
.GetCreationTime(filePath)
.ToString(
$"{Settings.PreviewPanelDateFormat} {Settings.PreviewPanelTimeFormat}",
CultureInfo.CurrentCulture
);
}
DateTime lastModified = File.GetLastWriteTime(filePath);
LastModifiedAt = lastModified.ToString("yy-M-dd ddd hh:mm", CultureInfo.CurrentCulture);
if (Settings.ShowModifiedDateInPreviewPanel)
{
LastModifiedAt = File
.GetLastWriteTime(filePath)
.ToString(
$"{Settings.PreviewPanelDateFormat} {Settings.PreviewPanelTimeFormat}",
CultureInfo.CurrentCulture
);
}
_ = LoadImageAsync();
}