Refactoring Refactoring icon, part 2

1. Add baidu, fix #576, #582
2. Refactoring
This commit is contained in:
bao-qian
2016-05-03 21:18:26 +01:00
parent 730864609f
commit 174c7a776e
21 changed files with 216 additions and 230 deletions

View File

@@ -19,7 +19,7 @@ namespace Wox.Plugin.PluginIndicator
Title = keyword, Title = keyword,
SubTitle = $"Activate {metadata.Name} plugin", SubTitle = $"Activate {metadata.Name} plugin",
Score = 100, Score = 100,
IcoPath = metadata.FullIcoPath, IcoPath = metadata.IcoPath,
Action = c => Action = c =>
{ {
context.API.ChangeQuery($"{keyword}{Plugin.Query.TermSeperater}"); context.API.ChangeQuery($"{keyword}{Plugin.Query.TermSeperater}");

View File

@@ -189,7 +189,7 @@ namespace Wox.Plugin.PluginManagement
{ {
Title = plugin.Name, Title = plugin.Name,
SubTitle = plugin.Description, SubTitle = plugin.Description,
IcoPath = plugin.FullIcoPath, IcoPath = plugin.IcoPath,
Action = e => Action = e =>
{ {
UnInstallPlugin(plugin); UnInstallPlugin(plugin);
@@ -229,7 +229,7 @@ namespace Wox.Plugin.PluginManagement
{ {
Title = $"{plugin.Name} - Action Keywords: {actionKeywordString}", Title = $"{plugin.Name} - Action Keywords: {actionKeywordString}",
SubTitle = plugin.Description, SubTitle = plugin.Description,
IcoPath = plugin.FullIcoPath IcoPath = plugin.IcoPath
}); });
} }
return results; return results;

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

View File

@@ -1,6 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using Newtonsoft.Json;
using Wox.Infrastructure.Storage;
namespace Wox.Plugin.WebSearch namespace Wox.Plugin.WebSearch
{ {
@@ -12,23 +10,31 @@ namespace Wox.Plugin.WebSearch
{ {
Title = "Google", Title = "Google",
ActionKeyword = "g", ActionKeyword = "g",
IconPath = "google.png", Icon = "google.png",
Url = "https://www.google.com/search?q={q}", Url = "https://www.google.com/search?q={q}",
Enabled = true Enabled = true
}, },
new WebSearch new WebSearch
{
Title = "Google Scholar",
ActionKeyword = "sc",
Icon = "google.png",
Url = "https://scholar.google.com/scholar?q={q}",
Enabled = true
},
new WebSearch
{ {
Title = "Wikipedia", Title = "Wikipedia",
ActionKeyword = "wiki", ActionKeyword = "wiki",
IconPath = "wiki.png", Icon = "wiki.png",
Url = "http://en.wikipedia.org/wiki/{q}", Url = "https://en.wikipedia.org/wiki/{q}",
Enabled = true Enabled = true
}, },
new WebSearch new WebSearch
{ {
Title = "FindIcon", Title = "FindIcon",
ActionKeyword = "findicon", ActionKeyword = "findicon",
IconPath = "pictures.png", Icon = "pictures.png",
Url = "http://findicons.com/search/{q}", Url = "http://findicons.com/search/{q}",
Enabled = true Enabled = true
}, },
@@ -36,39 +42,39 @@ namespace Wox.Plugin.WebSearch
{ {
Title = "Facebook", Title = "Facebook",
ActionKeyword = "facebook", ActionKeyword = "facebook",
IconPath = "facebook.png", Icon = "facebook.png",
Url = "http://www.facebook.com/search/?q={q}", Url = "https://www.facebook.com/search/?q={q}",
Enabled = true Enabled = true
}, },
new WebSearch new WebSearch
{ {
Title = "Twitter", Title = "Twitter",
ActionKeyword = "twitter", ActionKeyword = "twitter",
IconPath = "twitter.png", Icon = "twitter.png",
Url = "http://twitter.com/search?q={q}", Url = "https://twitter.com/search?q={q}",
Enabled = true Enabled = true
}, },
new WebSearch new WebSearch
{ {
Title = "Google Maps", Title = "Google Maps",
ActionKeyword = "maps", ActionKeyword = "maps",
IconPath = "google_maps.png", Icon = "google_maps.png",
Url = "http://maps.google.com/maps?q={q}", Url = "https://maps.google.com/maps?q={q}",
Enabled = true Enabled = true
}, },
new WebSearch new WebSearch
{ {
Title = "Google Translate", Title = "Google Translate",
ActionKeyword = "translate", ActionKeyword = "translate",
IconPath = "google_translate.png", Icon = "google_translate.png",
Url = "http://translate.google.com/#auto|en|{q}", Url = "https://translate.google.com/#auto|en|{q}",
Enabled = true Enabled = true
}, },
new WebSearch new WebSearch
{ {
Title = "Duckduckgo", Title = "Duckduckgo",
ActionKeyword = "duckduckgo", ActionKeyword = "duckduckgo",
IconPath = "duckduckgo.png", Icon = "duckduckgo.png",
Url = "https://duckduckgo.com/?q={q}", Url = "https://duckduckgo.com/?q={q}",
Enabled = true Enabled = true
}, },
@@ -76,7 +82,7 @@ namespace Wox.Plugin.WebSearch
{ {
Title = "Github", Title = "Github",
ActionKeyword = "github", ActionKeyword = "github",
IconPath = "github.png", Icon = "github.png",
Url = "https://github.com/search?q={q}", Url = "https://github.com/search?q={q}",
Enabled = true Enabled = true
}, },
@@ -84,7 +90,7 @@ namespace Wox.Plugin.WebSearch
{ {
Title = "Github Gist", Title = "Github Gist",
ActionKeyword = "gist", ActionKeyword = "gist",
IconPath = "gist.png", Icon = "gist.png",
Url = "https://gist.github.com/search?q={q}", Url = "https://gist.github.com/search?q={q}",
Enabled = true Enabled = true
}, },
@@ -92,7 +98,7 @@ namespace Wox.Plugin.WebSearch
{ {
Title = "Gmail", Title = "Gmail",
ActionKeyword = "gmail", ActionKeyword = "gmail",
IconPath = "gmail.png", Icon = "gmail.png",
Url = "https://mail.google.com/mail/ca/u/0/#apps/{q}", Url = "https://mail.google.com/mail/ca/u/0/#apps/{q}",
Enabled = true Enabled = true
}, },
@@ -100,39 +106,39 @@ namespace Wox.Plugin.WebSearch
{ {
Title = "Google Drive", Title = "Google Drive",
ActionKeyword = "drive", ActionKeyword = "drive",
IconPath = "google_drive.png", Icon = "google_drive.png",
Url = "http://drive.google.com/?hl=en&tab=bo#search/{q}", Url = "https://drive.google.com/?hl=en&tab=bo#search/{q}",
Enabled = true Enabled = true
}, },
new WebSearch new WebSearch
{ {
Title = "Wolframalpha", Title = "Wolframalpha",
ActionKeyword = "wolframalpha", ActionKeyword = "wolframalpha",
IconPath = "wolframalpha.png", Icon = "wolframalpha.png",
Url = "http://www.wolframalpha.com/input/?i={q}", Url = "https://www.wolframalpha.com/input/?i={q}",
Enabled = true Enabled = true
}, },
new WebSearch new WebSearch
{ {
Title = "Stackoverflow", Title = "Stackoverflow",
ActionKeyword = "stackoverflow", ActionKeyword = "stackoverflow",
IconPath = "stackoverflow.png", Icon = "stackoverflow.png",
Url = "http://stackoverflow.com/search?q={q}", Url = "https://stackoverflow.com/search?q={q}",
Enabled = true Enabled = true
}, },
new WebSearch new WebSearch
{ {
Title = "I'm Feeling Lucky", Title = "I'm Feeling Lucky",
ActionKeyword = "lucky", ActionKeyword = "lucky",
IconPath = "google.png", Icon = "google.png",
Url = "http://google.com/search?q={q}&btnI=I", Url = "https://google.com/search?q={q}&btnI=I",
Enabled = true Enabled = true
}, },
new WebSearch new WebSearch
{ {
Title = "Google Image", Title = "Google Image",
ActionKeyword = "image", ActionKeyword = "image",
IconPath = "google.png", Icon = "google.png",
Url = "https://www.google.com/search?q={q}&tbm=isch", Url = "https://www.google.com/search?q={q}&tbm=isch",
Enabled = true Enabled = true
}, },
@@ -140,15 +146,15 @@ namespace Wox.Plugin.WebSearch
{ {
Title = "Youtube", Title = "Youtube",
ActionKeyword = "youtube", ActionKeyword = "youtube",
IconPath = "youtube.png", Icon = "youtube.png",
Url = "http://www.youtube.com/results?search_query={q}", Url = "https://www.youtube.com/results?search_query={q}",
Enabled = true Enabled = true
}, },
new WebSearch new WebSearch
{ {
Title = "Bing", Title = "Bing",
ActionKeyword = "bing", ActionKeyword = "bing",
IconPath = "bing.png", Icon = "bing.png",
Url = "https://www.bing.com/search?q={q}", Url = "https://www.bing.com/search?q={q}",
Enabled = true Enabled = true
}, },
@@ -156,9 +162,17 @@ namespace Wox.Plugin.WebSearch
{ {
Title = "Yahoo", Title = "Yahoo",
ActionKeyword = "yahoo", ActionKeyword = "yahoo",
IconPath = "yahoo.png", Icon = "yahoo.png",
Url = "http://www.search.yahoo.com/search?p={q}", Url = "https://www.search.yahoo.com/search?p={q}",
Enabled = true Enabled = true
},
new WebSearch
{
Title= "Baidu",
ActionKeyword= "bd",
Icon= "baidu.png",
Url="https://www.baidu.com/#ie=UTF-8&wd={q}",
Enabled= true
} }
}; };

View File

@@ -1,12 +1,35 @@
using System; using System.IO;
using JetBrains.Annotations;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
namespace Wox.Plugin.WebSearch namespace Wox.Plugin.WebSearch
{ {
public class WebSearch public class WebSearch
{ {
public const string DefaultIcon = "web_search.png";
public string Title { get; set; } public string Title { get; set; }
public string ActionKeyword { get; set; } public string ActionKeyword { get; set; }
public string IconPath { get; set; } [NotNull]
private string _icon = DefaultIcon;
[NotNull]
public string Icon
{
get { return _icon; }
set
{
_icon = value;
IconPath = Path.Combine(WebSearchPlugin.PluginDirectory, WebSearchPlugin.ImageDirectory, value);
}
}
/// <summary>
/// All icon should be put under Images directory
/// </summary>
[NotNull]
[JsonIgnore]
internal string IconPath { get; private set; }
public string Url { get; set; } public string Url { get; set; }
public bool Enabled { get; set; } public bool Enabled { get; set; }
} }

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.Linq; using System.Linq;
using System.Windows.Controls; using System.Windows.Controls;
using JetBrains.Annotations; using JetBrains.Annotations;
@@ -13,14 +14,10 @@ namespace Wox.Plugin.WebSearch
{ {
public PluginInitContext Context { get; private set; } public PluginInitContext Context { get; private set; }
private readonly PluginJsonStorage<Settings> _storage; private PluginJsonStorage<Settings> _storage;
private readonly Settings _settings; private Settings _settings;
public const string ImageDirectory = "Images";
public WebSearchPlugin() public static string PluginDirectory;
{
_storage = new PluginJsonStorage<Settings>();
_settings = _storage.Load();
}
public void Save() public void Save()
{ {
@@ -48,7 +45,7 @@ namespace Wox.Plugin.WebSearch
Title = title, Title = title,
SubTitle = subtitle, SubTitle = subtitle,
Score = 6, Score = 6,
IcoPath = webSearch.IconPath, IcoPath = webSearch.IconPath,
Action = c => Action = c =>
{ {
Process.Start(webSearch.Url.Replace("{q}", Uri.EscapeDataString(keyword ?? string.Empty))); Process.Start(webSearch.Url.Replace("{q}", Uri.EscapeDataString(keyword ?? string.Empty)));
@@ -92,6 +89,9 @@ namespace Wox.Plugin.WebSearch
public void Init(PluginInitContext context) public void Init(PluginInitContext context)
{ {
Context = context; Context = context;
PluginDirectory = Context.CurrentPluginMetadata.PluginDirectory;
_storage = new PluginJsonStorage<Settings>();
_settings = _storage.Load();
} }
#region ISettingProvider Members #region ISettingProvider Members

View File

@@ -2,20 +2,14 @@
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Microsoft.Win32; using Microsoft.Win32;
using Wox.Infrastructure;
using Wox.Infrastructure.Exception; using Wox.Infrastructure.Exception;
using Wox.Infrastructure.Image; using Wox.Infrastructure.Image;
namespace Wox.Plugin.WebSearch 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 readonly WebSearchesSetting _settingWindow;
private bool _isUpdate; private bool _isUpdate;
private WebSearch _webSearch; private WebSearch _webSearch;
@@ -30,7 +24,6 @@ namespace Wox.Plugin.WebSearch
_context = settingWidow.Context; _context = settingWidow.Context;
_settingWindow = settingWidow; _settingWindow = settingWidow;
_settings = settings; _settings = settings;
_pluginDirectory = _settingWindow.Context.CurrentPluginMetadata.PluginDirectory;
} }
public void UpdateItem(WebSearch webSearch) public void UpdateItem(WebSearch webSearch)
@@ -47,21 +40,17 @@ namespace Wox.Plugin.WebSearch
_isUpdate = true; _isUpdate = true;
ConfirmButton.Content = "Update"; ConfirmButton.Content = "Update";
WebSearchIcon.Source = LoadIcon(webSearch.IconPath); WebSearchIcon.Source = ImageLoader.Load(webSearch.IconPath);
EnableCheckBox.IsChecked = webSearch.Enabled; EnableCheckBox.IsChecked = webSearch.Enabled;
WebSearchName.Text = webSearch.Title; WebSearchName.Text = webSearch.Title;
Url.Text = webSearch.Url; Url.Text = webSearch.Url;
Actionword.Text = webSearch.ActionKeyword; Actionword.Text = webSearch.ActionKeyword;
} }
public void AddItem(WebSearch websearch) public void AddItem(WebSearch webSearch)
{ {
_webSearch = websearch; _webSearch = webSearch;
if (string.IsNullOrEmpty(_webSearch.IconPath)) WebSearchIcon.Source = ImageLoader.Load(webSearch.IconPath);
{
_webSearch.IconPath = DefaultIcon;
WebSearchIcon.Source = LoadIcon(_webSearch.IconPath);
}
} }
private void CancelButtonOnClick(object sender, RoutedEventArgs e) private void CancelButtonOnClick(object sender, RoutedEventArgs e)
@@ -69,32 +58,6 @@ namespace Wox.Plugin.WebSearch
Close(); 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;
}
}
/// <summary> /// <summary>
/// Confirm button for both add and update /// Confirm button for both add and update
/// </summary> /// </summary>
@@ -156,9 +119,10 @@ namespace Wox.Plugin.WebSearch
private void SelectIconButtonOnClick(object sender, RoutedEventArgs e) private void SelectIconButtonOnClick(object sender, RoutedEventArgs e)
{ {
var directory = Path.Combine(WebSearchPlugin.PluginDirectory, WebSearchPlugin.ImageDirectory);
var dlg = new OpenFileDialog var dlg = new OpenFileDialog
{ {
InitialDirectory = Path.Combine(_pluginDirectory, ImageDirectory), InitialDirectory = directory,
Filter = "Image files (*.jpg, *.jpeg, *.gif, *.png, *.bmp) |*.jpg; *.jpeg; *.gif; *.png; *.bmp" 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; string fullpath = dlg.FileName;
if (fullpath != null) 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}");
}
} }
} }
} }

View File

@@ -124,6 +124,9 @@
<None Include="Images\youtube.png"> <None Include="Images\youtube.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<Content Include="Images\baidu.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Languages\en.xaml"> <Content Include="Languages\en.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>

View File

@@ -19,7 +19,8 @@
"image", "image",
"youtube", "youtube",
"bing", "bing",
"yahoo" "yahoo",
"bd"
], ],
"Name": "Web Searches", "Name": "Web Searches",
"Description": "Provide the web search ability", "Description": "Provide the web search ability",

View File

@@ -5,6 +5,7 @@ using System.Drawing;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Interop; using System.Windows.Interop;
using System.Windows.Media; using System.Windows.Media;
@@ -57,7 +58,6 @@ namespace Wox.Infrastructure.Image
{ {
try try
{ {
if (File.Exists(fileName) == false) return null;
Icon icon = GetFileIcon(fileName) ?? Icon.ExtractAssociatedIcon(fileName); Icon icon = GetFileIcon(fileName) ?? Icon.ExtractAssociatedIcon(fileName);
if (icon != null) if (icon != null)
{ {
@@ -65,96 +65,93 @@ namespace Wox.Infrastructure.Image
new Int32Rect(0, 0, icon.Width, icon.Height), BitmapSizeOptions.FromEmptyOptions()); new Int32Rect(0, 0, icon.Width, icon.Height), BitmapSizeOptions.FromEmptyOptions());
} }
} }
catch { } catch (System.Exception e)
{
Log.Error(e);
}
return null; return null;
} }
public static void PreloadImages() 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 => Stopwatch.Debug("Preload images from cache", () =>
{ {
var img = Load(i.Key, false); _cache.TopUsedImages.AsParallel().Where(i => !_imageSources.ContainsKey(i.Key)).ForAll(i =>
if (img != null) {
{ var img = Load(i.Key);
// todo happlebao magic if (img != null)
// the image created on other threads can be accessed from main ui thread, {
// this line made it possible // todo happlebao magic
// should be changed the Dispatcher.InvokeAsync in the future // the image created on other threads can be accessed from main ui thread,
img.Freeze(); // this line made it possible
_imageSources[i.Key] = img; // should be changed the Dispatcher.InvokeAsync in the future
} img.Freeze();
}); _imageSources[i.Key] = img;
}
});
});
}); });
Log.Info($"Preload {_cache.TopUsedImages.Count} images from cache"); Log.Info($"Preload {_cache.TopUsedImages.Count} images from cache");
} }
public static ImageSource Load(string path, bool addToCache = true) public static ImageSource Load(string path)
{ {
ImageSource image = null; ImageSource image;
if (string.IsNullOrEmpty(path)) if (string.IsNullOrEmpty(path))
{ {
path = Path.Combine(Wox.ProgramPath, "Images", "app.png"); path = Path.Combine(Wox.ProgramPath, "Images", "app.png");
image = new BitmapImage(new Uri(path)); image = _imageSources[path];
return image;
} }
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;
} }
else if (File.Exists(path) && Path.IsPathRooted(path))
if (_imageSources.ContainsKey(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 else
{ {
string ext = Path.GetExtension(path).ToLower(); path = Path.Combine(Wox.ProgramPath, "Images", Path.GetFileName(path));
if (File.Exists(path))
if (path.StartsWith("data:", StringComparison.OrdinalIgnoreCase))
{ {
image = new BitmapImage(new Uri(path)); image = new BitmapImage(new Uri(path));
} }
else if (SelfExts.Contains(ext) && File.Exists(path)) else
{ {
image = GetIcon(path); path = Path.Combine(Wox.ProgramPath, "Images", "app.png");
} image = _imageSources[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;
}
} }
} }
}); }
return image; return image;
} }

View File

@@ -2,9 +2,8 @@ using System;
using System.Globalization; using System.Globalization;
using System.Windows; using System.Windows;
using System.Windows.Data; using System.Windows.Data;
using Wox.Infrastructure.Image;
namespace Wox.Converters namespace Wox.Infrastructure.Image
{ {
public class ImagePathConverter : IValueConverter public class ImagePathConverter : IValueConverter
{ {

View File

@@ -77,6 +77,7 @@
<Compile Include="Hotkey\KeyEvent.cs" /> <Compile Include="Hotkey\KeyEvent.cs" />
<Compile Include="Image\ImageCache.cs" /> <Compile Include="Image\ImageCache.cs" />
<Compile Include="Image\ImageLoader.cs" /> <Compile Include="Image\ImageLoader.cs" />
<Compile Include="Image\ImagePathConverter.cs" />
<Compile Include="Logger\Log.cs" /> <Compile Include="Logger\Log.cs" />
<Compile Include="Storage\ISavable.cs" /> <Compile Include="Storage\ISavable.cs" />
<Compile Include="Storage\PluginSettingsStorage.cs" /> <Compile Include="Storage\PluginSettingsStorage.cs" />

View File

@@ -6,6 +6,7 @@ namespace Wox.Plugin
{ {
public class PluginMetadata public class PluginMetadata
{ {
private string _pluginDirectory;
public string ID { get; set; } public string ID { get; set; }
public string Name { get; set; } public string Name { get; set; }
public string Author { get; set; } public string Author { get; set; }
@@ -15,39 +16,34 @@ namespace Wox.Plugin
public string Website { get; set; } 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 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")] [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 string ActionKeyword { get; set; }
public List<string> ActionKeywords { get; set; } public List<string> ActionKeywords { get; set; }
public string IcoPath { get; set; } public string IcoPath { get; set;}
public override string ToString() public override string ToString()
{ {
return Name; return Name;
} }
public string FullIcoPath [Obsolete("Use IcoPath")]
{ public string FullIcoPath => IcoPath;
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);
}
}
} }
} }

View File

@@ -7,21 +7,24 @@ namespace Wox.Plugin
public class Result public class Result
{ {
private string _pluginDirectory;
private string _icoPath;
public string Title { get; set; } public string Title { get; set; }
public string SubTitle { 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 (!string.IsNullOrEmpty(PluginDirectory) && !Path.IsPathRooted(value))
if (IcoPath.StartsWith("data:"))
{ {
return IcoPath; _icoPath = Path.Combine(value, IcoPath);
}
else
{
_icoPath = value;
} }
return Path.Combine(PluginDirectory, IcoPath);
} }
} }
@@ -40,7 +43,18 @@ namespace Wox.Plugin
/// <summary> /// <summary>
/// Plugin directory /// Plugin directory
/// </summary> /// </summary>
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) public override bool Equals(object obj)
{ {

View File

@@ -39,7 +39,7 @@ namespace Wox
base.OnStartup(e); base.OnStartup(e);
RegisterUnhandledException(); RegisterUnhandledException();
Task.Factory.StartNew(ImageLoader.PreloadImages); ImageLoader.PreloadImages();
MainViewModel mainVM = new MainViewModel(); MainViewModel mainVM = new MainViewModel();
API = new PublicAPIInstance(mainVM, mainVM._settings); API = new PublicAPIInstance(mainVM, mainVM._settings);

View File

@@ -1,30 +0,0 @@
using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Markup;
namespace Wox.Converters
{
public abstract class ConvertorBase<T> : MarkupExtension, IValueConverter where T : class, new()
{
private static T converter;
/// <summary>
/// Must be implemented in inheritor.
/// </summary>
public abstract object Convert(object value, Type targetType, object parameter, CultureInfo culture);
/// <summary>
/// Override if needed.
/// </summary>
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());
}
}
}

View File

@@ -3,7 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 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" xmlns:vm="clr-namespace:Wox.ViewModel"
mc:Ignorable="d" d:DesignWidth="100" d:DesignHeight="100" mc:Ignorable="d" d:DesignWidth="100" d:DesignHeight="100"
d:DataContext="{d:DesignInstance vm:ResultsViewModel}" d:DataContext="{d:DesignInstance vm:ResultsViewModel}"
@@ -27,7 +27,7 @@
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5" <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5"
Cursor="Hand" UseLayoutRounding="False"> Cursor="Hand" UseLayoutRounding="False">
<Grid.Resources> <Grid.Resources>
<converters:ImagePathConverter x:Key="ImageConverter" /> <image:ImagePathConverter x:Key="ImageConverter" />
</Grid.Resources> </Grid.Resources>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="32" /> <ColumnDefinition Width="32" />
@@ -35,7 +35,7 @@
<ColumnDefinition Width="0" /> <ColumnDefinition Width="0" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Image x:Name="imgIco" Width="32" Height="32" HorizontalAlignment="Left" <Image x:Name="imgIco" Width="32" Height="32" HorizontalAlignment="Left"
Source="{Binding FullIcoPath,Converter={StaticResource ImageConverter},IsAsync=True}" /> Source="{Binding IcoPath,Converter={StaticResource ImageConverter},IsAsync=True}" />
<Grid Margin="5 0 5 0" Grid.Column="1" HorizontalAlignment="Stretch"> <Grid Margin="5 0 5 0" Grid.Column="1" HorizontalAlignment="Stretch">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition /> <RowDefinition />

View File

@@ -4,9 +4,7 @@
xmlns:wox="clr-namespace:Wox" xmlns:wox="clr-namespace:Wox"
x:Class="Wox.SettingWindow" x:Class="Wox.SettingWindow"
xmlns:woxPlugin="clr-namespace:Wox.Plugin;assembly=Wox.Plugin" xmlns:woxPlugin="clr-namespace:Wox.Plugin;assembly=Wox.Plugin"
xmlns:converters="clr-namespace:Wox.Converters" xmlns:image="clr-namespace:Wox.Infrastructure.Image;assembly=Wox.Infrastructure"
xmlns:userSettings="clr-namespace:Wox.Core.UserSettings;assembly=Wox.Core"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Icon="Images\app.png" Icon="Images\app.png"
Title="{DynamicResource woxsettings}" Title="{DynamicResource woxsettings}"
ResizeMode="NoResize" ResizeMode="NoResize"
@@ -18,7 +16,7 @@
IsHitTestVisible="False" x:Key="FeatureBoxSeperator"> IsHitTestVisible="False" x:Key="FeatureBoxSeperator">
<Separator Width="{Binding ElementName=lbPlugins, Path=ActualWidth}" /> <Separator Width="{Binding ElementName=lbPlugins, Path=ActualWidth}" />
</ListBoxItem> </ListBoxItem>
<converters:ImagePathConverter x:Key="ImageConverter" /> <image:ImagePathConverter x:Key="ImageConverter" />
</Window.Resources> </Window.Resources>
<TabControl Height="auto" x:Name="settingTab" SelectionChanged="settingTab_SelectionChanged"> <TabControl Height="auto" x:Name="settingTab" SelectionChanged="settingTab_SelectionChanged">
<TabItem Header="{DynamicResource general}"> <TabItem Header="{DynamicResource general}">
@@ -70,7 +68,7 @@
<ColumnDefinition /> <ColumnDefinition />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Image Width="32" Height="32" HorizontalAlignment="Left" <Image Width="32" Height="32" HorizontalAlignment="Left"
Source="{Binding Metadata.FullIcoPath,Converter={StaticResource ImageConverter},IsAsync=True}" /> Source="{Binding Metadata.IcoPath,Converter={StaticResource ImageConverter},IsAsync=True}" />
<Grid Margin="3 0 3 0" Grid.Column="1" HorizontalAlignment="Stretch"> <Grid Margin="3 0 3 0" Grid.Column="1" HorizontalAlignment="Stretch">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition /> <RowDefinition />

View File

@@ -551,7 +551,7 @@ namespace Wox
pluginAuthor.Text = InternationalizationManager.Instance.GetTranslation("author") + ": " + pair.Metadata.Author; pluginAuthor.Text = InternationalizationManager.Instance.GetTranslation("author") + ": " + pair.Metadata.Author;
pluginSubTitle.Text = pair.Metadata.Description; pluginSubTitle.Text = pair.Metadata.Description;
pluginId = pair.Metadata.ID; pluginId = pair.Metadata.ID;
pluginIcon.Source = ImageLoader.Load(pair.Metadata.FullIcoPath); pluginIcon.Source = ImageLoader.Load(pair.Metadata.IcoPath);
var customizedPluginConfig = _settings.PluginSettings[pluginId]; var customizedPluginConfig = _settings.PluginSettings[pluginId];
cbDisablePlugin.IsChecked = customizedPluginConfig != null && customizedPluginConfig.Disabled; cbDisablePlugin.IsChecked = customizedPluginConfig != null && customizedPluginConfig.Disabled;

View File

@@ -35,9 +35,10 @@ namespace Wox.ViewModel
public string SubTitle => RawResult.SubTitle; public string SubTitle => RawResult.SubTitle;
public string FullIcoPath => RawResult.FullIcoPath;
public string PluginID => RawResult.PluginID; public string PluginID => RawResult.PluginID;
public string IcoPath => RawResult.IcoPath;
public int Score public int Score
{ {
get { return RawResult.Score; } get { return RawResult.Score; }

View File

@@ -122,8 +122,6 @@
<Link>Properties\SolutionAssemblyInfo.cs</Link> <Link>Properties\SolutionAssemblyInfo.cs</Link>
</Compile> </Compile>
<Compile Include="CommandArgs\ToggleCommandArg.cs" /> <Compile Include="CommandArgs\ToggleCommandArg.cs" />
<Compile Include="Converters\ConvertorBase.cs" />
<Compile Include="Converters\ImagePathConverter.cs" />
<Compile Include="Helper\VisibilityExtensions.cs" /> <Compile Include="Helper\VisibilityExtensions.cs" />
<Compile Include="Helper\SingletonWindowOpener.cs" /> <Compile Include="Helper\SingletonWindowOpener.cs" />
<Compile Include="NotifyIconManager.cs" /> <Compile Include="NotifyIconManager.cs" />
@@ -378,9 +376,7 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource> </Resource>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup />
<Folder Include="Extensions\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>
<PostBuildEvent>xcopy /Y $(ProjectDir)Themes\* $(TargetDir)Themes\ <PostBuildEvent>xcopy /Y $(ProjectDir)Themes\* $(TargetDir)Themes\