Skip to content

Commit d52496b

Browse files
committed
Merge branch 'ImagePreview' of https://github.com/onesounds/Flow.Launcher into ImagePreview
2 parents 46f8d42 + 05dca1a commit d52496b

File tree

4 files changed

+48
-30
lines changed

4 files changed

+48
-30
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: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,17 @@ internal static Result CreateOpenCurrentFolderResult(string path, bool windowsIn
207207

208208
internal static Result CreateFileResult(string filePath, Query query, int score = 0, bool windowsIndexed = false)
209209
{
210-
bool shouldUseBigThumbnail = Result.ShouldUseFullWidthPreview(Path.GetExtension(filePath));
210+
Result.PreviewInfo preview = IsMedia(Path.GetExtension(filePath)) ? new Result.PreviewInfo {
211+
IsMedia = true,
212+
PreviewImagePath = filePath,
213+
} : Result.PreviewInfo.Default;
214+
211215
var result = new Result
212216
{
213217
Title = Path.GetFileName(filePath),
214218
SubTitle = Path.GetDirectoryName(filePath),
215219
IcoPath = filePath,
216-
PreviewImage = shouldUseBigThumbnail ? filePath : null,
217-
FullWidthPreview = shouldUseBigThumbnail,
220+
Preview = preview,
218221
AutoCompleteText = GetPathWithActionKeyword(filePath, ResultType.File),
219222
TitleHighlightData = StringMatcher.FuzzySearch(query.Search, Path.GetFileName(filePath)).MatchData,
220223
Score = score,
@@ -269,6 +272,20 @@ internal static Result CreateFileResult(string filePath, Query query, int score
269272
};
270273
return result;
271274
}
275+
276+
public static bool IsMedia(string extension)
277+
{
278+
return extension is ".jpg"
279+
or ".png"
280+
or ".avi"
281+
or ".mkv"
282+
or ".bmp"
283+
or ".gif"
284+
or ".wmv"
285+
or ".mp3"
286+
or ".flac"
287+
or ".mp4";
288+
}
272289
}
273290

274291
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
@@ -407,8 +407,12 @@ public Result Result(string query, IPublicAPI api)
407407
Title = title,
408408
SubTitle = Main._settings.HideAppsPath ? string.Empty : Location,
409409
IcoPath = LogoPath,
410-
PreviewImage = PreviewImagePath,
411-
FullWidthPreview = false,
410+
Preview = new Result.PreviewInfo
411+
{
412+
IsMedia = false,
413+
PreviewImagePath = PreviewImagePath,
414+
Description = Description
415+
},
412416
Score = matchResult.Score,
413417
TitleHighlightData = matchResult.MatchData,
414418
ContextData = this,

0 commit comments

Comments
 (0)