mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 20:57:22 +02:00
Refactoring command args and change the signal instance implement.
This commit is contained in:
41
Wox/CommandArgs/CommandArgsFactory.cs
Normal file
41
Wox/CommandArgs/CommandArgsFactory.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
21
Wox/CommandArgs/HideStartCommandArg.cs
Normal file
21
Wox/CommandArgs/HideStartCommandArg.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Wox/CommandArgs/ICommandArg.cs
Normal file
13
Wox/CommandArgs/ICommandArg.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
32
Wox/CommandArgs/InstallPluginCommandArg.cs
Normal file
32
Wox/CommandArgs/InstallPluginCommandArg.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
25
Wox/CommandArgs/PluginDebuggerCommandArg.cs
Normal file
25
Wox/CommandArgs/PluginDebuggerCommandArg.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
25
Wox/CommandArgs/QueryCommandArg.cs
Normal file
25
Wox/CommandArgs/QueryCommandArg.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
21
Wox/CommandArgs/ReloadPluginCommandArg.cs
Normal file
21
Wox/CommandArgs/ReloadPluginCommandArg.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user