src/Carnac.Logic/ShortcutAccumulator.cs

(开头部分) 3KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Linq;
using Carnac.Logic.Models;

namespace Carnac.Logic
{
    public class ShortcutAccumulator
    {
        List<KeyShortcut> possibleKeyShortcuts;
        Message[] messages;
        readonly List<KeyPress> keys;

        public ShortcutAccumulator()
        {
            keys = new List<KeyPress>();
        }

        public IEnumerable<KeyPress> Keys
        {
            get { return keys; }
        }

        public ShortcutAccumulator ProcessKey(IShortcutProvider shortcutProvider, KeyPress key)
        {
            if (HasCompletedValue)
                return new ShortcutAccumulator().ProcessKey(shortcutProvider, key);

            if (!keys.Any())
            {
                var possibleShortcuts = shortcutProvider.GetShortcutsStartingWith(key);
                if (possibleShortcuts.Any())
                    BeginShortcut(key, possibleShortcuts);
                else
                    Complete(key);

                return this;
            }

            Add(key);
            return this;
        }

        public Message[] GetMessages()
        {
            if (!HasCompletedValue)
                throw new InvalidOperationException();

            return messages;
        }

        public bool HasCompletedValue { get; private set; }

        void Add(KeyPress key)
        {
            var isFirstKey = keys.Count == 0;

            if (!isFirstKey && keys[0].Process.ProcessName != key.Process.ProcessName)
            {
                NoMatchingShortcut();
后面还有 54 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。