void AddSimpleRequirement(DropDownTreeNode parentNode) { if (parentNode.Tag is ComplexRequirement requirement) { var keySelector = new KeySelector(); keySelector.StartPosition = FormStartPosition.CenterParent; if (keySelector.ShowDialog() == DialogResult.OK) { var newMemento = myRequirement.CreateMemento(); bool changeOccured = false; foreach (var key in keySelector.SelectedKeys.Distinct()) { if (!requirement.myRequirements.Any(req => req is SimpleRequirement sReq && sReq.GetKey() == key)) { var newReq = new SimpleRequirement(key); requirement.myRequirements.Add(newReq); parentNode.Nodes.Insert(parentNode.Nodes.Count - 1, GenerateLeafNode(newReq)); SaveManager.Dirty = true; changeOccured = true; } } if (changeOccured) { myMementos[myRequirement].Add(newMemento); HideControls(); GenerateSeparators(parentNode); ShowControls(); } } } }
public KeyTreeNode(SimpleRequirement req) : base(req.GetKey().Name) { Tag = req; if (req.GetKey().Repeatable == true) { NumericUpDown.Tag = this; NumericUpDown.Minimum = 1; NumericUpDown.Maximum = 9; NumericUpDown.Increment = 1; NumericUpDown.Value = req.myRepeatCount; } if (KeyManager.IsSetting(req.myKeyId)) { InvertButton.Tag = this; InvertButton.BackgroundImage = Properties.Resources.NotEquals; InvertButton.BackgroundImageLayout = ImageLayout.Zoom; } }
private void treeView1_DragDrop(object sender, DragEventArgs e) { // Retrieve the client coordinates of the drop location. Point targetPoint = treeView1.PointToClient(new Point(e.X, e.Y)); // Retrieve the node at the drop location. TreeNode targetNode = treeView1.GetNodeAt(targetPoint); TreeNode targetParentNode = targetNode; if (!(targetParentNode is DropDownTreeNode)) { targetParentNode = targetNode.Parent; } // Dragged from key list if (e.Data.GetDataPresent(typeof(Guid)) && targetParentNode.Tag is ComplexRequirement complexRequirement) { var key = KeyManager.GetKey((Guid)e.Data.GetData(typeof(Guid))); if (!complexRequirement.myRequirements.Any(req => req is SimpleRequirement sReq && sReq.GetKey() == key)) { myMementos[myRequirement].Add(myRequirement.CreateMemento()); var newReq = new SimpleRequirement(key); complexRequirement.myRequirements.Add(newReq); targetParentNode.Nodes.Insert(targetParentNode.Nodes.Count - 1, GenerateLeafNode(newReq)); SaveManager.Dirty = true; HideControls(); GenerateSeparators(targetParentNode); ShowControls(); return; } } TreeNode draggedNode = null; if (e.Data.GetDataPresent(typeof(KeyTreeNode))) { draggedNode = (TreeNode)e.Data.GetData(typeof(KeyTreeNode)); } if (e.Data.GetDataPresent(typeof(DropDownTreeNode))) { draggedNode = (TreeNode)e.Data.GetData(typeof(DropDownTreeNode)); } // Dragged from within requirement tree if (draggedNode != null && !draggedNode.Parent.Equals(targetParentNode) && !ContainsNode(draggedNode, targetNode) && targetParentNode.Tag is ComplexRequirement requirement) { if (draggedNode is DropDownTreeNode || (draggedNode is KeyTreeNode && draggedNode.Tag is SimpleRequirement simpleReq && !requirement.myRequirements.Any(req => req is SimpleRequirement existingReq && existingReq.GetKey() == simpleReq.GetKey()))) { myMementos[myRequirement].Add(myRequirement.CreateMemento()); var draggedReq = draggedNode.Tag as Requirement; var parentNode = draggedNode.Parent; (parentNode.Tag as ComplexRequirement).myRequirements.Remove(draggedReq); draggedNode.Remove(); requirement.myRequirements.Add(draggedReq); targetParentNode.Nodes.Insert(targetParentNode.Nodes.Count - 1, draggedNode); SaveManager.Dirty = true; HideControls(); GenerateSeparators(parentNode); GenerateSeparators(targetParentNode); ShowControls(); } } }