public ProtocolNodeUi(Protocol protocol, ProtocolNode node) { InitializeComponent(); mProtocol = protocol; mNode = node; mFlowLayoutPanel.Dock = DockStyle.Fill; mDepthLabel = getDepthLabel(mNode); mFlowLayoutPanel.Controls.Add(mDepthLabel); mCheckBox = getCheckBox(mNode); mFlowLayoutPanel.Controls.Add(mCheckBox); if (mNode.Element.SubTextList.Count > 0) { mComboBoxSubText = getSubTextBox(mNode); mFlowLayoutPanel.Controls.Add(mComboBoxSubText); } if (mProtocol.getSectionIndex(mNode.Element.GotoList.Count) > 0) { mGotoLabel = getLinkLabel(mNode); mFlowLayoutPanel.Controls.Add(mGotoLabel); } this.Controls.Add(this.mFlowLayoutPanel); }
private void removeChildToolStripMenuItem_Click(object sender, EventArgs e) { ProtocolNode parent = (ProtocolNode)mProtocolTreeView.SelectedNode.Parent; ProtocolNode child = (ProtocolNode)mProtocolTreeView.SelectedNode; _RemoveNode(parent, child); }
private void mProtocolTreeView_DragDrop(object sender, DragEventArgs e) { // Check it's a treenode being dragged if (e.Data.GetDataPresent("System.Windows.Forms.TreeNode", false)) { TreeNode dragNode = (TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode"); // Get the target node from the mouse coords Point pt = ((TreeView)this.mProtocolTreeView).PointToClient(new Point(e.X, e.Y)); TreeNode targetNode = this.mProtocolTreeView.GetNodeAt(pt); // De-color it targetNode.BackColor = SystemColors.HighlightText; targetNode.ForeColor = SystemColors.ControlText; // 1) Check we're not dragging onto ourself // 2) Check we're not dragging onto one of our children // (this is the lazy way, will break if there are nodes with the same name, // but it's quicker than checking all nodes below is) // 3) Check we're not dragging onto our parent if (targetNode != dragNode && !targetNode.FullPath.StartsWith(dragNode.FullPath) && dragNode.Parent != targetNode) { // Copy the node, add as a child to the destination node ProtocolNode newTreeNode = (ProtocolNode)dragNode.Clone(); targetNode.Nodes.Add(newTreeNode); targetNode.Expand(); // Remove Original Node, set the dragged node as selected dragNode.Remove(); this.mProtocolTreeView.SelectedNode = newTreeNode; } } }
private void tree_DragOver(object sender, System.Windows.Forms.DragEventArgs e) { // Get the tree. TreeView tree = (TreeView)sender; // Drag and drop denied by default. e.Effect = DragDropEffects.None; // Is it a valid format? ProtocolNode dragedNode = (ProtocolNode)e.Data.GetData(typeof(ProtocolNode)); if (dragedNode != null) { // Get the screen point. Point pt = new Point(e.X, e.Y); // Convert to a point in the TreeView's coordinate system. pt = tree.PointToClient(pt); // Is the mouse over a valid node? ProtocolNode target = (ProtocolNode)tree.GetNodeAt(pt); if (isValidDragDrop(target)) { e.Effect = DragDropEffects.Move; tree.SelectedNode = target; } } }
private void mProtocolTreeView_MouseDown(object sender, MouseEventArgs e) { var selectedNode = (ProtocolNode)mProtocolTreeView.GetNodeAt(e.X, e.Y); mProtocolTreeView.SelectedNode = selectedNode; mSourceNode = selectedNode; }
public TreeNodeSelect(ProtocolNode node, ProtocolNode selectedNode) { InitializeComponent(); mTreeView.Nodes.AddRange(new /*System.Windows.Forms.TreeNode*/[] { node }); mSelectedNode = selectedNode; findNode(node); }
private ComboBox getSubTextBox(ProtocolNode node) { ComboBox cbb = new ComboBox(); cbb.DataSource = node.Element.SubTextList; cbb.AutoSize = true; return(cbb); }
private void mProtocolTreeView_DragEnter(object sender, DragEventArgs e) { e.Effect = this._dragMode; // Reset the previous node var this._previousNode = null; this._selectedNode = null; }
private void _nudgeNodeDown() { ProtocolNode cur = getSelNode(); NudgeDownCmd cmd = new NudgeDownCmd(cur); cmd.Execute(); mProtocolTreeView.SelectedNode = cur; }
private void _RemoveNode(ProtocolNode parent, ProtocolNode childNode) { List <ProtocolNode> list = null; getNodesThatLinkToNodeId_(mProtocolNode, ref list, childNode.Id); var cmd = new RemoveCmd(parent, childNode, list); cmd.Execute(); }
private void addSection() { ProtocolNode newSectionNode = new ProtocolNode("New Section"); newSectionNode.ImageIndex = SECT_IMG; newSectionNode.SelectedImageIndex = SECT_IMG; newSectionNode.IsSection = true; _addNode((ProtocolNode)mProtocolTreeView.Nodes[0], newSectionNode); }
private SleepEditControlLib.ProtocolNodeUi getNodeUi(ProtocolNode node) { SleepEditControlLib.ProtocolNodeUi widget = new SleepEditControlLib.ProtocolNodeUi(mProtocol, node); if (widget.GotoLabel != null) { widget.GotoLabel.Click += new EventHandler(GotoLabel_Click); } return(widget); }
private CheckBox getCheckBox(ProtocolNode node) { CheckBox cb = new CheckBox(); cb.AutoSize = true; cb.AutoEllipsis = true; cb.Text = node.Element.Text; return(cb); }
private LinkLabel getLinkLabel(ProtocolNode node) { LinkLabel lbl = new LinkLabel(); lbl.AutoSize = true; string str = mNode.Element.GotoSection; lbl.Tag = mProtocol.getSectionIndex(str); lbl.Text = str; return(lbl); }
private Label getDepthLabel(ProtocolNode node) { Label lbl = new Label(); int depth = node.Depth; if (depth > 0) { depth = depth - 1; } lbl.Width = depth * 20; return(lbl); }
private void findNode(ProtocolNode node) { foreach (ProtocolNode curNode in node.Nodes) { if (curNode.Id == mSelectedNode.Id) { curNode.ExpandAll(); mTreeView.SelectedNode = curNode; } findNode(curNode); } }
private bool contains(ProtocolNode parent, ProtocolNode child) { foreach (ProtocolNode node in parent.Nodes) { if (node.Nodes.Contains(child)) { mIsFound = true; } contains(node, child); } return(mIsFound); }
private void addChild() { ProtocolNode node = getSelNode(); if (node.IsProtocol) { return; } ProtocolNode childNode = new ProtocolNode("New Node"); _addNode(node, childNode); node.Expand(); }
private bool isValidDragDrop(ProtocolNode target) { if ( mSourceNode.IsSection && target != mProtocolTreeView.TopNode || mSourceNode.Equals(target) || target.Equals(mSourceNode.Parent) || mSourceNode.Nodes.Contains(target) || contains(mSourceNode, target)) { mIsFound = false; return(false); } return(true); }
private void populateForm() { mProtocolNode = mProtocol.Node; foreach (ProtocolNode node in mProtocolNode.NodeList) { TabPage tabPage = getTabPage(node); mTabControl.Controls.Add(tabPage); if (node.NodeList.Count > 0) { processAllNodes(node, ref tabPage); } } }
private void getNodesThatLinkToNodeId_(ProtocolNode rootNode, ref List <ProtocolNode> list, int id) { foreach (ProtocolNode curNode in rootNode.Nodes) { if (curNode.LinkId == id) { if (list == null) { list = new List <ProtocolNode>(); } list.Add(curNode); } getNodesThatLinkToNodeId_(curNode, ref list, id); } }
private void addChild() { var node = getSelNode(); if (node != null) { if (node.IsProtocol) { return; } var childNode = new ProtocolNode("New Node"); _addNode(node, childNode); node.Expand(); } }
void processAllNodes(ProtocolNode node, ref TabPage page) { if (node != null) { if (!node.IsSection) { FlowLayoutPanel panel = (FlowLayoutPanel)page.Controls.Find("FlowLayout", false)[0]; panel.Controls.Add(getNodeUi(node)); } foreach (ProtocolNode cur in node.NodeList) { processAllNodes(cur, ref page); } } }
private void Tree_ItemDrag(object sender, ItemDragEventArgs e) { // Get the tree. TreeView tree = (TreeView)sender; // Get the node underneath the mouse. ProtocolNode selectedNode = (ProtocolNode)mProtocolTreeView.SelectedNode; tree.SelectedNode = selectedNode; // Start the drag-and-drop operation with a cloned copy of the node. if (selectedNode != null) { tree.DoDragDrop((ProtocolNode)selectedNode.Clone(), DragDropEffects.Move); } }
private static TabPage getTabPage(ProtocolNode node) { TabPage tabPage = new TabPage(); tabPage.Text = node.Element.Text; tabPage.Tag = node; tabPage.Padding = new System.Windows.Forms.Padding(3); tabPage.UseVisualStyleBackColor = true; FlowLayoutPanel panel = new FlowLayoutPanel(); panel.Dock = DockStyle.Fill; panel.Name = "FlowLayout"; panel.FlowDirection = FlowDirection.TopDown; tabPage.Controls.Add(panel); return(tabPage); }
private void tree_DragDrop(object sender, System.Windows.Forms.DragEventArgs e) { // Get the tree. TreeView tree = (TreeView)sender; // Get the screen point. Point pt = new Point(e.X, e.Y); // Convert to a point in the TreeView's coordinate system. pt = tree.PointToClient(pt); // Get the node underneath the mouse. ProtocolNode newParentNode = (ProtocolNode)tree.GetNodeAt(pt); ProtocolNode newChildNode = (ProtocolNode)e.Data.GetData(typeof(ProtocolNode)); _move(newParentNode, newChildNode); }
private void mProtocolTreeView_DragOver(object sender, DragEventArgs e) { // Change any previous node back if (this._previousNode != null) { this._previousNode.BackColor = SystemColors.HighlightText; this._previousNode.ForeColor = SystemColors.ControlText; } // Get the node from the mouse position, color it Point pt = ((TreeView)this.mProtocolTreeView).PointToClient(new Point(e.X, e.Y)); ProtocolNode treeNode = (ProtocolNode)this.mProtocolTreeView.GetNodeAt(pt); // Remember the target node, so we can set it back this._previousNode = (ProtocolNode)treeNode; }
static void Main(string[] args) { ProtocolNode node = new ProtocolNode(); ProtocolManager.load(node); ProtocolManager.save(node, @"F:\protocol_out.xml"); int i = 0; // for (int i = 0; i < 20; i++) // { // System.Console.WriteLine(System.Guid.NewGuid().ToString()); // } }
private void newToolStripButton_Click(object sender, EventArgs e) { clearAllFields(); var newSectionNode = new ProtocolNode("New Section"); newSectionNode.ImageIndex = SECT_IMG; newSectionNode.SelectedImageIndex = SECT_IMG; newSectionNode.IsSection = true; mProtocolNode.Element.Text = "New Protocol"; mProtocolNode.Text = "New Protocol"; Text = "new Protocol"; mProtocolNode.Element.SubTextList.Clear(); mProtocolNode.IsProtocol = true; mProtocolNode.Id = 0; mProtocolNode.LinkId = -1; mProtocolNode.LinkText = ""; mProtocolNode.Nodes.Add(newSectionNode); mProtocolTreeView.Nodes.AddRange(new /*System.Windows.Forms.TreeNode*/[] { mProtocolNode }); }
private void mProtocolTreeView_AfterSelect(object sender, TreeViewEventArgs e) { mCurNode = getSelNode(); mDocument.Text = mCurNode.Element.Text; mIdLabelValue.Text = mCurNode.Id.ToString(); mLinkLabelText.Text = mCurNode.LinkId.ToString(); mLinkTextBox.Text = mCurNode.LinkText; mQuestionListComboBox.Items.Clear(); mQuestionListComboBox.Text = ""; if (mCurNode.Element.SubTextList.Count > 0) { foreach (var str in mCurNode.Element.SubTextList) { mQuestionListComboBox.Items.Add(str); } mQuestionListComboBox.Text = mQuestionListComboBox.Items[0] as string; } }