public XFolderNode(XProjectNode root, string directoryPath, ProjectElement element, bool isNonMemberItem) : base(root, directoryPath, element) { this.isNonMemberItem = isNonMemberItem; // Folders do not participate in SCC. base.ExcludeNodeFromScc = true; }
protected virtual int IncludeInProject() { new UIThread().MustBeCalledFromUIThread(); XProjectNode projectNode = this.ProjectMgr as XProjectNode; if (projectNode == null || projectNode.IsClosed) { return((int)OleConstants.OLECMDERR_E_NOTSUPPORTED); } else if (!this.IsNonMemberItem) { return(VSConstants.S_OK); // do nothing, just ignore it. } using (XHelperMethods.NewWaitCursor()) { // Check out the project file. if (!projectNode.QueryEditProjectFile(false)) { throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED); } for (HierarchyNode child = this.FirstChild; child != null; child = child.NextSibling) { IProjectSourceNode node = child as IProjectSourceNode; if (node != null) { int result = node.IncludeInProject(); if (result != VSConstants.S_OK) { return(result); } } } // make sure that all parent folders are included in the project XHelperMethods.EnsureParentFolderIncluded(this); // now add this node to the project. this.SetProperty((int)__VSHPROPID.VSHPROPID_IsNonMemberItem, false); this.ItemNode = projectNode.CreateMsBuildFileProjectElement(this.Url); this.ProjectMgr.Tracker.OnItemAdded(this.Url, VSADDFILEFLAGS.VSADDFILEFLAGS_NoFlags); // notify others ////projectNode.OnItemAdded(this.Parent, this); this.ReDraw(UIHierarchyElement.Icon); // We have to redraw the icon of the node as it is now a member of the project and should be drawn using a different icon. this.ReDraw(UIHierarchyElement.SccState); // update the SCC state icon. this.ResetProperties(); this.SetSpecialProperties(); // allows to set generators etc. // refresh property browser... XHelperMethods.RefreshPropertyBrowser(); } return(VSConstants.S_OK); }
// ========================================================================================= // Constructors // ========================================================================================= /// <summary> /// Initializes a new instance of the <see cref="OAXSharpProject"/> class. /// </summary> /// <param name="project">The node to which this project belongs.</param> public OAXSharpProject(XProjectNode xproject) : base(xproject) { if (xproject != null) { this.properties = new OAProperties(xproject.NodeProperties); } }
/// <summary> /// Reloads all nodes which are not part of the project, /// ensuring that they match the current file structure on disk /// </summary> /// <param name="node">The selected hierarchy node</param> internal static void RefreshProject(HierarchyNode node) { XProjectNode projectNode = node.ProjectMgr as XProjectNode; if (projectNode.ShowAllFilesEnabled) { projectNode.ToggleShowAllFiles(); projectNode.ToggleShowAllFiles(); } }
private static void AddNonMemberFileItems(XProjectNode project, IList <string> fileList) { Utilities.ArgumentNotNull("fileList", fileList); foreach (string fileKey in fileList) { HierarchyNode parentNode = project; string[] pathItems = fileKey.Split(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }); if (String.Equals(fileKey, project.ProjectFile, StringComparison.OrdinalIgnoreCase)) { continue; } XFolderNode topFolderNode = null; foreach (string fileOrDir in pathItems) { string childNodeId = Path.Combine(parentNode.VirtualNodeName, fileOrDir); FileInfo fileOrDirInfo = new FileInfo(Path.Combine(project.ProjectFolder, childNodeId)); if ((fileOrDirInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) { break; } //HierarchyNode childNode = project.FindURL(fileOrDirInfo.FullName); HierarchyNode childNode = parentNode.FindChild(childNodeId); if (childNode == null) { if (topFolderNode == null) { topFolderNode = parentNode as XFolderNode; if (topFolderNode != null && (!topFolderNode.IsNonMemberItem) && topFolderNode.IsExpanded) { topFolderNode = null; } } ProjectElement element = new ProjectElement(project, null, true); element.Rename(childNodeId); element.SetMetadata(ProjectFileConstants.Name, childNodeId); childNode = project.CreateFileNode(element); parentNode.AddChild(childNode); break; } parentNode = childNode; } if (topFolderNode != null) { topFolderNode.CollapseFolder(); } } }
internal static void RemoveNonMemberItems(XProjectNode project) { IList <HierarchyNode> nodeList = new List <HierarchyNode>(); XHelperMethods.FindNodes(nodeList, project, XProjectMembers.IsNodeNonMemberItem, null); for (int index = nodeList.Count - 1; index >= 0; index--) { HierarchyNode node = nodeList[index]; HierarchyNode parent = node.Parent; node.OnItemDeleted(); parent.RemoveChild(node); } }
// ========================================================================================= // Constructors // ========================================================================================= /// <summary> /// Creates a new project property object. /// </summary> /// <param name="project">Project that owns the property.</param> /// <param name="propertyName">Name of the property.</param> public ProjectProperty(XProjectNode project, string propertyName) { XHelperMethods.VerifyNonNullArgument(project, "project"); XHelperMethods.VerifyNonNullArgument(propertyName, "propertyName"); this.project = project; this.propertyName = propertyName; this.perUser = ProjectProperty.PerUserProperties.Contains(propertyName); this.perConfig = !ProjectProperty.NonPerConfigProperties.Contains(propertyName); this.allowVariables = ProjectProperty.AllowVariablesProperties.Contains(propertyName); this.list = ProjectProperty.ListProperties.Contains(propertyName); this.endOfProjectFile = ProjectProperty.EndOfProjectFileProperties.Contains(propertyName); }
internal static void AddNonMemberItems(XProjectNode project) { IList <string> files = new List <string>(); IList <string> folders = new List <string>(); // obtain the list of files and folders under the project folder. XProjectMembers.GetRelativeFileSystemEntries(project.ProjectFolder, null, files, folders); // exclude the items which are the part of the build. XProjectMembers.ExcludeProjectBuildItems(project, files, folders); XProjectMembers.AddNonMemberFolderItems(project, folders); XProjectMembers.AddNonMemberFileItems(project, files); }
private static void AddNonMemberFolderItems(XProjectNode project, IList <string> folderList) { if (folderList == null) { throw new ArgumentNullException("folderList"); } foreach (string folderKey in folderList) { HierarchyNode parentNode = project; string[] folders = folderKey.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); XFolderNode topFolderNode = null; foreach (string folder in folders) { string childNodeId = Path.Combine(parentNode.VirtualNodeName, folder); FileInfo folderInfo = new FileInfo(Path.Combine(project.ProjectFolder, childNodeId)); if ((folderInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) { break; } HierarchyNode childNode = parentNode.FindChild(childNodeId); if (childNode == null) { if (topFolderNode == null) { topFolderNode = parentNode as XFolderNode; if (topFolderNode != null && (!topFolderNode.IsNonMemberItem) && topFolderNode.IsExpanded) { topFolderNode = null; } } ProjectElement element = new ProjectElement(project, null, true); childNode = project.CreateFolderNode(childNodeId, element); parentNode.AddChild(childNode); } parentNode = childNode; } if (topFolderNode != null) { topFolderNode.CollapseFolder(); } } }
/// <summary> /// Adds the this node to the build system. /// </summary> /// <param name="recursive">Flag to indicate if the addition should be recursive.</param> protected virtual void AddToMSBuild(bool recursive) { XProjectNode projectNode = this.ProjectMgr as XProjectNode; if (projectNode == null || projectNode.IsClosed) { return; // do nothing } this.ItemNode = projectNode.CreateMsBuildFolderProjectElement(this.Url); this.SetProperty((int)__VSHPROPID.VSHPROPID_IsNonMemberItem, false); if (recursive) { for (HierarchyNode node = this.FirstChild; node != null; node = node.NextSibling) { IProjectSourceNode sourceNode = node as IProjectSourceNode; if (sourceNode != null) { sourceNode.IncludeInProject(recursive); } } } }
protected override int ExcludeFromProject() { new UIThread().MustBeCalledFromUIThread(); if (this.ProjectMgr == null || this.ProjectMgr.IsClosed) { return((int)OleConstants.OLECMDERR_E_NOTSUPPORTED); } else if (this.IsNonMemberItem) { return(VSConstants.S_OK); // do nothing, just ignore it. } using (XHelperMethods.NewWaitCursor()) { for (HierarchyNode child = this.FirstChild; child != null; child = child.NextSibling) { IProjectSourceNode node = child as IProjectSourceNode; if (node != null) { int result = node.ExcludeFromProject(); if (result != VSConstants.S_OK) { return(result); } } } // Ask Document tracker listeners if we can remove the item. { // just to limit the scope. string documentToRemove = this.GetMkDocument(); string[] filesToBeDeleted = new string[1] { documentToRemove }; VSQUERYREMOVEFILEFLAGS[] queryRemoveFlags = this.GetQueryRemoveFileFlags(filesToBeDeleted); if (!this.ProjectMgr.Tracker.CanRemoveItems(filesToBeDeleted, queryRemoveFlags)) { return((int)OleConstants.OLECMDERR_E_CANCELED); } // Close the document if it has a manager. DocumentManager manager = this.GetDocumentManager(); if (manager != null) { if (manager.Close(__FRAMECLOSE.FRAMECLOSE_PromptSave) == VSConstants.E_ABORT) { // User cancelled operation in message box. return(VSConstants.OLE_E_PROMPTSAVECANCELLED); } } // Check out the project file. if (!this.ProjectMgr.QueryEditProjectFile(false)) { throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED); } } // close the document window if open. this.CloseDocumentWindow(this); XProjectNode projectNode = this.ProjectMgr as XProjectNode; projectNode.RemoveURL(this.Url); if (projectNode != null && projectNode.ShowAllFilesEnabled && File.Exists(this.Url)) { // need to store before removing the node. string url = this.Url; string include = this.ItemNode.GetMetadata(ProjectFileConstants.Include); this.ItemNode.RemoveFromProjectFile(); this.ProjectMgr.Tracker.OnItemRemoved(url, VSREMOVEFILEFLAGS.VSREMOVEFILEFLAGS_NoFlags); this.SetProperty((int)__VSHPROPID.VSHPROPID_IsNonMemberItem, true); // Set it as non member item this.ItemNode = new ProjectElement(this.ProjectMgr, null, true); // now we have to set a new ItemNode to indicate that this is virtual node. this.ItemNode.Rename(include); this.ItemNode.SetMetadata(ProjectFileConstants.Name, url); ////this.ProjectMgr.OnItemAdded(this.Parent, this); this.ReDraw(UIHierarchyElement.Icon); // We have to redraw the icon of the node as it is now not a member of the project and should be drawn using a different icon. this.ReDraw(UIHierarchyElement.SccState); // update the SCC state icon. } else if (this.Parent != null) // the project node has no parentNode { // Remove from the Hierarchy this.OnItemDeleted(); this.Parent.RemoveChild(this); this.ItemNode.RemoveFromProjectFile(); } this.ResetProperties(); // refresh property browser... XHelperMethods.RefreshPropertyBrowser(); } return(VSConstants.S_OK); }
// ========================================================================================= // Constructors // ========================================================================================= /// <summary> /// Initializes a new instance of the <see cref="XFolderNode"/> class. /// </summary> /// <param name="root">The root <see cref="XProjectNode"/> that contains this node.</param> /// <param name="directoryPath">Root of the hierarchy.</param> /// <param name="element">The element that contains MSBuild properties.</param> public XFolderNode(XProjectNode root, string directoryPath, ProjectElement element) : this(root, directoryPath, element, false) { }
int IProjectSourceNode.ExcludeFromProject() { new UIThread().MustBeCalledFromUIThread(); XProjectNode projectNode = this.ProjectMgr as XProjectNode; if (projectNode == null || projectNode.IsClosed) { return((int)OleConstants.OLECMDERR_E_NOTSUPPORTED); } else if (this.IsNonMemberItem) { return(VSConstants.S_OK); // do nothing, just ignore it. } using (XHelperMethods.NewWaitCursor()) { // Check out the project file. if (!projectNode.QueryEditProjectFile(false)) { throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED); } // remove children, if any, before removing from the hierarchy for (HierarchyNode child = this.FirstChild; child != null; child = child.NextSibling) { IProjectSourceNode node = child as IProjectSourceNode; if (node != null) { int result = node.ExcludeFromProject(); if (result != VSConstants.S_OK) { return(result); } } } if (projectNode != null && projectNode.ShowAllFilesEnabled && Directory.Exists(this.Url)) { string url = this.Url; this.SetProperty((int)__VSHPROPID.VSHPROPID_IsNonMemberItem, true); this.ItemNode.RemoveFromProjectFile(); this.ItemNode = new ProjectElement(this.ProjectMgr, null, true); // now we have to create a new ItemNode to indicate that this is virtual node. this.ItemNode.Rename(url); this.ItemNode.SetMetadata(ProjectFileConstants.Name, this.Url); this.ReDraw(UIHierarchyElement.Icon); // we have to redraw the icon of the node as it is now not a member of the project and shoul be drawn using a different icon. } else if (this.Parent != null) // the project node has no parentNode { // this is important to make it non member item. otherwise, the multi-selection scenario would // not work if it has any parent child relation. this.SetProperty((int)__VSHPROPID.VSHPROPID_IsNonMemberItem, true); // remove from the hierarchy this.OnItemDeleted(); this.Parent.RemoveChild(this); this.ItemNode.RemoveFromProjectFile(); } // refresh property browser... XHelperMethods.RefreshPropertyBrowser(); } return(VSConstants.S_OK); }
// ========================================================================================= // Constructors // ========================================================================================= /// <summary> /// Initializes a new instance of the <see cref="XSharpFileNode"/> class. /// </summary> /// <param name="root">The project node.</param> /// <param name="e">The project element node.</param> internal XFileNode(XProjectNode root, ProjectElement element) : this(root, element, false) { }
public void Initialize(XProjectNode project, XBuildEventEditorForm editorForm) { this.project = project; this.editorForm = editorForm; }
/// <summary> /// The environment calls this to set the currently selected objects that the property page should show. /// </summary> /// <param name="count">The count of elements in <paramref name="punk"/>.</param> /// <param name="punk">An array of <b>IUnknown</b> objects to show in the property page.</param> /// <remarks> /// We are supposed to cache these objects until we get another call with <paramref name="count"/> = 0. /// Also, the environment is supposed to call this before calling <see cref="IPropertyPage2.Activate"/>, /// but like all things when interacting with Visual Studio, don't trust that and code defensively. /// </remarks> void IPropertyPage.SetObjects(uint count, object[] punk) { if (count == 0) { if (this.project != null) { //this.project.OutputTypeChanged -= this.HandleOutputTypeChanged; this.project = null; } return; } if (punk[0] is ProjectConfig) { List <XProjectConfig> configs = new List <XProjectConfig>(); for (int i = 0; i < count; i++) { XProjectConfig config = (XProjectConfig)punk[i]; if (this.project == null) { this.project = config.ProjectMgr as XProjectNode; //this.project.OutputTypeChanged += this.HandleOutputTypeChanged; } configs.Add(config); } this.projectConfigs = configs.ToArray(); } else if (punk[0] is NodeProperties) { if (this.project == null) { this.project = (punk[0] as NodeProperties).Node.ProjectMgr as XProjectNode; //this.project.OutputTypeChanged += this.HandleOutputTypeChanged; } Dictionary <string, XProjectConfig> configsMap = new Dictionary <string, XProjectConfig>(); for (int i = 0; i < count; i++) { NodeProperties property = (NodeProperties)punk[i]; IVsCfgProvider provider; ErrorHandler.ThrowOnFailure(property.Node.ProjectMgr.GetCfgProvider(out provider)); uint[] expected = new uint[1]; ErrorHandler.ThrowOnFailure(provider.GetCfgs(0, null, expected, null)); if (expected[0] > 0) { XProjectConfig[] configs = new XProjectConfig[expected[0]]; uint[] actual = new uint[1]; int hr = provider.GetCfgs(expected[0], configs, actual, null); if (hr != 0) { Marshal.ThrowExceptionForHR(hr); } foreach (XProjectConfig config in configs) { if (!configsMap.ContainsKey(config.ConfigName)) { configsMap.Add(config.ConfigName, config); } } } } if (configsMap.Count > 0) { if (this.projectConfigs == null) { this.projectConfigs = new XProjectConfig[configsMap.Keys.Count]; } configsMap.Values.CopyTo(this.projectConfigs, 0); } } if (this.active && this.project != null) { this.PropertyPagePanel.BindProperties(); this.IsDirty = false; } }
/// <summary> /// When building a project in VS, the configuration of referenced projects cannot be determined /// by MSBuild or from within an MSBuild task. So we'll get them from the VS project system here. /// </summary> /// <param name="project">The project where the properties are being defined; also the project /// whose references are being examined.</param> internal static void DefineProjectReferenceConfigurations(XProjectNode project) { StringBuilder configList = new StringBuilder(); IVsSolutionBuildManager solutionBuildManager = XHelperMethods.GetService <IVsSolutionBuildManager, SVsSolutionBuildManager>(project.Site); List <ProjectReferenceNode> referenceNodes = new List <ProjectReferenceNode>(); project.FindNodesOfType(referenceNodes); foreach (ProjectReferenceNode referenceNode in referenceNodes) { try { IVsHierarchy hierarchy = VsShellUtilities.GetHierarchy(referenceNode.ProjectMgr.Site, referenceNode.ReferencedProjectGuid); string configuration = null; IVsProjectCfg2 projectCfg2 = null; IVsProjectCfg[] projectCfgArray = new IVsProjectCfg[1]; // this can fail for some reason... this code was copied from Wix and probably isn't stable yet. // this routine is called from InvokeMSBuild and we don't want that to fix because of // some bug here, so this code is surrounded by try/catch until we figure this out int hr = solutionBuildManager.FindActiveProjectCfg(IntPtr.Zero, IntPtr.Zero, hierarchy, projectCfgArray); ErrorHandler.ThrowOnFailure(hr); projectCfg2 = projectCfgArray[0] as IVsProjectCfg2; if (projectCfg2 != null) { hr = projectCfg2.get_DisplayName(out configuration); if (hr != 0) { Marshal.ThrowExceptionForHR(hr); } } if (configuration != null) { if (configList.Length > 0) { configList.Append(';'); } configList.Append(referenceNode.ReferencedProjectName); configList.Append('='); configList.Append(configuration); } } catch (Exception) { ; } } if (configList.Length > 0) { project.BuildProject.SetGlobalProperty("VSProjectConfigurations", configList.ToString()); } }
public XFileNode(XProjectNode root, ProjectElement element, bool isNonMemberItem) : base(root, element) { this.isNonMemberItem = isNonMemberItem; }
/// <summary> /// Excludes the file and folder items from their corresponding maps if they are part of the build. /// </summary> /// <param name="project">The project to modify.</param> /// <param name="fileList">List containing relative files paths.</param> /// <param name="folderList">List containing relative folder paths.</param> private static void ExcludeProjectBuildItems(XProjectNode project, IList <string> fileList, IList <string> folderList) { var projectItems = project.BuildProject.Items; if (projectItems == null) { return; // do nothing, just ignore it. } else if (fileList == null && folderList == null) { throw new ArgumentNullException("folderList"); } // we need these maps because we need to have both lowercase and actual case path information. // we use lower case paths for case-insesitive search of file entries and actual paths for // creating hierarchy node. if we don't do that, we will end up with duplicate nodes when the // case of path in .vnproj file doesn't match with the actual file path on the disk. IDictionary <string, string> folderMap = null; IDictionary <string, string> fileMap = null; if (folderList != null) { folderMap = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); foreach (string folder in folderList) { folderMap.Add(folder, folder); } } if (fileList != null) { fileMap = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); foreach (string file in fileList) { fileMap.Add(file, file); } } foreach (var buildItem in projectItems) { if (folderMap != null && folderMap.Count > 0 && String.Equals(buildItem.ItemType, ProjectFileConstants.Folder, StringComparison.OrdinalIgnoreCase)) { string relativePath = buildItem.EvaluatedInclude; if (Path.IsPathRooted(relativePath)) // if not the relative path, make it relative { relativePath = XHelperMethods.GetRelativePath(project.ProjectFolder, relativePath); } if (folderMap.ContainsKey(relativePath)) { folderList.Remove(folderMap[relativePath]); // remove it from the actual list. folderMap.Remove(relativePath); } } else if (fileMap != null && fileMap.Count > 0 && XSharpFileType.IsProjectItemType(buildItem)) { string relativePath = buildItem.EvaluatedInclude; if (Path.IsPathRooted(relativePath)) // if not the relative path, make it relative { relativePath = XHelperMethods.GetRelativePath(project.ProjectFolder, relativePath); } if (fileMap.ContainsKey(relativePath)) { fileList.Remove(fileMap[relativePath]); // remove it from the actual list. fileMap.Remove(relativePath); } } } }