Sfall-ScriptEditor

Форк
0
/
PreviewRename.cs 
107 строк · 3.8 Кб
1
using ScriptEditor.TextEditorUtilities;
2
using System;
3
using System.Collections.Generic;
4
using System.Linq;
5
using System.Text.RegularExpressions;
6
using System.Windows.Forms;
7

8
namespace ScriptEditor
9
{
10
    public partial class PreviewRename : Form
11
    {
12
        public PreviewRename(string oldName, string newName)
13
        {
14
            InitializeComponent();
15

16
            this.Text += String.Format(" {0} to {1}", oldName, newName);
17

18
            button1.DialogResult = System.Windows.Forms.DialogResult.OK;
19
            button2.DialogResult = System.Windows.Forms.DialogResult.Cancel;
20
        }
21

22
        private int BuildSub(Dictionary<string, List<Refactor.PreviewMatch>> matchesList, int root)
23
        {
24
            int totalMatches = 0;
25
            foreach (var matches in matchesList)
26
            {
27
                treeView1.Nodes[root].Nodes.Add((root == 0) ? matches.Value[0].tab.filename : matches.Key);
28
                int c = treeView1.Nodes[root].Nodes.Count - 1;
29
                treeView1.Nodes[root].Nodes[c].Checked = true;
30
                int s = 0;
31
                foreach (var match in matches.Value)
32
                {
33
                    treeView1.Nodes[root].Nodes[c].Nodes.Add(match.previewText);
34
                    treeView1.Nodes[root].Nodes[c].Nodes[s].Tag = match;
35
                    treeView1.Nodes[root].Nodes[c].Nodes[s++].Checked = true;
36
                    totalMatches++;
37
                }
38
            }
39
            return totalMatches;
40
        }
41

42
        internal void BuildTreeMatches(Dictionary<string, List<Refactor.PreviewMatch>> tabs,
43
                                       Dictionary<string, List<Refactor.PreviewMatch>> files)
44
        {
45
            treeView1.Nodes.Add("Curren open scripts");
46
            treeView1.Nodes[0].Checked = true;
47
            int totalMatches = BuildSub(tabs, 0);
48

49
            treeView1.Nodes.Add("Files in project folder");
50
            treeView1.Nodes[1].Checked = true;
51
            totalMatches += BuildSub(files, 1);
52

53
            treeView1.Nodes[0].Expand();
54
            treeView1.Nodes[1].Expand();
55

56
            label1.Text = String.Format("Matches found: {0}, in {1} files.", totalMatches, tabs.Count() + files.Count());
57
        }
58

59
        internal void GetSelectedMatches(ref Dictionary<string, List<Refactor.PreviewMatch>> tabs,
60
                                         ref Dictionary<string, List<Refactor.PreviewMatch>> files)
61
        {
62
            GetMatches(treeView1.Nodes[0].Nodes, ref tabs);
63
            GetMatches(treeView1.Nodes[1].Nodes, ref files);
64
        }
65

66
        private List<Refactor.PreviewMatch> GetMatchesSub(TreeNode nodes)
67
        {
68
            List<Refactor.PreviewMatch> list = new List<Refactor.PreviewMatch>();
69
            foreach (TreeNode node in nodes.Nodes)
70
            {
71
                if (!node.Checked) continue;
72
                list.Add((Refactor.PreviewMatch)node.Tag);
73
            }
74
            return list;
75
        }
76

77
        private void GetMatches(TreeNodeCollection nodes, ref Dictionary<string, List<Refactor.PreviewMatch>> list)
78
        {
79
            foreach (TreeNode node in nodes)
80
            {
81
                if (!node.Checked) continue;
82
                list.Add(node.Text, GetMatchesSub(node));
83
            }
84
        }
85

86
        private void SetChildCheck(TreeNodeCollection nodes, bool state)
87
        {
88
            foreach (TreeNode node in nodes)
89
            {
90
                node.Checked = state;
91
                if (node.Nodes.Count != 0) SetChildCheck(node.Nodes, state);
92
            }
93
        }
94

95
        private void button_Click(object sender, EventArgs e)
96
        {
97
            this.Close();
98
        }
99

100
        private void treeView1_AfterCheck(object sender, TreeViewEventArgs e)
101
        {
102
            if (this.Visible && e.Action != TreeViewAction.Unknown) {
103
                SetChildCheck(e.Node.Nodes, e.Node.Checked);
104
            }
105
        }
106
    }
107
}
108

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.