Move web search setting to its own project

This commit is contained in:
qianlifeng
2015-01-26 22:50:38 +08:00
parent 56fa719931
commit 87958d9db8
13 changed files with 270 additions and 253 deletions

View File

@@ -45,18 +45,18 @@ namespace Wox.Plugin.PluginIndicator
} }
} }
results.AddRange(UserSettingStorage.Instance.WebSearches.Where(o => o.ActionWord.StartsWith(query.Search) && o.Enabled).Select(n => new Result() //results.AddRange(UserSettingStorage.Instance.WebSearches.Where(o => o.ActionWord.StartsWith(query.Search) && o.Enabled).Select(n => new Result()
{ //{
Title = n.ActionWord, // Title = n.ActionWord,
SubTitle = string.Format("Activate {0} web search", n.ActionWord), // SubTitle = string.Format("Activate {0} web search", n.ActionWord),
Score = 100, // Score = 100,
IcoPath = "Images/work.png", // IcoPath = "Images/work.png",
Action = (c) => // Action = (c) =>
{ // {
context.API.ChangeQuery(n.ActionWord + " "); // context.API.ChangeQuery(n.ActionWord + " ");
return false; // return false;
} // }
})); //}));
return results; return results;
} }

View File

@@ -1,6 +1,6 @@
using System; using System;
namespace Wox.Core.UserSettings namespace Wox.Plugin.WebSearch
{ {
[Serializable] [Serializable]
public class WebSearch public class WebSearch

View File

@@ -17,8 +17,8 @@ namespace Wox.Plugin.WebSearch
{ {
List<Result> results = new List<Result>(); List<Result> results = new List<Result>();
Core.UserSettings.WebSearch webSearch = WebSearch webSearch =
UserSettingStorage.Instance.WebSearches.FirstOrDefault(o => o.ActionWord == query.FirstSearch.Trim() && o.Enabled); WebSearchStorage.Instance.WebSearches.FirstOrDefault(o => o.ActionWord == query.FirstSearch.Trim() && o.Enabled);
if (webSearch != null) if (webSearch != null)
{ {
@@ -46,10 +46,10 @@ namespace Wox.Plugin.WebSearch
} }
}); });
if (UserSettingStorage.Instance.EnableWebSearchSuggestion && !string.IsNullOrEmpty(keyword)) if (WebSearchStorage.Instance.EnableWebSearchSuggestion && !string.IsNullOrEmpty(keyword))
{ {
ISuggestionSource sugg = SuggestionSourceFactory.GetSuggestionSource( ISuggestionSource sugg = SuggestionSourceFactory.GetSuggestionSource(
UserSettingStorage.Instance.WebSearchSuggestionSource); WebSearchStorage.Instance.WebSearchSuggestionSource);
if (sugg != null) if (sugg != null)
{ {
var result = sugg.GetSuggestions(keyword); var result = sugg.GetSuggestions(keyword);
@@ -80,8 +80,8 @@ namespace Wox.Plugin.WebSearch
{ {
this.context = context; this.context = context;
if (UserSettingStorage.Instance.WebSearches == null) if (WebSearchStorage.Instance.WebSearches == null)
UserSettingStorage.Instance.WebSearches = UserSettingStorage.Instance.LoadDefaultWebSearches(); WebSearchStorage.Instance.WebSearches = WebSearchStorage.Instance.LoadDefaultWebSearches();
} }
#region ISettingProvider Members #region ISettingProvider Members

View File

@@ -14,7 +14,7 @@ namespace Wox.Plugin.WebSearch
private string defaultWebSearchImageDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Images\\websearch"); private string defaultWebSearchImageDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Images\\websearch");
private WebSearchesSetting settingWindow; private WebSearchesSetting settingWindow;
private bool update; private bool update;
private Core.UserSettings.WebSearch updateWebSearch; private WebSearch updateWebSearch;
private PluginInitContext context; private PluginInitContext context;
public WebSearchSetting(WebSearchesSetting settingWidow,PluginInitContext context) public WebSearchSetting(WebSearchesSetting settingWidow,PluginInitContext context)
@@ -24,9 +24,9 @@ namespace Wox.Plugin.WebSearch
InitializeComponent(); InitializeComponent();
} }
public void UpdateItem(Core.UserSettings.WebSearch webSearch) public void UpdateItem(WebSearch webSearch)
{ {
updateWebSearch = UserSettingStorage.Instance.WebSearches.FirstOrDefault(o => o == webSearch); updateWebSearch = WebSearchStorage.Instance.WebSearches.FirstOrDefault(o => o == webSearch);
if (updateWebSearch == null || string.IsNullOrEmpty(updateWebSearch.Url)) if (updateWebSearch == null || string.IsNullOrEmpty(updateWebSearch.Url))
{ {
@@ -91,13 +91,13 @@ namespace Wox.Plugin.WebSearch
if (!update) if (!update)
{ {
if (UserSettingStorage.Instance.WebSearches.Exists(o => o.ActionWord == action)) if (WebSearchStorage.Instance.WebSearches.Exists(o => o.ActionWord == action))
{ {
string warning = context.API.GetTranslation("wox_plugin_websearch_action_keyword_exist"); string warning = context.API.GetTranslation("wox_plugin_websearch_action_keyword_exist");
MessageBox.Show(warning); MessageBox.Show(warning);
return; return;
} }
UserSettingStorage.Instance.WebSearches.Add(new Core.UserSettings.WebSearch() WebSearchStorage.Instance.WebSearches.Add(new WebSearch()
{ {
ActionWord = action, ActionWord = action,
Enabled = cbEnable.IsChecked ?? false, Enabled = cbEnable.IsChecked ?? false,
@@ -110,7 +110,7 @@ namespace Wox.Plugin.WebSearch
} }
else else
{ {
if (UserSettingStorage.Instance.WebSearches.Exists(o => o.ActionWord == action && o != updateWebSearch)) if (WebSearchStorage.Instance.WebSearches.Exists(o => o.ActionWord == action && o != updateWebSearch))
{ {
string warning = context.API.GetTranslation("wox_plugin_websearch_action_keyword_exist"); string warning = context.API.GetTranslation("wox_plugin_websearch_action_keyword_exist");
MessageBox.Show(warning); MessageBox.Show(warning);

View File

@@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using Newtonsoft.Json;
using Wox.Core.UserSettings;
using Wox.Infrastructure.Storage;
namespace Wox.Plugin.WebSearch
{
public class WebSearchStorage :JsonStrorage<WebSearchStorage>
{
[JsonProperty]
public List<WebSearch> WebSearches { get; set; }
[JsonProperty]
public bool EnableWebSearchSuggestion { get; set; }
[JsonProperty]
public string WebSearchSuggestionSource { get; set; }
protected override string ConfigFolder
{
get { return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); }
}
protected override string ConfigName
{
get { return "setting"; }
}
protected override WebSearchStorage LoadDefault()
{
WebSearches = LoadDefaultWebSearches();
return this;
}
public List<WebSearch> LoadDefaultWebSearches()
{
List<WebSearch> webSearches = new List<WebSearch>();
WebSearch googleWebSearch = new WebSearch()
{
Title = "Google",
ActionWord = "g",
IconPath = @"Images\websearch\google.png",
Url = "https://www.google.com/search?q={q}",
Enabled = true
};
webSearches.Add(googleWebSearch);
WebSearch wikiWebSearch = new WebSearch()
{
Title = "Wikipedia",
ActionWord = "wiki",
IconPath = @"Images\websearch\wiki.png",
Url = "http://en.wikipedia.org/wiki/{q}",
Enabled = true
};
webSearches.Add(wikiWebSearch);
WebSearch findIcon = new WebSearch()
{
Title = "FindIcon",
ActionWord = "findicon",
IconPath = @"Images\websearch\pictures.png",
Url = "http://findicons.com/search/{q}",
Enabled = true
};
webSearches.Add(findIcon);
return webSearches;
}
}
}

View File

@@ -24,9 +24,9 @@ namespace Wox.Plugin.WebSearch
private void Setting_Loaded(object sender, RoutedEventArgs e) private void Setting_Loaded(object sender, RoutedEventArgs e)
{ {
webSearchView.ItemsSource = UserSettingStorage.Instance.WebSearches; webSearchView.ItemsSource = WebSearchStorage.Instance.WebSearches;
cbEnableWebSearchSuggestion.IsChecked = UserSettingStorage.Instance.EnableWebSearchSuggestion; cbEnableWebSearchSuggestion.IsChecked = WebSearchStorage.Instance.EnableWebSearchSuggestion;
comboBoxSuggestionSource.Visibility = UserSettingStorage.Instance.EnableWebSearchSuggestion comboBoxSuggestionSource.Visibility = WebSearchStorage.Instance.EnableWebSearchSuggestion
? Visibility.Visible ? Visibility.Visible
: Visibility.Collapsed; : Visibility.Collapsed;
@@ -35,7 +35,7 @@ namespace Wox.Plugin.WebSearch
new ComboBoxItem() {Content = "Google"}, new ComboBoxItem() {Content = "Google"},
new ComboBoxItem() {Content = "Baidu"}, new ComboBoxItem() {Content = "Baidu"},
}; };
ComboBoxItem selected = items.FirstOrDefault(o => o.Content.ToString() == UserSettingStorage.Instance.WebSearchSuggestionSource); ComboBoxItem selected = items.FirstOrDefault(o => o.Content.ToString() == WebSearchStorage.Instance.WebSearchSuggestionSource);
if (selected == null) if (selected == null)
{ {
selected = items[0]; selected = items[0];
@@ -58,14 +58,14 @@ namespace Wox.Plugin.WebSearch
private void btnDeleteWebSearch_OnClick(object sender, RoutedEventArgs e) private void btnDeleteWebSearch_OnClick(object sender, RoutedEventArgs e)
{ {
Core.UserSettings.WebSearch selectedWebSearch = webSearchView.SelectedItem as Core.UserSettings.WebSearch; WebSearch selectedWebSearch = webSearchView.SelectedItem as WebSearch;
if (selectedWebSearch != null) if (selectedWebSearch != null)
{ {
string msg = string.Format(context.API.GetTranslation("wox_plugin_websearch_delete_warning"),selectedWebSearch.Title); string msg = string.Format(context.API.GetTranslation("wox_plugin_websearch_delete_warning"),selectedWebSearch.Title);
if (MessageBox.Show(msg,string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.Yes) if (MessageBox.Show(msg,string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{ {
UserSettingStorage.Instance.WebSearches.Remove(selectedWebSearch); WebSearchStorage.Instance.WebSearches.Remove(selectedWebSearch);
webSearchView.Items.Refresh(); webSearchView.Items.Refresh();
} }
} }
@@ -78,7 +78,7 @@ namespace Wox.Plugin.WebSearch
private void btnEditWebSearch_OnClick(object sender, RoutedEventArgs e) private void btnEditWebSearch_OnClick(object sender, RoutedEventArgs e)
{ {
Core.UserSettings.WebSearch selectedWebSearch = webSearchView.SelectedItem as Core.UserSettings.WebSearch; WebSearch selectedWebSearch = webSearchView.SelectedItem as WebSearch;
if (selectedWebSearch != null) if (selectedWebSearch != null)
{ {
WebSearchSetting webSearch = new WebSearchSetting(this,context); WebSearchSetting webSearch = new WebSearchSetting(this,context);
@@ -95,23 +95,22 @@ namespace Wox.Plugin.WebSearch
private void CbEnableWebSearchSuggestion_OnChecked(object sender, RoutedEventArgs e) private void CbEnableWebSearchSuggestion_OnChecked(object sender, RoutedEventArgs e)
{ {
comboBoxSuggestionSource.Visibility = Visibility.Visible; comboBoxSuggestionSource.Visibility = Visibility.Visible;
UserSettingStorage.Instance.EnableWebSearchSuggestion = true; WebSearchStorage.Instance.EnableWebSearchSuggestion = true;
UserSettingStorage.Instance.Save(); WebSearchStorage.Instance.Save();
} }
private void CbEnableWebSearchSuggestion_OnUnchecked(object sender, RoutedEventArgs e) private void CbEnableWebSearchSuggestion_OnUnchecked(object sender, RoutedEventArgs e)
{ {
comboBoxSuggestionSource.Visibility = Visibility.Collapsed; comboBoxSuggestionSource.Visibility = Visibility.Collapsed;
UserSettingStorage.Instance.EnableWebSearchSuggestion = false; WebSearchStorage.Instance.EnableWebSearchSuggestion = false;
UserSettingStorage.Instance.Save(); WebSearchStorage.Instance.Save();
} }
private void ComboBoxSuggestionSource_OnSelectionChanged(object sender, SelectionChangedEventArgs e) private void ComboBoxSuggestionSource_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{ {
if (e.AddedItems.Count > 0) if (e.AddedItems.Count > 0)
{ {
UserSettingStorage.Instance.WebSearchSuggestionSource = WebSearchStorage.Instance.WebSearchSuggestionSource = ((ComboBoxItem) e.AddedItems[0]).Content.ToString();
((ComboBoxItem) e.AddedItems[0]).Content.ToString();
UserSettingStorage.Instance.Save(); UserSettingStorage.Instance.Save();
} }
} }

View File

@@ -56,6 +56,7 @@
<Compile Include="SuggestionSources\Google.cs" /> <Compile Include="SuggestionSources\Google.cs" />
<Compile Include="SuggestionSources\ISuggestionSource.cs" /> <Compile Include="SuggestionSources\ISuggestionSource.cs" />
<Compile Include="SuggestionSources\SuggestionSourceFactory.cs" /> <Compile Include="SuggestionSources\SuggestionSourceFactory.cs" />
<Compile Include="WebSearch.cs" />
<Compile Include="WebSearchesSetting.xaml.cs"> <Compile Include="WebSearchesSetting.xaml.cs">
<DependentUpon>WebSearchesSetting.xaml</DependentUpon> <DependentUpon>WebSearchesSetting.xaml</DependentUpon>
</Compile> </Compile>
@@ -63,6 +64,7 @@
<Compile Include="WebSearchSetting.xaml.cs"> <Compile Include="WebSearchSetting.xaml.cs">
<DependentUpon>WebSearchSetting.xaml</DependentUpon> <DependentUpon>WebSearchSetting.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="WebSearchStorage.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="Languages\en.xaml"> <Content Include="Languages\en.xaml">

View File

@@ -121,13 +121,10 @@ namespace Wox.Core.Plugin
public static bool IsUserPluginQuery(Query query) public static bool IsUserPluginQuery(Query query)
{ {
if (string.IsNullOrEmpty(query.RawQuery)) return false; if (string.IsNullOrEmpty(query.RawQuery)) return false;
var strings = query.RawQuery.Split(' '); var strings = query.RawQuery.Split(' ');
var actionKeyword = string.Empty; if(strings.Length == 1) return false;
if (strings.Length > 0)
{ var actionKeyword = strings[0].Trim();
actionKeyword = strings[0].Trim();
}
if (string.IsNullOrEmpty(actionKeyword)) return false; if (string.IsNullOrEmpty(actionKeyword)) return false;
return plugins.Any(o => o.Metadata.PluginType == PluginType.User && o.Metadata.ActionKeyword == actionKeyword); return plugins.Any(o => o.Metadata.PluginType == PluginType.User && o.Metadata.ActionKeyword == actionKeyword);

View File

@@ -55,9 +55,6 @@ namespace Wox.Core.UserSettings
[JsonProperty] [JsonProperty]
public string ResultItemFontStretch { get; set; } public string ResultItemFontStretch { get; set; }
[JsonProperty]
public List<WebSearch> WebSearches { get; set; }
[JsonProperty] [JsonProperty]
public double WindowLeft { get; set; } public double WindowLeft { get; set; }
@@ -72,18 +69,14 @@ namespace Wox.Core.UserSettings
[JsonProperty] [JsonProperty]
public bool StartWoxOnSystemStartup { get; set; } public bool StartWoxOnSystemStartup { get; set; }
[Obsolete]
[JsonProperty] [JsonProperty]
public double Opacity { get; set; } public double Opacity { get; set; }
[Obsolete]
[JsonProperty] [JsonProperty]
public OpacityMode OpacityMode { get; set; } public OpacityMode OpacityMode { get; set; }
[JsonProperty]
public bool EnableWebSearchSuggestion { get; set; }
[JsonProperty]
public string WebSearchSuggestionSource { get; set; }
[JsonProperty] [JsonProperty]
public bool LeaveCmdOpen { get; set; } public bool LeaveCmdOpen { get; set; }
@@ -105,44 +98,6 @@ namespace Wox.Core.UserSettings
[JsonProperty] [JsonProperty]
public string ProxyPassword { get; set; } public string ProxyPassword { get; set; }
public List<WebSearch> LoadDefaultWebSearches()
{
List<WebSearch> webSearches = new List<WebSearch>();
WebSearch googleWebSearch = new WebSearch()
{
Title = "Google",
ActionWord = "g",
IconPath = Path.GetDirectoryName(Application.ExecutablePath) + @"\Images\websearch\google.png",
Url = "https://www.google.com/search?q={q}",
Enabled = true
};
webSearches.Add(googleWebSearch);
WebSearch wikiWebSearch = new WebSearch()
{
Title = "Wikipedia",
ActionWord = "wiki",
IconPath = Path.GetDirectoryName(Application.ExecutablePath) + @"\Images\websearch\wiki.png",
Url = "http://en.wikipedia.org/wiki/{q}",
Enabled = true
};
webSearches.Add(wikiWebSearch);
WebSearch findIcon = new WebSearch()
{
Title = "FindIcon",
ActionWord = "findicon",
IconPath = Path.GetDirectoryName(Application.ExecutablePath) + @"\Images\websearch\pictures.png",
Url = "http://findicons.com/search/{q}",
Enabled = true
};
webSearches.Add(findIcon);
return webSearches;
}
protected override string ConfigFolder protected override string ConfigFolder
{ {
get { return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Config"); } get { return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Config"); }
@@ -167,7 +122,6 @@ namespace Wox.Core.UserSettings
DontPromptUpdateMsg = false; DontPromptUpdateMsg = false;
Theme = "Dark"; Theme = "Dark";
Language = "en"; Language = "en";
WebSearches = LoadDefaultWebSearches();
CustomizedPluginConfigs = new List<CustomizedPluginConfig>(); CustomizedPluginConfigs = new List<CustomizedPluginConfig>();
Hotkey = "Alt + Space"; Hotkey = "Alt + Space";
QueryBoxFont = FontFamily.GenericSansSerif.Name; QueryBoxFont = FontFamily.GenericSansSerif.Name;

View File

@@ -99,7 +99,6 @@
<Compile Include="UserSettings\CustomizedPluginConfig.cs" /> <Compile Include="UserSettings\CustomizedPluginConfig.cs" />
<Compile Include="UserSettings\PluginHotkey.cs" /> <Compile Include="UserSettings\PluginHotkey.cs" />
<Compile Include="UserSettings\UserSettingStorage.cs" /> <Compile Include="UserSettings\UserSettingStorage.cs" />
<Compile Include="UserSettings\WebSearch.cs" />
<Compile Include="Version\SemanticVersion.cs" /> <Compile Include="Version\SemanticVersion.cs" />
<Compile Include="Version\VersionManager.cs" /> <Compile Include="Version\VersionManager.cs" />
</ItemGroup> </ItemGroup>

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using NUnit.Framework; using NUnit.Framework;
using Wox.Core.Plugin;
using Wox.Plugin; using Wox.Plugin;
namespace Wox.Test namespace Wox.Test

View File

@@ -13,12 +13,11 @@
AllowDrop="True" AllowDrop="True"
ShowInTaskbar="False" ShowInTaskbar="False"
Style="{DynamicResource WindowStyle}" Style="{DynamicResource WindowStyle}"
Icon="Images\app.png" Icon="Images\app.png">
>
<Window.Resources> <Window.Resources>
<ResourceDictionary Source="/PresentationFramework.Classic,Version=3.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35,processorArchitecture=MSIL;component/themes/Classic.xaml"/> <ResourceDictionary Source="/PresentationFramework.Classic,Version=3.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35,processorArchitecture=MSIL;component/themes/Classic.xaml"/>
</Window.Resources> </Window.Resources>
<Border Style="{DynamicResource WindowBorderStyle}" MouseDown="Border_OnMouseDown" CornerRadius="0"> <Border Style="{DynamicResource WindowBorderStyle}" MouseDown="Border_OnMouseDown">
<StackPanel Orientation="Vertical"> <StackPanel Orientation="Vertical">
<TextBox Style="{DynamicResource QueryBoxStyle}" PreviewDragOver="TbQuery_OnPreviewDragOver" AllowDrop="True" <TextBox Style="{DynamicResource QueryBoxStyle}" PreviewDragOver="TbQuery_OnPreviewDragOver" AllowDrop="True"
x:Name="tbQuery" PreviewKeyDown="TbQuery_OnPreviewKeyDown" TextChanged="TextBoxBase_OnTextChanged" /> x:Name="tbQuery" PreviewKeyDown="TbQuery_OnPreviewKeyDown" TextChanged="TextBoxBase_OnTextChanged" />

View File

@@ -162,10 +162,6 @@ namespace Wox
InitializeComponent(); InitializeComponent();
ThreadPool.SetMaxThreads(30, 10); ThreadPool.SetMaxThreads(30, 10);
ThreadPool.SetMinThreads(10, 5); ThreadPool.SetMinThreads(10, 5);
if (UserSettingStorage.Instance.OpacityMode == OpacityMode.LayeredWindow)
{
this.AllowsTransparency = true;
}
WebRequest.RegisterPrefix("data", new DataWebRequestFactory()); WebRequest.RegisterPrefix("data", new DataWebRequestFactory());
GlobalHotkey.Instance.hookedKeyboardCallback += KListener_hookedKeyboardCallback; GlobalHotkey.Instance.hookedKeyboardCallback += KListener_hookedKeyboardCallback;
@@ -241,14 +237,6 @@ namespace Wox
} }
InitProgressbarAnimation(); InitProgressbarAnimation();
//only works for win7+
if (UserSettingStorage.Instance.OpacityMode == OpacityMode.DWM)
DwmDropShadow.DropShadowToWindow(this);
this.Background = Brushes.Transparent;
HwndSource.FromHwnd(new WindowInteropHelper(this).Handle).CompositionTarget.BackgroundColor = Color.FromArgb(0, 0, 0, 0);
WindowIntelopHelper.DisableControlBox(this); WindowIntelopHelper.DisableControlBox(this);
UpdaterManager.Instance.CheckUpdate(); UpdaterManager.Instance.CheckUpdate();
} }
@@ -354,7 +342,7 @@ namespace Wox
Query(q); Query(q);
Dispatcher.DelayInvoke("ShowProgressbar", originQuery => Dispatcher.DelayInvoke("ShowProgressbar", originQuery =>
{ {
if (!queryHasReturn && originQuery == lastQuery) if (!queryHasReturn && originQuery == lastQuery && !string.IsNullOrEmpty(lastQuery))
{ {
StartProgress(); StartProgress();
} }