/// <summary> /// Child classes must be marked with UserFriendlyAttribute, to provide user friendly name. /// </summary> /// <returns></returns> public string GetUserFriendlyName() { string name = this.GetType().Name; CustomNameAttribute.GetClassAttributeValue(this.GetType(), ref name); return(name); }
void SetComponentMenuItemDropDownItems(ToolStripMenuItem item, Type parentingType, bool includeParentingType, string creationTitle, Image creationImage, Type[] constructorTypes) { if (fxpaBaseForm == null) { return; } if (constructorTypes != null) {// Add types available for creation List <Type> resultingTypes = ReflectionHelper.GatherTypeChildrenTypesFromAssembliesWithMatchingConstructor(parentingType, false, ReflectionHelper.GetApplicationEntryAssemblyAndReferencedAssemblies(), constructorTypes); if (includeParentingType && parentingType.IsAbstract == false) { resultingTypes.Add(parentingType); } foreach (Type componentType in resultingTypes) { string name = parentingType.Name; CustomNameAttribute.GetClassAttributeValue(componentType, ref name); ToolStripMenuItem newItem = new ToolStripMenuItem(creationTitle + name, creationImage); newItem.Tag = componentType; newItem.Click += new EventHandler(createItem_Click); item.DropDownItems.Add(newItem); } } // Existing platform components. foreach (IFxpaBaseCompoent component in fxpaBaseForm.Components) { if (parentingType.IsInstanceOfType(component)) { string name = component.Name; ToolStripMenuItem newItem = new ToolStripMenuItem("Remove " + name, Properties.Resources.DELETE2); newItem.Tag = component; newItem.Click += new EventHandler(removeItem_Click); item.DropDownItems.Add(newItem); } } // Also check the UI components that are stand alone (have no platform component). foreach (TabPage page in tabControl.TabPages) { if (((FxpaCommonControl)page.Tag).Component == null || ((FxpaCommonControl)page.Tag).Component is IFxpaBaseCompoent == false) { if (parentingType.IsInstanceOfType((FxpaCommonControl)page.Tag)) {// Found existing standalone component. string name = ((FxpaCommonControl)page.Tag).Name; ToolStripMenuItem newItem = new ToolStripMenuItem("Remove " + name, Properties.Resources.DELETE2); newItem.Tag = ((FxpaCommonControl)page.Tag); newItem.Click += new EventHandler(removeItem_Click); item.DropDownItems.Add(newItem); } } } }