mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-23 19:49:43 +01:00
tmp
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Newtonsoft.Json;
|
||||
using Exceptionless.Json;
|
||||
using JsonProperty = Newtonsoft.Json.JsonPropertyAttribute;
|
||||
using Wox.Infrastructure.Storage;
|
||||
|
||||
namespace Wox.Plugin.Everything
|
||||
|
||||
@@ -13,10 +13,9 @@ namespace Wox.Plugin.PluginIndicator
|
||||
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
var results = from plugin in PluginManager.NonGlobalPlugins
|
||||
select plugin.Metadata into metadata
|
||||
from keyword in metadata.ActionKeywords
|
||||
var results = from keyword in PluginManager.NonGlobalPlugins.Keys
|
||||
where keyword.StartsWith(query.Terms[0])
|
||||
let metadata = PluginManager.NonGlobalPlugins[keyword].Metadata
|
||||
let customizedPluginConfig =
|
||||
UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == metadata.ID)
|
||||
where customizedPluginConfig == null || !customizedPluginConfig.Disabled
|
||||
|
||||
@@ -29,8 +29,8 @@ namespace Wox.Core.Plugin
|
||||
|
||||
public static IEnumerable<PluginPair> AllPlugins { get; private set; }
|
||||
|
||||
public static IEnumerable<PluginPair> GlobalPlugins { get; private set; }
|
||||
public static IEnumerable<PluginPair> NonGlobalPlugins { get; private set; }
|
||||
public static List<PluginPair> GlobalPlugins { get; } = new List<PluginPair>();
|
||||
public static Dictionary<string, PluginPair> NonGlobalPlugins { get; } = new Dictionary<string, PluginPair>();
|
||||
|
||||
private static IEnumerable<PluginPair> InstantQueryPlugins { get; set; }
|
||||
public static IPublicAPI API { private set; get; }
|
||||
@@ -104,8 +104,20 @@ namespace Wox.Core.Plugin
|
||||
{
|
||||
InstantQueryPlugins = GetPluginsForInterface<IInstantQuery>();
|
||||
contextMenuPlugins = GetPluginsForInterface<IContextMenu>();
|
||||
GlobalPlugins = AllPlugins.Where(p => IsGlobalPlugin(p.Metadata));
|
||||
NonGlobalPlugins = AllPlugins.Where(p => !IsGlobalPlugin(p.Metadata));
|
||||
foreach (var plugin in AllPlugins)
|
||||
{
|
||||
if (IsGlobalPlugin(plugin.Metadata))
|
||||
{
|
||||
GlobalPlugins.Add(plugin);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (string actionKeyword in plugin.Metadata.ActionKeywords)
|
||||
{
|
||||
NonGlobalPlugins[actionKeyword] = plugin;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -123,7 +135,7 @@ namespace Wox.Core.Plugin
|
||||
var search = rawQuery;
|
||||
List<string> actionParameters = terms.ToList();
|
||||
if (terms.Length == 0) return null;
|
||||
if (IsVailldActionKeyword(terms[0]))
|
||||
if (NonGlobalPlugins.ContainsKey(terms[0]))
|
||||
{
|
||||
actionKeyword = terms[0];
|
||||
actionParameters = terms.Skip(1).ToList();
|
||||
@@ -143,8 +155,8 @@ namespace Wox.Core.Plugin
|
||||
|
||||
public static void QueryForAllPlugins(Query query)
|
||||
{
|
||||
var pluginPairs = GetPluginForActionKeyword(query.ActionKeyword) != null ?
|
||||
new List<PluginPair> { GetPluginForActionKeyword(query.ActionKeyword) } : GlobalPlugins;
|
||||
var pluginPairs = NonGlobalPlugins.ContainsKey(query.ActionKeyword) ?
|
||||
new List<PluginPair> { NonGlobalPlugins[query.ActionKeyword] } : GlobalPlugins;
|
||||
foreach (var plugin in pluginPairs)
|
||||
{
|
||||
var customizedPluginConfig = UserSettingStorage.Instance.
|
||||
@@ -187,21 +199,6 @@ namespace Wox.Core.Plugin
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if a query contains valid action keyword
|
||||
/// </summary>
|
||||
/// <param name="actionKeyword"></param>
|
||||
/// <returns></returns>
|
||||
private static bool IsVailldActionKeyword(string actionKeyword)
|
||||
{
|
||||
if (string.IsNullOrEmpty(actionKeyword) || actionKeyword == Query.GlobalPluginWildcardSign) return false;
|
||||
PluginPair pair = AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeywords.Contains(actionKeyword));
|
||||
if (pair == null) return false;
|
||||
var customizedPluginConfig = UserSettingStorage.Instance.
|
||||
CustomizedPluginConfigs.FirstOrDefault(o => o.ID == pair.Metadata.ID);
|
||||
return customizedPluginConfig == null || !customizedPluginConfig.Disabled;
|
||||
}
|
||||
|
||||
private static bool IsGlobalPlugin(PluginMetadata metadata)
|
||||
{
|
||||
return metadata.ActionKeywords.Contains(Query.GlobalPluginWildcardSign);
|
||||
@@ -225,13 +222,6 @@ namespace Wox.Core.Plugin
|
||||
return AllPlugins.FirstOrDefault(o => o.Metadata.ID == id);
|
||||
}
|
||||
|
||||
private static PluginPair GetPluginForActionKeyword(string actionKeyword)
|
||||
{
|
||||
//if a query doesn't contain a vaild action keyword, it should be a query for system plugin
|
||||
if (string.IsNullOrEmpty(actionKeyword) || actionKeyword == Query.GlobalPluginWildcardSign) return null;
|
||||
return NonGlobalPlugins.FirstOrDefault(o => o.Metadata.ActionKeywords.Contains(actionKeyword));
|
||||
}
|
||||
|
||||
public static IEnumerable<PluginPair> GetPluginsForInterface<T>() where T : IFeatures
|
||||
{
|
||||
return AllPlugins.Where(p => p.Plugin is T);
|
||||
|
||||
28
Wox/Helper/ListBoxItems.cs
Normal file
28
Wox/Helper/ListBoxItems.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Wox.Helper
|
||||
{
|
||||
class ListBoxItems : ObservableCollection<Result>
|
||||
{
|
||||
public void RemoveAll(Predicate<Result> predicate)
|
||||
{
|
||||
CheckReentrancy();
|
||||
|
||||
List<Result> itemsToRemove = Items.Where(x => predicate(x)).ToList();
|
||||
if (itemsToRemove.Count > 0)
|
||||
{
|
||||
itemsToRemove.ForEach(item => Items.Remove(item));
|
||||
|
||||
OnPropertyChanged(new PropertyChangedEventArgs("Count"));
|
||||
OnPropertyChanged(new PropertyChangedEventArgs("Item[]"));
|
||||
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, itemsToRemove));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,11 +43,11 @@ namespace Wox
|
||||
|
||||
private readonly Storyboard progressBarStoryboard = new Storyboard();
|
||||
private NotifyIcon notifyIcon;
|
||||
private bool queryHasReturn;
|
||||
private string lastQuery;
|
||||
private bool _queryHasReturn;
|
||||
private Query _lastQuery = new Query();
|
||||
private ToolTip toolTip = new ToolTip();
|
||||
|
||||
private bool ignoreTextChange = false;
|
||||
private bool _ignoreTextChange = false;
|
||||
private List<Result> CurrentContextMenus = new List<Result>();
|
||||
private string textBeforeEnterContextMenuMode;
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace Wox
|
||||
{
|
||||
Dispatcher.Invoke(new Action(() =>
|
||||
{
|
||||
ignoreTextChange = true;
|
||||
_ignoreTextChange = true;
|
||||
tbQuery.Text = query;
|
||||
tbQuery.CaretIndex = tbQuery.Text.Length;
|
||||
if (selectAll)
|
||||
@@ -441,10 +441,10 @@ namespace Wox
|
||||
|
||||
private void TbQuery_OnTextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
|
||||
if (ignoreTextChange) { ignoreTextChange = false; return; }
|
||||
|
||||
if (!string.IsNullOrEmpty(tbQuery.Text.Trim()))
|
||||
if (_ignoreTextChange) { _ignoreTextChange = false; return; }
|
||||
string query = tbQuery.Text.Trim();
|
||||
if (!string.IsNullOrEmpty(query))
|
||||
{
|
||||
toolTip.IsOpen = false;
|
||||
if (IsInContextMenuMode)
|
||||
@@ -453,10 +453,10 @@ namespace Wox
|
||||
return;
|
||||
}
|
||||
|
||||
Query(tbQuery.Text);
|
||||
Query(query);
|
||||
Dispatcher.DelayInvoke("ShowProgressbar", () =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(tbQuery.Text.Trim()) && tbQuery.Text != lastQuery && !queryHasReturn)
|
||||
if (!string.IsNullOrEmpty(query) && query != _lastQuery.RawQuery && !_queryHasReturn)
|
||||
{
|
||||
StartProgress();
|
||||
}
|
||||
@@ -479,7 +479,28 @@ namespace Wox
|
||||
var query = PluginManager.QueryInit(text);
|
||||
if (query != null)
|
||||
{
|
||||
lastQuery = query.RawQuery;
|
||||
// handle the exclusiveness of plugin using action keyword
|
||||
string lastKeyword = _lastQuery.ActionKeyword;
|
||||
string keyword = query.ActionKeyword;
|
||||
if (string.IsNullOrEmpty(lastKeyword))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
pnlResult.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
pnlResult.RemoveResultsFor(PluginManager.NonGlobalPlugins[lastKeyword]);
|
||||
}
|
||||
else if (lastKeyword != keyword)
|
||||
{
|
||||
pnlResult.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword]);
|
||||
}
|
||||
}
|
||||
_lastQuery = query;
|
||||
PluginManager.QueryForAllPlugins(query);
|
||||
}
|
||||
StopProgress();
|
||||
@@ -814,7 +835,7 @@ namespace Wox
|
||||
|
||||
private void UpdateResultView(List<Result> list)
|
||||
{
|
||||
queryHasReturn = true;
|
||||
_queryHasReturn = true;
|
||||
progressBar.Dispatcher.Invoke(new Action(StopProgress));
|
||||
if (list == null || list.Count == 0) return;
|
||||
|
||||
@@ -824,7 +845,7 @@ namespace Wox
|
||||
{
|
||||
o.Score += UserSelectedRecordStorage.Instance.GetSelectedCount(o) * 5;
|
||||
});
|
||||
List<Result> l = list.Where(o => o.OriginQuery != null && o.OriginQuery.RawQuery == lastQuery).ToList();
|
||||
List<Result> l = list.Where(o => o.OriginQuery != null && o.OriginQuery.RawQuery == _lastQuery.RawQuery).ToList();
|
||||
UpdateResultViewInternal(l);
|
||||
}
|
||||
}
|
||||
|
||||
26
Wox/Properties/Resources.Designer.cs
generated
26
Wox/Properties/Resources.Designer.cs
generated
@@ -1,10 +1,10 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 此代码由工具生成。
|
||||
// 运行时版本:4.0.30319.0
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// 对此文件的更改可能会导致不正确的行为,并且如果
|
||||
// 重新生成代码,这些更改将会丢失。
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -13,12 +13,12 @@ namespace Wox.Properties {
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 一个强类型的资源类,用于查找本地化的字符串等。
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// 此类是由 StronglyTypedResourceBuilder
|
||||
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
|
||||
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
|
||||
// (以 /str 作为命令选项),或重新生成 VS 项目。
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
@@ -33,7 +33,7 @@ namespace Wox.Properties {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回此类使用的缓存的 ResourceManager 实例。
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
@@ -47,8 +47,8 @@ namespace Wox.Properties {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使用此强类型资源类,为所有资源查找
|
||||
/// 重写当前线程的 CurrentUICulture 属性。
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
@@ -61,7 +61,7 @@ namespace Wox.Properties {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似于 (Icon) 的 System.Drawing.Icon 类型的本地化资源。
|
||||
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
|
||||
/// </summary>
|
||||
internal static System.Drawing.Icon app {
|
||||
get {
|
||||
|
||||
10
Wox/Properties/Settings.Designer.cs
generated
10
Wox/Properties/Settings.Designer.cs
generated
@@ -1,10 +1,10 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 此代码由工具生成。
|
||||
// 运行时版本:4.0.30319.0
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// 对此文件的更改可能会导致不正确的行为,并且如果
|
||||
// 重新生成代码,这些更改将会丢失。
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Wox.Properties {
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
@@ -9,6 +9,7 @@ using System.Windows.Media;
|
||||
using System.Linq;
|
||||
using System.Runtime.Remoting.Contexts;
|
||||
using Wox.Core.UserSettings;
|
||||
using Wox.Helper;
|
||||
using Wox.Plugin;
|
||||
using Wox.Storage;
|
||||
|
||||
@@ -20,7 +21,7 @@ namespace Wox
|
||||
public event Action<Result> LeftMouseClickEvent;
|
||||
public event Action<Result> RightMouseClickEvent;
|
||||
public event Action<Result, IDataObject, DragEventArgs> ItemDropEvent;
|
||||
private readonly ObservableCollection<Result> _results; //todo, for better performance, override the default linear search
|
||||
private readonly ListBoxItems _results; //todo, for better performance, override the default linear search
|
||||
private readonly object _resultsUpdateLock = new object();
|
||||
|
||||
protected virtual void OnRightMouseClick(Result result)
|
||||
@@ -38,6 +39,25 @@ namespace Wox
|
||||
|
||||
public int MaxResultsToShow { get { return UserSettingStorage.Instance.MaxResultsToShow * 50; } }
|
||||
|
||||
internal void RemoveResultsFor(PluginPair plugin)
|
||||
{
|
||||
lock (_resultsUpdateLock)
|
||||
{
|
||||
_results.RemoveAll(r => r.PluginID == plugin.Metadata.ID);
|
||||
}
|
||||
}
|
||||
|
||||
internal void RemoveResultsExcept(PluginPair plugin)
|
||||
{
|
||||
lock (_resultsUpdateLock)
|
||||
{
|
||||
_results.RemoveAll(r => r.PluginID != plugin.Metadata.ID);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void AddResults(List<Result> newResults)
|
||||
{
|
||||
if (newResults != null && newResults.Count > 0)
|
||||
@@ -45,16 +65,7 @@ namespace Wox
|
||||
lock (_resultsUpdateLock)
|
||||
{
|
||||
var pluginId = newResults[0].PluginID;
|
||||
var actionKeyword = newResults[0].OriginQuery.ActionKeyword;
|
||||
List<Result> oldResults;
|
||||
if (string.IsNullOrEmpty(actionKeyword))
|
||||
{
|
||||
oldResults = _results.Where(r => r.PluginID == pluginId).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
oldResults = _results.ToList();
|
||||
}
|
||||
var oldResults = _results.Where(r => r.PluginID == pluginId).ToList();
|
||||
// intersection of A (old results) and B (new newResults)
|
||||
var intersection = oldResults.Intersect(newResults).ToList();
|
||||
|
||||
@@ -236,7 +247,7 @@ namespace Wox
|
||||
public ResultPanel()
|
||||
{
|
||||
InitializeComponent();
|
||||
_results = new ObservableCollection<Result>();
|
||||
_results = new ListBoxItems();
|
||||
lbResults.ItemsSource = _results;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user