/// <summary> /// Generates the change menu item. /// </summary> /// <returns></returns> private ToolStripMenuItem GenerateChangeMenu() { ToolStripMenuItem menuItem = new ToolStripMenuItem("Change to"); menuItem.Image = CCNetConfig.Properties.Resources.securitychange_16x16; List <Type> serverSecurityModes = CoreUtil.GetAllServerSecurityModes(); foreach (Type securityMode in serverSecurityModes) { // Retrieve the display name of the security mode string displayName = securityMode.Name; DisplayNameAttribute attribute = CoreUtil.GetCustomAttribute <DisplayNameAttribute>(securityMode); if (attribute != null) { displayName = attribute.DisplayName; } // Add the actual menu item ToolStripMenuItem securityMenuItem = new ToolStripMenuItem(displayName); securityMenuItem.Image = CCNetConfig.Properties.Resources.applications_16x16; securityMenuItem.Tag = securityMode; menuItem.DropDownItems.Add(securityMenuItem); securityMenuItem.Click += delegate(object sender, EventArgs e) { // Generate the new instance and update the display ServerSecurity value = Activator.CreateInstance((sender as ToolStripMenuItem).Tag as Type) as ServerSecurity; configuration.Security = value; ChangeSecurity(value); UpdateDisplay(); }; } return(menuItem); }
/// <summary> /// Generates the change menu item. /// </summary> /// <returns></returns> private ToolStripMenuItem GenerateChangeMenu() { ToolStripMenuItem menuItem = new ToolStripMenuItem("Change to"); menuItem.Image = CCNetConfig.Properties.Resources.securitychange_16x16; List <Type> allowedItems = CoreUtil.GetAllItemsOfType(source.ItemType); foreach (Type allowedItem in allowedItems) { // Retrieve the display name of the security mode string displayName = allowedItem.Name; DisplayNameAttribute attribute = CoreUtil.GetCustomAttribute <DisplayNameAttribute>(allowedItem); if (attribute != null) { displayName = attribute.DisplayName; } // Add the actual menu item ToolStripMenuItem securityMenuItem = new ToolStripMenuItem(displayName); securityMenuItem.Image = CCNetConfig.Properties.Resources.applications_16x16; securityMenuItem.Tag = allowedItem; menuItem.DropDownItems.Add(securityMenuItem); securityMenuItem.Click += delegate(object sender, EventArgs e) { // Generate the new instance and update the display ICCNetObject value = Activator.CreateInstance((sender as ToolStripMenuItem).Tag as Type) as ICCNetObject; DataItem = value; ChangeDataValue(value); UpdateDisplay(); Nodes.Clear(); ReflectionHelper.GenerateChildNodes(this, DataItem); }; } return(menuItem); }
/// <summary> /// Generates the add menu item. /// </summary> /// <returns></returns> public ToolStripMenuItem GenerateAddMenu() { string menuText = string.Format("Add new {0}", source.ItemType.Name); if (!string.IsNullOrEmpty(source.AddMenuText)) { menuText = source.AddMenuText; } ToolStripMenuItem menuItem = new ToolStripMenuItem(menuText); // Set the menu image Bitmap image = Properties.Resources.add_16x16; if (!string.IsNullOrEmpty(source.ImageKey)) { try { image = Properties.Resources.ResourceManager.GetObject(source.ImageKey) as Bitmap; } catch (MissingManifestResourceException) { } } menuItem.Image = image; List <Type> itemTypes = CoreUtil.GetAllItemsOfType(source.ItemType); foreach (Type itemType in itemTypes) { if (!itemType.IsAbstract) { // Retrieve the display name of the item string displayName = itemType.Name; DisplayNameAttribute attribute = CoreUtil.GetCustomAttribute <DisplayNameAttribute>(itemType); if (attribute != null) { displayName = attribute.DisplayName; } // Add the actual menu item ToolStripMenuItem itemMenuItem = new ToolStripMenuItem(displayName); itemMenuItem.Image = CCNetConfig.Properties.Resources.applications_16x16; itemMenuItem.Tag = itemType; menuItem.DropDownItems.Add(itemMenuItem); itemMenuItem.Click += delegate(object sender, EventArgs e) { IList data = RetrieveDataList(); if (data != null) { object newItem = Activator.CreateInstance( (sender as ToolStripMenuItem).Tag as Type); data.Add(newItem); TreeView.SelectedNode = AddItemNode(newItem); TreeView.SelectedNode.EnsureVisible(); } else { MessageBox.Show("Unable to add to parent, list has not be initialised", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }; } } return(menuItem); }