diff --git a/Wox.Infrastructure/CommonStorage.cs b/Wox.Infrastructure/CommonStorage.cs index cfd671ed01..3a4dfa88c9 100644 --- a/Wox.Infrastructure/CommonStorage.cs +++ b/Wox.Infrastructure/CommonStorage.cs @@ -47,9 +47,21 @@ namespace Wox.Infrastructure } catch (Exception e) { - //on-op, keep default storage + LoadDefaultUserSetting(); } } + else + { + LoadDefaultUserSetting(); + } + } + + private static void LoadDefaultUserSetting() + { + //default setting + Instance.UserSetting.Theme = "Default"; + Instance.UserSetting.ReplaceWinR = true; + Instance.UserSetting.WebSearches = Instance.UserSetting.LoadDefaultWebSearches(); } public static CommonStorage Instance @@ -70,6 +82,5 @@ namespace Wox.Infrastructure return storage; } } - } } \ No newline at end of file diff --git a/Wox.Infrastructure/UserSettings/UserSetting.cs b/Wox.Infrastructure/UserSettings/UserSetting.cs index d6f8510ef5..79528a67b7 100644 --- a/Wox.Infrastructure/UserSettings/UserSetting.cs +++ b/Wox.Infrastructure/UserSettings/UserSetting.cs @@ -9,15 +9,7 @@ namespace Wox.Infrastructure.UserSettings public bool ReplaceWinR { get; set; } public List WebSearches { get; set; } - public UserSetting() - { - //default setting - Theme = "Default"; - ReplaceWinR = true; - WebSearches = LoadDefaultWebSearches(); - } - - private List LoadDefaultWebSearches() + public List LoadDefaultWebSearches() { List webSearches = new List(); diff --git a/Wox.Plugin.System/ThirdpartyPluginIndicator.cs b/Wox.Plugin.System/ThirdpartyPluginIndicator.cs index 406ef1b81c..363042102c 100644 --- a/Wox.Plugin.System/ThirdpartyPluginIndicator.cs +++ b/Wox.Plugin.System/ThirdpartyPluginIndicator.cs @@ -34,11 +34,10 @@ namespace Wox.Plugin.System } } - results.AddRange(CommonStorage.Instance.UserSetting.WebSearches.Where(o => o.ActionWord.StartsWith(query.RawQuery)).Select(n => new Result() + results.AddRange(CommonStorage.Instance.UserSetting.WebSearches.Where(o => o.ActionWord.StartsWith(query.RawQuery) && o.Enabled).Select(n => new Result() { - Title = n.ActionWord, - SubTitle = string.Format("Activate {0} plugin", n.ActionWord), + SubTitle = string.Format("Activate {0} web search", n.ActionWord), Score = 50, IcoPath = "Images/work.png", Action = () => changeQuery(n.ActionWord + " "), diff --git a/Wox.Plugin.System/WebSearchPlugin.cs b/Wox.Plugin.System/WebSearchPlugin.cs index bbfc859159..35049201af 100644 --- a/Wox.Plugin.System/WebSearchPlugin.cs +++ b/Wox.Plugin.System/WebSearchPlugin.cs @@ -17,14 +17,14 @@ namespace Wox.Plugin.System if (string.IsNullOrEmpty(query.ActionName)) return results; WebSearch webSearch = - CommonStorage.Instance.UserSetting.WebSearches.FirstOrDefault(o => o.ActionWord == query.ActionName); + CommonStorage.Instance.UserSetting.WebSearches.FirstOrDefault(o => o.ActionWord == query.ActionName && o.Enabled); if (webSearch != null) { string keyword = query.ActionParameters.Count > 0 ? query.RawQuery.Substring(query.RawQuery.IndexOf(' ') + 1) : ""; results.Add(new Result() { - Title = string.Format("Search {0} for {1}", webSearch.Title, keyword), + Title = string.Format("Search {0} for \"{1}\"", webSearch.Title, keyword), IcoPath = webSearch.IconPath, Action = () => Process.Start(webSearch.Url.Replace("{q}", keyword)) }); diff --git a/Wox/SettingWindow.xaml b/Wox/SettingWindow.xaml index 6a5bd51cfb..ea3d4fd79b 100644 --- a/Wox/SettingWindow.xaml +++ b/Wox/SettingWindow.xaml @@ -44,18 +44,15 @@ - - - - - - - - + + + + + diff --git a/Wox/SettingWindow.xaml.cs b/Wox/SettingWindow.xaml.cs index 91f05bdca6..955ea0d22e 100644 --- a/Wox/SettingWindow.xaml.cs +++ b/Wox/SettingWindow.xaml.cs @@ -5,6 +5,7 @@ using System.Windows; using System.Windows.Controls; using Wox.Helper; using Wox.Infrastructure; +using Wox.Infrastructure.UserSettings; namespace Wox { @@ -42,6 +43,11 @@ namespace Wox webSearchView.ItemsSource = CommonStorage.Instance.UserSetting.WebSearches; } + public void ReloadWebSearchView() + { + webSearchView.Items.Refresh(); + } + private List LoadAvailableThemes() { string themePath = Directory.GetCurrentDirectory() + "\\Themes\\"; @@ -56,10 +62,41 @@ namespace Wox CommonStorage.Instance.Save(); } - private void ButtonBase_OnClick(object sender, RoutedEventArgs e) + private void btnAddWebSearch_OnClick(object sender, RoutedEventArgs e) { - WebSearchSetting webSearch = new WebSearchSetting(); + WebSearchSetting webSearch = new WebSearchSetting(this); webSearch.Show(); } + + private void btnDeleteWebSearch_OnClick(object sender, RoutedEventArgs e) + { + WebSearch seletedWebSearch = webSearchView.SelectedItem as WebSearch; + if (seletedWebSearch != null && + MessageBox.Show("Are your sure to delete " + seletedWebSearch.Title, "Delete WebSearch", + MessageBoxButton.YesNo) == MessageBoxResult.Yes) + { + CommonStorage.Instance.UserSetting.WebSearches.Remove(seletedWebSearch); + webSearchView.Items.Refresh(); + } + else + { + MessageBox.Show("Please select a web search"); + } + } + + private void btnEditWebSearch_OnClick(object sender, RoutedEventArgs e) + { + WebSearch seletedWebSearch = webSearchView.SelectedItem as WebSearch; + if (seletedWebSearch != null) + { + WebSearchSetting webSearch = new WebSearchSetting(this); + webSearch.Show(); + webSearch.UpdateItem(seletedWebSearch); + } + else + { + MessageBox.Show("Please select a web search"); + } + } } } diff --git a/Wox/WebSearchSetting.xaml b/Wox/WebSearchSetting.xaml index ab9f36be0e..39465b19b5 100644 --- a/Wox/WebSearchSetting.xaml +++ b/Wox/WebSearchSetting.xaml @@ -11,6 +11,7 @@ + @@ -25,9 +26,12 @@ ActionWord: - + Enable: + + + - + diff --git a/Wox/WebSearchSetting.xaml.cs b/Wox/WebSearchSetting.xaml.cs index b094da3dca..7483bf792c 100644 --- a/Wox/WebSearchSetting.xaml.cs +++ b/Wox/WebSearchSetting.xaml.cs @@ -6,6 +6,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; +using System.Windows.Forms; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; @@ -13,16 +14,40 @@ using System.Windows.Shapes; using Wox.Helper; using Wox.Infrastructure; using Wox.Infrastructure.UserSettings; +using MessageBox = System.Windows.MessageBox; namespace Wox { public partial class WebSearchSetting : Window { - public WebSearchSetting() + private SettingWidow settingWidow; + private bool update; + private WebSearch updateWebSearch; + + public WebSearchSetting(SettingWidow settingWidow) { + this.settingWidow = settingWidow; InitializeComponent(); } + public void UpdateItem(WebSearch webSearch) + { + updateWebSearch = CommonStorage.Instance.UserSetting.WebSearches.FirstOrDefault(o => o == webSearch); + if (updateWebSearch == null || string.IsNullOrEmpty(updateWebSearch.Url)) + { + MessageBox.Show("Invalid web search"); + Close(); + return; + } + + update = true; + lblAdd.Text = "Update"; + cbEnable.IsChecked = webSearch.Enabled; + tbTitle.Text = webSearch.Title; + tbUrl.Text = webSearch.Url; + tbActionword.Text = webSearch.ActionWord; + } + private void BtnCancel_OnClick(object sender, RoutedEventArgs e) { Close(); @@ -50,22 +75,37 @@ namespace Wox MessageBox.Show("Please input ActionWord field"); return; } - if (CommonStorage.Instance.UserSetting.WebSearches.Exists(o => o.ActionWord == action)) - { - MessageBox.Show("ActionWord has existed, please input a new one."); - return; - } - CommonStorage.Instance.UserSetting.WebSearches.Add(new WebSearch() + + if (!update) { - ActionWord = action, - Enabled = true, - IconPath="", - Url = url, - Title = title - }); + if (CommonStorage.Instance.UserSetting.WebSearches.Exists(o => o.ActionWord == action)) + { + MessageBox.Show("ActionWord has existed, please input a new one."); + return; + } + CommonStorage.Instance.UserSetting.WebSearches.Add(new WebSearch() + { + ActionWord = action, + Enabled = cbEnable.IsChecked ?? false, + IconPath = "", + Url = url, + Title = title + }); + MessageBox.Show(string.Format("Add {0} web search successfully!", title)); + } + else + { + updateWebSearch.ActionWord = action; + updateWebSearch.IconPath = ""; + updateWebSearch.Enabled = cbEnable.IsChecked ?? false; + updateWebSearch.Url = url; + updateWebSearch.Title= title; + MessageBox.Show(string.Format("Update {0} web search successfully!", title)); + } CommonStorage.Instance.Save(); - MessageBox.Show("Succeed!"); + settingWidow.ReloadWebSearchView(); + Close(); } } }