Esempio n. 1
0
        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();
                }
            }
        }
 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));
     }
 }
Esempio n. 3
0
        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();
            }
        }
        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);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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);
        }