private static ToolStripItem CreateMenuItemFromAction(MenuItemDef action, Project project) { if (action is SeparatorMenuItemDef) { return(CreateMenuItemSeparator()); } else { // Build ContextMenu item ToolStripMenuItem menuItem = new ToolStripMenuItem(action.Title, null, (s, e) => action.Execute(action, project)); menuItem.Tag = action; menuItem.Name = action.Name; menuItem.Text = action.Title; menuItem.Checked = action.Checked; //menuItem.CheckOnClick = false; menuItem.Enabled = (action.IsFeasible && action.IsGranted(project.SecurityManager)); if (action.IsFeasible && !action.IsGranted(project.SecurityManager)) { menuItem.ToolTipText = "Action is not granted."; } else { menuItem.ToolTipText = action.Description; } menuItem.Image = action.Image; menuItem.ImageTransparentColor = action.ImageTransparentColor; menuItem.DropDownItems.Clear(); // Add sub menu items (do not skip any sub items: if parent is granted, subitems are granted too) if (action.SubItems != null) { for (int i = 0; i < action.SubItems.Length; ++i) { menuItem.DropDownItems.Add(CreateMenuItemFromAction(action.SubItems[i], project)); } } return(menuItem); } }
private static ToolStripItem CreateMenuItemFromAction(MenuItemDef action, Project project) { if (action is SeparatorMenuItemDef) { return(CreateMenuItemSeparator()); } else { // Build ContextMenu item ToolStripMenuItem menuItem = new ToolStripMenuItem(action.Title, null, (s, e) => action.Execute(action, project)); menuItem.Tag = action; menuItem.Name = action.Name; menuItem.Text = action.Title; menuItem.Checked = action.Checked; //menuItem.CheckOnClick = false; menuItem.Enabled = (action.IsFeasible && action.IsGranted(project.SecurityManager)); if (action.IsFeasible && !action.IsGranted(project.SecurityManager)) { if (action is DelegateMenuItemDef) { menuItem.ToolTipText = string.Format("Action is deactivated because you don't have the permission for '{0}'.", ((DelegateMenuItemDef)action).RequiredPermission); } else { menuItem.ToolTipText = "Action is deactivated because you don't have the required permissions."; } } else { menuItem.ToolTipText = action.Description; } menuItem.Image = action.Image; menuItem.ImageTransparentColor = action.ImageTransparentColor; menuItem.DropDownItems.Clear(); // Add sub menu items (do not skip any sub items: if parent is granted, subitems are granted too) if (action.SubItems != null) { int cnt = action.SubItems.Length; for (int i = 0; i < cnt; ++i) { menuItem.DropDownItems.Add(CreateMenuItemFromAction(action.SubItems[i], project)); } } return(menuItem); } }