diff --git a/Wox.Plugin/Result.cs b/Wox.Plugin/Result.cs index f0c7fd4460..310f00b3f6 100644 --- a/Wox.Plugin/Result.cs +++ b/Wox.Plugin/Result.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.IO; namespace Wox.Plugin { @@ -9,6 +10,19 @@ namespace Wox.Plugin { public string SubTitle { get; set; } public string IcoPath { get; set; } + public string FullIcoPath + { + get + { + if (IcoPath.StartsWith("data:")) + { + return IcoPath; + } + + return Path.Combine(PluginDirectory, IcoPath); + } + } + /// /// return true to hide wox after select result /// @@ -38,6 +52,8 @@ namespace Wox.Plugin { return r.Title == Title && r.SubTitle == SubTitle; } + + public override string ToString() { return Title + SubTitle; } diff --git a/Wox/Converters/AsyncConverter.cs b/Wox/Converters/AsyncConverter.cs new file mode 100644 index 0000000000..5df3bc7b5f --- /dev/null +++ b/Wox/Converters/AsyncConverter.cs @@ -0,0 +1,38 @@ +using System; +using System.ComponentModel; +using System.Threading; +using System.Windows.Data; +using System.Windows.Threading; + +namespace Wox.Converters +{ + public class AsyncTask : INotifyPropertyChanged + { + public AsyncTask(Func valueFunc) + { + LoadValue(valueFunc); + } + + private void LoadValue(Func valueFunc) + { + var frame = new DispatcherFrame(); + ThreadPool.QueueUserWorkItem(delegate + { + + object returnValue = + AsyncValue = valueFunc(); + if (PropertyChanged != null) + PropertyChanged(this, new PropertyChangedEventArgs("AsyncValue")); + + }); + } + + public event PropertyChangedEventHandler PropertyChanged; + + public object AsyncValue + { + get; + set; + } + } +} diff --git a/Wox/Converters/ImagePathConverter.cs b/Wox/Converters/ImagePathConverter.cs index c0ac72e25a..8f97fe3eda 100644 --- a/Wox/Converters/ImagePathConverter.cs +++ b/Wox/Converters/ImagePathConverter.cs @@ -1,30 +1,32 @@ using System; +using System.Diagnostics; using System.Globalization; using System.IO; +using System.Windows; using System.Windows.Data; using System.Windows.Media.Imaging; using Wox.Helper; namespace Wox.Converters { - public class ImagePathConverter : IMultiValueConverter + public class ImagePathConverter : IValueConverter { - public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - if (values[0] == null) return null; + if (value == null || value == DependencyProperty.UnsetValue) return null; - string relativePath = values[0].ToString(); - string pluginDirectory = values[1].ToString(); - string fullPath = Path.Combine(pluginDirectory, relativePath); + string fullPath = value.ToString(); - if (relativePath.StartsWith("data:", StringComparison.OrdinalIgnoreCase)) + if (fullPath.StartsWith("data:", StringComparison.OrdinalIgnoreCase)) { - return new BitmapImage(new Uri(relativePath)); + return new BitmapImage(new Uri(fullPath)); } + + return ImageLoader.Load(fullPath); } - public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return null; } diff --git a/Wox/Helper/ImageLoader.cs b/Wox/Helper/ImageLoader.cs index fed3d48578..a97d14ff26 100644 --- a/Wox/Helper/ImageLoader.cs +++ b/Wox/Helper/ImageLoader.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Drawing; using System.Globalization; using System.IO; diff --git a/Wox/ResultPanel.xaml b/Wox/ResultPanel.xaml index d05663585c..03927ce29d 100644 --- a/Wox/ResultPanel.xaml +++ b/Wox/ResultPanel.xaml @@ -18,22 +18,14 @@ + + + - - - - - - - - - - - - + diff --git a/Wox/ResultPanel.xaml.cs b/Wox/ResultPanel.xaml.cs index 1b94b7b4c1..b55c75a6c8 100644 --- a/Wox/ResultPanel.xaml.cs +++ b/Wox/ResultPanel.xaml.cs @@ -34,10 +34,6 @@ namespace Wox } foreach (var result in results) { - //ThreadPool.QueueUserWorkItem(delegate - // { - // ImageLoader.Load(Path.Combine(result.PluginDirectory, result.IcoPath)); - // }); int position = GetInsertLocation(result.Score); lbResults.Items.Insert(position, result); } diff --git a/Wox/Wox.csproj b/Wox/Wox.csproj index a2b2ed1ae3..6493bbe3eb 100644 --- a/Wox/Wox.csproj +++ b/Wox/Wox.csproj @@ -112,6 +112,7 @@ +