private void BindNode(ISimulatorNode simNode, TreeNode node, TreeNodeCollection parent) { node.Text = simNode.DisplayName; node.Tag = simNode; var menu = new ContextMenu(); foreach (var nodeAction in simNode.Actions) { var action = new MenuItem(nodeAction.DisplayName); action.Click += new EventHandler( delegate(Object o, EventArgs a) { nodeAction.Invoke(); } ); menu.MenuItems.Add(action); } if (simNode.Actions.Any()) { menu.MenuItems.Add("-"); } foreach (var factory in simNode.Children) { var action = new MenuItem(factory.DisplayName); action.Click += new EventHandler( delegate(Object o, EventArgs a) { var callbacks = new TreeNodeCallbacks(this); var child = factory.Create(callbacks); if (child != null) { this.BindNode(child, callbacks.node, node.Nodes); } } ); menu.MenuItems.Add(action); } if (simNode.Children.Any()) { menu.MenuItems.Add("-"); } var item = new MenuItem("Remove"); item.Click += new EventHandler( delegate(Object o, EventArgs a) { ShutdownFrom(node); parent.Remove(node); } ); menu.MenuItems.Add(item); node.ContextMenu = menu; parent.Add(node); }
private void SimulatorForm_Load(object sender, EventArgs e) { foreach (var factory in plugins) { var instance = factory.Create(this.log); var item = new ToolStripMenuItem(instance.RootDisplayName); item.Image = instance.PluginImage; this.addToolStripMenuItem.DropDownItems.Add(item); var page = new TabPage(instance.UniqueId); var treeView = new TreeView(); page.Tag = treeView; treeView.Dock = DockStyle.Fill; treeView.ImageList = instance.NodeImageList; page.Controls.Add(treeView); this.tabControlPlugins.TabPages.Add(page); item.Click += new EventHandler( delegate(Object o, EventArgs a) { var callbacks = new TreeNodeCallbacks(this); var node = instance.Create(callbacks); if (node != null) { BindNode(node, callbacks.node, treeView.Nodes); } } ); this.log.LogFull(DisplayHint.INFO, "INFO", "system", "Initialized " + instance.UniqueId + " plugin"); } }