Refactoring command args and change the signal instance implement.

This commit is contained in:
qianlifeng
2014-10-21 18:16:05 +08:00
parent 1cf79d8fbc
commit be33ac3c4f
14 changed files with 712 additions and 149 deletions

View File

@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Input;
namespace Wox.CommandArgs
{
internal static class CommandArgsFactory
{
private static List<ICommandArg> commandArgs;
static CommandArgsFactory()
{
var type = typeof(ICommandArg);
commandArgs = Assembly.GetExecutingAssembly()
.GetTypes()
.Where(p => type.IsAssignableFrom(p) && !p.IsInterface)
.Select(t => Activator.CreateInstance(t) as ICommandArg).ToList();
}
public static void Execute(IList<string> args)
{
if (args.Count > 0)
{
string command = args[0];
ICommandArg cmd = commandArgs.FirstOrDefault(o => o.Command.ToLower() == command);
if (cmd != null)
{
args.RemoveAt(0); //remove command itself
cmd.Execute(args);
}
}
else
{
App.Window.ShowApp();
}
}
}
}

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Wox.CommandArgs
{
public class HideStartCommandArg : ICommandArg
{
public string Command
{
get { return "hidestart"; }
}
public void Execute(IList<string> args)
{
//App.Window.ShowApp();
//App.Window.HideApp();
}
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Wox.CommandArgs
{
interface ICommandArg
{
string Command { get; }
void Execute(IList<string> args);
}
}

View File

@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using Wox.Helper;
namespace Wox.CommandArgs
{
public class InstallPluginCommandArg : ICommandArg
{
public string Command
{
get { return "installplugin"; }
}
public void Execute(IList<string> args)
{
if (args.Count > 0)
{
var path = args[0];
if (!File.Exists(path))
{
MessageBox.Show("Plugin " + path + " didn't exist");
return;
}
PluginInstaller.Install(path);
}
}
}
}

View File

@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
namespace Wox.CommandArgs
{
public class PluginDebuggerCommandArg : ICommandArg
{
public string Command
{
get { return "plugindebugger"; }
}
public void Execute(IList<string> args)
{
if (args.Count > 0)
{
var pluginFolderPath = args[0];
PluginLoader.Plugins.ActivatePluginDebugger(pluginFolderPath);
}
}
}
}

View File

@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Wox.CommandArgs
{
public class QueryCommandArg : ICommandArg
{
public string Command
{
get { return "query"; }
}
public void Execute(IList<string> args)
{
if (args.Count > 0)
{
string query = args[0];
App.Window.ChangeQuery(query);
}
App.Window.ShowApp();
}
}
}

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Wox.PluginLoader;
namespace Wox.CommandArgs
{
public class ReloadPluginCommandArg : ICommandArg
{
public string Command
{
get { return "reloadplugin"; }
}
public void Execute(IList<string> args)
{
Plugins.Init();
}
}
}