src/Carnac.Logic/ShortcutProvider.cs
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Carnac.Logic.Models;
using YamlDotNet.RepresentationModel;
namespace Carnac.Logic
{
public class ShortcutProvider : IShortcutProvider
{
readonly List<ShortcutCollection> shortcuts;
public ShortcutProvider()
{
string folder = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + @"\Keymaps\";
string filter = "*.yml";
if (!Directory.Exists(folder)) return;
string[] files = Directory.GetFiles(folder, filter);
shortcuts = GetYamlMappings(files).Select(GetShortcuts).ToList();
}
public List<KeyShortcut> GetShortcutsStartingWith(KeyPress keys)
{
var processName = keys.Process.ProcessName;
return shortcuts
.Where(s => s.Process == processName || string.IsNullOrWhiteSpace(s.Process))
.SelectMany(shortcut => shortcut.GetShortcutsMatching(new[] { keys }))
.ToList();
}
static string GetValueByKey(YamlMappingNode node, string name)
{
return node.Children.First(n => n.Key.ToString() == name).Value.ToString();
}
static KeyPressDefinition GetKeyPressDefintion(string combo)
{
combo = combo.ToLower();
var key = combo.Split('+').Last();
var keys = ReplaceKey.ToKey(key);
if (keys != null)
return
new KeyPressDefinition
(keys.Value,
shiftPressed: combo.Contains("shift"),
controlPressed: combo.Contains("ctrl"),
altPressed: combo.Contains("alt"),
winkeyPressed: combo.Contains("win"));
return null;
}
static IEnumerable<YamlMappingNode> GetYamlMappings(IEnumerable<string> filePaths)
{
var yaml = new YamlStream();
foreach (var file in filePaths)
{
yaml.Load(File.OpenText(file));
后面还有 43 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。