private void EditCommandLineNode(HiddenCheckBoxTreeNode node) { var image = StateImageList.Images[node.StateImageKey]; var editedCommandLine = commandLineEditForm.ShowPrompt(node.Text, image); if (editedCommandLine != null) { BeginUpdate(); var commandItem = listDataSource .SelectMany(g => g.CommandItems) .Single(c => c.CommandLine == node.Text); commandItem.CommandLine = editedCommandLine.CommandLine; node.Text = commandItem.CommandLine; if (!string.IsNullOrWhiteSpace(editedCommandLine.ImageKey)) { commandItem.Image = editedCommandLine.Image; StateImageList.Images.RemoveByKey(commandItem.ImageKey); commandItem.CreateImageKey(); StateImageList.Images.Add(commandItem.ImageKey, commandItem.Image); node.StateImageKey = commandItem.ImageKey; } EndUpdate(); } }
private void CreateSubNode(TreeNode node, string caption) { var group = GetGroup(node); if (node.Level == 0) { var nodePrompt = editForm.ShowPrompt(caption, null); if (string.IsNullOrWhiteSpace(nodePrompt)) { return; } var newNode = new TreeNode { Text = nodePrompt, Name = nodePrompt, ContextMenuStrip = new ContextMenuStrip() }; var newCommandItem = new CommandItemViewItem { Name = nodePrompt }; group.CommandItems.Add(newCommandItem); if (ValidateCollection(newNode, node.Nodes)) { newNode.ContextMenuStrip.Items.Add(NewUrl, null, (sender, e) => CreateSubNode(newNode, NewCommandLine)); newNode.ContextMenuStrip.Items.Add(Edit, null, (sender, e) => EditTreeNode(newNode, Edit)); node.Expand(); } } else if (node?.Level == 1) { var newCommandLine = commandLineEditForm.ShowPrompt(string.Empty, null); if (newCommandLine is null) { return; } var newCommandLineNode = new HiddenCheckBoxTreeNode { Text = newCommandLine.CommandLine, Name = newCommandLine.CommandLine, ContextMenuStrip = new ContextMenuStrip() }; if (ValidateCollection(newCommandLineNode, node.Nodes)) { var commandItem = GetCommandItem(node, group); commandItem.CommandLine = newCommandLine.CommandLine; commandItem.Image = newCommandLine.Image; commandItem.CreateImageKey(); StateImageList.Images.Add(commandItem.ImageKey, commandItem.Image); newCommandLineNode.StateImageKey = commandItem.ImageKey; node.ContextMenuStrip = new ContextMenuStrip(); node.ContextMenuStrip.Items.Add(Edit, null, (sender, e) => EditTreeNode(node, Edit)); newCommandLineNode.ContextMenuStrip.Items.Add(Edit, null, (sender, e) => EditCommandLineNode(newCommandLineNode)); node.Expand(); } } }
private void AddNewGroup(GroupViewItem group) { BeginUpdate(); var newSubGroupNodes = group.CommandItems.Select(item => { var commandItemNode = new TreeNode { Text = item.Name, Name = item.Name, ContextMenuStrip = new ContextMenuStrip() }; if (string.IsNullOrWhiteSpace(item.CommandLine)) { commandItemNode.ContextMenuStrip.Items.Add(NewUrl, null, (sender, e) => CreateSubNode(commandItemNode, SubGroupName)); } else { var commandLineNode = new HiddenCheckBoxTreeNode { Text = item.CommandLine, Name = item.CommandLine, ContextMenuStrip = new ContextMenuStrip() }; if (!string.IsNullOrWhiteSpace(item.CommandLine)) { commandLineNode.ContextMenuStrip.Items.Add(Edit, null, (sender, e) => EditCommandLineNode(commandLineNode)); } if (!StateImageList.Images.ContainsKey(item.ImageKey)) { item.CreateImageKey(); StateImageList.Images.Add(item.ImageKey, item.Image); commandLineNode.StateImageKey = item.ImageKey; } commandItemNode.Nodes.Add(commandLineNode); } commandItemNode.ContextMenuStrip.Items.Add(Edit, null, (sender, e) => EditTreeNode(commandItemNode, Edit)); return(commandItemNode); }).ToArray(); var newGroupNode = new TreeNode(group.Name, newSubGroupNodes) { Name = group.Name, ContextMenuStrip = new ContextMenuStrip() }; newGroupNode.ContextMenuStrip.Items.Add(NewSubGroup, null, (sender, e) => CreateSubNode(newGroupNode, SubGroupName)); newGroupNode.ContextMenuStrip.Items.Add(Edit, null, (sender, e) => EditTreeNode(newGroupNode, Edit)); if (!ValidateCollection(newGroupNode, Nodes)) { listDataSource.Remove(group); } EndUpdate(); }