mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge branch 'ImagePreview' of https://github.com/onesounds/Flow.Launcher into ImagePreview
This commit is contained in:
commit
d52496b9f4
4 changed files with 48 additions and 30 deletions
|
|
@ -81,16 +81,6 @@ namespace Flow.Launcher.Plugin
|
|||
/// </summary>
|
||||
public bool RoundedIcon { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Full image used for preview panel
|
||||
/// </summary>
|
||||
public string PreviewImage { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the preview image should occupy the full width of the preveiw panel.
|
||||
/// </summary>
|
||||
public bool FullWidthPreview { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Delegate function, see <see cref="Icon"/>
|
||||
/// </summary>
|
||||
|
|
@ -240,22 +230,29 @@ namespace Flow.Launcher.Plugin
|
|||
/// <default>#26a0da (blue)</default>
|
||||
public string ProgressBarColor { get; set; } = "#26a0da";
|
||||
|
||||
public PreviewInfo Preview { get; set; } = PreviewInfo.Default;
|
||||
|
||||
/// <summary>
|
||||
/// Suggests the preview image of result should use full width of the default preview panel by result's file extension.
|
||||
/// Info of the preview image.
|
||||
/// </summary>
|
||||
/// <param name="extension">File extension. Dot included.</param>
|
||||
public static bool ShouldUseFullWidthPreview(string extension)
|
||||
public record PreviewInfo
|
||||
{
|
||||
return extension is ".jpg"
|
||||
or ".png"
|
||||
or ".avi"
|
||||
or ".mkv"
|
||||
or ".bmp"
|
||||
or ".gif"
|
||||
or ".wmv"
|
||||
or ".mp3"
|
||||
or ".flac"
|
||||
or ".mp4";
|
||||
/// <summary>
|
||||
/// Full image used for preview panel
|
||||
/// </summary>
|
||||
public string PreviewImagePath { get; set; }
|
||||
/// <summary>
|
||||
/// Determines if the preview image should occupy the full width of the preveiw panel.
|
||||
/// </summary>
|
||||
public bool IsMedia { get; set; }
|
||||
public string Description { get; set; }
|
||||
|
||||
public static PreviewInfo Default { get; } = new()
|
||||
{
|
||||
PreviewImagePath = null,
|
||||
Description = null,
|
||||
IsMedia = false,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ namespace Flow.Launcher.ViewModel
|
|||
/// <summary>
|
||||
/// Determines if to use the full width of the preview panel
|
||||
/// </summary>
|
||||
public bool UseBigThumbnail => Result.FullWidthPreview;
|
||||
public bool UseBigThumbnail => Result.Preview.IsMedia;
|
||||
|
||||
public GlyphInfo Glyph { get; set; }
|
||||
|
||||
|
|
@ -210,7 +210,7 @@ namespace Flow.Launcher.ViewModel
|
|||
|
||||
private async Task LoadPreviewImageAsync()
|
||||
{
|
||||
var imagePath = Result.PreviewImage ?? Result.IcoPath;
|
||||
var imagePath = string.IsNullOrEmpty(Result.Preview.PreviewImagePath) ? Result.IcoPath : Result.Preview.PreviewImagePath;
|
||||
var iconDelegate = Result.Icon;
|
||||
if (ImageLoader.CacheContainImage(imagePath, true))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -207,14 +207,17 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
|||
|
||||
internal static Result CreateFileResult(string filePath, Query query, int score = 0, bool windowsIndexed = false)
|
||||
{
|
||||
bool shouldUseBigThumbnail = Result.ShouldUseFullWidthPreview(Path.GetExtension(filePath));
|
||||
Result.PreviewInfo preview = IsMedia(Path.GetExtension(filePath)) ? new Result.PreviewInfo {
|
||||
IsMedia = true,
|
||||
PreviewImagePath = filePath,
|
||||
} : Result.PreviewInfo.Default;
|
||||
|
||||
var result = new Result
|
||||
{
|
||||
Title = Path.GetFileName(filePath),
|
||||
SubTitle = Path.GetDirectoryName(filePath),
|
||||
IcoPath = filePath,
|
||||
PreviewImage = shouldUseBigThumbnail ? filePath : null,
|
||||
FullWidthPreview = shouldUseBigThumbnail,
|
||||
Preview = preview,
|
||||
AutoCompleteText = GetPathWithActionKeyword(filePath, ResultType.File),
|
||||
TitleHighlightData = StringMatcher.FuzzySearch(query.Search, Path.GetFileName(filePath)).MatchData,
|
||||
Score = score,
|
||||
|
|
@ -269,6 +272,20 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
|||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
public static bool IsMedia(string extension)
|
||||
{
|
||||
return extension is ".jpg"
|
||||
or ".png"
|
||||
or ".avi"
|
||||
or ".mkv"
|
||||
or ".bmp"
|
||||
or ".gif"
|
||||
or ".wmv"
|
||||
or ".mp3"
|
||||
or ".flac"
|
||||
or ".mp4";
|
||||
}
|
||||
}
|
||||
|
||||
public enum ResultType
|
||||
|
|
|
|||
|
|
@ -407,8 +407,12 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
|||
Title = title,
|
||||
SubTitle = Main._settings.HideAppsPath ? string.Empty : Location,
|
||||
IcoPath = LogoPath,
|
||||
PreviewImage = PreviewImagePath,
|
||||
FullWidthPreview = false,
|
||||
Preview = new Result.PreviewInfo
|
||||
{
|
||||
IsMedia = false,
|
||||
PreviewImagePath = PreviewImagePath,
|
||||
Description = Description
|
||||
},
|
||||
Score = matchResult.Score,
|
||||
TitleHighlightData = matchResult.MatchData,
|
||||
ContextData = this,
|
||||
|
|
|
|||
Loading…
Reference in a new issue