Sfall-ScriptEditor
107 строк · 3.8 Кб
1using ScriptEditor.TextEditorUtilities;2using System;3using System.Collections.Generic;4using System.Linq;5using System.Text.RegularExpressions;6using System.Windows.Forms;7
8namespace ScriptEditor9{
10public partial class PreviewRename : Form11{12public PreviewRename(string oldName, string newName)13{14InitializeComponent();15
16this.Text += String.Format(" {0} to {1}", oldName, newName);17
18button1.DialogResult = System.Windows.Forms.DialogResult.OK;19button2.DialogResult = System.Windows.Forms.DialogResult.Cancel;20}21
22private int BuildSub(Dictionary<string, List<Refactor.PreviewMatch>> matchesList, int root)23{24int totalMatches = 0;25foreach (var matches in matchesList)26{27treeView1.Nodes[root].Nodes.Add((root == 0) ? matches.Value[0].tab.filename : matches.Key);28int c = treeView1.Nodes[root].Nodes.Count - 1;29treeView1.Nodes[root].Nodes[c].Checked = true;30int s = 0;31foreach (var match in matches.Value)32{33treeView1.Nodes[root].Nodes[c].Nodes.Add(match.previewText);34treeView1.Nodes[root].Nodes[c].Nodes[s].Tag = match;35treeView1.Nodes[root].Nodes[c].Nodes[s++].Checked = true;36totalMatches++;37}38}39return totalMatches;40}41
42internal void BuildTreeMatches(Dictionary<string, List<Refactor.PreviewMatch>> tabs,43Dictionary<string, List<Refactor.PreviewMatch>> files)44{45treeView1.Nodes.Add("Curren open scripts");46treeView1.Nodes[0].Checked = true;47int totalMatches = BuildSub(tabs, 0);48
49treeView1.Nodes.Add("Files in project folder");50treeView1.Nodes[1].Checked = true;51totalMatches += BuildSub(files, 1);52
53treeView1.Nodes[0].Expand();54treeView1.Nodes[1].Expand();55
56label1.Text = String.Format("Matches found: {0}, in {1} files.", totalMatches, tabs.Count() + files.Count());57}58
59internal void GetSelectedMatches(ref Dictionary<string, List<Refactor.PreviewMatch>> tabs,60ref Dictionary<string, List<Refactor.PreviewMatch>> files)61{62GetMatches(treeView1.Nodes[0].Nodes, ref tabs);63GetMatches(treeView1.Nodes[1].Nodes, ref files);64}65
66private List<Refactor.PreviewMatch> GetMatchesSub(TreeNode nodes)67{68List<Refactor.PreviewMatch> list = new List<Refactor.PreviewMatch>();69foreach (TreeNode node in nodes.Nodes)70{71if (!node.Checked) continue;72list.Add((Refactor.PreviewMatch)node.Tag);73}74return list;75}76
77private void GetMatches(TreeNodeCollection nodes, ref Dictionary<string, List<Refactor.PreviewMatch>> list)78{79foreach (TreeNode node in nodes)80{81if (!node.Checked) continue;82list.Add(node.Text, GetMatchesSub(node));83}84}85
86private void SetChildCheck(TreeNodeCollection nodes, bool state)87{88foreach (TreeNode node in nodes)89{90node.Checked = state;91if (node.Nodes.Count != 0) SetChildCheck(node.Nodes, state);92}93}94
95private void button_Click(object sender, EventArgs e)96{97this.Close();98}99
100private void treeView1_AfterCheck(object sender, TreeViewEventArgs e)101{102if (this.Visible && e.Action != TreeViewAction.Unknown) {103SetChildCheck(e.Node.Nodes, e.Node.Checked);104}105}106}107}
108