コード例 #1
0
        public bool StartsWith(List <KeyCombination> prefix)
        {
            if (activeCombination.Count < prefix.Count)
            {
                return(false);
            }

            if (prefix.Count != 0 && typeof(IShortcutToolContext).IsAssignableFrom(m_Context))
            {
                var lastKeyCombination = prefix.Last();
                lastKeyCombination = new KeyCombination(lastKeyCombination.keyCode, lastKeyCombination.modifiers & ~m_ReservedModifier);

                for (int i = 0; i < prefix.Count - 1; i++)
                {
                    if (!prefix[i].Equals(activeCombination[i]))
                    {
                        return(false);
                    }
                }

                return(lastKeyCombination.Equals(activeCombination[prefix.Count - 1]));
            }

            for (int i = 0; i < prefix.Count; i++)
            {
                if (!prefix[i].Equals(activeCombination[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #2
0
        public bool StartsWith(List <KeyCombination> prefix)
        {
            if (activeCombination.Count < prefix.Count)
            {
                return(false);
            }

            if (prefix.Count != 0)
            {
                var contextType = context;
                if (typeof(IShortcutToolContext).IsAssignableFrom(contextType))
                {
                    var attributes = contextType.GetCustomAttributes(typeof(ReserveModifiersAttribute), true);

                    var lastKeyCombination = prefix.Last();
                    var newModifier        = lastKeyCombination.modifiers;

                    foreach (var attribute in attributes)
                    {
                        var modifier = (attribute as ReserveModifiersAttribute).modifier;
                        if ((modifier & ShortcutModifiers.Shift) == ShortcutModifiers.Shift)
                        {
                            newModifier = newModifier & ~ShortcutModifiers.Shift;
                        }
                        if ((modifier & ShortcutModifiers.Alt) == ShortcutModifiers.Alt)
                        {
                            newModifier = newModifier & ~ShortcutModifiers.Alt;
                        }
                        if ((modifier & ShortcutModifiers.ControlOrCommand) == ShortcutModifiers.ControlOrCommand)
                        {
                            newModifier = newModifier & ~ShortcutModifiers.ControlOrCommand;
                        }
                    }

                    lastKeyCombination = new KeyCombination(lastKeyCombination.keyCode, newModifier);

                    for (int i = 0; i < prefix.Count - 1; i++)
                    {
                        if (!prefix[i].Equals(activeCombination[i]))
                        {
                            return(false);
                        }
                    }

                    return(lastKeyCombination.Equals(activeCombination[prefix.Count - 1]));
                }
            }

            for (int i = 0; i < prefix.Count; i++)
            {
                if (!prefix[i].Equals(activeCombination[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #3
0
        internal static ShortcutEntry CreateFromAttribute(MethodInfo methodInfo, ShortcutAttribute attribute)
        {
            var keyEvent           = Event.KeyboardEvent(attribute.defaultKeyCombination);
            var defaultCombination = new List <KeyCombination>();
            var keyCombination     = new KeyCombination(keyEvent);

            defaultCombination.Add(keyCombination);
            var identifier   = new Identifier(methodInfo, attribute);
            var type         = attribute is ClutchShortcutAttribute ? ShortcutType.Clutch : ShortcutType.Action;
            var methodParams = methodInfo.GetParameters();
            Action <ShortcutArguments> action;

            if (methodParams.Length == 0)
            {
                action = shortcutArgs =>
                {
                    methodInfo.Invoke(null, k_EmptyReusableShortcutArgs);
                };
            }
            else
            {
                action = shortcutArgs =>
                {
                    k_ReusableShortcutArgs[0] = shortcutArgs;
                    methodInfo.Invoke(null, k_ReusableShortcutArgs);
                };
            }

            KeyCombination?prefKeyMigratedValue = null;
            var            prefKeyAttr          = methodInfo.GetCustomAttributes(
                typeof(FormerlyPrefKeyAsAttribute), false
                ).FirstOrDefault() as FormerlyPrefKeyAsAttribute;

            if (prefKeyAttr != null)
            {
                var    prefKeyDefaultValue = new KeyCombination(Event.KeyboardEvent(prefKeyAttr.defaultValue));
                string name;
                Event  keyboardEvent;
                if (
                    PrefKey.TryParseUniquePrefString(EditorPrefs.GetString(prefKeyAttr.name, prefKeyAttr.defaultValue), out name, out keyboardEvent)
                    )
                {
                    var prefKeyCurrentValue = new KeyCombination(keyboardEvent);
                    if (!prefKeyCurrentValue.Equals(prefKeyDefaultValue))
                    {
                        prefKeyMigratedValue = prefKeyCurrentValue;
                    }
                }
            }

            return(new ShortcutEntry(identifier, defaultCombination, action, attribute.context, type, prefKeyMigratedValue));
        }
コード例 #4
0
        internal static void MigrateUserSpecifiedPrefKeys(
            IEnumerable <MethodInfo> methodsWithFormerlyPrefKeyAs, List <ShortcutEntry> entries
            )
        {
            foreach (var method in methodsWithFormerlyPrefKeyAs)
            {
                var shortcutAttr =
                    Attribute.GetCustomAttribute(method, typeof(ShortcutAttribute), true) as ShortcutAttribute;
                if (shortcutAttr == null)
                {
                    continue;
                }

                var entry = entries.Find(e => string.Equals(e.identifier.path, shortcutAttr.identifier));
                // ignore former PrefKeys if the shortcut profile has already loaded and applied an override
                if (entry == null || entry.overridden)
                {
                    continue;
                }

                var prefKeyAttr =
                    (FormerlyPrefKeyAsAttribute)Attribute.GetCustomAttribute(method, typeof(FormerlyPrefKeyAsAttribute));
                var    prefKeyDefaultValue = new KeyCombination(Event.KeyboardEvent(prefKeyAttr.defaultValue));
                string name;
                Event  keyboardEvent;
                var    parsed = PrefKey.TryParseUniquePrefString(
                    EditorPrefs.GetString(prefKeyAttr.name, prefKeyAttr.defaultValue), out name, out keyboardEvent
                    );
                if (!parsed)
                {
                    continue;
                }
                var prefKeyCurrentValue = new KeyCombination(keyboardEvent);
                // only migrate pref keys that the user actually overwrote
                if (!prefKeyCurrentValue.Equals(prefKeyDefaultValue))
                {
                    entry.SetOverride(new List <KeyCombination> {
                        prefKeyCurrentValue
                    });
                }
            }
        }