Example #1
0
        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);
        }
Example #2
0
        private void removeChildToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ProtocolNode parent = (ProtocolNode)mProtocolTreeView.SelectedNode.Parent;
            ProtocolNode child  = (ProtocolNode)mProtocolTreeView.SelectedNode;

            _RemoveNode(parent, child);
        }
Example #3
0
        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;
                }
            }
        }
Example #4
0
        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;
                }
            }
        }
Example #5
0
        private void mProtocolTreeView_MouseDown(object sender, MouseEventArgs e)
        {
            var selectedNode = (ProtocolNode)mProtocolTreeView.GetNodeAt(e.X, e.Y);

            mProtocolTreeView.SelectedNode = selectedNode;
            mSourceNode = selectedNode;
        }
Example #6
0
 public TreeNodeSelect(ProtocolNode node, ProtocolNode selectedNode)
 {
     InitializeComponent();
     mTreeView.Nodes.AddRange(new /*System.Windows.Forms.TreeNode*/[] { node });
     mSelectedNode = selectedNode;
     findNode(node);
 }
Example #7
0
        private ComboBox getSubTextBox(ProtocolNode node)
        {
            ComboBox cbb = new ComboBox();

            cbb.DataSource = node.Element.SubTextList;
            cbb.AutoSize   = true;
            return(cbb);
        }
Example #8
0
        private void mProtocolTreeView_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = this._dragMode;

            // Reset the previous node var
            this._previousNode = null;
            this._selectedNode = null;
        }
Example #9
0
        private void _nudgeNodeDown()
        {
            ProtocolNode cur = getSelNode();
            NudgeDownCmd cmd = new NudgeDownCmd(cur);

            cmd.Execute();
            mProtocolTreeView.SelectedNode = cur;
        }
Example #10
0
        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();
        }
Example #11
0
        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);
        }
Example #12
0
 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);
 }
Example #13
0
        private CheckBox getCheckBox(ProtocolNode node)
        {
            CheckBox cb = new CheckBox();

            cb.AutoSize     = true;
            cb.AutoEllipsis = true;
            cb.Text         = node.Element.Text;
            return(cb);
        }
Example #14
0
        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);
        }
Example #15
0
        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);
        }
Example #16
0
 private void findNode(ProtocolNode node)
 {
     foreach (ProtocolNode curNode in node.Nodes)
     {
         if (curNode.Id == mSelectedNode.Id)
         {
             curNode.ExpandAll();
             mTreeView.SelectedNode = curNode;
         }
         findNode(curNode);
     }
 }
Example #17
0
 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);
 }
Example #18
0
        private void addChild()
        {
            ProtocolNode node = getSelNode();

            if (node.IsProtocol)
            {
                return;
            }
            ProtocolNode childNode = new ProtocolNode("New Node");

            _addNode(node, childNode);
            node.Expand();
        }
Example #19
0
 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);
 }
Example #20
0
        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);
                }
            }
        }
Example #21
0
 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);
     }
 }
Example #22
0
        private void addChild()
        {
            var node = getSelNode();

            if (node != null)
            {
                if (node.IsProtocol)
                {
                    return;
                }
                var childNode = new ProtocolNode("New Node");
                _addNode(node, childNode);
                node.Expand();
            }
        }
Example #23
0
        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);
                }
            }
        }
Example #24
0
        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);
            }
        }
Example #25
0
        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);
        }
Example #26
0
        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);
        }
Example #27
0
        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;
        }
Example #28
0
        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());
//             }
        }
Example #29
0
        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 });
        }
Example #30
0
        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;
            }
        }