OLD | NEW |
| (Empty) |
1 /// Copyright (c) Microsoft Corporation. All rights reserved. | |
2 | |
3 using System; | |
4 using System.Diagnostics; | |
5 using System.Globalization; | |
6 using System.Runtime.InteropServices; | |
7 using Microsoft.VisualStudio; | |
8 using Microsoft.VisualStudio.Shell.Interop; | |
9 | |
10 namespace Microsoft.VisualStudio.Project.Automation | |
11 { | |
12 [ComVisible(true), CLSCompliant(false)] | |
13 public class OASolutionFolder<T> : EnvDTE80.SolutionFolder | |
14 where T : HierarchyNode | |
15 { | |
16 bool hidden = false; | |
17 T node; | |
18 | |
19 public OASolutionFolder(T associatedNode) | |
20 { | |
21 if(associatedNode == null) | |
22 { | |
23 throw new ArgumentNullException("associatedNode"
); | |
24 } | |
25 | |
26 Debug.Assert(associatedNode.ProjectMgr is ProjectContain
erNode, "Expecting obejct of type" + typeof(ProjectContainerNode).Name); | |
27 | |
28 if(!(associatedNode.ProjectMgr is ProjectContainerNode)) | |
29 throw new ArgumentException(SR.GetString(SR.Inva
lidParameter, CultureInfo.CurrentUICulture), "associatedNode"); | |
30 | |
31 this.node = associatedNode; | |
32 } | |
33 | |
34 | |
35 #region SolutionFolder Members | |
36 | |
37 public virtual EnvDTE.Project AddFromFile(string fileName) | |
38 { | |
39 ProjectContainerNode projectContainer = (ProjectContaine
rNode)this.node.ProjectMgr; | |
40 ProjectElement newElement = new ProjectElement(projectCo
ntainer, fileName, ProjectFileConstants.SubProject); | |
41 NestedProjectNode newNode = projectContainer.AddExisting
NestedProject(newElement, __VSCREATEPROJFLAGS.CPF_NOTINSLNEXPLR | __VSCREATEPROJ
FLAGS.CPF_SILENT | __VSCREATEPROJFLAGS.CPF_OPENFILE); | |
42 if(newNode == null) | |
43 return null; | |
44 // Now that the sub project was created, get its extensi
bility object so we can return it | |
45 object newProject = null; | |
46 if(ErrorHandler.Succeeded(newNode.NestedHierarchy.GetPro
perty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out newPr
oject))) | |
47 return newProject as EnvDTE.Project; | |
48 else | |
49 return null; | |
50 } | |
51 | |
52 public virtual EnvDTE.Project AddFromTemplate(string fileName, s
tring destination, string projectName) | |
53 { | |
54 bool isVSTemplate = Utilities.IsTemplateFile(fileName); | |
55 | |
56 NestedProjectNode newNode = null; | |
57 if(isVSTemplate) | |
58 { | |
59 // Get the wizard to run, we will get called aga
in and use the alternate code path | |
60 ProjectElement newElement = new ProjectElement(t
his.node.ProjectMgr, System.IO.Path.Combine(destination, projectName), ProjectFi
leConstants.SubProject); | |
61 newElement.SetMetadata(ProjectFileConstants.Temp
late, fileName); | |
62 ((ProjectContainerNode)this.node.ProjectMgr).Run
VsTemplateWizard(newElement, false); | |
63 } | |
64 else | |
65 { | |
66 if((String.IsNullOrEmpty(System.IO.Path.GetExten
sion(projectName)))) | |
67 { | |
68 string targetExtension = System.IO.Path.
GetExtension(fileName); | |
69 projectName = System.IO.Path.ChangeExten
sion(projectName, targetExtension); | |
70 } | |
71 | |
72 ProjectContainerNode projectContainer = (Project
ContainerNode)this.node.ProjectMgr; | |
73 newNode = projectContainer.AddNestedProjectFromT
emplate(fileName, destination, projectName, null, __VSCREATEPROJFLAGS.CPF_NOTINS
LNEXPLR | __VSCREATEPROJFLAGS.CPF_SILENT | __VSCREATEPROJFLAGS.CPF_CLONEFILE); | |
74 } | |
75 if(newNode == null) | |
76 return null; | |
77 | |
78 // Now that the sub project was created, get its extensi
bility object so we can return it | |
79 object newProject = null; | |
80 if(ErrorHandler.Succeeded(newNode.NestedHierarchy.GetPro
perty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out newPr
oject))) | |
81 return newProject as EnvDTE.Project; | |
82 else | |
83 return null; | |
84 } | |
85 | |
86 public virtual EnvDTE.Project AddSolutionFolder(string Name) | |
87 { | |
88 throw new NotImplementedException(); | |
89 } | |
90 | |
91 public virtual EnvDTE.Project Parent | |
92 { | |
93 get | |
94 { | |
95 throw new NotImplementedException(); | |
96 } | |
97 } | |
98 | |
99 public virtual bool Hidden | |
100 { | |
101 get | |
102 { | |
103 return hidden; | |
104 } | |
105 set | |
106 { | |
107 hidden = value; | |
108 } | |
109 } | |
110 | |
111 public virtual EnvDTE.DTE DTE | |
112 { | |
113 get | |
114 { | |
115 return (EnvDTE.DTE)this.node.ProjectMgr.Site.Get
Service(typeof(EnvDTE.DTE)); | |
116 } | |
117 } | |
118 | |
119 #endregion | |
120 } | |
121 | |
122 } | |
OLD | NEW |