-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrmAllFileList.cs
More file actions
172 lines (149 loc) · 5.9 KB
/
frmAllFileList.cs
File metadata and controls
172 lines (149 loc) · 5.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace RangeOfInfluenceDetection
{
public partial class frmAllFileList : Form
{
#region 宣言
// 影響範囲情報
#endregion
/// <summary>
/// メイン画面から呼ばれる際のコンストラクタ
/// </summary>リストボックスに表示されする文言リスト
public frmAllFileList ()
{
InitializeComponent();
// MarkInfoの初期化
Program.SourceList.ForEach(x => x.MarkInfos.Clear());
foreach (SourceInfo info in Program.SourceList)
{
// コードを読み込む
using (StreamReader reader = new StreamReader(Path.Combine(AppInfomation.SearchDirectory,
info.fileName)))
{
info.codeBefore = reader.ReadToEnd();
}
// ツリーとルートノードを取得する
info.treeBefore = CSharpSyntaxTree.ParseText(info.codeBefore);
info.rootBefore = info.treeBefore.GetCompilationUnitRoot();
info.methodBefore.Visit(info.rootBefore);
// リストアイテムに追加する
lstResult.Items.Add(info.fileName);
}
btnCodeDisplay.Enabled = false;
}
private void btnSln_Click(object sender, EventArgs e)
{
AppInfomation.PathSelectForm.Visible = true;
this.Close();
}
/// <summary>
/// コードを表示をクリック
/// </summary>
private void btnCodeDisplay_Click(object sender, EventArgs e)
{
// 選択されているファイルを文字列として読み取る
string selected = lstResult.SelectedItem.ToString().TrimStart(' ','★');
SourceInfo info = Program.SourceList.Find(x => x.fileName == selected);
Source source = new Source(info);
source.Show();
this.Visible = false;
}
/// <summary>
/// 影響範囲があるリストアイテムをマーク
/// </summary>
public void RefreshItem()
{
lstResult.Items.Clear();
// 影響範囲だったソースファイルはリストボックスに表示する際、目印を付ける
foreach (SourceInfo info in Program.SourceList)
{
if (info.codeChange)
{
// ディクショナリーに登録されている場合は目印を付けてリストに登録する
lstResult.Items.Add("★ " + info.fileName);
}
else
{
lstResult.Items.Add(" " + info.fileName);
}
}
}
// RUNしているタスクを終了する
private void frmAllFileList_FormClosing(object sender, FormClosingEventArgs e)
{
System.Diagnostics.StackFrame caller = new System.Diagnostics.StackFrame(1);
// TODO: ×やボタンで閉じたときの制御を見る
if (caller.GetMethod().ReflectedType.Name != this.GetType().FullName)
AppInfomation.PathSelectForm.Close();
}
/// <summary>
/// 表示時イベント
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void frmAllFileList_Shown(object sender, EventArgs e)
{
// 自身をAppInfoに追加
AppInfomation.ListForm = this;
}
/// <summary>
/// 変更をリセットする
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnReset_Click(object sender, EventArgs e)
{
// MarkInfoの初期化
Program.SourceList.ForEach(x => x.MarkInfos.Clear());
// ファイルの読み直し
foreach (SourceInfo info in Program.SourceList)
{
// コードを読み込む
using (StreamReader reader = new StreamReader(Path.Combine(AppInfomation.SearchDirectory,
info.fileName)))
{
info.codeBefore = reader.ReadToEnd();
}
info.codeChange = false;
// ツリーとルートノードを取得する
info.treeBefore = CSharpSyntaxTree.ParseText(info.codeBefore);
info.rootBefore = info.treeBefore.GetCompilationUnitRoot();
info.methodBefore = new Roslyn.MethodCollector();
info.methodBefore.Visit(info.rootBefore);
// 変更後情報(After)をリセットする
info.codeAfter = null;
info.treeAfter = null;
info.rootAfter = null;
info.methodAfter = new Roslyn.MethodCollector();
}
// ★をリセットする
RefreshItem();
}
/// <summary>
/// グリッドの選択アイテム変更イベント
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void lstResult_SelectedIndexChanged(object sender, EventArgs e)
{
if (lstResult.SelectedIndex != -1)
// アイテムが選択されている場合
btnCodeDisplay.Enabled = true;
else
btnCodeDisplay.Enabled = false;
}
}
}