public void BuildMenu() { foreach (var command in _defaultCommand) { ICommandSourceParent commandVisual; if (!_commandInformations.TryGetValue(command, out commandVisual)) { commandVisual = new ShellMenuItem(command); _commandInformations.Add(command, commandVisual); } var parentCommand = command.MenuCommandParent; if (parentCommand != null) { BuildMenuCommandHierarchy(parentCommand, commandVisual, _shellMenu); } } }
private void BuildMenuCommandHierarchy(ICommandEx parentCommand, ICommandSourceParent commandVisual, ShellMenu shellMenu) { if (parentCommand != null) { ICommandSourceParent parentCommandVisual; if (_commandInformations.TryGetValue(parentCommand, out parentCommandVisual)) { parentCommandVisual.AddItem(commandVisual); return; } parentCommandVisual = new ShellMenuItem(parentCommand); parentCommandVisual.AddItem(commandVisual); _commandInformations.Add(parentCommand, parentCommandVisual); parentCommand = parentCommand.MenuCommandParent; BuildMenuCommandHierarchy(parentCommand, parentCommandVisual, shellMenu); } else { shellMenu.AddItem(commandVisual); } }