2016-08-18 00:16:40 +00:00
using System ;
using System.Windows.Media ;
using System.Windows.Threading ;
2016-05-22 04:30:38 +00:00
using Wox.Infrastructure.Image ;
2016-08-18 00:16:40 +00:00
using Wox.Infrastructure.Logger ;
2016-02-18 11:31:15 +00:00
using Wox.Plugin ;
2016-05-22 04:30:38 +00:00
2016-02-18 11:31:15 +00:00
namespace Wox.ViewModel
{
2016-05-23 21:08:13 +00:00
public class ResultViewModel : BaseModel
2016-02-18 11:31:15 +00:00
{
2016-02-21 15:19:42 +00:00
public ResultViewModel ( Result result )
2016-02-18 11:31:15 +00:00
{
2016-02-22 21:47:10 +00:00
if ( result ! = null )
2016-02-18 11:31:15 +00:00
{
2016-06-22 23:22:41 +00:00
Result = result ;
2016-02-18 11:31:15 +00:00
}
}
2016-08-18 00:16:40 +00:00
public ImageSource Image
{
get
{
if ( string . IsNullOrEmpty ( Result . IcoPath ) )
{
try
{
return Result . Icon ( ) ;
}
catch ( Exception e )
{
2017-01-24 00:24:20 +00:00
Log . Exception ( $"|ResultViewModel.Image|IcoPath is empty and exception when calling Icon() for result <{Result.Title}> of plugin <{Result.PluginDirectory}>" , e ) ;
2016-08-18 00:16:40 +00:00
return ImageLoader . Load ( Result . IcoPath ) ;
}
}
else
{
return ImageLoader . Load ( Result . IcoPath ) ;
}
}
}
2016-02-19 15:26:13 +00:00
2016-06-22 23:22:41 +00:00
public Result Result { get ; }
2016-04-21 00:53:21 +00:00
2016-02-18 14:53:41 +00:00
public override bool Equals ( object obj )
{
2016-06-22 23:26:57 +00:00
var r = obj as ResultViewModel ;
2016-02-18 14:53:41 +00:00
if ( r ! = null )
{
2016-06-22 23:22:41 +00:00
return Result . Equals ( r . Result ) ;
}
else
{
return false ;
2016-02-18 14:53:41 +00:00
}
2016-02-19 14:55:58 +00:00
}
public override int GetHashCode ( )
{
2016-06-22 23:22:41 +00:00
return Result . GetHashCode ( ) ;
2016-02-19 14:55:58 +00:00
}
public override string ToString ( )
{
2016-06-22 23:22:41 +00:00
return Result . ToString ( ) ;
2016-02-18 14:53:41 +00:00
}
2016-02-18 11:31:15 +00:00
}
}