Enable multiple action keywords

See issue #352
This commit is contained in:
bao-qian 2015-11-04 22:49:40 +00:00
parent 59a4abff7c
commit a07d6aa1e7
25 changed files with 95 additions and 112 deletions

View File

@ -12,7 +12,7 @@ using Control = System.Windows.Controls.Control;
namespace Wox.Plugin.CMD namespace Wox.Plugin.CMD
{ {
public class CMD : IPlugin, ISettingProvider, IPluginI18n, IInstantQuery, IExclusiveQuery, IContextMenu public class CMD : IPlugin, ISettingProvider, IPluginI18n, IInstantQuery, IContextMenu
{ {
private PluginInitContext context; private PluginInitContext context;
private bool WinRStroked; private bool WinRStroked;
@ -202,11 +202,6 @@ namespace Wox.Plugin.CMD
public bool IsInstantQuery(string query) => false; public bool IsInstantQuery(string query) => false;
public bool IsExclusiveQuery(Query query)
{
return query.Search.StartsWith(">");
}
public List<Result> LoadContextMenus(Result selectedResult) public List<Result> LoadContextMenus(Result selectedResult)
{ {
return new List<Result>() return new List<Result>()

View File

@ -23,7 +23,7 @@
<system:String x:Key="wox_plugin_websearch_input_title">Please input title</system:String> <system:String x:Key="wox_plugin_websearch_input_title">Please input title</system:String>
<system:String x:Key="wox_plugin_websearch_input_action_keyword">Please input action keyword</system:String> <system:String x:Key="wox_plugin_websearch_input_action_keyword">Please input action keyword</system:String>
<system:String x:Key="wox_plugin_websearch_input_url">Please input URL</system:String> <system:String x:Key="wox_plugin_websearch_input_url">Please input URL</system:String>
<system:String x:Key="wox_plugin_websearch_action_keyword_exist">ActionWord has existed, please input a new one</system:String> <system:String x:Key="wox_plugin_websearch_action_keyword_exist">ActionKeyword has existed, please input a new one</system:String>
<system:String x:Key="wox_plugin_websearch_succeed">Succeed</system:String> <system:String x:Key="wox_plugin_websearch_succeed">Succeed</system:String>
<system:String x:Key="wox_plugin_websearch_plugin_name">Web Searches</system:String> <system:String x:Key="wox_plugin_websearch_plugin_name">Web Searches</system:String>

View File

@ -6,7 +6,7 @@ namespace Wox.Plugin.WebSearch
public class WebSearch public class WebSearch
{ {
public string Title { get; set; } public string Title { get; set; }
public string ActionWord { get; set; } public string ActionKeyword { get; set; }
public string IconPath { get; set; } public string IconPath { get; set; }
public string Url { get; set; } public string Url { get; set; }
public bool Enabled { get; set; } public bool Enabled { get; set; }

View File

@ -8,7 +8,7 @@ using Wox.Plugin.WebSearch.SuggestionSources;
namespace Wox.Plugin.WebSearch namespace Wox.Plugin.WebSearch
{ {
public class WebSearchPlugin : IPlugin, ISettingProvider, IPluginI18n, IInstantQuery, IExclusiveQuery public class WebSearchPlugin : IPlugin, ISettingProvider, IPluginI18n, IInstantQuery
{ {
private PluginInitContext context; private PluginInitContext context;
private IDisposable suggestionTimer; private IDisposable suggestionTimer;
@ -16,17 +16,12 @@ namespace Wox.Plugin.WebSearch
public List<Result> Query(Query query) public List<Result> Query(Query query)
{ {
List<Result> results = new List<Result>(); List<Result> results = new List<Result>();
if (!query.Search.Contains(' '))
{
return results;
}
WebSearch webSearch = WebSearch webSearch =
WebSearchStorage.Instance.WebSearches.FirstOrDefault(o => o.ActionWord == query.FirstSearch.Trim() && o.Enabled); WebSearchStorage.Instance.WebSearches.FirstOrDefault(o => o.ActionKeyword == query.ActionKeyword && o.Enabled);
if (webSearch != null) if (webSearch != null)
{ {
string keyword = query.SecondToEndSearch; string keyword = query.ActionKeyword;
string title = keyword; string title = keyword;
string subtitle = context.API.GetTranslation("wox_plugin_websearch_search") + " " + webSearch.Title; string subtitle = context.API.GetTranslation("wox_plugin_websearch_search") + " " + webSearch.Title;
if (string.IsNullOrEmpty(keyword)) if (string.IsNullOrEmpty(keyword))
@ -122,14 +117,5 @@ namespace Wox.Plugin.WebSearch
public bool IsInstantQuery(string query) => false; public bool IsInstantQuery(string query) => false;
public bool IsExclusiveQuery(Query query)
{
var strings = query.RawQuery.Split(' ');
if (strings.Length > 1)
{
return WebSearchStorage.Instance.WebSearches.Exists(o => o.ActionWord == strings[0] && o.Enabled);
}
return false;
}
} }
} }

View File

@ -42,7 +42,7 @@ namespace Wox.Plugin.WebSearch
cbEnable.IsChecked = webSearch.Enabled; cbEnable.IsChecked = webSearch.Enabled;
tbTitle.Text = webSearch.Title; tbTitle.Text = webSearch.Title;
tbUrl.Text = webSearch.Url; tbUrl.Text = webSearch.Url;
tbActionword.Text = webSearch.ActionWord; tbActionword.Text = webSearch.ActionKeyword;
} }
private void ShowIcon(string path) private void ShowIcon(string path)
@ -90,7 +90,7 @@ namespace Wox.Plugin.WebSearch
if (!update) if (!update)
{ {
if (WebSearchStorage.Instance.WebSearches.Exists(o => o.ActionWord == action)) if (WebSearchStorage.Instance.WebSearches.Exists(o => o.ActionKeyword == action))
{ {
string warning = context.API.GetTranslation("wox_plugin_websearch_action_keyword_exist"); string warning = context.API.GetTranslation("wox_plugin_websearch_action_keyword_exist");
MessageBox.Show(warning); MessageBox.Show(warning);
@ -98,7 +98,7 @@ namespace Wox.Plugin.WebSearch
} }
WebSearchStorage.Instance.WebSearches.Add(new WebSearch() WebSearchStorage.Instance.WebSearches.Add(new WebSearch()
{ {
ActionWord = action, ActionKeyword = action,
Enabled = cbEnable.IsChecked ?? false, Enabled = cbEnable.IsChecked ?? false,
IconPath = tbIconPath.Text, IconPath = tbIconPath.Text,
Url = url, Url = url,
@ -109,13 +109,13 @@ namespace Wox.Plugin.WebSearch
} }
else else
{ {
if (WebSearchStorage.Instance.WebSearches.Exists(o => o.ActionWord == action && o != updateWebSearch)) if (WebSearchStorage.Instance.WebSearches.Exists(o => o.ActionKeyword == action && o != updateWebSearch))
{ {
string warning = context.API.GetTranslation("wox_plugin_websearch_action_keyword_exist"); string warning = context.API.GetTranslation("wox_plugin_websearch_action_keyword_exist");
MessageBox.Show(warning); MessageBox.Show(warning);
return; return;
} }
updateWebSearch.ActionWord = action; updateWebSearch.ActionKeyword = action;
updateWebSearch.IconPath = tbIconPath.Text; updateWebSearch.IconPath = tbIconPath.Text;
updateWebSearch.Enabled = cbEnable.IsChecked ?? false; updateWebSearch.Enabled = cbEnable.IsChecked ?? false;
updateWebSearch.Url = url; updateWebSearch.Url = url;

View File

@ -40,7 +40,7 @@ namespace Wox.Plugin.WebSearch
WebSearch googleWebSearch = new WebSearch() WebSearch googleWebSearch = new WebSearch()
{ {
Title = "Google", Title = "Google",
ActionWord = "g", ActionKeyword = "g",
IconPath = @"Images\websearch\google.png", IconPath = @"Images\websearch\google.png",
Url = "https://www.google.com/search?q={q}", Url = "https://www.google.com/search?q={q}",
Enabled = true Enabled = true
@ -51,7 +51,7 @@ namespace Wox.Plugin.WebSearch
WebSearch wikiWebSearch = new WebSearch() WebSearch wikiWebSearch = new WebSearch()
{ {
Title = "Wikipedia", Title = "Wikipedia",
ActionWord = "wiki", ActionKeyword = "wiki",
IconPath = @"Images\websearch\wiki.png", IconPath = @"Images\websearch\wiki.png",
Url = "http://en.wikipedia.org/wiki/{q}", Url = "http://en.wikipedia.org/wiki/{q}",
Enabled = true Enabled = true
@ -61,7 +61,7 @@ namespace Wox.Plugin.WebSearch
WebSearch findIcon = new WebSearch() WebSearch findIcon = new WebSearch()
{ {
Title = "FindIcon", Title = "FindIcon",
ActionWord = "findicon", ActionKeyword = "findicon",
IconPath = @"Images\websearch\pictures.png", IconPath = @"Images\websearch\pictures.png",
Url = "http://findicons.com/search/{q}", Url = "http://findicons.com/search/{q}",
Enabled = true Enabled = true

View File

@ -22,7 +22,7 @@
<GridViewColumn Header="{DynamicResource wox_plugin_websearch_action_keyword}" Width="180"> <GridViewColumn Header="{DynamicResource wox_plugin_websearch_action_keyword}" Width="180">
<GridViewColumn.CellTemplate> <GridViewColumn.CellTemplate>
<DataTemplate> <DataTemplate>
<TextBlock Text="{Binding ActionWord}"/> <TextBlock Text="{Binding ActionKeyword}"/>
</DataTemplate> </DataTemplate>
</GridViewColumn.CellTemplate> </GridViewColumn.CellTemplate>
</GridViewColumn> </GridViewColumn>

View File

@ -59,7 +59,7 @@
<Compile Include="WebSearchesSetting.xaml.cs"> <Compile Include="WebSearchesSetting.xaml.cs">
<DependentUpon>WebSearchesSetting.xaml</DependentUpon> <DependentUpon>WebSearchesSetting.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="WebQueryPlugin.cs" /> <Compile Include="WebSearchPlugin.cs" />
<Compile Include="WebSearchSetting.xaml.cs"> <Compile Include="WebSearchSetting.xaml.cs">
<DependentUpon>WebSearchSetting.xaml</DependentUpon> <DependentUpon>WebSearchSetting.xaml</DependentUpon>
</Compile> </Compile>
@ -135,5 +135,4 @@
<Target Name="AfterBuild"> <Target Name="AfterBuild">
</Target> </Target>
--> -->
</Project> </Project>

View File

@ -1,6 +1,6 @@
{ {
"ID":"565B73353DBF4806919830B9202EE3BF", "ID":"565B73353DBF4806919830B9202EE3BF",
"ActionKeyword":"*", "ActionKeywords": ["g", "wiki", "findicon"],
"Name":"Web Searches", "Name":"Web Searches",
"Description":"Provide the web search ability", "Description":"Provide the web search ability",
"Author":"qianlifeng", "Author":"qianlifeng",

View File

@ -72,6 +72,10 @@ namespace Wox.Core.Plugin
{ {
metadata = JsonConvert.DeserializeObject<PluginMetadata>(File.ReadAllText(configPath)); metadata = JsonConvert.DeserializeObject<PluginMetadata>(File.ReadAllText(configPath));
metadata.PluginDirectory = pluginDirectory; metadata.PluginDirectory = pluginDirectory;
// for plugins which doesn't has ActionKeywords key
metadata.ActionKeywords = metadata.ActionKeywords ?? new[] {metadata.ActionKeyword};
// for plugin still use old ActionKeyword
metadata.ActionKeyword = metadata.ActionKeywords?[0];
} }
catch (System.Exception) catch (System.Exception)
{ {
@ -112,9 +116,10 @@ namespace Wox.Core.Plugin
//replace action keyword if user customized it. //replace action keyword if user customized it.
var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == metadata.ID); var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == metadata.ID);
if (customizedPluginConfig != null && !string.IsNullOrEmpty(customizedPluginConfig.Actionword)) if (customizedPluginConfig?.ActionKeywords?.Length > 0)
{ {
metadata.ActionKeyword = customizedPluginConfig.Actionword; metadata.ActionKeywords = customizedPluginConfig.ActionKeywords;
metadata.ActionKeyword = customizedPluginConfig.ActionKeywords[0]; //todo reenable
} }
return metadata; return metadata;

View File

@ -1,11 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Threading; using System.Threading;
using System.Windows.Documents;
using Wox.Core.Exception; using Wox.Core.Exception;
using Wox.Core.i18n; using Wox.Core.i18n;
using Wox.Core.UI; using Wox.Core.UI;
@ -110,7 +108,6 @@ namespace Wox.Core.Plugin
ThreadPool.QueueUserWorkItem(o => ThreadPool.QueueUserWorkItem(o =>
{ {
instantQueryPlugins = GetPlugins<IInstantQuery>(); instantQueryPlugins = GetPlugins<IInstantQuery>();
exclusiveSearchPlugins = GetPlugins<IExclusiveQuery>();
contextMenuPlugins = GetPlugins<IContextMenu>(); contextMenuPlugins = GetPlugins<IContextMenu>();
}); });
} }
@ -123,8 +120,8 @@ namespace Wox.Core.Plugin
public static Query QueryInit(string text) //todo is that possible to move it into type Query? public static Query QueryInit(string text) //todo is that possible to move it into type Query?
{ {
// replace multiple white spaces with one white space // replace multiple white spaces with one white space
var terms = text.Split(new[] { Query.Seperater }, StringSplitOptions.RemoveEmptyEntries); var terms = text.Split(new[] { Query.TermSeperater }, StringSplitOptions.RemoveEmptyEntries);
var rawQuery = string.Join(Query.Seperater, terms.ToArray()); var rawQuery = string.Join(Query.TermSeperater, terms.ToArray());
var actionKeyword = string.Empty; var actionKeyword = string.Empty;
var search = rawQuery; var search = rawQuery;
IEnumerable<string> actionParameters = terms; IEnumerable<string> actionParameters = terms;
@ -136,7 +133,7 @@ namespace Wox.Core.Plugin
if (!string.IsNullOrEmpty(actionKeyword)) if (!string.IsNullOrEmpty(actionKeyword))
{ {
actionParameters = terms.Skip(1); actionParameters = terms.Skip(1);
search = string.Join(Query.Seperater, actionParameters.ToArray()); search = string.Join(Query.TermSeperater, actionParameters.ToArray());
} }
return new Query return new Query
{ {
@ -204,7 +201,7 @@ namespace Wox.Core.Plugin
private static bool IsVailldActionKeyword(string actionKeyword) private static bool IsVailldActionKeyword(string actionKeyword)
{ {
if (string.IsNullOrEmpty(actionKeyword) || actionKeyword == Query.WildcardSign) return false; if (string.IsNullOrEmpty(actionKeyword) || actionKeyword == Query.WildcardSign) return false;
PluginPair pair = AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == actionKeyword); PluginPair pair = AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeywords.Contains(actionKeyword));
if (pair == null) return false; if (pair == null) return false;
var customizedPluginConfig = UserSettingStorage.Instance. var customizedPluginConfig = UserSettingStorage.Instance.
CustomizedPluginConfigs.FirstOrDefault(o => o.ID == pair.Metadata.ID); CustomizedPluginConfigs.FirstOrDefault(o => o.ID == pair.Metadata.ID);
@ -213,7 +210,7 @@ namespace Wox.Core.Plugin
public static bool IsSystemPlugin(PluginMetadata metadata) public static bool IsSystemPlugin(PluginMetadata metadata)
{ {
return metadata.ActionKeyword == Query.WildcardSign; return metadata.ActionKeywords.Contains(Query.WildcardSign);
} }
private static bool IsInstantQueryPlugin(PluginPair plugin) private static bool IsInstantQueryPlugin(PluginPair plugin)
@ -239,21 +236,11 @@ namespace Wox.Core.Plugin
return AllPlugins.Where(p => p.Plugin is T); return AllPlugins.Where(p => p.Plugin is T);
} }
private static PluginPair GetExclusivePlugin(Query query)
{
return exclusiveSearchPlugins.FirstOrDefault(p => ((IExclusiveQuery)p.Plugin).IsExclusiveQuery(query));
}
private static PluginPair GetActionKeywordPlugin(Query query)
{
//if a query doesn't contain a vaild action keyword, it should not be a action keword plugin query
if (string.IsNullOrEmpty(query.ActionKeyword)) return null;
return AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == query.ActionKeyword);
}
private static PluginPair GetNonSystemPlugin(Query query) private static PluginPair GetNonSystemPlugin(Query query)
{ {
return GetExclusivePlugin(query) ?? GetActionKeywordPlugin(query); //if a query doesn't contain a vaild action keyword, it should be a query for system plugin
if (string.IsNullOrEmpty(query.ActionKeyword)) return null;
return AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeywords.Contains(query.ActionKeyword));
} }
private static List<PluginPair> GetSystemPlugins() private static List<PluginPair> GetSystemPlugins()

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
namespace Wox.Core.UserSettings namespace Wox.Core.UserSettings
{ {
@ -9,7 +10,7 @@ namespace Wox.Core.UserSettings
public string Name { get; set; } public string Name { get; set; }
public string Actionword { get; set; } public string[] ActionKeywords { get; set; }
public bool Disabled { get; set; } public bool Disabled { get; set; }
} }

View File

@ -10,8 +10,10 @@ namespace Wox.Plugin
List<Result> LoadContextMenus(Result selectedResult); List<Result> LoadContextMenus(Result selectedResult);
} }
[Obsolete("If a plugin has a action keyword, then it is exclusive. This interface will be remove in v1.3.0")]
public interface IExclusiveQuery : IFeatures public interface IExclusiveQuery : IFeatures
{ {
[Obsolete("If a plugin has a action keyword, then it is exclusive. This method will be remove in v1.3.0")]
bool IsExclusiveQuery(Query query); bool IsExclusiveQuery(Query query);
} }

View File

@ -1,5 +1,6 @@
using System; using System;
using System.IO; using System.IO;
using System.Collections.Generic;
namespace Wox.Plugin namespace Wox.Plugin
{ {
@ -23,8 +24,11 @@ namespace Wox.Plugin
public string PluginDirectory { get; set; } public string PluginDirectory { get; set; }
[Obsolete("Use ActionKeywords instead, because Wox now support multiple action keywords. This will be remove in v1.3.0")]
public string ActionKeyword { get; set; } public string ActionKeyword { get; set; }
public string[] ActionKeywords { get; set; }
public string IcoPath { get; set; } public string IcoPath { get; set; }
public override string ToString() public override string ToString()

View File

@ -25,14 +25,15 @@ namespace Wox.Plugin
/// </summary> /// </summary>
internal string[] Terms { private get; set; } internal string[] Terms { private get; set; }
public const string Seperater = " "; public const string TermSeperater = " ";
public const string ActionKeywordSeperater = ";";
/// <summary> /// <summary>
/// * is used for System Plugin /// * is used for System Plugin
/// </summary> /// </summary>
public const string WildcardSign = "*"; public const string WildcardSign = "*";
internal string ActionKeyword { get; set; } public string ActionKeyword { get; set; }
/// <summary> /// <summary>
/// Return first search split by space if it has /// Return first search split by space if it has
@ -46,8 +47,8 @@ namespace Wox.Plugin
{ {
get get
{ {
var index = String.IsNullOrEmpty(ActionKeyword) ? 1 : 2; var index = string.IsNullOrEmpty(ActionKeyword) ? 1 : 2;
return String.Join(Seperater, Terms.Skip(index).ToArray()); return string.Join(TermSeperater, Terms.Skip(index).ToArray());
} }
} }
@ -65,18 +66,17 @@ namespace Wox.Plugin
{ {
try try
{ {
return String.IsNullOrEmpty(ActionKeyword) ? Terms[index] : Terms[index + 1]; return string.IsNullOrEmpty(ActionKeyword) ? Terms[index] : Terms[index + 1];
} }
catch (IndexOutOfRangeException) catch (IndexOutOfRangeException)
{ {
return String.Empty; return string.Empty;
} }
} }
public override string ToString() => RawQuery; public override string ToString() => RawQuery;
[Obsolete("Use Search instead, A plugin developer shouldn't care about action name, as it may changed by users. " + [Obsolete("Use ActionKeyword, this property will be removed in v1.3.0")]
"this property will be removed in v1.3.0")]
public string ActionName { get; internal set; } public string ActionName { get; internal set; }
[Obsolete("Use Search instead, this property will be removed in v1.3.0")] [Obsolete("Use Search instead, this property will be removed in v1.3.0")]

View File

@ -1,7 +1,7 @@
<Window x:Class="Wox.ActionKeyword" <Window x:Class="Wox.ActionKeywords"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ActionKeyword" Title="ActionKeywords"
Icon="Images\app.png" Icon="Images\app.png"
ResizeMode="NoResize" ResizeMode="NoResize"
Loaded="ActionKeyword_OnLoaded" Loaded="ActionKeyword_OnLoaded"
@ -19,7 +19,7 @@
<ColumnDefinition></ColumnDefinition> <ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<TextBlock Margin="10" FontSize="14" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right" Text="{DynamicResource oldActionKeyword}"></TextBlock> <TextBlock Margin="10" FontSize="14" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right" Text="{DynamicResource oldActionKeyword}"></TextBlock>
<TextBlock x:Name="tbOldActionKeyword" Margin="10" FontSize="14" Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left">Old ActionKeyword:</TextBlock> <TextBlock x:Name="tbOldActionKeyword" Margin="10" FontSize="14" Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left">Old ActionKeywords:</TextBlock>
<TextBlock Margin="10" FontSize="14" Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right" Text="{DynamicResource newActionKeyword}"></TextBlock> <TextBlock Margin="10" FontSize="14" Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right" Text="{DynamicResource newActionKeyword}"></TextBlock>
<StackPanel Grid.Row="1" Orientation="Horizontal" Grid.Column="1" > <StackPanel Grid.Row="1" Orientation="Horizontal" Grid.Column="1" >

View File

@ -1,4 +1,5 @@
using System.Linq; using System;
using System.Linq;
using System.Windows; using System.Windows;
using Wox.Core.i18n; using Wox.Core.i18n;
using Wox.Core.Plugin; using Wox.Core.Plugin;
@ -7,11 +8,11 @@ using Wox.Plugin;
namespace Wox namespace Wox
{ {
public partial class ActionKeyword : Window public partial class ActionKeywords : Window
{ {
private PluginMetadata pluginMetadata; private PluginMetadata pluginMetadata;
public ActionKeyword(string pluginId) public ActionKeywords(string pluginId)
{ {
InitializeComponent(); InitializeComponent();
PluginPair plugin = PluginManager.GetPlugin(pluginId); PluginPair plugin = PluginManager.GetPlugin(pluginId);
@ -27,7 +28,7 @@ namespace Wox
private void ActionKeyword_OnLoaded(object sender, RoutedEventArgs e) private void ActionKeyword_OnLoaded(object sender, RoutedEventArgs e)
{ {
tbOldActionKeyword.Text = pluginMetadata.ActionKeyword; tbOldActionKeyword.Text = string.Join(Query.ActionKeywordSeperater, pluginMetadata.ActionKeywords);
tbAction.Focus(); tbAction.Focus();
} }
@ -44,15 +45,18 @@ namespace Wox
return; return;
} }
var actionKeywords = tbAction.Text.Trim().Split(new[] { Query.ActionKeywordSeperater }, StringSplitOptions.RemoveEmptyEntries).ToArray();
//check new action keyword didn't used by other plugin //check new action keyword didn't used by other plugin
if (tbAction.Text.Trim() != Query.WildcardSign && PluginManager.AllPlugins.Any(o => o.Metadata.ActionKeyword == tbAction.Text.Trim())) if (actionKeywords[0] != Query.WildcardSign && PluginManager.AllPlugins.
SelectMany(p => p.Metadata.ActionKeywords).
Any(k => actionKeywords.Contains(k)))
{ {
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("newActionKeywordHasBeenAssigned")); MessageBox.Show(InternationalizationManager.Instance.GetTranslation("newActionKeywordHasBeenAssigned"));
return; return;
} }
pluginMetadata.ActionKeyword = tbAction.Text.Trim(); pluginMetadata.ActionKeywords = actionKeywords;
var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == pluginMetadata.ID); var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == pluginMetadata.ID);
if (customizedPluginConfig == null) if (customizedPluginConfig == null)
{ {
@ -61,12 +65,12 @@ namespace Wox
Disabled = false, Disabled = false,
ID = pluginMetadata.ID, ID = pluginMetadata.ID,
Name = pluginMetadata.Name, Name = pluginMetadata.Name,
Actionword = tbAction.Text.Trim() ActionKeywords = actionKeywords
}); });
} }
else else
{ {
customizedPluginConfig.Actionword = tbAction.Text.Trim(); customizedPluginConfig.ActionKeywords = actionKeywords;
} }
UserSettingStorage.Instance.Save(); UserSettingStorage.Instance.Save();
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("succeed")); MessageBox.Show(InternationalizationManager.Instance.GetTranslation("succeed"));

View File

@ -6,7 +6,7 @@ using System.Windows;
using Wox.CommandArgs; using Wox.CommandArgs;
using Wox.Core.Plugin; using Wox.Core.Plugin;
using Wox.Helper; using Wox.Helper;
using Wox.Infrastructure; using Stopwatch = Wox.Infrastructure.Stopwatch;
namespace Wox namespace Wox
{ {

View File

@ -77,13 +77,13 @@
<system:String x:Key="about_activate_times">You have activated Wox {0} times</system:String> <system:String x:Key="about_activate_times">You have activated Wox {0} times</system:String>
<!--Action Keyword Setting Dialog--> <!--Action Keyword Setting Dialog-->
<system:String x:Key="oldActionKeyword">Old Action Keyword</system:String> <system:String x:Key="oldActionKeywords">Old Action Keyword</system:String>
<system:String x:Key="newActionKeyword">New Action Keyword</system:String> <system:String x:Key="newActionKeywords">New Action Keyword</system:String>
<system:String x:Key="cancel">Cancel</system:String> <system:String x:Key="cancel">Cancel</system:String>
<system:String x:Key="done">Done</system:String> <system:String x:Key="done">Done</system:String>
<system:String x:Key="cannotFindSpecifiedPlugin">Can't find specified plugin</system:String> <system:String x:Key="cannotFindSpecifiedPlugin">Can't find specified plugin</system:String>
<system:String x:Key="newActionKeywordCannotBeEmpty">New Action Keyword can't be empty</system:String> <system:String x:Key="newActionKeywordsCannotBeEmpty">New Action Keyword can't be empty</system:String>
<system:String x:Key="newActionKeywordHasBeenAssigned">New ActionKeyword has been assigned to other plugin, please assign another new action keyword</system:String> <system:String x:Key="newActionKeywordsHasBeenAssigned">New ActionKeywords has been assigned to other plugin, please assign another new action keyword</system:String>
<system:String x:Key="succeed">Succeed</system:String> <system:String x:Key="succeed">Succeed</system:String>
<system:String x:Key="actionkeyword_tips">Use * if you don't want to specify a action keyword</system:String> <system:String x:Key="actionkeyword_tips">Use * if you don't want to specify a action keyword</system:String>

View File

@ -77,13 +77,13 @@
<system:String x:Key="about_activate_times">Вы воспользовались Wox уже {0} раз</system:String> <system:String x:Key="about_activate_times">Вы воспользовались Wox уже {0} раз</system:String>
<!--Action Keyword Setting Dialog--> <!--Action Keyword Setting Dialog-->
<system:String x:Key="oldActionKeyword">Текущая горячая клавиша</system:String> <system:String x:Key="oldActionKeywords">Текущая горячая клавиша</system:String>
<system:String x:Key="newActionKeyword">Новая горячая клавиша</system:String> <system:String x:Key="newActionKeywords">Новая горячая клавиша</system:String>
<system:String x:Key="cancel">Отменить</system:String> <system:String x:Key="cancel">Отменить</system:String>
<system:String x:Key="done">Подтвердить</system:String> <system:String x:Key="done">Подтвердить</system:String>
<system:String x:Key="cannotFindSpecifiedPlugin">Не удалось найти заданный плагин</system:String> <system:String x:Key="cannotFindSpecifiedPlugin">Не удалось найти заданный плагин</system:String>
<system:String x:Key="newActionKeywordCannotBeEmpty">Новая горячая клавиша не может быть пустой</system:String> <system:String x:Key="newActionKeywordsCannotBeEmpty">Новая горячая клавиша не может быть пустой</system:String>
<system:String x:Key="newActionKeywordHasBeenAssigned">Новая горячая клавиша уже используется другим плагином. Пожалуйста, зайдайте новую</system:String> <system:String x:Key="newActionKeywordsHasBeenAssigned">Новая горячая клавиша уже используется другим плагином. Пожалуйста, зайдайте новую</system:String>
<system:String x:Key="succeed">Сохранено</system:String> <system:String x:Key="succeed">Сохранено</system:String>
<system:String x:Key="actionkeyword_tips">Используйте * в случае, если вы не хотите задавать конкретную горячую клавишу</system:String> <system:String x:Key="actionkeyword_tips">Используйте * в случае, если вы не хотите задавать конкретную горячую клавишу</system:String>

View File

@ -77,13 +77,13 @@
<system:String x:Key="about_activate_times">你已经激活了Wox {0} 次</system:String> <system:String x:Key="about_activate_times">你已经激活了Wox {0} 次</system:String>
<!--Action Keyword 设置对话框--> <!--Action Keyword 设置对话框-->
<system:String x:Key="oldActionKeyword">旧触发关键字</system:String> <system:String x:Key="oldActionKeywords">旧触发关键字</system:String>
<system:String x:Key="newActionKeyword">新触发关键字</system:String> <system:String x:Key="newActionKeywords">新触发关键字</system:String>
<system:String x:Key="cancel">取消</system:String> <system:String x:Key="cancel">取消</system:String>
<system:String x:Key="done">确定</system:String> <system:String x:Key="done">确定</system:String>
<system:String x:Key="cannotFindSpecifiedPlugin">找不到指定的插件</system:String> <system:String x:Key="cannotFindSpecifiedPlugin">找不到指定的插件</system:String>
<system:String x:Key="newActionKeywordCannotBeEmpty">新触发关键字不能为空</system:String> <system:String x:Key="newActionKeywordsCannotBeEmpty">新触发关键字不能为空</system:String>
<system:String x:Key="newActionKeywordHasBeenAssigned">新触发关键字已经被指派给其他插件了,请重新选择一个关键字</system:String> <system:String x:Key="newActionKeywordsHasBeenAssigned">新触发关键字已经被指派给其他插件了,请重新选择一个关键字</system:String>
<system:String x:Key="succeed">成功</system:String> <system:String x:Key="succeed">成功</system:String>
<system:String x:Key="actionkeyword_tips">如果你不想设置触发关键字,可以使用*代替</system:String> <system:String x:Key="actionkeyword_tips">如果你不想设置触发关键字,可以使用*代替</system:String>

View File

@ -77,13 +77,13 @@
<system:String x:Key="about_activate_times">你已經激活了Wox {0} 次</system:String> <system:String x:Key="about_activate_times">你已經激活了Wox {0} 次</system:String>
<!--Action Keyword 設置對話框--> <!--Action Keyword 設置對話框-->
<system:String x:Key="oldActionKeyword">舊觸發關鍵字</system:String> <system:String x:Key="oldActionKeywords">舊觸發關鍵字</system:String>
<system:String x:Key="newActionKeyword">新觸發關鍵字</system:String> <system:String x:Key="newActionKeywords">新觸發關鍵字</system:String>
<system:String x:Key="cancel">取消</system:String> <system:String x:Key="cancel">取消</system:String>
<system:String x:Key="done">確定</system:String> <system:String x:Key="done">確定</system:String>
<system:String x:Key="cannotFindSpecifiedPlugin">找不到指定的插件</system:String> <system:String x:Key="cannotFindSpecifiedPlugin">找不到指定的插件</system:String>
<system:String x:Key="newActionKeywordCannotBeEmpty">新觸發關鍵字不能為空</system:String> <system:String x:Key="newActionKeywordsCannotBeEmpty">新觸發關鍵字不能為空</system:String>
<system:String x:Key="newActionKeywordHasBeenAssigned">新觸發關鍵字已經被指派給其他插件了,請重新選擇一個關鍵字</system:String> <system:String x:Key="newActionKeywordsHasBeenAssigned">新觸發關鍵字已經被指派給其他插件了,請重新選擇一個關鍵字</system:String>
<system:String x:Key="succeed">成功</system:String> <system:String x:Key="succeed">成功</system:String>
<system:String x:Key="actionkeyword_tips">如果你不想設置觸發關鍵字,可以使用*代替</system:String> <system:String x:Key="actionkeyword_tips">如果你不想設置觸發關鍵字,可以使用*代替</system:String>

View File

@ -109,7 +109,7 @@
<TextBlock x:Name="pluginActionKeywordTitle" Margin="20 0 0 0"> <TextBlock x:Name="pluginActionKeywordTitle" Margin="20 0 0 0">
<TextBlock Text="{DynamicResource actionKeyword}"></TextBlock> <TextBlock Text="{DynamicResource actionKeyword}"></TextBlock>
</TextBlock> </TextBlock>
<TextBlock Margin="5 0 0 0" ToolTip="Change Action Keyword" Cursor="Hand" MouseUp="PluginActionKeyword_OnMouseUp" Foreground="Blue" Text="key" x:Name="pluginActionKeyword"></TextBlock> <TextBlock Margin="5 0 0 0" ToolTip="Change Action Keyword" Cursor="Hand" MouseUp="PluginActionKeywords_OnMouseUp" Foreground="Blue" Text="key" x:Name="pluginActionKeywords"></TextBlock>
<TextBlock Margin="10 0 0 0" Text="Init time: 0ms" x:Name="pluginInitTime"></TextBlock> <TextBlock Margin="10 0 0 0" Text="Init time: 0ms" x:Name="pluginInitTime"></TextBlock>
<TextBlock Margin="10 0 0 0" Text="Query time: 0ms" x:Name="pluginQueryTime"></TextBlock> <TextBlock Margin="10 0 0 0" Text="Query time: 0ms" x:Name="pluginQueryTime"></TextBlock>
<TextBlock HorizontalAlignment="Right" Cursor="Hand" MouseUp="tbOpenPluginDirecoty_MouseUp" Foreground="Blue" Text="{DynamicResource pluginDirectory}" x:Name="tbOpenPluginDirecoty"></TextBlock> <TextBlock HorizontalAlignment="Right" Cursor="Hand" MouseUp="tbOpenPluginDirecoty_MouseUp" Foreground="Blue" Text="{DynamicResource pluginDirectory}" x:Name="tbOpenPluginDirecoty"></TextBlock>
@ -234,7 +234,7 @@
<GridViewColumn Header="{DynamicResource actionKeyword}" Width="500"> <GridViewColumn Header="{DynamicResource actionKeyword}" Width="500">
<GridViewColumn.CellTemplate> <GridViewColumn.CellTemplate>
<DataTemplate> <DataTemplate>
<TextBlock Text="{Binding ActionKeyword}"/> <TextBlock Text="{Binding ActionKeywords}"/>
</DataTemplate> </DataTemplate>
</GridViewColumn.CellTemplate> </GridViewColumn.CellTemplate>
</GridViewColumn> </GridViewColumn>

View File

@ -527,7 +527,7 @@ namespace Wox
{ {
provider = pair.Plugin as ISettingProvider; provider = pair.Plugin as ISettingProvider;
pluginAuthor.Visibility = Visibility.Visible; pluginAuthor.Visibility = Visibility.Visible;
pluginActionKeyword.Visibility = Visibility.Visible; pluginActionKeywords.Visibility = Visibility.Visible;
pluginInitTime.Text = pluginInitTime.Text =
string.Format(InternationalizationManager.Instance.GetTranslation("plugin_init_time"), pair.InitTime); string.Format(InternationalizationManager.Instance.GetTranslation("plugin_init_time"), pair.InitTime);
pluginQueryTime.Text = pluginQueryTime.Text =
@ -536,7 +536,7 @@ namespace Wox
tbOpenPluginDirecoty.Visibility = Visibility.Visible; tbOpenPluginDirecoty.Visibility = Visibility.Visible;
pluginTitle.Text = pair.Metadata.Name; pluginTitle.Text = pair.Metadata.Name;
pluginTitle.Cursor = Cursors.Hand; pluginTitle.Cursor = Cursors.Hand;
pluginActionKeyword.Text = pair.Metadata.ActionKeyword; pluginActionKeywords.Text = string.Join(Query.ActionKeywordSeperater, pair.Metadata.ActionKeywords);
pluginAuthor.Text = InternationalizationManager.Instance.GetTranslation("author") + ": " + pair.Metadata.Author; pluginAuthor.Text = InternationalizationManager.Instance.GetTranslation("author") + ": " + pair.Metadata.Author;
pluginSubTitle.Text = pair.Metadata.Description; pluginSubTitle.Text = pair.Metadata.Description;
pluginId = pair.Metadata.ID; pluginId = pair.Metadata.ID;
@ -578,12 +578,13 @@ namespace Wox
var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == id); var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == id);
if (customizedPluginConfig == null) if (customizedPluginConfig == null)
{ {
// todo when this part will be invoked
UserSettingStorage.Instance.CustomizedPluginConfigs.Add(new CustomizedPluginConfig() UserSettingStorage.Instance.CustomizedPluginConfigs.Add(new CustomizedPluginConfig()
{ {
Disabled = cbDisabled.IsChecked ?? true, Disabled = cbDisabled.IsChecked ?? true,
ID = id, ID = id,
Name = name, Name = name,
Actionword = string.Empty ActionKeywords = null
}); });
} }
else else
@ -593,7 +594,7 @@ namespace Wox
UserSettingStorage.Instance.Save(); UserSettingStorage.Instance.Save();
} }
private void PluginActionKeyword_OnMouseUp(object sender, MouseButtonEventArgs e) private void PluginActionKeywords_OnMouseUp(object sender, MouseButtonEventArgs e)
{ {
if (e.ChangedButton == MouseButton.Left) if (e.ChangedButton == MouseButton.Left)
{ {
@ -602,10 +603,10 @@ namespace Wox
{ {
//third-party plugin //third-party plugin
string id = pair.Metadata.ID; string id = pair.Metadata.ID;
ActionKeyword changeKeywordWindow = new ActionKeyword(id); ActionKeywords changeKeywordsWindow = new ActionKeywords(id);
changeKeywordWindow.ShowDialog(); changeKeywordsWindow.ShowDialog();
PluginPair plugin = PluginManager.GetPlugin(id); PluginPair plugin = PluginManager.GetPlugin(id);
if (plugin != null) pluginActionKeyword.Text = plugin.Metadata.ActionKeyword; if (plugin != null) pluginActionKeywords.Text = string.Join(Query.ActionKeywordSeperater, pair.Metadata.ActionKeywords);
} }
} }
} }

View File

@ -126,8 +126,8 @@
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
</Page> </Page>
<Compile Include="ActionKeyword.xaml.cs"> <Compile Include="ActionKeywords.xaml.cs">
<DependentUpon>ActionKeyword.xaml</DependentUpon> <DependentUpon>ActionKeywords.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="CommandArgs\CommandArgsFactory.cs" /> <Compile Include="CommandArgs\CommandArgsFactory.cs" />
<Compile Include="CommandArgs\HideStartCommandArg.cs" /> <Compile Include="CommandArgs\HideStartCommandArg.cs" />
@ -160,7 +160,7 @@
<Compile Include="SettingWindow.xaml.cs"> <Compile Include="SettingWindow.xaml.cs">
<DependentUpon>SettingWindow.xaml</DependentUpon> <DependentUpon>SettingWindow.xaml</DependentUpon>
</Compile> </Compile>
<Page Include="ActionKeyword.xaml"> <Page Include="ActionKeywords.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
@ -374,5 +374,4 @@ cd "$(TargetDir)Plugins" &amp; del /s /q WindowsInput.dll
<Target Name="AfterBuild"> <Target Name="AfterBuild">
</Target> </Target>
--> -->
</Project> </Project>