public override ShortcutEntry CreateShortcutEntry(MethodInfo methodInfo) { var identifier = new Identifier(methodInfo, this); IEnumerable <KeyCombination> defaultCombination; if (defaultKeyCombination == null) { defaultCombination = Enumerable.Empty <KeyCombination>(); } else { defaultCombination = new[] { KeyCombination.ParseLegacyBindingString(defaultKeyCombination) } }; var type = this is ClutchShortcutAttribute ? ShortcutType.Clutch : ShortcutType.Action; var methodParams = methodInfo.GetParameters(); Action <ShortcutArguments> action; // We instantiate this as the specific delegate type in advance, // because passing ShortcutArguments in object[] via MethodInfo.Invoke() causes boxing/allocation if (methodParams.Any()) { action = (Action <ShortcutArguments>)methodInfo.CreateDelegate(typeof(Action <ShortcutArguments>), null); } else { m_NoArgumentsAction = (Action)methodInfo.CreateDelegate(typeof(Action), null); action = NoArgumentShortcutMethodProxy; } return(new ShortcutEntry(identifier, defaultCombination, action, context, type)); } }
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 = KeyCombination.ParseLegacyBindingString(prefKeyAttr.defaultValue); string name; string binding; Event keyboardEvent; var parsed = PrefKey.TryParseUniquePrefString(EditorPrefs.GetString(prefKeyAttr.name, prefKeyAttr.defaultValue), out name, out keyboardEvent, out binding); if (!parsed) { continue; } var prefKeyCurrentValue = KeyCombination.ParseLegacyBindingString(binding); // only migrate pref keys that the user actually overwrote if (!prefKeyCurrentValue.Equals(prefKeyDefaultValue)) { entry.SetOverride(new List <KeyCombination> { prefKeyCurrentValue }); } } }
public IEnumerable <IShortcutEntryDiscoveryInfo> GetDefinedShortcuts() { var entries = new List <IShortcutEntryDiscoveryInfo>(); var names = new List <string>(); var defaultShortcuts = new List <string>(); Menu.GetMenuItemDefaultShortcuts(names, defaultShortcuts); entries.Capacity += names.Count; for (int index = 0; index < names.Count; ++index) { var keys = new List <KeyCombination>(); if (!string.IsNullOrEmpty(defaultShortcuts[index])) { keys.Add(KeyCombination.ParseLegacyBindingString(defaultShortcuts[index])); } entries.Add(new MenuItemEntryDiscoveryInfo(names[index], keys)); } return(entries); }
public override ShortcutEntry CreateShortcutEntry(MethodInfo methodInfo) { var identifier = new Identifier(methodInfo, this); IEnumerable <KeyCombination> defaultCombination; if (defaultKeyCombination == null) { defaultCombination = Enumerable.Empty <KeyCombination>(); } else { defaultCombination = new[] { KeyCombination.ParseLegacyBindingString(defaultKeyCombination) } }; var type = this 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); }; } return(new ShortcutEntry(identifier, defaultCombination, action, context, type)); } }