예제 #1
0
        protected override ProjectNode CreateProject()
        {
            ProjectNode         project            = new NemerleProjectNode(Package);
            IOleServiceProvider oleServiceProvider = Package.GetService <IOleServiceProvider>();

            project.SetSite(oleServiceProvider);

            return(project);
        }
예제 #2
0
        private static void AssertOuputFile(GeneralPropertyPage page, string expectedAssemblyName, OutputType outputType)
        {
            FieldInfo outputTypeInfo = typeof(GeneralPropertyPage).GetField("outputType", BindingFlags.NonPublic | BindingFlags.Instance);

            outputTypeInfo.SetValue(page, outputType);
            Assert.AreEqual <string>(outputType.ToString(), outputTypeInfo.GetValue(page).ToString());
            string expectedOutputFile = expectedAssemblyName + NemerleProjectNode.GetOuputExtension(outputType);

            Assert.AreEqual <string>(expectedOutputFile, page.OutputFile);
        }
예제 #3
0
        public override void RemoveChild(HierarchyNode node)
        {
            NemerleProjectNode project = ProjectMgr as NemerleProjectNode;

            if (project != null)
            {
                ReferenceNode referenceNode = (ReferenceNode)node;
                //TODO: Удалить из списка макро-сборок
                project.ProjectInfo.RemoveMacroAssembly(referenceNode);
            }

            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            ProjectMgr.ItemIdMap.Remove(node);

            HierarchyNode last = null;

            for (HierarchyNode n = this.FirstChild; n != null; n = n.NextSibling)
            {
                if (n == node)
                {
                    if (last != null)
                    {
                        last.NextSibling = n.NextSibling;
                    }

                    if (n == this.LastChild)
                    {
                        if (last == this.LastChild)
                        {
                            this.LastChild = null;
                        }
                        else
                        {
                            this.LastChild = last;
                        }
                    }

                    if (n == this.FirstChild)
                    {
                        this.FirstChild = n.NextSibling;
                    }

                    return;
                }

                last = n;
            }

            throw new InvalidOperationException("Node not found");
        }
        public override void RemoveChild(HierarchyNode node)
        {
            base.RemoveChild(node);

            NemerleProjectNode project = ProjectMgr as NemerleProjectNode;

            if (project != null)
            {
                ReferenceNode referenceNode = (ReferenceNode)node;
                project.ProjectInfo.RemoveAssembly(referenceNode);
            }
        }
예제 #5
0
        /// <summary>
        /// Handles command status on source a node. Should be overridden by descendant nodes.
        /// </summary>
        /// <param name="node">A HierarchyNode that implements the IProjectSourceNode interface.</param>
        /// <param name="guidCmdGroup">A unique identifier of the command group. The pguidCmdGroup parameter can be NULL to specify the standard group.</param>
        /// <param name="cmd">The command to query status for.</param>
        /// <param name="result">An out parameter specifying the QueryStatusResult of the command.</param>
        /// <param name="returnCode">If the method succeeds, it returns S_OK. If it fails, it returns an error code.</param>
        /// <returns>Returns true if the status request is handled, false otherwise.</returns>
        internal static bool QueryStatusOnProjectSourceNode(HierarchyNode node, Guid guidCmdGroup, uint cmd, ref QueryStatusResult result, out int returnCode)
        {
            if (guidCmdGroup == VsMenus.guidStandardCommandSet2K)
            {
                IProjectSourceNode sourceNode = node as IProjectSourceNode;
                switch ((VsCommands2K)cmd)
                {
                case VsCommands2K.SHOWALLFILES:
                {
                    NemerleProjectNode projectNode = node.ProjectMgr as NemerleProjectNode;
                    result |= QueryStatusResult.SUPPORTED | QueryStatusResult.ENABLED;
                    if (projectNode != null && projectNode.ShowAllFilesEnabled)
                    {
                        result |= QueryStatusResult.LATCHED;                                         // it should be displayed as pressed
                    }
                    returnCode = VSConstants.S_OK;
                    return(true);                                    // handled.
                }

                case VsCommands2K.INCLUDEINPROJECT:
                    // if it is a non member item node, the we support "Include In Project" command
                    if (sourceNode != null && sourceNode.IsNonMemberItem)
                    {
                        result    |= QueryStatusResult.SUPPORTED | QueryStatusResult.ENABLED;
                        returnCode = VSConstants.S_OK;
                        return(true);                                // handled.
                    }

                    break;

                case VsCommands2K.EXCLUDEFROMPROJECT:
                    // if it is a non member item node, then we don't support "Exclude From Project" command
                    if (sourceNode != null && sourceNode.IsNonMemberItem)
                    {
                        returnCode = (int)OleConstants.MSOCMDERR_E_NOTSUPPORTED;
                        return(true);                                // handled.
                    }

                    break;

                case OpenFolderInExplorerCmdId:
                    result    |= QueryStatusResult.SUPPORTED | QueryStatusResult.ENABLED;
                    returnCode = VSConstants.S_OK;
                    return(true);
                }
            }

            // just an arbitrary value, it doesn't matter if method hasn't handled the request
            returnCode = VSConstants.S_FALSE;

            // not handled
            return(false);
        }
        public override void AddChild(HierarchyNode node)
        {
            base.AddChild(node);

            NemerleProjectNode project = ProjectMgr as NemerleProjectNode;

            if (project != null && project.ProjectInfo.IsLoaded)
            {
                ReferenceNode referenceNode = (ReferenceNode)node;
                project.ProjectInfo.AddAssembly(referenceNode);
            }
        }
예제 #7
0
        internal static void AddNonMemberItems(NemerleProjectNode project)
        {
            IList <string> files   = new List <string>();
            IList <string> folders = new List <string>();

            // obtain the list of files and folders under the project folder.
            GetRelativeFileSystemEntries(project.ProjectFolder, null, files, folders);

            // exclude the items which are the part of the build.
            ExcludeProjectBuildItems(project, files, folders);

            AddNonMemberFolderItems(project, folders);
            AddNonMemberFileItems(project, files);
        }
예제 #8
0
        int IProjectSourceNode.IncludeInProject()
        {
            NemerleProjectNode projectNode = ProjectMgr as NemerleProjectNode;

            if (projectNode == null || projectNode.IsClosed)
            {
                return((int)OleConstants.OLECMDERR_E_NOTSUPPORTED);
            }

            if (!IsNonMemberItem)
            {
                return(VSConstants.S_OK);
            }

            ((NemerlePackage)ProjectMgr.Package).SetWaitCursor();

            // Check out the project file.
            if (!projectNode.QueryEditProjectFile(false))
            {
                throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
            }

            HierarchyHelpers.EnsureParentFolderIncluded(this);

            SetProperty((int)__VSHPROPID.VSHPROPID_IsNonMemberItem, false);

            ItemNode = projectNode.CreateMsBuildFileProjectElement(Url);
            ProjectMgr.Tracker.OnItemAdded(Url, VSADDFILEFLAGS.VSADDFILEFLAGS_NoFlags);

            var proj = ProjectInfo.FindProject(ProjectMgr);

            if (proj != null)
            {
                proj.AddSource(this.Url);
            }

            //projectNode.OnItemAdded(Parent, 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.
            ReDraw(UIHierarchyElement.SccState);         // update the SCC state icon.

            ResetProperties();

            HierarchyHelpers.RefreshPropertyBrowser(this);

            return(VSConstants.S_OK);
        }
예제 #9
0
        public ProjectInfo(
            NemerleProjectNode projectNode,
            IVsHierarchy hierarchy,
            NemerleLanguageService languageService,
            string fileName,
            string location
            )
        {
            ErrorHelper.ThrowIsNull(languageService, "languageService");
            ErrorHelper.ThrowIsNull(projectNode, "projectNode");
            ErrorHelper.ThrowIsNull(hierarchy, "hierarchy");
            Debug.Assert(projectNode.Site != null);

            LanguageService = languageService;
            _errorList      = new ErrorListProvider(languageService.Site);
            ProjectFullPath = Path.GetFullPath(fileName);
            _projectNode    = projectNode;
            _hierarchy      = hierarchy;

            _engine = EngineFactory.Create(this, new TraceWriter(), false);             // it enables parser working.

            Engine.TypedtreeCreated += delegate
            {
                _buildTypedtreeCount++;
                AstToolWindow tool = AstToolWindow.AstTool;
                if (tool != null)
                {
                    tool.BuildTypedtreeCount = _buildTypedtreeCount;
                }
            };

            if (!string.IsNullOrEmpty(location))
            {
                _projectLocation = location;
            }
            else
            {
                _projectLocation = Path.GetDirectoryName(fileName);
            }

            if (!_projectLocation.EndsWith("\\"))
            {
                _projectLocation += "\\";
            }
        }
예제 #10
0
        /// <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)
        {
            NemerleProjectNode projectNode = ProjectMgr as NemerleProjectNode;

            if (projectNode == null || projectNode.IsClosed)
            {
                return;
            }

            ItemNode = projectNode.CreateMsBuildFolderProjectElement(Url);
            SetProperty((int)__VSHPROPID.VSHPROPID_IsNonMemberItem, false);
            if (recursive)
            {
                for (HierarchyNode node = FirstChild; node != null; node = node.NextSibling)
                {
                    IProjectSourceNode sourceNode = node as IProjectSourceNode;
                    if (sourceNode != null)
                    {
                        sourceNode.IncludeInProject(true);
                    }
                }
            }
        }
예제 #11
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);
        }
예제 #12
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);
        }
예제 #13
0
        public override void AddChild(HierarchyNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            // make sure the node is in the map.
            Object nodeWithSameID = this.ProjectMgr.ItemIdMap[node.ID];

            if (!Object.ReferenceEquals(node, nodeWithSameID as HierarchyNode))
            {
                if (nodeWithSameID == null && node.ID <= this.ProjectMgr.ItemIdMap.Count)
                {
                    // reuse our hierarchy id if possible.
                    this.ProjectMgr.ItemIdMap.SetAt(node.ID, this);
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }

            HierarchyNode previous = null;

            for (HierarchyNode n = this.FirstChild; n != null; n = n.NextSibling)
            {
                if (this.ProjectMgr.CompareNodes(node, n) > 0)
                {
                    break;
                }

                previous = n;
            }

            // insert "node" after "previous".
            if (previous != null)
            {
                node.NextSibling     = previous.NextSibling;
                previous.NextSibling = node;

                if (previous == this.LastChild)
                {
                    this.LastChild = node;
                }
            }
            else
            {
                if (this.LastChild == null)
                {
                    this.LastChild = node;
                }

                node.NextSibling = this.FirstChild;
                this.FirstChild  = node;
            }

            node.Parent = this;
            this.OnItemAdded(this, node);

            NemerleProjectNode project = ProjectMgr as NemerleProjectNode;

            if (project != null)
            {
                ReferenceNode referenceNode = (ReferenceNode)node;
                //TODO: Добавить в список макро-сборок
                project.ProjectInfo.AddMacroAssembly(referenceNode);
            }
        }