From 174c7a776e2bb9c7a7add832e7d62a50864d0313 Mon Sep 17 00:00:00 2001 From: bao-qian Date: Tue, 3 May 2016 21:18:26 +0100 Subject: [PATCH] Refactoring Refactoring icon, part 2 1. Add baidu, fix #576, #582 2. Refactoring --- .../PluginIndicator.cs | 2 +- Plugins/Wox.Plugin.PluginManagement/Main.cs | 4 +- Plugins/Wox.Plugin.WebSearch/Images/baidu.png | Bin 0 -> 5560 bytes Plugins/Wox.Plugin.WebSearch/Settings.cs | 78 ++++++----- Plugins/Wox.Plugin.WebSearch/WebSearch.cs | 27 +++- .../Wox.Plugin.WebSearch/WebSearchPlugin.cs | 18 +-- .../WebSearchSetting.xaml.cs | 61 +++------ .../Wox.Plugin.WebSearch.csproj | 3 + Plugins/Wox.Plugin.WebSearch/plugin.json | 3 +- Wox.Infrastructure/Image/ImageLoader.cs | 121 +++++++++--------- .../Image/ImagePathConverter.cs | 3 +- Wox.Infrastructure/Wox.Infrastructure.csproj | 1 + Wox.Plugin/PluginMetadata.cs | 34 +++-- Wox.Plugin/Result.cs | 32 +++-- Wox/App.xaml.cs | 2 +- Wox/Converters/ConvertorBase.cs | 30 ----- Wox/ResultListBox.xaml | 6 +- Wox/SettingWindow.xaml | 8 +- Wox/SettingWindow.xaml.cs | 2 +- Wox/ViewModel/ResultViewModel.cs | 5 +- Wox/Wox.csproj | 6 +- 21 files changed, 216 insertions(+), 230 deletions(-) create mode 100644 Plugins/Wox.Plugin.WebSearch/Images/baidu.png delete mode 100644 Wox/Converters/ConvertorBase.cs diff --git a/Plugins/Wox.Plugin.PluginIndicator/PluginIndicator.cs b/Plugins/Wox.Plugin.PluginIndicator/PluginIndicator.cs index 531b6732db..011d3bde0c 100644 --- a/Plugins/Wox.Plugin.PluginIndicator/PluginIndicator.cs +++ b/Plugins/Wox.Plugin.PluginIndicator/PluginIndicator.cs @@ -19,7 +19,7 @@ namespace Wox.Plugin.PluginIndicator Title = keyword, SubTitle = $"Activate {metadata.Name} plugin", Score = 100, - IcoPath = metadata.FullIcoPath, + IcoPath = metadata.IcoPath, Action = c => { context.API.ChangeQuery($"{keyword}{Plugin.Query.TermSeperater}"); diff --git a/Plugins/Wox.Plugin.PluginManagement/Main.cs b/Plugins/Wox.Plugin.PluginManagement/Main.cs index 216157a1c7..93841eb82f 100644 --- a/Plugins/Wox.Plugin.PluginManagement/Main.cs +++ b/Plugins/Wox.Plugin.PluginManagement/Main.cs @@ -189,7 +189,7 @@ namespace Wox.Plugin.PluginManagement { Title = plugin.Name, SubTitle = plugin.Description, - IcoPath = plugin.FullIcoPath, + IcoPath = plugin.IcoPath, Action = e => { UnInstallPlugin(plugin); @@ -229,7 +229,7 @@ namespace Wox.Plugin.PluginManagement { Title = $"{plugin.Name} - Action Keywords: {actionKeywordString}", SubTitle = plugin.Description, - IcoPath = plugin.FullIcoPath + IcoPath = plugin.IcoPath }); } return results; diff --git a/Plugins/Wox.Plugin.WebSearch/Images/baidu.png b/Plugins/Wox.Plugin.WebSearch/Images/baidu.png new file mode 100644 index 0000000000000000000000000000000000000000..2d30b504eb363900b526aedb71171955352585cd GIT binary patch literal 5560 zcmV;p6-VlcP)YZL_ z=%zsyK@bGSjYWwYqXtn!B*sV-muNB*P1I)uHKW>x`wB7}Hd2(elSQEJA0<1zp#rI1q2lTzM7MCX~&pd`^@W(nYZ zA;jZ71|eg;SIh>$%=4v`_Yl#^vECy|{4nz_A;hnV=}~t_eE@FteMP*CjiD;6g-mnfV1NW!QcW`-YVA>EvQ>;6p@L0C+Im z`B{|f!OXQpG*Jjq-}m)zOaW5L zl%AnK+4VMkDvxbE3v~U$!1LD+ z$MjM01v3xTb>qp+jac_Z3);FE0N{2BTsk=$cg!xph}@L8?r#^pi$TH6gM|>aPB+LX zzgt_4XSYZG;u+EhuiV`7y8xJL6*3ARRz|5uKzPDxBGDazXrshdMfqk z_6H1`5BjmYvNNuGJpOKj?rRslUW2#yv>ATJlFf~VjK&G1l;a7&2~Ib}2&;EA$9<3e zwO!bLxIOB1|J>Pv=R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d;wR1c z?W? z-hVK2iInmH5jndwO=2m`Tth^og%IsPpKve{l@rn9&NVHG9S9-r?(KZwIPt5LGLxD2 z5K;fyCrJi8%)FC`P8UKP+tYqS5F&(V6GHrl{Y^_^HO#CEA#U#5`GAHZh=|rR^HcUU zEs0J1HxYe${EM1i31&`{Qf?!nDb}|uiPbRkCL+2(2+>ah9o8+y%qK`Gw-eD&YnzwE zN|^bm5Mmk;X&!YJRuoD^M~UdW%-m#M^O9HzGuIK(#o;<1h@uJ>LhKSkoX^b8m$OP@ z2xcx9LYyOn*c<7(sIqV(+DSyynb|SjKoVmx^Y)%$e^0b)b>#&JAxec1(*dlEyLCw{ zgG2n4h`vKam3ls7I5x@5^Q4r2C!!+bO-y1H%)D0!aU&6JHS#&bnL$MKst{s4Ge64A z&K}&C1kBtjrTi@sO)=W}K%8|DdbWyp0$4~y#&W)r#04|^04yP*hlLRJvEIiNc?vUU z0GKDGoCjcbQdeLN%-jax9U;Wa0RBltao5W;U7sYSRHT%X0h}hKoCshHfZ+fN5Yio{ z5m7>%Q;=vda}c3ay;cDA0LlTB3L(A*utNy3L(7{N5B~=*6j%@PF{8i$0000 + /// All icon should be put under Images directory + /// + [NotNull] + [JsonIgnore] + internal string IconPath { get; private set; } + public string Url { get; set; } public bool Enabled { get; set; } } diff --git a/Plugins/Wox.Plugin.WebSearch/WebSearchPlugin.cs b/Plugins/Wox.Plugin.WebSearch/WebSearchPlugin.cs index 2bb2ee877d..8232c7f28e 100644 --- a/Plugins/Wox.Plugin.WebSearch/WebSearchPlugin.cs +++ b/Plugins/Wox.Plugin.WebSearch/WebSearchPlugin.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using System.Linq; using System.Windows.Controls; using JetBrains.Annotations; @@ -13,14 +14,10 @@ namespace Wox.Plugin.WebSearch { public PluginInitContext Context { get; private set; } - private readonly PluginJsonStorage _storage; - private readonly Settings _settings; - - public WebSearchPlugin() - { - _storage = new PluginJsonStorage(); - _settings = _storage.Load(); - } + private PluginJsonStorage _storage; + private Settings _settings; + public const string ImageDirectory = "Images"; + public static string PluginDirectory; public void Save() { @@ -48,7 +45,7 @@ namespace Wox.Plugin.WebSearch Title = title, SubTitle = subtitle, Score = 6, - IcoPath = webSearch.IconPath, + IcoPath = webSearch.IconPath, Action = c => { Process.Start(webSearch.Url.Replace("{q}", Uri.EscapeDataString(keyword ?? string.Empty))); @@ -92,6 +89,9 @@ namespace Wox.Plugin.WebSearch public void Init(PluginInitContext context) { Context = context; + PluginDirectory = Context.CurrentPluginMetadata.PluginDirectory; + _storage = new PluginJsonStorage(); + _settings = _storage.Load(); } #region ISettingProvider Members diff --git a/Plugins/Wox.Plugin.WebSearch/WebSearchSetting.xaml.cs b/Plugins/Wox.Plugin.WebSearch/WebSearchSetting.xaml.cs index a359378e73..e3f3bbfbbd 100644 --- a/Plugins/Wox.Plugin.WebSearch/WebSearchSetting.xaml.cs +++ b/Plugins/Wox.Plugin.WebSearch/WebSearchSetting.xaml.cs @@ -2,20 +2,14 @@ using System.IO; using System.Linq; using System.Windows; -using System.Windows.Media; -using System.Windows.Media.Imaging; using Microsoft.Win32; -using Wox.Infrastructure; using Wox.Infrastructure.Exception; using Wox.Infrastructure.Image; namespace Wox.Plugin.WebSearch { - public partial class WebSearchSetting : Window + public partial class WebSearchSetting { - private const string ImageDirectory = "Images"; - private const string DefaultIcon = "web_search.png"; - private readonly string _pluginDirectory; private readonly WebSearchesSetting _settingWindow; private bool _isUpdate; private WebSearch _webSearch; @@ -30,7 +24,6 @@ namespace Wox.Plugin.WebSearch _context = settingWidow.Context; _settingWindow = settingWidow; _settings = settings; - _pluginDirectory = _settingWindow.Context.CurrentPluginMetadata.PluginDirectory; } public void UpdateItem(WebSearch webSearch) @@ -47,21 +40,17 @@ namespace Wox.Plugin.WebSearch _isUpdate = true; ConfirmButton.Content = "Update"; - WebSearchIcon.Source = LoadIcon(webSearch.IconPath); + WebSearchIcon.Source = ImageLoader.Load(webSearch.IconPath); EnableCheckBox.IsChecked = webSearch.Enabled; WebSearchName.Text = webSearch.Title; Url.Text = webSearch.Url; Actionword.Text = webSearch.ActionKeyword; } - public void AddItem(WebSearch websearch) + public void AddItem(WebSearch webSearch) { - _webSearch = websearch; - if (string.IsNullOrEmpty(_webSearch.IconPath)) - { - _webSearch.IconPath = DefaultIcon; - WebSearchIcon.Source = LoadIcon(_webSearch.IconPath); - } + _webSearch = webSearch; + WebSearchIcon.Source = ImageLoader.Load(webSearch.IconPath); } private void CancelButtonOnClick(object sender, RoutedEventArgs e) @@ -69,32 +58,6 @@ namespace Wox.Plugin.WebSearch Close(); } - private ImageSource LoadIcon(string path) - { - if (path != null) - { - var releativePath = Path.Combine(_pluginDirectory, ImageDirectory, Path.GetFileName(path)); - if (File.Exists(releativePath)) - { - _webSearch.IconPath = path; - var source = ImageLoader.Load(releativePath); - return source; - } - else - { - _webSearch.IconPath = path; - var source = ImageLoader.Load(path); - return source; - } - } - else - { - var source = ImageLoader.Load(Path.Combine(_pluginDirectory, ImageDirectory, DefaultIcon)); - return source; - } - - } - /// /// Confirm button for both add and update /// @@ -156,9 +119,10 @@ namespace Wox.Plugin.WebSearch private void SelectIconButtonOnClick(object sender, RoutedEventArgs e) { + var directory = Path.Combine(WebSearchPlugin.PluginDirectory, WebSearchPlugin.ImageDirectory); var dlg = new OpenFileDialog { - InitialDirectory = Path.Combine(_pluginDirectory, ImageDirectory), + InitialDirectory = directory, Filter = "Image files (*.jpg, *.jpeg, *.gif, *.png, *.bmp) |*.jpg; *.jpeg; *.gif; *.png; *.bmp" }; @@ -168,7 +132,16 @@ namespace Wox.Plugin.WebSearch string fullpath = dlg.FileName; if (fullpath != null) { - WebSearchIcon.Source = LoadIcon(fullpath); + _webSearch.Icon = Path.GetFileName(fullpath); + if (File.Exists(_webSearch.IconPath)) + { + WebSearchIcon.Source = ImageLoader.Load(_webSearch.IconPath); + } + else + { + _webSearch.Icon = WebSearch.DefaultIcon; + MessageBox.Show($"The file should be put under {directory}"); + } } } } diff --git a/Plugins/Wox.Plugin.WebSearch/Wox.Plugin.WebSearch.csproj b/Plugins/Wox.Plugin.WebSearch/Wox.Plugin.WebSearch.csproj index c32cf95632..3d52d10179 100644 --- a/Plugins/Wox.Plugin.WebSearch/Wox.Plugin.WebSearch.csproj +++ b/Plugins/Wox.Plugin.WebSearch/Wox.Plugin.WebSearch.csproj @@ -124,6 +124,9 @@ PreserveNewest + + PreserveNewest + MSBuild:Compile Designer diff --git a/Plugins/Wox.Plugin.WebSearch/plugin.json b/Plugins/Wox.Plugin.WebSearch/plugin.json index 751208bc75..115fb21e61 100644 --- a/Plugins/Wox.Plugin.WebSearch/plugin.json +++ b/Plugins/Wox.Plugin.WebSearch/plugin.json @@ -19,7 +19,8 @@ "image", "youtube", "bing", - "yahoo" + "yahoo", + "bd" ], "Name": "Web Searches", "Description": "Provide the web search ability", diff --git a/Wox.Infrastructure/Image/ImageLoader.cs b/Wox.Infrastructure/Image/ImageLoader.cs index f823452e2c..bbea213101 100644 --- a/Wox.Infrastructure/Image/ImageLoader.cs +++ b/Wox.Infrastructure/Image/ImageLoader.cs @@ -5,6 +5,7 @@ using System.Drawing; using System.IO; using System.Linq; using System.Runtime.InteropServices; +using System.Threading.Tasks; using System.Windows; using System.Windows.Interop; using System.Windows.Media; @@ -57,7 +58,6 @@ namespace Wox.Infrastructure.Image { try { - if (File.Exists(fileName) == false) return null; Icon icon = GetFileIcon(fileName) ?? Icon.ExtractAssociatedIcon(fileName); if (icon != null) { @@ -65,96 +65,93 @@ namespace Wox.Infrastructure.Image new Int32Rect(0, 0, icon.Width, icon.Height), BitmapSizeOptions.FromEmptyOptions()); } } - catch { } + catch (System.Exception e) + { + Log.Error(e); + } return null; } public static void PreloadImages() { - Stopwatch.Debug("Preload images from cache", () => + var path = Path.Combine(Wox.ProgramPath, "Images", "app.png"); + _imageSources[path] = new BitmapImage(new Uri(path)); + Task.Factory.StartNew(() => { - _cache.TopUsedImages.AsParallel().Where(i => !_imageSources.ContainsKey(i.Key)).ForAll(i => - { - var img = Load(i.Key, false); - if (img != null) - { - // todo happlebao magic - // the image created on other threads can be accessed from main ui thread, - // this line made it possible - // should be changed the Dispatcher.InvokeAsync in the future - img.Freeze(); - _imageSources[i.Key] = img; - } - }); + Stopwatch.Debug("Preload images from cache", () => + { + _cache.TopUsedImages.AsParallel().Where(i => !_imageSources.ContainsKey(i.Key)).ForAll(i => + { + var img = Load(i.Key); + if (img != null) + { + // todo happlebao magic + // the image created on other threads can be accessed from main ui thread, + // this line made it possible + // should be changed the Dispatcher.InvokeAsync in the future + img.Freeze(); + _imageSources[i.Key] = img; + } + }); + }); }); Log.Info($"Preload {_cache.TopUsedImages.Count} images from cache"); } - public static ImageSource Load(string path, bool addToCache = true) - { - ImageSource image = null; + public static ImageSource Load(string path) + { + ImageSource image; if (string.IsNullOrEmpty(path)) { path = Path.Combine(Wox.ProgramPath, "Images", "app.png"); - image = new BitmapImage(new Uri(path)); - return image; + image = _imageSources[path]; } - Stopwatch.Debug($"Loading image path: {path}", () => + else if (_imageSources.ContainsKey(path)) { + image = _imageSources[path]; + } + else + { + string ext = Path.GetExtension(path).ToLower(); - if (addToCache) + if (path.StartsWith("data:", StringComparison.OrdinalIgnoreCase)) { - _cache.Add(path); + image = new BitmapImage(new Uri(path)); + _imageSources[path] = image; } - - - if (_imageSources.ContainsKey(path)) + else if (File.Exists(path) && Path.IsPathRooted(path)) { - image = _imageSources[path]; + if (SelfExts.Contains(ext)) + { + image = GetIcon(path); + _imageSources[path] = image; + } + else if (ImageExts.Contains(ext)) + { + image = new BitmapImage(new Uri(path)); + _imageSources[path] = image; + } + else + { + path = Path.Combine(Wox.ProgramPath, "Images", "app.png"); + image = _imageSources[path]; + } } else { - string ext = Path.GetExtension(path).ToLower(); - - if (path.StartsWith("data:", StringComparison.OrdinalIgnoreCase)) + path = Path.Combine(Wox.ProgramPath, "Images", Path.GetFileName(path)); + if (File.Exists(path)) { image = new BitmapImage(new Uri(path)); } - else if (SelfExts.Contains(ext) && File.Exists(path)) + else { - image = GetIcon(path); - } - else if (!string.IsNullOrEmpty(path) && ImageExts.Contains(ext)) - { - if (File.Exists(path)) - { - image = new BitmapImage(new Uri(path)); - } - else - { - path = Path.Combine(Wox.ProgramPath, "Images", Path.GetFileName(path)); - if (File.Exists(path)) - { - image = new BitmapImage(new Uri(path)); - } - else - { - path = Path.Combine(Wox.ProgramPath, "Images", "app.png"); - image = new BitmapImage(new Uri(path)); - } - } - } - - if (image != null && addToCache) - { - if (!_imageSources.ContainsKey(path)) - { - _imageSources[path] = image; - } + path = Path.Combine(Wox.ProgramPath, "Images", "app.png"); + image = _imageSources[path]; } } - }); + } return image; } diff --git a/Wox.Infrastructure/Image/ImagePathConverter.cs b/Wox.Infrastructure/Image/ImagePathConverter.cs index 77747fbc92..0fd99c3719 100644 --- a/Wox.Infrastructure/Image/ImagePathConverter.cs +++ b/Wox.Infrastructure/Image/ImagePathConverter.cs @@ -2,9 +2,8 @@ using System; using System.Globalization; using System.Windows; using System.Windows.Data; -using Wox.Infrastructure.Image; -namespace Wox.Converters +namespace Wox.Infrastructure.Image { public class ImagePathConverter : IValueConverter { diff --git a/Wox.Infrastructure/Wox.Infrastructure.csproj b/Wox.Infrastructure/Wox.Infrastructure.csproj index 093b682489..55e750155e 100644 --- a/Wox.Infrastructure/Wox.Infrastructure.csproj +++ b/Wox.Infrastructure/Wox.Infrastructure.csproj @@ -77,6 +77,7 @@ + diff --git a/Wox.Plugin/PluginMetadata.cs b/Wox.Plugin/PluginMetadata.cs index 6c6dc5136e..bdf51d4030 100644 --- a/Wox.Plugin/PluginMetadata.cs +++ b/Wox.Plugin/PluginMetadata.cs @@ -6,6 +6,7 @@ namespace Wox.Plugin { public class PluginMetadata { + private string _pluginDirectory; public string ID { get; set; } public string Name { get; set; } public string Author { get; set; } @@ -15,39 +16,34 @@ namespace Wox.Plugin public string Website { get; set; } - public string ExecuteFilePath => Path.Combine(PluginDirectory, ExecuteFileName); + public string ExecuteFilePath { get; private set;} public string ExecuteFileName { get; set; } - public string PluginDirectory { get; set; } + public string PluginDirectory + { + get { return _pluginDirectory; } + internal set + { + _pluginDirectory = value; + ExecuteFilePath = Path.Combine(value, ExecuteFileName); + IcoPath = Path.Combine(value, IcoPath); + } + } [Obsolete("Use ActionKeywords instead, because Wox now support multiple action keywords. This will be remove in v1.3.0")] public string ActionKeyword { get; set; } public List ActionKeywords { get; set; } - public string IcoPath { get; set; } + public string IcoPath { get; set;} public override string ToString() { return Name; } - public string FullIcoPath - { - get - { - // Return the default icon if IcoPath is empty - if (string.IsNullOrEmpty(IcoPath)) - return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Images\\work.png"); - - if (IcoPath.StartsWith("data:")) - { - return IcoPath; - } - - return Path.Combine(PluginDirectory, IcoPath); - } - } + [Obsolete("Use IcoPath")] + public string FullIcoPath => IcoPath; } } diff --git a/Wox.Plugin/Result.cs b/Wox.Plugin/Result.cs index 53f0658d91..aba637b01a 100644 --- a/Wox.Plugin/Result.cs +++ b/Wox.Plugin/Result.cs @@ -7,21 +7,24 @@ namespace Wox.Plugin public class Result { + private string _pluginDirectory; + private string _icoPath; public string Title { get; set; } public string SubTitle { get; set; } - public string IcoPath { get; set; } - public string FullIcoPath + public string IcoPath { - get + get { return _icoPath; } + set { - if (string.IsNullOrEmpty(IcoPath)) return string.Empty; - if (IcoPath.StartsWith("data:")) + if (!string.IsNullOrEmpty(PluginDirectory) && !Path.IsPathRooted(value)) { - return IcoPath; + _icoPath = Path.Combine(value, IcoPath); + } + else + { + _icoPath = value; } - - return Path.Combine(PluginDirectory, IcoPath); } } @@ -40,7 +43,18 @@ namespace Wox.Plugin /// /// Plugin directory /// - public string PluginDirectory { get; set; } + public string PluginDirectory + { + get { return _pluginDirectory; } + set + { + _pluginDirectory = value; + if (!string.IsNullOrEmpty(IcoPath) && Path.IsPathRooted(IcoPath)) + { + IcoPath = Path.Combine(value, IcoPath); + } + } + } public override bool Equals(object obj) { diff --git a/Wox/App.xaml.cs b/Wox/App.xaml.cs index caa00246b5..9fc782a359 100644 --- a/Wox/App.xaml.cs +++ b/Wox/App.xaml.cs @@ -39,7 +39,7 @@ namespace Wox base.OnStartup(e); RegisterUnhandledException(); - Task.Factory.StartNew(ImageLoader.PreloadImages); + ImageLoader.PreloadImages(); MainViewModel mainVM = new MainViewModel(); API = new PublicAPIInstance(mainVM, mainVM._settings); diff --git a/Wox/Converters/ConvertorBase.cs b/Wox/Converters/ConvertorBase.cs deleted file mode 100644 index d07965b0b3..0000000000 --- a/Wox/Converters/ConvertorBase.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Globalization; -using System.Windows.Data; -using System.Windows.Markup; - -namespace Wox.Converters -{ - public abstract class ConvertorBase : MarkupExtension, IValueConverter where T : class, new() - { - private static T converter; - - /// - /// Must be implemented in inheritor. - /// - public abstract object Convert(object value, Type targetType, object parameter, CultureInfo culture); - - /// - /// Override if needed. - /// - public virtual object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - throw new NotImplementedException(); - } - - public override object ProvideValue(IServiceProvider serviceProvider) - { - return converter ?? (converter = new T()); - } - } -} \ No newline at end of file diff --git a/Wox/ResultListBox.xaml b/Wox/ResultListBox.xaml index e39899babb..5d73ee306b 100644 --- a/Wox/ResultListBox.xaml +++ b/Wox/ResultListBox.xaml @@ -3,7 +3,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:converters="clr-namespace:Wox.Converters" + xmlns:image="clr-namespace:Wox.Infrastructure.Image;assembly=Wox.Infrastructure" xmlns:vm="clr-namespace:Wox.ViewModel" mc:Ignorable="d" d:DesignWidth="100" d:DesignHeight="100" d:DataContext="{d:DesignInstance vm:ResultsViewModel}" @@ -27,7 +27,7 @@ - + @@ -35,7 +35,7 @@ + Source="{Binding IcoPath,Converter={StaticResource ImageConverter},IsAsync=True}" /> diff --git a/Wox/SettingWindow.xaml b/Wox/SettingWindow.xaml index 6df47ccd25..b0fc8b93e1 100644 --- a/Wox/SettingWindow.xaml +++ b/Wox/SettingWindow.xaml @@ -4,9 +4,7 @@ xmlns:wox="clr-namespace:Wox" x:Class="Wox.SettingWindow" xmlns:woxPlugin="clr-namespace:Wox.Plugin;assembly=Wox.Plugin" - xmlns:converters="clr-namespace:Wox.Converters" - xmlns:userSettings="clr-namespace:Wox.Core.UserSettings;assembly=Wox.Core" - xmlns:sys="clr-namespace:System;assembly=mscorlib" + xmlns:image="clr-namespace:Wox.Infrastructure.Image;assembly=Wox.Infrastructure" Icon="Images\app.png" Title="{DynamicResource woxsettings}" ResizeMode="NoResize" @@ -18,7 +16,7 @@ IsHitTestVisible="False" x:Key="FeatureBoxSeperator"> - + @@ -70,7 +68,7 @@ + Source="{Binding Metadata.IcoPath,Converter={StaticResource ImageConverter},IsAsync=True}" /> diff --git a/Wox/SettingWindow.xaml.cs b/Wox/SettingWindow.xaml.cs index c1cbd59d07..02f8f0d5c9 100644 --- a/Wox/SettingWindow.xaml.cs +++ b/Wox/SettingWindow.xaml.cs @@ -551,7 +551,7 @@ namespace Wox pluginAuthor.Text = InternationalizationManager.Instance.GetTranslation("author") + ": " + pair.Metadata.Author; pluginSubTitle.Text = pair.Metadata.Description; pluginId = pair.Metadata.ID; - pluginIcon.Source = ImageLoader.Load(pair.Metadata.FullIcoPath); + pluginIcon.Source = ImageLoader.Load(pair.Metadata.IcoPath); var customizedPluginConfig = _settings.PluginSettings[pluginId]; cbDisablePlugin.IsChecked = customizedPluginConfig != null && customizedPluginConfig.Disabled; diff --git a/Wox/ViewModel/ResultViewModel.cs b/Wox/ViewModel/ResultViewModel.cs index 35fb206ff8..d23af16d90 100644 --- a/Wox/ViewModel/ResultViewModel.cs +++ b/Wox/ViewModel/ResultViewModel.cs @@ -35,9 +35,10 @@ namespace Wox.ViewModel public string SubTitle => RawResult.SubTitle; - public string FullIcoPath => RawResult.FullIcoPath; - public string PluginID => RawResult.PluginID; + + public string IcoPath => RawResult.IcoPath; + public int Score { get { return RawResult.Score; } diff --git a/Wox/Wox.csproj b/Wox/Wox.csproj index 4c1098898e..c9f4be0224 100644 --- a/Wox/Wox.csproj +++ b/Wox/Wox.csproj @@ -122,8 +122,6 @@ Properties\SolutionAssemblyInfo.cs - - @@ -378,9 +376,7 @@ PreserveNewest - - - + xcopy /Y $(ProjectDir)Themes\* $(TargetDir)Themes\