Esempio n. 1
0
        /// <summary>
        /// Create my file nodes that know about the file
        /// </summary>
        /// <param name="item">msbuild item</param>
        /// <returns>FileNode added</returns>
        public override FileNode CreateFileNode(ProjectElement item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            DelphiFileNode lNewNode;
            string         include = item.GetMetadata(ProjectFileConstants.Include);

            if (DelphiProjectFileNode.IsDelphiProjectFile(include))
            {
                lNewNode = new DelphiProjectFileNode(this, item);
            }
            else if (DelphiPackageFileNode.IsDelphiProjectFile(include))
            {
                lNewNode = new DelphiPackageFileNode(this, item);
            }
            else
            {
                lNewNode = new DelphiFileNode(this, item);
            }
            lNewNode.OleServiceProvider.AddService(typeof(EnvDTE.Project), new OleServiceProvider.ServiceCreatorCallback(this.CreateServices), false);
            lNewNode.OleServiceProvider.AddService(typeof(VSLangProj.VSProject), new OleServiceProvider.ServiceCreatorCallback(this.CreateServices), false);

            lNewNode.OnAfterDelphiUnitRename += new AfterDelphiUnitRename(AfterDelphiUnitRenameEvent);
            lNewNode.OnAfterFileRename       += new AfterFileRename(AfterFileRenameEvent);

            return(lNewNode);
        }
Esempio n. 2
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);
                        DelphiFileNode node = projMgr.NodeFromItemId(itemid) as DelphiFileNode;
                        if (null != node && node.NodeProperties is SingleFileGeneratorNodeProperties)
                        {
                            node.RunGenerator();
                        }
                    }
                }
            }

            return(hr);
        }
Esempio n. 3
0
        private void AfterFileRenameEvent(DelphiFileNode aDelphiFileNode, string aOldUnitName, string aNewUnitName)
        {
            DelphiMainFileNode lNode = GetDelphiMainFileNode();

            if (lNode != null)
            {
                if (!lNode.IsDelphiFile(aOldUnitName))
                {
                    lNode.RenameContainedFile(aOldUnitName, aNewUnitName);
                }
            }
        }
Esempio n. 4
0
        private void AfterDelphiUnitRenameEvent(object sender, string aOldUnitName, string aNewUnitName)
        {
            HierarchyNode lNode = this.FirstChild;

            do
            {
                DelphiFileNode lDelphiNode = lNode as DelphiFileNode;
                if (lDelphiNode != null && sender != lDelphiNode)
                {
                    lDelphiNode.RenameDelphiUnit(aOldUnitName, aNewUnitName);
                }
                lNode = lNode.NextSibling;
            } while (lNode != null);
        }
Esempio n. 5
0
        protected virtual void AddDelphiDirectiveFiles(DelphiFileNode aDelphiFileNode, string aDirectiveSourcePath)
        {
            if (aDelphiFileNode == null)
            {
                return;
            }
            if (!this.IsCodeFile(aDelphiFileNode.FileName))
            {
                return;
            }
            if (!Directory.Exists(aDirectiveSourcePath))
            {
                return;
            }
            string[] lDirectiveFiles = aDelphiFileNode.GetDirectiveFiles();
            // root the path for all resource files so they get copied to the new output folder
            // sorry no referencing these files as the are a part of code file
            for (int i = 0; i < lDirectiveFiles.Length; i++)
            {
                if (!Path.IsPathRooted(lDirectiveFiles[i]))
                {
                    lDirectiveFiles[i] = Path.Combine(aDirectiveSourcePath, Path.GetFileName(lDirectiveFiles[i]));
                }
            }

            // remove all existing children
            for (HierarchyNode lChild = aDelphiFileNode.FirstChild; lChild != null; lChild = lChild.NextSibling)
            {
                lChild.Remove(true);
            }
            // add the new children and modify the code file
            CopyFilesToVSProject(lDirectiveFiles, aDelphiFileNode, false);

            // Notify tracker
            for (HierarchyNode lChild = aDelphiFileNode.FirstChild; lChild != null; lChild = lChild.NextSibling)
            {
                this.Tracker.OnItemAdded(lChild.Url, VSADDFILEFLAGS.VSADDFILEFLAGS_NoFlags);
            }
        }