2014-01-28 03:19:27 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Data;
|
|
|
|
|
using System.Windows.Documents;
|
2014-02-02 08:15:34 +00:00
|
|
|
|
using System.Windows.Forms;
|
2014-01-28 03:19:27 +00:00
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
using System.Windows.Media.Imaging;
|
|
|
|
|
using System.Windows.Shapes;
|
2014-01-29 14:44:57 +00:00
|
|
|
|
using Wox.Helper;
|
|
|
|
|
using Wox.Infrastructure;
|
|
|
|
|
using Wox.Infrastructure.UserSettings;
|
2014-02-02 08:15:34 +00:00
|
|
|
|
using MessageBox = System.Windows.MessageBox;
|
2014-01-28 03:19:27 +00:00
|
|
|
|
|
2014-01-29 10:33:24 +00:00
|
|
|
|
namespace Wox
|
2014-01-28 03:19:27 +00:00
|
|
|
|
{
|
|
|
|
|
public partial class WebSearchSetting : Window
|
|
|
|
|
{
|
2014-02-02 08:15:34 +00:00
|
|
|
|
private SettingWidow settingWidow;
|
|
|
|
|
private bool update;
|
|
|
|
|
private WebSearch updateWebSearch;
|
|
|
|
|
|
|
|
|
|
public WebSearchSetting(SettingWidow settingWidow)
|
2014-01-28 03:19:27 +00:00
|
|
|
|
{
|
2014-02-02 08:15:34 +00:00
|
|
|
|
this.settingWidow = settingWidow;
|
2014-01-28 03:19:27 +00:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-02 08:15:34 +00:00
|
|
|
|
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";
|
2014-02-06 14:22:02 +00:00
|
|
|
|
tbIconPath.Text = webSearch.IconPath;
|
|
|
|
|
ShowIcon(webSearch.IconPath);
|
2014-02-02 08:15:34 +00:00
|
|
|
|
cbEnable.IsChecked = webSearch.Enabled;
|
|
|
|
|
tbTitle.Text = webSearch.Title;
|
|
|
|
|
tbUrl.Text = webSearch.Url;
|
|
|
|
|
tbActionword.Text = webSearch.ActionWord;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-06 14:22:02 +00:00
|
|
|
|
private void ShowIcon(string path)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
imgIcon.Source = new BitmapImage(new Uri(path));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 03:19:27 +00:00
|
|
|
|
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
2014-01-29 14:44:57 +00:00
|
|
|
|
|
|
|
|
|
private void btnAdd_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
string title = tbTitle.Text;
|
|
|
|
|
if (string.IsNullOrEmpty(title))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Please input Title field");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string url = tbUrl.Text;
|
|
|
|
|
if (string.IsNullOrEmpty(url))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Please input URL field");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string action = tbActionword.Text;
|
|
|
|
|
if (string.IsNullOrEmpty(action))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Please input ActionWord field");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-02-02 08:15:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!update)
|
2014-01-29 14:44:57 +00:00
|
|
|
|
{
|
2014-02-02 08:15:34 +00:00
|
|
|
|
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,
|
2014-02-06 14:22:02 +00:00
|
|
|
|
IconPath = tbIconPath.Text,
|
2014-02-02 08:15:34 +00:00
|
|
|
|
Url = url,
|
|
|
|
|
Title = title
|
|
|
|
|
});
|
|
|
|
|
MessageBox.Show(string.Format("Add {0} web search successfully!", title));
|
2014-01-29 14:44:57 +00:00
|
|
|
|
}
|
2014-02-02 08:15:34 +00:00
|
|
|
|
else
|
2014-01-29 14:44:57 +00:00
|
|
|
|
{
|
2014-02-02 08:15:34 +00:00
|
|
|
|
updateWebSearch.ActionWord = action;
|
2014-02-06 14:22:02 +00:00
|
|
|
|
updateWebSearch.IconPath = tbIconPath.Text;
|
2014-02-02 08:15:34 +00:00
|
|
|
|
updateWebSearch.Enabled = cbEnable.IsChecked ?? false;
|
|
|
|
|
updateWebSearch.Url = url;
|
|
|
|
|
updateWebSearch.Title= title;
|
|
|
|
|
MessageBox.Show(string.Format("Update {0} web search successfully!", title));
|
|
|
|
|
}
|
2014-01-29 14:44:57 +00:00
|
|
|
|
CommonStorage.Instance.Save();
|
2014-02-02 08:15:34 +00:00
|
|
|
|
settingWidow.ReloadWebSearchView();
|
|
|
|
|
Close();
|
2014-01-29 14:44:57 +00:00
|
|
|
|
}
|
2014-02-06 14:22:02 +00:00
|
|
|
|
|
|
|
|
|
private void BtnSelectIcon_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var dlg = new Microsoft.Win32.OpenFileDialog
|
|
|
|
|
{
|
|
|
|
|
DefaultExt = ".png",
|
|
|
|
|
Filter =
|
|
|
|
|
"JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bool? result = dlg.ShowDialog();
|
|
|
|
|
if (result == true)
|
|
|
|
|
{
|
|
|
|
|
string filename = dlg.FileName;
|
|
|
|
|
tbIconPath.Text = filename;
|
|
|
|
|
ShowIcon(filename);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-28 03:19:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|