PowerToys/Wox/SettingWindow.xaml.cs

822 lines
32 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
2014-07-04 15:12:22 +08:00
using System.Diagnostics;
using System.IO;
using System.Linq;
2014-07-18 20:00:55 +08:00
using System.Net;
using System.Windows;
using System.Windows.Controls;
2015-10-31 07:17:34 +08:00
using System.Windows.Data;
using System.Windows.Input;
2014-03-19 22:17:01 +08:00
using System.Windows.Media;
using System.Windows.Media.Imaging;
2015-01-14 22:19:44 +08:00
using Microsoft.Win32;
2015-01-02 23:07:49 +08:00
using Wox.Core.i18n;
2015-10-31 07:17:34 +08:00
using Wox.Core.Plugin;
2015-01-02 23:07:49 +08:00
using Wox.Core.Theme;
2015-01-27 21:51:29 +08:00
using Wox.Core.Updater;
using Wox.Core.UserSettings;
2015-10-31 07:17:34 +08:00
using Wox.Helper;
using Wox.Infrastructure;
2015-10-31 07:17:34 +08:00
using Wox.Plugin;
using Application = System.Windows.Forms.Application;
using Stopwatch = Wox.Infrastructure.Stopwatch;
2014-01-29 18:33:24 +08:00
namespace Wox
{
2014-03-20 02:26:00 +08:00
public partial class SettingWindow : Window
{
2015-02-07 21:27:48 +08:00
public readonly MainWindow MainWindow;
2014-06-30 21:31:13 +08:00
bool settingsLoaded = false;
private Dictionary<ISettingProvider, Control> featureControls = new Dictionary<ISettingProvider, Control>();
2015-02-07 21:27:48 +08:00
private bool themeTabLoaded = false;
2014-03-20 02:26:00 +08:00
public SettingWindow(MainWindow mainWindow)
{
2014-02-22 15:52:20 +08:00
this.MainWindow = mainWindow;
InitializeComponent();
Loaded += Setting_Loaded;
2014-02-22 15:52:20 +08:00
}
private void Setting_Loaded(object sender, RoutedEventArgs ev)
{
2014-12-14 23:16:29 +08:00
#region General
2014-04-13 10:08:33 +08:00
cbHideWhenDeactive.Checked += (o, e) =>
{
UserSettingStorage.Instance.HideWhenDeactive = true;
UserSettingStorage.Instance.Save();
};
cbHideWhenDeactive.Unchecked += (o, e) =>
{
UserSettingStorage.Instance.HideWhenDeactive = false;
UserSettingStorage.Instance.Save();
};
2015-02-20 21:45:42 +08:00
cbRememberLastLocation.Checked += (o, e) =>
{
UserSettingStorage.Instance.RememberLastLaunchLocation = true;
UserSettingStorage.Instance.Save();
};
cbRememberLastLocation.Unchecked += (o, e) =>
{
UserSettingStorage.Instance.RememberLastLaunchLocation = false;
UserSettingStorage.Instance.Save();
};
2014-12-14 23:16:29 +08:00
cbDontPromptUpdateMsg.Checked += (o, e) =>
{
UserSettingStorage.Instance.DontPromptUpdateMsg = true;
UserSettingStorage.Instance.Save();
};
cbDontPromptUpdateMsg.Unchecked += (o, e) =>
{
UserSettingStorage.Instance.DontPromptUpdateMsg = false;
UserSettingStorage.Instance.Save();
};
cbIgnoreHotkeysOnFullscreen.Checked += (o, e) =>
{
UserSettingStorage.Instance.IgnoreHotkeysOnFullscreen = true;
UserSettingStorage.Instance.Save();
};
cbIgnoreHotkeysOnFullscreen.Unchecked += (o, e) =>
{
UserSettingStorage.Instance.IgnoreHotkeysOnFullscreen = false;
UserSettingStorage.Instance.Save();
};
2015-01-14 22:19:44 +08:00
cbStartWithWindows.IsChecked = CheckApplicationIsStartupWithWindow();
comboMaxResultsToShow.SelectionChanged += (o, e) =>
{
UserSettingStorage.Instance.MaxResultsToShow = (int)comboMaxResultsToShow.SelectedItem;
UserSettingStorage.Instance.Save();
MainWindow.pnlResult.lbResults.GetBindingExpression(MaxHeightProperty).UpdateTarget();
};
2014-06-30 21:31:13 +08:00
cbHideWhenDeactive.IsChecked = UserSettingStorage.Instance.HideWhenDeactive;
2014-12-14 23:16:29 +08:00
cbDontPromptUpdateMsg.IsChecked = UserSettingStorage.Instance.DontPromptUpdateMsg;
2015-02-20 21:45:42 +08:00
cbRememberLastLocation.IsChecked = UserSettingStorage.Instance.RememberLastLaunchLocation;
cbIgnoreHotkeysOnFullscreen.IsChecked = UserSettingStorage.Instance.IgnoreHotkeysOnFullscreen;
2014-06-30 21:31:13 +08:00
2015-01-02 16:16:09 +08:00
LoadLanguages();
comboMaxResultsToShow.ItemsSource = Enumerable.Range(2, 16);
var maxResults = UserSettingStorage.Instance.MaxResultsToShow;
comboMaxResultsToShow.SelectedItem = maxResults == 0 ? 6 : maxResults;
2015-01-02 16:16:09 +08:00
2014-12-14 23:16:29 +08:00
#endregion
2014-07-18 20:00:55 +08:00
#region Proxy
cbEnableProxy.Checked += (o, e) => EnableProxy();
cbEnableProxy.Unchecked += (o, e) => DisableProxy();
cbEnableProxy.IsChecked = UserSettingStorage.Instance.ProxyEnabled;
tbProxyServer.Text = UserSettingStorage.Instance.ProxyServer;
if (UserSettingStorage.Instance.ProxyPort != 0)
{
2015-08-27 19:38:07 +08:00
tbProxyPort.Text = UserSettingStorage.Instance.ProxyPort.ToString();
}
2014-07-18 20:00:55 +08:00
tbProxyUserName.Text = UserSettingStorage.Instance.ProxyUserName;
tbProxyPassword.Password = UserSettingStorage.Instance.ProxyPassword;
if (UserSettingStorage.Instance.ProxyEnabled)
{
EnableProxy();
}
else
{
DisableProxy();
}
#endregion
2014-12-16 22:25:22 +08:00
#region About
2015-01-27 21:51:29 +08:00
tbVersion.Text = UpdaterManager.Instance.CurrentVersion.ToString();
2015-01-23 21:52:46 +08:00
string activateTimes = string.Format(InternationalizationManager.Instance.GetTranslation("about_activate_times"),
UserSettingStorage.Instance.ActivateTimes);
tbActivatedTimes.Text = activateTimes;
2014-12-16 22:25:22 +08:00
#endregion
settingsLoaded = true;
}
2015-02-21 21:57:00 +08:00
public void SwitchTo(string tabName)
{
switch (tabName)
{
case "general":
settingTab.SelectedIndex = 0;
break;
case "plugin":
settingTab.SelectedIndex = 1;
break;
case "theme":
settingTab.SelectedIndex = 2;
break;
case "hotkey":
settingTab.SelectedIndex = 3;
break;
case "proxy":
settingTab.SelectedIndex = 4;
break;
case "about":
settingTab.SelectedIndex = 5;
break;
}
}
private void settingTab_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// Update controls inside the selected tab
if (e.OriginalSource != settingTab) return;
if (tabPlugin.IsSelected)
{
OnPluginTabSelected();
}
else if (tabTheme.IsSelected)
{
OnThemeTabSelected();
}
else if (tabHotkey.IsSelected)
{
OnHotkeyTabSelected();
}
// save multiple action keywords settings, todo: this hack is ugly
var tab = e.RemovedItems.Count > 0 ? e.RemovedItems[0] : null;
if (ReferenceEquals(tab, tabPlugin))
{
var metadata = (lbPlugins.SelectedItem as PluginPair)?.Metadata;
if (metadata != null)
{
var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == metadata.ID);
if (customizedPluginConfig != null && !customizedPluginConfig.Disabled)
{
customizedPluginConfig.ActionKeywords = metadata.ActionKeywords;
UserSettingStorage.Instance.Save();
}
}
}
}
2015-02-07 21:27:48 +08:00
#region General
2015-01-02 16:16:09 +08:00
private void LoadLanguages()
{
2015-01-21 23:00:56 +08:00
cbLanguages.ItemsSource = InternationalizationManager.Instance.LoadAvailableLanguages();
cbLanguages.DisplayMemberPath = "Display";
cbLanguages.SelectedValuePath = "LanguageCode";
2015-01-02 16:16:09 +08:00
cbLanguages.SelectedValue = UserSettingStorage.Instance.Language;
cbLanguages.SelectionChanged += cbLanguages_SelectionChanged;
}
void cbLanguages_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
2015-01-21 23:00:56 +08:00
InternationalizationManager.Instance.ChangeLanguage(cbLanguages.SelectedItem as Language);
2015-01-02 16:16:09 +08:00
}
private void CbStartWithWindows_OnChecked(object sender, RoutedEventArgs e)
{
2015-01-14 22:19:44 +08:00
AddApplicationToStartup();
2014-03-23 16:17:41 +08:00
UserSettingStorage.Instance.StartWoxOnSystemStartup = true;
UserSettingStorage.Instance.Save();
}
private void CbStartWithWindows_OnUnchecked(object sender, RoutedEventArgs e)
{
2015-01-14 22:19:44 +08:00
RemoveApplicationFromStartup();
UserSettingStorage.Instance.StartWoxOnSystemStartup = false;
UserSettingStorage.Instance.Save();
}
private void AddApplicationToStartup()
{
using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
{
2015-01-14 22:19:44 +08:00
key.SetValue("Wox", "\"" + Application.ExecutablePath + "\" --hidestart");
}
2015-01-14 22:19:44 +08:00
}
2014-03-19 01:20:51 +08:00
2015-01-14 22:19:44 +08:00
private void RemoveApplicationFromStartup()
{
using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
{
key.DeleteValue("Wox", false);
}
}
2015-01-14 22:19:44 +08:00
private bool CheckApplicationIsStartupWithWindow()
{
2015-01-14 22:19:44 +08:00
using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
{
return key.GetValue("Wox") != null;
}
}
2015-02-07 21:27:48 +08:00
#endregion
#region Hotkey
2014-02-22 15:52:20 +08:00
void ctlHotkey_OnHotkeyChanged(object sender, System.EventArgs e)
{
if (ctlHotkey.CurrentHotkeyAvailable)
{
MainWindow.SetHotkey(ctlHotkey.CurrentHotkey, delegate
2014-02-22 15:52:20 +08:00
{
if (!MainWindow.IsVisible)
{
MainWindow.ShowApp();
}
else
{
MainWindow.HideApp();
}
});
2014-03-23 16:17:41 +08:00
MainWindow.RemoveHotkey(UserSettingStorage.Instance.Hotkey);
UserSettingStorage.Instance.Hotkey = ctlHotkey.CurrentHotkey.ToString();
UserSettingStorage.Instance.Save();
2014-02-22 15:52:20 +08:00
}
}
2015-02-07 21:27:48 +08:00
private void OnHotkeyTabSelected()
{
ctlHotkey.HotkeyChanged += ctlHotkey_OnHotkeyChanged;
2015-02-07 21:27:48 +08:00
ctlHotkey.SetHotkey(UserSettingStorage.Instance.Hotkey, false);
lvCustomHotkey.ItemsSource = UserSettingStorage.Instance.CustomPluginHotkeys;
}
2014-02-22 15:52:20 +08:00
private void BtnDeleteCustomHotkey_OnClick(object sender, RoutedEventArgs e)
{
CustomPluginHotkey item = lvCustomHotkey.SelectedItem as CustomPluginHotkey;
2015-01-02 16:16:09 +08:00
if (item == null)
{
2015-01-21 23:00:56 +08:00
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem"));
2015-01-02 16:16:09 +08:00
return;
}
2015-01-21 23:00:56 +08:00
string deleteWarning = string.Format(InternationalizationManager.Instance.GetTranslation("deleteCustomHotkeyWarning"), item.Hotkey);
if (MessageBox.Show(deleteWarning, InternationalizationManager.Instance.GetTranslation("delete"), MessageBoxButton.YesNo) == MessageBoxResult.Yes)
2014-02-22 15:52:20 +08:00
{
2014-03-23 16:17:41 +08:00
UserSettingStorage.Instance.CustomPluginHotkeys.Remove(item);
2014-02-22 15:52:20 +08:00
lvCustomHotkey.Items.Refresh();
2014-03-23 16:17:41 +08:00
UserSettingStorage.Instance.Save();
2014-02-22 15:52:20 +08:00
MainWindow.RemoveHotkey(item.Hotkey);
}
}
private void BtnEditCustomHotkey_OnClick(object sender, RoutedEventArgs e)
{
CustomPluginHotkey item = lvCustomHotkey.SelectedItem as CustomPluginHotkey;
if (item != null)
{
2015-01-02 23:07:49 +08:00
CustomQueryHotkeySetting window = new CustomQueryHotkeySetting(this);
2014-02-22 15:52:20 +08:00
window.UpdateItem(item);
window.ShowDialog();
}
else
{
2015-01-21 23:00:56 +08:00
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem"));
2014-02-22 15:52:20 +08:00
}
}
private void BtnAddCustomeHotkey_OnClick(object sender, RoutedEventArgs e)
{
2015-01-02 23:07:49 +08:00
new CustomQueryHotkeySetting(this).ShowDialog();
2014-02-22 15:52:20 +08:00
}
public void ReloadCustomPluginHotkeyView()
{
lvCustomHotkey.Items.Refresh();
}
#endregion
2014-03-19 22:17:01 +08:00
#region Theme
2015-02-07 21:27:48 +08:00
private void tbMoreThemes_MouseUp(object sender, MouseButtonEventArgs e)
{
Process.Start("http://www.getwox.com/theme");
}
private void OnThemeTabSelected()
{
Stopwatch.Debug("theme load", () =>
{
var s = Fonts.SystemFontFamilies;
});
2015-02-07 21:27:48 +08:00
if (themeTabLoaded) return;
themeTabLoaded = true;
if (!string.IsNullOrEmpty(UserSettingStorage.Instance.QueryBoxFont) &&
Fonts.SystemFontFamilies.Count(o => o.FamilyNames.Values.Contains(UserSettingStorage.Instance.QueryBoxFont)) > 0)
{
cbQueryBoxFont.Text = UserSettingStorage.Instance.QueryBoxFont;
cbQueryBoxFontFaces.SelectedItem = SyntaxSugars.CallOrRescueDefault(() => ((FontFamily)cbQueryBoxFont.SelectedItem).ConvertFromInvariantStringsOrNormal(
UserSettingStorage.Instance.QueryBoxFontStyle,
UserSettingStorage.Instance.QueryBoxFontWeight,
UserSettingStorage.Instance.QueryBoxFontStretch
));
}
if (!string.IsNullOrEmpty(UserSettingStorage.Instance.ResultItemFont) &&
Fonts.SystemFontFamilies.Count(o => o.FamilyNames.Values.Contains(UserSettingStorage.Instance.ResultItemFont)) > 0)
{
cbResultItemFont.Text = UserSettingStorage.Instance.ResultItemFont;
cbResultItemFontFaces.SelectedItem = SyntaxSugars.CallOrRescueDefault(() => ((FontFamily)cbResultItemFont.SelectedItem).ConvertFromInvariantStringsOrNormal(
UserSettingStorage.Instance.ResultItemFontStyle,
UserSettingStorage.Instance.ResultItemFontWeight,
UserSettingStorage.Instance.ResultItemFontStretch
));
}
2015-02-07 21:27:48 +08:00
resultPanelPreview.AddResults(new List<Result>()
{
new Result()
{
Title = "Wox is an effective launcher for windows",
SubTitle = "Wox provide bundles of features let you access infomations quickly.",
IcoPath = "Images/app.png",
PluginDirectory = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath)
},
new Result()
{
Title = "Search applications",
SubTitle = "Search applications, files (via everything plugin) and browser bookmarks",
IcoPath = "Images/app.png",
PluginDirectory = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath)
},
new Result()
{
Title = "Search web contents with shortcuts",
SubTitle = "e.g. search google with g keyword or youtube keyword)",
IcoPath = "Images/app.png",
PluginDirectory = Path.GetDirectoryName(Application.ExecutablePath)
},
new Result()
{
Title = "clipboard history ",
IcoPath = "Images/app.png",
PluginDirectory = Path.GetDirectoryName(Application.ExecutablePath)
},
new Result()
{
Title = "Themes support",
SubTitle = "get more themes from http://www.getwox.com/theme",
IcoPath = "Images/app.png",
PluginDirectory = Path.GetDirectoryName(Application.ExecutablePath)
},
new Result()
{
Title = "Plugins support",
SubTitle = "get more plugins from http://www.getwox.com/plugin",
IcoPath = "Images/app.png",
PluginDirectory = Path.GetDirectoryName(Application.ExecutablePath)
},
new Result()
{
Title = "Wox is an open-source software",
SubTitle = "Wox benefits from the open-source community a lot",
IcoPath = "Images/app.png",
PluginDirectory = Path.GetDirectoryName(Application.ExecutablePath)
}
});
foreach (string theme in ThemeManager.Theme.LoadAvailableThemes())
{
string themeName = System.IO.Path.GetFileNameWithoutExtension(theme);
themeComboBox.Items.Add(themeName);
}
themeComboBox.SelectedItem = UserSettingStorage.Instance.Theme;
var wallpaper = WallpaperPathRetrieval.GetWallpaperPath();
if (wallpaper != null && File.Exists(wallpaper))
{
var brush = new ImageBrush(new BitmapImage(new Uri(wallpaper)));
brush.Stretch = Stretch.UniformToFill;
PreviewPanel.Background = brush;
}
else
{
var wallpaperColor = WallpaperPathRetrieval.GetWallpaperColor();
PreviewPanel.Background = new SolidColorBrush(wallpaperColor);
}
}
2014-03-19 22:17:01 +08:00
private void ThemeComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
string themeName = themeComboBox.SelectedItem.ToString();
2014-03-23 16:17:41 +08:00
UserSettingStorage.Instance.Theme = themeName;
DelayChangeTheme();
2014-03-23 16:17:41 +08:00
UserSettingStorage.Instance.Save();
2014-03-19 22:17:01 +08:00
}
private void CbQueryBoxFont_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (!settingsLoaded) return;
2014-03-19 22:17:01 +08:00
string queryBoxFontName = cbQueryBoxFont.SelectedItem.ToString();
2014-03-23 16:17:41 +08:00
UserSettingStorage.Instance.QueryBoxFont = queryBoxFontName;
this.cbQueryBoxFontFaces.SelectedItem = ((FontFamily)cbQueryBoxFont.SelectedItem).ChooseRegularFamilyTypeface();
DelayChangeTheme();
UserSettingStorage.Instance.Save();
}
private void DelayChangeTheme()
{
Dispatcher.DelayInvoke("delayChangeTheme", () =>
{
ThemeManager.Theme.ChangeTheme(UserSettingStorage.Instance.Theme);
}, TimeSpan.FromMilliseconds(100));
}
private void CbQueryBoxFontFaces_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (!settingsLoaded) return;
FamilyTypeface typeface = (FamilyTypeface)cbQueryBoxFontFaces.SelectedItem;
if (typeface == null)
{
if (cbQueryBoxFontFaces.Items.Count > 0)
cbQueryBoxFontFaces.SelectedIndex = 0;
return;
}
else
{
UserSettingStorage.Instance.QueryBoxFontStretch = typeface.Stretch.ToString();
UserSettingStorage.Instance.QueryBoxFontWeight = typeface.Weight.ToString();
UserSettingStorage.Instance.QueryBoxFontStyle = typeface.Style.ToString();
UserSettingStorage.Instance.Save();
DelayChangeTheme();
}
2014-03-19 22:17:01 +08:00
}
private void CbResultItemFont_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (!settingsLoaded) return;
2014-03-19 22:17:01 +08:00
string resultItemFont = cbResultItemFont.SelectedItem.ToString();
2014-03-23 16:17:41 +08:00
UserSettingStorage.Instance.ResultItemFont = resultItemFont;
this.cbResultItemFontFaces.SelectedItem = ((FontFamily)cbResultItemFont.SelectedItem).ChooseRegularFamilyTypeface();
2014-03-23 16:17:41 +08:00
UserSettingStorage.Instance.Save();
DelayChangeTheme();
2014-03-19 22:17:01 +08:00
}
private void CbResultItemFontFaces_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (!settingsLoaded) return;
FamilyTypeface typeface = (FamilyTypeface)cbResultItemFontFaces.SelectedItem;
if (typeface == null)
{
if (cbResultItemFontFaces.Items.Count > 0)
cbResultItemFontFaces.SelectedIndex = 0;
}
else
{
UserSettingStorage.Instance.ResultItemFontStretch = typeface.Stretch.ToString();
UserSettingStorage.Instance.ResultItemFontWeight = typeface.Weight.ToString();
UserSettingStorage.Instance.ResultItemFontStyle = typeface.Style.ToString();
UserSettingStorage.Instance.Save();
DelayChangeTheme();
}
}
2014-03-26 17:34:19 +08:00
2014-03-19 22:17:01 +08:00
#endregion
2014-03-26 17:34:19 +08:00
2015-02-07 21:27:48 +08:00
#region Plugin
2014-03-26 17:34:19 +08:00
private void lbPlugins_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
ISettingProvider provider = null;
var pair = lbPlugins.SelectedItem as PluginPair;
string pluginId = string.Empty;
if (pair != null)
{
provider = pair.Plugin as ISettingProvider;
2014-06-30 21:31:13 +08:00
pluginAuthor.Visibility = Visibility.Visible;
pluginInitTime.Text =
string.Format(InternationalizationManager.Instance.GetTranslation("plugin_init_time"), pair.InitTime);
pluginQueryTime.Text =
string.Format(InternationalizationManager.Instance.GetTranslation("plugin_query_time"), pair.AvgQueryTime);
2015-11-07 02:12:46 +08:00
if (pair.Metadata.ActionKeywords.Count > 1)
{
pluginActionKeywordsTitle.Visibility = Visibility.Collapsed;
pluginActionKeywords.Visibility = Visibility.Collapsed;
}
else
{
pluginActionKeywordsTitle.Visibility = Visibility.Visible;
pluginActionKeywords.Visibility = Visibility.Visible;
}
tbOpenPluginDirecoty.Visibility = Visibility.Visible;
pluginTitle.Text = pair.Metadata.Name;
2014-07-04 15:12:22 +08:00
pluginTitle.Cursor = Cursors.Hand;
pluginActionKeywords.Text = string.Join(Query.ActionKeywordSeperater, pair.Metadata.ActionKeywords.ToArray());
2015-01-21 23:00:56 +08:00
pluginAuthor.Text = InternationalizationManager.Instance.GetTranslation("author") + ": " + pair.Metadata.Author;
pluginSubTitle.Text = pair.Metadata.Description;
pluginId = pair.Metadata.ID;
2014-12-18 19:22:47 +08:00
pluginIcon.Source = ImageLoader.ImageLoader.Load(pair.Metadata.FullIcoPath);
}
var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == pluginId);
cbDisablePlugin.IsChecked = customizedPluginConfig != null && customizedPluginConfig.Disabled;
PluginContentPanel.Content = null;
if (provider != null)
{
Control control = null;
if (!featureControls.TryGetValue(provider, out control))
featureControls.Add(provider, control = provider.CreateSettingPanel());
PluginContentPanel.Content = control;
control.HorizontalAlignment = HorizontalAlignment.Stretch;
control.VerticalAlignment = VerticalAlignment.Stretch;
control.Width = Double.NaN;
control.Height = Double.NaN;
}
}
private void CbDisablePlugin_OnClick(object sender, RoutedEventArgs e)
{
CheckBox cbDisabled = e.Source as CheckBox;
if (cbDisabled == null) return;
var pair = lbPlugins.SelectedItem as PluginPair;
var id = string.Empty;
var name = string.Empty;
if (pair != null)
{
//third-party plugin
id = pair.Metadata.ID;
name = pair.Metadata.Name;
}
var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == id);
if (customizedPluginConfig == null)
{
// todo when this part will be invoked
UserSettingStorage.Instance.CustomizedPluginConfigs.Add(new CustomizedPluginConfig()
{
Disabled = cbDisabled.IsChecked ?? true,
ID = id,
Name = name,
ActionKeywords = null
});
}
else
{
customizedPluginConfig.Disabled = cbDisabled.IsChecked ?? true;
}
UserSettingStorage.Instance.Save();
}
private void PluginActionKeywords_OnMouseUp(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
{
var pair = lbPlugins.SelectedItem as PluginPair;
if (pair != null)
{
//third-party plugin
string id = pair.Metadata.ID;
ActionKeywords changeKeywordsWindow = new ActionKeywords(id);
changeKeywordsWindow.ShowDialog();
PluginPair plugin = PluginManager.GetPluginForId(id);
if (plugin != null) pluginActionKeywords.Text = string.Join(Query.ActionKeywordSeperater, pair.Metadata.ActionKeywords.ToArray());
}
}
}
2014-07-04 15:12:22 +08:00
private void PluginTitle_OnMouseUp(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
2014-07-04 15:12:22 +08:00
{
var pair = lbPlugins.SelectedItem as PluginPair;
if (pair != null)
{
//third-party plugin
if (!string.IsNullOrEmpty(pair.Metadata.Website))
{
try
{
Process.Start(pair.Metadata.Website);
}
catch
{ }
}
}
}
}
private void tbOpenPluginDirecoty_MouseUp(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
{
var pair = lbPlugins.SelectedItem as PluginPair;
if (pair != null)
{
//third-party plugin
if (!string.IsNullOrEmpty(pair.Metadata.Website))
{
try
{
Process.Start(pair.Metadata.PluginDirectory);
}
catch
{ }
}
}
}
}
private void tbMorePlugins_MouseUp(object sender, MouseButtonEventArgs e)
{
Process.Start("http://www.getwox.com/plugin");
}
2015-02-07 21:27:48 +08:00
private void OnPluginTabSelected()
{
2015-02-07 21:27:48 +08:00
var plugins = new CompositeCollection
{
new CollectionContainer
{
Collection = PluginManager.AllPlugins
}
};
lbPlugins.ItemsSource = plugins;
lbPlugins.SelectedIndex = 0;
}
#endregion
#region Proxy
2014-07-18 20:00:55 +08:00
private void btnSaveProxy_Click(object sender, RoutedEventArgs e)
{
UserSettingStorage.Instance.ProxyEnabled = cbEnableProxy.IsChecked ?? false;
int port = 80;
if (UserSettingStorage.Instance.ProxyEnabled)
{
if (string.IsNullOrEmpty(tbProxyServer.Text))
{
2015-01-21 23:00:56 +08:00
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("serverCantBeEmpty"));
2014-07-18 20:00:55 +08:00
return;
}
if (string.IsNullOrEmpty(tbProxyPort.Text))
{
2015-01-21 23:00:56 +08:00
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("portCantBeEmpty"));
2014-07-18 20:00:55 +08:00
return;
}
if (!int.TryParse(tbProxyPort.Text, out port))
{
2015-01-21 23:00:56 +08:00
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("invalidPortFormat"));
2014-07-18 20:00:55 +08:00
return;
}
}
UserSettingStorage.Instance.ProxyServer = tbProxyServer.Text;
UserSettingStorage.Instance.ProxyPort = port;
UserSettingStorage.Instance.ProxyUserName = tbProxyUserName.Text;
UserSettingStorage.Instance.ProxyPassword = tbProxyPassword.Password;
UserSettingStorage.Instance.Save();
2015-01-21 23:00:56 +08:00
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("saveProxySuccessfully"));
2014-07-18 20:00:55 +08:00
}
private void btnTestProxy_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(tbProxyServer.Text))
{
2015-01-21 23:00:56 +08:00
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("serverCantBeEmpty"));
2014-07-18 20:00:55 +08:00
return;
}
if (string.IsNullOrEmpty(tbProxyPort.Text))
{
2015-01-21 23:00:56 +08:00
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("portCantBeEmpty"));
2014-07-18 20:00:55 +08:00
return;
}
int port;
if (!int.TryParse(tbProxyPort.Text, out port))
{
2015-01-21 23:00:56 +08:00
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("invalidPortFormat"));
2014-07-18 20:00:55 +08:00
return;
}
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.baidu.com");
request.Timeout = 1000 * 5;
request.ReadWriteTimeout = 1000 * 5;
if (string.IsNullOrEmpty(tbProxyUserName.Text))
{
request.Proxy = new WebProxy(tbProxyServer.Text, port);
}
else
{
request.Proxy = new WebProxy(tbProxyServer.Text, port);
request.Proxy.Credentials = new NetworkCredential(tbProxyUserName.Text, tbProxyPassword.Password);
}
try
{
2015-01-02 16:16:09 +08:00
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
2014-07-18 20:00:55 +08:00
if (response.StatusCode == HttpStatusCode.OK)
{
2015-01-21 23:00:56 +08:00
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("proxyIsCorrect"));
2014-07-18 20:00:55 +08:00
}
else
{
2015-01-21 23:00:56 +08:00
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("proxyConnectFailed"));
2014-07-18 20:00:55 +08:00
}
}
catch
{
2015-01-21 23:00:56 +08:00
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("proxyConnectFailed"));
2014-07-18 20:00:55 +08:00
}
}
2014-12-16 22:25:22 +08:00
2015-02-07 21:27:48 +08:00
private void EnableProxy()
{
tbProxyPassword.IsEnabled = true;
tbProxyServer.IsEnabled = true;
tbProxyUserName.IsEnabled = true;
tbProxyPort.IsEnabled = true;
}
private void DisableProxy()
{
tbProxyPassword.IsEnabled = false;
tbProxyServer.IsEnabled = false;
tbProxyUserName.IsEnabled = false;
tbProxyPort.IsEnabled = false;
}
#endregion
#region About
2014-12-16 22:25:22 +08:00
private void tbWebsite_MouseUp(object sender, MouseButtonEventArgs e)
{
Process.Start("http://www.getwox.com");
}
2015-02-07 21:27:48 +08:00
#endregion
2015-09-26 05:50:22 +08:00
private void Window_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
// Hide window with ESC, but make sure it is not pressed as a hotkey
if (e.Key == Key.Escape && !ctlHotkey.IsFocused)
{
Close();
}
}
}
}