From 7bcbe5d7918229e17d53b19c5432ad83ad16de4f Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Fri, 4 Jul 2014 12:08:37 +0800 Subject: [PATCH] close #21 Allow user to set their custom ActionKeyword --- Wox/ActionKeyword.xaml | 35 +++++++++++ Wox/ActionKeyword.xaml.cs | 89 ++++++++++++++++++++++++++++ Wox/PluginLoader/BasePluginLoader.cs | 8 +++ Wox/SettingWindow.xaml | 5 +- Wox/SettingWindow.xaml.cs | 20 ++++++- Wox/Wox.csproj | 7 +++ 6 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 Wox/ActionKeyword.xaml create mode 100644 Wox/ActionKeyword.xaml.cs diff --git a/Wox/ActionKeyword.xaml b/Wox/ActionKeyword.xaml new file mode 100644 index 000000000..20288b6d1 --- /dev/null +++ b/Wox/ActionKeyword.xaml @@ -0,0 +1,35 @@ + + + + + + + + + + + + Old ActionKeyword: + Old ActionKeyword: + + New ActionKeyword: + + + + + + + + + + diff --git a/Wox/ActionKeyword.xaml.cs b/Wox/ActionKeyword.xaml.cs new file mode 100644 index 000000000..a2a103743 --- /dev/null +++ b/Wox/ActionKeyword.xaml.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Forms; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; +using Wox.Infrastructure.Storage.UserSettings; +using Wox.Plugin; +using Wox.PluginLoader; +using MessageBox = System.Windows.MessageBox; + +namespace Wox +{ + public partial class ActionKeyword : Window + { + private PluginMetadata pluginMetadata; + + public ActionKeyword(string pluginId) + { + InitializeComponent(); + PluginPair plugin = Plugins.AllPlugins.FirstOrDefault(o => o.Metadata.ID == pluginId); + if (plugin == null) + { + MessageBox.Show("Can't find specific plugin"); + 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)) + { + MessageBox.Show("New ActionKeyword can't be empty"); + return; + } + + //check new action keyword didn't used by other plugin + if (Plugins.AllPlugins.Exists(o => o.Metadata.ActionKeyword == tbAction.Text.Trim())) + { + MessageBox.Show("New ActionKeyword has been assigned to other plugin, please assign another new action keyword"); + 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(); + MessageBox.Show("Sucessfully applied the new action keyword"); + Close(); + } + + + } +} diff --git a/Wox/PluginLoader/BasePluginLoader.cs b/Wox/PluginLoader/BasePluginLoader.cs index e88cc41d7..6e13fec2b 100644 --- a/Wox/PluginLoader/BasePluginLoader.cs +++ b/Wox/PluginLoader/BasePluginLoader.cs @@ -6,6 +6,7 @@ using System.Windows.Forms; using Newtonsoft.Json; using Wox.Helper; +using Wox.Infrastructure.Storage.UserSettings; using Wox.Plugin; using Wox.Plugin.SystemPlugins; @@ -104,6 +105,13 @@ private static PluginMetadata GetMetadataFromJson(string pluginDirectory) { return null; } + var customizedPluginConfig = + UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == metadata.ID); + if (customizedPluginConfig != null && !string.IsNullOrEmpty(customizedPluginConfig.Actionword)) + { + metadata.ActionKeyword = customizedPluginConfig.Actionword; + } + return metadata; } } diff --git a/Wox/SettingWindow.xaml b/Wox/SettingWindow.xaml index d79dc8590..d852a96da 100644 --- a/Wox/SettingWindow.xaml +++ b/Wox/SettingWindow.xaml @@ -124,7 +124,10 @@ - + + ActionKeyword: + + diff --git a/Wox/SettingWindow.xaml.cs b/Wox/SettingWindow.xaml.cs index 97a0375dc..5608b2739 100644 --- a/Wox/SettingWindow.xaml.cs +++ b/Wox/SettingWindow.xaml.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Windows; using System.Windows.Controls; +using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using IWshRuntimeLibrary; @@ -433,7 +434,7 @@ private void lbPlugins_OnSelectionChanged(object sender, SelectionChangedEventAr pluginActionKeyword.Visibility = Visibility.Visible; pluginWebsite.Visibility = Visibility.Visible; pluginTitle.Text = pair.Metadata.Name; - pluginActionKeyword.Text = "ActionKeyword: " + pair.Metadata.ActionKeyword; + pluginActionKeyword.Text = pair.Metadata.ActionKeyword; pluginAuthor.Text = "Author: " + pair.Metadata.Author; pluginWebsite.Text = "Website: " + pair.Metadata.Website; pluginSubTitle.Text = pair.Metadata.Description; @@ -532,5 +533,22 @@ private void CbDisablePlugin_OnClick(object sender, RoutedEventArgs e) } UserSettingStorage.Instance.Save(); } + + private void PluginActionKeyword_OnMouseUp(object sender, MouseButtonEventArgs e) + { + if (e.ChangedButton == MouseButton.Left) + { + var pair = lbPlugins.SelectedItem as PluginPair; + if (pair != null) + { + //third-party plugin + string id = pair.Metadata.ID; + ActionKeyword changeKeywordWindow = new ActionKeyword(id); + changeKeywordWindow.ShowDialog(); + PluginPair plugin = Plugins.AllPlugins.FirstOrDefault(o => o.Metadata.ID == id); + if (plugin != null) pluginActionKeyword.Text = plugin.Metadata.ActionKeyword; + } + } + } } } diff --git a/Wox/Wox.csproj b/Wox/Wox.csproj index 5a7a65113..53e586e22 100644 --- a/Wox/Wox.csproj +++ b/Wox/Wox.csproj @@ -105,6 +105,9 @@ MSBuild:Compile Designer + + ActionKeyword.xaml + @@ -152,6 +155,10 @@ + + Designer + MSBuild:Compile + Designer MSBuild:Compile