OLD | NEW |
| (Empty) |
1 /// Copyright (c) Microsoft Corporation. All rights reserved. | |
2 | |
3 using System; | |
4 using System.Diagnostics; | |
5 using System.Runtime.InteropServices; | |
6 using Microsoft.VisualStudio; | |
7 using Microsoft.VisualStudio.Shell.Interop; | |
8 | |
9 namespace Microsoft.VisualStudio.Project.Automation | |
10 { | |
11 [ComVisible(true), CLSCompliant(false)] | |
12 public class OAProjectItem<T> : EnvDTE.ProjectItem | |
13 where T : HierarchyNode | |
14 { | |
15 | |
16 #region fields | |
17 private T node; | |
18 private OAProject project; | |
19 #endregion | |
20 | |
21 #region properties | |
22 protected T Node | |
23 { | |
24 get | |
25 { | |
26 return this.node; | |
27 } | |
28 } | |
29 | |
30 /// <summary> | |
31 /// Returns the automation project | |
32 /// </summary> | |
33 protected OAProject Project | |
34 { | |
35 get | |
36 { | |
37 return this.project; | |
38 } | |
39 } | |
40 #endregion | |
41 | |
42 #region ctors | |
43 public OAProjectItem(OAProject project, T node) | |
44 { | |
45 this.node = node; | |
46 this.project = project; | |
47 } | |
48 #endregion | |
49 | |
50 #region EnvDTE.ProjectItem | |
51 | |
52 /// <summary> | |
53 /// Gets the requested Extender if it is available for this obje
ct | |
54 /// </summary> | |
55 /// <param name="extenderName">The name of the extender.</param> | |
56 /// <returns>The extender object.</returns> | |
57 public virtual object get_Extender(string extenderName) | |
58 { | |
59 return null; | |
60 } | |
61 | |
62 /// <summary> | |
63 /// Gets an object that can be accessed by name at run time. | |
64 /// </summary> | |
65 public virtual object Object | |
66 { | |
67 get | |
68 { | |
69 return this.node.Object; | |
70 } | |
71 } | |
72 | |
73 /// <summary> | |
74 /// Gets the Document associated with the item, if one exists. | |
75 /// </summary> | |
76 public virtual EnvDTE.Document Document | |
77 { | |
78 get | |
79 { | |
80 return null; | |
81 } | |
82 } | |
83 | |
84 /// <summary> | |
85 /// Gets the number of files associated with a ProjectItem. | |
86 /// </summary> | |
87 public virtual short FileCount | |
88 { | |
89 get | |
90 { | |
91 return (short)1; | |
92 } | |
93 } | |
94 | |
95 /// <summary> | |
96 /// Gets a collection of all properties that pertain to the obje
ct. | |
97 /// </summary> | |
98 public virtual EnvDTE.Properties Properties | |
99 { | |
100 get | |
101 { | |
102 if(this.node.NodeProperties == null) | |
103 { | |
104 return null; | |
105 } | |
106 return new OAProperties(this.node.NodeProperties
); | |
107 } | |
108 } | |
109 | |
110 | |
111 /// <summary> | |
112 /// Gets the FileCodeModel object for the project item. | |
113 /// </summary> | |
114 public virtual EnvDTE.FileCodeModel FileCodeModel | |
115 { | |
116 get | |
117 { | |
118 return null; | |
119 } | |
120 } | |
121 | |
122 /// <summary> | |
123 /// Gets a ProjectItems for the object. | |
124 /// </summary> | |
125 public virtual EnvDTE.ProjectItems ProjectItems | |
126 { | |
127 get | |
128 { | |
129 return null; | |
130 } | |
131 } | |
132 | |
133 /// <summary> | |
134 /// Gets a GUID string indicating the kind or type of the object
. | |
135 /// </summary> | |
136 public virtual string Kind | |
137 { | |
138 get | |
139 { | |
140 Guid guid; | |
141 ErrorHandler.ThrowOnFailure(this.node.GetGuidPro
perty((int)__VSHPROPID.VSHPROPID_TypeGuid, out guid)); | |
142 return guid.ToString("B"); | |
143 } | |
144 } | |
145 | |
146 /// <summary> | |
147 /// Saves the project item. | |
148 /// </summary> | |
149 /// <param name="fileName">The name with which to save the proje
ct or project item.</param> | |
150 /// <remarks>Implemented by subclasses.</remarks> | |
151 public virtual void Save(string fileName) | |
152 { | |
153 throw new NotImplementedException(); | |
154 } | |
155 | |
156 /// <summary> | |
157 /// Gets the top-level extensibility object. | |
158 /// </summary> | |
159 public virtual EnvDTE.DTE DTE | |
160 { | |
161 get | |
162 { | |
163 return (EnvDTE.DTE)this.project.DTE; | |
164 } | |
165 } | |
166 | |
167 /// <summary> | |
168 /// Gets the ProjectItems collection containing the ProjectItem
object supporting this property. | |
169 /// </summary> | |
170 public virtual EnvDTE.ProjectItems Collection | |
171 { | |
172 get | |
173 { | |
174 // Get the parent node | |
175 HierarchyNode parentNode = this.node.Parent; | |
176 Debug.Assert(parentNode != null, "Failed to get
the parent node"); | |
177 | |
178 // Get the ProjectItems object for the parent no
de | |
179 if(parentNode is ProjectNode) | |
180 { | |
181 // The root node for the project | |
182 return ((OAProject)parentNode.GetAutomat
ionObject()).ProjectItems; | |
183 } | |
184 else if(parentNode is FileNode && parentNode.Fir
stChild != null) | |
185 { | |
186 // The item has children | |
187 return ((OAProjectItem<FileNode>)parentN
ode.GetAutomationObject()).ProjectItems; | |
188 } | |
189 else if(parentNode is FolderNode) | |
190 { | |
191 return ((OAProjectItem<FolderNode>)paren
tNode.GetAutomationObject()).ProjectItems; | |
192 } | |
193 else | |
194 { | |
195 // Not supported. Override this method i
n derived classes to return appropriate collection object | |
196 throw new NotImplementedException(); | |
197 } | |
198 } | |
199 } | |
200 /// <summary> | |
201 /// Gets a list of available Extenders for the object. | |
202 /// </summary> | |
203 public virtual object ExtenderNames | |
204 { | |
205 get | |
206 { | |
207 return null; | |
208 } | |
209 } | |
210 | |
211 /// <summary> | |
212 /// Gets the ConfigurationManager object for this ProjectItem. | |
213 /// </summary> | |
214 /// <remarks>We do not support config management based per item.
</remarks> | |
215 public virtual EnvDTE.ConfigurationManager ConfigurationManager | |
216 { | |
217 get | |
218 { | |
219 return null; | |
220 } | |
221 } | |
222 | |
223 /// <summary> | |
224 /// Gets the project hosting the ProjectItem. | |
225 /// </summary> | |
226 public virtual EnvDTE.Project ContainingProject | |
227 { | |
228 get | |
229 { | |
230 return this.project; | |
231 } | |
232 } | |
233 | |
234 /// <summary> | |
235 /// Gets or sets a value indicating whether or not the object ha
s been modified since last being saved or opened. | |
236 /// </summary> | |
237 public virtual bool Saved | |
238 { | |
239 get | |
240 { | |
241 return !this.IsDirty; | |
242 | |
243 } | |
244 set | |
245 { | |
246 throw new NotImplementedException(); | |
247 } | |
248 } | |
249 | |
250 /// <summary> | |
251 /// Gets the Extender category ID (CATID) for the object. | |
252 /// </summary> | |
253 public virtual string ExtenderCATID | |
254 { | |
255 get | |
256 { | |
257 return null; | |
258 } | |
259 } | |
260 | |
261 /// <summary> | |
262 /// If the project item is the root of a subproject, then the Su
bProject property returns the Project object for the subproject. | |
263 /// </summary> | |
264 public virtual EnvDTE.Project SubProject | |
265 { | |
266 get | |
267 { | |
268 return null; | |
269 } | |
270 } | |
271 | |
272 /// <summary> | |
273 /// Microsoft Internal Use Only. Checks if the document associat
ed to this item is dirty. | |
274 /// </summary> | |
275 public virtual bool IsDirty | |
276 { | |
277 get | |
278 { | |
279 throw new NotImplementedException(); | |
280 } | |
281 set | |
282 { | |
283 throw new NotImplementedException(); | |
284 } | |
285 } | |
286 | |
287 /// <summary> | |
288 /// Gets or sets the name of the object. | |
289 /// </summary> | |
290 public virtual string Name | |
291 { | |
292 get | |
293 { | |
294 return this.node.Caption; | |
295 } | |
296 set | |
297 { | |
298 if(this.node == null || this.node.ProjectMgr ==
null || this.node.ProjectMgr.IsClosed || this.node.ProjectMgr.Site == null) | |
299 { | |
300 throw new InvalidOperationException(); | |
301 } | |
302 | |
303 using(AutomationScope scope = new AutomationScop
e(this.Node.ProjectMgr.Site)) | |
304 { | |
305 this.node.SetEditLabel(value); | |
306 } | |
307 } | |
308 } | |
309 /// <summary> | |
310 /// Removes the project item from hierarchy. | |
311 /// </summary> | |
312 public virtual void Remove() | |
313 { | |
314 if(this.node == null || this.node.ProjectMgr == null ||
this.node.ProjectMgr.IsClosed || this.node.ProjectMgr.Site == null) | |
315 { | |
316 throw new InvalidOperationException(); | |
317 } | |
318 | |
319 using(AutomationScope scope = new AutomationScope(this.N
ode.ProjectMgr.Site)) | |
320 { | |
321 this.node.Remove(false); | |
322 } | |
323 } | |
324 | |
325 /// <summary> | |
326 /// Removes the item from its project and its storage. | |
327 /// </summary> | |
328 public virtual void Delete() | |
329 { | |
330 if(this.node == null || this.node.ProjectMgr == null ||
this.node.ProjectMgr.IsClosed || this.node.ProjectMgr.Site == null) | |
331 { | |
332 throw new InvalidOperationException(); | |
333 } | |
334 | |
335 using(AutomationScope scope = new AutomationScope(this.N
ode.ProjectMgr.Site)) | |
336 { | |
337 this.node.Remove(true); | |
338 } | |
339 } | |
340 | |
341 /// <summary> | |
342 /// Saves the project item. | |
343 /// </summary> | |
344 /// <param name="newFileName">The file name with which to save t
he solution, project, or project item. If the file exists, it is overwritten.</p
aram> | |
345 /// <returns>true if save was successful</returns> | |
346 /// <remarks>This method is implemented on subclasses.</remarks> | |
347 public virtual bool SaveAs(string newFileName) | |
348 { | |
349 throw new NotImplementedException(); | |
350 } | |
351 | |
352 /// <summary> | |
353 /// Gets a value indicating whether the project item is open in
a particular view type. | |
354 /// </summary> | |
355 /// <param name="viewKind">A Constants.vsViewKind* indicating th
e type of view to check./param> | |
356 /// <returns>A Boolean value indicating true if the project is o
pen in the given view type; false if not. </returns> | |
357 public virtual bool get_IsOpen(string viewKind) | |
358 { | |
359 throw new NotImplementedException(); | |
360 } | |
361 | |
362 /// <summary> | |
363 /// Gets the full path and names of the files associated with a
project item. | |
364 /// </summary> | |
365 /// <param name="index"> The index of the item</param> | |
366 /// <returns>The full path of the associated item</returns> | |
367 /// <exception cref="ArgumentOutOfRangeException">Is thrown if i
ndex is not one</exception> | |
368 public virtual string get_FileNames(short index) | |
369 { | |
370 // This method should really only be called with 1 as th
e parameter, but | |
371 // there used to be a bug in VB/C# that would work with
0. To avoid breaking | |
372 // existing automation they are still accepting 0. To be
compatible with them | |
373 // we accept it as well. | |
374 Debug.Assert(index > 0, "Index is 1 based."); | |
375 if(index < 0) | |
376 { | |
377 throw new ArgumentOutOfRangeException("index"); | |
378 } | |
379 return this.node.Url; | |
380 } | |
381 | |
382 /// <summary> | |
383 /// Expands the view of Solution Explorer to show project items.
| |
384 /// </summary> | |
385 public virtual void ExpandView() | |
386 { | |
387 if(this.node == null || this.node.ProjectMgr == null ||
this.node.ProjectMgr.IsClosed || this.node.ProjectMgr.Site == null) | |
388 { | |
389 throw new InvalidOperationException(); | |
390 } | |
391 | |
392 using(AutomationScope scope = new AutomationScope(this.N
ode.ProjectMgr.Site)) | |
393 { | |
394 IVsUIHierarchyWindow uiHierarchy = UIHierarchyUt
ilities.GetUIHierarchyWindow(this.node.ProjectMgr.Site, HierarchyNode.SolutionEx
plorer); | |
395 if(uiHierarchy == null) | |
396 { | |
397 throw new InvalidOperationException(); | |
398 } | |
399 | |
400 ErrorHandler.ThrowOnFailure(uiHierarchy.ExpandIt
em(this.node.ProjectMgr, this.node.ID, EXPANDFLAGS.EXPF_ExpandFolder)); | |
401 | |
402 } | |
403 } | |
404 | |
405 /// <summary> | |
406 /// Opens the project item in the specified view. Not implemente
d because this abstract class dont know what to open | |
407 /// </summary> | |
408 /// <param name="ViewKind">Specifies the view kind in which to o
pen the item</param> | |
409 /// <returns>Window object</returns> | |
410 public virtual EnvDTE.Window Open(string ViewKind) | |
411 { | |
412 throw new NotImplementedException(); | |
413 } | |
414 | |
415 #endregion | |
416 } | |
417 } | |
OLD | NEW |