private void treeObjects_OnDropItemIntoTree(object sender, DragEventArgs e) { TreeNode myNode = null; if (e.Data.GetDataPresent(typeof(TreeNode))) { myNode = (TreeNode)(e.Data.GetData(typeof(TreeNode))); } else { return; } Point position = new Point(e.X, e.Y); position = this.treeObjects.PointToClient(position); TreeNode dropNode = this.treeObjects.GetNodeAt(position); TreeNode dragNode = null; bool needUpdate = false; if ((dropNode != null && dropNode.Parent != myNode && dropNode != myNode) || (dropNode == null)) { dragNode = myNode; myNode.Remove(); needUpdate = true; } if (dragNode != null && needUpdate) { TestObjectNurse dragNurse = TestObjectNurse.FromTreeNode(dragNode); string newName = ""; if (dropNode == null) { newName = SpyWindowHelper.DeriveControlName(RootNurseObject, dragNurse.NodeName); treeObjects.Nodes.Add(dragNode); } else { newName = SpyWindowHelper.DeriveControlName(RootNurseObject, dragNurse.NodeName); dropNode.Nodes.Add(dragNode); } if (newName != dragNurse.NodeName) { dragNurse.NodeName = newName; SelectedNodesChanged(dragNode); MessageBox.Show(string.Format(StringResources.LPSpy_SpyMainWindow_ObjNameSameMsg, newName)); } treeObjects.SelectedNode = dragNode; AppEnvironment.SetModelChanged(true); } }
private void treeObjects_OnObjectNameChanged(object sender, NodeLabelEditEventArgs e) { if (e.CancelEdit) { return; } if (e.Label == null) { return; } TestObjectNurse nurse = TestObjectNurse.FromTreeNode(e.Node); if (e.Label == nurse.NodeName) { return; } string newName = e.Label; if (e.Label.StartsWith(nurse.ControlTypeString + ":")) { newName = newName.Substring((nurse.ControlTypeString + ":").Length); newName = newName.Trim(); } string nameChecker = SpyWindowHelper.DeriveControlName(nurse.ParentNurse, newName); if (nameChecker == newName) { nurse.NodeName = newName; if (NodeNameChanged != null) { NodeNameChanged(sender, e); } _presenterModel.SetSelectNodeName(newName); AppEnvironment.SetModelChanged(true); return; } else { MessageBox.Show(string.Format(StringResources.LPSpy_SpyMainWindow_SelectobjMsg, newName)); e.CancelEdit = true; e.Node.Text = TestObjectNurse.FromTreeNode(e.Node).NodeName; } }