/// <summary> /// 设置插件参数。PluginViewBase将插件初始化后调用该方法,由继承的类对插件进行一些设置后再进行后续的加载步骤。 /// </summary> /// <param name="plugin">需要被设置参数的插件。</param> protected override void SetPlugin(IPlugin plugin) { IClassifyPlugin classifyPlugin = plugin as IClassifyPlugin; classifyPlugin.SetClassifys(this.Classifys); }
private bool GetClassifyMenu(PluginTypeCollection pluginTypes, ToolStripItemCollection menuItems) { bool bolIsOutMenu = false; for (int intIndex = 0; intIndex < pluginTypes.Count; intIndex++) { ClassifyPluginType pluginType = pluginTypes[intIndex] as ClassifyPluginType; if ((pluginType.Type.GetInterface(typeof(IClassifyHtmlPlugin).FullName, true) != null) || (Function.IsInheritableBaseType(pluginType.Type, typeof(System.Windows.Forms.Control)))) { //HTML、控件 ToolStripMenuItem mnuClassifyPlugin = new ToolStripMenuItem(); mnuClassifyPlugin.Text = pluginType.Name; mnuClassifyPlugin.Image = pluginType.Icon16; mnuClassifyPlugin.Tag = pluginType; if (pluginType.Description != null && pluginType.Description.Length > 0) { mnuClassifyPlugin.ToolTipText = pluginType.Description; } if (pluginType.Icon16 != null) { mnuClassifyPlugin.Image = pluginType.Icon16; } mnuClassifyPlugin.Click += new EventHandler(mnuClassifyPlugin_Click); if (pluginType.Children.Count > 0) { this.GetClassifyMenu(pluginType.Children, mnuClassifyPlugin.DropDownItems); } //mnuClassifyPlugin.MouseEnter += new EventHandler(mnuClassifyPlugin_MouseEnter); menuItems.Add(mnuClassifyPlugin); bolIsOutMenu = true; } else if (Function.IsInheritableBaseType(pluginType.Type, typeof(System.Windows.Forms.ToolStripItem))) { //自定义的菜单项 System.Reflection.ConstructorInfo ci = pluginType.Type.GetConstructor(new System.Type[] { }); object objInstance = ci.Invoke(new object[] { }); IClassifyPlugin plugin = objInstance as IClassifyPlugin; ToolStripItem mnuClassifyPlugin = plugin as ToolStripItem; if (pluginType.Icon16 != null) { mnuClassifyPlugin.Image = pluginType.Icon16; } menuItems.Add(mnuClassifyPlugin); plugin.SetClassifys((Classify[])mnuClassifyPlugin.Owner.Tag); if (plugin is IUseAccount) { IUseAccount useAccount = plugin as IUseAccount; useAccount.SetAccount(this.CurrentAccount); } plugin.SetApplication(this); if (mnuClassifyPlugin.Text.Length == 0) { mnuClassifyPlugin.Text = pluginType.Name; } if (pluginType.Description != null && pluginType.Description.Length > 0 && (mnuClassifyPlugin.ToolTipText == null || mnuClassifyPlugin.ToolTipText.Length == 0)) { mnuClassifyPlugin.ToolTipText = pluginType.Description; } //tsi.MouseEnter += new EventHandler(mnuClassifyPlugin_MouseEnter); bolIsOutMenu = true; } else if (pluginType.Name == null) { //分隔线 if (bolIsOutMenu && pluginType.Children.Count > 0) { menuItems.Add(new ToolStripSeparator()); } //分隔线的子插件 if (this.GetClassifyMenu(pluginType.Children, menuItems)) { bolIsOutMenu = true; } } else { //作为分类处理 if (pluginType.Children.Count > 0) { ToolStripMenuItem mnuClassifyPlugin = new ToolStripMenuItem(); mnuClassifyPlugin.Text = pluginType.Name; if (pluginType.Description != null && pluginType.Description.Length > 0) { mnuClassifyPlugin.ToolTipText = pluginType.Description; } if (pluginType.Icon16 != null) { mnuClassifyPlugin.Image = pluginType.Icon16; } //mnuClassifyPlugin.MouseEnter += new EventHandler(mnuClassifyPlugin_MouseEnter); this.GetClassifyMenu(pluginType.Children, mnuClassifyPlugin.DropDownItems); menuItems.Add(mnuClassifyPlugin); bolIsOutMenu = true; } } } return(bolIsOutMenu); }