Skip to content

Commit 85c0387

Browse files
committed
Support custom preview panel for folder results
1 parent f069ee9 commit 85c0387

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,7 @@ internal static Result CreateFolderResult(string title, string subtitle, string
9999
AutoCompleteText = GetAutoCompleteText(title, query, path, ResultType.Folder),
100100
TitleHighlightData = Context.API.FuzzySearch(query.Search, title).MatchData,
101101
CopyText = path,
102-
Preview = new Result.PreviewInfo
103-
{
104-
FilePath = path,
105-
},
102+
PreviewPanel = new Lazy<UserControl>(() => new PreviewPanel(Settings, path, ResultType.Folder)),
106103
Action = c =>
107104
{
108105
if (c.SpecialKeyState.ToModifierKeys() == ModifierKeys.Alt)
@@ -286,7 +283,7 @@ internal static Result CreateFileResult(string filePath, Query query, int score
286283
TitleHighlightData = Context.API.FuzzySearch(query.Search, title).MatchData,
287284
Score = score,
288285
CopyText = filePath,
289-
PreviewPanel = new Lazy<UserControl>(() => new PreviewPanel(Settings, filePath)),
286+
PreviewPanel = new Lazy<UserControl>(() => new PreviewPanel(Settings, filePath, ResultType.File)),
290287
Action = c =>
291288
{
292289
if (c.SpecialKeyState.ToModifierKeys() == ModifierKeys.Alt)
@@ -354,7 +351,6 @@ private static string GetMoreInfoToolTip(string filePath, ResultType type)
354351
{
355352
case ResultType.Folder:
356353
var folderSize = PreviewPanel.GetFolderSize(filePath);
357-
if (string.IsNullOrEmpty(folderSize)) folderSize = Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info_unknown");
358354
var folderCreatedAt = PreviewPanel.GetFolderCreatedAt(filePath, Settings.PreviewPanelDateFormat, Settings.PreviewPanelTimeFormat, Settings.ShowFileAgeInPreviewPanel);
359355
var folderModifiedAt = PreviewPanel.GetFolderLastModifiedAt(filePath, Settings.PreviewPanelDateFormat, Settings.PreviewPanelTimeFormat, Settings.ShowFileAgeInPreviewPanel);
360356
return string.Format(Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info"),

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private set
5050
? Visibility.Visible
5151
: Visibility.Collapsed;
5252

53-
public PreviewPanel(Settings settings, string filePath)
53+
public PreviewPanel(Settings settings, string filePath, ResultType type)
5454
{
5555
InitializeComponent();
5656

@@ -60,17 +60,21 @@ public PreviewPanel(Settings settings, string filePath)
6060

6161
if (Settings.ShowFileSizeInPreviewPanel)
6262
{
63-
FileSize = GetFileSize(filePath);
63+
FileSize = type == ResultType.File ? GetFileSize(filePath) : GetFolderSize(filePath);
6464
}
6565

6666
if (Settings.ShowCreatedDateInPreviewPanel)
6767
{
68-
CreatedAt = GetFileCreatedAt(filePath, Settings.PreviewPanelDateFormat, Settings.PreviewPanelTimeFormat, Settings.ShowFileAgeInPreviewPanel);
68+
CreatedAt = type == ResultType.File ?
69+
GetFileCreatedAt(filePath, Settings.PreviewPanelDateFormat, Settings.PreviewPanelTimeFormat, Settings.ShowFileAgeInPreviewPanel) :
70+
GetFolderCreatedAt(filePath, Settings.PreviewPanelDateFormat, Settings.PreviewPanelTimeFormat, Settings.ShowFileAgeInPreviewPanel);
6971
}
7072

7173
if (Settings.ShowModifiedDateInPreviewPanel)
7274
{
73-
LastModifiedAt = GetFileLastModifiedAt(filePath, Settings.PreviewPanelDateFormat, Settings.PreviewPanelTimeFormat, Settings.ShowFileAgeInPreviewPanel);
75+
LastModifiedAt = type == ResultType.File ?
76+
GetFileLastModifiedAt(filePath, Settings.PreviewPanelDateFormat, Settings.PreviewPanelTimeFormat, Settings.ShowFileAgeInPreviewPanel) :
77+
GetFolderLastModifiedAt(filePath, Settings.PreviewPanelDateFormat, Settings.PreviewPanelTimeFormat, Settings.ShowFileAgeInPreviewPanel);
7478
}
7579

7680
_ = LoadImageAsync();
@@ -126,7 +130,7 @@ public static string GetFolderSize(string folderPath)
126130
}
127131
catch (Exception)
128132
{
129-
return string.Empty;
133+
return Main.Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info_unknown");
130134
}
131135
return ResultManager.ToReadableSize(size, 2);
132136
}

0 commit comments

Comments
 (0)