mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
- Use DynamicData SourceList with automatic sorting by score descending - Add ReplaceResults() with EditDiff for minimal UI updates (reduces flickering) - Keep previous results visible while typing until new results arrive - Add ImageLoader with Windows Shell API (IShellItemImageFactory) for exe/ico icons - Use AlphaFormat.Unpremul to correctly render transparent icons without white borders - Query all plugins in parallel and merge/sort results globally
56 lines
1.6 KiB
C#
56 lines
1.6 KiB
C#
using System.Threading.Tasks;
|
|
using Avalonia.Media;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using Flow.Launcher.Avalonia.Helper;
|
|
using Flow.Launcher.Infrastructure.UserSettings;
|
|
using Flow.Launcher.Plugin;
|
|
|
|
namespace Flow.Launcher.Avalonia.ViewModel;
|
|
|
|
/// <summary>
|
|
/// ViewModel for a single result item.
|
|
/// </summary>
|
|
public partial class ResultViewModel : ObservableObject
|
|
{
|
|
[ObservableProperty]
|
|
private string _title = string.Empty;
|
|
|
|
[ObservableProperty]
|
|
private string _subTitle = string.Empty;
|
|
|
|
[ObservableProperty]
|
|
private string _iconPath = string.Empty;
|
|
|
|
[ObservableProperty]
|
|
private bool _isSelected;
|
|
|
|
[ObservableProperty]
|
|
private Settings? _settings;
|
|
|
|
[ObservableProperty]
|
|
private int _score;
|
|
|
|
/// <summary>
|
|
/// The underlying plugin result. Used for executing actions and accessing additional properties.
|
|
/// </summary>
|
|
public Result? PluginResult { get; set; }
|
|
|
|
// Computed properties for display
|
|
public bool ShowIcon => !string.IsNullOrEmpty(IconPath);
|
|
|
|
public bool ShowSubTitle => !string.IsNullOrEmpty(SubTitle);
|
|
|
|
/// <summary>
|
|
/// Gets the query suggestion text for autocomplete, if available.
|
|
/// </summary>
|
|
public string? QuerySuggestionText => PluginResult?.AutoCompleteText;
|
|
|
|
// Cached task for the image - created once per IconPath
|
|
private Task<IImage?>? _imageTask;
|
|
|
|
/// <summary>
|
|
/// The icon image task. Use with Avalonia's ^ stream binding operator.
|
|
/// Returns a cached task to avoid re-loading on every property access.
|
|
/// </summary>
|
|
public Task<IImage?> Image => _imageTask ??= ImageLoader.LoadAsync(IconPath);
|
|
}
|