add refresh plugin action keyword display when changed

This commit is contained in:
Jeremy Wu 2020-06-17 21:56:46 +10:00
parent 34622d6bbf
commit 651e2a95b2
3 changed files with 20 additions and 9 deletions

View file

@ -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

View file

@ -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();
}
}

View file

@ -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);
}
}