コード例 #1
0
        private void CopyClass()
        {
            if (treeView1.SelectedNode == null)
            {
                return;
            }

            if (treeView1.SelectedNode.Tag == null)
            {
                return;
            }

            if (!(treeView1.SelectedNode.Tag is NodeItem))
            {
                return;
            }

            NodeItem   nodeItem   = treeView1.SelectedNode.Tag as NodeItem;
            NodeDefine nodeDefine = nodeItem.NodeDefine;

            NodeDefineListContent content = new NodeDefineListContent();

            content.DataList.Add(nodeDefine);

            if (content.DataList.Count > 0)
            {
                Clipboard.SetText(XmlUtility.ObjectToString(content));
            }

            MainForm.Instance.ShowInfo("您复制了" + content.DataList.Count.ToString() + "个节点类!!!");
        }
コード例 #2
0
        private void  除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (treeView1.SelectedNode == null)
            {
                return;
            }

            if (treeView1.SelectedNode.Tag == null)
            {
                return;
            }

            if (!(treeView1.SelectedNode.Tag is NodeItem))
            {
                return;
            }

            NodeItem   nodeItem   = treeView1.SelectedNode.Tag as NodeItem;
            NodeDefine nodeDefine = nodeItem.NodeDefine;

            if (MessageBox.Show(string.Format("是否删除节点{0}?", nodeDefine.ClassType), "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                m_Nodes.Remove(nodeDefine);
                m_NodeTreeViewManager.RemoveNodeDefine(nodeDefine);
            }
        }
コード例 #3
0
        private void 编辑类ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (treeView1.SelectedNode == null)
            {
                return;
            }

            if (treeView1.SelectedNode.Tag == null)
            {
                return;
            }

            if (!(treeView1.SelectedNode.Tag is NodeItem))
            {
                return;
            }

            NodeItem   nodeItem   = treeView1.SelectedNode.Tag as NodeItem;
            NodeDefine nodeDefine = nodeItem.NodeDefine;

            EditNodeDefineForm editClassForm = new EditNodeDefineForm(this, nodeDefine, delegate()
            {
                nodeItem = m_NodeTreeViewManager.BindNodeDefine(nodeDefine);
                treeView1.SelectedNode = nodeItem.TreeNode;
            });

            editClassForm.ShowDialog();
        }
コード例 #4
0
        public bool RemoveNodeClass(NodeClass nodeClass)
        {
            NodeItem nodeItem = FindNodeItem(nodeClass);

            if (nodeItem != null)
            {
                nodeItem.TreeNode.Remove();
            }

            if (nodeItem.CategoryItem != null)
            {
                TreeNode treeNode = nodeItem.CategoryItem.TreeNode;
                while (treeNode.Tag is CategoryItem)
                {
                    TreeNode parentNode = treeNode.Parent;
                    if (treeNode.Nodes.Count == 0)
                    {
                        treeNode.Remove();
                        treeNode = parentNode;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            return(false);
        }
コード例 #5
0
        private void treeView1_MouseDown(object sender, MouseEventArgs e)
        {
            if (treeView1.SelectedNode == null)
            {
                return;
            }

            for (int i = 0; i < contextMenuStrip1.Items.Count; i++)
            {
                contextMenuStrip1.Items[i].Visible = false;
            }

            if (treeView1.SelectedNode.Tag is NodeTypeItem || treeView1.SelectedNode.Tag is CategoryItem)
            {
                contextMenuStrip1.Items[0].Visible = true;
                contextMenuStrip1.Items[3].Visible = true;
            }
            else if (treeView1.SelectedNode.Tag is NodeItem)
            {
                contextMenuStrip1.Items[1].Visible = true;
                contextMenuStrip1.Items[2].Visible = true;
            }

            if (e.Clicks == 2)
            {
                if (treeView1.SelectedNode == null)
                {
                    return;
                }

                if (treeView1.SelectedNode.Tag == null)
                {
                    return;
                }

                if (!(treeView1.SelectedNode.Tag is NodeItem))
                {
                    return;
                }

                NodeItem   nodeItem   = treeView1.SelectedNode.Tag as NodeItem;
                NodeDefine nodeDefine = nodeItem.NodeDefine;


                EditNodeDefineForm editClassForm = new EditNodeDefineForm(this, nodeDefine, delegate()
                {
                    nodeItem = m_NodeTreeViewManager.BindNodeDefine(nodeDefine);
                    treeView1.SelectedNode = nodeItem.TreeNode;
                });
                editClassForm.ShowDialog();
            }
        }
コード例 #6
0
        public NodeItem FindNodeItem(NodeClass nodeClass)
        {
            for (int i = 0; i < m_TreeView.Nodes.Count; i++)
            {
                TreeNode treeNode = m_TreeView.Nodes[i];
                NodeItem nodeItem = FindNodeItem(treeNode, nodeClass);
                if (nodeItem != null)
                {
                    return(nodeItem);
                }
            }

            return(null);
        }
コード例 #7
0
        private NodeItem FindNodeItem(TreeNode treeNode, NodeClass nodeClass)
        {
            if (treeNode.Tag is NodeItem)
            {
                NodeItem nodeItem = treeNode.Tag as NodeItem;
                if (nodeItem.NodeClass.ClassType == nodeClass.ClassType || nodeItem.NodeClass == nodeClass)
                {
                    return(nodeItem);
                }
            }

            for (int i = 0; i < treeNode.Nodes.Count; i++)
            {
                TreeNode tempTreeNode = treeNode.Nodes[i];
                NodeItem nodeItem     = FindNodeItem(tempTreeNode, nodeClass);
                if (nodeItem != null)
                {
                    return(nodeItem);
                }
            }

            return(null);
        }
コード例 #8
0
        public NodeItem BindNodeClass(NodeClass nodeClass)
        {
            NodeTypeItem nodeTypeItem = GetNodeTypeItem(nodeClass.NodeType);

            if (nodeTypeItem == null)
            {
                return(null);
            }

            NodeItem nodeItem = FindNodeItem(nodeClass);

            //刷新
            if (nodeItem != null)
            {
                if (nodeItem.OldNodeType == nodeClass.NodeType && nodeItem.OldCategory == nodeClass.Category)
                {
                    nodeItem.TreeNode.Text = nodeClass.ClassType;
                    return(nodeItem);
                }
                else
                {
                    nodeItem.TreeNode.Remove();
                }

                if (nodeItem.OldCategory != nodeClass.Category)
                {
                    CheckRemoveCategory(nodeItem.OldNodeType, nodeItem.OldCategory);
                }
            }

            if (nodeItem == null)
            {
                nodeItem = new NodeItem();
            }

            if (string.IsNullOrEmpty(nodeClass.Category))
            {
                TreeNode treeNode = nodeTypeItem.TreeNode.Nodes.Add(nodeClass.ClassType);
                treeNode.Tag          = nodeItem;
                nodeItem.TreeNode     = treeNode;
                nodeItem.CategoryItem = null;
                nodeItem.NodeTypeItem = nodeTypeItem;
                nodeItem.NodeClass    = nodeClass;

                nodeItem.OldCategory = nodeClass.Category;
                nodeItem.OldNodeType = nodeClass.NodeType;
            }
            else
            {
                CategoryItem categoryItem = FindCategoryItem(nodeClass.NodeType, nodeClass.Category);

                if (categoryItem == null)
                {
                    categoryItem = BindCategory(nodeTypeItem.TreeNode, nodeClass.Category);
                }

                TreeNode treeNode = categoryItem.TreeNode.Nodes.Add(nodeClass.ClassType);
                treeNode.Tag          = nodeItem;
                nodeItem.TreeNode     = treeNode;
                nodeItem.CategoryItem = categoryItem;
                nodeItem.NodeTypeItem = nodeTypeItem;
                nodeItem.NodeClass    = nodeClass;

                nodeItem.OldCategory = nodeClass.Category;
                nodeItem.OldNodeType = nodeClass.NodeType;
            }

            return(nodeItem);
        }
コード例 #9
0
        public NodeItem BindNodeDefine(NodeDefine nodeDefine)
        {
            NodeTypeItem nodeTypeItem = GetNodeTypeItem(nodeDefine.NodeType);

            if (nodeTypeItem == null)
            {
                return(null);
            }

            NodeItem nodeItem = FindNodeItem(nodeDefine);

            //刷新
            if (nodeItem != null)
            {
                if (nodeItem.OldNodeType == nodeDefine.NodeType && nodeItem.OldCategory == nodeDefine.Category)
                {
                    nodeItem.TreeNode.Text = nodeDefine.ClassType + (string.IsNullOrEmpty(nodeDefine.Label) ? string.Empty : " (" + nodeDefine.Label + ")");
                    return(nodeItem);
                }
                else
                {
                    nodeItem.TreeNode.Remove();
                }

                if (nodeItem.OldCategory != nodeDefine.Category)
                {
                    CheckRemoveCategory(nodeItem.OldNodeType, nodeItem.OldCategory);
                }
            }

            if (nodeItem == null)
            {
                nodeItem = new NodeItem();
            }

            if (string.IsNullOrEmpty(nodeDefine.Category))
            {
                TreeNode treeNode = nodeTypeItem.TreeNode.Nodes.Add(nodeDefine.ClassType + (string.IsNullOrEmpty(nodeDefine.Label) ? string.Empty : " (" + nodeDefine.Label + ")"));
                treeNode.Tag          = nodeItem;
                nodeItem.TreeNode     = treeNode;
                nodeItem.CategoryItem = null;
                nodeItem.NodeTypeItem = nodeTypeItem;
                nodeItem.NodeDefine   = nodeDefine;

                nodeItem.OldCategory = nodeDefine.Category;
                nodeItem.OldNodeType = nodeDefine.NodeType;
            }
            else
            {
                CategoryItem categoryItem = FindCategoryItem(nodeDefine.NodeType, nodeDefine.Category);

                if (categoryItem == null)
                {
                    categoryItem = BindCategory(nodeTypeItem.TreeNode, nodeDefine.Category);
                }

                TreeNode treeNode = categoryItem.TreeNode.Nodes.Add(nodeDefine.ClassType + (string.IsNullOrEmpty(nodeDefine.Label) ? string.Empty : " (" + nodeDefine.Label + ")"));
                treeNode.Tag          = nodeItem;
                nodeItem.TreeNode     = treeNode;
                nodeItem.CategoryItem = categoryItem;
                nodeItem.NodeTypeItem = nodeTypeItem;
                nodeItem.NodeDefine   = nodeDefine;

                nodeItem.OldCategory = nodeDefine.Category;
                nodeItem.OldNodeType = nodeDefine.NodeType;
            }

            return(nodeItem);
        }