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(FoxProProjectFileConstants.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];
                        FoxProFileNode node        = this.project.FindChild(newfilename) as FoxProFileNode;
                        if (node == null)
                        {
                            throw new InvalidOperationException("Could not find the FoxProFileNode object");
                        }
                        this.project.SetProjectProperty(FoxProProjectFileConstants.MainFile, node.GetRelativePath());
                        break;
                    }
                }

                index++;
            }

            return(VSConstants.S_OK);
        }
        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);
                        FoxProFileNode node = projMgr.NodeFromItemId(itemid) as FoxProFileNode;
                        if (null != node)
                        {
                            node.RunGenerator();
                        }
                    }
                }
            }

            return(hr);
        }
예제 #3
0
        /// <summary>
        /// Create a file node based on an msbuild item.
        /// </summary>
        /// <param name="item">The msbuild item to be analyzed</param>
        /// <returns>FoxProFileNode or FileNode</returns>
        public override FileNode CreateFileNode(ProjectElement item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

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

            newNode.OleServiceProvider.AddService(typeof(EnvDTE.Project), new OleServiceProvider.ServiceCreatorCallback(this.CreateServices), false);
            newNode.OleServiceProvider.AddService(typeof(EnvDTE.ProjectItem), 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);
        }
        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(FoxProProjectFileConstants.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 FoxProFileNode 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 FoxPro filenode we willl map this file to the MainFile property
                    FoxProFileNode filenode = project.FindChild(newfile) as FoxProFileNode;
                    if (filenode != null)
                    {
                        this.project.SetProjectProperty(FoxProProjectFileConstants.MainFile, filenode.GetRelativePath());
                        break;
                    }
                }

                index++;
            }

            return(VSConstants.S_OK);
        }