Add title translations

This commit is contained in:
qianlifeng
2015-02-07 21:27:48 +08:00
parent 437c1a154c
commit 2d05ecc81f
29 changed files with 759 additions and 390 deletions

View File

@@ -17,19 +17,25 @@ using Application = System.Windows.Forms.Application;
using File = System.IO.File;
using MessageBox = System.Windows.MessageBox;
using System.Windows.Data;
using System.Windows.Forms;
using Microsoft.Win32;
using Wox.Core.i18n;
using Wox.Core.Theme;
using Wox.Core.Updater;
using Wox.Core.UserSettings;
using CheckBox = System.Windows.Controls.CheckBox;
using Control = System.Windows.Controls.Control;
using Cursors = System.Windows.Input.Cursors;
using HorizontalAlignment = System.Windows.HorizontalAlignment;
namespace Wox
{
public partial class SettingWindow : Window
{
public MainWindow MainWindow;
public readonly MainWindow MainWindow;
bool settingsLoaded = false;
private Dictionary<ISettingProvider, Control> featureControls = new Dictionary<ISettingProvider, Control>();
private bool themeTabLoaded = false;
public SettingWindow(MainWindow mainWindow)
{
@@ -74,8 +80,208 @@ namespace Wox
#endregion
#region Theme
#region Proxy
cbEnableProxy.Checked += (o, e) => EnableProxy();
cbEnableProxy.Unchecked += (o, e) => DisableProxy();
cbEnableProxy.IsChecked = UserSettingStorage.Instance.ProxyEnabled;
tbProxyServer.Text = UserSettingStorage.Instance.ProxyServer;
tbProxyPort.Text = UserSettingStorage.Instance.ProxyPort.ToString();
tbProxyUserName.Text = UserSettingStorage.Instance.ProxyUserName;
tbProxyPassword.Password = UserSettingStorage.Instance.ProxyPassword;
if (UserSettingStorage.Instance.ProxyEnabled)
{
EnableProxy();
}
else
{
DisableProxy();
}
#endregion
#region About
tbVersion.Text = UpdaterManager.Instance.CurrentVersion.ToString();
string activateTimes = string.Format(InternationalizationManager.Instance.GetTranslation("about_activate_times"),
UserSettingStorage.Instance.ActivateTimes);
tbActivatedTimes.Text = activateTimes;
#endregion
settingsLoaded = true;
}
#region General
private void LoadLanguages()
{
cbLanguages.ItemsSource = InternationalizationManager.Instance.LoadAvailableLanguages();
cbLanguages.DisplayMemberPath = "Display";
cbLanguages.SelectedValuePath = "LanguageCode";
cbLanguages.SelectedValue = UserSettingStorage.Instance.Language;
cbLanguages.SelectionChanged += cbLanguages_SelectionChanged;
}
void cbLanguages_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
InternationalizationManager.Instance.ChangeLanguage(cbLanguages.SelectedItem as Language);
}
private void CbStartWithWindows_OnChecked(object sender, RoutedEventArgs e)
{
AddApplicationToStartup();
UserSettingStorage.Instance.StartWoxOnSystemStartup = true;
UserSettingStorage.Instance.Save();
}
private void CbStartWithWindows_OnUnchecked(object sender, RoutedEventArgs e)
{
RemoveApplicationFromStartup();
UserSettingStorage.Instance.StartWoxOnSystemStartup = false;
UserSettingStorage.Instance.Save();
}
private void AddApplicationToStartup()
{
using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
{
key.SetValue("Wox", "\"" + Application.ExecutablePath + "\" --hidestart");
}
}
private void RemoveApplicationFromStartup()
{
using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
{
key.DeleteValue("Wox", false);
}
}
private bool CheckApplicationIsStartupWithWindow()
{
using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
{
return key.GetValue("Wox") != null;
}
}
#endregion
#region Hotkey
void ctlHotkey_OnHotkeyChanged(object sender, System.EventArgs e)
{
if (ctlHotkey.CurrentHotkeyAvailable)
{
MainWindow.SetHotkey(ctlHotkey.CurrentHotkey.ToString(), delegate
{
if (!MainWindow.IsVisible)
{
MainWindow.ShowApp();
}
else
{
MainWindow.HideApp();
}
});
MainWindow.RemoveHotkey(UserSettingStorage.Instance.Hotkey);
UserSettingStorage.Instance.Hotkey = ctlHotkey.CurrentHotkey.ToString();
UserSettingStorage.Instance.Save();
}
}
private void TabHotkey_OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
var tabItem = sender as TabItem;
var clickingBody = (tabItem.Content as UIElement).IsMouseOver;
if (!clickingBody)
{
OnHotkeyTabSelected();
}
}
private void OnHotkeyTabSelected()
{
ctlHotkey.OnHotkeyChanged += ctlHotkey_OnHotkeyChanged;
ctlHotkey.SetHotkey(UserSettingStorage.Instance.Hotkey, false);
lvCustomHotkey.ItemsSource = UserSettingStorage.Instance.CustomPluginHotkeys;
}
private void BtnDeleteCustomHotkey_OnClick(object sender, RoutedEventArgs e)
{
CustomPluginHotkey item = lvCustomHotkey.SelectedItem as CustomPluginHotkey;
if (item == null)
{
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem"));
return;
}
string deleteWarning = string.Format(InternationalizationManager.Instance.GetTranslation("deleteCustomHotkeyWarning"), item.Hotkey);
if (MessageBox.Show(deleteWarning, InternationalizationManager.Instance.GetTranslation("delete"), MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
UserSettingStorage.Instance.CustomPluginHotkeys.Remove(item);
lvCustomHotkey.Items.Refresh();
UserSettingStorage.Instance.Save();
MainWindow.RemoveHotkey(item.Hotkey);
}
}
private void BtnEditCustomHotkey_OnClick(object sender, RoutedEventArgs e)
{
CustomPluginHotkey item = lvCustomHotkey.SelectedItem as CustomPluginHotkey;
if (item != null)
{
CustomQueryHotkeySetting window = new CustomQueryHotkeySetting(this);
window.UpdateItem(item);
window.ShowDialog();
}
else
{
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem"));
}
}
private void BtnAddCustomeHotkey_OnClick(object sender, RoutedEventArgs e)
{
new CustomQueryHotkeySetting(this).ShowDialog();
}
public void ReloadCustomPluginHotkeyView()
{
lvCustomHotkey.Items.Refresh();
}
#endregion
#region Theme
private void tbMoreThemes_MouseUp(object sender, MouseButtonEventArgs e)
{
Process.Start("http://www.getwox.com/theme");
}
private void CbOpacityMode_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
UserSettingStorage.Instance.OpacityMode = (OpacityMode)CbOpacityMode.SelectedItem;
UserSettingStorage.Instance.Save();
spOpacity.Visibility = UserSettingStorage.Instance.OpacityMode == OpacityMode.LayeredWindow ? Visibility.Visible : Visibility.Collapsed;
if (UserSettingStorage.Instance.OpacityMode == OpacityMode.LayeredWindow)
PreviewMainPanel.Opacity = UserSettingStorage.Instance.Opacity;
else
PreviewMainPanel.Opacity = 1;
}
private void OnThemeTabSelected()
{
if (themeTabLoaded) return;
themeTabLoaded = true;
if (!string.IsNullOrEmpty(UserSettingStorage.Instance.QueryBoxFont) &&
Fonts.SystemFontFamilies.Count(o => o.FamilyNames.Values.Contains(UserSettingStorage.Instance.QueryBoxFont)) > 0)
{
@@ -175,196 +381,18 @@ namespace Wox
//PreviewPanel
ThemeManager.Theme.ChangeTheme(UserSettingStorage.Instance.Theme);
#endregion
}
#region Plugin
ctlHotkey.OnHotkeyChanged += ctlHotkey_OnHotkeyChanged;
ctlHotkey.SetHotkey(UserSettingStorage.Instance.Hotkey, false);
lvCustomHotkey.ItemsSource = UserSettingStorage.Instance.CustomPluginHotkeys;
var plugins = new CompositeCollection
private void TabTheme_OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
var tabItem = sender as TabItem;
var clickingBody = (tabItem.Content as UIElement).IsMouseOver;
if (!clickingBody)
{
new CollectionContainer
{
Collection = PluginManager.AllPlugins
}
};
lbPlugins.ItemsSource = plugins;
lbPlugins.SelectedIndex = 0;
#endregion
#region Proxy
cbEnableProxy.Checked += (o, e) => EnableProxy();
cbEnableProxy.Unchecked += (o, e) => DisableProxy();
cbEnableProxy.IsChecked = UserSettingStorage.Instance.ProxyEnabled;
tbProxyServer.Text = UserSettingStorage.Instance.ProxyServer;
tbProxyPort.Text = UserSettingStorage.Instance.ProxyPort.ToString();
tbProxyUserName.Text = UserSettingStorage.Instance.ProxyUserName;
tbProxyPassword.Password = UserSettingStorage.Instance.ProxyPassword;
if (UserSettingStorage.Instance.ProxyEnabled)
{
EnableProxy();
}
else
{
DisableProxy();
}
#endregion
#region About
tbVersion.Text = UpdaterManager.Instance.CurrentVersion.ToString();
string activateTimes = string.Format(InternationalizationManager.Instance.GetTranslation("about_activate_times"),
UserSettingStorage.Instance.ActivateTimes);
tbActivatedTimes.Text = activateTimes;
#endregion
settingsLoaded = true;
}
private void LoadLanguages()
{
cbLanguages.ItemsSource = InternationalizationManager.Instance.LoadAvailableLanguages();
cbLanguages.DisplayMemberPath = "Display";
cbLanguages.SelectedValuePath = "LanguageCode";
cbLanguages.SelectedValue = UserSettingStorage.Instance.Language;
cbLanguages.SelectionChanged += cbLanguages_SelectionChanged;
}
void cbLanguages_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
InternationalizationManager.Instance.ChangeLanguage(cbLanguages.SelectedItem as Language);
}
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;
}
private void CbStartWithWindows_OnChecked(object sender, RoutedEventArgs e)
{
AddApplicationToStartup();
UserSettingStorage.Instance.StartWoxOnSystemStartup = true;
UserSettingStorage.Instance.Save();
}
private void CbStartWithWindows_OnUnchecked(object sender, RoutedEventArgs e)
{
RemoveApplicationFromStartup();
UserSettingStorage.Instance.StartWoxOnSystemStartup = false;
UserSettingStorage.Instance.Save();
}
private void AddApplicationToStartup()
{
using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
{
key.SetValue("Wox", "\"" + Application.ExecutablePath + "\" --hidestart");
OnThemeTabSelected();
}
}
private void RemoveApplicationFromStartup()
{
using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
{
key.DeleteValue("Wox", false);
}
}
private bool CheckApplicationIsStartupWithWindow()
{
using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
{
return key.GetValue("Wox") != null;
}
}
void ctlHotkey_OnHotkeyChanged(object sender, System.EventArgs e)
{
if (ctlHotkey.CurrentHotkeyAvailable)
{
MainWindow.SetHotkey(ctlHotkey.CurrentHotkey.ToString(), delegate
{
if (!MainWindow.IsVisible)
{
MainWindow.ShowApp();
}
else
{
MainWindow.HideApp();
}
});
MainWindow.RemoveHotkey(UserSettingStorage.Instance.Hotkey);
UserSettingStorage.Instance.Hotkey = ctlHotkey.CurrentHotkey.ToString();
UserSettingStorage.Instance.Save();
}
}
#region Custom Plugin Hotkey
private void BtnDeleteCustomHotkey_OnClick(object sender, RoutedEventArgs e)
{
CustomPluginHotkey item = lvCustomHotkey.SelectedItem as CustomPluginHotkey;
if (item == null)
{
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem"));
return;
}
string deleteWarning = string.Format(InternationalizationManager.Instance.GetTranslation("deleteCustomHotkeyWarning"), item.Hotkey);
if (MessageBox.Show(deleteWarning, InternationalizationManager.Instance.GetTranslation("delete"), MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
UserSettingStorage.Instance.CustomPluginHotkeys.Remove(item);
lvCustomHotkey.Items.Refresh();
UserSettingStorage.Instance.Save();
MainWindow.RemoveHotkey(item.Hotkey);
}
}
private void BtnEditCustomHotkey_OnClick(object sender, RoutedEventArgs e)
{
CustomPluginHotkey item = lvCustomHotkey.SelectedItem as CustomPluginHotkey;
if (item != null)
{
CustomQueryHotkeySetting window = new CustomQueryHotkeySetting(this);
window.UpdateItem(item);
window.ShowDialog();
}
else
{
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem"));
}
}
private void BtnAddCustomeHotkey_OnClick(object sender, RoutedEventArgs e)
{
new CustomQueryHotkeySetting(this).ShowDialog();
}
public void ReloadCustomPluginHotkeyView()
{
lvCustomHotkey.Items.Refresh();
}
#endregion
#region Theme
private void ThemeComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
string themeName = themeComboBox.SelectedItem.ToString();
@@ -452,18 +480,8 @@ namespace Wox
}
#endregion
private void CbOpacityMode_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
UserSettingStorage.Instance.OpacityMode = (OpacityMode)CbOpacityMode.SelectedItem;
UserSettingStorage.Instance.Save();
#region Plugin
spOpacity.Visibility = UserSettingStorage.Instance.OpacityMode == OpacityMode.LayeredWindow ? Visibility.Visible : Visibility.Collapsed;
if (UserSettingStorage.Instance.OpacityMode == OpacityMode.LayeredWindow)
PreviewMainPanel.Opacity = UserSettingStorage.Instance.Opacity;
else
PreviewMainPanel.Opacity = 1;
}
private void lbPlugins_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
@@ -473,7 +491,6 @@ namespace Wox
if (pair != null)
{
//third-party plugin
provider = pair.Plugin as ISettingProvider;
pluginAuthor.Visibility = Visibility.Visible;
pluginActionKeyword.Visibility = Visibility.Visible;
@@ -491,11 +508,6 @@ namespace Wox
pluginId = pair.Metadata.ID;
pluginIcon.Source = ImageLoader.ImageLoader.Load(pair.Metadata.FullIcoPath);
}
else
{
//system plugin
provider = lbPlugins.SelectedItem as ISettingProvider;
}
var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == pluginId);
cbDisablePlugin.IsChecked = customizedPluginConfig != null && customizedPluginConfig.Disabled;
@@ -611,11 +623,33 @@ namespace Wox
Process.Start("http://www.getwox.com/plugin");
}
private void tbMoreThemes_MouseUp(object sender, MouseButtonEventArgs e)
private void OnPluginTabSelected()
{
Process.Start("http://www.getwox.com/theme");
var plugins = new CompositeCollection
{
new CollectionContainer
{
Collection = PluginManager.AllPlugins
}
};
lbPlugins.ItemsSource = plugins;
lbPlugins.SelectedIndex = 0;
}
private void TabPlugin_OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
var tabItem = sender as TabItem;
var clickingBody = (tabItem.Content as UIElement).IsMouseOver;
if (!clickingBody)
{
OnPluginTabSelected();
}
}
#endregion
#region Proxy
private void btnSaveProxy_Click(object sender, RoutedEventArgs e)
{
UserSettingStorage.Instance.ProxyEnabled = cbEnableProxy.IsChecked ?? false;
@@ -698,9 +732,31 @@ namespace Wox
}
}
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
private void tbWebsite_MouseUp(object sender, MouseButtonEventArgs e)
{
Process.Start("http://www.getwox.com");
}
#endregion
}
}