/// <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); } } } }
void createItem_Click(object sender, EventArgs e) { ToolStripMenuItem item = (ToolStripMenuItem)sender; Type type = (Type)item.Tag; IFxpaBaseCompoent component = null; if (type.IsSubclassOf(typeof(Analyzer))) { component = new LocalAnalyzerHost(CustomNameAttribute.GetClassAttributeName(type), type); } else { ConstructorInfo info = type.GetConstructor(new Type[] { }); if (info != null) { component = (IFxpaBaseCompoent)info.Invoke(new object[] { }); } } // ... if (component == null) { MessageBox.Show("Failed to create component.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Set settings for component. if (component.SetInitialState(fxpaBaseForm.Settings) == false) { MessageBox.Show("Component failed to initialize from initial state.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Register to platform. fxpaBaseForm.RegisterComponent(component); }
/// <summary> /// /// </summary> public FxpaSource() //: base(false) { this.Name = CustomNameAttribute.GetClassAttributeName(typeof(FxpaSource)); //this._id.Name = this.Name; }