Пример #1
0
        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
        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);
        }