public override int OnAfterRenameFiles(int cProjects, int cFiles, IVsProject[] projects, int[] firstIndices, string[] oldFileNames, string[] newFileNames, VSRENAMEFILEFLAGS[] flags)
        {
            //Get the current value of the MainFile Property
            string currentMainFile    = this.project.GetProjectProperty(PythonProjectFileConstants.MainFile, true);
            string fullPathToMainFile = Path.Combine(Path.GetDirectoryName(this.project.BaseURI.Uri.LocalPath), currentMainFile);

            //Investigate all of the oldFileNames if they belong to the current project and if they are equal to the current MainFile
            int index = 0;

            foreach (string oldfile in oldFileNames)
            {
                //Compare this project with the project that the old file belongs to
                IVsProject belongsToProject = projects[firstIndices[index]];
                if (Utilities.IsSameComObject(belongsToProject, this.project))
                {
                    //Compare the files and update the MainFile Property if the currentMainFile is an old file
                    if (NativeMethods.IsSamePath(oldfile, fullPathToMainFile))
                    {
                        //Get the newfilename and update the MainFile property
                        string         newfilename = newFileNames[index];
                        PythonFileNode node        = this.project.FindChild(newfilename) as PythonFileNode;
                        if (node == null)
                        {
                            throw new InvalidOperationException("Could not find the PythonFileNode object");
                        }
                        this.project.SetProjectProperty(PythonProjectFileConstants.MainFile, node.GetRelativePath());
                        break;
                    }
                }

                index++;
            }

            return(VSConstants.S_OK);
        }
コード例 #2
0
        /// <summary>
        /// Create a file node based on an msbuild item.
        /// </summary>
        /// <param name="item">The msbuild item to be analyzed</param>
        /// <returns>PythonFileNode or FileNode</returns>
        public override FileNode CreateFileNode(ProjectElement item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            string         include = item.GetMetadata(ProjectFileConstants.Include);
            PythonFileNode newNode = new PythonFileNode(this, item);

            newNode.OleServiceProvider.AddService(typeof(EnvDTE.Project), new OleServiceProvider.ServiceCreatorCallback(this.CreateServices), false);
            newNode.OleServiceProvider.AddService(typeof(EnvDTE.ProjectItem), newNode.ServiceCreator, false);
            if (!string.IsNullOrEmpty(include) && Path.GetExtension(include).Equals(".xaml", StringComparison.OrdinalIgnoreCase))
            {
                //Create a DesignerContext for the XAML designer for this file
                newNode.OleServiceProvider.AddService(typeof(DesignerContext), newNode.ServiceCreator, false);
            }
            newNode.OleServiceProvider.AddService(typeof(VSLangProj.VSProject), new OleServiceProvider.ServiceCreatorCallback(this.CreateServices), false);
            if (IsCodeFile(include))
            {
                newNode.OleServiceProvider.AddService(
                    typeof(SVSMDCodeDomProvider), new OleServiceProvider.ServiceCreatorCallback(this.CreateServices), false);
            }

            return(newNode);
        }
コード例 #3
0
        public override int OnElementValueChanged(uint elementid, object varValueOld, object varValueNew)
        {
            int hr = VSConstants.S_OK;

            if (elementid == VSConstants.DocumentFrame)
            {
                IVsWindowFrame pWindowFrame = varValueOld as IVsWindowFrame;
                if (pWindowFrame != null)
                {
                    object document;
                    // Get the name of the document associated with the old window frame
                    hr = pWindowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_pszMkDocument, out document);
                    if (ErrorHandler.Succeeded(hr))
                    {
                        uint         itemid;
                        IVsHierarchy hier = projMgr as IVsHierarchy;
                        hr = hier.ParseCanonicalName((string)document, out itemid);
                        PythonFileNode node = projMgr.NodeFromItemId(itemid) as PythonFileNode;
                        if (null != node)
                        {
                            node.RunGenerator();
                        }
                    }
                }
            }

            return(hr);
        }
        public override int OnAfterAddFilesEx(int cProjects, int cFiles, IVsProject[] projects, int[] firstIndices, string[] newFileNames, VSADDFILEFLAGS[] flags)
        {
            //Get the current value of the MainFile Property
            string currentMainFile = this.project.GetProjectProperty(PythonProjectFileConstants.MainFile, true);

            if (!string.IsNullOrEmpty(currentMainFile))
            {
                //No need for further operation since MainFile is already set
                return(VSConstants.S_OK);
            }

            string fullPathToMainFile = Path.Combine(Path.GetDirectoryName(this.project.BaseURI.Uri.LocalPath), currentMainFile);

            //Investigate all of the newFileNames if they belong to the current project and set the first pythonFileNode found equal to MainFile
            int index = 0;

            foreach (string newfile in newFileNames)
            {
                //Compare this project with the project that the new file belongs to
                IVsProject belongsToProject = projects[firstIndices[index]];
                if (Utilities.IsSameComObject(belongsToProject, this.project))
                {
                    //If the newfile is a python filenode we willl map this file to the MainFile property
                    PythonFileNode filenode = project.FindChild(newfile) as PythonFileNode;
                    if (filenode != null)
                    {
                        this.project.SetProjectProperty(PythonProjectFileConstants.MainFile, filenode.GetRelativePath());
                        break;
                    }
                }

                index++;
            }

            return(VSConstants.S_OK);
        }
コード例 #5
0
        /// <summary>
        /// Create a file node based on an msbuild item.
        /// </summary>
        /// <param name="item">The msbuild item to be analyzed</param>
        /// <returns>PythonFileNode or FileNode</returns>
        public override FileNode CreateFileNode(ProjectElement item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            string include = item.GetMetadata(ProjectFileConstants.Include);
            PythonFileNode newNode = new PythonFileNode(this, item);
            newNode.OleServiceProvider.AddService(typeof(EnvDTE.Project), new OleServiceProvider.ServiceCreatorCallback(this.CreateServices), false);
            newNode.OleServiceProvider.AddService(typeof(EnvDTE.ProjectItem), newNode.ServiceCreator, false);
            if (!string.IsNullOrEmpty(include) && Path.GetExtension(include).Equals(".xaml", StringComparison.OrdinalIgnoreCase))
            {
                //Create a DesignerContext for the XAML designer for this file
                newNode.OleServiceProvider.AddService(typeof(DesignerContext), newNode.ServiceCreator, false);
            }
            newNode.OleServiceProvider.AddService(typeof(VSLangProj.VSProject), new OleServiceProvider.ServiceCreatorCallback(this.CreateServices), false);
            if (IsCodeFile(include))
            {
                newNode.OleServiceProvider.AddService(
                    typeof(SVSMDCodeDomProvider), new OleServiceProvider.ServiceCreatorCallback(this.CreateServices), false);
            }

            return newNode;
        }