Skip to content

Commit 3436c57

Browse files
authored
Merge pull request #2679 from onesounds/240430PreviewSetting
Improve Explorer Preview Panel
2 parents 6133e55 + 72f0a74 commit 3436c57

File tree

10 files changed

+438
-30
lines changed

10 files changed

+438
-30
lines changed

Flow.Launcher.Plugin/Result.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public Result Clone()
204204
Score = Score,
205205
TitleHighlightData = TitleHighlightData,
206206
OriginQuery = OriginQuery,
207-
PluginDirectory = PluginDirectory
207+
PluginDirectory = PluginDirectory,
208208
};
209209
}
210210

@@ -258,7 +258,7 @@ public ValueTask<bool> ExecuteAsync(ActionContext context)
258258
public string ProgressBarColor { get; set; } = "#26a0da";
259259

260260
/// <summary>
261-
/// Contains data used to populate the the preview section of this result.
261+
/// Contains data used to populate the preview section of this result.
262262
/// </summary>
263263
public PreviewInfo Preview { get; set; } = PreviewInfo.Default;
264264

Flow.Launcher/Languages/en.xaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,4 +417,8 @@
417417
<system:String x:Key="RecommendAcronyms">sn</system:String>
418418
<system:String x:Key="RecommendAcronymsDesc">Sticky Notes</system:String>
419419

420+
<!-- Preview Area -->
421+
<system:String x:Key="FileSize">File Size</system:String>
422+
<system:String x:Key="Created">Created</system:String>
423+
<system:String x:Key="LastModified">Last Modified</system:String>
420424
</ResourceDictionary>

Flow.Launcher/MainWindow.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
xmlns:flowlauncher="clr-namespace:Flow.Launcher"
88
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
99
xmlns:svgc="http://sharpvectors.codeplex.com/svgc/"
10+
xmlns:sys="clr-namespace:System;assembly=mscorlib"
1011
xmlns:ui="http://schemas.modernwpf.com/2019"
1112
xmlns:vm="clr-namespace:Flow.Launcher.ViewModel"
1213
Name="FlowMainWindow"
@@ -514,4 +515,4 @@
514515
</StackPanel>
515516
</Border>
516517
</Grid>
517-
</Window>
518+
</Window>

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
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">Size</system:String>
34+
<system:String x:Key="plugin_explorer_previewpanel_display_file_creation_checkbox">Creation date</system:String>
35+
<system:String x:Key="plugin_explorer_previewpanel_display_file_modification_checkbox">Modification date</system:String>
36+
<system:String x:Key="plugin_explorer_previewpanel_file_info_label">Display File Info</system:String>
37+
<system:String x:Key="plugin_explorer_previewpanel_date_and_time_format_label">Date and time format</system:String>
3238
<system:String x:Key="plugin_explorer_everything_sort_option">Sort Option:</system:String>
3339
<system:String x:Key="plugin_explorer_everything_installed_path">Everything Path:</system:String>
3440
<system:String x:Key="plugin_explorer_launch_hidden">Launch Hidden</system:String>
@@ -105,10 +111,11 @@
105111
<system:String x:Key="plugin_explorer_openwith">Open With</system:String>
106112
<system:String x:Key="plugin_explorer_openwith_subtitle">Select a program to open with</system:String>
107113

108-
<!-- Special Results-->
114+
<!-- Special Results -->
109115
<system:String x:Key="plugin_explorer_diskfreespace">{0} free of {1}</system:String>
110116
<system:String x:Key="plugin_explorer_openresultfolder">Open in Default File Manager</system:String>
111-
<system:String x:Key="plugin_explorer_openresultfolder_subtitle">Use '>' to search in this directory, '*' to search for file extensions or '>*' to combine both searches.</system:String>
117+
<system:String x:Key="plugin_explorer_openresultfolder_subtitle">
118+
Use '>' to search in this directory, '*' to search for file extensions or '>*' to combine both searches.</system:String>
112119

113120
<!-- Everything -->
114121
<system:String x:Key="flowlauncher_plugin_everything_sdk_issue">Failed to load Everything SDK</system:String>
@@ -133,7 +140,7 @@
133140
<system:String x:Key="flowlauncher_plugin_everything_nonfastsort_warning">Warning: This is not a Fast Sort option, searches may be slow</system:String>
134141

135142
<system:String x:Key="flowlauncher_plugin_everything_search_fullpath">Search Full Path</system:String>
136-
143+
137144
<system:String x:Key="flowlauncher_plugin_everything_click_to_launch_or_install">Click to launch or install Everything</system:String>
138145
<system:String x:Key="flowlauncher_plugin_everything_installing_title">Everything Installation</system:String>
139146
<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: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88
using System.Windows;
99
using Flow.Launcher.Plugin.Explorer.Search.Everything;
1010
using System.Windows.Input;
11+
using Path = System.IO.Path;
12+
using System.Windows.Controls;
13+
using Flow.Launcher.Plugin.Explorer.Views;
1114

1215
namespace Flow.Launcher.Plugin.Explorer.Search
1316
{
1417
public static class ResultManager
1518
{
19+
private static readonly string[] SizeUnits = { "B", "KB", "MB", "GB", "TB" };
1620
private static PluginInitContext Context;
1721
private static Settings Settings { get; set; }
1822

@@ -172,36 +176,28 @@ internal static Result CreateDriveSpaceDisplayResult(string path, string actionK
172176
};
173177
}
174178

175-
private static string ToReadableSize(long pDrvSize, int pi)
179+
internal static string ToReadableSize(long sizeOnDrive, int pi)
176180
{
177-
int mok = 0;
178-
double drvSize = pDrvSize;
179-
string uom = "Byte"; // Unit Of Measurement
181+
var unitIndex = 0;
182+
double readableSize = sizeOnDrive;
180183

181-
while (drvSize > 1024.0)
184+
while (readableSize > 1024.0 && unitIndex < SizeUnits.Length - 1)
182185
{
183-
drvSize /= 1024.0;
184-
mok++;
186+
readableSize /= 1024.0;
187+
unitIndex++;
185188
}
186189

187-
if (mok == 1)
188-
uom = "KB";
189-
else if (mok == 2)
190-
uom = " MB";
191-
else if (mok == 3)
192-
uom = " GB";
193-
else if (mok == 4)
194-
uom = " TB";
195-
196-
var returnStr = $"{Convert.ToInt32(drvSize)}{uom}";
197-
if (mok != 0)
190+
var unit = SizeUnits[unitIndex] ?? "";
191+
192+
var returnStr = $"{Convert.ToInt32(readableSize)} {unit}";
193+
if (unitIndex != 0)
198194
{
199195
returnStr = pi switch
200196
{
201-
1 => $"{drvSize:F1}{uom}",
202-
2 => $"{drvSize:F2}{uom}",
203-
3 => $"{drvSize:F3}{uom}",
204-
_ => $"{Convert.ToInt32(drvSize)}{uom}"
197+
1 => $"{readableSize:F1} {unit}",
198+
2 => $"{readableSize:F2} {unit}",
199+
3 => $"{readableSize:F3} {unit}",
200+
_ => $"{Convert.ToInt32(readableSize)} {unit}"
205201
};
206202
}
207203

@@ -239,6 +235,9 @@ internal static Result CreateFileResult(string filePath, Query query, int score
239235

240236
var title = Path.GetFileName(filePath);
241237

238+
239+
/* Preview Detail */
240+
242241
var result = new Result
243242
{
244243
Title = title,
@@ -249,6 +248,7 @@ internal static Result CreateFileResult(string filePath, Query query, int score
249248
TitleHighlightData = StringMatcher.FuzzySearch(query.Search, title).MatchData,
250249
Score = score,
251250
CopyText = 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: 52 additions & 1 deletion
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+
<TextBlock Foreground="{DynamicResource Color05B}" Text="{DynamicResource plugin_explorer_previewpanel_file_info_label}" />
357+
<CheckBox
358+
Margin="0,10,0,0"
359+
Content="{DynamicResource plugin_explorer_previewpanel_display_file_size_checkbox}"
360+
IsChecked="{Binding ShowFileSizeInPreviewPanel}" />
361+
362+
<CheckBox
363+
Margin="0,10,0,0"
364+
Content="{DynamicResource plugin_explorer_previewpanel_display_file_creation_checkbox}"
365+
IsChecked="{Binding ShowCreatedDateInPreviewPanel}" />
366+
367+
<CheckBox
368+
Margin="0,10,0,0"
369+
Content="{DynamicResource plugin_explorer_previewpanel_display_file_modification_checkbox}"
370+
IsChecked="{Binding ShowModifiedDateInPreviewPanel}" />
371+
372+
<StackPanel
373+
Margin="0,20,0,0"
374+
IsEnabled="{Binding ShowPreviewPanelDateTimeChoices}"
375+
Visibility="{Binding PreviewPanelDateTimeChoicesVisibility}">
376+
<TextBlock Foreground="{DynamicResource Color05B}" Text="{DynamicResource plugin_explorer_previewpanel_date_and_time_format_label}" />
377+
<StackPanel Margin="0,10,0,0" Orientation="Horizontal">
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+
Foreground="{DynamicResource Color05B}"
386+
Text="{Binding PreviewPanelDateFormatDemo}" />
387+
</StackPanel>
388+
<StackPanel Margin="0,10,0,10" Orientation="Horizontal">
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+
Foreground="{DynamicResource Color05B}"
397+
Text="{Binding PreviewPanelTimeFormatDemo}" />
398+
</StackPanel>
399+
</StackPanel>
400+
</StackPanel>
401+
</TabItem>
351402
<TabItem
352403
Width="Auto"
353404
Header="{DynamicResource plugin_explorer_everything_setting_header}"
@@ -403,7 +454,7 @@
403454
<TextBox
404455
Grid.Row="2"
405456
Grid.Column="1"
406-
Width="250"
457+
MinWidth="350"
407458
Margin="0,15,0,0"
408459
Text="{Binding EverythingInstalledPath}" />
409460
</Grid>

0 commit comments

Comments
 (0)