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); } } } }
public MenuItemBinding(WebAction action, ActionDispatcher dispatcher, MenuItem item) { _actionItem = action; _actionDispatcher = dispatcher; _actionDispatcher.Register(action.Identifier, this); item.Click += OnItemClick; Item = item; }
private void ReleaseMenuItem(MenuItem item, bool disposing) { var binding = item.Tag as MenuItemBinding; if (binding != null) { if (disposing) { binding.Dispose(); } item.Tag = null; } foreach (MenuItem child in item.Items) { ReleaseMenuItem(child, disposing); } }
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); }
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; } }