PageRenderTime 28ms CodeModel.GetById 15ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/DirectoryProjectItem.cs

https://github.com/ajadex/SharpDevelop
C# | 71 lines | 45 code | 9 blank | 17 comment | 2 complexity | dc96b9dee2a6f71e1a2a1f5cb32adabb MD5 | raw file
 1// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
 2// 
 3// Permission is hereby granted, free of charge, to any person obtaining a copy of this
 4// software and associated documentation files (the "Software"), to deal in the Software
 5// without restriction, including without limitation the rights to use, copy, modify, merge,
 6// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
 7// to whom the Software is furnished to do so, subject to the following conditions:
 8// 
 9// The above copyright notice and this permission notice shall be included in all copies or
10// substantial portions of the Software.
11// 
12// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17// DEALINGS IN THE SOFTWARE.
18
19using System;
20using System.IO;
21using System.Linq;
22
23using ICSharpCode.Core;
24using ICSharpCode.SharpDevelop.Project;
25using SD = ICSharpCode.SharpDevelop.Project;
26
27namespace ICSharpCode.PackageManagement.EnvDTE
28{
29	public class DirectoryProjectItem : ProjectItem
30	{
31		string relativePath;
32		
33		public DirectoryProjectItem(
34			Project project,
35			string relativePath)
36			: this(project, CreateFileProjectItem(project, relativePath))
37		{
38			this.relativePath = relativePath;
39		}
40		
41		static FileProjectItem CreateFileProjectItem(Project project, string relativePath)
42		{
43			return new FileProjectItem(project.MSBuildProject, ItemType.Folder, relativePath);
44		}
45		
46		static string GetSubdirectoryName(string relativePath)
47		{
48			return relativePath.Split('\\').First();
49		}
50		
51		public DirectoryProjectItem(Project project, FileProjectItem projectItem)
52			: base(project, projectItem)
53		{
54		}
55		
56		internal override bool IsChildItem(SD.ProjectItem msbuildProjectItem)
57		{
58			string directory = Path.GetDirectoryName(msbuildProjectItem.Include);
59			if (directory == relativePath) {
60				return true;
61			}
62			return false;
63		}
64		
65		public static DirectoryProjectItem CreateDirectoryProjectItemFromFullPath(Project project, string directory)
66		{
67			string relativePath = project.GetRelativePath(directory);
68			return new DirectoryProjectItem(project, relativePath);
69		}
70	}
71}