mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-07 09:28:03 +08:00
structure change
This commit is contained in:
parent
1eb3f449e2
commit
dc51bc39ab
@ -1,36 +0,0 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的常规信息通过以下
|
||||
// 特性集控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("WinAlfred.Plugin.System")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Microsoft")]
|
||||
[assembly: AssemblyProduct("WinAlfred.Plugin.System")]
|
||||
[assembly: AssemblyCopyright("Copyright © Microsoft 2013")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 将 ComVisible 设置为 false 使此程序集中的类型
|
||||
// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
|
||||
// 则将该类型上的 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||
[assembly: Guid("5cdfe514-80c9-4d82-94e7-c6f79a26ccda")]
|
||||
|
||||
// 程序集的版本信息由下面四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 生成号
|
||||
// 修订号
|
||||
//
|
||||
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
||||
// 方法是按如下所示使用“*”:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
@ -1,72 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{E515011D-A769-418B-8761-ABE6F29827A0}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>WinAlfred.Plugin.System</RootNamespace>
|
||||
<AssemblyName>WinAlfred.Plugin.System</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Main.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\WinAlfred.Plugin\WinAlfred.Plugin.csproj">
|
||||
<Project>{8451ecdd-2ea4-4966-bb0a-7bbc40138e80}</Project>
|
||||
<Name>WinAlfred.Plugin</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="plugin.ini">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Images\lock.png" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>xcopy /Y $(TargetDir)$(TargetFileName) $(SolutionDir)WinAlfred\bin\Debug\Plugins\System\
|
||||
xcopy /Y $(TargetDir)plugin.ini $(SolutionDir)WinAlfred\bin\Debug\Plugins\System\
|
||||
xcopy /Y $(ProjectDir)Images\*.* $(SolutionDir)WinAlfred\bin\Debug\Plugins\System\Images\</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
@ -1,8 +0,0 @@
|
||||
[plugin]
|
||||
ActionKeyword = sys
|
||||
Name = System Commands
|
||||
Author = qianlifeng
|
||||
Version = 0.1
|
||||
Language = csharp
|
||||
Description = test
|
||||
ExecuteFile = WinAlfred.Plugin.System.dll
|
@ -1,20 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace WinAlfred.Plugin.System
|
||||
{
|
||||
public class CMD:IPlugin
|
||||
public class CMD : ISystemPlugin
|
||||
{
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
List<Result> results = new List<Result>();
|
||||
if (query.RawQuery.StartsWith(">") && query.RawQuery.Length > 1)
|
||||
{
|
||||
string cmd = query.RawQuery.Substring(1);
|
||||
Result result = new Result
|
||||
{
|
||||
Title = cmd,
|
||||
SubTitle = "execute command through command shell" ,
|
||||
IcoPath = "Images/cmd.png",
|
||||
Action = () =>
|
||||
{
|
||||
Process process = new Process();
|
||||
ProcessStartInfo startInfo = new ProcessStartInfo();
|
||||
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
|
||||
startInfo.FileName = "cmd.exe";
|
||||
startInfo.Arguments = "/C " + cmd;
|
||||
process.StartInfo = startInfo;
|
||||
process.Start();
|
||||
}
|
||||
};
|
||||
results.Add(result);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
public void Init()
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return "CMD";
|
||||
}
|
||||
}
|
||||
|
||||
public string Description
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Execute shell commands.";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,5 +7,7 @@ namespace WinAlfred.Plugin.System
|
||||
{
|
||||
public interface ISystemPlugin : IPlugin
|
||||
{
|
||||
string Name { get; }
|
||||
string Description { get; }
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
@ -8,7 +7,7 @@ using System.Windows.Forms;
|
||||
|
||||
namespace WinAlfred.Plugin.System
|
||||
{
|
||||
public class Main : IPlugin
|
||||
public class Sys : ISystemPlugin
|
||||
{
|
||||
List<Result> availableResults = new List<Result>();
|
||||
|
||||
@ -20,18 +19,18 @@ namespace WinAlfred.Plugin.System
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
List<Result> results = new List<Result>();
|
||||
if (query.ActionParameters.Count == 0)
|
||||
|
||||
foreach (Result availableResult in availableResults)
|
||||
{
|
||||
results = availableResults;
|
||||
}
|
||||
else
|
||||
{
|
||||
results.AddRange(availableResults.Where(result => result.Title.ToLower().Contains(query.ActionParameters[0].ToLower())));
|
||||
if (availableResult.Title.ToLower().StartsWith(query.RawQuery.ToLower()))
|
||||
{
|
||||
results.Add(availableResult);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
public void Init()
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
availableResults.Add(new Result
|
||||
{
|
||||
@ -54,7 +53,23 @@ namespace WinAlfred.Plugin.System
|
||||
Score = 20,
|
||||
IcoPath = "Images\\lock.png",
|
||||
Action = () => LockWorkStation()
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return "sys";
|
||||
}
|
||||
}
|
||||
|
||||
public string Description
|
||||
{
|
||||
get
|
||||
{
|
||||
return "provide system commands";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -32,6 +32,7 @@
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Data" />
|
||||
@ -41,6 +42,8 @@
|
||||
<Compile Include="CMD.cs" />
|
||||
<Compile Include="ISystemPlugin.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Sys.cs" />
|
||||
<Compile Include="ThirdpartyPluginIndicator.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\WinAlfred.Plugin\WinAlfred.Plugin.csproj">
|
||||
@ -49,6 +52,10 @@
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>
|
||||
</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
|
@ -5,6 +5,6 @@ namespace WinAlfred.Plugin
|
||||
public interface IPlugin
|
||||
{
|
||||
List<Result> Query(Query query);
|
||||
void Init();
|
||||
void Init(PluginInitContext context);
|
||||
}
|
||||
}
|
13
WinAlfred.Plugin/PluginInitContext.cs
Normal file
13
WinAlfred.Plugin/PluginInitContext.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace WinAlfred.Plugin
|
||||
{
|
||||
public class PluginInitContext
|
||||
{
|
||||
public List<PluginPair> Plugins { get; set; }
|
||||
public Action<string> ChangeQuery { get; set; }
|
||||
}
|
||||
}
|
@ -11,6 +11,15 @@ namespace WinAlfred.Plugin
|
||||
public string IcoPath { get; set; }
|
||||
public Action Action { get; set; }
|
||||
public int Score { get; set; }
|
||||
|
||||
//todo: this should be controlled by system, not visible to users
|
||||
/// <summary>
|
||||
/// Only resulsts that originQuery match with curren query will be displayed in the panel
|
||||
/// </summary>
|
||||
public Query OriginQuery { get; set; }
|
||||
/// <summary>
|
||||
/// context results connected with current reuslt, usually, it can use <- or -> navigate context results
|
||||
/// </summary>
|
||||
public List<Result> ContextResults { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
@ -60,6 +60,7 @@
|
||||
<Compile Include="AllowedLanguage.cs" />
|
||||
<Compile Include="IPlugin.cs" />
|
||||
<Compile Include="Plugin.cs" />
|
||||
<Compile Include="PluginInitContext.cs" />
|
||||
<Compile Include="PluginMetadata.cs" />
|
||||
<Compile Include="PluginType.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
@ -7,8 +7,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinAlfred.Plugin", "WinAlfr
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Plugin", "Plugin", "{3A73F5A7-0335-40D8-BF7C-F20BE5D0BA87}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinAlfred.Plugin.System", "Plugins\WinAlfred.Plugin.System\WinAlfred.Plugin.System.csproj", "{E515011D-A769-418B-8761-ABE6F29827A0}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinAlfred", "WinAlfred\WinAlfred.csproj", "{DB90F671-D861-46BB-93A3-F1304F5BA1C5}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PyWinAlfred", "PyWinAlfred\PyWinAlfred.vcxproj", "{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}"
|
||||
@ -60,20 +58,6 @@ Global
|
||||
{8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Release|Win32.Build.0 = Release|x86
|
||||
{8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{E515011D-A769-418B-8761-ABE6F29827A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E515011D-A769-418B-8761-ABE6F29827A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E515011D-A769-418B-8761-ABE6F29827A0}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{E515011D-A769-418B-8761-ABE6F29827A0}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{E515011D-A769-418B-8761-ABE6F29827A0}.Debug|Win32.ActiveCfg = Debug|Any CPU
|
||||
{E515011D-A769-418B-8761-ABE6F29827A0}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{E515011D-A769-418B-8761-ABE6F29827A0}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{E515011D-A769-418B-8761-ABE6F29827A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E515011D-A769-418B-8761-ABE6F29827A0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E515011D-A769-418B-8761-ABE6F29827A0}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{E515011D-A769-418B-8761-ABE6F29827A0}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{E515011D-A769-418B-8761-ABE6F29827A0}.Release|Win32.ActiveCfg = Release|Any CPU
|
||||
{E515011D-A769-418B-8761-ABE6F29827A0}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{E515011D-A769-418B-8761-ABE6F29827A0}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
@ -124,7 +108,4 @@ Global
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{E515011D-A769-418B-8761-ABE6F29827A0} = {3A73F5A7-0335-40D8-BF7C-F20BE5D0BA87}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 4.5 KiB |
@ -13,6 +13,7 @@ using WinAlfred.Helper;
|
||||
using WinAlfred.Plugin;
|
||||
using WinAlfred.PluginLoader;
|
||||
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
|
||||
using Timer = System.Threading.Timer;
|
||||
|
||||
namespace WinAlfred
|
||||
{
|
||||
@ -21,11 +22,12 @@ namespace WinAlfred
|
||||
private KeyboardHook hook = new KeyboardHook();
|
||||
private List<Result> results = new List<Result>();
|
||||
private NotifyIcon notifyIcon = null;
|
||||
private CommandDispatcher cmdDispatcher = new CommandDispatcher();
|
||||
private Command cmdDispatcher;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
hook.KeyPressed += OnHotKey;
|
||||
hook.RegisterHotKey(XModifierKeys.Alt, Keys.Space);
|
||||
resultCtrl.resultItemChangedEvent += resultCtrl_resultItemChangedEvent;
|
||||
@ -51,7 +53,12 @@ namespace WinAlfred
|
||||
private void resultCtrl_resultItemChangedEvent()
|
||||
{
|
||||
Height = resultCtrl.pnlContainer.ActualHeight + tbQuery.Height + tbQuery.Margin.Top + tbQuery.Margin.Bottom;
|
||||
resultCtrl.Margin = results.Count > 0 ? new Thickness { Bottom = 10, Left = 10, Right = 10 } : new Thickness { Bottom = 0, Left = 10, Right = 10 };
|
||||
resultCtrl.Margin = resultCtrl.GetCurrentResultCount() > 0 ? new Thickness { Bottom = 10, Left = 10, Right = 10 } : new Thickness { Bottom = 0, Left = 10, Right = 10 };
|
||||
|
||||
if (resultCtrl.GetCurrentResultCount() == 1)
|
||||
{
|
||||
resultCtrl.SelectFirst();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnHotKey(object sender, KeyPressedEventArgs e)
|
||||
@ -68,6 +75,19 @@ namespace WinAlfred
|
||||
|
||||
private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
resultCtrl.Dirty = true;
|
||||
//auto clear results after 50ms if there are any results returned by plugins
|
||||
//why we do this? because if we clear resulsts in the start of the text changed event
|
||||
//we will see the splash. The more closer that clear and addResult method, the less splash we will see.
|
||||
new Timer(o =>
|
||||
{
|
||||
if (resultCtrl.Dirty)
|
||||
{
|
||||
resultCtrl.Dispatcher.Invoke(new Action(() => resultCtrl.Clear()));
|
||||
}
|
||||
}, null, TimeSpan.FromMilliseconds(50),TimeSpan.FromMilliseconds(-1));
|
||||
if (string.IsNullOrEmpty(tbQuery.Text)) return;
|
||||
|
||||
var q = new Query(tbQuery.Text);
|
||||
cmdDispatcher.DispatchCommand(q);
|
||||
}
|
||||
@ -77,7 +97,7 @@ namespace WinAlfred
|
||||
Hide();
|
||||
}
|
||||
|
||||
private void ShowWinAlfred()
|
||||
public void ShowWinAlfred()
|
||||
{
|
||||
tbQuery.SelectAll();
|
||||
Show();
|
||||
@ -87,7 +107,8 @@ namespace WinAlfred
|
||||
|
||||
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Plugins.Init();
|
||||
Plugins.Init(this);
|
||||
cmdDispatcher = new Command(this);
|
||||
ShowWinAlfred();
|
||||
InitialTray();
|
||||
}
|
||||
@ -118,5 +139,14 @@ namespace WinAlfred
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnUpdateResultView(List<Result> list)
|
||||
{
|
||||
resultCtrl.Dispatcher.Invoke(new Action(() =>
|
||||
{
|
||||
List<Result> l = list.Where(o => o.OriginQuery != null && o.OriginQuery.RawQuery == tbQuery.Text).OrderByDescending(o => o.Score).ToList();
|
||||
resultCtrl.AddResults(l);
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
@ -30,25 +30,18 @@ namespace WinAlfred.PluginLoader
|
||||
|
||||
private static void ParseSystemPlugins()
|
||||
{
|
||||
try
|
||||
{
|
||||
Assembly asm = Assembly.GetAssembly(typeof (CMD));
|
||||
List<Type> types = asm.GetTypes().Where(o => o.GetInterfaces().Contains(typeof(ISystemPlugin))).ToList();
|
||||
foreach (Type type in types)
|
||||
{
|
||||
ISystemPlugin sysPlugin = Activator.CreateInstance(types[0]) as ISystemPlugin;
|
||||
PluginMetadata metadata = new PluginMetadata();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(string.Format("Cound't load system plugin: {0}", e.Message));
|
||||
#if (DEBUG)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
PluginMetadata metadata = new PluginMetadata();
|
||||
metadata.Name = "System Plugins";
|
||||
metadata.Author = "System";
|
||||
metadata.Description = "system plugins collection";
|
||||
metadata.Language = AllowedLanguage.CSharp;
|
||||
metadata.Version = "1.0";
|
||||
metadata.PluginType = PluginType.System;
|
||||
metadata.ActionKeyword = "*";
|
||||
metadata.ExecuteFileName = "WinAlfred.Plugin.System.dll";
|
||||
metadata.ExecuteFilePath = AppDomain.CurrentDomain.BaseDirectory + metadata.ExecuteFileName;
|
||||
metadata.PluginDirecotry = AppDomain.CurrentDomain.BaseDirectory;
|
||||
pluginMetadatas.Add(metadata);
|
||||
}
|
||||
|
||||
private static void ParseThirdPartyPlugins()
|
||||
|
@ -5,6 +5,7 @@ using System.Reflection;
|
||||
using System.Threading;
|
||||
using WinAlfred.Helper;
|
||||
using WinAlfred.Plugin;
|
||||
using WinAlfred.Plugin.System;
|
||||
|
||||
namespace WinAlfred.PluginLoader
|
||||
{
|
||||
@ -20,28 +21,23 @@ namespace WinAlfred.PluginLoader
|
||||
try
|
||||
{
|
||||
Assembly asm = Assembly.LoadFile(metadata.ExecuteFilePath);
|
||||
List<Type> types = asm.GetTypes().Where(o => o.GetInterfaces().Contains(typeof (IPlugin))).ToList();
|
||||
List<Type> types = asm.GetTypes().Where(o => o.IsClass && o.GetInterfaces().Contains(typeof(IPlugin)) || o.GetInterfaces().Contains(typeof(ISystemPlugin))).ToList();
|
||||
if (types.Count == 0)
|
||||
{
|
||||
Log.Error(string.Format("Cound't load plugin {0}: didn't find the class who implement IPlugin",
|
||||
metadata.Name));
|
||||
continue;
|
||||
}
|
||||
if (types.Count > 1)
|
||||
{
|
||||
Log.Error(
|
||||
string.Format(
|
||||
"Cound't load plugin {0}: find more than one class who implement IPlugin, there should only one class implement IPlugin",
|
||||
metadata.Name));
|
||||
continue;
|
||||
}
|
||||
|
||||
PluginPair pair = new PluginPair()
|
||||
foreach (Type type in types)
|
||||
{
|
||||
Plugin = Activator.CreateInstance(types[0]) as IPlugin,
|
||||
Metadata = metadata
|
||||
};
|
||||
plugins.Add(pair);
|
||||
PluginPair pair = new PluginPair()
|
||||
{
|
||||
Plugin = Activator.CreateInstance(type) as IPlugin,
|
||||
Metadata = metadata
|
||||
};
|
||||
plugins.Add(pair);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -61,10 +57,7 @@ namespace WinAlfred.PluginLoader
|
||||
|
||||
private void InitPlugin(List<PluginPair> plugins)
|
||||
{
|
||||
foreach (IPlugin plugin in plugins.Select(pluginPair => pluginPair.Plugin))
|
||||
{
|
||||
new Thread(plugin.Init).Start();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using WinAlfred.Plugin;
|
||||
|
||||
namespace WinAlfred.PluginLoader
|
||||
@ -10,11 +11,24 @@ namespace WinAlfred.PluginLoader
|
||||
{
|
||||
private static List<PluginPair> plugins = new List<PluginPair>();
|
||||
|
||||
public static void Init()
|
||||
public static void Init(MainWindow window)
|
||||
{
|
||||
plugins.Clear();
|
||||
plugins.AddRange(new PythonPluginLoader().LoadPlugin());
|
||||
plugins.AddRange(new CSharpPluginLoader().LoadPlugin());
|
||||
foreach (IPlugin plugin in plugins.Select(pluginPair => pluginPair.Plugin))
|
||||
{
|
||||
IPlugin plugin1 = plugin;
|
||||
ThreadPool.QueueUserWorkItem(o => plugin1.Init(new PluginInitContext()
|
||||
{
|
||||
Plugins = plugins,
|
||||
ChangeQuery = s =>
|
||||
{
|
||||
window.tbQuery.Text = s;
|
||||
window.ShowWinAlfred();
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
public static List<PluginPair> AllPlugins
|
||||
|
@ -22,10 +22,6 @@ namespace WinAlfred.PluginLoader
|
||||
plugins.Add(pair);
|
||||
}
|
||||
|
||||
foreach (IPlugin plugin in plugins.Select(pluginPair => pluginPair.Plugin))
|
||||
{
|
||||
new Thread(plugin.Init).Start();
|
||||
}
|
||||
return plugins;
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ namespace WinAlfred.PluginLoader
|
||||
|
||||
}
|
||||
|
||||
public void Init()
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
InitPythonEnv();
|
||||
}
|
||||
|
@ -21,7 +21,7 @@
|
||||
<TextBlock x:Name="tbTitle" FontSize="16" Foreground="#37392c" FontWeight="Medium">Title</TextBlock>
|
||||
<TextBlock Grid.Row="1" Foreground="#8e94a4" x:Name="tbSubTitle">sdfdsf</TextBlock>
|
||||
</Grid>
|
||||
<DockPanel Grid.Column="2" >
|
||||
<DockPanel Grid.Column="2" Visibility="Hidden">
|
||||
<Image Source="Images\ctrl.png" VerticalAlignment="Center"/>
|
||||
<TextBlock x:Name="tbIndex" FontSize="16" Foreground="#5c1f87" Margin="0 5 0 0" Text="1" VerticalAlignment="Center" HorizontalAlignment="Left" />
|
||||
</DockPanel>
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
@ -39,7 +40,7 @@ namespace WinAlfred
|
||||
|
||||
tbTitle.Text = result.Title;
|
||||
tbSubTitle.Text = result.SubTitle;
|
||||
if (!string.IsNullOrEmpty(result.IcoPath))
|
||||
if (!string.IsNullOrEmpty(result.IcoPath) && File.Exists(result.PluginDirectory + result.IcoPath))
|
||||
{
|
||||
imgIco.Source = new BitmapImage(new Uri(result.PluginDirectory + result.IcoPath));
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ namespace WinAlfred
|
||||
{
|
||||
public partial class ResultPanel : UserControl
|
||||
{
|
||||
public bool Dirty { get; set; }
|
||||
|
||||
public delegate void ResultItemsChanged();
|
||||
|
||||
public event ResultItemsChanged resultItemChangedEvent;
|
||||
@ -19,7 +21,14 @@ namespace WinAlfred
|
||||
|
||||
public void AddResults(List<Result> results)
|
||||
{
|
||||
pnlContainer.Children.Clear();
|
||||
if (results.Count == 0) return;
|
||||
|
||||
if (Dirty)
|
||||
{
|
||||
Dirty = false;
|
||||
pnlContainer.Children.Clear();
|
||||
}
|
||||
|
||||
for (int i = 0; i < results.Count; i++)
|
||||
{
|
||||
Result result = results[i];
|
||||
@ -41,6 +50,11 @@ namespace WinAlfred
|
||||
OnResultItemChangedEvent();
|
||||
}
|
||||
|
||||
public int GetCurrentResultCount()
|
||||
{
|
||||
return pnlContainer.Children.Count;
|
||||
}
|
||||
|
||||
private int GetCurrentSelectedResultIndex()
|
||||
{
|
||||
for (int i = 0; i < pnlContainer.Children.Count; i++)
|
||||
@ -114,7 +128,7 @@ namespace WinAlfred
|
||||
if (index < oldIndex)
|
||||
{
|
||||
//move up and old item is at the top of the scroll view
|
||||
if ( newItemBottomPoint.Y - sv.VerticalOffset == 0)
|
||||
if (newItemBottomPoint.Y - sv.VerticalOffset == 0)
|
||||
{
|
||||
scrollPosition = sv.VerticalOffset - resultItemControl.ActualHeight;
|
||||
}
|
||||
@ -160,5 +174,12 @@ namespace WinAlfred
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
pnlContainer.Children.Clear();
|
||||
pnlContainer.Height = 0;
|
||||
OnResultItemChangedEvent();
|
||||
}
|
||||
}
|
||||
}
|
@ -64,15 +64,16 @@
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Compile Include="Commands\CommandDispatcher.cs" />
|
||||
<Compile Include="Commands\BaseCommand.cs" />
|
||||
<Compile Include="Commands\Command.cs" />
|
||||
<Compile Include="Commands\PluginCommand.cs" />
|
||||
<Compile Include="Commands\SystemCommand.cs" />
|
||||
<Compile Include="Helper\IniParser.cs" />
|
||||
<Compile Include="Helper\KeyboardHook.cs" />
|
||||
<Compile Include="Helper\Log.cs" />
|
||||
<Compile Include="Helper\WinAlfredException.cs" />
|
||||
<Compile Include="PluginLoader\BasePluginLoader.cs" />
|
||||
<Compile Include="PluginLoader\CSharpPluginLoader.cs" />
|
||||
<Compile Include="Helper\IniParser.cs" />
|
||||
<Compile Include="PluginLoader\Plugins.cs" />
|
||||
<Compile Include="PluginLoader\PythonPluginLoader.cs" />
|
||||
<Compile Include="PluginLoader\PythonPluginWrapper.cs" />
|
||||
@ -158,6 +159,9 @@
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>xcopy /Y $(ProjectDir)Images\*.* $(SolutionDir)WinAlfred\bin\Debug\Images\</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
|
Loading…
Reference in New Issue
Block a user