/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. using System;
  19. using System.IO;
  20. using System.Linq;
  21. using ICSharpCode.Core;
  22. using ICSharpCode.SharpDevelop.Project;
  23. using SD = ICSharpCode.SharpDevelop.Project;
  24. namespace ICSharpCode.PackageManagement.EnvDTE
  25. {
  26. public class DirectoryProjectItem : ProjectItem
  27. {
  28. string relativePath;
  29. public DirectoryProjectItem(
  30. Project project,
  31. string relativePath)
  32. : this(project, CreateFileProjectItem(project, relativePath))
  33. {
  34. this.relativePath = relativePath;
  35. }
  36. static FileProjectItem CreateFileProjectItem(Project project, string relativePath)
  37. {
  38. return new FileProjectItem(project.MSBuildProject, ItemType.Folder, relativePath);
  39. }
  40. static string GetSubdirectoryName(string relativePath)
  41. {
  42. return relativePath.Split('\\').First();
  43. }
  44. public DirectoryProjectItem(Project project, FileProjectItem projectItem)
  45. : base(project, projectItem)
  46. {
  47. }
  48. internal override bool IsChildItem(SD.ProjectItem msbuildProjectItem)
  49. {
  50. string directory = Path.GetDirectoryName(msbuildProjectItem.Include);
  51. if (directory == relativePath) {
  52. return true;
  53. }
  54. return false;
  55. }
  56. public static DirectoryProjectItem CreateDirectoryProjectItemFromFullPath(Project project, string directory)
  57. {
  58. string relativePath = project.GetRelativePath(directory);
  59. return new DirectoryProjectItem(project, relativePath);
  60. }
  61. }
  62. }