private void 降级ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (_treeView.SelectedItems.Count > 0)
            {
                TreeListViewItem node = _treeView.SelectedItems[0];
                YmlItem          item = (YmlItem)node.Tag;

                TreeListViewItem preNode = getSameLevelPreNode(node, node);
                if (preNode != null)
                {
                    node.Parent.Items.Remove(node);
                    preNode.Items.Add(node);

                    item.Level            = item.Level + 1;
                    item.Parent           = (YmlItem)preNode.Tag;
                    node.SubItems[2].Text = "" + item.Level;
                }
                else
                {
                    TreeListViewItem nextNode = getSameLevelNextNode(node, node);
                    if (nextNode != null)
                    {
                        node.Parent.Items.Remove(node);
                        nextNode.Items.Add(node);

                        item.Level            = item.Level + 1;
                        item.Parent           = (YmlItem)nextNode.Tag;
                        node.SubItems[2].Text = "" + item.Level;
                    }
                }
            }
            btn_save.Enabled = true;
        }
        private void _treeView_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                if (_treeView.SelectedItems.Count > 0)
                {
                    TreeListViewItem node = _treeView.SelectedItems[0];
                    YmlItem          item = (YmlItem)node.Tag;

                    TreeListViewItem preNode  = getSameLevelPreNode(node, node);
                    bool             isenable = false;
                    if (preNode != null)
                    {
                        isenable = true;
                    }
                    else
                    {
                        TreeListViewItem nextNode = getSameLevelNextNode(node, node);
                        if (nextNode != null)
                        {
                            isenable = true;
                        }
                    }
                    降级ToolStripMenuItem.Enabled = isenable;
                    升级ToolStripMenuItem.Enabled = item.Level > 0;
                }
            }
        }
        private void 添加顶级节点ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            TreeListViewItem viewItem = new TreeListViewItem();
            YmlItem          obj      = new YmlItem()
            {
                Key        = "",
                Value      = "",
                Level      = 0,
                Common     = "",
                Uuid       = Guid.NewGuid().ToString("N"),
                ImageIndex = 3,
                Parent     = null,
                SpcCount   = 0
            };

            viewItem.Tag        = obj;
            viewItem.Text       = obj.Key;
            viewItem.ImageIndex = obj.ImageIndex;

            viewItem.SubItems.Add(obj.Value);
            viewItem.SubItems.Add("" + obj.Level);
            viewItem.SubItems.Add(obj.Common);

            _treeView.Items.Add(viewItem);

            YmlNodeForm form = new YmlNodeForm(viewItem, null, null, 2);

            form.ShowDialog(this);
            btn_save.Enabled = true;
        }
        private void 升级ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (_treeView.SelectedItems.Count > 0)
            {
                TreeListViewItem node = _treeView.SelectedItems[0];
                YmlItem          item = (YmlItem)node.Tag;
                if (node.Parent != null && item.Level > 0)
                {
                    TreeListViewItem parentNode = node.Parent;
                    YmlItem          parentItem = (YmlItem)parentNode.Tag;

                    node.Parent.Items.Remove(node);
                    if (parentNode.Parent == null)
                    {
                        _treeView.Items.Add(node);
                    }
                    else
                    {
                        parentNode.Parent.Items.Add(node);
                    }

                    item.Level  = parentItem.Level;
                    item.Parent = parentItem.Parent;

                    node.SubItems[2].Text = "" + item.Level;
                }
            }
            btn_save.Enabled = true;
        }
        private void 添加同级节点ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (_treeView.SelectedItems.Count > 0)
            {
                TreeListViewItem parentNode = _treeView.SelectedItems[0];
                YmlItem          parentObj  = (YmlItem)parentNode.Tag;

                TreeListViewItem viewItem = new TreeListViewItem();
                YmlItem          obj      = new YmlItem()
                {
                    Key        = "",
                    Value      = "",
                    Level      = parentObj.Level,
                    Common     = "",
                    Uuid       = Guid.NewGuid().ToString("N"),
                    ImageIndex = parentObj.ImageIndex == 2 ? 1 : parentObj.ImageIndex,
                    Parent     = parentObj.Parent,
                    SpcCount   = parentObj.SpcCount
                };
                viewItem.Tag        = obj;
                viewItem.Text       = obj.Key;
                viewItem.ImageIndex = obj.ImageIndex;

                viewItem.SubItems.Add(obj.Value);
                viewItem.SubItems.Add("" + obj.Level);
                viewItem.SubItems.Add(obj.Common);

                if (parentNode.Parent != null)
                {
                    parentNode.Parent.Items.Add(viewItem);
                }
                else
                {
                    _treeView.Items.Add(viewItem);
                }

                YmlNodeForm form = new YmlNodeForm(viewItem, null, null, 1);
                form.ShowDialog(this);

                string value = viewItem.SubItems[1].Text;
                if (string.IsNullOrWhiteSpace(value))
                {
                    string key = viewItem.SubItems[0].Text;
                    if (key.Trim().StartsWith("#"))
                    {
                        obj.ImageIndex = 2;
                    }
                    else
                    {
                        obj.ImageIndex = 3;
                    }
                    viewItem.ImageIndex = obj.ImageIndex;
                }
                btn_save.Enabled = true;
            }
        }
Exemple #6
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (_treeView.SelectedItems.Count > 0)
            {
                TreeListViewItem item = _treeView.SelectedItems[0];
                YmlItem          file = (YmlItem)item.Tag;
                parent.Text = listToNodeText(getParentText(item));

                parentItem = file;
            }

            panel1.Visible = false;
        }
Exemple #7
0
        private void btn_sure_Click(object sender, EventArgs e)
        {
            if (treeNode != null)
            {
                YmlItem item = (YmlItem)treeNode.Tag;
                item.Key    = name.Text;
                item.Value  = value.Text;
                item.Common = common.Text;
                if (!item.Common.TrimStart().StartsWith("#") && item.Common != "")
                {
                    item.Common = "#" + item.Common;
                }
                if (!item.Key.TrimStart().StartsWith("#"))
                {
                    if (string.IsNullOrWhiteSpace(item.Value))
                    {
                        item.ImageIndex = 3;
                    }
                    else
                    {
                        item.ImageIndex = 1;
                    }
                }
                else
                {
                    item.ImageIndex = 2;
                }
                treeNode.SubItems[0].Text = item.Key;
                treeNode.SubItems[1].Text = item.Value;
                treeNode.SubItems[3].Text = item.Common;
                treeNode.ImageIndex       = item.ImageIndex;

                if (parentItem != null)
                {
                    treeNode.SubItems[2].Text = "" + (parentItem.Level + 1);
                    item.Level                = (parentItem.Level + 1);
                    item.SpcCount             = item.Level * 4;
                    treeNode.SubItems[2].Text = "" + item.Level;
                    if (callback != null)
                    {
                        callback(parentItem);
                    }
                }
            }
            this.Close();
        }
Exemple #8
0
        private void RenderTree()
        {
            // 树形
            _treeView.Items.Clear();
            TreeListViewItem viewItem = null, parentItem = null;
            Dictionary <string, TreeListViewItem> _cache = new Dictionary <string, TreeListViewItem>();

            foreach (YmlItem obj in lists)
            {
                if (obj.ImageIndex == 1 || obj.ImageIndex == 2)
                {
                    continue;
                }
                viewItem            = new TreeListViewItem();
                viewItem.Tag        = obj;
                viewItem.Text       = obj.Key;
                viewItem.ImageIndex = obj.ImageIndex;

                viewItem.SubItems.Add(obj.Value);

                if (obj.Level == 0)
                {
                    _treeView.Items.Add(viewItem);
                }
                else if (_cache.ContainsKey(obj.Parent.Uuid))
                {
                    parentItem = _cache[obj.Parent.Uuid];
                    if (null != parentItem)
                    {
                        parentItem.Items.Add(viewItem);
                    }
                }
                else
                {
                    _treeView.Items.Add(viewItem);
                }

                _cache.Add(obj.Uuid, viewItem);
            }
            _treeView.ExpandAll();
        }
        private TreeListViewItem getTreeNode(TreeListViewItemCollection items, string uuid)
        {
            TreeListViewItem node = null;
            YmlItem          item = null;

            foreach (TreeListViewItem treeNode in items)
            {
                item = (YmlItem)treeNode.Tag;
                if (item.Uuid == uuid)
                {
                    node = treeNode;
                    return(node);
                }
                node = getTreeNode(treeNode.Items, uuid);
                if (null != node)
                {
                    return(node);
                }
            }
            return(null);
        }
Exemple #10
0
        public static List <YmlItem> FormatYmlToTree(string content)
        {
            List <YmlItem> lists = new List <YmlItem>();

            string[]       lines = content.Split('\n');
            YmlItem        item = null;
            string         startStr = "";
            List <YmlItem> levels = new List <YmlItem>();
            int            index1 = -1, index2 = -1, index = 0;

            foreach (string line in lines)
            {
                if (string.IsNullOrWhiteSpace(line))
                {
                    item            = new YmlItem();
                    item.Uuid       = "T" + (index++);
                    item.ImageIndex = 2;
                    item.Key        = "#" + line;
                    item.Value      = "";
                    item.Level      = 0;
                    item.Common     = "";

                    lists.Add(item);
                    continue;
                }
                if (line.TrimStart().StartsWith("#"))
                {
                    item            = new YmlItem();
                    item.Uuid       = "T" + (index++);
                    item.ImageIndex = 2;
                    item.Key        = line;
                    item.Value      = "";
                    item.Level      = 0;
                    item.Common     = "";

                    lists.Add(item);
                }
                else
                {
                    item            = new YmlItem();
                    item.Uuid       = "T" + (index++);
                    item.ImageIndex = 0;
                    item.Key        = "";
                    item.Value      = "";
                    item.Level      = 0;
                    item.Common     = "";

                    item.SpcCount = StartSpaceCount(line);
                    if (item.SpcCount == 0)
                    {
                        levels.Clear();
                        item.Level = 0;
                    }
                    else
                    {
                        // level
                        for (int i = levels.Count - 1; i >= 0; i--)
                        {
                            if (levels[i].SpcCount < item.SpcCount)
                            {
                                item.Level  = levels[i].Level + 1;
                                item.Parent = levels[i];
                                break;
                            }
                        }
                    }
                    levels.Add(item);

                    index2 = line.IndexOf("#");
                    if (index2 > 0)
                    {
                        startStr    = line.Substring(0, index2);
                        item.Common = line.Substring(index2);
                    }
                    else
                    {
                        startStr = line;
                    }

                    index1 = startStr.IndexOf(":");
                    if (index1 > 0)
                    {
                        item.Key   = startStr.Substring(0, index1).TrimStart();
                        item.Value = startStr.Substring(index1 + 1).Trim();
                    }
                    else
                    {
                        item.Key    = startStr.TrimStart();
                        item.Common = "--格式错误--";
                    }

                    if (!string.IsNullOrWhiteSpace(item.Value))
                    {
                        item.ImageIndex = 1;
                    }

                    lists.Add(item);
                }
            }

            return(lists);
        }