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

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.
noelallen1 2012/08/04 01:18:34 Could you explain why you are doing this in the co
tysand 2012/08/04 02:07:34 Done.
111 /// </summary>
112 /// <param name="guid">Guid of the command grouping.</param>
113 /// <param name="id">ID of the command within its grouping.</param>
114 /// <param name="customIn">Command specific input.</param>
115 /// <param name="customOut">Command specific parameter.</param>
116 private void CommandEventsAfterExecute(string guid, int id, object customIn, object customOut)
117 {
118 const string VSStd2KCmdIDEnumGuid = "{1496A755-94DE-11D0-8C3F-00C04FC2AAE2 }";
119 if (guid.Equals(VSStd2KCmdIDEnumGuid, StringComparison.OrdinalIgnoreCase))
120 {
121 // If loading a NaCl or Pepper platform, perform property modifications.
122 if (id == (int)VSConstants.VSStd2KCmdID.SolutionPlatform)
123 {
124 string platform = customOut as string;
125 if (Strings.NaClPlatformName.Equals(platform) ||
126 Strings.PepperPlatformName.Equals(platform))
127 {
128 PerformPropertyModifications();
129 }
130 }
131 }
132 }
133
134 /// <summary>
135 /// Goes through all projects in the solution and updates their properties w ith necessary
136 /// modifications if they are NaCl or Pepper configurations. We add the vers ion information
137 /// here.
noelallen1 2012/08/04 01:18:34 Same... Good to document why in case that reason g
tysand 2012/08/04 02:07:34 Done.
138 /// </summary>
139 private void PerformPropertyModifications()
140 {
141 string naclAddInVersion = GetAddInVersionFromDescription();
142
143 var configs = Utility.GetPlatformVCConfigurations(dte_, Strings.PepperPlat formName);
144 configs.AddRange(Utility.GetPlatformVCConfigurations(dte_, Strings.NaClPla tformName));
145
146 foreach (VCConfiguration config in configs)
147 {
148 IVCRulePropertyStorage general = config.Rules.Item("ConfigurationGeneral ");
149 string projectVersionSetting = general.GetEvaluatedPropertyValue("NaClAd dInVersion");
150 if (string.IsNullOrEmpty(projectVersionSetting))
151 {
152 general.SetPropertyValue("NaClAddInVersion", naclAddInVersion);
153 PerformPropertyFixes(config);
154 }
155 }
156 }
157
158 /// <summary>
159 /// Takes a project configuration and sets values in the project file to wor k around some
160 /// problems in Visual Studio.
161 /// </summary>
162 /// <param name="config">A configuration that needs modification.</param>
163 private void PerformPropertyFixes(VCConfiguration config)
164 {
165 string name = config.Platform.Name;
noelallen1 2012/08/04 01:18:34 Is 'name' ever used?
tysand 2012/08/04 02:07:34 Embarrassing, this was debugging code. Removed it.
166 string aaa = config.Name;
noelallen1 2012/08/04 01:18:34 'aaa' what is this variable for?
tysand 2012/08/04 02:07:34 Debugging code. Oops. On 2012/08/04 01:18:34, noel
167 IVCRulePropertyStorage debugger = config.Rules.Item("WindowsLocalDebugger" );
168 string evaluatedCommand = debugger.GetEvaluatedPropertyValue("LocalDebugge rCommand");
169 debugger.SetPropertyValue("LocalDebuggerCommand", evaluatedCommand);
170
171 string arguments = debugger.GetUnevaluatedPropertyValue("LocalDebuggerComm andArguments");
172 debugger.SetPropertyValue("LocalDebuggerCommandArguments", arguments);
173 }
174
175 /// <summary>
176 /// During the build process we dynamically put the add-in version number in to the add-in
177 /// description. This function extracts that version number.
178 /// </summary>
179 /// <returns>The add-in version number.</returns>
180 private string GetAddInVersionFromDescription()
181 {
182 string naclAddinVersion = "missing";
183 foreach (AddIn addin in dte_.AddIns)
184 {
185 if (addin.Name.Equals(Strings.AddInName))
186 {
187 string identifier = "Version: [";
188 int start = addin.Description.IndexOf(identifier) + identifier.Length;
189 int end = addin.Description.LastIndexOf(']');
190 if (start >= 0 && end >= 0)
191 {
192 naclAddinVersion = addin.Description.Substring(start, end - start);
193 break;
194 }
195 }
196 }
197
198 return naclAddinVersion;
199 }
200
201 /// <summary>
202 /// Called when Visual Studio ends a debugging session.
203 /// </summary>
204 /// <param name="reason">The parameter is not used.</param>
205 private void DebuggerOnEnterDesignMode(dbgEventReason reason)
206 {
207 debuggerHelper_.StopDebugging();
208 }
209
210 /// <summary>
211 /// Called when Visual Studio starts a debugging session.
212 /// </summary>
213 /// <param name="reason">Indicates how we are entering run mode (breakpoint or launch).</param>
214 private void DebuggerOnEnterRunMode(dbgEventReason reason)
215 {
216 // If we are starting debugging (not re-entering from a breakpoint)
217 // then load project settings and start the debugger-helper.
218 if (reason == dbgEventReason.dbgEventReasonLaunchProgram &&
219 debuggerHelper_.LoadProjectSettings())
220 {
221 debuggerHelper_.StartDebugging();
222 }
223 }
117 } 224 }
118 } 225 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698