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()
{
Title = n.ActionWord,
SubTitle = string.Format("Activate {0} web search", n.ActionWord),
Score = 100,
IcoPath = "Images/work.png",
Action = (c) =>
{
context.API.ChangeQuery(n.ActionWord + " ");
return false;
}
}));
//results.AddRange(UserSettingStorage.Instance.WebSearches.Where(o => o.ActionWord.StartsWith(query.Search) && o.Enabled).Select(n => new Result()
//{
// Title = n.ActionWord,
// SubTitle = string.Format("Activate {0} web search", n.ActionWord),
// Score = 100,
// IcoPath = "Images/work.png",
// Action = (c) =>
// {
// context.API.ChangeQuery(n.ActionWord + " ");
// return false;
// }
//}));
return results;
}

View File

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

View File

@ -17,8 +17,8 @@ namespace Wox.Plugin.WebSearch
{
List<Result> results = new List<Result>();
Core.UserSettings.WebSearch webSearch =
UserSettingStorage.Instance.WebSearches.FirstOrDefault(o => o.ActionWord == query.FirstSearch.Trim() && o.Enabled);
WebSearch webSearch =
WebSearchStorage.Instance.WebSearches.FirstOrDefault(o => o.ActionWord == query.FirstSearch.Trim() && o.Enabled);
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(
UserSettingStorage.Instance.WebSearchSuggestionSource);
WebSearchStorage.Instance.WebSearchSuggestionSource);
if (sugg != null)
{
var result = sugg.GetSuggestions(keyword);
@ -80,8 +80,8 @@ namespace Wox.Plugin.WebSearch
{
this.context = context;
if (UserSettingStorage.Instance.WebSearches == null)
UserSettingStorage.Instance.WebSearches = UserSettingStorage.Instance.LoadDefaultWebSearches();
if (WebSearchStorage.Instance.WebSearches == null)
WebSearchStorage.Instance.WebSearches = WebSearchStorage.Instance.LoadDefaultWebSearches();
}
#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 WebSearchesSetting settingWindow;
private bool update;
private Core.UserSettings.WebSearch updateWebSearch;
private WebSearch updateWebSearch;
private PluginInitContext context;
public WebSearchSetting(WebSearchesSetting settingWidow,PluginInitContext context)
@ -24,9 +24,9 @@ namespace Wox.Plugin.WebSearch
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))
{
@ -91,13 +91,13 @@ namespace Wox.Plugin.WebSearch
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");
MessageBox.Show(warning);
return;
}
UserSettingStorage.Instance.WebSearches.Add(new Core.UserSettings.WebSearch()
WebSearchStorage.Instance.WebSearches.Add(new WebSearch()
{
ActionWord = action,
Enabled = cbEnable.IsChecked ?? false,
@ -110,7 +110,7 @@ namespace Wox.Plugin.WebSearch
}
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");
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)
{
webSearchView.ItemsSource = UserSettingStorage.Instance.WebSearches;
cbEnableWebSearchSuggestion.IsChecked = UserSettingStorage.Instance.EnableWebSearchSuggestion;
comboBoxSuggestionSource.Visibility = UserSettingStorage.Instance.EnableWebSearchSuggestion
webSearchView.ItemsSource = WebSearchStorage.Instance.WebSearches;
cbEnableWebSearchSuggestion.IsChecked = WebSearchStorage.Instance.EnableWebSearchSuggestion;
comboBoxSuggestionSource.Visibility = WebSearchStorage.Instance.EnableWebSearchSuggestion
? Visibility.Visible
: Visibility.Collapsed;
@ -35,7 +35,7 @@ namespace Wox.Plugin.WebSearch
new ComboBoxItem() {Content = "Google"},
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)
{
selected = items[0];
@ -58,14 +58,14 @@ namespace Wox.Plugin.WebSearch
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)
{
string msg = string.Format(context.API.GetTranslation("wox_plugin_websearch_delete_warning"),selectedWebSearch.Title);
if (MessageBox.Show(msg,string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
UserSettingStorage.Instance.WebSearches.Remove(selectedWebSearch);
WebSearchStorage.Instance.WebSearches.Remove(selectedWebSearch);
webSearchView.Items.Refresh();
}
}
@ -78,7 +78,7 @@ namespace Wox.Plugin.WebSearch
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)
{
WebSearchSetting webSearch = new WebSearchSetting(this,context);
@ -95,23 +95,22 @@ namespace Wox.Plugin.WebSearch
private void CbEnableWebSearchSuggestion_OnChecked(object sender, RoutedEventArgs e)
{
comboBoxSuggestionSource.Visibility = Visibility.Visible;
UserSettingStorage.Instance.EnableWebSearchSuggestion = true;
UserSettingStorage.Instance.Save();
WebSearchStorage.Instance.EnableWebSearchSuggestion = true;
WebSearchStorage.Instance.Save();
}
private void CbEnableWebSearchSuggestion_OnUnchecked(object sender, RoutedEventArgs e)
{
comboBoxSuggestionSource.Visibility = Visibility.Collapsed;
UserSettingStorage.Instance.EnableWebSearchSuggestion = false;
UserSettingStorage.Instance.Save();
WebSearchStorage.Instance.EnableWebSearchSuggestion = false;
WebSearchStorage.Instance.Save();
}
private void ComboBoxSuggestionSource_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count > 0)
{
UserSettingStorage.Instance.WebSearchSuggestionSource =
((ComboBoxItem) e.AddedItems[0]).Content.ToString();
WebSearchStorage.Instance.WebSearchSuggestionSource = ((ComboBoxItem) e.AddedItems[0]).Content.ToString();
UserSettingStorage.Instance.Save();
}
}

View File

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

View File

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

View File

@ -55,9 +55,6 @@ namespace Wox.Core.UserSettings
[JsonProperty]
public string ResultItemFontStretch { get; set; }
[JsonProperty]
public List<WebSearch> WebSearches { get; set; }
[JsonProperty]
public double WindowLeft { get; set; }
@ -72,18 +69,14 @@ namespace Wox.Core.UserSettings
[JsonProperty]
public bool StartWoxOnSystemStartup { get; set; }
[Obsolete]
[JsonProperty]
public double Opacity { get; set; }
[Obsolete]
[JsonProperty]
public OpacityMode OpacityMode { get; set; }
[JsonProperty]
public bool EnableWebSearchSuggestion { get; set; }
[JsonProperty]
public string WebSearchSuggestionSource { get; set; }
[JsonProperty]
public bool LeaveCmdOpen { get; set; }
@ -105,44 +98,6 @@ namespace Wox.Core.UserSettings
[JsonProperty]
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
{
get { return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Config"); }
@ -167,7 +122,6 @@ namespace Wox.Core.UserSettings
DontPromptUpdateMsg = false;
Theme = "Dark";
Language = "en";
WebSearches = LoadDefaultWebSearches();
CustomizedPluginConfigs = new List<CustomizedPluginConfig>();
Hotkey = "Alt + Space";
QueryBoxFont = FontFamily.GenericSansSerif.Name;

View File

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

View File

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

View File

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

View File

@ -162,10 +162,6 @@ namespace Wox
InitializeComponent();
ThreadPool.SetMaxThreads(30, 10);
ThreadPool.SetMinThreads(10, 5);
if (UserSettingStorage.Instance.OpacityMode == OpacityMode.LayeredWindow)
{
this.AllowsTransparency = true;
}
WebRequest.RegisterPrefix("data", new DataWebRequestFactory());
GlobalHotkey.Instance.hookedKeyboardCallback += KListener_hookedKeyboardCallback;
@ -241,14 +237,6 @@ namespace Wox
}
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);
UpdaterManager.Instance.CheckUpdate();
}
@ -354,7 +342,7 @@ namespace Wox
Query(q);
Dispatcher.DelayInvoke("ShowProgressbar", originQuery =>
{
if (!queryHasReturn && originQuery == lastQuery)
if (!queryHasReturn && originQuery == lastQuery && !string.IsNullOrEmpty(lastQuery))
{
StartProgress();
}