OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 namespace NativeClientVSAddIn | 5 namespace NativeClientVSAddIn |
6 { | 6 { |
7 using System; | 7 using System; |
8 | 8 |
9 using EnvDTE; | 9 using EnvDTE; |
10 using EnvDTE80; | 10 using EnvDTE80; |
11 using Extensibility; | 11 using Extensibility; |
12 using Microsoft.VisualStudio; | 12 using Microsoft.VisualStudio; |
13 using Microsoft.VisualStudio.VCProjectEngine; | 13 using Microsoft.VisualStudio.VCProjectEngine; |
14 | 14 |
15 /// <summary>The object for implementing an Add-in.</summary> | 15 /// <summary>The object for implementing an Add-in.</summary> |
16 /// <seealso class='IDTExtensibility2' /> | 16 /// <seealso class='IDTExtensibility2' /> |
17 public class Connect : IDTExtensibility2 | 17 public class Connect : IDTExtensibility2 |
18 { | 18 { |
19 /// <summary> | 19 /// <summary> |
| 20 /// The main Visual Studio interface. |
| 21 /// </summary> |
| 22 private DTE2 dte_; |
| 23 |
| 24 /// <summary> |
20 /// Receives events related to starting/stopping debugging. | 25 /// Receives events related to starting/stopping debugging. |
21 /// </summary> | 26 /// </summary> |
22 private DebuggerEvents debuggerEvents_; | 27 private DebuggerEvents debuggerEvents_; |
23 | 28 |
24 /// <summary> | 29 /// <summary> |
25 /// Receives all generic events from Visual Studio. | 30 /// Receives all generic events from Visual Studio. |
26 /// </summary> | 31 /// </summary> |
27 private CommandEvents commandEvents_; | 32 private CommandEvents commandEvents_; |
28 | 33 |
29 /// <summary> | 34 /// <summary> |
30 /// The main Visual Studio interface. | 35 /// Holds methods related to debugging. |
31 /// </summary> | 36 /// </summary> |
32 private DTE2 dte_; | 37 private PluginDebuggerBase debugger_; |
33 | 38 |
34 /// <summary> | 39 /// <summary> |
35 /// Holds methods related to running the plug-in and debugging. | 40 /// The web server launched during debugging. |
36 /// </summary> | 41 /// </summary> |
37 private PluginDebuggerHelper debuggerHelper_; | 42 private WebServer webServer_; |
| 43 |
| 44 /// <summary> |
| 45 /// Visual Studio output window pane that captures output from the web serve
r, and displays |
| 46 /// other web-server related information. |
| 47 /// </summary> |
| 48 private OutputWindowPane webServerOutputPane_; |
38 | 49 |
39 /// <summary> | 50 /// <summary> |
40 /// Implements the OnConnection method of the IDTExtensibility2 interface. | 51 /// Implements the OnConnection method of the IDTExtensibility2 interface. |
41 /// Receives notification that the Add-in is being loaded. | 52 /// Receives notification that the Add-in is being loaded. |
42 /// </summary> | 53 /// </summary> |
43 /// <param name="application">Root object of the host application.</param> | 54 /// <param name="application">Root object of the host application.</param> |
44 /// <param name="connectMode"> | 55 /// <param name="connectMode"> |
45 /// Describes how the Add-in is being loaded (e.g. command line or UI). This
is unused since | 56 /// Describes how the Add-in is being loaded (e.g. command line or UI). This
is unused since |
46 /// the add-in functions the same regardless of how it was loaded. | 57 /// the add-in functions the same regardless of how it was loaded. |
47 /// </param> | 58 /// </param> |
48 /// <param name="addInInst">Object representing this Add-in.</param> | 59 /// <param name="addInInst">Object representing this Add-in.</param> |
49 /// <param name="custom">Unused, but could contain host specific data for th
e add-in.</param> | 60 /// <param name="custom">Unused, but could contain host specific data for th
e add-in.</param> |
50 /// <seealso class='IDTExtensibility2' /> | 61 /// <seealso class='IDTExtensibility2' /> |
51 public void OnConnection( | 62 public void OnConnection( |
52 object application, | 63 object application, |
53 ext_ConnectMode connectMode, | 64 ext_ConnectMode connectMode, |
54 object addInInst, | 65 object addInInst, |
55 ref Array custom) | 66 ref Array custom) |
56 { | 67 { |
57 dte_ = (DTE2)application; | 68 dte_ = (DTE2)application; |
58 debuggerHelper_ = new PluginDebuggerHelper(dte_); | |
59 | 69 |
60 debuggerEvents_ = dte_.Events.DebuggerEvents; | 70 debuggerEvents_ = dte_.Events.DebuggerEvents; |
61 debuggerEvents_.OnEnterDesignMode += DebuggerOnEnterDesignMode; | 71 debuggerEvents_.OnEnterDesignMode += DebuggerOnEnterDesignMode; |
62 debuggerEvents_.OnEnterRunMode += DebuggerOnEnterRunMode; | 72 debuggerEvents_.OnEnterRunMode += DebuggerOnEnterRunMode; |
63 | 73 |
64 commandEvents_ = dte_.Events.CommandEvents; | 74 commandEvents_ = dte_.Events.CommandEvents; |
65 commandEvents_.AfterExecute += CommandEventsAfterExecute; | 75 commandEvents_.AfterExecute += CommandEventsAfterExecute; |
| 76 |
| 77 try |
| 78 { |
| 79 webServerOutputPane_ = dte_.ToolWindows.OutputWindow.OutputWindowPanes.I
tem( |
| 80 Strings.WebServerOutputWindowTitle); |
| 81 } |
| 82 catch (ArgumentException) |
| 83 { |
| 84 // This exception is expected if the window pane hasn't been created yet
. |
| 85 webServerOutputPane_ = dte_.ToolWindows.OutputWindow.OutputWindowPanes.A
dd( |
| 86 Strings.WebServerOutputWindowTitle); |
| 87 } |
66 } | 88 } |
67 | 89 |
68 /// <summary> | 90 /// <summary> |
69 /// Implements the OnDisconnection method of the IDTExtensibility2 | 91 /// Implements the OnDisconnection method of the IDTExtensibility2 |
70 /// interface. Receives notification that the Add-in is being unloaded. | 92 /// interface. Receives notification that the Add-in is being unloaded. |
71 /// </summary> | 93 /// </summary> |
72 /// <param name='disconnectMode'>Describes how the Add-in is being unloaded.
</param> | 94 /// <param name='disconnectMode'>Describes how the Add-in is being unloaded.
</param> |
73 /// <param name='custom'>Array of parameters that are host application speci
fic.</param> | 95 /// <param name='custom'>Array of parameters that are host application speci
fic.</param> |
74 /// <seealso class='IDTExtensibility2' /> | 96 /// <seealso class='IDTExtensibility2' /> |
75 public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array cus
tom) | 97 public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array cus
tom) |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 /// PerformPropertyFixes() performs a work around on the property pages to f
orce Visual Studio | 164 /// PerformPropertyFixes() performs a work around on the property pages to f
orce Visual Studio |
143 /// to save some specific properties into the project file to get around iss
ue 140162. | 165 /// to save some specific properties into the project file to get around iss
ue 140162. |
144 /// </summary> | 166 /// </summary> |
145 private void PerformPropertyModifications() | 167 private void PerformPropertyModifications() |
146 { | 168 { |
147 string naclAddInVersion = GetAddInVersionFromDescription(); | 169 string naclAddInVersion = GetAddInVersionFromDescription(); |
148 | 170 |
149 var configs = Utility.GetPlatformVCConfigurations(dte_, Strings.PepperPlat
formName); | 171 var configs = Utility.GetPlatformVCConfigurations(dte_, Strings.PepperPlat
formName); |
150 configs.AddRange(Utility.GetPlatformVCConfigurations(dte_, Strings.NaClPla
tformName)); | 172 configs.AddRange(Utility.GetPlatformVCConfigurations(dte_, Strings.NaClPla
tformName)); |
151 | 173 |
| 174 var properties = new PropertyManager(); |
152 foreach (VCConfiguration config in configs) | 175 foreach (VCConfiguration config in configs) |
153 { | 176 { |
154 IVCRulePropertyStorage general = config.Rules.Item("ConfigurationGeneral
"); | 177 properties.SetTarget(config); |
155 string projectVersionSetting = general.GetEvaluatedPropertyValue("NaClAd
dInVersion"); | 178 if (string.IsNullOrEmpty(properties.NaClAddInVersion)) |
156 if (string.IsNullOrEmpty(projectVersionSetting)) | |
157 { | 179 { |
158 general.SetPropertyValue("NaClAddInVersion", naclAddInVersion); | 180 // Set the NaCl add-in version so that it is stored in the project fil
e. |
| 181 properties.SetProperty("ConfigurationGeneral", "NaClAddInVersion", nac
lAddInVersion); |
| 182 |
| 183 // Expand the CHROME_PATH variable to its full path. |
| 184 string expandedChrome = properties.GetProperty( |
| 185 "WindowsLocalDebugger", "LocalDebuggerCommand"); |
| 186 properties.SetProperty("WindowsLocalDebugger", "LocalDebuggerCommand",
expandedChrome); |
159 | 187 |
160 // Work around for issue 140162. Forces some properties to save to the
project file. | 188 // Work around for issue 140162. Forces some properties to save to the
project file. |
161 PerformPropertyFixes(config); | 189 PerformPropertyFixes(config); |
162 } | 190 } |
163 } | 191 } |
164 } | 192 } |
165 | 193 |
166 /// <summary> | 194 /// <summary> |
167 /// Takes a project configuration and sets values in the project file to wor
k around some | 195 /// Takes a project configuration and sets values in the project file to wor
k around some |
168 /// problems in Visual Studio. This is a work around for issue 140162. | 196 /// problems in Visual Studio. This is a work around for issue 140162. |
169 /// </summary> | 197 /// </summary> |
170 /// <param name="config">A configuration that needs modification.</param> | 198 /// <param name="config">A configuration that needs modification.</param> |
171 private void PerformPropertyFixes(VCConfiguration config) | 199 private void PerformPropertyFixes(VCConfiguration config) |
172 { | 200 { |
173 IVCRulePropertyStorage debugger = config.Rules.Item("WindowsLocalDebugger"
); | 201 IVCRulePropertyStorage debugger = config.Rules.Item("WindowsLocalDebugger"
); |
174 string evaluatedCommand = debugger.GetEvaluatedPropertyValue("LocalDebugge
rCommand"); | |
175 debugger.SetPropertyValue("LocalDebuggerCommand", evaluatedCommand); | |
176 | |
177 string arguments = debugger.GetUnevaluatedPropertyValue("LocalDebuggerComm
andArguments"); | 202 string arguments = debugger.GetUnevaluatedPropertyValue("LocalDebuggerComm
andArguments"); |
178 debugger.SetPropertyValue("LocalDebuggerCommandArguments", arguments); | 203 debugger.SetPropertyValue("LocalDebuggerCommandArguments", arguments); |
179 } | 204 } |
180 | 205 |
181 /// <summary> | 206 /// <summary> |
182 /// During the build process we dynamically put the add-in version number in
to the add-in | 207 /// During the build process we dynamically put the add-in version number in
to the add-in |
183 /// description. This function extracts that version number. | 208 /// description. This function extracts that version number. |
184 /// </summary> | 209 /// </summary> |
185 /// <returns>The add-in version number.</returns> | 210 /// <returns>The add-in version number.</returns> |
186 private string GetAddInVersionFromDescription() | 211 private string GetAddInVersionFromDescription() |
(...skipping 12 matching lines...) Expand all Loading... |
199 break; | 224 break; |
200 } | 225 } |
201 } | 226 } |
202 } | 227 } |
203 | 228 |
204 return naclAddinVersion; | 229 return naclAddinVersion; |
205 } | 230 } |
206 | 231 |
207 /// <summary> | 232 /// <summary> |
208 /// Called when Visual Studio ends a debugging session. | 233 /// Called when Visual Studio ends a debugging session. |
| 234 /// Shuts down the web server and debugger. |
209 /// </summary> | 235 /// </summary> |
210 /// <param name="reason">The parameter is not used.</param> | 236 /// <param name="reason">The parameter is not used.</param> |
211 private void DebuggerOnEnterDesignMode(dbgEventReason reason) | 237 private void DebuggerOnEnterDesignMode(dbgEventReason reason) |
212 { | 238 { |
213 debuggerHelper_.StopDebugging(); | 239 if (debugger_ != null) |
| 240 { |
| 241 debugger_.Dispose(); |
| 242 debugger_ = null; |
| 243 } |
| 244 |
| 245 if (webServer_ != null) |
| 246 { |
| 247 webServer_.Dispose(); |
| 248 webServer_ = null; |
| 249 } |
214 } | 250 } |
215 | 251 |
216 /// <summary> | 252 /// <summary> |
217 /// Called when Visual Studio starts a debugging session. | 253 /// Called when Visual Studio starts a debugging session. |
| 254 /// Here we kick off the debugger and web server if appropriate. |
218 /// </summary> | 255 /// </summary> |
219 /// <param name="reason">Indicates how we are entering run mode (breakpoint
or launch).</param> | 256 /// <param name="reason">Indicates how we are entering run mode (breakpoint
or launch).</param> |
220 private void DebuggerOnEnterRunMode(dbgEventReason reason) | 257 private void DebuggerOnEnterRunMode(dbgEventReason reason) |
221 { | 258 { |
222 // If we are starting debugging (not re-entering from a breakpoint) | 259 // If we are starting debugging (not re-entering from a breakpoint) |
223 // then load project settings and start the debugger-helper. | 260 // then load project settings and start the debugger-helper. |
224 if (reason == dbgEventReason.dbgEventReasonLaunchProgram && | 261 if (reason == dbgEventReason.dbgEventReasonLaunchProgram) |
225 debuggerHelper_.LoadProjectSettings()) | |
226 { | 262 { |
227 debuggerHelper_.StartDebugging(); | 263 PropertyManager properties = new PropertyManager(); |
| 264 properties.SetTargetToActive(dte_); |
| 265 if (properties.ProjectPlatform == PropertyManager.ProjectPlatformType.Na
Cl) |
| 266 { |
| 267 debugger_ = new PluginDebuggerGDB(dte_, properties); |
| 268 webServer_ = new WebServer(webServerOutputPane_, properties); |
| 269 } |
| 270 else if (properties.ProjectPlatform == PropertyManager.ProjectPlatformTy
pe.Pepper) |
| 271 { |
| 272 debugger_ = new PluginDebuggerVS(dte_, properties); |
| 273 webServer_ = new WebServer(webServerOutputPane_, properties); |
| 274 } |
228 } | 275 } |
229 } | 276 } |
230 } | 277 } |
231 } | 278 } |
OLD | NEW |