PowerToys/Wox/ActionKeywords.xaml.cs

58 lines
1.9 KiB
C#
Raw Normal View History

2016-01-06 14:45:08 +08:00
using System.Windows;
2014-12-26 19:36:43 +08:00
using Wox.Core.Plugin;
using Wox.Core.Resource;
using Wox.Infrastructure.Exception;
2016-06-19 23:18:43 +08:00
using Wox.Infrastructure.UserSettings;
using Wox.Plugin;
namespace Wox
{
public partial class ActionKeywords : Window
{
private PluginPair _plugin;
private Settings _settings;
private readonly Internationalization _translater = InternationalizationManager.Instance;
public ActionKeywords(string pluginId, Settings settings)
{
InitializeComponent();
_plugin = PluginManager.GetPluginForId(pluginId);
_settings = settings;
if (_plugin == null)
{
MessageBox.Show(_translater.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();
if (!PluginManager.ActionKeywordRegistered(newActionKeyword))
{
var id = _plugin.Metadata.ID;
PluginManager.ReplaceActionKeyword(id, oldActionKeyword, newActionKeyword);
MessageBox.Show(_translater.GetTranslation("succeed"));
Close();
}
else
{
string msg = _translater.GetTranslation("newActionKeywordsHasBeenAssigned");
MessageBox.Show(msg);
}
}
}
}