Пример #1
0
        public string CheckForErrors()
        {
            // Make sure all modifiable input commands are synchronized first.
            foreach (var command in Commands)
            {
                (command as UserCommandModifiableKeyInput)?.SynchronizeCombine();
            }

            StringBuilder errors = new StringBuilder();

            // Check for commands which both require a particular modifier, and ignore it.
            foreach (var command in EnumExtension.GetValues <UserCommand>())
            {
                if (Commands[(int)command] is UserCommandModifiableKeyInput modInput)
                {
                    if (modInput.Shift && modInput.IgnoreShift)
                    {
                        errors.AppendLine(settingsCatalog.GetStringFmt("{0} requires and is modified by Shift", commonCatalog.GetString(command.GetDescription())));
                    }
                    if (modInput.Control && modInput.IgnoreControl)
                    {
                        errors.AppendLine(settingsCatalog.GetStringFmt("{0} requires and is modified by Control", commonCatalog.GetString(command.GetDescription())));
                    }
                    if (modInput.Alt && modInput.IgnoreAlt)
                    {
                        errors.AppendLine(settingsCatalog.GetStringFmt("{0} requires and is modified by Alt", commonCatalog.GetString(command.GetDescription())));
                    }
                }
            }

            // Check for two commands assigned to the same key
            UserCommand firstCommand = EnumExtension.GetValues <UserCommand>().Min();
            UserCommand lastCommand  = EnumExtension.GetValues <UserCommand>().Max();

            for (UserCommand command1 = firstCommand; command1 <= lastCommand; command1++)
            {
                var input1 = Commands[(int)command1];

                // Modifier inputs don't matter as they don't represent any key.
                if (input1 is UserCommandModifierInput)
                {
                    continue;
                }

                for (var command2 = command1 + 1; command2 <= lastCommand; command2++)
                {
                    var input2 = Commands[(int)command2];

                    // Modifier inputs don't matter as they don't represent any key.
                    if (input2 is UserCommandModifierInput)
                    {
                        continue;
                    }

                    // Ignore problems when both inputs are on defaults. (This protects the user somewhat but leaves developers in the dark.)
                    //if (input1.PersistentDescriptor == InputSettings.DefaultCommands[(int)command1].PersistentDescriptor && input2.PersistentDescriptor == InputSettings.DefaultCommands[(int)command2].PersistentDescriptor)
                    if (input1.UniqueDescriptor == DefaultCommands[(int)command1].UniqueDescriptor &&
                        input2.UniqueDescriptor == DefaultCommands[(int)command2].UniqueDescriptor)
                    {
                        continue;
                    }

                    var unique1      = input1.GetUniqueInputs();
                    var unique2      = input2.GetUniqueInputs();
                    var sharedUnique = unique1.Where(id => unique2.Contains(id));
                    foreach (var uniqueInput in sharedUnique)
                    {
                        errors.AppendLine(settingsCatalog.GetStringFmt("{0} and {1} both match {2}", commonCatalog.GetString(command1.GetDescription()),
                                                                       commonCatalog.GetString(command2.GetDescription()), KeyboardMap.GetPrettyUniqueInput(uniqueInput)));
                    }
                }
            }

            return(errors.ToString());
        }