2016-08-18 08:16:40 +08:00
using System ;
using System.Windows.Media ;
using System.Windows.Threading ;
2019-11-09 17:55:53 +08:00
using Wox.Infrastructure ;
2016-05-22 12:30:38 +08:00
using Wox.Infrastructure.Image ;
2016-08-18 08:16:40 +08:00
using Wox.Infrastructure.Logger ;
2016-02-18 19:31:15 +08:00
using Wox.Plugin ;
2016-05-22 12:30:38 +08:00
2016-02-18 19:31:15 +08:00
namespace Wox.ViewModel
{
2016-05-24 05:08:13 +08:00
public class ResultViewModel : BaseModel
2016-02-18 19:31:15 +08:00
{
2016-02-21 23:19:42 +08:00
public ResultViewModel ( Result result )
2016-02-18 19:31:15 +08:00
{
2016-02-23 05:47:10 +08:00
if ( result ! = null )
2016-02-18 19:31:15 +08:00
{
2016-06-23 07:22:41 +08:00
Result = result ;
2016-02-18 19:31:15 +08:00
}
}
2016-08-18 08:16:40 +08:00
public ImageSource Image
{
get
{
2019-11-09 17:55:53 +08:00
var imagePath = Result . IcoPath ;
if ( string . IsNullOrEmpty ( imagePath ) & & Result . Icon ! = null )
2016-08-18 08:16:40 +08:00
{
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 ) ;
2019-11-09 17:55:53 +08:00
imagePath = Constant . ErrorIcon ;
2016-08-18 08:16:40 +08:00
}
}
2019-11-09 17:55:53 +08:00
// will get here either when icoPath has value\icon delegate is null\when had exception in delegate
return ImageLoader . Load ( imagePath ) ;
2016-08-18 08:16:40 +08:00
}
}
2016-02-19 23:26:13 +08:00
2016-06-23 07:22:41 +08:00
public Result Result { get ; }
2016-04-21 08:53:21 +08:00
2016-02-18 22:53:41 +08:00
public override bool Equals ( object obj )
{
2016-06-23 07:26:57 +08:00
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
}
2016-02-19 22:55:58 +08:00
}
public override int GetHashCode ( )
{
2016-06-23 07:22:41 +08:00
return Result . GetHashCode ( ) ;
2016-02-19 22:55:58 +08:00
}
public override string ToString ( )
{
2016-06-23 07:22:41 +08:00
return Result . ToString ( ) ;
2016-02-18 22:53:41 +08:00
}
2016-02-18 19:31:15 +08:00
}
}