PowerToys/Wox/ActionKeywords.xaml.cs
bao-qian b22a4501cc Use variable instead of global static method
1. introduce variable
2. part of #389
3. refactoring program suffix in program plugin
4. 全局变量一时爽,代码重构火葬场
2016-03-28 03:09:57 +01:00

60 lines
1.8 KiB
C#

using System.Windows;
using Wox.Core.Plugin;
using Wox.Core.Resource;
using Wox.Core.UserSettings;
using Wox.Infrastructure.Exception;
using Wox.Plugin;
namespace Wox
{
public partial class ActionKeywords : Window
{
private PluginPair _plugin;
private UserSettingStorage _settings;
public ActionKeywords(string pluginId, UserSettingStorage settings)
{
InitializeComponent();
_plugin = PluginManager.GetPluginForId(pluginId);
_settings = settings;
if (_plugin == null)
{
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("cannotFindSpecifiedPlugin"));
Close();
}
}
private void ActionKeyword_OnLoaded(object sender, RoutedEventArgs e)
{
tbOldActionKeyword.Text = string.Join(Query.ActionKeywordSeperater, _plugin.Metadata.ActionKeywords.ToArray());
tbAction.Focus();
}
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
{
Close();
}
private void btnDone_OnClick(object sender, RoutedEventArgs _)
{
var oldActionKeyword = _plugin.Metadata.ActionKeywords[0];
var newActionKeyword = tbAction.Text.Trim();
try
{
// update in-memory data
PluginManager.UpdateActionKeywordForPlugin(_plugin, oldActionKeyword, newActionKeyword);
}
catch (WoxPluginException e)
{
MessageBox.Show(e.Message);
return;
}
// update persistant data
_settings.UpdateActionKeyword(_plugin.Metadata);
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("succeed"));
Close();
}
}
}