Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Side by Side Diff: visual_studio/NativeClientVSAddIn/NativeClientVSAddIn/Connect.cs

Issue 10830151: VS Add-in more properties and improvements (Closed) Base URL: https://nativeclient-sdk.googlecode.com/svn/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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;
13 using Microsoft.VisualStudio.VCProjectEngine;
12 14
13 /// <summary>The object for implementing an Add-in.</summary> 15 /// <summary>The object for implementing an Add-in.</summary>
14 /// <seealso class='IDTExtensibility2' /> 16 /// <seealso class='IDTExtensibility2' />
15 public class Connect : IDTExtensibility2 17 public class Connect : IDTExtensibility2
16 { 18 {
17 /// <summary> 19 /// <summary>
18 /// Receives events related to starting/stopping debugging. 20 /// Receives events related to starting/stopping debugging.
19 /// </summary> 21 /// </summary>
20 private DebuggerEvents debuggerEvents_; 22 private DebuggerEvents debuggerEvents_;
21 23
22 /// <summary> 24 /// <summary>
25 /// Receives all generic events from Visual Studio.
26 /// </summary>
27 private CommandEvents commandEvents_;
28
29 /// <summary>
30 /// The main Visual Studio interface.
31 /// </summary>
32 private DTE2 dte_;
33
34 /// <summary>
23 /// Holds methods related to running the plug-in and debugging. 35 /// Holds methods related to running the plug-in and debugging.
24 /// </summary> 36 /// </summary>
25 private PluginDebuggerHelper debuggerHelper_; 37 private PluginDebuggerHelper debuggerHelper_;
26 38
27 /// <summary> 39 /// <summary>
28 /// Implements the OnConnection method of the IDTExtensibility2 interface. 40 /// Implements the OnConnection method of the IDTExtensibility2 interface.
29 /// Receives notification that the Add-in is being loaded. 41 /// Receives notification that the Add-in is being loaded.
30 /// </summary> 42 /// </summary>
31 /// <param name="application">Root object of the host application.</param> 43 /// <param name="application">Root object of the host application.</param>
32 /// <param name="connectMode"> 44 /// <param name="connectMode">
33 /// Describes how the Add-in is being loaded (e.g. command line or UI). This is unused since 45 /// Describes how the Add-in is being loaded (e.g. command line or UI). This is unused since
34 /// the add-in functions the same regardless of how it was loaded. 46 /// the add-in functions the same regardless of how it was loaded.
35 /// </param> 47 /// </param>
36 /// <param name="addInInst">Object representing this Add-in.</param> 48 /// <param name="addInInst">Object representing this Add-in.</param>
37 /// <param name="custom">Unused, but could contain host specific data for th e add-in.</param> 49 /// <param name="custom">Unused, but could contain host specific data for th e add-in.</param>
38 /// <seealso class='IDTExtensibility2' /> 50 /// <seealso class='IDTExtensibility2' />
39 public void OnConnection( 51 public void OnConnection(
40 object application, 52 object application,
41 ext_ConnectMode connectMode, 53 ext_ConnectMode connectMode,
42 object addInInst, 54 object addInInst,
43 ref Array custom) 55 ref Array custom)
44 { 56 {
45 DTE2 dte = (DTE2)application; 57 dte_ = (DTE2)application;
46 debuggerHelper_ = new PluginDebuggerHelper(dte); 58 debuggerHelper_ = new PluginDebuggerHelper(dte_);
47 59
48 debuggerEvents_ = dte.Events.DebuggerEvents; 60 debuggerEvents_ = dte_.Events.DebuggerEvents;
49 debuggerEvents_.OnEnterDesignMode += DebuggerOnEnterDesignMode; 61 debuggerEvents_.OnEnterDesignMode += DebuggerOnEnterDesignMode;
50 debuggerEvents_.OnEnterRunMode += DebuggerOnEnterRunMode; 62 debuggerEvents_.OnEnterRunMode += DebuggerOnEnterRunMode;
63
64 commandEvents_ = dte_.Events.CommandEvents;
65 commandEvents_.AfterExecute += CommandEventsAfterExecute;
51 } 66 }
52 67
53 /// <summary> 68 /// <summary>
54 /// Called when Visual Studio ends a debugging session.
55 /// </summary>
56 /// <param name="reason">The parameter is not used.</param>
57 public void DebuggerOnEnterDesignMode(dbgEventReason reason)
58 {
59 debuggerHelper_.StopDebugging();
60 }
61
62 /// <summary>
63 /// Called when Visual Studio starts a debugging session.
64 /// </summary>
65 /// <param name="reason">Indicates how we are entering run mode (breakpoint or launch).</param>
66 public void DebuggerOnEnterRunMode(dbgEventReason reason)
67 {
68 // If we are starting debugging (not re-entering from a breakpoint)
69 // then load project settings and start the debugger-helper.
70 if (reason == dbgEventReason.dbgEventReasonLaunchProgram &&
71 debuggerHelper_.LoadProjectSettings())
72 {
73 debuggerHelper_.StartDebugging();
74 }
75 }
76
77 /// <summary>
78 /// Implements the OnDisconnection method of the IDTExtensibility2 69 /// Implements the OnDisconnection method of the IDTExtensibility2
79 /// interface. Receives notification that the Add-in is being unloaded. 70 /// interface. Receives notification that the Add-in is being unloaded.
80 /// </summary> 71 /// </summary>
81 /// <param name='disconnectMode'>Describes how the Add-in is being unloaded. </param> 72 /// <param name='disconnectMode'>Describes how the Add-in is being unloaded. </param>
82 /// <param name='custom'>Array of parameters that are host application speci fic.</param> 73 /// <param name='custom'>Array of parameters that are host application speci fic.</param>
83 /// <seealso class='IDTExtensibility2' /> 74 /// <seealso class='IDTExtensibility2' />
84 public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array cus tom) 75 public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array cus tom)
85 { 76 {
86 } 77 }
87 78
(...skipping 19 matching lines...) Expand all
107 98
108 /// <summary> 99 /// <summary>
109 /// Implements the OnBeginShutdown method of the IDTExtensibility2 interface . 100 /// Implements the OnBeginShutdown method of the IDTExtensibility2 interface .
110 /// Receives notification that the host application is being unloaded. 101 /// Receives notification that the host application is being unloaded.
111 /// </summary> 102 /// </summary>
112 /// <param name='custom'>Array of parameters that are host application speci fic.</param> 103 /// <param name='custom'>Array of parameters that are host application speci fic.</param>
113 /// <seealso class='IDTExtensibility2' /> 104 /// <seealso class='IDTExtensibility2' />
114 public void OnBeginShutdown(ref Array custom) 105 public void OnBeginShutdown(ref Array custom)
115 { 106 {
116 } 107 }
108
109 /// <summary>
110 /// Receives notification after any generic VS command has executed.
111 /// Here we capture the SolutionPlatform event which indicates the solution platform has
112 /// changed. We use this event to trigger a modification of property settin gs since this
113 /// event happens immediately after the platforms are added. See PerformProp ertyModifications()
114 /// for what sort of modifications we are doing.
115 /// </summary>
116 /// <param name="guid">Guid of the command grouping.</param>
117 /// <param name="id">ID of the command within its grouping.</param>
118 /// <param name="customIn">Command specific input.</param>
119 /// <param name="customOut">Command specific parameter.</param>
120 private void CommandEventsAfterExecute(string guid, int id, object customIn, object customOut)
121 {
122 const string VSStd2KCmdIDEnumGuid = "{1496A755-94DE-11D0-8C3F-00C04FC2AAE2 }";
123 if (guid.Equals(VSStd2KCmdIDEnumGuid, StringComparison.OrdinalIgnoreCase))
124 {
125 // If loading a NaCl or Pepper platform, perform property modifications.
126 if (id == (int)VSConstants.VSStd2KCmdID.SolutionPlatform)
127 {
128 string platform = customOut as string;
129 if (Strings.NaClPlatformName.Equals(platform) ||
130 Strings.PepperPlatformName.Equals(platform))
131 {
132 PerformPropertyModifications();
133 }
134 }
135 }
136 }
137
138 /// <summary>
139 /// Goes through all projects in the solution and updates their properties w ith necessary
140 /// modifications if they are NaCl or Pepper configurations. We add the vers ion information
141 /// here so that the version is stored directly in the project file. The cal l to
142 /// 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.
144 /// </summary>
145 private void PerformPropertyModifications()
146 {
147 string naclAddInVersion = GetAddInVersionFromDescription();
148
149 var configs = Utility.GetPlatformVCConfigurations(dte_, Strings.PepperPlat formName);
150 configs.AddRange(Utility.GetPlatformVCConfigurations(dte_, Strings.NaClPla tformName));
151
152 foreach (VCConfiguration config in configs)
153 {
154 IVCRulePropertyStorage general = config.Rules.Item("ConfigurationGeneral ");
155 string projectVersionSetting = general.GetEvaluatedPropertyValue("NaClAd dInVersion");
156 if (string.IsNullOrEmpty(projectVersionSetting))
157 {
158 general.SetPropertyValue("NaClAddInVersion", naclAddInVersion);
159
160 // Work around for issue 140162. Forces some properties to save to the project file.
161 PerformPropertyFixes(config);
162 }
163 }
164 }
165
166 /// <summary>
167 /// 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.
169 /// </summary>
170 /// <param name="config">A configuration that needs modification.</param>
171 private void PerformPropertyFixes(VCConfiguration config)
172 {
173 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");
178 debugger.SetPropertyValue("LocalDebuggerCommandArguments", arguments);
179 }
180
181 /// <summary>
182 /// 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.
184 /// </summary>
185 /// <returns>The add-in version number.</returns>
186 private string GetAddInVersionFromDescription()
187 {
188 string naclAddinVersion = "missing";
189 foreach (AddIn addin in dte_.AddIns)
190 {
191 if (addin.Name.Equals(Strings.AddInName))
192 {
193 string identifier = "Version: [";
194 int start = addin.Description.IndexOf(identifier) + identifier.Length;
195 int end = addin.Description.LastIndexOf(']');
196 if (start >= 0 && end >= 0)
197 {
198 naclAddinVersion = addin.Description.Substring(start, end - start);
199 break;
200 }
201 }
202 }
203
204 return naclAddinVersion;
205 }
206
207 /// <summary>
208 /// Called when Visual Studio ends a debugging session.
209 /// </summary>
210 /// <param name="reason">The parameter is not used.</param>
211 private void DebuggerOnEnterDesignMode(dbgEventReason reason)
212 {
213 debuggerHelper_.StopDebugging();
214 }
215
216 /// <summary>
217 /// Called when Visual Studio starts a debugging session.
218 /// </summary>
219 /// <param name="reason">Indicates how we are entering run mode (breakpoint or launch).</param>
220 private void DebuggerOnEnterRunMode(dbgEventReason reason)
221 {
222 // If we are starting debugging (not re-entering from a breakpoint)
223 // then load project settings and start the debugger-helper.
224 if (reason == dbgEventReason.dbgEventReasonLaunchProgram &&
225 debuggerHelper_.LoadProjectSettings())
226 {
227 debuggerHelper_.StartDebugging();
228 }
229 }
117 } 230 }
118 } 231 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698