diff --git a/Flow.Launcher/ActionKeywords.xaml.cs b/Flow.Launcher/ActionKeywords.xaml.cs index 0f8690cca..c58cc3ea7 100644 --- a/Flow.Launcher/ActionKeywords.xaml.cs +++ b/Flow.Launcher/ActionKeywords.xaml.cs @@ -1,9 +1,10 @@ -using System.Windows; +using System.Windows; using Flow.Launcher.Core.Plugin; using Flow.Launcher.Core.Resource; using Flow.Launcher.Infrastructure.Exception; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; +using Flow.Launcher.ViewModel; namespace Flow.Launcher { @@ -12,13 +13,14 @@ namespace Flow.Launcher private PluginPair _plugin; private Settings _settings; private readonly Internationalization _translater = InternationalizationManager.Instance; + private readonly PluginViewModel pluginViewModel; - public ActionKeywords(string pluginId, Settings settings) + public ActionKeywords(string pluginId, Settings settings, PluginViewModel pluginViewModel) { InitializeComponent(); _plugin = PluginManager.GetPluginForId(pluginId); _settings = settings; - if (_plugin == null) + this.pluginViewModel = pluginViewModel; { MessageBox.Show(_translater.GetTranslation("cannotFindSpecifiedPlugin")); Close(); @@ -41,10 +43,9 @@ namespace Flow.Launcher var oldActionKeyword = _plugin.Metadata.ActionKeywords[0]; var newActionKeyword = tbAction.Text.Trim(); newActionKeyword = newActionKeyword.Length > 0 ? newActionKeyword : "*"; - if (!PluginManager.ActionKeywordRegistered(newActionKeyword)) + if (!pluginViewModel.IsActionKeywordRegistered(newActionKeyword)) { - var id = _plugin.Metadata.ID; - PluginManager.ReplaceActionKeyword(id, oldActionKeyword, newActionKeyword); + pluginViewModel.ChangeActionKeyword(newActionKeyword, oldActionKeyword); Close(); } else diff --git a/Flow.Launcher/SettingWindow.xaml.cs b/Flow.Launcher/SettingWindow.xaml.cs index aa54bb7c5..1f37c8990 100644 --- a/Flow.Launcher/SettingWindow.xaml.cs +++ b/Flow.Launcher/SettingWindow.xaml.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Diagnostics; using System.IO; using System.Windows; @@ -214,7 +214,7 @@ namespace Flow.Launcher if (e.ChangedButton == MouseButton.Left) { var id = _viewModel.SelectedPlugin.PluginPair.Metadata.ID; - ActionKeywords changeKeywordsWindow = new ActionKeywords(id, _settings); + ActionKeywords changeKeywordsWindow = new ActionKeywords(id, _settings, _viewModel.SelectedPlugin); changeKeywordsWindow.ShowDialog(); } } diff --git a/Flow.Launcher/ViewModel/PluginViewModel.cs b/Flow.Launcher/ViewModel/PluginViewModel.cs index e79636771..a2accceb1 100644 --- a/Flow.Launcher/ViewModel/PluginViewModel.cs +++ b/Flow.Launcher/ViewModel/PluginViewModel.cs @@ -1,8 +1,9 @@ -using System.Windows; +using System.Windows; using System.Windows.Media; using Flow.Launcher.Plugin; using Flow.Launcher.Core.Resource; using Flow.Launcher.Infrastructure.Image; +using Flow.Launcher.Core.Plugin; namespace Flow.Launcher.ViewModel { @@ -25,5 +26,14 @@ namespace Flow.Launcher.ViewModel public string InitilizaTime => string.Format(_translator.GetTranslation("plugin_init_time"), PluginPair.Metadata.InitTime); public string QueryTime => string.Format(_translator.GetTranslation("plugin_query_time"), PluginPair.Metadata.AvgQueryTime); public string ActionKeywordsText => string.Join(Query.ActionKeywordSeperater, PluginPair.Metadata.ActionKeywords); + + public void ChangeActionKeyword(string newActionKeyword, string oldActionKeyword) + { + PluginManager.ReplaceActionKeyword(PluginPair.Metadata.ID, oldActionKeyword, newActionKeyword); + + OnPropertyChanged(nameof(ActionKeywordsText)); + } + + public bool IsActionKeywordRegistered(string newActionKeyword) => PluginManager.ActionKeywordRegistered(newActionKeyword); } }