mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 04:07:40 +02:00
structure change
This commit is contained in:
27
WinAlfred/Commands/Command.cs
Normal file
27
WinAlfred/Commands/Command.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using WinAlfred.Helper;
|
||||
using WinAlfred.Plugin;
|
||||
|
||||
namespace WinAlfred.Commands
|
||||
{
|
||||
public class Command
|
||||
{
|
||||
private PluginCommand pluginCmd;
|
||||
private SystemCommand systemCmd;
|
||||
|
||||
public Command(MainWindow window)
|
||||
{
|
||||
pluginCmd = new PluginCommand(window);
|
||||
systemCmd = new SystemCommand(window);
|
||||
}
|
||||
|
||||
public void DispatchCommand(Query query)
|
||||
{
|
||||
systemCmd.Dispatch(query);
|
||||
pluginCmd.Dispatch(query);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using WinAlfred.Helper;
|
||||
using WinAlfred.Plugin;
|
||||
|
||||
namespace WinAlfred.Commands
|
||||
{
|
||||
public class CommandDispatcher
|
||||
{
|
||||
private PluginCommand pluginCmd = new PluginCommand();
|
||||
private SystemCommand systemCmd = new SystemCommand();
|
||||
|
||||
//public delegate void resultUpdateDelegate(List<Result> results);
|
||||
|
||||
//public event resultUpdateDelegate OnResultUpdateEvent;
|
||||
|
||||
//protected virtual void OnOnResultUpdateEvent(List<Result> list)
|
||||
//{
|
||||
// resultUpdateDelegate handler = OnResultUpdateEvent;
|
||||
// if (handler != null) handler(list);
|
||||
//}
|
||||
|
||||
public void DispatchCommand(Query query)
|
||||
{
|
||||
systemCmd.Dispatch(query);
|
||||
pluginCmd.Dispatch(query);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,44 +2,54 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using WinAlfred.Helper;
|
||||
using WinAlfred.Plugin;
|
||||
using WinAlfred.PluginLoader;
|
||||
|
||||
namespace WinAlfred.Commands
|
||||
{
|
||||
public class PluginCommand
|
||||
public class PluginCommand : BaseCommand
|
||||
{
|
||||
public void Dispatch(Query q)
|
||||
public PluginCommand(MainWindow mainWindow)
|
||||
: base(mainWindow)
|
||||
{
|
||||
//ThreadPool.QueueUserWorkItem(state =>
|
||||
//{
|
||||
|
||||
}
|
||||
|
||||
public override void Dispatch(Query q)
|
||||
{
|
||||
|
||||
foreach (PluginPair pair in Plugins.AllPlugins)
|
||||
{
|
||||
if (pair.Metadata.ActionKeyword == q.ActionName)
|
||||
{
|
||||
try
|
||||
PluginPair pair1 = pair;
|
||||
ThreadPool.QueueUserWorkItem(state =>
|
||||
{
|
||||
pair.Plugin.Query(q).ForEach(o => o.PluginDirectory = pair.Metadata.PluginDirecotry);
|
||||
}
|
||||
catch (Exception queryException)
|
||||
{
|
||||
Log.Error(string.Format("Plugin {0} query failed: {1}", pair.Metadata.Name,
|
||||
queryException.Message));
|
||||
#if (DEBUG)
|
||||
try
|
||||
{
|
||||
throw;
|
||||
List<Result> r = pair1.Plugin.Query(q);
|
||||
r.ForEach(o =>
|
||||
{
|
||||
o.PluginDirectory = pair1.Metadata.PluginDirecotry;
|
||||
o.OriginQuery = q;
|
||||
});
|
||||
UpdateResultView(r);
|
||||
}
|
||||
catch (Exception queryException)
|
||||
{
|
||||
Log.Error(string.Format("Plugin {0} query failed: {1}", pair1.Metadata.Name,
|
||||
queryException.Message));
|
||||
#if (DEBUG)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
resultCtrl.Dispatcher.Invoke(new Action(() =>
|
||||
{
|
||||
resultCtrl.AddResults(results.OrderByDescending(o => o.Score).ToList());
|
||||
resultCtrl.SelectFirst();
|
||||
}));
|
||||
//});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,15 +2,38 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using WinAlfred.Plugin;
|
||||
using WinAlfred.PluginLoader;
|
||||
|
||||
namespace WinAlfred.Commands
|
||||
{
|
||||
public class SystemCommand
|
||||
public class SystemCommand : BaseCommand
|
||||
{
|
||||
public void Dispatch(Query query)
|
||||
private List<PluginPair> systemPlugins;
|
||||
|
||||
public SystemCommand(MainWindow window)
|
||||
: base(window)
|
||||
{
|
||||
|
||||
systemPlugins = Plugins.AllPlugins.Where(o => o.Metadata.PluginType == PluginType.System).ToList();
|
||||
}
|
||||
|
||||
public override void Dispatch(Query query)
|
||||
{
|
||||
foreach (PluginPair pair in systemPlugins)
|
||||
{
|
||||
PluginPair pair1 = pair;
|
||||
ThreadPool.QueueUserWorkItem(state =>
|
||||
{
|
||||
List<Result> results = pair1.Plugin.Query(query);
|
||||
foreach (Result result in results)
|
||||
{
|
||||
result.PluginDirectory = pair1.Metadata.PluginDirecotry;
|
||||
result.OriginQuery = query;
|
||||
}
|
||||
UpdateResultView(results);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user