mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 19:57:07 +02:00
Change plugin config file format (from ini to json)
This commit is contained in:
234
Plugins/Wox.Plugin.Clipboard/ClipboardMonitor.cs
Normal file
234
Plugins/Wox.Plugin.Clipboard/ClipboardMonitor.cs
Normal file
@@ -0,0 +1,234 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Wox.Plugin.Clipboard
|
||||
{
|
||||
public static class ClipboardMonitor
|
||||
{
|
||||
public delegate void OnClipboardChangeEventHandler(ClipboardFormat format, object data);
|
||||
public static event OnClipboardChangeEventHandler OnClipboardChange;
|
||||
|
||||
public static void Start()
|
||||
{
|
||||
ClipboardWatcher.Start();
|
||||
ClipboardWatcher.OnClipboardChange += (ClipboardFormat format, object data) =>
|
||||
{
|
||||
if (OnClipboardChange != null)
|
||||
OnClipboardChange(format, data);
|
||||
};
|
||||
}
|
||||
|
||||
public static void Stop()
|
||||
{
|
||||
OnClipboardChange = null;
|
||||
ClipboardWatcher.Stop();
|
||||
}
|
||||
|
||||
class ClipboardWatcher : Form
|
||||
{
|
||||
// static instance of this form
|
||||
private static ClipboardWatcher mInstance;
|
||||
|
||||
// needed to dispose this form
|
||||
static IntPtr nextClipboardViewer;
|
||||
|
||||
public delegate void OnClipboardChangeEventHandler(ClipboardFormat format, object data);
|
||||
public static event OnClipboardChangeEventHandler OnClipboardChange;
|
||||
|
||||
// start listening
|
||||
public static void Start()
|
||||
{
|
||||
// we can only have one instance if this class
|
||||
if (mInstance != null)
|
||||
return;
|
||||
|
||||
Thread t = new Thread(new ParameterizedThreadStart(x =>
|
||||
{
|
||||
Application.Run(new ClipboardWatcher());
|
||||
}));
|
||||
t.SetApartmentState(ApartmentState.STA); // give the [STAThread] attribute
|
||||
t.Start();
|
||||
}
|
||||
|
||||
// stop listening (dispose form)
|
||||
public static void Stop()
|
||||
{
|
||||
mInstance.Invoke(new MethodInvoker(() =>
|
||||
{
|
||||
ChangeClipboardChain(mInstance.Handle, nextClipboardViewer);
|
||||
}));
|
||||
mInstance.Invoke(new MethodInvoker(mInstance.Close));
|
||||
|
||||
mInstance.Dispose();
|
||||
|
||||
mInstance = null;
|
||||
}
|
||||
|
||||
// on load: (hide this window)
|
||||
protected override void SetVisibleCore(bool value)
|
||||
{
|
||||
CreateHandle();
|
||||
|
||||
mInstance = this;
|
||||
|
||||
nextClipboardViewer = SetClipboardViewer(mInstance.Handle);
|
||||
|
||||
base.SetVisibleCore(false);
|
||||
}
|
||||
|
||||
[DllImport("User32.dll", CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr SetClipboardViewer(IntPtr hWndNewViewer);
|
||||
|
||||
[DllImport("User32.dll", CharSet = CharSet.Auto)]
|
||||
public static extern bool ChangeClipboardChain(IntPtr hWndRemove, IntPtr hWndNewNext);
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
||||
public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
// defined in winuser.h
|
||||
const int WM_DRAWCLIPBOARD = 0x308;
|
||||
const int WM_CHANGECBCHAIN = 0x030D;
|
||||
|
||||
protected override void WndProc(ref Message m)
|
||||
{
|
||||
switch (m.Msg)
|
||||
{
|
||||
case WM_DRAWCLIPBOARD:
|
||||
ClipChanged();
|
||||
SendMessage(nextClipboardViewer, m.Msg, m.WParam, m.LParam);
|
||||
break;
|
||||
|
||||
case WM_CHANGECBCHAIN:
|
||||
if (m.WParam == nextClipboardViewer)
|
||||
nextClipboardViewer = m.LParam;
|
||||
else
|
||||
SendMessage(nextClipboardViewer, m.Msg, m.WParam, m.LParam);
|
||||
break;
|
||||
|
||||
default:
|
||||
base.WndProc(ref m);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static readonly string[] formats = Enum.GetNames(typeof(ClipboardFormat));
|
||||
|
||||
private void ClipChanged()
|
||||
{
|
||||
IDataObject iData = System.Windows.Forms.Clipboard.GetDataObject();
|
||||
|
||||
ClipboardFormat? format = null;
|
||||
|
||||
foreach (var f in formats)
|
||||
{
|
||||
if (iData.GetDataPresent(f))
|
||||
{
|
||||
format = (ClipboardFormat)Enum.Parse(typeof(ClipboardFormat), f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
object data = iData.GetData(format.ToString());
|
||||
|
||||
if (data == null || format == null)
|
||||
return;
|
||||
|
||||
if (OnClipboardChange != null)
|
||||
OnClipboardChange((ClipboardFormat)format, data);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public enum ClipboardFormat : byte
|
||||
{
|
||||
/// <summary>Specifies the standard ANSI text format. This static field is read-only.
|
||||
/// </summary>
|
||||
/// <filterpriority>1</filterpriority>
|
||||
Text,
|
||||
/// <summary>Specifies the standard Windows Unicode text format. This static field
|
||||
/// is read-only.</summary>
|
||||
/// <filterpriority>1</filterpriority>
|
||||
UnicodeText,
|
||||
/// <summary>Specifies the Windows device-independent bitmap (DIB) format. This static
|
||||
/// field is read-only.</summary>
|
||||
/// <filterpriority>1</filterpriority>
|
||||
Dib,
|
||||
/// <summary>Specifies a Windows bitmap format. This static field is read-only.</summary>
|
||||
/// <filterpriority>1</filterpriority>
|
||||
Bitmap,
|
||||
/// <summary>Specifies the Windows enhanced metafile format. This static field is
|
||||
/// read-only.</summary>
|
||||
/// <filterpriority>1</filterpriority>
|
||||
EnhancedMetafile,
|
||||
/// <summary>Specifies the Windows metafile format, which Windows Forms does not
|
||||
/// directly use. This static field is read-only.</summary>
|
||||
/// <filterpriority>1</filterpriority>
|
||||
MetafilePict,
|
||||
/// <summary>Specifies the Windows symbolic link format, which Windows Forms does
|
||||
/// not directly use. This static field is read-only.</summary>
|
||||
/// <filterpriority>1</filterpriority>
|
||||
SymbolicLink,
|
||||
/// <summary>Specifies the Windows Data Interchange Format (DIF), which Windows Forms
|
||||
/// does not directly use. This static field is read-only.</summary>
|
||||
/// <filterpriority>1</filterpriority>
|
||||
Dif,
|
||||
/// <summary>Specifies the Tagged Image File Format (TIFF), which Windows Forms does
|
||||
/// not directly use. This static field is read-only.</summary>
|
||||
/// <filterpriority>1</filterpriority>
|
||||
Tiff,
|
||||
/// <summary>Specifies the standard Windows original equipment manufacturer (OEM)
|
||||
/// text format. This static field is read-only.</summary>
|
||||
/// <filterpriority>1</filterpriority>
|
||||
OemText,
|
||||
/// <summary>Specifies the Windows palette format. This static field is read-only.
|
||||
/// </summary>
|
||||
/// <filterpriority>1</filterpriority>
|
||||
Palette,
|
||||
/// <summary>Specifies the Windows pen data format, which consists of pen strokes
|
||||
/// for handwriting software, Windows Forms does not use this format. This static
|
||||
/// field is read-only.</summary>
|
||||
/// <filterpriority>1</filterpriority>
|
||||
PenData,
|
||||
/// <summary>Specifies the Resource Interchange File Format (RIFF) audio format,
|
||||
/// which Windows Forms does not directly use. This static field is read-only.</summary>
|
||||
/// <filterpriority>1</filterpriority>
|
||||
Riff,
|
||||
/// <summary>Specifies the wave audio format, which Windows Forms does not directly
|
||||
/// use. This static field is read-only.</summary>
|
||||
/// <filterpriority>1</filterpriority>
|
||||
WaveAudio,
|
||||
/// <summary>Specifies the Windows file drop format, which Windows Forms does not
|
||||
/// directly use. This static field is read-only.</summary>
|
||||
/// <filterpriority>1</filterpriority>
|
||||
FileDrop,
|
||||
/// <summary>Specifies the Windows culture format, which Windows Forms does not directly
|
||||
/// use. This static field is read-only.</summary>
|
||||
/// <filterpriority>1</filterpriority>
|
||||
Locale,
|
||||
/// <summary>Specifies text consisting of HTML data. This static field is read-only.
|
||||
/// </summary>
|
||||
/// <filterpriority>1</filterpriority>
|
||||
Html,
|
||||
/// <summary>Specifies text consisting of Rich Text Format (RTF) data. This static
|
||||
/// field is read-only.</summary>
|
||||
/// <filterpriority>1</filterpriority>
|
||||
Rtf,
|
||||
/// <summary>Specifies a comma-separated value (CSV) format, which is a common interchange
|
||||
/// format used by spreadsheets. This format is not used directly by Windows Forms.
|
||||
/// This static field is read-only.</summary>
|
||||
/// <filterpriority>1</filterpriority>
|
||||
CommaSeparatedValue,
|
||||
/// <summary>Specifies the Windows Forms string class format, which Windows Forms
|
||||
/// uses to store string objects. This static field is read-only.</summary>
|
||||
/// <filterpriority>1</filterpriority>
|
||||
StringFormat,
|
||||
/// <summary>Specifies a format that encapsulates any type of Windows Forms object.
|
||||
/// This static field is read-only.</summary>
|
||||
/// <filterpriority>1</filterpriority>
|
||||
Serializable,
|
||||
}
|
||||
}
|
||||
BIN
Plugins/Wox.Plugin.Clipboard/Images/clipboard.png
Normal file
BIN
Plugins/Wox.Plugin.Clipboard/Images/clipboard.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 924 B |
85
Plugins/Wox.Plugin.Clipboard/Main.cs
Normal file
85
Plugins/Wox.Plugin.Clipboard/Main.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
using WindowsInput;
|
||||
using WindowsInput.Native;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Wox.Plugin.Clipboard
|
||||
{
|
||||
public class Main : IPlugin
|
||||
{
|
||||
private const int MaxDataCount = 100;
|
||||
private readonly KeyboardSimulator keyboardSimulator = new KeyboardSimulator(new InputSimulator());
|
||||
private PluginInitContext context;
|
||||
List<string> dataList = new List<string>();
|
||||
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
var results = new List<Result>();
|
||||
List<string> displayData = new List<string>();
|
||||
if (query.ActionParameters.Count == 0)
|
||||
{
|
||||
displayData = dataList;
|
||||
}
|
||||
else
|
||||
{
|
||||
displayData = dataList.Where(i => i.ToLower().Contains(query.GetAllRemainingParameter().ToLower()))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
results.AddRange(displayData.Select(o => new Result
|
||||
{
|
||||
Title = o,
|
||||
IcoPath = "Images\\clipboard.png",
|
||||
Action = c =>
|
||||
{
|
||||
if (c.SpecialKeyState.CtrlPressed)
|
||||
{
|
||||
context.ShowCurrentResultItemTooltip(o);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Windows.Forms.Clipboard.SetText(o);
|
||||
context.HideApp();
|
||||
keyboardSimulator.ModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_V);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}).Reverse());
|
||||
return results;
|
||||
}
|
||||
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
this.context = context;
|
||||
ClipboardMonitor.OnClipboardChange += ClipboardMonitor_OnClipboardChange;
|
||||
ClipboardMonitor.Start();
|
||||
}
|
||||
|
||||
void ClipboardMonitor_OnClipboardChange(ClipboardFormat format, object data)
|
||||
{
|
||||
if (format == ClipboardFormat.Html ||
|
||||
format == ClipboardFormat.SymbolicLink ||
|
||||
format == ClipboardFormat.Text ||
|
||||
format == ClipboardFormat.UnicodeText)
|
||||
{
|
||||
if (data != null && !string.IsNullOrEmpty(data.ToString()))
|
||||
{
|
||||
if (dataList.Contains(data.ToString()))
|
||||
{
|
||||
dataList.Remove(data.ToString());
|
||||
}
|
||||
dataList.Add(data.ToString());
|
||||
|
||||
if (dataList.Count > MaxDataCount)
|
||||
{
|
||||
dataList.Remove(dataList.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
36
Plugins/Wox.Plugin.Clipboard/Properties/AssemblyInfo.cs
Normal file
36
Plugins/Wox.Plugin.Clipboard/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的常规信息通过以下
|
||||
// 特性集控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("Wox.Plugin.DotnetPluginTest")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Wox.Plugin.DotnetPluginTest")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2014")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 将 ComVisible 设置为 false 使此程序集中的类型
|
||||
// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
|
||||
// 则将该类型上的 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||
[assembly: Guid("62685493-1710-4c1d-a179-cf466a44f45e")]
|
||||
|
||||
// 程序集的版本信息由下面四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 生成号
|
||||
// 修订号
|
||||
//
|
||||
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
||||
// 方法是按如下所示使用“*”:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
89
Plugins/Wox.Plugin.Clipboard/Wox.Plugin.Clipboard.csproj
Normal file
89
Plugins/Wox.Plugin.Clipboard/Wox.Plugin.Clipboard.csproj
Normal file
@@ -0,0 +1,89 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.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>{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Wox.Plugin.Clipboard</RootNamespace>
|
||||
<AssemblyName>Wox.Plugin.Clipboard</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
|
||||
<RestorePackages>true</RestorePackages>
|
||||
</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="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\packages\Newtonsoft.Json.6.0.1\lib\net35\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<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" />
|
||||
<Reference Include="WindowsInput">
|
||||
<HintPath>..\..\packages\InputSimulator.1.0.4.0\lib\net20\WindowsInput.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ClipboardMonitor.cs" />
|
||||
<Compile Include="Main.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Wox.Plugin\Wox.Plugin.csproj">
|
||||
<Project>{8451ecdd-2ea4-4966-bb0a-7bbc40138e80}</Project>
|
||||
<Name>Wox.Plugin</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
<None Include="plugin.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Images\clipboard.png" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>xcopy /Y /E $(TargetDir)*.* $(SolutionDir)Wox\bin\Debug\Plugins\$(ProjectName)\
|
||||
xcopy /Y /E $(ProjectDir)Images $(SolutionDir)Wox\bin\Debug\Plugins\$(ProjectName)\Images\</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
|
||||
</Target>
|
||||
<!-- 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>
|
||||
5
Plugins/Wox.Plugin.Clipboard/packages.config
Normal file
5
Plugins/Wox.Plugin.Clipboard/packages.config
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="InputSimulator" version="1.0.4.0" targetFramework="net35" />
|
||||
<package id="Newtonsoft.Json" version="6.0.1" targetFramework="net35" />
|
||||
</packages>
|
||||
12
Plugins/Wox.Plugin.Clipboard/plugin.json
Normal file
12
Plugins/Wox.Plugin.Clipboard/plugin.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"ID":"D2D2C23B084D411DB66FE0C79D6C2A6C",
|
||||
"ActionKeyword":"cb",
|
||||
"Name":"Wox.Plugin.Clipboard",
|
||||
"Description":"clipboard history search",
|
||||
"Author":"qianlifeng",
|
||||
"Version":"1.0",
|
||||
"Language":"csharp",
|
||||
"Website":"http://www.getwox.com",
|
||||
"ExecuteFileName":"Wox.Plugin.Clipboard.dll"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user