Example #1
0
        public static void RegisterShellMenuCommands([NotNull] SitecorePackage package)
        {
            Assert.ArgumentNotNull(package, nameof(package));

            menuCommands.Clear();

            var menuCommandService = package.MenuService;

            var context = new ShellContext();

            context.Initialize();

            var boundCommands = new List <BoundCommand>();

            var unboundCommands = new Dictionary <ShellMenuCommandPlacement, List <UnboundCommand> >();

            unboundCommands[ShellMenuCommandPlacement.MainMenu]                = new List <UnboundCommand>();
            unboundCommands[ShellMenuCommandPlacement.SolutionExplorerItem]    = new List <UnboundCommand>();
            unboundCommands[ShellMenuCommandPlacement.SolutionExplorerFolder]  = new List <UnboundCommand>();
            unboundCommands[ShellMenuCommandPlacement.SolutionExplorerProject] = new List <UnboundCommand>();

            GetCommands(boundCommands, unboundCommands);

            CreateShellMenuCommands(context, menuCommandService, boundCommands);
            CreateShellMenuCommands(context, menuCommandService, unboundCommands, ShellMenuCommandPlacement.MainMenu, CommandIds.ExtensibilityMenu);
            CreateShellMenuCommands(context, menuCommandService, unboundCommands, ShellMenuCommandPlacement.SolutionExplorerItem, CommandIds.SolutionExplorerItemExtensibilityMenu);
            CreateShellMenuCommands(context, menuCommandService, unboundCommands, ShellMenuCommandPlacement.SolutionExplorerFolder, CommandIds.SolutionExplorerFolderExtensibilityMenu);
            CreateShellMenuCommands(context, menuCommandService, unboundCommands, ShellMenuCommandPlacement.SolutionExplorerProject, CommandIds.ProjectExtensibilityMenu);
        }
Example #2
0
        private static void CreateShellMenuCommands([NotNull] ShellContext context, [NotNull] OleMenuCommandService menuCommandService, [NotNull] List <BoundCommand> boundCommands)
        {
            Debug.ArgumentNotNull(context, nameof(context));
            Debug.ArgumentNotNull(menuCommandService, nameof(menuCommandService));
            Debug.ArgumentNotNull(boundCommands, nameof(boundCommands));

            foreach (var cmd in boundCommands)
            {
                var boundCommand = cmd;
                var command      = boundCommand.Command;

                var commandId   = new CommandID(GuidList.CommandSet, boundCommand.CommandId);
                var menuCommand = new OleMenuCommand((sender, args) => command.Execute(context), 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);
            }
        }
Example #3
0
        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++;
            }
        }