forked from vsClojure/vsClojure
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClojureProjectNode.cs
More file actions
268 lines (221 loc) · 8.32 KB
/
Copy pathClojureProjectNode.cs
File metadata and controls
268 lines (221 loc) · 8.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/***************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
This code is licensed under the Visual Studio SDK license terms.
THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
***************************************************************************/
using System;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using ClojureExtension.Project.Configuration;
using ClojureExtension.Utilities;
using EnvDTE;
using Microsoft.ClojureExtension;
using Microsoft.ClojureExtension.Configuration;
using Microsoft.ClojureExtension.Project;
using Microsoft.VisualStudio.Project;
using Microsoft.VisualStudio.Project.Automation;
using Microsoft.VisualStudio.Shell;
using VSLangProj;
namespace ClojureExtension.Project
{
/// <summary>
/// This class extends the ProjectNode in order to represent our project
/// within the hierarchy.
/// </summary>
[Guid(Guids.ClojureProject)]
public class ClojureProjectNode : ProjectNode
{
#region Enum for image list
internal enum MyCustomProjectImageName
{
Project = 0,
}
#endregion
#region Constants
internal const string ProjectTypeName = "Clojure";
#endregion
#region Fields
private Package package;
internal static int imageOffset;
private static ImageList imageList;
private VSProject vsProject;
public Package Package
{
get { return package; }
}
#endregion
#region Constructors
/// <summary>
/// Initializes the <see cref = "ClojureProjectNode" /> class.
/// </summary>
static ClojureProjectNode()
{
imageList = Microsoft.VisualStudio.Project.Utilities.GetImageList(typeof (ClojureProjectNode).Assembly.GetManifestResourceStream("ClojureExtension.Project.Resources.ClojureImageList.bmp"));
}
/// <summary>
/// Initializes a new instance of the <see cref = "ClojureProjectNode" /> class.
/// </summary>
/// <param name = "package">Value of the project package for initialize internal package field.</param>
public ClojureProjectNode(Package package)
{
this.package = package;
InitializeImageList();
CanProjectDeleteItems = true;
}
#endregion
#region Properties
/// <summary>
/// Gets or sets the image list.
/// </summary>
/// <value>The image list.</value>
public static ImageList ImageList
{
get { return imageList; }
set { imageList = value; }
}
protected internal VSProject VSProject
{
get
{
if (vsProject == null)
{
vsProject = new OAVSProject(this);
}
return vsProject;
}
}
#endregion
#region Overriden implementation
/// <summary>
/// Gets the project GUID.
/// </summary>
/// <value>The project GUID.</value>
public override Guid ProjectGuid
{
get { return typeof (ClojureProjectFactory).GUID; }
}
public override bool IsCodeFile(string fileName)
{
return fileName.ToLower().EndsWith(".clj");
}
/// <summary>
/// Gets the type of the project.
/// </summary>
/// <value>The type of the project.</value>
public override string ProjectType
{
get { return ProjectTypeName; }
}
/// <summary>
/// Return an imageindex
/// </summary>
/// <value></value>
/// <returns></returns>
public override int ImageIndex
{
get { return imageOffset + (int) MyCustomProjectImageName.Project; }
}
/// <summary>
/// Returns an automation object representing this node
/// </summary>
/// <returns>The automation object</returns>
public override object GetAutomationObject()
{
return new OAClojureProject(this);
}
/// <summary>
/// Creates the file node.
/// </summary>
/// <param name = "item">The project element item.</param>
/// <returns></returns>
public override FileNode CreateFileNode(ProjectElement item)
{
ClojureProjectFileNode node = new ClojureProjectFileNode(this, item);
node.OleServiceProvider.AddService(typeof (EnvDTE.Project), new OleServiceProvider.ServiceCreatorCallback(CreateServices), false);
node.OleServiceProvider.AddService(typeof (ProjectItem), node.ServiceCreator, false);
node.OleServiceProvider.AddService(typeof (VSProject), new OleServiceProvider.ServiceCreatorCallback(CreateServices), false);
return node;
}
/// <summary>
/// Generate new Guid value and update it with GeneralPropertyPage GUID.
/// </summary>
/// <returns>Returns the property pages that are independent of configuration.</returns>
protected override Guid[] GetConfigurationIndependentPropertyPages()
{
Guid[] result = new Guid[1];
result[0] = typeof (GeneralPropertyPage).GUID;
return result;
}
/// <summary>
/// Overriding to provide project general property page.
/// </summary>
/// <returns>Returns the GeneralPropertyPage GUID value.</returns>
protected override Guid[] GetPriorityProjectDesignerPages()
{
Guid[] result = new Guid[1];
result[0] = typeof (GeneralPropertyPage).GUID;
return result;
}
/// <summary>
/// Adds the file from template.
/// </summary>
/// <param name = "source">The source template.</param>
/// <param name = "target">The target file.</param>
public override void AddFileFromTemplate(string source, string target)
{
if (!File.Exists(source))
{
throw new FileNotFoundException(string.Format("Template file not found: {0}", source));
}
string projectPath = Path.GetDirectoryName(GetMkDocument());
string relativePath = Path.GetDirectoryName(target).Substring(projectPath.Length);
string fileNamespace = relativePath.Replace("\\", ".");
fileNamespace = fileNamespace.TrimStart(new[] {'.'});
if (!string.IsNullOrEmpty(fileNamespace)) fileNamespace += ".";
fileNamespace += Path.GetFileNameWithoutExtension(target);
FileTemplateProcessor.AddReplace("%namespace%", fileNamespace);
try
{
FileTemplateProcessor.UntokenFile(source, target);
FileTemplateProcessor.Reset();
}
catch (Exception e)
{
throw new FileLoadException("Failed to add template file to project", target, e);
}
}
#endregion
#region Private implementation
private void InitializeImageList()
{
imageOffset = ImageHandler.ImageList.Images.Count;
foreach (Image img in ImageList.Images)
{
ImageHandler.AddImage(img);
}
}
private object CreateServices(Type serviceType)
{
object service = null;
if (typeof (VSProject) == serviceType)
{
service = VSProject;
}
else if (typeof (EnvDTE.Project) == serviceType)
{
service = GetAutomationObject();
}
return service;
}
protected override ConfigProvider CreateConfigProvider()
{
return new ClojureConfigProvider(this);
}
#endregion
}
}