PowerToys/Wox/ViewModel/ResultViewModel.cs

72 lines
1.8 KiB
C#
Raw Normal View History

using System;
using System.Windows.Media;
using System.Windows.Threading;
using Wox.Infrastructure;
using Wox.Infrastructure.Image;
using Wox.Infrastructure.Logger;
using Wox.Plugin;
namespace Wox.ViewModel
{
public class ResultViewModel : BaseModel
{
public ResultViewModel(Result result)
{
if (result != null)
{
2016-06-23 07:22:41 +08:00
Result = result;
}
}
public ImageSource Image
{
get
{
var imagePath = Result.IcoPath;
if (string.IsNullOrEmpty(imagePath) && Result.Icon != null)
{
try
{
return Result.Icon();
}
catch (Exception e)
{
2017-01-24 08:24:20 +08:00
Log.Exception($"|ResultViewModel.Image|IcoPath is empty and exception when calling Icon() for result <{Result.Title}> of plugin <{Result.PluginDirectory}>", e);
imagePath = Constant.ErrorIcon;
}
}
// will get here either when icoPath has value\icon delegate is null\when had exception in delegate
return ImageLoader.Load(imagePath);
}
}
2016-06-23 07:22:41 +08:00
public Result Result { get; }
2016-02-18 22:53:41 +08:00
public override bool Equals(object obj)
{
var r = obj as ResultViewModel;
2016-02-18 22:53:41 +08:00
if (r != null)
{
2016-06-23 07:22:41 +08:00
return Result.Equals(r.Result);
}
else
{
return false;
2016-02-18 22:53:41 +08:00
}
}
public override int GetHashCode()
{
2016-06-23 07:22:41 +08:00
return Result.GetHashCode();
}
public override string ToString()
{
2016-06-23 07:22:41 +08:00
return Result.ToString();
2016-02-18 22:53:41 +08:00
}
}
}