private void btn_meihua_Click(object sender, EventArgs e)
        {
            int index = ymlEditor.GetFirstCharIndexOfCurrentLine();
            int row   = ymlEditor.GetLineFromCharIndex(index);
            int start = ymlEditor.SelectionStart;

            string content = ymlEditor.Text;

            // YML编辑器
            ymlEditor.Text = "";
            List <YmlLine> list = YmlFormatUtil.FormatYml(content, true);

            foreach (YmlLine line in list)
            {
                ymlEditor.SelectionColor = line.Color;
                ymlEditor.SelectionFont  = line.Font;
                ymlEditor.AppendText(line.Text);
            }

            if (row > 10)
            {
                index = ymlEditor.GetFirstCharIndexFromLine(row - 10);
                ymlEditor.SelectionStart  = index;
                ymlEditor.SelectionLength = 0;
                ymlEditor.ScrollToCaret();
            }

            ymlEditor.SelectionStart  = start;
            ymlEditor.SelectionLength = 0;
            ymlEditor.Focus();
        }
        private List <string> getTreeNodeContent(TreeListViewItemCollection items)
        {
            List <string> list  = new List <string>();
            string        line  = "";
            int           level = 0;

            foreach (TreeListViewItem treeNode in items)
            {
                line = treeNode.Text;
                if (!line.TrimStart().StartsWith("#"))
                {
                    line += ": ";
                    level = Convert.ToInt32(treeNode.SubItems[2].Text);
                    line  = YmlFormatUtil.GetSpace(level * 4) + line;
                    line += treeNode.SubItems[1].Text;
                    line += treeNode.SubItems[3].Text;
                }
                if (!string.IsNullOrWhiteSpace(line))
                {
                    list.Add(line);
                }
                list.AddRange(getTreeNodeContent(treeNode.Items));
            }
            return(list);
        }
        private bool Validate(ListViewItem item, string content)
        {
            bool     result = true;
            YmlFile  file   = (YmlFile)item.Tag;
            YmlError error  = YmlFormatUtil.ValidateYml(content);

            if (error != null)
            {
                try
                {
                    if (tabControl1.SelectedIndex == 1)
                    {
                        ymlEditor.SelectionStart = error.index - 1;
                        ymlEditor.ScrollToCaret();
                        ymlEditor.Select(error.index, 0);
                        ymlEditor.Focus();
                    }
                }
                catch { }

                MessageBox.Show(this, error.msg);
                file.correct    = false;
                item.ImageIndex = 3;

                result = false;
            }
            else
            {
                if (file.status == YmlFileState.NoModif)
                {
                    item.ImageIndex = 1;
                }
                else if (file.status == YmlFileState.Modif)
                {
                    item.ImageIndex = 2;
                }
                else if (file.status == YmlFileState.NoAsync)
                {
                    item.ImageIndex = 0;
                }
            }
            return(result);
        }
 private void 编辑节点ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (_treeView.SelectedItems.Count > 0)
     {
         List <YmlItem>   lists    = YmlFormatUtil.FormatYmlToTree(resContent);
         TreeListViewItem item     = _treeView.SelectedItems[0];
         string           parentId = null;
         if (null != item.Parent)
         {
             parentId = ((YmlItem)item.Parent.Tag).Uuid;
         }
         YmlNodeForm form = new YmlNodeForm(item, lists, (ymlItem) => {
             if (null != ymlItem)
             {
                 string newParentId = ymlItem.Uuid;
                 if (newParentId != parentId)
                 {
                     TreeListViewItem parentNode = getTreeNode(_treeView.Items, newParentId);
                     if (null != parentNode)
                     {
                         if (null != item.Parent)
                         {
                             item.Parent.Items.Remove(item);
                         }
                         else
                         {
                             _treeView.Items.Remove(item);
                         }
                         parentNode.Items.Add(item);
                     }
                 }
             }
         }, 0);
         form.ShowDialog(this);
         btn_save.Enabled = true;
     }
 }
        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count > 0)
            {
                ListViewItem item = listView1.SelectedItems[0];
                foreach (ListViewItem item2 in listView1.Items)
                {
                    item2.ForeColor = Color.Black;
                }
                item.ForeColor = Color.Red;

                YmlFile file    = (YmlFile)item.Tag;
                string  path    = file.localPath + file.localName;
                string  content = YSTools.YSFile.readFileToString(path);
                if ((file.remotePath + file.remoteName) == "")
                {
                    file_label.Text = file.localPath + file.localName;
                }
                else
                {
                    file_label.Text = file.remotePath + file.remoteName;
                }

                // 渲染
                if (tabControl1.SelectedIndex == 0)
                {
                    if (resContent != content || _treeView.Items.Count == 0)
                    {
                        resContent       = content;
                        btn_save.Enabled = false;
                        btn_tree.Text    = "展开全部节点";

                        // 树形
                        _treeView.Items.Clear();
                        List <YmlItem>   lists = YmlFormatUtil.FormatYmlToTree(content);
                        TreeListViewItem viewItem = null, parentItem = null;
                        Dictionary <string, TreeListViewItem> _cache = new Dictionary <string, TreeListViewItem>();
                        foreach (YmlItem obj in lists)
                        {
                            viewItem            = new TreeListViewItem();
                            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 (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);
                        }

                        Validate(item, content);
                    }
                }
                else
                {
                    if (resContent != content || ymlEditor.Text == "")
                    {
                        // YML编辑器
                        ymlEditor.Text = "";
                        List <YmlLine> list = YmlFormatUtil.FormatYml(content);
                        foreach (YmlLine line in list)
                        {
                            ymlEditor.SelectionColor = line.Color;
                            ymlEditor.SelectionFont  = line.Font;
                            ymlEditor.AppendText(line.Text);
                        }

                        ymlEditor.ClearUndo();

                        Validate(item, content);
                    }
                }
            }
        }