2013-12-22 19:35:21 +08:00
|
|
|
|
using System;
|
2014-01-25 18:00:13 +08:00
|
|
|
|
using System.ComponentModel;
|
2014-01-04 20:26:13 +08:00
|
|
|
|
using System.Drawing;
|
2014-01-03 23:52:36 +08:00
|
|
|
|
using System.IO;
|
2014-01-04 20:26:13 +08:00
|
|
|
|
using System.Windows;
|
2013-12-22 19:35:21 +08:00
|
|
|
|
using System.Windows.Controls;
|
2014-01-26 21:18:01 +08:00
|
|
|
|
using System.Windows.Input;
|
2013-12-22 19:35:21 +08:00
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
using System.Windows.Media.Imaging;
|
2014-01-29 18:33:24 +08:00
|
|
|
|
using Wox.Annotations;
|
|
|
|
|
using Wox.Helper;
|
2014-01-29 22:44:57 +08:00
|
|
|
|
using Wox.Infrastructure;
|
2014-01-29 18:33:24 +08:00
|
|
|
|
using Wox.Plugin;
|
2014-01-04 20:26:13 +08:00
|
|
|
|
using Brush = System.Windows.Media.Brush;
|
2013-12-22 19:35:21 +08:00
|
|
|
|
|
2014-01-29 18:33:24 +08:00
|
|
|
|
namespace Wox
|
2013-12-22 19:35:21 +08:00
|
|
|
|
{
|
2014-01-25 18:00:13 +08:00
|
|
|
|
public partial class ResultItem : UserControl, INotifyPropertyChanged
|
2013-12-22 19:35:21 +08:00
|
|
|
|
{
|
|
|
|
|
private bool selected;
|
|
|
|
|
|
|
|
|
|
public Result Result { get; private set; }
|
|
|
|
|
|
|
|
|
|
public bool Selected
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return selected;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
selected = value;
|
2014-01-25 18:00:13 +08:00
|
|
|
|
OnPropertyChanged("Selected");
|
2013-12-22 19:35:21 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ResultItem(Result result)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
Result = result;
|
|
|
|
|
|
|
|
|
|
tbTitle.Text = result.Title;
|
|
|
|
|
tbSubTitle.Text = result.SubTitle;
|
2014-01-29 22:44:57 +08:00
|
|
|
|
if (string.IsNullOrEmpty(result.SubTitle))
|
|
|
|
|
{
|
|
|
|
|
SubTitleRowDefinition.Height = new GridLength(0);
|
|
|
|
|
}
|
2014-01-04 20:26:13 +08:00
|
|
|
|
string path = string.Empty;
|
|
|
|
|
if (!string.IsNullOrEmpty(result.IcoPath) && result.IcoPath.Contains(":\\") && File.Exists(result.IcoPath))
|
2013-12-22 19:35:21 +08:00
|
|
|
|
{
|
2014-01-04 20:26:13 +08:00
|
|
|
|
path = result.IcoPath;
|
2013-12-22 19:35:21 +08:00
|
|
|
|
}
|
2014-01-04 20:26:13 +08:00
|
|
|
|
else if (!string.IsNullOrEmpty(result.IcoPath) && File.Exists(result.PluginDirectory + result.IcoPath))
|
|
|
|
|
{
|
|
|
|
|
path = result.PluginDirectory + result.IcoPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(path))
|
|
|
|
|
{
|
|
|
|
|
if (path.ToLower().EndsWith(".exe") || path.ToLower().EndsWith(".lnk"))
|
|
|
|
|
{
|
|
|
|
|
imgIco.Source = GetIcon(path);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
imgIco.Source = new BitmapImage(new Uri(path));
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-26 21:18:01 +08:00
|
|
|
|
|
|
|
|
|
AddHandler(MouseLeftButtonUpEvent, new RoutedEventHandler((o, e) =>
|
|
|
|
|
{
|
2014-01-30 00:53:51 +08:00
|
|
|
|
if (Result.Action != null)
|
|
|
|
|
Result.Action();
|
|
|
|
|
|
2014-01-28 11:19:27 +08:00
|
|
|
|
CommonStorage.Instance.UserSelectedRecords.Add(result);
|
2014-01-29 18:33:24 +08:00
|
|
|
|
if (!result.DontHideWoxAfterSelect)
|
2014-01-26 21:18:01 +08:00
|
|
|
|
{
|
|
|
|
|
App.Window.HideApp();
|
|
|
|
|
}
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}));
|
2014-01-04 20:26:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-25 18:00:13 +08:00
|
|
|
|
private static ImageSource GetIcon(string fileName)
|
2014-01-04 20:26:13 +08:00
|
|
|
|
{
|
|
|
|
|
Icon icon = Icon.ExtractAssociatedIcon(fileName);
|
|
|
|
|
return System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(
|
|
|
|
|
icon.Handle,
|
|
|
|
|
new Int32Rect(0, 0, icon.Width, icon.Height),
|
|
|
|
|
BitmapSizeOptions.FromEmptyOptions());
|
2013-12-22 19:35:21 +08:00
|
|
|
|
}
|
2014-01-25 18:00:13 +08:00
|
|
|
|
|
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
|
|
|
|
|
|
[NotifyPropertyChangedInvocator]
|
|
|
|
|
protected virtual void OnPropertyChanged(string propertyName)
|
|
|
|
|
{
|
|
|
|
|
PropertyChangedEventHandler handler = PropertyChanged;
|
|
|
|
|
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
|
|
|
|
|
}
|
2013-12-22 19:35:21 +08:00
|
|
|
|
}
|
|
|
|
|
}
|