/// <summary> /// Creates an MSBuild ProjectElement for a file. /// </summary> /// <param name="file">The path to the file.</param> /// <returns>An instance of the <see cref="ProjectElement"/> class.</returns> protected override ProjectElement AddFileToMsBuild(string file) { if (file == null) { throw new ArgumentNullException("file"); } string itemPath = PackageUtilities.MakeRelativeIfRooted(file, this.BaseURI); if (Path.IsPathRooted(itemPath)) { throw new ArgumentException("Cannot add item with full path.", "file"); } ProjectElement newItem = this.CreateMsBuildFileItem(itemPath, ProjectFileConstants.Content); if (MultiverseInterfaceProjectNode.IsPythonFile(itemPath)) { newItem.SetMetadata(ProjectFileConstants.SubType, MultiverseInterfaceSubType.Code); } else if (MultiverseInterfaceProjectNode.IsFrameXmlFile(itemPath)) { newItem.SetMetadata(ProjectFileConstants.SubType, MultiverseInterfaceSubType.Frame); } else if (MultiverseInterfaceProjectNode.IsTableOfContentsFile(itemPath)) { newItem.SetMetadata(ProjectFileConstants.SubType, MultiverseInterfaceSubType.TableOfContents); } return(newItem); }
/* /// <summary> * /// Would like to treat files added to the project as "links". However, the MPF does not support this. * /// Therefore going to craft own implementation. Unfortunately that means that these functions * /// need to be overridden, which would not necessarily be considered because they are too "low-level", but * /// there seems no other way to do this, i.e. there is not enough granularity or possiblity to override specifics * /// in the base implementation. To reduce impact when new versions of the SDK become available the methods * /// in the base classes have been copied here with specific changes made. * /// * /// If a new version of the SDK comes which still does not implement links then copy these methods again * /// and make the changes. * /// * /// If links are ever implemented in the SDK then delete the following methods completely and adjust appropriately. * /// * /// Changes: The bits associated with the file system have been removed. * /// </summary> * public override int AddItemWithSpecific(uint itemIdLoc, VSADDITEMOPERATION op, string itemName, uint filesToOpen, string[] files, System.IntPtr dlgOwner, uint editorFlags, ref System.Guid editorType, string physicalView, ref System.Guid logicalView, VSADDRESULT[] result) * { * if ( files == null || result == null || files.Length == 0 || result.Length == 0 ) * return VSConstants.E_INVALIDARG; * string[] actualFiles = new string[files.Length]; * * // Locate the node to be the container node for the file(s) being added. * HierarchyNode parentNode = NodeFromItemId(itemIdLoc); * if ( parentNode == null ) * return VSConstants.E_INVALIDARG; * * while ( !(parentNode is ProjectNode) && !(parentNode is FolderNode) && (!CanFileNodesHaveChilds || !(parentNode is FileNode)) ) * { * parentNode = parentNode.Parent; * } * * // Get the directory for the node that is the parent of the item. * * string baseDirectory = GetBaseDirectoryForAddingFiles(parentNode); * if ( string.IsNullOrEmpty(baseDirectory) ) * return VSConstants.E_FAIL; * * // This contains the path to the file as if it was directly part of the project. * // These are required to ensure that the general project continues to recognise the files. * * List<string> projectPaths = new List<string>(); * for ( int index = 0; index < files.Length; index++ ) * { * string projectPath = Path.Combine(baseDirectory, Path.GetFileName(files[index])); * projectPaths.Add(projectPath); * } * * // Ask tracker objects if we can add files. * * VSQUERYADDFILEFLAGS[] flags = GetQueryAddFileFlags(files); * if ( !Tracker.CanAddItems(projectPaths.ToArray(), flags) ) * return VSConstants.E_FAIL; * * // Ensure that the project can be updated. * * if ( !ProjectMgr.QueryEditProjectFile(false) ) * throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED); * * // Add the files to the hierarchy. * * int actualFilesAddedIndex = 0; * for ( int index = 0; index < projectPaths.Count; index++ ) * { * result[0] = VSADDRESULT.ADDRESULT_Failure; * string filePath = files[index]; * string projectPath = projectPaths[index]; * * HierarchyNode child = FindChild(projectPath); * if ( child != null ) * { * // If the file to be added is an existing file part of the hierarchy then continue. * * if ( Microsoft.Build.BuildEngine.NativeMethods.IsSamePath(filePath, projectPath) ) * { * result[0] = VSADDRESULT.ADDRESULT_Cancel; * continue; * } * else * { * int canOverWriteExistingItem = CanOverwriteExistingItem(filePath, projectPath); * if ( canOverWriteExistingItem == (int) OleConstants.OLECMDERR_E_CANCELED ) * { * result[0] = VSADDRESULT.ADDRESULT_Cancel; * return canOverWriteExistingItem; * } * } * } * * // Add new node. * * AddNewFileNodeToHierarchy(parentNode, filePath); * UpdateNewFileNode(FindChild(filePath), projectPath); * result[0] = VSADDRESULT.ADDRESULT_Success; * actualFiles[actualFilesAddedIndex++] = projectPath; * } * * // Notify listeners that items were appended. * * if ( actualFilesAddedIndex > 0 ) * parentNode.OnItemsAppended(parentNode); * * // Open the files if required. * * if ( actualFiles.Length <= filesToOpen ) * { * for ( int index = 0; index < filesToOpen; index++ ) * { * string name = actualFiles[index]; * if ( !string.IsNullOrEmpty(name) ) * { * HierarchyNode child = FindChild(name); * if ( child != null ) * { * IVsWindowFrame frame; * if ( editorType == System.Guid.Empty ) * { * System.Guid view = System.Guid.Empty; * ErrorHandler.ThrowOnFailure(this.OpenItem(child.ID, ref view, System.IntPtr.Zero, out frame)); * } * else * { * ErrorHandler.ThrowOnFailure(this.OpenItemWithSpecific(child.ID, editorFlags, ref editorType, physicalView, ref logicalView, System.IntPtr.Zero, out frame)); * } * * // Show the window frame in the UI and make it the active window. * * if ( frame != null ) * ErrorHandler.ThrowOnFailure(frame.Show()); * } * } * } * } * * return VSConstants.S_OK; * } */ protected virtual void UpdateNewFileNode(HierarchyNode node, string projectPath) { // Update the properties of the build element. ProjectElement element = node.ItemNode; element.SetMetadata(Constants.Project.Item.SubType, null); element.SetMetadata(Constants.Project.Item.Link, FilePath.GetRelativePath(projectPath, BaseURI.AbsoluteUrl)); }
protected override void BindReferenceData() { if (ItemNode == null || ItemNode.Item == null) { ProjectElement element = new ProjectElement(ProjectManager, ProjectRelativeFilePath, DartProjectFileConstants.JarReference); // Set the basic information about this reference element.SetMetadata(DartProjectFileConstants.IncludeInBuild, true.ToString()); element.SetMetadata(ProjectFileConstants.Private, false.ToString()); ItemNode = element; } }
protected override ProjectElement AddFolderToMSBuild(string folder, string itemType) { if (itemType == ProjectFileConstants.Folder) { ProjectElement folderElement = new ProjectElement(this, null, true); folderElement.Rename(folder); folderElement.SetMetadata(ProjectFileConstants.Name, folder); folderElement.SetMetadata(ProjectFileConstants.BuildAction, itemType); return(folderElement); } else { return(base.AddFolderToMSBuild(folder, itemType)); } }
//===================================================================== /// <summary> /// This is used to set the Image project element metadata /// </summary> /// <param name="element">The project element to update</param> public static void SetImageMetadata(this ProjectElement element) { string baseName = Path.GetFileNameWithoutExtension(element.GetMetadata(ProjectFileConstants.Include)); if (String.IsNullOrEmpty(element.GetMetadata(SandcastleBuildItemMetadata.ImageId))) { element.SetMetadata(SandcastleBuildItemMetadata.ImageId, baseName); } if (String.IsNullOrEmpty(element.GetMetadata(SandcastleBuildItemMetadata.AlternateText))) { baseName = baseName.Replace("_", " "); element.SetMetadata(SandcastleBuildItemMetadata.AlternateText, reInsertSpaces.Replace(baseName, " $&").Trim()); } }
private ProjectElement CreateProjectElement() { ProjectElement element = new ProjectElement(ProjectMgr, m_name, "ConfigReference"); element.SetMetadata("HintPath", m_hintPath); return(element); }
private static void AddNonMemberFileItems(WixProjectNode project, IList <string> fileList) { if (fileList == null) { throw new ArgumentNullException("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; } WixFolderNode 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 = parentNode.FindChild(childNodeId); if (childNode == null) { if (topFolderNode == null) { topFolderNode = parentNode as WixFolderNode; 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(); } } }
private static void AddNonMemberFileItems(ProjectNode project, IEnumerable<string> fileList) { ErrorHelper.ThrowIsNull(fileList, "fileList"); foreach (string fileKey in fileList) { HierarchyNode parentNode = project; string[] pathItems = fileKey.Split(new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }); if (StringComparer.OrdinalIgnoreCase.Equals(fileKey, project.ProjectFile)) continue; NemerleFolderNode 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 = parentNode.FindChild(childNodeId); if (childNode == null) { if (topFolderNode == null) { topFolderNode = parentNode as NemerleFolderNode; 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(); } }
public virtual EnvDTE.Project AddFromTemplate(string fileName, string destination, string projectName) { bool isVSTemplate = Utilities.IsTemplateFile(fileName); NestedProjectNode newNode = null; ThreadHelper.ThrowIfNotOnUIThread(); if (isVSTemplate) { // Get the wizard to run, we will get called again and use the alternate code path ProjectElement newElement = new ProjectElement(this.node.ProjectMgr, System.IO.Path.Combine(destination, projectName), ProjectFileConstants.SubProject); newElement.SetMetadata(ProjectFileConstants.Template, fileName); ((ProjectContainerNode)this.node.ProjectMgr).RunVsTemplateWizard(newElement, false); } else { if ((String.IsNullOrEmpty(System.IO.Path.GetExtension(projectName)))) { string targetExtension = System.IO.Path.GetExtension(fileName); projectName = System.IO.Path.ChangeExtension(projectName, targetExtension); } ProjectContainerNode projectContainer = (ProjectContainerNode)this.node.ProjectMgr; newNode = projectContainer.AddNestedProjectFromTemplate(fileName, destination, projectName, null, __VSCREATEPROJFLAGS.CPF_NOTINSLNEXPLR | __VSCREATEPROJFLAGS.CPF_SILENT | __VSCREATEPROJFLAGS.CPF_CLONEFILE); } if (newNode == null) { return(null); } // Now that the sub project was created, get its extensibility object so we can return it object newProject = null; if (ErrorHandler.Succeeded(newNode.NestedHierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out newProject))) { return(newProject as EnvDTE.Project); } else { return(null); } }
internal void UpdateFolderBuildAction(JavaFolderNode folderNode, FolderBuildAction buildAction) { string existingBuildAction = folderNode.ItemNode.ItemName; if (string.IsNullOrEmpty(existingBuildAction)) { existingBuildAction = FolderBuildAction.Folder.ToString(); } if (string.Equals(existingBuildAction, buildAction.ToString())) { return; } if (buildAction == FolderBuildAction.Folder && !folderNode.ItemNode.IsVirtual && folderNode.ItemNode.Item.DirectMetadataCount == 0) { // remove <Folder /> elements from the project as long as they don't have any direct metadata (xml child elements) ProjectElement updatedElement = new ProjectElement(this, null, true); updatedElement.Rename(folderNode.ItemNode.Item.EvaluatedInclude); updatedElement.SetMetadata(ProjectFileConstants.Name, folderNode.ItemNode.Item.EvaluatedInclude); ProjectElement oldElement = folderNode.ItemNode; folderNode.ItemNode = updatedElement; oldElement.RemoveFromProjectFile(); } else if (!folderNode.ItemNode.IsVirtual) { folderNode.ItemNode.ItemName = buildAction.ToString(); } else { ProjectElement updatedElement = AddFolderToMSBuild(folderNode.VirtualNodeName, buildAction.ToString()); folderNode.ItemNode = updatedElement; } folderNode.Redraw(UIHierarchyElements.Icon); }
int IProjectSourceNode.ExcludeFromProject() { NemerleProjectNode projectNode = ProjectMgr as NemerleProjectNode; if (projectNode == null || projectNode.IsClosed) { return((int)OleConstants.OLECMDERR_E_NOTSUPPORTED); } if (IsNonMemberItem) { return(VSConstants.S_OK); // do nothing, just ignore it. } ((NemerlePackage)ProjectMgr.Package).SetWaitCursor(); // 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 = FirstChild; child != null; child = child.NextSibling) { IProjectSourceNode node = child as IProjectSourceNode; if (node == null) { continue; } int result = node.ExcludeFromProject(); if (result != VSConstants.S_OK) { return(result); } } if (projectNode.ShowAllFilesEnabled && Directory.Exists(Url)) { string url = Url; SetProperty((int)__VSHPROPID.VSHPROPID_IsNonMemberItem, true); ItemNode.RemoveFromProjectFile(); ItemNode = new ProjectElement(ProjectMgr, null, true); // now we have to create a new ItemNode to indicate that this is virtual node. ItemNode.Rename(url); ItemNode.SetMetadata(ProjectFileConstants.Name, Url); 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 (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. SetProperty((int)__VSHPROPID.VSHPROPID_IsNonMemberItem, true); // remove from the hierarchy OnItemDeleted(); Parent.RemoveChild(this); ItemNode.RemoveFromProjectFile(); } HierarchyHelpers.RefreshPropertyBrowser(this); return(VSConstants.S_OK); }
int IProjectSourceNode.ExcludeFromProject() { if (ProjectMgr == null || ProjectMgr.IsClosed) { return((int)OleConstants.OLECMDERR_E_NOTSUPPORTED); } if (IsNonMemberItem) { return(VSConstants.S_OK); // do nothing, just ignore it. } ((NemerlePackage)ProjectMgr.Package).SetWaitCursor(); // Ask Document tracker listeners if we can remove the item. { // just to limit the scope. string documentToRemove = GetMkDocument(); string[] filesToBeDeleted = new[] { documentToRemove }; VSQUERYREMOVEFILEFLAGS[] queryRemoveFlags = GetQueryRemoveFileFlags(filesToBeDeleted); if (!ProjectMgr.Tracker.CanRemoveItems(filesToBeDeleted, queryRemoveFlags)) { return((int)OleConstants.OLECMDERR_E_CANCELED); } // Close the document if it has a manager. DocumentManager manager = GetDocumentManager(); if (manager != null) { if (manager.Close(__FRAMECLOSE.FRAMECLOSE_PromptSave) == VSConstants.E_ABORT) { return(VSConstants.OLE_E_PROMPTSAVECANCELLED); } } if (!ProjectMgr.QueryEditProjectFile(false)) { throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED); } } // close the document window if open. CloseDocumentWindow(this); NemerleProjectNode projectNode = ProjectMgr as NemerleProjectNode; if (projectNode != null && projectNode.ShowAllFilesEnabled && File.Exists(Url)) { string url = Url; // need to store before removing the node. ItemNode.RemoveFromProjectFile(); ProjectMgr.Tracker.OnItemRemoved(url, VSREMOVEFILEFLAGS.VSREMOVEFILEFLAGS_NoFlags); SetProperty((int)__VSHPROPID.VSHPROPID_IsNonMemberItem, true); // Set it as non member item ItemNode = new ProjectElement(ProjectMgr, null, true); // now we have to set a new ItemNode to indicate that this is virtual node. ItemNode.Rename(url); ItemNode.SetMetadata(ProjectFileConstants.Name, url); //ProjectMgr.OnItemDeleted(); var proj = ProjectInfo.FindProject(ProjectMgr); if (proj != null) { proj.RemoveSource(this.Url); } 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. ReDraw(UIHierarchyElement.SccState); // update the SCC state icon. } else if (Parent != null) // the project node has no parentNode { // Remove from the Hierarchy OnItemDeleted(); Parent.RemoveChild(this); ItemNode.RemoveFromProjectFile(); } ResetProperties(); HierarchyHelpers.RefreshPropertyBrowser(this); return(VSConstants.S_OK); }