Exemplo n.º 1
0
        internal static TreeNode AddChildNode(TreeNode parentNode, string name)
        {
            var childNode = new TreeNode(name)
            {
                Tag = new Dictionary <string, string>()
            };

            childNode.Name = childNode.Text.Replace(" ", "");
            if (name == "#comment")
            {
                childNode.ForeColor = System.Drawing.Color.Gray;
            }
            if (parentNode != null)
            {
                var parentCap = new DefinitionNodeCapabilities(parentNode);
                var nodeIndex = parentCap.IndexOfChild(name);
                var pos       = 0;
                while (pos < parentNode.Nodes.Count && nodeIndex >= parentCap.IndexOfChild(parentNode.Nodes[pos].Name))
                {
                    pos++;
                }
                if (pos == parentNode.Nodes.Count)
                {
                    parentNode.Nodes.Add(childNode);
                }
                else
                {
                    parentNode.Nodes.Insert(pos, childNode);
                }
                if (parentNode.Name == "DataBlock")
                {
                    if (name == "Export")
                    {
                        //var attributesNode = AddChildNode(childNode, "Attributes");
                        //AddChildNode(attributesNode, "Attribute");
                    }
                    else if (name == "Import")
                    {
                        var matchNode = AddChildNode(childNode, "Match");
                        AddChildNode(matchNode, "Attribute");
                    }
                }
            }
            return(childNode);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds a context menu to a TreeNode control
        /// </summary>
        /// <param name="node">TreeNode where to add the context menu</param>
        /// <param name="tree">Current application form</param>
        public static void AddContextMenu(TreeNode node, ShuffleBuilder tree)
        {
            tree.addMenu.Items.Clear();
            tree.gbNodeQuickActions.Controls.Clear();
            if (node == null && tree.tvDefinition.Nodes.Count > 0)
            {
                node = tree.tvDefinition.Nodes[0];
            }
            if (node != null)
            {
                var nodecapabilities = new DefinitionNodeCapabilities(node);

                foreach (var childcapability in nodecapabilities.ChildTypes)
                {
                    if (childcapability.Name == "-")
                    {
                        tree.addMenu.Items.Add(new ToolStripSeparator());
                        AddLinkSeparator(tree);
                    }
                    else if (childcapability.Multiple || !node.Nodes.ContainsKey(childcapability.Name))
                    {
                        AddMenuFromCapability(tree.addMenu, childcapability.Name);
                        AddLinkFromCapability(tree, childcapability.Name, null, childcapability.Name == "#comment");
                    }
                }
                if (tree.addMenu.Items.Count == 0)
                {
                    AddLinkFromCapability(tree, "nothing to add", string.Empty);
                    var dummy = tree.addMenu.Items.Add("nothing to add");
                    dummy.Enabled = false;
                }

                tree.deleteToolStripMenuItem.Enabled    = nodecapabilities.Delete;
                tree.commentToolStripMenuItem.Enabled   = nodecapabilities.Comment;
                tree.uncommentToolStripMenuItem.Enabled = nodecapabilities.Uncomment;
                tree.cutToolStripMenuItem.Enabled       = nodecapabilities.CutCopy;
                tree.copyToolStripMenuItem.Enabled      = nodecapabilities.CutCopy;
                tree.pasteToolStripMenuItem.Enabled     = tree.clipboard.IsValidForPaste(node);

                node.ContextMenuStrip = tree.nodeMenu;
            }
            return;
        }