private static void CreateShellMenuCommands([NotNull] ShellContext context, [NotNull] OleMenuCommandService menuCommandService, [NotNull] Dictionary <ShellMenuCommandPlacement, List <UnboundCommand> > unboundCommands, ShellMenuCommandPlacement placement, int cmdid) { Debug.ArgumentNotNull(context, nameof(context)); Debug.ArgumentNotNull(menuCommandService, nameof(menuCommandService)); Debug.ArgumentNotNull(unboundCommands, nameof(unboundCommands)); var commands = unboundCommands[placement]; if (commands.Count == 0) { var commandId = new CommandID(GuidList.CommandSet, cmdid); var menuCommand = new OleMenuCommand(delegate { }, commandId, @"Extensibility Menu"); menuCommand.BeforeQueryStatus += delegate { menuCommand.Visible = false; }; menuCommandService.AddCommand(menuCommand); menuCommands.Add(menuCommand); return; } commands.Sort(new UnboundCommandSorter()); foreach (var unboundShellCommand in commands) { var command = unboundShellCommand.Command; var commandId = new CommandID(GuidList.CommandSet, cmdid); EventHandler execute = delegate { AppHost.Usage.ReportCommand(command, context); command.Execute(context); }; var menuCommand = new OleMenuCommand(execute, commandId, command.Text); EventHandler queryStatus = delegate { try { menuCommand.Enabled = command.CanExecute(context); menuCommand.Visible = command.IsVisible; } catch { menuCommand.Visible = false; throw; } }; command.CanExecuteChanged += queryStatus; menuCommand.BeforeQueryStatus += queryStatus; menuCommandService.AddCommand(menuCommand); menuCommands.Add(menuCommand); cmdid++; } }
public ShellMenuCommandAttribute(ShellMenuCommandPlacement placement, double priority) { Placement = placement; Priority = priority; IsBound = false; }