Example #1
0
        private void UpdateCommands()
        {
            var selectedCommand = SelectedCommand;

            var allCommands = _commandManager.GetCommands().OrderBy(x => x).ToList();

            if (!string.IsNullOrWhiteSpace(CommandFilter))
            {
                allCommands = allCommands.Where(x => x.IndexOf(CommandFilter, StringComparison.OrdinalIgnoreCase) >= 0).ToList();
            }

            using (Commands.SuspendChangeNotifications())
            {
                Commands.Clear();

                foreach (var command in allCommands)
                {
                    var commandInfo = _commandInfoService.GetCommandInfo(command);
                    if (!commandInfo.IsHidden)
                    {
                        Commands.Add(commandInfo);
                    }
                }
            }

            // restore selection
            if (selectedCommand != null && Commands.FirstOrDefault(x => string.Equals(x.CommandName, selectedCommand)) != null)
            {
                SelectedCommand = selectedCommand;
            }
        }
        public static void UpdateCommandInfo(this ICommandInfoService commandInfoService, string commandName, Action <ICommandInfo> commandInfoUpdateCallback)
        {
            Argument.IsNotNull(() => commandInfoService);
            Argument.IsNotNull(() => commandName);
            Argument.IsNotNull(() => commandInfoUpdateCallback);

            var commandInfo = commandInfoService.GetCommandInfo(commandName);

            commandInfoUpdateCallback(commandInfo);
        }
        protected override async Task InitializeAsync()
        {
            await base.InitializeAsync();

            Title = string.Format(_languageService.GetString("Orchestra_ShortcutsForApplication"), AssemblyHelper.GetEntryAssembly().Title());

            var mappingsByGroup = new Dictionary <string, KeyboardMappings>();

            mappingsByGroup.Add(string.Empty, new KeyboardMappings {
                GroupName = string.Empty
            });

            var commands = _commandManager.GetCommands();
            var groups   = (from command in commands
                            select command.GetCommandGroup()).Distinct().OrderBy(x => x);

            foreach (var group in groups)
            {
                mappingsByGroup[group] = new KeyboardMappings {
                    GroupName = group
                };
            }

            foreach (var command in commands.OrderBy(x => x.GetCommandName()))
            {
                var commandInfo = _commandInfoService.GetCommandInfo(command);
                if (commandInfo.IsHidden)
                {
                    Log.Debug("Command '{0}' is hidden, not showing in keyboard mappings overview", command);
                    continue;
                }

                var groupName    = command.GetCommandGroup();
                var inputGesture = _commandManager.GetInputGesture(command);
                mappingsByGroup[groupName].Mappings.Add(new KeyboardMapping
                {
                    CommandName  = command,
                    InputGesture = inputGesture
                });
            }

            var additionalKeyboardMappings = _keyboardMappingsService.AdditionalKeyboardMappings;

            foreach (var additionalKeyboardMapping in additionalKeyboardMappings)
            {
                var groupName = additionalKeyboardMapping.CommandName.GetCommandGroup();

                if (!mappingsByGroup.ContainsKey(groupName))
                {
                    mappingsByGroup[groupName] = new KeyboardMappings {
                        GroupName = groupName
                    };
                }

                mappingsByGroup[groupName].Mappings.Add(additionalKeyboardMapping);
            }

            if (mappingsByGroup[string.Empty].Mappings.Count == 0)
            {
                mappingsByGroup.Remove(string.Empty);
            }

            var finalMappings = new Dictionary <string, KeyboardMappings>();

            foreach (var mappingGroup in mappingsByGroup)
            {
                var keyboardMappings = new KeyboardMappings
                {
                    GroupName = mappingGroup.Key
                };

                keyboardMappings.Mappings.AddRange(mappingGroup.Value.Mappings.OrderBy(x => x.CommandName));

                finalMappings[mappingGroup.Key] = keyboardMappings;
            }

            KeyboardMappings = new List <KeyboardMappings>(finalMappings.Values.OrderBy(x => x.GroupName));
        }