diff --git a/Plugins/Wox.Plugin.WebSearch/Settings.cs b/Plugins/Wox.Plugin.WebSearch/Settings.cs
index 6c878adfd8..c1fb1dda02 100644
--- a/Plugins/Wox.Plugin.WebSearch/Settings.cs
+++ b/Plugins/Wox.Plugin.WebSearch/Settings.cs
@@ -12,7 +12,7 @@ namespace Wox.Plugin.WebSearch
{
Title = "Google",
ActionKeyword = "g",
- IconPath = "Images\\google.png",
+ IconPath = "google.png",
Url = "https://www.google.com/search?q={q}",
Enabled = true
},
@@ -20,7 +20,7 @@ namespace Wox.Plugin.WebSearch
{
Title = "Wikipedia",
ActionKeyword = "wiki",
- IconPath = "Images\\wiki.png",
+ IconPath = "wiki.png",
Url = "http://en.wikipedia.org/wiki/{q}",
Enabled = true
},
@@ -28,7 +28,7 @@ namespace Wox.Plugin.WebSearch
{
Title = "FindIcon",
ActionKeyword = "findicon",
- IconPath = "Images\\pictures.png",
+ IconPath = "pictures.png",
Url = "http://findicons.com/search/{q}",
Enabled = true
},
@@ -36,7 +36,7 @@ namespace Wox.Plugin.WebSearch
{
Title = "Facebook",
ActionKeyword = "facebook",
- IconPath = "Images\\facebook.png",
+ IconPath = "facebook.png",
Url = "http://www.facebook.com/search/?q={q}",
Enabled = true
},
@@ -44,7 +44,7 @@ namespace Wox.Plugin.WebSearch
{
Title = "Twitter",
ActionKeyword = "twitter",
- IconPath = "Images\\twitter.png",
+ IconPath = "twitter.png",
Url = "http://twitter.com/search?q={q}",
Enabled = true
},
@@ -52,7 +52,7 @@ namespace Wox.Plugin.WebSearch
{
Title = "Google Maps",
ActionKeyword = "maps",
- IconPath = "Images\\google_maps.png",
+ IconPath = "google_maps.png",
Url = "http://maps.google.com/maps?q={q}",
Enabled = true
},
@@ -60,7 +60,7 @@ namespace Wox.Plugin.WebSearch
{
Title = "Google Translate",
ActionKeyword = "translate",
- IconPath = "Images\\google_translate.png",
+ IconPath = "google_translate.png",
Url = "http://translate.google.com/#auto|en|{q}",
Enabled = true
},
@@ -68,7 +68,7 @@ namespace Wox.Plugin.WebSearch
{
Title = "Duckduckgo",
ActionKeyword = "duckduckgo",
- IconPath = "Images\\duckduckgo.png",
+ IconPath = "duckduckgo.png",
Url = "https://duckduckgo.com/?q={q}",
Enabled = true
},
@@ -76,7 +76,7 @@ namespace Wox.Plugin.WebSearch
{
Title = "Github",
ActionKeyword = "github",
- IconPath = "Images\\github.png",
+ IconPath = "github.png",
Url = "https://github.com/search?q={q}",
Enabled = true
},
@@ -84,7 +84,7 @@ namespace Wox.Plugin.WebSearch
{
Title = "Github Gist",
ActionKeyword = "gist",
- IconPath = "Images\\gist.png",
+ IconPath = "gist.png",
Url = "https://gist.github.com/search?q={q}",
Enabled = true
},
@@ -92,7 +92,7 @@ namespace Wox.Plugin.WebSearch
{
Title = "Gmail",
ActionKeyword = "gmail",
- IconPath = "Images\\gmail.png",
+ IconPath = "gmail.png",
Url = "https://mail.google.com/mail/ca/u/0/#apps/{q}",
Enabled = true
},
@@ -100,7 +100,7 @@ namespace Wox.Plugin.WebSearch
{
Title = "Google Drive",
ActionKeyword = "drive",
- IconPath = "Images\\google_drive.png",
+ IconPath = "google_drive.png",
Url = "http://drive.google.com/?hl=en&tab=bo#search/{q}",
Enabled = true
},
@@ -108,7 +108,7 @@ namespace Wox.Plugin.WebSearch
{
Title = "Wolframalpha",
ActionKeyword = "wolframalpha",
- IconPath = "Images\\wolframalpha.png",
+ IconPath = "wolframalpha.png",
Url = "http://www.wolframalpha.com/input/?i={q}",
Enabled = true
},
@@ -116,7 +116,7 @@ namespace Wox.Plugin.WebSearch
{
Title = "Stackoverflow",
ActionKeyword = "stackoverflow",
- IconPath = "Images\\stackoverflow.png",
+ IconPath = "stackoverflow.png",
Url = "http://stackoverflow.com/search?q={q}",
Enabled = true
},
@@ -124,7 +124,7 @@ namespace Wox.Plugin.WebSearch
{
Title = "I'm Feeling Lucky",
ActionKeyword = "lucky",
- IconPath = "Images\\google.png",
+ IconPath = "google.png",
Url = "http://google.com/search?q={q}&btnI=I",
Enabled = true
},
@@ -132,7 +132,7 @@ namespace Wox.Plugin.WebSearch
{
Title = "Google Image",
ActionKeyword = "image",
- IconPath = "Images\\google.png",
+ IconPath = "google.png",
Url = "https://www.google.com/search?q={q}&tbm=isch",
Enabled = true
},
@@ -140,7 +140,7 @@ namespace Wox.Plugin.WebSearch
{
Title = "Youtube",
ActionKeyword = "youtube",
- IconPath = "Images\\youtube.png",
+ IconPath = "youtube.png",
Url = "http://www.youtube.com/results?search_query={q}",
Enabled = true
},
@@ -148,7 +148,7 @@ namespace Wox.Plugin.WebSearch
{
Title = "Bing",
ActionKeyword = "bing",
- IconPath = "Images\\bing.png",
+ IconPath = "bing.png",
Url = "https://www.bing.com/search?q={q}",
Enabled = true
},
@@ -156,7 +156,7 @@ namespace Wox.Plugin.WebSearch
{
Title = "Yahoo",
ActionKeyword = "yahoo",
- IconPath = "Images\\yahoo.png",
+ IconPath = "yahoo.png",
Url = "http://www.search.yahoo.com/search?p={q}",
Enabled = true
}
diff --git a/Plugins/Wox.Plugin.WebSearch/WebSearchSetting.xaml b/Plugins/Wox.Plugin.WebSearch/WebSearchSetting.xaml
index 39976e6695..c83f9ae08a 100644
--- a/Plugins/Wox.Plugin.WebSearch/WebSearchSetting.xaml
+++ b/Plugins/Wox.Plugin.WebSearch/WebSearchSetting.xaml
@@ -18,27 +18,25 @@
-
+
-
+
-
+
-
+
-
-
-
+
+
-
-
+
+
diff --git a/Plugins/Wox.Plugin.WebSearch/WebSearchSetting.xaml.cs b/Plugins/Wox.Plugin.WebSearch/WebSearchSetting.xaml.cs
index d3e4715bcc..a359378e73 100644
--- a/Plugins/Wox.Plugin.WebSearch/WebSearchSetting.xaml.cs
+++ b/Plugins/Wox.Plugin.WebSearch/WebSearchSetting.xaml.cs
@@ -2,37 +2,41 @@
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
{
- private const string _imageDirectoryName = "Images";
- private string _pluginDirectory = WoxDirectroy.Executable;
+ 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 _updateWebSearch;
+ private WebSearch _webSearch;
private readonly PluginInitContext _context;
private readonly WebSearchPlugin _plugin;
- private Settings _settings;
+ private readonly Settings _settings;
public WebSearchSetting(WebSearchesSetting settingWidow, Settings settings)
{
+ InitializeComponent();
_plugin = settingWidow.Plugin;
_context = settingWidow.Context;
_settingWindow = settingWidow;
- InitializeComponent();
_settings = settings;
+ _pluginDirectory = _settingWindow.Context.CurrentPluginMetadata.PluginDirectory;
}
public void UpdateItem(WebSearch webSearch)
{
- _updateWebSearch = _settings.WebSearches.FirstOrDefault(o => o == webSearch);
- if (_updateWebSearch == null || string.IsNullOrEmpty(_updateWebSearch.Url))
+ _webSearch = _settings.WebSearches.FirstOrDefault(o => o == webSearch);
+ if (_webSearch == null || string.IsNullOrEmpty(_webSearch.Url))
{
string warning = _context.API.GetTranslation("wox_plugin_websearch_invalid_web_search");
@@ -42,31 +46,61 @@ namespace Wox.Plugin.WebSearch
}
_isUpdate = true;
- lblAdd.Text = "Update";
- tbIconPath.Text = webSearch.IconPath;
- ShowIcon(webSearch.IconPath);
- cbEnable.IsChecked = webSearch.Enabled;
- tbTitle.Text = webSearch.Title;
- tbUrl.Text = webSearch.Url;
- tbActionword.Text = webSearch.ActionKeyword;
+ ConfirmButton.Content = "Update";
+ WebSearchIcon.Source = LoadIcon(webSearch.IconPath);
+ EnableCheckBox.IsChecked = webSearch.Enabled;
+ WebSearchName.Text = webSearch.Title;
+ Url.Text = webSearch.Url;
+ Actionword.Text = webSearch.ActionKeyword;
}
- private void ShowIcon(string path)
+ public void AddItem(WebSearch websearch)
{
- imgIcon.Source = new BitmapImage(new Uri(Path.Combine(_pluginDirectory, path), UriKind.Absolute));
+ _webSearch = websearch;
+ if (string.IsNullOrEmpty(_webSearch.IconPath))
+ {
+ _webSearch.IconPath = DefaultIcon;
+ WebSearchIcon.Source = LoadIcon(_webSearch.IconPath);
+ }
}
- private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
+ private void CancelButtonOnClick(object sender, RoutedEventArgs e)
{
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
///
- private void btnConfirm_OnClick(object sender, RoutedEventArgs e)
+ private void ConfirmButtonOnClick(object sender, RoutedEventArgs e)
{
- string title = tbTitle.Text;
+ string title = WebSearchName.Text;
if (string.IsNullOrEmpty(title))
{
string warning = _context.API.GetTranslation("wox_plugin_websearch_input_title");
@@ -74,7 +108,7 @@ namespace Wox.Plugin.WebSearch
return;
}
- string url = tbUrl.Text;
+ string url = Url.Text;
if (string.IsNullOrEmpty(url))
{
string warning = _context.API.GetTranslation("wox_plugin_websearch_input_url");
@@ -82,24 +116,19 @@ namespace Wox.Plugin.WebSearch
return;
}
- string newActionKeyword = tbActionword.Text.Trim();
+ string newActionKeyword = Actionword.Text.Trim();
+
if (_isUpdate)
{
try
{
- _plugin.NotifyActionKeywordsUpdated(_updateWebSearch.ActionKeyword, newActionKeyword);
+ _plugin.NotifyActionKeywordsUpdated(_webSearch.ActionKeyword, newActionKeyword);
}
catch (WoxPluginException exception)
{
MessageBox.Show(exception.Message);
return;
}
-
- _updateWebSearch.ActionKeyword = newActionKeyword;
- _updateWebSearch.IconPath = tbIconPath.Text;
- _updateWebSearch.Enabled = cbEnable.IsChecked ?? false;
- _updateWebSearch.Url = url;
- _updateWebSearch.Title = title;
}
else
{
@@ -112,42 +141,34 @@ namespace Wox.Plugin.WebSearch
MessageBox.Show(exception.Message);
return;
}
- _settings.WebSearches.Add(new WebSearch
- {
- ActionKeyword = newActionKeyword,
- Enabled = cbEnable.IsChecked ?? false,
- IconPath = tbIconPath.Text,
- Url = url,
- Title = title
- });
+
+ _settings.WebSearches.Add(_webSearch);
}
+ _webSearch.ActionKeyword = newActionKeyword;
+ _webSearch.Enabled = EnableCheckBox.IsChecked ?? false;
+ _webSearch.Url = url;
+ _webSearch.Title = title;
+
_settingWindow.ReloadWebSearchView();
Close();
}
- private void BtnSelectIcon_OnClick(object sender, RoutedEventArgs e)
+ private void SelectIconButtonOnClick(object sender, RoutedEventArgs e)
{
- if (!Directory.Exists(_pluginDirectory))
- {
- _pluginDirectory =
- Path.GetDirectoryName(WoxDirectroy.Executable);
- }
-
var dlg = new OpenFileDialog
{
- InitialDirectory = Path.Combine(_pluginDirectory, _imageDirectoryName),
+ InitialDirectory = Path.Combine(_pluginDirectory, ImageDirectory),
Filter = "Image files (*.jpg, *.jpeg, *.gif, *.png, *.bmp) |*.jpg; *.jpeg; *.gif; *.png; *.bmp"
};
bool? result = dlg.ShowDialog();
- if (result == true)
+ if (result != null && result == true)
{
- string filename = dlg.FileName;
- if (filename != null)
+ string fullpath = dlg.FileName;
+ if (fullpath != null)
{
- tbIconPath.Text = Path.Combine(_imageDirectoryName, Path.GetFileName(filename));
- ShowIcon(tbIconPath.Text);
+ WebSearchIcon.Source = LoadIcon(fullpath);
}
}
}
diff --git a/Plugins/Wox.Plugin.WebSearch/WebSearchesSetting.xaml.cs b/Plugins/Wox.Plugin.WebSearch/WebSearchesSetting.xaml.cs
index cfc2af4c1f..0768ee9aaf 100644
--- a/Plugins/Wox.Plugin.WebSearch/WebSearchesSetting.xaml.cs
+++ b/Plugins/Wox.Plugin.WebSearch/WebSearchesSetting.xaml.cs
@@ -53,8 +53,12 @@ namespace Wox.Plugin.WebSearch
private void btnAddWebSearch_OnClick(object sender, RoutedEventArgs e)
{
- WebSearchSetting webSearch = new WebSearchSetting(this, _settings);
- webSearch.ShowDialog();
+ var setting = new WebSearchSetting(this, _settings);
+ var webSearch = new WebSearch();
+
+
+ setting.AddItem(webSearch);
+ setting.ShowDialog();
}
private void btnDeleteWebSearch_OnClick(object sender, RoutedEventArgs e)
diff --git a/Wox.Core/Updater/UpdaterManager.cs b/Wox.Core/Updater/UpdaterManager.cs
index c8f710ba51..5e83e0c404 100644
--- a/Wox.Core/Updater/UpdaterManager.cs
+++ b/Wox.Core/Updater/UpdaterManager.cs
@@ -115,8 +115,8 @@ namespace Wox.Core.Updater
}
catch (Exception e)
{
- Log.Error(e);
updManager.CleanUp();
+ Log.Error(e);
return;
}
diff --git a/Wox.Infrastructure/Image/ImageLoader.cs b/Wox.Infrastructure/Image/ImageLoader.cs
index 1ecd4e9f25..788395a8e7 100644
--- a/Wox.Infrastructure/Image/ImageLoader.cs
+++ b/Wox.Infrastructure/Image/ImageLoader.cs
@@ -13,11 +13,11 @@ using Wox.Infrastructure.Storage;
namespace Wox.Infrastructure.Image
{
- public class ImageLoader
+ public static class ImageLoader
{
- private readonly ConcurrentDictionary _imageSources = new ConcurrentDictionary();
+ private static readonly ConcurrentDictionary _imageSources = new ConcurrentDictionary();
- private readonly List ImageExts = new List
+ private static readonly List ImageExts = new List
{
".png",
".jpg",
@@ -28,7 +28,7 @@ namespace Wox.Infrastructure.Image
".ico"
};
- private readonly List SelfExts = new List
+ private static readonly List SelfExts = new List
{
".exe",
".lnk",
@@ -38,21 +38,21 @@ namespace Wox.Infrastructure.Image
".appref-ms"
};
- private readonly ImageCache _cache;
- private readonly BinaryStorage _storage;
+ private static readonly ImageCache _cache;
+ private static readonly BinaryStorage _storage;
- public ImageLoader()
+ static ImageLoader()
{
_storage = new BinaryStorage();
_cache = _storage.Load();
}
- ~ImageLoader()
+ public static void Save()
{
_storage.Save();
}
- private ImageSource GetIcon(string fileName)
+ private static ImageSource GetIcon(string fileName)
{
try
{
@@ -69,7 +69,7 @@ namespace Wox.Infrastructure.Image
return null;
}
- public void PreloadImages()
+ public static void PreloadImages()
{
Stopwatch.Debug($"Preload {_cache.TopUsedImages.Count} images", () =>
{
@@ -89,10 +89,15 @@ namespace Wox.Infrastructure.Image
});
}
- public ImageSource Load(string path, bool addToCache = true)
+ public static ImageSource Load(string path, bool addToCache = true)
{
- if (string.IsNullOrEmpty(path)) return null;
ImageSource image = null;
+ if (string.IsNullOrEmpty(path))
+ {
+ path = Path.Combine(WoxDirectroy.Executable, "Images", "app.png");
+ image = new BitmapImage(new Uri(path));
+ return image;
+ }
Stopwatch.Debug($"Loading image path: {path}", () =>
{
@@ -152,7 +157,7 @@ namespace Wox.Infrastructure.Image
}
// http://blogs.msdn.com/b/oldnewthing/archive/2011/01/27/10120844.aspx
- private Icon GetFileIcon(string name)
+ private static Icon GetFileIcon(string name)
{
SHFILEINFO shfi = new SHFILEINFO();
uint flags = SHGFI_SYSICONINDEX;
diff --git a/Wox.Infrastructure/Storage/BinaryStorage.cs b/Wox.Infrastructure/Storage/BinaryStorage.cs
index 7fc339df99..3165530b06 100644
--- a/Wox.Infrastructure/Storage/BinaryStorage.cs
+++ b/Wox.Infrastructure/Storage/BinaryStorage.cs
@@ -73,13 +73,13 @@ namespace Wox.Infrastructure.Storage
}
catch (SerializationException e)
{
- Log.Error(e);
LoadDefault();
+ Log.Error(e);
}
catch (InvalidCastException e)
{
- Log.Error(e);
LoadDefault();
+ Log.Error(e);
}
finally
{
diff --git a/Wox/App.xaml.cs b/Wox/App.xaml.cs
index 01edd7141a..4194a4597d 100644
--- a/Wox/App.xaml.cs
+++ b/Wox/App.xaml.cs
@@ -21,7 +21,6 @@ namespace Wox
{
private const string Unique = "Wox_Unique_Application_Mutex";
public static MainWindow Window { get; private set; }
- public static ImageLoader ImageLoader;
public static PublicAPIInstance API { get; private set; }
[STAThread]
@@ -44,7 +43,6 @@ namespace Wox
WoxDirectroy.Executable = Directory.GetParent(Assembly.GetExecutingAssembly().Location).ToString();
RegisterUnhandledException();
- ImageLoader = new ImageLoader();
Task.Factory.StartNew(ImageLoader.PreloadImages);
PluginManager.Initialize();
diff --git a/Wox/Converters/ImagePathConverter.cs b/Wox/Converters/ImagePathConverter.cs
index a15c54cc42..77747fbc92 100644
--- a/Wox/Converters/ImagePathConverter.cs
+++ b/Wox/Converters/ImagePathConverter.cs
@@ -2,6 +2,7 @@ using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
+using Wox.Infrastructure.Image;
namespace Wox.Converters
{
@@ -13,7 +14,7 @@ namespace Wox.Converters
{
return null;
}
- var image = App.ImageLoader.Load(value.ToString());
+ var image = ImageLoader.Load(value.ToString());
return image;
}
diff --git a/Wox/Msg.xaml.cs b/Wox/Msg.xaml.cs
index 689def37f6..e3689b12df 100644
--- a/Wox/Msg.xaml.cs
+++ b/Wox/Msg.xaml.cs
@@ -7,6 +7,7 @@ using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using Wox.Helper;
using Wox.Infrastructure;
+using Wox.Infrastructure.Image;
namespace Wox
{
@@ -37,7 +38,7 @@ namespace Wox
Storyboard.SetTargetProperty(fadeOutAnimation, new PropertyPath(TopProperty));
fadeOutStoryboard.Children.Add(fadeOutAnimation);
- imgClose.Source = App.ImageLoader.Load(Path.Combine(WoxDirectroy.Executable, "Images\\close.png"));
+ imgClose.Source = ImageLoader.Load(Path.Combine(WoxDirectroy.Executable, "Images\\close.png"));
imgClose.MouseUp += imgClose_MouseUp;
}
@@ -65,10 +66,10 @@ namespace Wox
}
if (!File.Exists(iconPath))
{
- imgIco.Source = App.ImageLoader.Load(Path.Combine(WoxDirectroy.Executable, "Images\\app.png"));
+ imgIco.Source = ImageLoader.Load(Path.Combine(WoxDirectroy.Executable, "Images\\app.png"));
}
else {
- imgIco.Source = App.ImageLoader.Load(iconPath);
+ imgIco.Source = ImageLoader.Load(iconPath);
}
Show();
diff --git a/Wox/SettingWindow.xaml.cs b/Wox/SettingWindow.xaml.cs
index adc626a9df..c1cbd59d07 100644
--- a/Wox/SettingWindow.xaml.cs
+++ b/Wox/SettingWindow.xaml.cs
@@ -19,6 +19,7 @@ using Wox.Core.Updater;
using Wox.Core.UserSettings;
using Wox.Helper;
using Wox.Infrastructure.Hotkey;
+using Wox.Infrastructure.Image;
using Wox.Plugin;
using Wox.ViewModel;
using Application = System.Windows.Forms.Application;
@@ -550,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 = App.ImageLoader.Load(pair.Metadata.FullIcoPath);
+ pluginIcon.Source = ImageLoader.Load(pair.Metadata.FullIcoPath);
var customizedPluginConfig = _settings.PluginSettings[pluginId];
cbDisablePlugin.IsChecked = customizedPluginConfig != null && customizedPluginConfig.Disabled;