예제 #1
0
        public static void SetEndpointsMenuItems(this IApplication app
            , string caption
            , Action<IAbstractEndpoint, IApplication> handler
            , Func<IAbstractEndpoint, IApplication, bool> visibilityEvaluator
            )
        {
            var endpoints = app.Design.Endpoints.GetAll();
            try
            {
                foreach (var endpoint in endpoints)
                {
                    var ep = endpoint.As<IProductElement>();
                    var menuItem = ep.AutomationExtensions.OfType<MenuCommand>().FirstOrDefault(a => a.Text == caption);
                    if (menuItem == null)
                    {
                        menuItem = new MenuCommand(ep
                            , caption
                            , () => handler(endpoint, app));
                        ep.AddAutomationExtension(menuItem);
                    }

                    menuItem.Visible = visibilityEvaluator(endpoint, app);
                }
            }
            // We might not able to get the IToolkitInterface if
            // the package is being initialized
            catch (ArgumentNullException) { }
            catch (NullReferenceException) { }
        }
예제 #2
0
        public static void SetElementMenuItems(this IApplication app
            , IEnumerable<IProductElement> elements
            , string caption
            , Action<IProductElement, IApplication> handler
            , Func<IProductElement, IApplication, bool> visibilityEvaluator
            )
        {
            try
            {
                foreach (var el in elements)
                {
                    var localElement = el;
                    var menuItem = el.AutomationExtensions.OfType<MenuCommand>().FirstOrDefault(a => a.Text == caption);
                    if (menuItem == null)
                    {
                        menuItem = new MenuCommand(el
                            , caption
                            , () => handler(localElement, app));
                        el.AddAutomationExtension(menuItem);
                    }

                    menuItem.Visible = visibilityEvaluator(el, app);
                }
            }
            // We might not able to get the IToolkitInterface if
            // the package is being initialized
            catch (ArgumentNullException) { }
        }