mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 12:18:50 +02:00
Merge branch 'dev' of https://github.com/Wox-launcher/Wox.git
This commit is contained in:
@@ -21,22 +21,17 @@ namespace Wox.Plugin.CMD
|
|||||||
public List<Result> Query(Query query)
|
public List<Result> Query(Query query)
|
||||||
{
|
{
|
||||||
List<Result> results = new List<Result>();
|
List<Result> results = new List<Result>();
|
||||||
List<Result> pushedResults = new List<Result>();
|
|
||||||
string cmd = query.Search;
|
string cmd = query.Search;
|
||||||
if (string.IsNullOrEmpty(cmd))
|
if (string.IsNullOrEmpty(cmd))
|
||||||
{
|
{
|
||||||
return GetAllHistoryCmds();
|
return ResultsFromlHistory();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var queryCmd = GetCurrentCmd(cmd);
|
var queryCmd = GetCurrentCmd(cmd);
|
||||||
context.API.PushResults(query, context.CurrentPluginMetadata, new List<Result>() { queryCmd });
|
results.Add(queryCmd);
|
||||||
pushedResults.Add(queryCmd);
|
|
||||||
|
|
||||||
var history = GetHistoryCmds(cmd, queryCmd);
|
var history = GetHistoryCmds(cmd, queryCmd);
|
||||||
context.API.PushResults(query, context.CurrentPluginMetadata, history);
|
results.AddRange(history);
|
||||||
pushedResults.AddRange(history);
|
|
||||||
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -57,7 +52,11 @@ namespace Wox.Plugin.CMD
|
|||||||
|
|
||||||
if (basedir != null)
|
if (basedir != null)
|
||||||
{
|
{
|
||||||
List<string> autocomplete = Directory.GetFileSystemEntries(basedir).Select(o => dir + Path.GetFileName(o)).Where(o => o.StartsWith(cmd, StringComparison.OrdinalIgnoreCase) && !results.Any(p => o.Equals(p.Title, StringComparison.OrdinalIgnoreCase)) && !pushedResults.Any(p => o.Equals(p.Title, StringComparison.OrdinalIgnoreCase))).ToList();
|
var autocomplete = Directory.GetFileSystemEntries(basedir).
|
||||||
|
Select(o => dir + Path.GetFileName(o)).
|
||||||
|
Where(o => o.StartsWith(cmd, StringComparison.OrdinalIgnoreCase) &&
|
||||||
|
!results.Any(p => o.Equals(p.Title, StringComparison.OrdinalIgnoreCase)) &&
|
||||||
|
!results.Any(p => o.Equals(p.Title, StringComparison.OrdinalIgnoreCase))).ToList();
|
||||||
autocomplete.Sort();
|
autocomplete.Sort();
|
||||||
results.AddRange(autocomplete.ConvertAll(m => new Result()
|
results.AddRange(autocomplete.ConvertAll(m => new Result()
|
||||||
{
|
{
|
||||||
@@ -94,7 +93,7 @@ namespace Wox.Plugin.CMD
|
|||||||
var ret = new Result
|
var ret = new Result
|
||||||
{
|
{
|
||||||
Title = m.Key,
|
Title = m.Key,
|
||||||
SubTitle = string.Format(context.API.GetTranslation("wox_plugin_cmd_cmd_has_been_executed_times"), m.Value),
|
SubTitle = string.Format(context.API.GetTranslation("wox_plugin_cmd_cmd_has_been_executed_times"), m.Value),
|
||||||
IcoPath = "Images/cmd.png",
|
IcoPath = "Images/cmd.png",
|
||||||
Action = (c) =>
|
Action = (c) =>
|
||||||
{
|
{
|
||||||
@@ -125,13 +124,13 @@ namespace Wox.Plugin.CMD
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Result> GetAllHistoryCmds()
|
private List<Result> ResultsFromlHistory()
|
||||||
{
|
{
|
||||||
IEnumerable<Result> history = CMDStorage.Instance.CMDHistory.OrderByDescending(o => o.Value)
|
IEnumerable<Result> history = CMDStorage.Instance.CMDHistory.OrderByDescending(o => o.Value)
|
||||||
.Select(m => new Result
|
.Select(m => new Result
|
||||||
{
|
{
|
||||||
Title = m.Key,
|
Title = m.Key,
|
||||||
SubTitle = string.Format(context.API.GetTranslation("wox_plugin_cmd_cmd_has_been_executed_times"), m.Value),
|
SubTitle = string.Format(context.API.GetTranslation("wox_plugin_cmd_cmd_has_been_executed_times"), m.Value),
|
||||||
IcoPath = "Images/cmd.png",
|
IcoPath = "Images/cmd.png",
|
||||||
Action = (c) =>
|
Action = (c) =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,10 +13,9 @@ namespace Wox.Plugin.PluginIndicator
|
|||||||
|
|
||||||
public List<Result> Query(Query query)
|
public List<Result> Query(Query query)
|
||||||
{
|
{
|
||||||
var results = from plugin in PluginManager.NonGlobalPlugins
|
var results = from keyword in PluginManager.NonGlobalPlugins.Keys
|
||||||
select plugin.Metadata into metadata
|
|
||||||
from keyword in metadata.ActionKeywords
|
|
||||||
where keyword.StartsWith(query.Terms[0])
|
where keyword.StartsWith(query.Terms[0])
|
||||||
|
let metadata = PluginManager.NonGlobalPlugins[keyword].Metadata
|
||||||
let customizedPluginConfig =
|
let customizedPluginConfig =
|
||||||
UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == metadata.ID)
|
UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == metadata.ID)
|
||||||
where customizedPluginConfig == null || !customizedPluginConfig.Disabled
|
where customizedPluginConfig == null || !customizedPluginConfig.Disabled
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using Wox.Infrastructure.Logger;
|
||||||
namespace Wox.Plugin.Program
|
namespace Wox.Plugin.Program
|
||||||
{
|
{
|
||||||
internal class FileChangeWatcher
|
internal class FileChangeWatcher
|
||||||
@@ -15,7 +15,7 @@ namespace Wox.Plugin.Program
|
|||||||
if (watchedPath.Contains(path)) return;
|
if (watchedPath.Contains(path)) return;
|
||||||
if (!Directory.Exists(path))
|
if (!Directory.Exists(path))
|
||||||
{
|
{
|
||||||
Debug.WriteLine(string.Format("FileChangeWatcher: {0} doesn't exist", path));
|
Log.Warn($"FileChangeWatcher: {path} doesn't exist");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ namespace Wox.Plugin.Program.ProgramSources
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Error(e.StackTrace);
|
Log.Error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Wox.Core.Exception;
|
||||||
using Wox.Infrastructure.Logger;
|
using Wox.Infrastructure.Logger;
|
||||||
|
|
||||||
namespace Wox.Plugin.Program.ProgramSources
|
namespace Wox.Plugin.Program.ProgramSources
|
||||||
@@ -70,7 +71,8 @@ namespace Wox.Plugin.Program.ProgramSources
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Warn(string.Format("GetAppFromDirectory failed: {0} - {1}", path, e.Message));
|
var woxPluginException = new WoxPluginException("Program", $"GetAppFromDirectory failed: {path}", e);
|
||||||
|
Log.Error(woxPluginException);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ using System.Windows;
|
|||||||
using IWshRuntimeLibrary;
|
using IWshRuntimeLibrary;
|
||||||
using Wox.Infrastructure;
|
using Wox.Infrastructure;
|
||||||
using Wox.Plugin.Program.ProgramSources;
|
using Wox.Plugin.Program.ProgramSources;
|
||||||
|
using Wox.Infrastructure.Logger;
|
||||||
using Stopwatch = Wox.Infrastructure.Stopwatch;
|
using Stopwatch = Wox.Infrastructure.Stopwatch;
|
||||||
|
|
||||||
namespace Wox.Plugin.Program
|
namespace Wox.Plugin.Program
|
||||||
@@ -75,7 +76,7 @@ namespace Wox.Plugin.Program
|
|||||||
{
|
{
|
||||||
programs = ProgramCacheStorage.Instance.Programs;
|
programs = ProgramCacheStorage.Instance.Programs;
|
||||||
});
|
});
|
||||||
Debug.WriteLine($"Preload {programs.Count} programs from cache");
|
Log.Info($"Preload {programs.Count} programs from cache");
|
||||||
Stopwatch.Debug("Program Index", IndexPrograms);
|
Stopwatch.Debug("Program Index", IndexPrograms);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,7 +99,7 @@ namespace Wox.Plugin.Program
|
|||||||
}
|
}
|
||||||
|
|
||||||
sources.Clear();
|
sources.Clear();
|
||||||
foreach(var source in programSources.Where(o => o.Enabled))
|
foreach (var source in programSources.Where(o => o.Enabled))
|
||||||
{
|
{
|
||||||
Type sourceClass;
|
Type sourceClass;
|
||||||
if (SourceTypes.TryGetValue(source.Type, out sourceClass))
|
if (SourceTypes.TryGetValue(source.Type, out sourceClass))
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace Wox.Plugin.WebSearch
|
|
||||||
{
|
|
||||||
public static class EasyTimer
|
|
||||||
{
|
|
||||||
public static IDisposable SetInterval(Action method, int delayInMilliseconds)
|
|
||||||
{
|
|
||||||
System.Timers.Timer timer = new System.Timers.Timer(delayInMilliseconds);
|
|
||||||
timer.Elapsed += (source, e) =>
|
|
||||||
{
|
|
||||||
method();
|
|
||||||
};
|
|
||||||
|
|
||||||
timer.Enabled = true;
|
|
||||||
timer.Start();
|
|
||||||
|
|
||||||
// Returns a stop handle which can be used for stopping
|
|
||||||
// the timer, if required
|
|
||||||
return timer as IDisposable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IDisposable SetTimeout(Action method, int delayInMilliseconds)
|
|
||||||
{
|
|
||||||
System.Timers.Timer timer = new System.Timers.Timer(delayInMilliseconds);
|
|
||||||
timer.Elapsed += (source, e) =>
|
|
||||||
{
|
|
||||||
method();
|
|
||||||
};
|
|
||||||
|
|
||||||
timer.AutoReset = false;
|
|
||||||
timer.Enabled = true;
|
|
||||||
timer.Start();
|
|
||||||
|
|
||||||
// Returns a stop handle which can be used for stopping
|
|
||||||
// the timer, if required
|
|
||||||
return timer as IDisposable;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,14 +4,14 @@ using System.Diagnostics;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Windows.Controls;
|
||||||
using Wox.Plugin.WebSearch.SuggestionSources;
|
using Wox.Plugin.WebSearch.SuggestionSources;
|
||||||
|
|
||||||
namespace Wox.Plugin.WebSearch
|
namespace Wox.Plugin.WebSearch
|
||||||
{
|
{
|
||||||
public class WebSearchPlugin : IPlugin, ISettingProvider, IPluginI18n, IInstantQuery
|
public class WebSearchPlugin : IPlugin, ISettingProvider, IPluginI18n, IInstantQuery
|
||||||
{
|
{
|
||||||
private PluginInitContext context;
|
private PluginInitContext _context;
|
||||||
private IDisposable suggestionTimer;
|
|
||||||
|
|
||||||
public List<Result> Query(Query query)
|
public List<Result> Query(Query query)
|
||||||
{
|
{
|
||||||
@@ -21,71 +21,63 @@ namespace Wox.Plugin.WebSearch
|
|||||||
|
|
||||||
if (webSearch != null)
|
if (webSearch != null)
|
||||||
{
|
{
|
||||||
string keyword = query.ActionKeyword;
|
string keyword = query.Search;
|
||||||
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))
|
||||||
{
|
{
|
||||||
title = subtitle;
|
title = subtitle;
|
||||||
subtitle = null;
|
subtitle = string.Empty;
|
||||||
}
|
}
|
||||||
context.API.PushResults(query, context.CurrentPluginMetadata, new List<Result>()
|
var result = new Result
|
||||||
{
|
{
|
||||||
new Result()
|
Title = title,
|
||||||
|
SubTitle = subtitle,
|
||||||
|
Score = 6,
|
||||||
|
IcoPath = webSearch.IconPath,
|
||||||
|
Action = c =>
|
||||||
{
|
{
|
||||||
Title = title,
|
Process.Start(webSearch.Url.Replace("{q}", Uri.EscapeDataString(keyword ?? string.Empty)));
|
||||||
SubTitle = subtitle,
|
return true;
|
||||||
Score = 6,
|
|
||||||
IcoPath = webSearch.IconPath,
|
|
||||||
Action = (c) =>
|
|
||||||
{
|
|
||||||
Process.Start(webSearch.Url.Replace("{q}", Uri.EscapeDataString(keyword)));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
results.Add(result);
|
||||||
|
|
||||||
if (WebSearchStorage.Instance.EnableWebSearchSuggestion && !string.IsNullOrEmpty(keyword))
|
if (WebSearchStorage.Instance.EnableWebSearchSuggestion && !string.IsNullOrEmpty(keyword))
|
||||||
{
|
{
|
||||||
if (suggestionTimer != null)
|
// todo use Task.Wait when .net upgraded
|
||||||
{
|
results.AddRange(ResultsFromSuggestions(keyword, subtitle, webSearch));
|
||||||
suggestionTimer.Dispose();
|
|
||||||
}
|
|
||||||
suggestionTimer = EasyTimer.SetTimeout(() => { QuerySuggestions(keyword, query, subtitle, webSearch); }, 350);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void QuerySuggestions(string keyword, Query query, string subtitle, WebSearch webSearch)
|
private IEnumerable<Result> ResultsFromSuggestions(string keyword, string subtitle, WebSearch webSearch)
|
||||||
{
|
{
|
||||||
ISuggestionSource sugg = SuggestionSourceFactory.GetSuggestionSource(WebSearchStorage.Instance.WebSearchSuggestionSource, context);
|
ISuggestionSource sugg = SuggestionSourceFactory.GetSuggestionSource(WebSearchStorage.Instance.WebSearchSuggestionSource, _context);
|
||||||
if (sugg != null)
|
var suggestions = sugg?.GetSuggestions(keyword);
|
||||||
|
if (suggestions != null)
|
||||||
{
|
{
|
||||||
var result = sugg.GetSuggestions(keyword);
|
var resultsFromSuggestion = suggestions.Select(o => new Result
|
||||||
if (result != null)
|
|
||||||
{
|
{
|
||||||
context.API.PushResults(query, context.CurrentPluginMetadata,
|
Title = o,
|
||||||
result.Select(o => new Result()
|
SubTitle = subtitle,
|
||||||
{
|
Score = 5,
|
||||||
Title = o,
|
IcoPath = webSearch.IconPath,
|
||||||
SubTitle = subtitle,
|
Action = c =>
|
||||||
Score = 5,
|
{
|
||||||
IcoPath = webSearch.IconPath,
|
Process.Start(webSearch.Url.Replace("{q}", Uri.EscapeDataString(o)));
|
||||||
Action = (c) =>
|
return true;
|
||||||
{
|
}
|
||||||
Process.Start(webSearch.Url.Replace("{q}", Uri.EscapeDataString(o)));
|
});
|
||||||
return true;
|
return resultsFromSuggestion;
|
||||||
}
|
|
||||||
}).ToList());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return new List<Result>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Init(PluginInitContext context)
|
public void Init(PluginInitContext context)
|
||||||
{
|
{
|
||||||
this.context = context;
|
_context = context;
|
||||||
|
|
||||||
if (WebSearchStorage.Instance.WebSearches == null)
|
if (WebSearchStorage.Instance.WebSearches == null)
|
||||||
WebSearchStorage.Instance.WebSearches = WebSearchStorage.Instance.LoadDefaultWebSearches();
|
WebSearchStorage.Instance.WebSearches = WebSearchStorage.Instance.LoadDefaultWebSearches();
|
||||||
@@ -93,9 +85,9 @@ namespace Wox.Plugin.WebSearch
|
|||||||
|
|
||||||
#region ISettingProvider Members
|
#region ISettingProvider Members
|
||||||
|
|
||||||
public System.Windows.Controls.Control CreateSettingPanel()
|
public Control CreateSettingPanel()
|
||||||
{
|
{
|
||||||
return new WebSearchesSetting(context);
|
return new WebSearchesSetting(_context);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -107,12 +99,12 @@ namespace Wox.Plugin.WebSearch
|
|||||||
|
|
||||||
public string GetTranslatedPluginTitle()
|
public string GetTranslatedPluginTitle()
|
||||||
{
|
{
|
||||||
return context.API.GetTranslation("wox_plugin_websearch_plugin_name");
|
return _context.API.GetTranslation("wox_plugin_websearch_plugin_name");
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetTranslatedPluginDescription()
|
public string GetTranslatedPluginDescription()
|
||||||
{
|
{
|
||||||
return context.API.GetTranslation("wox_plugin_websearch_plugin_description");
|
return _context.API.GetTranslation("wox_plugin_websearch_plugin_description");
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsInstantQuery(string query) => false;
|
public bool IsInstantQuery(string query) => false;
|
||||||
|
|||||||
@@ -49,7 +49,6 @@
|
|||||||
<Reference Include="WindowsBase" />
|
<Reference Include="WindowsBase" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="EasyTimer.cs" />
|
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="SuggestionSources\Baidu.cs" />
|
<Compile Include="SuggestionSources\Baidu.cs" />
|
||||||
<Compile Include="SuggestionSources\Google.cs" />
|
<Compile Include="SuggestionSources\Google.cs" />
|
||||||
@@ -93,9 +92,6 @@
|
|||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
</Page>
|
</Page>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
|
||||||
<WCFMetadata Include="Service References\" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\Wox.Infrastructure\Wox.Infrastructure.csproj">
|
<ProjectReference Include="..\..\Wox.Infrastructure\Wox.Infrastructure.csproj">
|
||||||
<Project>{4fd29318-a8ab-4d8f-aa47-60bc241b8da3}</Project>
|
<Project>{4fd29318-a8ab-4d8f-aa47-60bc241b8da3}</Project>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using Wox.Core.Exception;
|
||||||
using Wox.Infrastructure.Logger;
|
using Wox.Infrastructure.Logger;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
|
|
||||||
@@ -19,10 +20,10 @@ namespace Wox.Core.Plugin
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Assembly asm = Assembly.Load(AssemblyName.GetAssemblyName(metadata.ExecuteFilePath));
|
Assembly asm = Assembly.Load(AssemblyName.GetAssemblyName(metadata.ExecuteFilePath));
|
||||||
List<Type> types = asm.GetTypes().Where(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Contains(typeof(IPlugin))).ToList();
|
List<Type> types = asm.GetTypes().Where(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Contains(typeof(IPlugin))).ToList();
|
||||||
if (types.Count == 0)
|
if (types.Count == 0)
|
||||||
{
|
{
|
||||||
Log.Warn(string.Format("Couldn't load plugin {0}: didn't find the class that implement IPlugin", metadata.Name));
|
Log.Warn($"Couldn't load plugin {metadata.Name}: didn't find the class that implement IPlugin");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,12 +40,7 @@ namespace Wox.Core.Plugin
|
|||||||
}
|
}
|
||||||
catch (System.Exception e)
|
catch (System.Exception e)
|
||||||
{
|
{
|
||||||
Log.Error(string.Format("Couldn't load plugin {0}: {1}", metadata.Name, e.Message));
|
Log.Error(new WoxPluginException(metadata.Name, $"Couldn't load plugin", e));
|
||||||
#if (DEBUG)
|
|
||||||
{
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ namespace Wox.Core.Plugin
|
|||||||
}
|
}
|
||||||
catch (System.Exception e)
|
catch (System.Exception e)
|
||||||
{
|
{
|
||||||
Log.Error(e.Message);
|
Log.Error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ namespace Wox.Core.Plugin
|
|||||||
}
|
}
|
||||||
catch (System.Exception e)
|
catch (System.Exception e)
|
||||||
{
|
{
|
||||||
Log.Error(ExceptionFormatter.FormatExcpetion(e));
|
Log.Fatal(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PluginMetadata metadata = GetPluginMetadata(directory);
|
PluginMetadata metadata = GetPluginMetadata(directory);
|
||||||
@@ -63,7 +63,7 @@ namespace Wox.Core.Plugin
|
|||||||
string configPath = Path.Combine(pluginDirectory, pluginConfigName);
|
string configPath = Path.Combine(pluginDirectory, pluginConfigName);
|
||||||
if (!File.Exists(configPath))
|
if (!File.Exists(configPath))
|
||||||
{
|
{
|
||||||
Log.Warn(string.Format("parse plugin {0} failed: didn't find config file.", configPath));
|
Log.Warn($"parse plugin {configPath} failed: didn't find config file.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,40 +77,25 @@ namespace Wox.Core.Plugin
|
|||||||
// for plugin still use old ActionKeyword
|
// for plugin still use old ActionKeyword
|
||||||
metadata.ActionKeyword = metadata.ActionKeywords?[0];
|
metadata.ActionKeyword = metadata.ActionKeywords?[0];
|
||||||
}
|
}
|
||||||
catch (System.Exception)
|
catch (System.Exception e)
|
||||||
{
|
{
|
||||||
string error = string.Format("Parse plugin config {0} failed: json format is not valid", configPath);
|
string msg = $"Parse plugin config {configPath} failed: json format is not valid";
|
||||||
Log.Warn(error);
|
Log.Error(new WoxException(msg));
|
||||||
#if (DEBUG)
|
|
||||||
{
|
|
||||||
throw new WoxException(error);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!AllowedLanguage.IsAllowed(metadata.Language))
|
if (!AllowedLanguage.IsAllowed(metadata.Language))
|
||||||
{
|
{
|
||||||
string error = string.Format("Parse plugin config {0} failed: invalid language {1}", configPath, metadata.Language);
|
string msg = $"Parse plugin config {configPath} failed: invalid language {metadata.Language}";
|
||||||
Log.Warn(error);
|
Log.Error(new WoxException(msg));
|
||||||
#if (DEBUG)
|
|
||||||
{
|
|
||||||
throw new WoxException(error);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!File.Exists(metadata.ExecuteFilePath))
|
if (!File.Exists(metadata.ExecuteFilePath))
|
||||||
{
|
{
|
||||||
string error = string.Format("Parse plugin config {0} failed: ExecuteFile {1} didn't exist", configPath, metadata.ExecuteFilePath);
|
string msg = $"Parse plugin config {configPath} failed: ExecuteFile {metadata.ExecuteFilePath} didn't exist";
|
||||||
Log.Warn(error);
|
Log.Error(new WoxException(msg));
|
||||||
#if (DEBUG)
|
|
||||||
{
|
|
||||||
throw new WoxException(error);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,8 +29,8 @@ namespace Wox.Core.Plugin
|
|||||||
|
|
||||||
public static IEnumerable<PluginPair> AllPlugins { get; private set; }
|
public static IEnumerable<PluginPair> AllPlugins { get; private set; }
|
||||||
|
|
||||||
public static IEnumerable<PluginPair> GlobalPlugins { get; private set; }
|
public static List<PluginPair> GlobalPlugins { get; } = new List<PluginPair>();
|
||||||
public static IEnumerable<PluginPair> NonGlobalPlugins { get; private set; }
|
public static Dictionary<string, PluginPair> NonGlobalPlugins { get; } = new Dictionary<string, PluginPair>();
|
||||||
|
|
||||||
private static IEnumerable<PluginPair> InstantQueryPlugins { get; set; }
|
private static IEnumerable<PluginPair> InstantQueryPlugins { get; set; }
|
||||||
public static IPublicAPI API { private set; get; }
|
public static IPublicAPI API { private set; get; }
|
||||||
@@ -58,7 +58,7 @@ namespace Wox.Core.Plugin
|
|||||||
}
|
}
|
||||||
catch (System.Exception e)
|
catch (System.Exception e)
|
||||||
{
|
{
|
||||||
Log.Error(e.Message);
|
Log.Error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -69,7 +69,7 @@ namespace Wox.Core.Plugin
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static void Init(IPublicAPI api)
|
public static void Init(IPublicAPI api)
|
||||||
{
|
{
|
||||||
if (api == null) throw new WoxCritialException("api is null");
|
if (api == null) throw new WoxFatalException("api is null");
|
||||||
|
|
||||||
SetupPluginDirectories();
|
SetupPluginDirectories();
|
||||||
API = api;
|
API = api;
|
||||||
@@ -104,8 +104,20 @@ namespace Wox.Core.Plugin
|
|||||||
{
|
{
|
||||||
InstantQueryPlugins = GetPluginsForInterface<IInstantQuery>();
|
InstantQueryPlugins = GetPluginsForInterface<IInstantQuery>();
|
||||||
contextMenuPlugins = GetPluginsForInterface<IContextMenu>();
|
contextMenuPlugins = GetPluginsForInterface<IContextMenu>();
|
||||||
GlobalPlugins = AllPlugins.Where(p => IsGlobalPlugin(p.Metadata));
|
foreach (var plugin in AllPlugins)
|
||||||
NonGlobalPlugins = AllPlugins.Where(p => !IsGlobalPlugin(p.Metadata));
|
{
|
||||||
|
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;
|
var search = rawQuery;
|
||||||
List<string> actionParameters = terms.ToList();
|
List<string> actionParameters = terms.ToList();
|
||||||
if (terms.Length == 0) return null;
|
if (terms.Length == 0) return null;
|
||||||
if (IsVailldActionKeyword(terms[0]))
|
if (NonGlobalPlugins.ContainsKey(terms[0]))
|
||||||
{
|
{
|
||||||
actionKeyword = terms[0];
|
actionKeyword = terms[0];
|
||||||
actionParameters = terms.Skip(1).ToList();
|
actionParameters = terms.Skip(1).ToList();
|
||||||
@@ -143,8 +155,8 @@ namespace Wox.Core.Plugin
|
|||||||
|
|
||||||
public static void QueryForAllPlugins(Query query)
|
public static void QueryForAllPlugins(Query query)
|
||||||
{
|
{
|
||||||
var pluginPairs = GetPluginForActionKeyword(query.ActionKeyword) != null ?
|
var pluginPairs = NonGlobalPlugins.ContainsKey(query.ActionKeyword) ?
|
||||||
new List<PluginPair> { GetPluginForActionKeyword(query.ActionKeyword) } : GlobalPlugins;
|
new List<PluginPair> { NonGlobalPlugins[query.ActionKeyword] } : GlobalPlugins;
|
||||||
foreach (var plugin in pluginPairs)
|
foreach (var plugin in pluginPairs)
|
||||||
{
|
{
|
||||||
var customizedPluginConfig = UserSettingStorage.Instance.
|
var customizedPluginConfig = UserSettingStorage.Instance.
|
||||||
@@ -152,7 +164,7 @@ namespace Wox.Core.Plugin
|
|||||||
if (customizedPluginConfig != null && customizedPluginConfig.Disabled) continue;
|
if (customizedPluginConfig != null && customizedPluginConfig.Disabled) continue;
|
||||||
if (IsInstantQueryPlugin(plugin))
|
if (IsInstantQueryPlugin(plugin))
|
||||||
{
|
{
|
||||||
Stopwatch.Debug($"Instant Query for {plugin.Metadata.Name}", () =>
|
Stopwatch.Normal($"Instant QueryForPlugin for {plugin.Metadata.Name}", () =>
|
||||||
{
|
{
|
||||||
QueryForPlugin(plugin, query);
|
QueryForPlugin(plugin, query);
|
||||||
});
|
});
|
||||||
@@ -161,7 +173,10 @@ namespace Wox.Core.Plugin
|
|||||||
{
|
{
|
||||||
ThreadPool.QueueUserWorkItem(state =>
|
ThreadPool.QueueUserWorkItem(state =>
|
||||||
{
|
{
|
||||||
QueryForPlugin(plugin, query);
|
Stopwatch.Normal($"Normal QueryForPlugin for {plugin.Metadata.Name}", () =>
|
||||||
|
{
|
||||||
|
QueryForPlugin(plugin, query);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -172,7 +187,7 @@ namespace Wox.Core.Plugin
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
List<Result> results = new List<Result>();
|
List<Result> results = new List<Result>();
|
||||||
var milliseconds = Stopwatch.Normal($"Query for {pair.Metadata.Name}", () =>
|
var milliseconds = Stopwatch.Normal($"Plugin.Query cost for {pair.Metadata.Name}", () =>
|
||||||
{
|
{
|
||||||
results = pair.Plugin.Query(query) ?? results;
|
results = pair.Plugin.Query(query) ?? results;
|
||||||
results.ForEach(o => { o.PluginID = pair.Metadata.ID; });
|
results.ForEach(o => { o.PluginID = pair.Metadata.ID; });
|
||||||
@@ -183,25 +198,10 @@ namespace Wox.Core.Plugin
|
|||||||
}
|
}
|
||||||
catch (System.Exception e)
|
catch (System.Exception e)
|
||||||
{
|
{
|
||||||
throw new WoxPluginException(pair.Metadata.Name, e);
|
throw new WoxPluginException(pair.Metadata.Name, $"QueryForPlugin failed", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <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)
|
private static bool IsGlobalPlugin(PluginMetadata metadata)
|
||||||
{
|
{
|
||||||
return metadata.ActionKeywords.Contains(Query.GlobalPluginWildcardSign);
|
return metadata.ActionKeywords.Contains(Query.GlobalPluginWildcardSign);
|
||||||
@@ -225,13 +225,6 @@ namespace Wox.Core.Plugin
|
|||||||
return AllPlugins.FirstOrDefault(o => o.Metadata.ID == id);
|
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
|
public static IEnumerable<PluginPair> GetPluginsForInterface<T>() where T : IFeatures
|
||||||
{
|
{
|
||||||
return AllPlugins.Where(p => p.Plugin is T);
|
return AllPlugins.Where(p => p.Plugin is T);
|
||||||
@@ -249,12 +242,7 @@ namespace Wox.Core.Plugin
|
|||||||
}
|
}
|
||||||
catch (System.Exception e)
|
catch (System.Exception e)
|
||||||
{
|
{
|
||||||
Log.Error($"Couldn't load plugin context menus {pluginPair.Metadata.Name}: {e.Message}");
|
Log.Error(new WoxPluginException(pluginPair.Metadata.Name, $"Couldn't load plugin context menus", e));
|
||||||
#if (DEBUG)
|
|
||||||
{
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace Wox.Core.Theme
|
|||||||
}
|
}
|
||||||
catch (System.Exception e)
|
catch (System.Exception e)
|
||||||
{
|
{
|
||||||
Log.Error(e.Message);
|
Log.Error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,13 +57,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="APIServer.cs" />
|
<Compile Include="APIServer.cs" />
|
||||||
<Compile Include="Exception\ExceptionFormatter.cs" />
|
|
||||||
<Compile Include="Exception\WoxCritialException.cs" />
|
|
||||||
<Compile Include="Exception\WoxException.cs" />
|
|
||||||
<Compile Include="Exception\WoxHttpException.cs" />
|
|
||||||
<Compile Include="Exception\WoxI18nException.cs" />
|
|
||||||
<Compile Include="Exception\WoxJsonRPCException.cs" />
|
|
||||||
<Compile Include="Exception\WoxPluginException.cs" />
|
|
||||||
<Compile Include="Updater\Release.cs" />
|
<Compile Include="Updater\Release.cs" />
|
||||||
<Compile Include="Updater\UpdaterManager.cs" />
|
<Compile Include="Updater\UpdaterManager.cs" />
|
||||||
<Compile Include="Updater\WoxUpdateSource.cs" />
|
<Compile Include="Updater\WoxUpdateSource.cs" />
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace Wox.Core.i18n
|
|||||||
}
|
}
|
||||||
catch (System.Exception e)
|
catch (System.Exception e)
|
||||||
{
|
{
|
||||||
Log.Error(e.Message);
|
Log.Error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -122,12 +122,8 @@ namespace Wox.Core.i18n
|
|||||||
}
|
}
|
||||||
catch (System.Exception e)
|
catch (System.Exception e)
|
||||||
{
|
{
|
||||||
Log.Warn("Update Plugin metadata translation failed:" + e.Message);
|
var woxPluginException = new WoxPluginException(pluginPair.Metadata.Name, "Update Plugin metadata translation failed:", e);
|
||||||
#if (DEBUG)
|
Log.Error(woxPluginException);
|
||||||
{
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
public WoxException(string msg, System.Exception innerException)
|
public WoxException(string msg, System.Exception innerException)
|
||||||
: base(msg, innerException)
|
: base(msg, innerException)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represent exceptions that wox can't handle and MUST close running Wox.
|
/// Represent exceptions that wox can't handle and MUST close running Wox.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class WoxCritialException : WoxException
|
public class WoxFatalException : WoxException
|
||||||
{
|
{
|
||||||
public WoxCritialException(string msg) : base(msg)
|
public WoxFatalException(string msg) : base(msg)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,8 +4,8 @@
|
|||||||
{
|
{
|
||||||
public string PluginName { get; set; }
|
public string PluginName { get; set; }
|
||||||
|
|
||||||
public WoxPluginException(string pluginName,System.Exception e)
|
public WoxPluginException(string pluginName, string msg, System.Exception e)
|
||||||
: base(e.Message,e)
|
: base($"{msg}: {pluginName}", e)
|
||||||
{
|
{
|
||||||
PluginName = pluginName;
|
PluginName = pluginName;
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
using Wox.Core.Exception;
|
||||||
|
|
||||||
namespace Wox.Infrastructure.Logger
|
namespace Wox.Infrastructure.Logger
|
||||||
{
|
{
|
||||||
@@ -7,34 +8,40 @@ namespace Wox.Infrastructure.Logger
|
|||||||
{
|
{
|
||||||
private static NLog.Logger logger = LogManager.GetCurrentClassLogger();
|
private static NLog.Logger logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
public static void Error(string msg)
|
|
||||||
{
|
|
||||||
logger.Error(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Error(Exception e)
|
public static void Error(Exception e)
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
throw e;
|
||||||
|
#else
|
||||||
logger.Error(e.Message + "\r\n" + e.StackTrace);
|
logger.Error(e.Message + "\r\n" + e.StackTrace);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Debug(string msg)
|
public static void Debug(string msg)
|
||||||
{
|
{
|
||||||
|
System.Diagnostics.Debug.WriteLine($"DEBUG: {msg}");
|
||||||
logger.Debug(msg);
|
logger.Debug(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Info(string msg)
|
public static void Info(string msg)
|
||||||
{
|
{
|
||||||
|
System.Diagnostics.Debug.WriteLine($"INFO: {msg}");
|
||||||
logger.Info(msg);
|
logger.Info(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Warn(string msg)
|
public static void Warn(string msg)
|
||||||
{
|
{
|
||||||
|
System.Diagnostics.Debug.WriteLine($"WARN: {msg}");
|
||||||
logger.Warn(msg);
|
logger.Warn(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Fatal(string msg)
|
public static void Fatal(Exception e)
|
||||||
{
|
{
|
||||||
logger.Fatal(msg);
|
#if DEBUG
|
||||||
|
throw e;
|
||||||
|
#else
|
||||||
|
logger.Fatal(ExceptionFormatter.FormatExcpetion(e));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,14 +18,6 @@ namespace Wox.Infrastructure
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
[Conditional("DEBUG")]
|
|
||||||
private static void WriteTimeInfo(string name, long milliseconds)
|
|
||||||
{
|
|
||||||
string info = $"{name} : {milliseconds}ms";
|
|
||||||
System.Diagnostics.Debug.WriteLine(info);
|
|
||||||
Log.Info(info);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This stopwatch will also appear only in Debug mode
|
/// This stopwatch will also appear only in Debug mode
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -36,7 +28,8 @@ namespace Wox.Infrastructure
|
|||||||
action();
|
action();
|
||||||
stopWatch.Stop();
|
stopWatch.Stop();
|
||||||
var milliseconds = stopWatch.ElapsedMilliseconds;
|
var milliseconds = stopWatch.ElapsedMilliseconds;
|
||||||
WriteTimeInfo(name, milliseconds);
|
string info = $"{name} : {milliseconds}ms";
|
||||||
|
Log.Debug(info);
|
||||||
return milliseconds;
|
return milliseconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,9 +46,17 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
<Reference Include="WindowsBase" />
|
<Reference Include="WindowsBase" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Exception\ExceptionFormatter.cs" />
|
||||||
|
<Compile Include="Exception\WoxException.cs" />
|
||||||
|
<Compile Include="Exception\WoxFatalException.cs" />
|
||||||
|
<Compile Include="Exception\WoxHttpException.cs" />
|
||||||
|
<Compile Include="Exception\WoxI18nException.cs" />
|
||||||
|
<Compile Include="Exception\WoxJsonRPCException.cs" />
|
||||||
|
<Compile Include="Exception\WoxPluginException.cs" />
|
||||||
<Compile Include="Hotkey\InterceptKeys.cs" />
|
<Compile Include="Hotkey\InterceptKeys.cs" />
|
||||||
<Compile Include="Hotkey\KeyEvent.cs" />
|
<Compile Include="Hotkey\KeyEvent.cs" />
|
||||||
<Compile Include="Logger\Log.cs" />
|
<Compile Include="Logger\Log.cs" />
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace Wox.Test.Plugins
|
|||||||
[Test]
|
[Test]
|
||||||
public void PublicAPIIsNullTest()
|
public void PublicAPIIsNullTest()
|
||||||
{
|
{
|
||||||
Assert.Throws(typeof(WoxCritialException), () => PluginManager.Init(null));
|
Assert.Throws(typeof(WoxFatalException), () => PluginManager.Init(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
3
Wox.sln
3
Wox.sln
@@ -62,6 +62,9 @@ EndProject
|
|||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.Everything", "Plugins\Wox.Plugin.Everything\Wox.Plugin.Everything.csproj", "{230AE83F-E92E-4E69-8355-426B305DA9C0}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.Everything", "Plugins\Wox.Plugin.Everything\Wox.Plugin.Everything.csproj", "{230AE83F-E92E-4E69-8355-426B305DA9C0}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
|
GlobalSection(Performance) = preSolution
|
||||||
|
HasPerformanceSessions = true
|
||||||
|
EndGlobalSection
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace Wox.Helper
|
|||||||
{
|
{
|
||||||
public static void Report(Exception e)
|
public static void Report(Exception e)
|
||||||
{
|
{
|
||||||
Log.Error(ExceptionFormatter.FormatExcpetion(e));
|
Log.Fatal(e);
|
||||||
new CrashReporter.CrashReporter(e).Show();
|
new CrashReporter.CrashReporter(e).Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
67
Wox/Helper/ListBoxItems.cs
Normal file
67
Wox/Helper/ListBoxItems.cs
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
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>
|
||||||
|
// todo implement custom moveItem,removeItem,insertItem for better performance
|
||||||
|
{
|
||||||
|
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[]"));
|
||||||
|
// fuck ms
|
||||||
|
// http://blogs.msdn.com/b/nathannesbit/archive/2009/04/20/addrange-and-observablecollection.aspx
|
||||||
|
// http://geekswithblogs.net/NewThingsILearned/archive/2008/01/16/listcollectionviewcollectionview-doesnt-support-notifycollectionchanged-with-multiple-items.aspx
|
||||||
|
// PS: don't use Reset for other data updates, it will cause UI flickering
|
||||||
|
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(List<Result> newItems)
|
||||||
|
{
|
||||||
|
int newCount = newItems.Count;
|
||||||
|
int oldCount = Items.Count;
|
||||||
|
int location = newCount > oldCount ? oldCount : newCount;
|
||||||
|
for (int i = 0; i < location; i++)
|
||||||
|
{
|
||||||
|
Result oldItem = Items[i];
|
||||||
|
Result newItem = newItems[i];
|
||||||
|
if (!Equals(oldItem, newItem))
|
||||||
|
{
|
||||||
|
this[i] = newItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newCount > oldCount)
|
||||||
|
{
|
||||||
|
for (int i = oldCount; i < newCount; i++)
|
||||||
|
{
|
||||||
|
Add(newItems[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int removeIndex = newCount;
|
||||||
|
for (int i = newCount; i < oldCount; i++)
|
||||||
|
{
|
||||||
|
RemoveAt(removeIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,6 +32,7 @@ using IDataObject = System.Windows.IDataObject;
|
|||||||
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
|
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
|
||||||
using MenuItem = System.Windows.Forms.MenuItem;
|
using MenuItem = System.Windows.Forms.MenuItem;
|
||||||
using MessageBox = System.Windows.MessageBox;
|
using MessageBox = System.Windows.MessageBox;
|
||||||
|
using Stopwatch = Wox.Infrastructure.Stopwatch;
|
||||||
using ToolTip = System.Windows.Controls.ToolTip;
|
using ToolTip = System.Windows.Controls.ToolTip;
|
||||||
|
|
||||||
namespace Wox
|
namespace Wox
|
||||||
@@ -43,11 +44,11 @@ namespace Wox
|
|||||||
|
|
||||||
private readonly Storyboard progressBarStoryboard = new Storyboard();
|
private readonly Storyboard progressBarStoryboard = new Storyboard();
|
||||||
private NotifyIcon notifyIcon;
|
private NotifyIcon notifyIcon;
|
||||||
private bool queryHasReturn;
|
private bool _queryHasReturn;
|
||||||
private string lastQuery;
|
private Query _lastQuery = new Query();
|
||||||
private ToolTip toolTip = new ToolTip();
|
private ToolTip toolTip = new ToolTip();
|
||||||
|
|
||||||
private bool ignoreTextChange = false;
|
private bool _ignoreTextChange = false;
|
||||||
private List<Result> CurrentContextMenus = new List<Result>();
|
private List<Result> CurrentContextMenus = new List<Result>();
|
||||||
private string textBeforeEnterContextMenuMode;
|
private string textBeforeEnterContextMenuMode;
|
||||||
|
|
||||||
@@ -72,7 +73,7 @@ namespace Wox
|
|||||||
{
|
{
|
||||||
Dispatcher.Invoke(new Action(() =>
|
Dispatcher.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
ignoreTextChange = true;
|
_ignoreTextChange = true;
|
||||||
tbQuery.Text = query;
|
tbQuery.Text = query;
|
||||||
tbQuery.CaretIndex = tbQuery.Text.Length;
|
tbQuery.CaretIndex = tbQuery.Text.Length;
|
||||||
if (selectAll)
|
if (selectAll)
|
||||||
@@ -162,7 +163,7 @@ namespace Wox
|
|||||||
o.PluginID = plugin.ID;
|
o.PluginID = plugin.ID;
|
||||||
o.OriginQuery = query;
|
o.OriginQuery = query;
|
||||||
});
|
});
|
||||||
UpdateResultView(results);
|
UpdateResultView(results, plugin, query);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ShowContextMenu(PluginMetadata plugin, List<Result> results)
|
public void ShowContextMenu(PluginMetadata plugin, List<Result> results)
|
||||||
@@ -176,7 +177,7 @@ namespace Wox
|
|||||||
o.ContextMenu = null;
|
o.ContextMenu = null;
|
||||||
});
|
});
|
||||||
pnlContextMenu.Clear();
|
pnlContextMenu.Clear();
|
||||||
pnlContextMenu.AddResults(results);
|
pnlContextMenu.AddResults(results, plugin.ID);
|
||||||
pnlContextMenu.Visibility = Visibility.Visible;
|
pnlContextMenu.Visibility = Visibility.Visible;
|
||||||
pnlResult.Visibility = Visibility.Collapsed;
|
pnlResult.Visibility = Visibility.Collapsed;
|
||||||
}
|
}
|
||||||
@@ -418,11 +419,12 @@ namespace Wox
|
|||||||
|
|
||||||
private void QueryContextMenu()
|
private void QueryContextMenu()
|
||||||
{
|
{
|
||||||
|
var contextMenuId = "Context Menu Id";
|
||||||
pnlContextMenu.Clear();
|
pnlContextMenu.Clear();
|
||||||
var query = tbQuery.Text.ToLower();
|
var query = tbQuery.Text.ToLower();
|
||||||
if (string.IsNullOrEmpty(query))
|
if (string.IsNullOrEmpty(query))
|
||||||
{
|
{
|
||||||
pnlContextMenu.AddResults(CurrentContextMenus);
|
pnlContextMenu.AddResults(CurrentContextMenus, contextMenuId);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -435,32 +437,25 @@ namespace Wox
|
|||||||
filterResults.Add(contextMenu);
|
filterResults.Add(contextMenu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pnlContextMenu.AddResults(filterResults);
|
pnlContextMenu.AddResults(filterResults, contextMenuId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void TbQuery_OnTextChanged(object sender, TextChangedEventArgs e)
|
private void TbQuery_OnTextChanged(object sender, TextChangedEventArgs e)
|
||||||
{
|
{
|
||||||
|
if (_ignoreTextChange) { _ignoreTextChange = false; return; }
|
||||||
|
|
||||||
if (ignoreTextChange) { ignoreTextChange = false; return; }
|
toolTip.IsOpen = false;
|
||||||
|
if (IsInContextMenuMode)
|
||||||
if (!string.IsNullOrEmpty(tbQuery.Text.Trim()))
|
|
||||||
{
|
{
|
||||||
toolTip.IsOpen = false;
|
QueryContextMenu();
|
||||||
if (IsInContextMenuMode)
|
return;
|
||||||
{
|
}
|
||||||
QueryContextMenu();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Query(tbQuery.Text);
|
string query = tbQuery.Text.Trim();
|
||||||
Dispatcher.DelayInvoke("ShowProgressbar", () =>
|
if (!string.IsNullOrEmpty(query))
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(tbQuery.Text.Trim()) && tbQuery.Text != lastQuery && !queryHasReturn)
|
Query(query);
|
||||||
{
|
|
||||||
StartProgress();
|
|
||||||
}
|
|
||||||
}, TimeSpan.FromMilliseconds(150));
|
|
||||||
//reset query history index after user start new query
|
//reset query history index after user start new query
|
||||||
ResetQueryHistoryIndex();
|
ResetQueryHistoryIndex();
|
||||||
}
|
}
|
||||||
@@ -472,14 +467,44 @@ namespace Wox
|
|||||||
|
|
||||||
private void ResetQueryHistoryIndex()
|
private void ResetQueryHistoryIndex()
|
||||||
{
|
{
|
||||||
|
pnlResult.RemoveResultsFor(QueryHistoryStorage.MetaData);
|
||||||
QueryHistoryStorage.Instance.Reset();
|
QueryHistoryStorage.Instance.Reset();
|
||||||
}
|
}
|
||||||
private void Query(string text)
|
private void Query(string text)
|
||||||
{
|
{
|
||||||
|
_queryHasReturn = false;
|
||||||
var query = PluginManager.QueryInit(text);
|
var query = PluginManager.QueryInit(text);
|
||||||
if (query != null)
|
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].Metadata);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(keyword))
|
||||||
|
{
|
||||||
|
pnlResult.RemoveResultsFor(PluginManager.NonGlobalPlugins[lastKeyword].Metadata);
|
||||||
|
}
|
||||||
|
else if (lastKeyword != keyword)
|
||||||
|
{
|
||||||
|
pnlResult.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword].Metadata);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_lastQuery = query;
|
||||||
|
Dispatcher.DelayInvoke("ShowProgressbar", () =>
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(query.RawQuery) && query.RawQuery == _lastQuery.RawQuery && !_queryHasReturn)
|
||||||
|
{
|
||||||
|
StartProgress();
|
||||||
|
}
|
||||||
|
}, TimeSpan.FromMilliseconds(150));
|
||||||
PluginManager.QueryForAllPlugins(query);
|
PluginManager.QueryForAllPlugins(query);
|
||||||
}
|
}
|
||||||
StopProgress();
|
StopProgress();
|
||||||
@@ -716,9 +741,11 @@ namespace Wox
|
|||||||
{
|
{
|
||||||
if (history != null)
|
if (history != null)
|
||||||
{
|
{
|
||||||
|
var historyMetadata = QueryHistoryStorage.MetaData;
|
||||||
ChangeQueryText(history.Query, true);
|
ChangeQueryText(history.Query, true);
|
||||||
var executeQueryHistoryTitle = GetTranslation("executeQuery");
|
var executeQueryHistoryTitle = GetTranslation("executeQuery");
|
||||||
var lastExecuteTime = GetTranslation("lastExecuteTime");
|
var lastExecuteTime = GetTranslation("lastExecuteTime");
|
||||||
|
pnlResult.RemoveResultsExcept(historyMetadata);
|
||||||
UpdateResultViewInternal(new List<Result>()
|
UpdateResultViewInternal(new List<Result>()
|
||||||
{
|
{
|
||||||
new Result(){
|
new Result(){
|
||||||
@@ -731,7 +758,7 @@ namespace Wox
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}, historyMetadata);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -812,28 +839,27 @@ namespace Wox
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateResultView(List<Result> list)
|
private void UpdateResultView(List<Result> list, PluginMetadata metadata, Query originQuery)
|
||||||
{
|
{
|
||||||
queryHasReturn = true;
|
_queryHasReturn = true;
|
||||||
progressBar.Dispatcher.Invoke(new Action(StopProgress));
|
progressBar.Dispatcher.Invoke(new Action(StopProgress));
|
||||||
if (list == null || list.Count == 0) return;
|
|
||||||
|
|
||||||
if (list.Count > 0)
|
list.ForEach(o =>
|
||||||
{
|
{
|
||||||
list.ForEach(o =>
|
o.Score += UserSelectedRecordStorage.Instance.GetSelectedCount(o) * 5;
|
||||||
{
|
});
|
||||||
o.Score += UserSelectedRecordStorage.Instance.GetSelectedCount(o) * 5;
|
if (originQuery.RawQuery == _lastQuery.RawQuery)
|
||||||
});
|
{
|
||||||
List<Result> l = list.Where(o => o.OriginQuery != null && o.OriginQuery.RawQuery == lastQuery).ToList();
|
UpdateResultViewInternal(list, metadata);
|
||||||
UpdateResultViewInternal(l);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateResultViewInternal(List<Result> list)
|
private void UpdateResultViewInternal(List<Result> list, PluginMetadata metadata)
|
||||||
{
|
{
|
||||||
Dispatcher.Invoke(new Action(() =>
|
Dispatcher.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
pnlResult.AddResults(list);
|
Stopwatch.Normal($"UI update cost for {metadata.Name}",
|
||||||
|
() => { pnlResult.AddResults(list, metadata.ID); });
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -882,7 +908,7 @@ namespace Wox
|
|||||||
textBeforeEnterContextMenuMode = tbQuery.Text;
|
textBeforeEnterContextMenuMode = tbQuery.Text;
|
||||||
ChangeQueryText("");
|
ChangeQueryText("");
|
||||||
pnlContextMenu.Clear();
|
pnlContextMenu.Clear();
|
||||||
pnlContextMenu.AddResults(results);
|
pnlContextMenu.AddResults(results, result.PluginID);
|
||||||
CurrentContextMenus = results;
|
CurrentContextMenus = results;
|
||||||
pnlContextMenu.Visibility = Visibility.Visible;
|
pnlContextMenu.Visibility = Visibility.Visible;
|
||||||
pnlResult.Visibility = Visibility.Collapsed;
|
pnlResult.Visibility = Visibility.Collapsed;
|
||||||
|
|||||||
26
Wox/Properties/Resources.Designer.cs
generated
26
Wox/Properties/Resources.Designer.cs
generated
@@ -1,10 +1,10 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// <auto-generated>
|
// <auto-generated>
|
||||||
// 此代码由工具生成。
|
// This code was generated by a tool.
|
||||||
// 运行时版本:4.0.30319.0
|
// 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>
|
// </auto-generated>
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -13,12 +13,12 @@ namespace Wox.Properties {
|
|||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 一个强类型的资源类,用于查找本地化的字符串等。
|
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
// 此类是由 StronglyTypedResourceBuilder
|
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||||
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
|
// class via a tool like ResGen or Visual Studio.
|
||||||
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
|
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||||
// (以 /str 作为命令选项),或重新生成 VS 项目。
|
// with the /str option, or rebuild your VS project.
|
||||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
@@ -33,7 +33,7 @@ namespace Wox.Properties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 返回此类使用的缓存的 ResourceManager 实例。
|
/// Returns the cached ResourceManager instance used by this class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||||
@@ -47,8 +47,8 @@ namespace Wox.Properties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 使用此强类型资源类,为所有资源查找
|
/// Overrides the current thread's CurrentUICulture property for all
|
||||||
/// 重写当前线程的 CurrentUICulture 属性。
|
/// resource lookups using this strongly typed resource class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||||
internal static global::System.Globalization.CultureInfo Culture {
|
internal static global::System.Globalization.CultureInfo Culture {
|
||||||
@@ -61,7 +61,7 @@ namespace Wox.Properties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似于 (Icon) 的 System.Drawing.Icon 类型的本地化资源。
|
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static System.Drawing.Icon app {
|
internal static System.Drawing.Icon app {
|
||||||
get {
|
get {
|
||||||
|
|||||||
10
Wox/Properties/Settings.Designer.cs
generated
10
Wox/Properties/Settings.Designer.cs
generated
@@ -1,10 +1,10 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// <auto-generated>
|
// <auto-generated>
|
||||||
// 此代码由工具生成。
|
// This code was generated by a tool.
|
||||||
// 运行时版本:4.0.30319.0
|
// 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>
|
// </auto-generated>
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ namespace Wox.Properties {
|
|||||||
|
|
||||||
|
|
||||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
[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 {
|
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||||
|
|
||||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
@@ -9,6 +10,7 @@ using System.Windows.Media;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.Remoting.Contexts;
|
using System.Runtime.Remoting.Contexts;
|
||||||
using Wox.Core.UserSettings;
|
using Wox.Core.UserSettings;
|
||||||
|
using Wox.Helper;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
using Wox.Storage;
|
using Wox.Storage;
|
||||||
|
|
||||||
@@ -20,7 +22,7 @@ namespace Wox
|
|||||||
public event Action<Result> LeftMouseClickEvent;
|
public event Action<Result> LeftMouseClickEvent;
|
||||||
public event Action<Result> RightMouseClickEvent;
|
public event Action<Result> RightMouseClickEvent;
|
||||||
public event Action<Result, IDataObject, DragEventArgs> ItemDropEvent;
|
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;
|
||||||
private readonly object _resultsUpdateLock = new object();
|
private readonly object _resultsUpdateLock = new object();
|
||||||
|
|
||||||
protected virtual void OnRightMouseClick(Result result)
|
protected virtual void OnRightMouseClick(Result result)
|
||||||
@@ -38,65 +40,74 @@ namespace Wox
|
|||||||
|
|
||||||
public int MaxResultsToShow { get { return UserSettingStorage.Instance.MaxResultsToShow * 50; } }
|
public int MaxResultsToShow { get { return UserSettingStorage.Instance.MaxResultsToShow * 50; } }
|
||||||
|
|
||||||
public void AddResults(List<Result> newResults)
|
internal void RemoveResultsFor(PluginMetadata metadata)
|
||||||
{
|
{
|
||||||
if (newResults != null && newResults.Count > 0)
|
lock (_resultsUpdateLock)
|
||||||
{
|
{
|
||||||
lock (_resultsUpdateLock)
|
_results.RemoveAll(r => r.PluginID == metadata.ID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void RemoveResultsExcept(PluginMetadata metadata)
|
||||||
|
{
|
||||||
|
lock (_resultsUpdateLock)
|
||||||
|
{
|
||||||
|
_results.RemoveAll(r => r.PluginID != metadata.ID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddResults(List<Result> newResults, string resultId)
|
||||||
|
{
|
||||||
|
lock (_resultsUpdateLock)
|
||||||
|
{
|
||||||
|
var resultCopy = _results.ToList();
|
||||||
|
var oldResults = resultCopy.Where(r => r.PluginID == resultId).ToList();
|
||||||
|
// intersection of A (old results) and B (new newResults)
|
||||||
|
var intersection = oldResults.Intersect(newResults).ToList();
|
||||||
|
// remove result of relative complement of B in A
|
||||||
|
foreach (var result in oldResults.Except(intersection))
|
||||||
{
|
{
|
||||||
var pluginId = newResults[0].PluginID;
|
resultCopy.Remove(result);
|
||||||
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();
|
|
||||||
}
|
|
||||||
// intersection of A (old results) and B (new newResults)
|
|
||||||
var intersection = oldResults.Intersect(newResults).ToList();
|
|
||||||
|
|
||||||
// remove result of relative complement of B in A
|
|
||||||
foreach (var result in oldResults.Except(intersection))
|
|
||||||
{
|
|
||||||
_results.Remove(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
// update scores
|
|
||||||
foreach (var result in newResults)
|
|
||||||
{
|
|
||||||
if (IsTopMostResult(result))
|
|
||||||
{
|
|
||||||
result.Score = int.MaxValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// update index for result in intersection of A and B
|
|
||||||
foreach (var result in intersection)
|
|
||||||
{
|
|
||||||
int oldIndex = _results.IndexOf(result);
|
|
||||||
int oldScore = _results[oldIndex].Score;
|
|
||||||
if (result.Score != oldScore)
|
|
||||||
{
|
|
||||||
int newIndex = InsertIndexOf(result.Score);
|
|
||||||
if (newIndex != oldIndex)
|
|
||||||
{
|
|
||||||
_results.Move(oldIndex, newIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// insert result in relative complement of A in B
|
|
||||||
foreach (var result in newResults.Except(intersection))
|
|
||||||
{
|
|
||||||
int newIndex = InsertIndexOf(result.Score);
|
|
||||||
_results.Insert(newIndex, result);
|
|
||||||
}
|
|
||||||
lbResults.Margin = lbResults.Items.Count > 0 ? new Thickness { Top = 8 } : new Thickness { Top = 0 };
|
|
||||||
SelectFirst();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update scores
|
||||||
|
foreach (var result in newResults)
|
||||||
|
{
|
||||||
|
if (IsTopMostResult(result))
|
||||||
|
{
|
||||||
|
result.Score = int.MaxValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// update index for result in intersection of A and B
|
||||||
|
foreach (var result in intersection)
|
||||||
|
{
|
||||||
|
int oldIndex = resultCopy.IndexOf(result);
|
||||||
|
int oldScore = resultCopy[oldIndex].Score;
|
||||||
|
if (result.Score != oldScore)
|
||||||
|
{
|
||||||
|
int newIndex = InsertIndexOf(result.Score, resultCopy);
|
||||||
|
if (newIndex != oldIndex)
|
||||||
|
{
|
||||||
|
var item = resultCopy[oldIndex];
|
||||||
|
resultCopy.RemoveAt(oldIndex);
|
||||||
|
resultCopy.Insert(newIndex, item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// insert result in relative complement of A in B
|
||||||
|
foreach (var result in newResults.Except(intersection))
|
||||||
|
{
|
||||||
|
int newIndex = InsertIndexOf(result.Score, resultCopy);
|
||||||
|
resultCopy.Insert(newIndex, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// update UI in one run, so it can avoid UI flickering
|
||||||
|
_results.Update(resultCopy);
|
||||||
|
|
||||||
|
lbResults.Margin = lbResults.Items.Count > 0 ? new Thickness { Top = 8 } : new Thickness { Top = 0 };
|
||||||
|
SelectFirst();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,13 +116,13 @@ namespace Wox
|
|||||||
return TopMostRecordStorage.Instance.IsTopMost(result);
|
return TopMostRecordStorage.Instance.IsTopMost(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int InsertIndexOf(int newScore)
|
private int InsertIndexOf(int newScore, IList<Result> list)
|
||||||
{
|
{
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (; index < lbResults.Items.Count; index++)
|
for (; index < list.Count; index++)
|
||||||
{
|
{
|
||||||
Result result = lbResults.Items[index] as Result;
|
var result = list[index];
|
||||||
if (newScore > result?.Score)
|
if (newScore > result.Score)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -236,7 +247,7 @@ namespace Wox
|
|||||||
public ResultPanel()
|
public ResultPanel()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_results = new ObservableCollection<Result>();
|
_results = new ListBoxItems();
|
||||||
lbResults.ItemsSource = _results;
|
lbResults.ItemsSource = _results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -429,7 +429,7 @@ namespace Wox
|
|||||||
IcoPath = "Images/app.png",
|
IcoPath = "Images/app.png",
|
||||||
PluginDirectory = Path.GetDirectoryName(Application.ExecutablePath)
|
PluginDirectory = Path.GetDirectoryName(Application.ExecutablePath)
|
||||||
}
|
}
|
||||||
});
|
}, "test id");
|
||||||
|
|
||||||
foreach (string theme in ThemeManager.Theme.LoadAvailableThemes())
|
foreach (string theme in ThemeManager.Theme.LoadAvailableThemes())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using System.Linq;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Wox.Infrastructure.Storage;
|
using Wox.Infrastructure.Storage;
|
||||||
|
using Wox.Plugin;
|
||||||
|
|
||||||
namespace Wox.Storage
|
namespace Wox.Storage
|
||||||
{
|
{
|
||||||
@@ -16,6 +17,9 @@ namespace Wox.Storage
|
|||||||
private int MaxHistory = 300;
|
private int MaxHistory = 300;
|
||||||
private int cursor = 0;
|
private int cursor = 0;
|
||||||
|
|
||||||
|
public static PluginMetadata MetaData { get; } = new PluginMetadata
|
||||||
|
{ ID = "Query history", Name = "Query history" };
|
||||||
|
|
||||||
protected override string ConfigFolder
|
protected override string ConfigFolder
|
||||||
{
|
{
|
||||||
get { return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Config"); }
|
get { return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Config"); }
|
||||||
|
|||||||
@@ -106,6 +106,7 @@
|
|||||||
<Compile Include="Converters\OpacityModeConverter.cs" />
|
<Compile Include="Converters\OpacityModeConverter.cs" />
|
||||||
<Compile Include="Converters\StringEmptyConverter.cs" />
|
<Compile Include="Converters\StringEmptyConverter.cs" />
|
||||||
<Compile Include="Converters\StringNullOrEmptyToVisibilityConverter.cs" />
|
<Compile Include="Converters\StringNullOrEmptyToVisibilityConverter.cs" />
|
||||||
|
<Compile Include="Helper\ListBoxItems.cs" />
|
||||||
<Compile Include="Helper\SingletonWindowOpener.cs" />
|
<Compile Include="Helper\SingletonWindowOpener.cs" />
|
||||||
<Compile Include="ImageLoader\ImageCacheStroage.cs" />
|
<Compile Include="ImageLoader\ImageCacheStroage.cs" />
|
||||||
<Compile Include="ShellContext\ShellContextMenuManager.cs" />
|
<Compile Include="ShellContext\ShellContextMenuManager.cs" />
|
||||||
@@ -280,7 +281,9 @@
|
|||||||
<Generator>ResXFileCodeGenerator</Generator>
|
<Generator>ResXFileCodeGenerator</Generator>
|
||||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
<None Include="App.config" />
|
<None Include="App.config">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
</None>
|
||||||
<None Include="Properties\Settings.settings">
|
<None Include="Properties\Settings.settings">
|
||||||
<Generator>SettingsSingleFileGenerator</Generator>
|
<Generator>SettingsSingleFileGenerator</Generator>
|
||||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||||
@@ -305,9 +308,6 @@
|
|||||||
<Name>Wox.Plugin</Name>
|
<Name>Wox.Plugin</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
|
||||||
<WCFMetadata Include="Service References\" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
|
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user