mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 11:46:30 +02:00
Move some user settings to its own dll (cmd,folder plugin and etc)
This commit is contained in:
@@ -2,13 +2,20 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using WindowsInput;
|
||||
using WindowsInput.Native;
|
||||
using Wox.Infrastructure.Hotkey;
|
||||
using Control = System.Windows.Controls.Control;
|
||||
|
||||
namespace Wox.Plugin.CMD
|
||||
{
|
||||
public class CMD : IPlugin, ISettingProvider
|
||||
{
|
||||
private readonly GlobalHotkey globalHotkey = new GlobalHotkey();
|
||||
private PluginInitContext context;
|
||||
private bool WinRStroked;
|
||||
private readonly KeyboardSimulator keyboardSimulator = new KeyboardSimulator(new InputSimulator());
|
||||
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
@@ -166,6 +173,33 @@ namespace Wox.Plugin.CMD
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
this.context = context;
|
||||
globalHotkey.hookedKeyboardCallback += KListener_hookedKeyboardCallback;
|
||||
}
|
||||
|
||||
private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, SpecialKeyState state)
|
||||
{
|
||||
if (CMDStorage.Instance.ReplaceWinR)
|
||||
{
|
||||
if (keyevent == KeyEvent.WM_KEYDOWN && vkcode == (int)Keys.R && state.WinPressed)
|
||||
{
|
||||
WinRStroked = true;
|
||||
OnWinRPressed();
|
||||
return false;
|
||||
}
|
||||
if (keyevent == KeyEvent.WM_KEYUP && WinRStroked && vkcode == (int)Keys.LWin)
|
||||
{
|
||||
WinRStroked = false;
|
||||
keyboardSimulator.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.CONTROL);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void OnWinRPressed()
|
||||
{
|
||||
context.API.ShowApp();
|
||||
context.API.ChangeQuery(">");
|
||||
}
|
||||
|
||||
public Control CreateSettingPanel()
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
|
||||
namespace Wox.Plugin.CMD
|
||||
{
|
||||
@@ -13,30 +12,30 @@ namespace Wox.Plugin.CMD
|
||||
|
||||
private void CMDSetting_OnLoaded(object sender, RoutedEventArgs re)
|
||||
{
|
||||
cbReplaceWinR.IsChecked = UserSettingStorage.Instance.ReplaceWinR;
|
||||
cbLeaveCmdOpen.IsChecked = UserSettingStorage.Instance.LeaveCmdOpen;
|
||||
cbReplaceWinR.IsChecked = CMDStorage.Instance.ReplaceWinR;
|
||||
cbLeaveCmdOpen.IsChecked = CMDStorage.Instance.LeaveCmdOpen;
|
||||
|
||||
cbLeaveCmdOpen.Checked += (o, e) =>
|
||||
{
|
||||
UserSettingStorage.Instance.LeaveCmdOpen = true;
|
||||
UserSettingStorage.Instance.Save();
|
||||
CMDStorage.Instance.LeaveCmdOpen = true;
|
||||
CMDStorage.Instance.Save();
|
||||
};
|
||||
|
||||
cbLeaveCmdOpen.Unchecked += (o, e) =>
|
||||
{
|
||||
UserSettingStorage.Instance.LeaveCmdOpen = false;
|
||||
UserSettingStorage.Instance.Save();
|
||||
CMDStorage.Instance.LeaveCmdOpen = false;
|
||||
CMDStorage.Instance.Save();
|
||||
};
|
||||
|
||||
cbReplaceWinR.Checked += (o, e) =>
|
||||
{
|
||||
UserSettingStorage.Instance.ReplaceWinR = true;
|
||||
UserSettingStorage.Instance.Save();
|
||||
CMDStorage.Instance.ReplaceWinR = true;
|
||||
CMDStorage.Instance.Save();
|
||||
};
|
||||
cbReplaceWinR.Unchecked += (o, e) =>
|
||||
{
|
||||
UserSettingStorage.Instance.ReplaceWinR = false;
|
||||
UserSettingStorage.Instance.Save();
|
||||
CMDStorage.Instance.ReplaceWinR = false;
|
||||
CMDStorage.Instance.Save();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,38 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Newtonsoft.Json;
|
||||
using Wox.Infrastructure.Storage;
|
||||
using System.IO;
|
||||
|
||||
namespace Wox.Plugin.CMD
|
||||
{
|
||||
public class CMDStorage : JsonStrorage<CMDStorage>
|
||||
{
|
||||
[JsonProperty]
|
||||
public bool ReplaceWinR { get; set; }
|
||||
|
||||
[JsonProperty]
|
||||
public bool LeaveCmdOpen { get; set; }
|
||||
|
||||
[JsonProperty]
|
||||
public Dictionary<string, int> CMDHistory = new Dictionary<string, int>();
|
||||
|
||||
protected override string ConfigFolder
|
||||
{
|
||||
get { return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); }
|
||||
}
|
||||
|
||||
protected override string ConfigName
|
||||
{
|
||||
get { return "CMDHistory"; }
|
||||
}
|
||||
|
||||
protected override CMDStorage LoadDefault()
|
||||
{
|
||||
ReplaceWinR = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void AddCmdHistory(string cmdName)
|
||||
{
|
||||
if (CMDHistory.ContainsKey(cmdName))
|
||||
|
||||
@@ -44,11 +44,15 @@
|
||||
<Reference Include="PresentationFramework" />
|
||||
<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="WindowsBase" />
|
||||
<Reference Include="WindowsInput">
|
||||
<HintPath>..\..\packages\InputSimulator.1.0.4.0\lib\net20\WindowsInput.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CMD.cs" />
|
||||
|
||||
Reference in New Issue
Block a user