Mouse select support & Code refactoring

This commit is contained in:
qianlifeng
2014-01-26 21:18:01 +08:00
parent 36018fe570
commit c7dfaac61a
12 changed files with 106 additions and 89 deletions

View File

@@ -8,24 +8,11 @@ namespace WinAlfred.Commands
{
public abstract class BaseCommand
{
private MainWindow window;
public void Dispatch(Query query)
{
Dispatch(query, true);
}
public abstract void Dispatch(Query query, bool updateView);
//TODO:Ugly, we should subscribe events here, instead of just use usercontrol as the parameter
protected BaseCommand(MainWindow window)
{
this.window = window;
}
public abstract void Dispatch(Query query, bool updateView = true);
protected void UpdateResultView(List<Result> results)
{
window.OnUpdateResultView(results);
App.Window.OnUpdateResultView(results);
}
}
}

View File

@@ -1,33 +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 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);
}
public void DispatchCommand(Query query,bool updateView)
{
systemCmd.Dispatch(query,updateView);
pluginCmd.Dispatch(query,updateView);
}
}
}

View File

@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WinAlfred.Helper;
using WinAlfred.Plugin;
namespace WinAlfred.Commands
{
internal static class CommandFactory
{
private static PluginCommand pluginCmd;
private static SystemCommand systemCmd;
public static void DispatchCommand(Query query, bool updateView = true)
{
//lazy init command instance.
if (pluginCmd == null)
{
pluginCmd = new PluginCommand();
}
if (systemCmd == null)
{
systemCmd = new SystemCommand();
}
systemCmd.Dispatch(query,updateView);
pluginCmd.Dispatch(query,updateView);
}
}
}

View File

@@ -14,13 +14,7 @@ namespace WinAlfred.Commands
private string currentPythonModulePath = string.Empty;
private IntPtr GIL;
public PluginCommand(MainWindow mainWindow)
: base(mainWindow)
{
}
public override void Dispatch(Query q,bool updateView)
public override void Dispatch(Query q,bool updateView = true)
{
PluginPair thirdPlugin = Plugins.AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == q.ActionName);
if (thirdPlugin != null && !string.IsNullOrEmpty(thirdPlugin.Metadata.ActionKeyword))

View File

@@ -12,13 +12,12 @@ namespace WinAlfred.Commands
{
private List<PluginPair> systemPlugins;
public SystemCommand(MainWindow window)
: base(window)
public SystemCommand()
{
systemPlugins = Plugins.AllPlugins.Where(o => o.Metadata.PluginType == PluginType.System).ToList();
}
public override void Dispatch(Query query,bool updateView)
public override void Dispatch(Query query,bool updateView = true)
{
foreach (PluginPair pair in systemPlugins)
{