Skip to content

Commit 5b561f4

Browse files
committed
Add settings for file size and date/time in explorer plugin
1 parent 696ae7e commit 5b561f4

File tree

7 files changed

+222
-18
lines changed

7 files changed

+222
-18
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
<system:String x:Key="plugin_explorer_manageactionkeywords_header">Customise Action Keywords</system:String>
3030
<system:String x:Key="plugin_explorer_quickaccesslinks_header">Quick Access Links</system:String>
3131
<system:String x:Key="plugin_explorer_everything_setting_header">Everything Setting</system:String>
32+
<system:String x:Key="plugin_explorer_previewpanel_setting_header">Preview Panel</system:String>
33+
<system:String x:Key="plugin_explorer_previewpanel_display_file_size_checkbox">Display file size</system:String>
34+
<system:String x:Key="plugin_explorer_previewpanel_display_file_creation_checkbox">Display file creation date</system:String>
35+
<system:String x:Key="plugin_explorer_previewpanel_display_file_modification_checkbox">Display file modification date</system:String>
36+
<system:String x:Key="plugin_explorer_previewpanel_date_and_time_format_label">Date and time format:</system:String>
3237
<system:String x:Key="plugin_explorer_everything_sort_option">Sort Option:</system:String>
3338
<system:String x:Key="plugin_explorer_everything_installed_path">Everything Path:</system:String>
3439
<system:String x:Key="plugin_explorer_launch_hidden">Launch Hidden</system:String>
@@ -133,7 +138,7 @@
133138
<system:String x:Key="flowlauncher_plugin_everything_nonfastsort_warning">Warning: This is not a Fast Sort option, searches may be slow</system:String>
134139

135140
<system:String x:Key="flowlauncher_plugin_everything_search_fullpath">Search Full Path</system:String>
136-
141+
137142
<system:String x:Key="flowlauncher_plugin_everything_click_to_launch_or_install">Click to launch or install Everything</system:String>
138143
<system:String x:Key="flowlauncher_plugin_everything_installing_title">Everything Installation</system:String>
139144
<system:String x:Key="flowlauncher_plugin_everything_installing_subtitle">Installing Everything service. Please wait...</system:String>

Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ internal static Result CreateFileResult(string filePath, Query query, int score
248248
TitleHighlightData = StringMatcher.FuzzySearch(query.Search, title).MatchData,
249249
Score = score,
250250
CopyText = filePath,
251-
PreviewPanel = new Lazy<UserControl>(() => new PreviewPanel(filePath)),
251+
PreviewPanel = new Lazy<UserControl>(() => new PreviewPanel(Settings, filePath)),
252252
Action = c =>
253253
{
254254
try

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ public class Settings
5555

5656
public bool WarnWindowsSearchServiceOff { get; set; } = true;
5757

58+
public bool ShowFileSizeInPreviewPanel { get; set; } = true;
59+
60+
public bool ShowCreatedDateInPreviewPanel { get; set; } = true;
61+
62+
public bool ShowModifiedDateInPreviewPanel { get; set; } = true;
63+
64+
public string PreviewPanelDateFormat { get; set; } = "yyyy-MM-dd";
65+
66+
public string PreviewPanelTimeFormat { get; set; } = "HH:mm";
67+
5868
private EverythingSearchManager _everythingManagerInstance;
5969
private WindowsIndexSearchManager _windowsIndexSearchManager;
6070

@@ -137,7 +147,7 @@ public enum ContentIndexSearchEngineOption
137147
ContentSearchEngine == ContentIndexSearchEngineOption.Everything;
138148

139149
public bool EverythingSearchFullPath { get; set; } = false;
140-
150+
141151
#endregion
142152

143153
internal enum ActionKeyword

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

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Collections.Generic;
99
using System.Diagnostics;
1010
using System.Diagnostics.CodeAnalysis;
11+
using System.Globalization;
1112
using System.IO;
1213
using System.Linq;
1314
using System.Windows;
@@ -101,7 +102,107 @@ private void InitializeEngineSelection()
101102

102103
#endregion
103104

105+
#region Preview Panel
104106

107+
public bool ShowFileSizeInPreviewPanel
108+
{
109+
get => Settings.ShowFileSizeInPreviewPanel;
110+
set
111+
{
112+
Settings.ShowFileSizeInPreviewPanel = value;
113+
OnPropertyChanged();
114+
}
115+
}
116+
117+
public bool ShowCreatedDateInPreviewPanel
118+
{
119+
get => Settings.ShowCreatedDateInPreviewPanel;
120+
set
121+
{
122+
Settings.ShowCreatedDateInPreviewPanel = value;
123+
OnPropertyChanged();
124+
OnPropertyChanged(nameof(ShowPreviewPanelDateTimeChoices));
125+
OnPropertyChanged(nameof(PreviewPanelDateTimeChoicesVisibility));
126+
}
127+
}
128+
129+
public bool ShowModifiedDateInPreviewPanel
130+
{
131+
get => Settings.ShowModifiedDateInPreviewPanel;
132+
set
133+
{
134+
Settings.ShowModifiedDateInPreviewPanel = value;
135+
OnPropertyChanged();
136+
OnPropertyChanged(nameof(ShowPreviewPanelDateTimeChoices));
137+
OnPropertyChanged(nameof(PreviewPanelDateTimeChoicesVisibility));
138+
}
139+
}
140+
141+
public string PreviewPanelDateFormat
142+
{
143+
get => Settings.PreviewPanelDateFormat;
144+
set
145+
{
146+
Settings.PreviewPanelDateFormat = value;
147+
OnPropertyChanged();
148+
OnPropertyChanged(nameof(PreviewPanelDateFormatDemo));
149+
}
150+
}
151+
152+
public string PreviewPanelTimeFormat
153+
{
154+
get => Settings.PreviewPanelTimeFormat;
155+
set
156+
{
157+
Settings.PreviewPanelTimeFormat = value;
158+
OnPropertyChanged();
159+
OnPropertyChanged(nameof(PreviewPanelTimeFormatDemo));
160+
}
161+
}
162+
163+
public string PreviewPanelDateFormatDemo => DateTime.Now.ToString(PreviewPanelDateFormat, CultureInfo.CurrentCulture);
164+
public string PreviewPanelTimeFormatDemo => DateTime.Now.ToString(PreviewPanelTimeFormat, CultureInfo.CurrentCulture);
165+
166+
public bool ShowPreviewPanelDateTimeChoices => ShowCreatedDateInPreviewPanel || ShowModifiedDateInPreviewPanel;
167+
168+
public Visibility PreviewPanelDateTimeChoicesVisibility => ShowCreatedDateInPreviewPanel || ShowModifiedDateInPreviewPanel ? Visibility.Visible : Visibility.Collapsed;
169+
170+
171+
public List<string> TimeFormatList { get; } = new()
172+
{
173+
"h:mm",
174+
"hh:mm",
175+
"H:mm",
176+
"HH:mm",
177+
"tt h:mm",
178+
"tt hh:mm",
179+
"h:mm tt",
180+
"hh:mm tt",
181+
"hh:mm:ss tt",
182+
"HH:mm:ss"
183+
};
184+
185+
186+
public List<string> DateFormatList { get; } = new()
187+
{
188+
"dd/MM/yyyy",
189+
"dd/MM/yyyy ddd",
190+
"dd/MM/yyyy, dddd",
191+
"dd-MM-yyyy",
192+
"dd-MM-yyyy ddd",
193+
"dd-MM-yyyy, dddd",
194+
"dd.MM.yyyy",
195+
"dd.MM.yyyy ddd",
196+
"dd.MM.yyyy, dddd",
197+
"MM/dd/yyyy",
198+
"MM/dd/yyyy ddd",
199+
"MM/dd/yyyy, dddd",
200+
"yyyy-MM-dd",
201+
"yyyy-MM-dd ddd",
202+
"yyyy-MM-dd, dddd",
203+
};
204+
205+
#endregion
105206

106207
#region ActionKeyword
107208

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,57 @@
348348
</StackPanel>
349349
</StackPanel>
350350
</TabItem>
351+
<TabItem
352+
Width="Auto"
353+
Header="{DynamicResource plugin_explorer_previewpanel_setting_header}"
354+
Style="{DynamicResource ExplorerTabItem}">
355+
<StackPanel Margin="30,20,0,10">
356+
<CheckBox
357+
Content="{DynamicResource plugin_explorer_previewpanel_display_file_size_checkbox}"
358+
IsChecked="{Binding ShowFileSizeInPreviewPanel}" />
359+
360+
<CheckBox
361+
Margin="0,10,0,0"
362+
Content="{DynamicResource plugin_explorer_previewpanel_display_file_creation_checkbox}"
363+
IsChecked="{Binding ShowCreatedDateInPreviewPanel}" />
364+
365+
<CheckBox
366+
Margin="0,10,0,0"
367+
Content="{DynamicResource plugin_explorer_previewpanel_display_file_modification_checkbox}"
368+
IsChecked="{Binding ShowModifiedDateInPreviewPanel}" />
369+
370+
<StackPanel
371+
Margin="0,20,0,0"
372+
IsEnabled="{Binding ShowPreviewPanelDateTimeChoices}"
373+
Visibility="{Binding PreviewPanelDateTimeChoicesVisibility}">
374+
<TextBlock
375+
Text="{DynamicResource plugin_explorer_previewpanel_date_and_time_format_label}"
376+
Foreground="{DynamicResource Color05B}" />
377+
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
378+
<ComboBox
379+
Width="200"
380+
ItemsSource="{Binding DateFormatList}"
381+
SelectedItem="{Binding PreviewPanelDateFormat}" />
382+
<TextBlock
383+
Margin="12,0,0,0"
384+
VerticalAlignment="Center"
385+
Text="{Binding PreviewPanelDateFormatDemo}"
386+
Foreground="{DynamicResource Color05B}" />
387+
</StackPanel>
388+
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
389+
<ComboBox
390+
Width="200"
391+
ItemsSource="{Binding TimeFormatList}"
392+
SelectedItem="{Binding PreviewPanelTimeFormat}" />
393+
<TextBlock
394+
Margin="12,0,0,0"
395+
VerticalAlignment="Center"
396+
Text="{Binding PreviewPanelTimeFormatDemo}"
397+
Foreground="{DynamicResource Color05B}" />
398+
</StackPanel>
399+
</StackPanel>
400+
</StackPanel>
401+
</TabItem>
351402
<TabItem
352403
Width="Auto"
353404
Header="{DynamicResource plugin_explorer_everything_setting_header}"

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@
8080
<TextBlock
8181
Grid.Row="0"
8282
Grid.Column="0"
83-
Margin="0"
83+
Margin="0 0 8 0"
84+
Visibility="{Binding FileSizeVisibility, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"
8485
VerticalAlignment="Top"
8586
Style="{DynamicResource PreviewItemSubTitleStyle}"
8687
Text="{DynamicResource FileSize}"
@@ -90,15 +91,18 @@
9091
Grid.Row="0"
9192
Grid.Column="1"
9293
Margin="0"
94+
Visibility="{Binding FileSizeVisibility, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"
9395
HorizontalAlignment="Right"
9496
VerticalAlignment="Top"
9597
Style="{DynamicResource PreviewItemSubTitleStyle}"
9698
Text="{Binding FileSize, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"
9799
TextWrapping="Wrap" />
100+
98101
<TextBlock
99102
Grid.Row="1"
100103
Grid.Column="0"
101-
Margin="0"
104+
Margin="0 0 8 0"
105+
Visibility="{Binding CreatedAtVisibility, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"
102106
VerticalAlignment="Top"
103107
Style="{DynamicResource PreviewItemSubTitleStyle}"
104108
Text="{DynamicResource Created}"
@@ -107,6 +111,7 @@
107111
Grid.Row="1"
108112
Grid.Column="1"
109113
Margin="0"
114+
Visibility="{Binding CreatedAtVisibility, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"
110115
HorizontalAlignment="Right"
111116
VerticalAlignment="Top"
112117
Style="{DynamicResource PreviewItemSubTitleStyle}"
@@ -116,7 +121,8 @@
116121
<TextBlock
117122
Grid.Row="2"
118123
Grid.Column="0"
119-
Margin="0"
124+
Margin="0 0 8 0"
125+
Visibility="{Binding LastModifiedAtVisibility, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"
120126
VerticalAlignment="Top"
121127
Style="{DynamicResource PreviewItemSubTitleStyle}"
122128
Text="{DynamicResource LastModified}"
@@ -125,6 +131,7 @@
125131
Grid.Row="2"
126132
Grid.Column="1"
127133
Margin="0"
134+
Visibility="{Binding LastModifiedAtVisibility, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"
128135
HorizontalAlignment="Right"
129136
VerticalAlignment="Top"
130137
Style="{DynamicResource PreviewItemSubTitleStyle}"

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

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
using System;
2-
using System.ComponentModel;
1+
using System.ComponentModel;
32
using System.Globalization;
43
using System.IO;
54
using System.Runtime.CompilerServices;
65
using System.Threading.Tasks;
6+
using System.Windows;
77
using System.Windows.Controls;
88
using System.Windows.Media;
99
using System.Windows.Media.Imaging;
@@ -17,10 +17,11 @@ namespace Flow.Launcher.Plugin.Explorer.Views;
1717
public partial class PreviewPanel : UserControl, INotifyPropertyChanged
1818
{
1919
private string FilePath { get; }
20-
public string FileSize { get; }
21-
public string CreatedAt { get; }
22-
public string LastModifiedAt { get; }
20+
public string FileSize { get; } = "";
21+
public string CreatedAt { get; } = "";
22+
public string LastModifiedAt { get; } = "";
2323
private ImageSource _previewImage = new BitmapImage();
24+
private Settings Settings { get; }
2425

2526
public ImageSource PreviewImage
2627
{
@@ -32,20 +33,49 @@ private set
3233
}
3334
}
3435

35-
public PreviewPanel(string filePath)
36+
public Visibility FileSizeVisibility => Settings.ShowFileSizeInPreviewPanel
37+
? Visibility.Visible
38+
: Visibility.Collapsed;
39+
public Visibility CreatedAtVisibility => Settings.ShowCreatedDateInPreviewPanel
40+
? Visibility.Visible
41+
: Visibility.Collapsed;
42+
public Visibility LastModifiedAtVisibility => Settings.ShowModifiedDateInPreviewPanel
43+
? Visibility.Visible
44+
: Visibility.Collapsed;
45+
46+
public PreviewPanel(Settings settings, string filePath)
3647
{
3748
InitializeComponent();
3849

50+
Settings = settings;
51+
3952
FilePath = filePath;
4053

41-
var fileSize = new FileInfo(filePath).Length;
42-
FileSize = ResultManager.ToReadableSize(fileSize, 2);
54+
if (Settings.ShowFileSizeInPreviewPanel)
55+
{
56+
var fileSize = new FileInfo(filePath).Length;
57+
FileSize = ResultManager.ToReadableSize(fileSize, 2);
58+
}
4359

44-
DateTime created = File.GetCreationTime(filePath);
45-
CreatedAt = created.ToString("yy-M-dd ddd hh:mm", CultureInfo.CurrentCulture);
60+
if (Settings.ShowCreatedDateInPreviewPanel)
61+
{
62+
CreatedAt = File
63+
.GetCreationTime(filePath)
64+
.ToString(
65+
$"{Settings.PreviewPanelDateFormat} {Settings.PreviewPanelTimeFormat}",
66+
CultureInfo.CurrentCulture
67+
);
68+
}
4669

47-
DateTime lastModified = File.GetLastWriteTime(filePath);
48-
LastModifiedAt = lastModified.ToString("yy-M-dd ddd hh:mm", CultureInfo.CurrentCulture);
70+
if (Settings.ShowModifiedDateInPreviewPanel)
71+
{
72+
LastModifiedAt = File
73+
.GetLastWriteTime(filePath)
74+
.ToString(
75+
$"{Settings.PreviewPanelDateFormat} {Settings.PreviewPanelTimeFormat}",
76+
CultureInfo.CurrentCulture
77+
);
78+
}
4979

5080
_ = LoadImageAsync();
5181
}

0 commit comments

Comments
 (0)