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 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); } } } }