2015-10-31 07:17:34 +08:00
|
|
|
|
using System.Linq;
|
2014-07-04 12:08:37 +08:00
|
|
|
|
using System.Windows;
|
2015-01-02 23:07:49 +08:00
|
|
|
|
using Wox.Core.i18n;
|
2014-12-26 19:36:43 +08:00
|
|
|
|
using Wox.Core.Plugin;
|
2015-01-05 22:41:17 +08:00
|
|
|
|
using Wox.Core.UserSettings;
|
2014-07-04 12:08:37 +08:00
|
|
|
|
using Wox.Plugin;
|
|
|
|
|
|
|
|
|
|
namespace Wox
|
|
|
|
|
{
|
|
|
|
|
public partial class ActionKeyword : Window
|
|
|
|
|
{
|
|
|
|
|
private PluginMetadata pluginMetadata;
|
|
|
|
|
|
|
|
|
|
public ActionKeyword(string pluginId)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2014-12-26 19:36:43 +08:00
|
|
|
|
PluginPair plugin = PluginManager.GetPlugin(pluginId);
|
2014-07-04 12:08:37 +08:00
|
|
|
|
if (plugin == null)
|
|
|
|
|
{
|
2015-01-21 23:00:56 +08:00
|
|
|
|
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("cannotFindSpecifiedPlugin"));
|
2014-07-04 12:08:37 +08:00
|
|
|
|
Close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pluginMetadata = plugin.Metadata;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ActionKeyword_OnLoaded(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
tbOldActionKeyword.Text = pluginMetadata.ActionKeyword;
|
|
|
|
|
tbAction.Focus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnDone_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(tbAction.Text))
|
|
|
|
|
{
|
2015-01-21 23:00:56 +08:00
|
|
|
|
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("newActionKeywordCannotBeEmpty"));
|
2014-07-04 12:08:37 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//check new action keyword didn't used by other plugin
|
2015-01-26 17:46:55 +08:00
|
|
|
|
if (tbAction.Text.Trim() != PluginManager.ActionKeywordWildcardSign && PluginManager.AllPlugins.Exists(o => o.Metadata.ActionKeyword == tbAction.Text.Trim()))
|
2014-07-04 12:08:37 +08:00
|
|
|
|
{
|
2015-01-21 23:00:56 +08:00
|
|
|
|
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("newActionKeywordHasBeenAssigned"));
|
2014-07-04 12:08:37 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pluginMetadata.ActionKeyword = tbAction.Text.Trim();
|
|
|
|
|
var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == pluginMetadata.ID);
|
|
|
|
|
if (customizedPluginConfig == null)
|
|
|
|
|
{
|
|
|
|
|
UserSettingStorage.Instance.CustomizedPluginConfigs.Add(new CustomizedPluginConfig()
|
|
|
|
|
{
|
|
|
|
|
Disabled = false,
|
|
|
|
|
ID = pluginMetadata.ID,
|
|
|
|
|
Name = pluginMetadata.Name,
|
|
|
|
|
Actionword = tbAction.Text.Trim()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
customizedPluginConfig.Actionword = tbAction.Text.Trim();
|
|
|
|
|
}
|
|
|
|
|
UserSettingStorage.Instance.Save();
|
2015-01-21 23:00:56 +08:00
|
|
|
|
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("succeed"));
|
2014-07-04 12:08:37 +08:00
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|