PowerToys/Wox/ViewModel/ResultViewModel.cs

71 lines
1.7 KiB
C#
Raw Normal View History

using System;
using System.Windows.Media;
using System.Windows.Threading;
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
{
if (string.IsNullOrEmpty(Result.IcoPath))
{
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);
return ImageLoader.Load(Result.IcoPath);
}
}
else
{
return ImageLoader.Load(Result.IcoPath);
}
}
}
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
}
}
}