77using System ;
88using System . Collections . Generic ;
99using System . ComponentModel . Design ;
10- using System . Globalization ;
1110using System . IO ;
1211using System . Windows ;
13- using System . Windows . Forms ;
1412using EncodingNormalizerVsx . View ;
1513using EnvDTE ;
1614using Microsoft . VisualStudio . Shell ;
17- using Microsoft . VisualStudio . Shell . Interop ;
18- using MessageBox = System . Windows . MessageBox ;
15+ using Window = System . Windows . Window ;
1916
2017namespace EncodingNormalizerVsx
2118{
2219 /// <summary>
23- /// Command handler
20+ /// Command handler
2421 /// </summary>
2522 internal sealed class EncodingNormalizer
2623 {
2724 /// <summary>
28- /// Command ID.
25+ /// Command ID.
2926 /// </summary>
3027 public const int CommandId = 0x0100 ;
3128
3229 /// <summary>
33- /// Command menu group (command set GUID).
30+ /// Command menu group (command set GUID).
3431 /// </summary>
3532 public static readonly Guid CommandSet = new Guid ( "0640f5ce-e6bc-43ba-b45e-497d70819a20" ) ;
3633
3734 /// <summary>
38- /// VS Package that provides this command, not null.
35+ /// VS Package that provides this command, not null.
3936 /// </summary>
4037 private readonly Package package ;
4138
39+ private Window _conformWindow ;
40+ private Window _definitionWindow ;
41+
4242 /// <summary>
43- /// Initializes a new instance of the <see cref="EncodingNormalizer"/> class.
44- /// Adds our command handlers for menu (commands must exist in the command table file)
43+ /// Initializes a new instance of the <see cref="EncodingNormalizer" /> class.
44+ /// Adds our command handlers for menu (commands must exist in the command table file)
4545 /// </summary>
4646 /// <param name="package">Owner package, not null.</param>
4747 private EncodingNormalizer ( Package package )
4848 {
4949 if ( package == null )
50- {
5150 throw new ArgumentNullException ( "package" ) ;
52- }
5351
5452 this . package = package ;
5553
56- OleMenuCommandService commandService = this . ServiceProvider . GetService ( typeof ( IMenuCommandService ) ) as OleMenuCommandService ;
54+ var commandService = ServiceProvider . GetService ( typeof ( IMenuCommandService ) ) as OleMenuCommandService ;
5755 if ( commandService != null )
5856 {
5957 var menuCommandID = new CommandID ( CommandSet , CommandId ) ;
60- var menuItem = new MenuCommand ( this . EncodingNormalizerCallback , menuCommandID ) ;
58+ var menuItem = new MenuCommand ( EncodingNormalizerCallback , menuCommandID ) ;
6159 commandService . AddCommand ( menuItem ) ;
6260
6361 menuCommandID = new CommandID ( CommandSet , 0x0101 ) ;
64- menuItem = new MenuCommand ( this . MenuItemCallback , menuCommandID ) ;
62+ menuItem = new MenuCommand ( MenuItemCallback , menuCommandID ) ;
6563 commandService . AddCommand ( menuItem ) ;
6664 }
6765 }
6866
69- private System . Windows . Window _conformWindow ;
70- private System . Windows . Window _definitionWindow ;
67+ //private void ReadAccount()
68+ //{
69+ // var folder = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) +
70+ // "\\EncodingNormalizer\\";
71+ // var file = folder+ "Account.json";
72+ // if (!Directory.Exists(folder))
73+ // {
74+ // Directory.CreateDirectory(folder);
75+ // }
76+
77+ // using (StreamWriter stream = File.CreateText(file))
78+ // {
79+ // stream.Write("EncodingNormalizer");
80+ // }
81+
82+ // using (StreamReader stream=File.OpenText(file))
83+ // {
84+ // string str = stream.ReadToEnd();
85+ // }
86+ //}
87+
88+ /// <summary>
89+ /// Gets the instance of the command.
90+ /// </summary>
91+ public static EncodingNormalizer Instance { get ; private set ; }
92+
93+ /// <summary>
94+ /// Gets the service provider from the owner package.
95+ /// </summary>
96+ private IServiceProvider ServiceProvider
97+ {
98+ get { return package ; }
99+ }
71100
72101 private void EncodingNormalizerCallback ( object sender , EventArgs e )
73102 {
74- DTE dte = ( DTE ) ServiceProvider . GetService ( typeof ( DTE ) ) ;
103+ var dte = ( DTE ) ServiceProvider . GetService ( typeof ( DTE ) ) ;
75104 var file = dte . Solution . FullName ;
76- List < string > project = new List < string > ( ) ;
77- int noLoadProjectCount = 0 ;
105+ var project = new List < string > ( ) ;
106+ var noLoadProjectCount = 0 ;
78107 //if (string.IsNullOrEmpty(file))
79108 {
80109 if ( dte . Solution . Projects . Count > 0 )
@@ -84,30 +113,25 @@ private void EncodingNormalizerCallback(object sender, EventArgs e)
84113 try
85114 {
86115 foreach ( var temp in dte . Solution . Projects )
87- {
88116 try
89117 {
90- file = ( ( Project ) temp ) . FileName ;
118+ file = ( ( Project ) temp ) . FileName ;
91119 if ( file . EndsWith ( ".csproj" ) )
92120 {
93-
94121 }
95- file = ( ( Project ) temp ) . FullName ;
122+ file = ( ( Project ) temp ) . FullName ;
96123
97124 if ( ! string . IsNullOrEmpty ( file ) )
98- {
99125 project . Add ( new FileInfo ( file ) . Directory ? . FullName ) ;
100- }
101126 }
102127 catch ( NotImplementedException )
103128 {
104129 noLoadProjectCount ++ ;
105130 }
106- }
107131 }
108132 catch ( NotImplementedException )
109133 {
110- System . Windows . MessageBox . Show ( "The project not loaded." , "项目还没有加载完成" ) ;
134+ MessageBox . Show ( "The project not loaded." , "项目还没有加载完成" ) ;
111135 return ;
112136 }
113137 if ( noLoadProjectCount > 0 )
@@ -140,9 +164,6 @@ private void EncodingNormalizerCallback(object sender, EventArgs e)
140164 //MessageBox.Show(AppDomain.CurrentDomain.BaseDirectory, "路径");
141165 //string str = EncodingNormalizerPackage.DefinitionPage().CriterionEncoding.ToString();
142166 // MessageBox.Show(str, "路径");
143-
144-
145-
146167 }
147168
148169 private void ConformWindow ( string file , List < string > project )
@@ -156,72 +177,26 @@ private void ConformWindow(string file, List<string> project)
156177
157178 var folder = "" ;
158179 if ( ! string . IsNullOrEmpty ( file ) )
159- {
160180 folder = new FileInfo ( file ) . Directory ? . FullName ;
161- }
162- System . Windows . Window window = new System . Windows . Window ( ) ;
163- ConformPage conformPage = new ConformPage ( ) ;
181+ var window = new Window ( ) ;
182+ var conformPage = new ConformPage ( ) ;
164183 window . Content = conformPage ;
165184 window . Title = "编码规范工具" ;
166185 conformPage . Closing += ( _s , _e ) =>
167186 {
168187 window . Close ( ) ;
169188 _conformWindow = null ;
170189 } ;
171- window . Closed += ( _s , _e ) =>
172- {
173- _conformWindow = null ;
174- } ;
190+ window . Closed += ( _s , _e ) => { _conformWindow = null ; } ;
175191 conformPage . SolutionFolder = folder ;
176192 conformPage . Project = project ;
177193 window . Show ( ) ;
178194 conformPage . InspectFolderEncoding ( ) ;
179195 _conformWindow = window ;
180196 }
181197
182- //private void ReadAccount()
183- //{
184- // var folder = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) +
185- // "\\EncodingNormalizer\\";
186- // var file = folder+ "Account.json";
187- // if (!Directory.Exists(folder))
188- // {
189- // Directory.CreateDirectory(folder);
190- // }
191-
192- // using (StreamWriter stream = File.CreateText(file))
193- // {
194- // stream.Write("EncodingNormalizer");
195- // }
196-
197- // using (StreamReader stream=File.OpenText(file))
198- // {
199- // string str = stream.ReadToEnd();
200- // }
201- //}
202-
203- /// <summary>
204- /// Gets the instance of the command.
205- /// </summary>
206- public static EncodingNormalizer Instance
207- {
208- get ;
209- private set ;
210- }
211-
212- /// <summary>
213- /// Gets the service provider from the owner package.
214- /// </summary>
215- private IServiceProvider ServiceProvider
216- {
217- get
218- {
219- return this . package ;
220- }
221- }
222-
223198 /// <summary>
224- /// Initializes the singleton instance of the command.
199+ /// Initializes the singleton instance of the command.
225200 /// </summary>
226201 /// <param name="package">Owner package, not null.</param>
227202 public static void Initialize ( Package package )
@@ -230,9 +205,9 @@ public static void Initialize(Package package)
230205 }
231206
232207 /// <summary>
233- /// This function is the callback used to execute the command when the menu item is clicked.
234- /// See the constructor to see how the menu item is associated with this function using
235- /// OleMenuCommandService service and MenuCommand class.
208+ /// This function is the callback used to execute the command when the menu item is clicked.
209+ /// See the constructor to see how the menu item is associated with this function using
210+ /// OleMenuCommandService service and MenuCommand class.
236211 /// </summary>
237212 /// <param name="sender">Event sender.</param>
238213 /// <param name="e">Event args.</param>
@@ -244,17 +219,14 @@ private void MenuItemCallback(object sender, EventArgs e)
244219 _definitionWindow . Show ( ) ;
245220 return ;
246221 }
247- System . Windows . Window window = new System . Windows . Window ( ) ;
248- View . DefinitionPage definitionPage = new DefinitionPage ( ) ;
222+ var window = new Window ( ) ;
223+ var definitionPage = new DefinitionPage ( ) ;
249224 definitionPage . Closing += ( _s , _e ) =>
250225 {
251226 window . Close ( ) ;
252227 _definitionWindow = null ;
253228 } ;
254- window . Closed += ( _s , _e ) =>
255- {
256- _definitionWindow = null ;
257- } ;
229+ window . Closed += ( _s , _e ) => { _definitionWindow = null ; } ;
258230 window . Title = "编码规范工具设置" ;
259231 window . Content = definitionPage ;
260232 window . Show ( ) ;
@@ -273,4 +245,4 @@ private void MenuItemCallback(object sender, EventArgs e)
273245 // OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
274246 }
275247 }
276- }
248+ }
0 commit comments