Пример #1
0
        public MenuAdapter(ContextMenu menu, WebActionNode model, ActionDispatcher actionDispatcher)
            : base(menu)
        {
            _menu = menu;

            if (model is WebDropDownButtonAction)
            {
                //TODO (CR May 2010): there's probably a more generic way to do this
                WebDropDownButtonAction a = model as WebDropDownButtonAction;
                foreach (WebActionNode node in a.DropDownActions)
                {
                    MenuItem menuItem = BuildMenuItem(node, actionDispatcher);
                    if (menuItem != null)
                        _menu.Items.Add(menuItem);
                }
            }
            else
            {
                foreach (WebActionNode node in model.Children)
                {
                    MenuItem menuItem = BuildMenuItem(node, actionDispatcher);
                    if (menuItem != null)
                        _menu.Items.Add(menuItem);
                }
            }
        }
Пример #2
0
 internal static IPopup BuildContextMenu(WebActionNode model, ActionDispatcher actionDispatcher)
 {
     ContextMenu menu = new ContextMenu();
     return new MenuAdapter(menu, model, actionDispatcher);
 }
Пример #3
0
        private static MenuItem BuildActionMenuItem(WebActionNode subNode, ActionDispatcher dispatcher)
        {
            WebAction actionNode = subNode as WebAction;

            MenuItem item = new MenuItem
            {
                IsEnabled = actionNode.Enabled,
                IsChecked = (actionNode is WebClickAction) && (actionNode as WebClickAction).Checked,
                Visibility = actionNode.DesiredVisiblility
            };

            var binding = new MenuItemBinding(actionNode, dispatcher, item);

            binding.SetLabel(actionNode.Label);
            binding.SetIcon();

            item.Tag = binding;

            return item;
        }
Пример #4
0
 internal static IPopup BuildContextMenu(WebActionNode model, ServerEventMediator dispatcher)
 {
     return BuildContextMenu(model, new ActionDispatcher(dispatcher));
 }
Пример #5
0
        private static MenuItem BuildMenuItem(WebActionNode node, ActionDispatcher dispatcher)
        {
            MenuItem thisMenu = null;
            try
            {

                if (node.Children != null)
                {
                    thisMenu = new MenuItem { Header = node.LocalizedText };

                    foreach (WebActionNode subNode in node.Children)
                    {
                        if (subNode.Children == null || subNode.Children.Count == 0)
                        {
                            MenuItem menuItem = BuildActionMenuItem(subNode, dispatcher);

                            if (menuItem != null)
                            {
                                if (menuItem.IsChecked)
                                    thisMenu.IsChecked = true;

                                if (menuItem != null)
                                    thisMenu.Items.Add(menuItem);
                            }

                        }
                        else
                        {
                            MenuItem menuItem = BuildMenuItem(subNode, dispatcher);
                            if (menuItem != null)
                            {
                                if (menuItem.IsChecked)
                                    thisMenu.IsChecked = true;

                                thisMenu.Items.Add(menuItem);
                            }
                        }
                    }

                    // Don't show the menu if it has no children
                    thisMenu.Visibility = node.DesiredVisiblility;
                }
                else
                {
                    WebAction actionNode = node as WebAction;
                    thisMenu = BuildActionMenuItem(actionNode, dispatcher);
                }

                return thisMenu;
            }
            catch (Exception ex)
            {
                // When an error happens here we need as much technical details as possible to diagnose the problem
                // Also, it's better to capture the error in English
                var itemName = node.LocalizedText;
                if (node is WebActionNode)
                    itemName = (node as WebActionNode).LocalizedText;
                if (node is WebAction)
                    itemName = (node as WebAction).Label;

                var message = new StringBuilder();
                message.AppendFormat("An expected error has occurred when building menu item labelled: {0}", itemName);
                message.AppendLine();
                message.AppendLine(string.Format("Details: {0}", ex.Message));
                message.AppendLine("Stack:");
                message.AppendLine(ex.StackTrace);

                var newEx = new Exception(message.ToString(), ex);
                throw newEx;
            }
        }