Implement WebSearch feature.

This commit is contained in:
qianlifeng
2014-02-02 16:15:34 +08:00
parent 76fa97e0a0
commit 495e0ce89b
8 changed files with 122 additions and 42 deletions

View File

@@ -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();
}
}
}