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,
SubTitle = $"Activate {metadata.Name} plugin",
Score = 100,
IcoPath = metadata.FullIcoPath,
IcoPath = metadata.IcoPath,
Action = c =>
{
context.API.ChangeQuery($"{keyword}{Plugin.Query.TermSeperater}");

View File

@@ -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;

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

View File

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

View File

@@ -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<Settings> _storage;
private readonly Settings _settings;
public WebSearchPlugin()
{
_storage = new PluginJsonStorage<Settings>();
_settings = _storage.Load();
}
private PluginJsonStorage<Settings> _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>();
_settings = _storage.Load();
}
#region ISettingProvider Members

View File

@@ -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;
}
}
/// <summary>
/// Confirm button for both add and update
/// </summary>
@@ -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}");
}
}
}
}

View File

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

View File

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