Skip to content

Commit 6c54ad8

Browse files
refactor preview info
1 parent 53b1781 commit 6c54ad8

File tree

4 files changed

+49
-31
lines changed

4 files changed

+49
-31
lines changed

Flow.Launcher.Plugin/Result.cs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,6 @@ public string IcoPath
8181
/// </summary>
8282
public bool RoundedIcon { get; set; } = false;
8383

84-
/// <summary>
85-
/// Full image used for preview panel
86-
/// </summary>
87-
public string PreviewImage { get; set; } = null;
88-
89-
/// <summary>
90-
/// Determines if the preview image should occupy the full width of the preveiw panel.
91-
/// </summary>
92-
public bool FullWidthPreview { get; set; } = false;
93-
9484
/// <summary>
9585
/// Delegate function, see <see cref="Icon"/>
9686
/// </summary>
@@ -240,22 +230,29 @@ public ValueTask<bool> ExecuteAsync(ActionContext context)
240230
/// <default>#26a0da (blue)</default>
241231
public string ProgressBarColor { get; set; } = "#26a0da";
242232

233+
public PreviewInfo Preview { get; set; } = PreviewInfo.Default;
234+
243235
/// <summary>
244-
/// Suggests the preview image of result should use full width of the default preview panel by result's file extension.
236+
/// Info of the preview image.
245237
/// </summary>
246-
/// <param name="extension">File extension. Dot included.</param>
247-
public static bool ShouldUseFullWidthPreview(string extension)
238+
public record PreviewInfo
248239
{
249-
return extension is ".jpg"
250-
or ".png"
251-
or ".avi"
252-
or ".mkv"
253-
or ".bmp"
254-
or ".gif"
255-
or ".wmv"
256-
or ".mp3"
257-
or ".flac"
258-
or ".mp4";
240+
/// <summary>
241+
/// Full image used for preview panel
242+
/// </summary>
243+
public string PreviewImagePath { get; set; }
244+
/// <summary>
245+
/// Determines if the preview image should occupy the full width of the preveiw panel.
246+
/// </summary>
247+
public bool IsMedia { get; set; }
248+
public string Description { get; set; }
249+
250+
public static PreviewInfo Default { get; } = new()
251+
{
252+
PreviewImagePath = null,
253+
Description = null,
254+
IsMedia = false,
255+
};
259256
}
260257
}
261258
}

Flow.Launcher/ViewModel/ResultViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public ImageSource PreviewImage
169169
/// <summary>
170170
/// Determines if to use the full width of the preview panel
171171
/// </summary>
172-
public bool UseBigThumbnail => Result.FullWidthPreview;
172+
public bool UseBigThumbnail => Result.Preview.IsMedia;
173173

174174
public GlyphInfo Glyph { get; set; }
175175

@@ -210,7 +210,7 @@ private async Task LoadImageAsync()
210210

211211
private async Task LoadPreviewImageAsync()
212212
{
213-
var imagePath = Result.PreviewImage ?? Result.IcoPath;
213+
var imagePath = string.IsNullOrEmpty(Result.Preview.PreviewImagePath) ? Result.IcoPath : Result.Preview.PreviewImagePath;
214214
var iconDelegate = Result.Icon;
215215
if (ImageLoader.CacheContainImage(imagePath, true))
216216
{

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ internal static Result CreateOpenCurrentFolderResult(string path, bool windowsIn
174174
}, StringSplitOptions.None).Last();
175175

176176
var title = $"Open {folderName}";
177-
177+
178178
var subtitleFolderName = folderName;
179179

180180
// ie. max characters can be displayed without subtitle cutting off: "Program Files (x86)"
@@ -205,14 +205,17 @@ internal static Result CreateOpenCurrentFolderResult(string path, bool windowsIn
205205

206206
internal static Result CreateFileResult(string filePath, Query query, int score = 0, bool windowsIndexed = false)
207207
{
208-
bool shouldUseBigThumbnail = Result.ShouldUseFullWidthPreview(Path.GetExtension(filePath));
208+
Result.PreviewInfo preview = IsMedia(Path.GetExtension(filePath)) ? new Result.PreviewInfo {
209+
IsMedia = true,
210+
PreviewImagePath = filePath,
211+
} : Result.PreviewInfo.Default;
212+
209213
var result = new Result
210214
{
211215
Title = Path.GetFileName(filePath),
212216
SubTitle = Path.GetDirectoryName(filePath),
213217
IcoPath = filePath,
214-
PreviewImage = shouldUseBigThumbnail ? filePath : null,
215-
FullWidthPreview = shouldUseBigThumbnail,
218+
Preview = preview,
216219
AutoCompleteText = GetPathWithActionKeyword(filePath, ResultType.File),
217220
TitleHighlightData = StringMatcher.FuzzySearch(query.Search, Path.GetFileName(filePath)).MatchData,
218221
Score = score,
@@ -266,6 +269,20 @@ internal static Result CreateFileResult(string filePath, Query query, int score
266269
};
267270
return result;
268271
}
272+
273+
public static bool IsMedia(string extension)
274+
{
275+
return extension is ".jpg"
276+
or ".png"
277+
or ".avi"
278+
or ".mkv"
279+
or ".bmp"
280+
or ".gif"
281+
or ".wmv"
282+
or ".mp3"
283+
or ".flac"
284+
or ".mp4";
285+
}
269286
}
270287

271288
public enum ResultType

Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,12 @@ public Result Result(string query, IPublicAPI api)
405405
Title = title,
406406
SubTitle = Main._settings.HideAppsPath ? string.Empty : Location,
407407
IcoPath = LogoPath,
408-
PreviewImage = PreviewImagePath,
409-
FullWidthPreview = false,
408+
Preview = new Result.PreviewInfo
409+
{
410+
IsMedia = false,
411+
PreviewImagePath = PreviewImagePath,
412+
Description = Description
413+
},
410414
Score = matchResult.Score,
411415
TitleHighlightData = matchResult.MatchData,
412416
ContextData = this,

0 commit comments

Comments
 (0)