Exemple #1
0
        public Task InitializeAsync()
        {
            OleMenuCommandService commandService = _serviceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (commandService == null)
            {
                _logger.WriteLine("OleMenuCommandService was not resolved");
                return(Task.CompletedTask);
            }

            var id = 1;

            foreach (var iconType in ExtensionCatalogue.IconTypes)
            {
                var names  = Enum.GetNames(iconType);
                var values = Enum.GetValues(iconType);

                for (var idx = 0; idx < names.Length; idx++)
                {
                    var cmdidMyDynamicStartCommand = id * 100;

                    var value = (int)values.GetValue(idx);
                    var icon  = new ExtensionMethodIcon(iconType, value);

                    CommandID dynamicItemRootId = new CommandID(guidDynamicCommandsSet.SetId, cmdidMyDynamicStartCommand);

                    var existing = commandService.FindCommand(dynamicItemRootId);
                    if (existing != null)
                    {
                        commandService.RemoveCommand(existing);
                    }

                    var matchingMethods = _extensionsCacheService.ExtensionsForIcon(icon);
                    if (matchingMethods.Any())
                    {
                        DynamicItemMenuCommand dynamicMenuCommand = new DynamicItemMenuCommand(
                            _extensionsCacheService,
                            _invocationService,
                            dynamicItemRootId,
                            cmdidMyDynamicStartCommand,
                            matchingMethods
                            )
                        {
                            Visible = false
                        };
                        commandService.AddCommand(dynamicMenuCommand);
                    }

                    id++;
                }
            }

            return(Task.CompletedTask);
        }
Exemple #2
0
        void Reload()
        {
            OleMenuCommandService commandService = _serviceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (commandService == null)
            {
                _logger.WriteLine("OleMenuCommandService was not resolved");
                return;
            }

            // Add the DynamicItemMenuCommand for the expansion of the root item into N items at run time.
            CommandID dynamicItemRootId = new CommandID(_commandsSetId, (int)_cmdidMyDynamicStartCommand);

            var matchingMethods = _extensionsCacheService.ExtensionsForIcon(_icon);
            var existing        = commandService.FindCommand(dynamicItemRootId) as DynamicItemMenuCommand;

            if (existing != null)
            {
                existing.Update(matchingMethods);
            }
            else
            {
                DynamicItemMenuCommand dynamicMenuCommand = new DynamicItemMenuCommand(
                    _extensionsCacheService,
                    _invocationService,
                    dynamicItemRootId,
                    _cmdidMyDynamicStartCommand,
                    matchingMethods
                    )
                {
                    Visible = false,
                    Enabled = false
                };
                commandService.AddCommand(dynamicMenuCommand);
            }
        }
        static void OnBeforeQueryStatusDynamicItem(object sender, EventArgs args)
        {
            DynamicItemMenuCommand matchedCommand = (DynamicItemMenuCommand)sender;

            matchedCommand.OnBeforeQueryStatusDynamicItem();
        }
        static void OnInvokedDynamicItem(object sender, EventArgs args)
        {
            DynamicItemMenuCommand invokedCommand = (DynamicItemMenuCommand)sender;

            invokedCommand.Invoke();
        }