PageRenderTime 44ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/Tools/IronStudio/IronStudio/VisualStudio/Project/Automation/OANavigableProjectItems.cs

http://github.com/IronLanguages/main
C# | 280 lines | 163 code | 24 blank | 93 comment | 14 complexity | 15147371188ce0f99a601eb1b00e3fb3 MD5 | raw file
Possible License(s): CPL-1.0, BSD-3-Clause, ISC, GPL-2.0, MPL-2.0-no-copyleft-exception
  1. /* ****************************************************************************
  2. *
  3. * Copyright (c) Microsoft Corporation.
  4. *
  5. * This source code is subject to terms and conditions of the Apache License, Version 2.0. A
  6. * copy of the license can be found in the License.html file at the root of this distribution. If
  7. * you cannot locate the Apache License, Version 2.0, please send an email to
  8. * ironpy@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
  9. * by the terms of the Apache License, Version 2.0.
  10. *
  11. * You must not remove this notice, or any other, from this software.
  12. *
  13. * ***************************************************************************/
  14. using System;
  15. using System.Collections;
  16. using System.Collections.Generic;
  17. using System.Diagnostics.CodeAnalysis;
  18. using System.Runtime.InteropServices;
  19. namespace Microsoft.VisualStudio.Project.Automation
  20. {
  21. /// <summary>
  22. /// This can navigate a collection object only (partial implementation of ProjectItems interface)
  23. /// </summary>
  24. [SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")]
  25. [ComVisible(true), CLSCompliant(false)]
  26. public class OANavigableProjectItems : EnvDTE.ProjectItems
  27. {
  28. #region fields
  29. private OAProject project;
  30. private IList<EnvDTE.ProjectItem> items;
  31. private HierarchyNode nodeWithItems;
  32. #endregion
  33. #region properties
  34. /// <summary>
  35. /// Defines an internal list of project items
  36. /// </summary>
  37. internal IList<EnvDTE.ProjectItem> Items
  38. {
  39. get
  40. {
  41. return this.items;
  42. }
  43. }
  44. /// <summary>
  45. /// Defines a relationship to the associated project.
  46. /// </summary>
  47. internal OAProject Project
  48. {
  49. get
  50. {
  51. return this.project;
  52. }
  53. }
  54. /// <summary>
  55. /// Defines the node that contains the items
  56. /// </summary>
  57. internal HierarchyNode NodeWithItems
  58. {
  59. get
  60. {
  61. return this.nodeWithItems;
  62. }
  63. }
  64. #endregion
  65. #region ctor
  66. /// <summary>
  67. /// Constructor.
  68. /// </summary>
  69. /// <param name="project">The associated project.</param>
  70. /// <param name="nodeWithItems">The node that defines the items.</param>
  71. public OANavigableProjectItems(OAProject project, HierarchyNode nodeWithItems)
  72. {
  73. this.project = project;
  74. this.nodeWithItems = nodeWithItems;
  75. this.items = this.GetListOfProjectItems();
  76. }
  77. /// <summary>
  78. /// Constructor.
  79. /// </summary>
  80. /// <param name="project">The associated project.</param>
  81. /// <param name="items">A list of items that will make up the items defined by this object.</param>
  82. /// <param name="nodeWithItems">The node that defines the items.</param>
  83. public OANavigableProjectItems(OAProject project, IList<EnvDTE.ProjectItem> items, HierarchyNode nodeWithItems)
  84. {
  85. this.items = items;
  86. this.project = project;
  87. this.nodeWithItems = nodeWithItems;
  88. }
  89. #endregion
  90. #region EnvDTE.ProjectItems
  91. /// <summary>
  92. /// Gets a value indicating the number of objects in the collection.
  93. /// </summary>
  94. public virtual int Count
  95. {
  96. get
  97. {
  98. return items.Count;
  99. }
  100. }
  101. /// <summary>
  102. /// Gets the immediate parent object of a ProjectItems collection.
  103. /// </summary>
  104. public virtual object Parent
  105. {
  106. get
  107. {
  108. return this.nodeWithItems.GetAutomationObject();
  109. }
  110. }
  111. /// <summary>
  112. /// Gets an enumeration indicating the type of object.
  113. /// </summary>
  114. public virtual string Kind
  115. {
  116. get
  117. {
  118. // TODO: Add OAProjectItems.Kind getter implementation
  119. return null;
  120. }
  121. }
  122. /// <summary>
  123. /// Gets the top-level extensibility object.
  124. /// </summary>
  125. public virtual EnvDTE.DTE DTE
  126. {
  127. get
  128. {
  129. return (EnvDTE.DTE)this.project.DTE;
  130. }
  131. }
  132. /// <summary>
  133. /// Gets the project hosting the project item or items.
  134. /// </summary>
  135. public virtual EnvDTE.Project ContainingProject
  136. {
  137. get
  138. {
  139. return this.project;
  140. }
  141. }
  142. /// <summary>
  143. /// Adds one or more ProjectItem objects from a directory to the ProjectItems collection.
  144. /// </summary>
  145. /// <param name="directory">The directory from which to add the project item.</param>
  146. /// <returns>A ProjectItem object.</returns>
  147. public virtual EnvDTE.ProjectItem AddFromDirectory(string directory)
  148. {
  149. throw new NotImplementedException();
  150. }
  151. /// <summary>
  152. /// Creates a new project item from an existing item template file and adds it to the project.
  153. /// </summary>
  154. /// <param name="fileName">The full path and file name of the template project file.</param>
  155. /// <param name="name">The file name to use for the new project item.</param>
  156. /// <returns>A ProjectItem object. </returns>
  157. public virtual EnvDTE.ProjectItem AddFromTemplate(string fileName, string name)
  158. {
  159. throw new NotImplementedException();
  160. }
  161. /// <summary>
  162. /// Creates a new folder in Solution Explorer.
  163. /// </summary>
  164. /// <param name="name">The name of the folder node in Solution Explorer.</param>
  165. /// <param name="kind">The type of folder to add. The available values are based on vsProjectItemsKindConstants and vsProjectItemKindConstants</param>
  166. /// <returns>A ProjectItem object.</returns>
  167. public virtual EnvDTE.ProjectItem AddFolder(string name, string kind)
  168. {
  169. throw new NotImplementedException();
  170. }
  171. /// <summary>
  172. /// Copies a source file and adds it to the project.
  173. /// </summary>
  174. /// <param name="filePath">The path and file name of the project item to be added.</param>
  175. /// <returns>A ProjectItem object. </returns>
  176. public virtual EnvDTE.ProjectItem AddFromFileCopy(string filePath)
  177. {
  178. throw new NotImplementedException();
  179. }
  180. /// <summary>
  181. /// Adds a project item from a file that is installed in a project directory structure.
  182. /// </summary>
  183. /// <param name="fileName">The file name of the item to add as a project item. </param>
  184. /// <returns>A ProjectItem object. </returns>
  185. public virtual EnvDTE.ProjectItem AddFromFile(string fileName)
  186. {
  187. throw new NotImplementedException();
  188. }
  189. /// <summary>
  190. /// Get Project Item from index
  191. /// </summary>
  192. /// <param name="index">Either index by number (1-based) or by name can be used to get the item</param>
  193. /// <returns>Project Item. ArgumentException if invalid index is specified</returns>
  194. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
  195. public virtual EnvDTE.ProjectItem Item(object index)
  196. {
  197. // Changed from MPFProj: throws ArgumentException instead of returning null (http://mpfproj10.codeplex.com/workitem/9158)
  198. if(index is int)
  199. {
  200. int realIndex = (int)index - 1;
  201. if(realIndex >= 0 && realIndex < this.items.Count)
  202. {
  203. return (EnvDTE.ProjectItem)items[realIndex];
  204. }
  205. }
  206. else if(index is string)
  207. {
  208. string name = (string)index;
  209. foreach(EnvDTE.ProjectItem item in items)
  210. {
  211. if(String.Compare(item.Name, name, StringComparison.OrdinalIgnoreCase) == 0)
  212. {
  213. return item;
  214. }
  215. }
  216. }
  217. throw new ArgumentException();
  218. }
  219. /// <summary>
  220. /// Returns an enumeration for items in a collection.
  221. /// </summary>
  222. /// <returns>An IEnumerator for this object.</returns>
  223. public virtual IEnumerator GetEnumerator()
  224. {
  225. if(this.items == null)
  226. {
  227. yield return null;
  228. }
  229. int count = items.Count;
  230. for(int i = 0; i < count; i++)
  231. {
  232. yield return items[i];
  233. }
  234. }
  235. #endregion
  236. #region virtual methods
  237. /// <summary>
  238. /// Retrives a list of items associated with the current node.
  239. /// </summary>
  240. /// <returns>A List of project items</returns>
  241. protected IList<EnvDTE.ProjectItem> GetListOfProjectItems()
  242. {
  243. List<EnvDTE.ProjectItem> list = new List<EnvDTE.ProjectItem>();
  244. for(HierarchyNode child = this.NodeWithItems.FirstChild; child != null; child = child.NextSibling)
  245. {
  246. EnvDTE.ProjectItem item = child.GetAutomationObject() as EnvDTE.ProjectItem;
  247. if(null != item)
  248. {
  249. list.Add(item);
  250. }
  251. }
  252. return list;
  253. }
  254. #endregion
  255. }
  256. }