Exemple #1
0
 public int AddItemWithSpecific(uint itemid, VSADDITEMOPERATION dwAddItemOperation, string pszItemName,
                                uint cFilesToOpen, string[] rgpszFilesToOpen, IntPtr hwndDlgOwner, uint grfEditorFlags, ref Guid rguidEditorType,
                                string pszPhysicalView, ref Guid rguidLogicalView, VSADDRESULT[] pResult)
 {
     _logger.LogHierarchy("AddItemWithSpecific({0})", (int)itemid);
     return(VSConstants.E_NOTIMPL);
 }
        public int AddItem(uint itemid, VSADDITEMOPERATION dwAddItemOperation, string pszItemName, uint cFilesToOpen, string[] rgpszFilesToOpen, IntPtr hwndDlgOwner, VSADDRESULT[] pResult)
        {
            _logger.LogHierarchy("AddItem({0})", (int)itemid);
            Guid guid = Guid.Empty;

            return(AddItemWithSpecific(itemid, dwAddItemOperation, pszItemName, cFilesToOpen, rgpszFilesToOpen, hwndDlgOwner, 0U, ref guid, (string)null, ref guid, pResult));
        }
Exemple #3
0
        /// <summary>
        /// Adds an item to the project.
        /// </summary>
        /// <param name="path">The full path of the item to add.</param>
        /// <param name="op">The <paramref name="VSADDITEMOPERATION"/> to use when adding the item.</param>
        /// <returns>A ProjectItem object. </returns>
        protected virtual EnvDTE.ProjectItem AddItem(string path, VSADDITEMOPERATION op)
        {
            if (this.Project == null || this.Project.Project == null || this.Project.Project.Site == null || this.Project.Project.IsClosed)
            {
                throw new InvalidOperationException();
            }

            return(UIThread.DoOnUIThread(delegate()
            {
                ProjectNode proj = this.Project.Project;

                EnvDTE.ProjectItem itemAdded = null;
                using (AutomationScope scope = new AutomationScope(this.Project.Project.Site))
                {
                    VSADDRESULT[] result = new VSADDRESULT[1];
                    ErrorHandler.ThrowOnFailure(proj.AddItem(this.NodeWithItems.ID, op, path, 0, new string[1] {
                        path
                    }, IntPtr.Zero, result));

                    string fileName = System.IO.Path.GetFileName(path);
                    string fileDirectory = proj.GetBaseDirectoryForAddingFiles(this.NodeWithItems);
                    string filePathInProject = System.IO.Path.Combine(fileDirectory, fileName);

                    itemAdded = this.EvaluateAddResult(result[0], filePathInProject);
                }

                return itemAdded;
            }));
        }
Exemple #4
0
        int IVsProject3.AddItemWithSpecific(uint itemidLoc, VSADDITEMOPERATION dwAddItemOperation, string pszItemName, uint cFilesToOpen, string[] rgpszFilesToOpen, IntPtr hwndDlgOwner, uint grfEditorFlags, ref Guid rguidEditorType, string pszPhysicalView, ref Guid rguidLogicalView, VSADDRESULT[] pResult)
        {
            int hr = ((IVsProject3)this).AddItem(itemidLoc, dwAddItemOperation, pszItemName, cFilesToOpen, rgpszFilesToOpen, hwndDlgOwner, pResult);

            // TODO: Open the items once they've been added.
            return(hr);
        }
Exemple #5
0
        /// <summary>
        /// Adds an item to the project.
        /// </summary>
        /// <param name="path">The full path of the item to add.</param>
        /// <param name="op">The <paramref name="VSADDITEMOPERATION"/> to use when adding the item.</param>
        /// <returns>A ProjectItem object. </returns>
        protected virtual EnvDTE.ProjectItem AddItem(string path, VSADDITEMOPERATION op)
        {
            CheckProjectIsValid();
            return(this.Project.ProjectNode.Site.GetUIThread().Invoke <EnvDTE.ProjectItem>(() =>
            {
                var proj = this.Project.ProjectNode;
                EnvDTE.ProjectItem itemAdded = null;
                using (var scope = new AutomationScope(this.Project.ProjectNode.Site))
                {
                    var result = new VSADDRESULT[1];
                    ErrorHandler.ThrowOnFailure(proj.AddItem(this.NodeWithItems.ID, op, path, 0, new string[1] {
                        path
                    }, IntPtr.Zero, result));

                    string realPath = null;
                    if (op != VSADDITEMOPERATION.VSADDITEMOP_LINKTOFILE)
                    {
                        var fileName = Path.GetFileName(path);
                        var fileDirectory = proj.GetBaseDirectoryForAddingFiles(this.NodeWithItems);
                        realPath = Path.Combine(fileDirectory, fileName);
                    }
                    else
                    {
                        realPath = path;
                    }

                    itemAdded = this.EvaluateAddResult(result[0], realPath);
                }

                return itemAdded;
            }));
        }
        /// <summary>
        /// Adds an item to the project.
        /// </summary>
        /// <param name="path">The full path of the item to add.</param>
        /// <param name="op">The <paramref name="VSADDITEMOPERATION"/> to use when adding the item.</param>
        /// <returns>A ProjectItem object. </returns>
        protected virtual ProjectItem AddItem(string path, VSADDITEMOPERATION op)
        {
            CheckProjectIsValid();

            return(ThreadHelper.JoinableTaskFactory.Run(async delegate
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                ProjectNode proj = this.Project.Project;

                ProjectItem itemAdded = null;
                using (AutomationScope scope = new AutomationScope(this.Project.Project.Site))
                {
                    VSADDRESULT[] result = new VSADDRESULT[1];
                    ErrorHandler.ThrowOnFailure(proj.AddItem(this.NodeWithItems.ID, op, path, 0, new string[1] {
                        path
                    }, IntPtr.Zero, result));

                    string fileName = System.IO.Path.GetFileName(path);
                    string fileDirectory = proj.GetBaseDirectoryForAddingFiles(this.NodeWithItems);
                    string filePathInProject = System.IO.Path.Combine(fileDirectory, fileName);

                    itemAdded = this.EvaluateAddResult(result[0], filePathInProject);
                }

                return itemAdded;
            }));
        }
    public int AddItem(uint itemidLoc, VSADDITEMOPERATION dwAddItemOperation, string pszItemName, uint cFilesToOpen, string[] rgpszFilesToOpen, IntPtr hwndDlgOwner, VSADDRESULT[] pResult)
    {
        AddItemCalled = true;

        AddItemArgumentItemidLoc = itemidLoc;
        AddItemArgumentAddItemOperation = dwAddItemOperation;
        AddItemArgumentItemName = pszItemName;
        AddItemArgumentFilesToOpen = cFilesToOpen;
        AddItemArgumentArrayFilesToOpen = rgpszFilesToOpen;

        return VSConstants.S_OK;
    }
        public int AddItem(uint itemidLoc, VSADDITEMOPERATION dwAddItemOperation, string pszItemName, uint cFilesToOpen, string[] rgpszFilesToOpen,
                           IntPtr hwndDlgOwner, VSADDRESULT[] pResult)
        {
            AddItemCalled = true;

            AddItemArgumentItemidLoc        = itemidLoc;
            AddItemArgumentAddItemOperation = dwAddItemOperation;
            AddItemArgumentItemName         = pszItemName;
            AddItemArgumentFilesToOpen      = cFilesToOpen;
            AddItemArgumentArrayFilesToOpen = rgpszFilesToOpen;

            return(VSConstants.S_OK);
        }
Exemple #9
0
        public int AddItem(uint itemidLoc, VSADDITEMOPERATION dwAddItemOperation, string pszItemName, uint cFilesToOpen, string[] rgpszFilesToOpen, IntPtr hwndDlgOwner, VSADDRESULT[] pResult)
        {
            // Check if we are adding an item to a folder that consists of browser-side code.
            // In this case, we will want to open the file with the default editor.
            var isClientCode = false;
            var project      = _innerVsHierarchy.GetProject().GetNodejsProject();

            var selectedItems = this.GetSelectedItems().GetEnumerator();

            if (selectedItems.MoveNext())
            {
                var    currentId = selectedItems.Current.itemid;
                string name;
                GetCanonicalName(currentId, out name);
                var nodeFolderNode = project.FindNodeByFullPath(name) as NodejsFolderNode;

                if (nodeFolderNode != null)
                {
                    if (nodeFolderNode.ContentType == FolderContentType.Browser)
                    {
                        isClientCode = true;
                    }
                }
            }

            if (!isClientCode && _innerProject3 != null && IsJavaScriptFile(pszItemName))
            {
                Guid ourEditor = Guid.Empty;
                Guid view      = Guid.Empty;
                return(_innerProject3.AddItemWithSpecific(
                           itemidLoc,
                           dwAddItemOperation,
                           pszItemName,
                           cFilesToOpen,
                           rgpszFilesToOpen,
                           hwndDlgOwner,
                           dwAddItemOperation == VSADDITEMOPERATION.VSADDITEMOP_CLONEFILE ?
                           (uint)__VSSPECIFICEDITORFLAGS.VSSPECIFICEDITOR_DoOpen :
                           0,
                           ref ourEditor,
                           String.Empty,
                           ref view,
                           pResult
                           ));
            }
            return(_innerProject.AddItem(itemidLoc, dwAddItemOperation, pszItemName, cFilesToOpen, rgpszFilesToOpen, hwndDlgOwner, pResult));
        }
Exemple #10
0
        EnvDTE.ProjectItem AddItem(string path, VSADDITEMOPERATION op)
        {
            ProjectNode proj = this.project.project;

            VSADDRESULT[] result = new VSADDRESULT[1];
            NativeMethods.ThrowOnFailure(proj.AddItem(node.ID, op, path, 0, new string[1] {
                path
            }, IntPtr.Zero, null));
            if (result[0] == VSADDRESULT.ADDRESULT_Success)
            {
                HierarchyNode      child = node.LastChild;
                EnvDTE.ProjectItem item  = new OAProjectItem(this.project, child);
                this.items.Add(item);
                return(item);
            }
            return(null);
        }
        /// <summary>
        /// Creates a new project item from an existing item template file and adds it to the project.
        /// </summary>
        /// <param name="fileName">The full path and file name of the template project file.</param>
        /// <param name="name">The file name to use for the new project item.</param>
        /// <returns>A ProjectItem object. </returns>
        public override EnvDTE.ProjectItem AddFromTemplate(string fileName, string name)
        {
            if (this.Project == null || this.Project.Project == null || this.Project.Project.Site == null || this.Project.Project.IsClosed)
            {
                throw new InvalidOperationException();
            }

            ProjectNode proj = this.Project.Project;

            IVsExtensibility3 extensibility = this.Project.Project.Site.GetService(typeof(IVsExtensibility)) as IVsExtensibility3;

            if (extensibility == null)
            {
                throw new InvalidOperationException();
            }

            EnvDTE.ProjectItem itemAdded = null;
            extensibility.EnterAutomationFunction();

            try
            {
                VSADDITEMOPERATION op     = VSADDITEMOPERATION.VSADDITEMOP_CLONEFILE;
                VSADDRESULT[]      result = new VSADDRESULT[1];

                // It is not a very good idea to throw since the AddItem might return Cancel or Abort.
                // The problem is that up in the call stack the wizard code does not check whether it has received a ProjectItem or not and will crash.
                // The other problem is that we cannot get add wizard dialog back if a cancel or abort was returned because we throw and that code will never be executed. Typical catch 22.
                ErrorHandler.ThrowOnFailure(proj.AddItem(this.NodeWithItems.ID, op, name, 0, new string[1] {
                    fileName
                }, IntPtr.Zero, result));

                string fileDirectory    = proj.GetBaseDirectoryForAddingFiles(this.NodeWithItems);
                string templateFilePath = System.IO.Path.Combine(fileDirectory, name);
                itemAdded = this.EvaluateAddResult(result[0], templateFilePath);
            }
            finally
            {
                extensibility.ExitAutomationFunction();
            }

            return(itemAdded);
        }
Exemple #12
0
        /// <summary>
        /// Adds an item to the project.
        /// </summary>
        /// <param name="path">The full path of the item to add.</param>
        /// <param name="op">The VSADDITEMOPERATION to use when adding the item.</param>
        /// <returns>A ProjectItem object. </returns>
        public virtual EnvDTE.ProjectItem AddItem(string path, VSADDITEMOPERATION op)
        {
            return(UIThread.DoOnUIThread(delegate() {
                if (this.Project == null || this.Project.Project == null || this.Project.Project.Site == null || this.Project.Project.IsClosed)
                {
                    throw new InvalidOperationException();
                }

                ProjectNode proj = this.Project.Project;

                IVsExtensibility3 extensibility = this.Project.Project.Site.GetService(typeof(IVsExtensibility)) as IVsExtensibility3;

                if (extensibility == null)
                {
                    throw new InvalidOperationException();
                }

                EnvDTE.ProjectItem itemAdded = null;
                extensibility.EnterAutomationFunction();

                try
                {
                    VSADDRESULT[] result = new VSADDRESULT[1];
                    ErrorHandler.ThrowOnFailure(proj.AddItem(this.NodeWithItems.ID, op, path, 0, new string[1] {
                        path
                    }, IntPtr.Zero, result));

                    string fileName = System.IO.Path.GetFileName(path);
                    string fileDirectory = proj.GetBaseDirectoryForAddingFiles(this.NodeWithItems);
                    string filePathInProject = System.IO.Path.Combine(fileDirectory, fileName);

                    itemAdded = this.EvaluateAddResult(result[0], filePathInProject);
                }
                finally
                {
                    extensibility.ExitAutomationFunction();
                }

                return itemAdded;
            }));
        }
Exemple #13
0
 int IVsProject.AddItem(uint itemidLoc, VSADDITEMOPERATION dwAddItemOperation, string pszItemName, uint cFilesToOpen, string[] rgpszFilesToOpen, IntPtr hwndDlgOwner, VSADDRESULT[] pResult)
 {
     if (Directory.Exists(rgpszFilesToOpen[0]))
     {
         AddProject(new MockVSHierarchy(rgpszFilesToOpen[0], this));
     }
     else
     {
         children.Add(rgpszFilesToOpen[0]);
         if (project != null)
         {
             FileInfo itemFileInfo = new FileInfo(rgpszFilesToOpen[0]);
             project.Save(fileName);
             FileInfo projectFileInfo = new FileInfo(project.FullPath);
             string   itemName        = itemFileInfo.FullName.Substring(projectFileInfo.Directory.FullName.Length + 1);
             project.AddItem("Compile", itemName);
             project.Save(fileName);
         }
     }
     return(VSConstants.S_OK);
 }
Exemple #14
0
        int IVsProject.AddItem(uint itemidLoc, VSADDITEMOPERATION dwAddItemOperation, string pszItemName, uint cFilesToOpen, string[] rgpszFilesToOpen, IntPtr hwndDlgOwner, VSADDRESULT[] pResult)
        {
            if (cFilesToOpen == 1 && Path.GetFileName(rgpszFilesToOpen[0]).Equals("DjangoNewAppFiles.vstemplate", StringComparison.OrdinalIgnoreCase))
            {
                object selectedObj;
                ErrorHandler.ThrowOnFailure(
                    _innerVsHierarchy.GetProperty(
                        itemidLoc,
                        (int)__VSHPROPID.VSHPROPID_ExtObject,
                        out selectedObj
                        )
                    );

                EnvDTE.ProjectItems items = null;
                var project = selectedObj as EnvDTE.Project;
                if (project != null)
                {
                    items = project.ProjectItems;
                }
                else
                {
                    var selection = selectedObj as EnvDTE.ProjectItem;
                    if (selection != null)
                    {
                        items = selection.ProjectItems;
                    }
                }

                if (items != null)
                {
                    bool cancel;
                    pszItemName = ResolveAppNameCollisionWithUser(items, pszItemName, out cancel);
                    if (cancel)
                    {
                        return(VSConstants.E_ABORT);
                    }
                }
            }
            return(_innerProject.AddItem(itemidLoc, dwAddItemOperation, pszItemName, cFilesToOpen, rgpszFilesToOpen, hwndDlgOwner, pResult));
        }
Exemple #15
0
        /// <summary>
        /// Adds an item to the project.
        /// </summary>
        /// <param name="path">The full path of the item to add.</param>
        /// <param name="op">The <paramref name="VSADDITEMOPERATION"/> to use when adding the item.</param>
        /// <returns>A ProjectItem object. </returns>
        protected virtual EnvDTE.ProjectItem AddItem(string path, VSADDITEMOPERATION op)
        {
            CheckProjectIsValid();
            return(UIThread.Instance.RunSync <EnvDTE.ProjectItem>(() => {
                string ext = Path.GetExtension(path);
                foreach (var extension in this.Project.ProjectNode.CodeFileExtensions)
                {
                    // http://pytools.codeplex.com/workitem/617
                    // We are currently in create project from existing code mode.  The wizard walks all of the top-level
                    // files and adds them.  It then lets us handle any subdirectories by calling AddFromDirectory.
                    // But we want to filter the files for both top-level and subdirectories.  Therefore we derive from
                    // PageManager and track when we're running the wizard and adding files for the wizard.  If we are
                    // currently adding them ignore anything other than a .py/.pyw files - returnning null is fine
                    // here, the wizard doesn't care about the result.
                    if (String.Compare(ext, extension, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        ProjectNode proj = this.Project.ProjectNode;

                        EnvDTE.ProjectItem itemAdded = null;
                        using (AutomationScope scope = new AutomationScope(this.Project.ProjectNode.Site)) {
                            VSADDRESULT[] result = new VSADDRESULT[1];
                            ErrorHandler.ThrowOnFailure(proj.AddItem(this.NodeWithItems.ID, op, path, 0, new string[1] {
                                path
                            }, IntPtr.Zero, result));

                            string fileName = System.IO.Path.GetFileName(path);
                            string fileDirectory = proj.GetBaseDirectoryForAddingFiles(this.NodeWithItems);
                            string filePathInProject = System.IO.Path.Combine(fileDirectory, fileName);

                            itemAdded = this.EvaluateAddResult(result[0], filePathInProject);
                        }

                        return itemAdded;
                    }
                }

                return null;
            }));
        }
Exemple #16
0
        /// <summary>
        /// Adds an item to the project.
        /// </summary>
        /// <param name="path">The full path of the item to add.</param>
        /// <param name="op">The <paramref name="VSADDITEMOPERATION"/> to use when adding the item.</param>
        /// <returns>A ProjectItem object. </returns>
        protected virtual EnvDTE.ProjectItem AddItem(string path, VSADDITEMOPERATION op)
        {
            CheckProjectIsValid();

            ProjectNode proj = this.Project.Project;

            EnvDTE.ProjectItem itemAdded = null;
            using (AutomationScope scope = new AutomationScope(this.Project.Project.Site))
            {
                VSADDRESULT[] result = new VSADDRESULT[1];
                ErrorHandler.ThrowOnFailure(proj.AddItem(this.NodeWithItems.ID, op, path, 0, new string[1] {
                    path
                }, IntPtr.Zero, result));

                string fileName          = System.IO.Path.GetFileName(path);
                string fileDirectory     = proj.GetBaseDirectoryForAddingFiles(this.NodeWithItems);
                string filePathInProject = System.IO.Path.Combine(fileDirectory, fileName);

                itemAdded = this.EvaluateAddResult(result[0], filePathInProject);
            }

            return(itemAdded);
        }
Exemple #17
0
 public int AddItem(uint itemidLoc, VSADDITEMOPERATION dwAddItemOperation, string pszItemName, uint cFilesToOpen, string[] rgpszFilesToOpen, IntPtr hwndDlgOwner, VSADDRESULT[] pResult)
 {
     if (_innerProject3 != null && IsJavaScriptFile(pszItemName))
     {
         Guid ourEditor = typeof(NodejsEditorFactory).GUID;
         Guid view      = Guid.Empty;
         return(_innerProject3.AddItemWithSpecific(
                    itemidLoc,
                    dwAddItemOperation,
                    pszItemName,
                    cFilesToOpen,
                    rgpszFilesToOpen,
                    hwndDlgOwner,
                    dwAddItemOperation == VSADDITEMOPERATION.VSADDITEMOP_CLONEFILE ?
                    (uint)__VSSPECIFICEDITORFLAGS.VSSPECIFICEDITOR_DoOpen :
                    0,
                    ref ourEditor,
                    String.Empty,
                    ref view,
                    pResult
                    ));
     }
     return(_innerProject.AddItem(itemidLoc, dwAddItemOperation, pszItemName, cFilesToOpen, rgpszFilesToOpen, hwndDlgOwner, pResult));
 }
Exemple #18
0
 public int AddItemWithSpecific(uint itemid, VSADDITEMOPERATION dwAddItemOperation, string pszItemName, uint cFilesToOpen, string[] rgpszFilesToOpen, IntPtr hwndDlgOwner, uint grfEditorFlags, ref Guid rguidEditorType, string pszPhysicalView, ref Guid rguidLogicalView, VSADDRESULT[] pResult) {
   _logger.LogHierarchy("AddItemWithSpecific({0})", (int)itemid);
   return VSConstants.E_NOTIMPL;
 }
Exemple #19
0
        /// <summary>
        ///     Adds an item to the project.
        /// </summary>
        /// <param name="path">The full path of the item to add.</param>
        /// <param name="op">The <paramref name="VSADDITEMOPERATION" /> to use when adding the item.</param>
        /// <returns>A ProjectItem object. </returns>
        protected virtual ProjectItem AddItem(string path, VSADDITEMOPERATION op)
        {
            if (Project == null || Project.Project == null || Project.Project.Site == null || Project.Project.IsClosed)
            {
                throw new InvalidOperationException();
            }

            return UIThread.DoOnUIThread(delegate
            {
                var proj = Project.Project;

                ProjectItem itemAdded = null;
                using (var scope = new AutomationScope(Project.Project.Site))
                {
                    var result = new VSADDRESULT[1];
                    ErrorHandler.ThrowOnFailure(proj.AddItem(NodeWithItems.ID, op, path, 0, new string[1] {path},
                        IntPtr.Zero, result));

                    var fileName = Path.GetFileName(path);
                    var fileDirectory = proj.GetBaseDirectoryForAddingFiles(NodeWithItems);
                    var filePathInProject = Path.Combine(fileDirectory, fileName);

                    itemAdded = EvaluateAddResult(result[0], filePathInProject);
                }

                return itemAdded;
            });
        }
        public int AddItem(uint itemidLoc, VSADDITEMOPERATION dwAddItemOperation, string pszItemName, uint cFilesToOpen, string[] rgpszFilesToOpen, IntPtr hwndDlgOwner, VSADDRESULT[] pResult) {
            // Check if we are adding an item to a folder that consists of browser-side code.
            // In this case, we will want to open the file with the default editor.
            var isClientCode = false;
            var project = _innerVsHierarchy.GetProject().GetNodejsProject();

            var selectedItems = this.GetSelectedItems().GetEnumerator();
            if (selectedItems.MoveNext()) {
                var currentId = selectedItems.Current.itemid;
                string name;
                GetCanonicalName(currentId, out name);
                var nodeFolderNode = project.FindNodeByFullPath(name) as NodejsFolderNode;

                if (nodeFolderNode != null) {
                    if (nodeFolderNode.ContentType == FolderContentType.Browser) {
                        isClientCode = true;
                    }
                }
            }

            if (!isClientCode && _innerProject3 != null && IsJavaScriptFile(pszItemName)) {
                Guid ourEditor = IsES6IntellisensePreview() ? Guid.Empty : typeof(NodejsEditorFactory).GUID;
                Guid view = Guid.Empty;
                return _innerProject3.AddItemWithSpecific(
                    itemidLoc,
                    dwAddItemOperation,
                    pszItemName,
                    cFilesToOpen,
                    rgpszFilesToOpen,
                    hwndDlgOwner,
                    dwAddItemOperation == VSADDITEMOPERATION.VSADDITEMOP_CLONEFILE ?
                        (uint)__VSSPECIFICEDITORFLAGS.VSSPECIFICEDITOR_DoOpen :
                        0,
                    ref ourEditor,
                    String.Empty,
                    ref view,
                    pResult
                );
            }
            return _innerProject.AddItem(itemidLoc, dwAddItemOperation, pszItemName, cFilesToOpen, rgpszFilesToOpen, hwndDlgOwner, pResult);
        }
 public int AddItemWithSpecific(uint itemidLoc, VSADDITEMOPERATION dwAddItemOperation, string pszItemName, uint cFilesToOpen, string[] rgpszFilesToOpen, IntPtr hwndDlgOwner, uint grfEditorFlags, ref Guid rguidEditorType, string pszPhysicalView, ref Guid rguidLogicalView, VSADDRESULT[] pResult)
 {
     throw new NotImplementedException();
 }
Exemple #22
0
 public int AddItem(uint itemid, VSADDITEMOPERATION dwAddItemOperation, string pszItemName, uint cFilesToOpen, string[] rgpszFilesToOpen, IntPtr hwndDlgOwner, VSADDRESULT[] pResult) {
   _logger.LogHierarchy("AddItem({0})", (int)itemid);
   Guid guid = Guid.Empty;
   return AddItemWithSpecific(itemid, dwAddItemOperation, pszItemName, cFilesToOpen, rgpszFilesToOpen, hwndDlgOwner, 0U, ref guid, (string)null, ref guid, pResult);
 }
        /// <summary>
        ///     Adds an item to the project.
        /// </summary>
        /// <param name="path">The full path of the item to add.</param>
        /// <param name="op">
        ///     The <paramref name="VSADDITEMOPERATION" /> to use when adding the item.
        /// </param>
        /// <returns>A ProjectItem object. </returns>
        protected virtual ProjectItem AddItem(string path, VSADDITEMOPERATION op)
        {
            CheckProjectIsValid();

            ProjectNode proj = Project.Project;

            ProjectItem itemAdded = null;
            using (var scope = new AutomationScope(Project.Project.Site))
            {
                var result = new VSADDRESULT[1];
                ErrorHandler.ThrowOnFailure(proj.AddItem(NodeWithItems.ID, op, path, 0, new string[1] {path}, IntPtr.Zero, result));

                string fileName = Path.GetFileName(path);
                string fileDirectory = proj.GetBaseDirectoryForAddingFiles(NodeWithItems);
                string filePathInProject = Path.Combine(fileDirectory, fileName);

                itemAdded = EvaluateAddResult(result[0], filePathInProject);
            }

            return itemAdded;
        }
 public int AddItem([ComAliasName("Microsoft.VisualStudio.Shell.Interop.VSITEMID")] uint itemidLoc, [ComAliasName("Microsoft.VisualStudio.Shell.Interop.VSADDITEMOPERATION")] VSADDITEMOPERATION dwAddItemOperation, [ComAliasName("Microsoft.VisualStudio.OLE.Interop.LPCOLESTR")] string pszItemName, [ComAliasName("Microsoft.VisualStudio.OLE.Interop.ULONG")] uint cFilesToOpen, [ComAliasName("Microsoft.VisualStudio.OLE.Interop.LPCOLESTR")] string[] rgpszFilesToOpen, IntPtr hwndDlgOwner, [ComAliasName("Microsoft.VisualStudio.Shell.Interop.VSADDRESULT")] VSADDRESULT[] pResult)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Adds an item to the project.
        /// </summary>
        /// <param name="path">The full path of the item to add.</param>
        /// <param name="op">The <paramref name="VSADDITEMOPERATION"/> to use when adding the item.</param>
        /// <returns>A ProjectItem object. </returns>
        protected virtual EnvDTE.ProjectItem AddItem(string path, VSADDITEMOPERATION op) {
            CheckProjectIsValid();
            return UIThread.Instance.RunSync<EnvDTE.ProjectItem>(() => {
                string ext = Path.GetExtension(path);
                foreach (var extension in this.Project.ProjectNode.CodeFileExtensions) {
                    // http://pytools.codeplex.com/workitem/617
                    // We are currently in create project from existing code mode.  The wizard walks all of the top-level
                    // files and adds them.  It then lets us handle any subdirectories by calling AddFromDirectory.
                    // But we want to filter the files for both top-level and subdirectories.  Therefore we derive from
                    // PageManager and track when we're running the wizard and adding files for the wizard.  If we are
                    // currently adding them ignore anything other than a .py/.pyw files - returnning null is fine
                    // here, the wizard doesn't care about the result.
                    if (String.Compare(ext, extension, StringComparison.OrdinalIgnoreCase) == 0) {
                        ProjectNode proj = this.Project.ProjectNode;

                        EnvDTE.ProjectItem itemAdded = null;
                        using (AutomationScope scope = new AutomationScope(this.Project.ProjectNode.Site)) {
                            VSADDRESULT[] result = new VSADDRESULT[1];
                            ErrorHandler.ThrowOnFailure(proj.AddItem(this.NodeWithItems.ID, op, path, 0, new string[1] { path }, IntPtr.Zero, result));

                            string fileName = System.IO.Path.GetFileName(path);
                            string fileDirectory = proj.GetBaseDirectoryForAddingFiles(this.NodeWithItems);
                            string filePathInProject = System.IO.Path.Combine(fileDirectory, fileName);

                            itemAdded = this.EvaluateAddResult(result[0], filePathInProject);
                    }

                        return itemAdded;
                    }
                }

                return null;
            });
        }
Exemple #26
0
        // (after dialog) Add existing item -> AdItemWithSpecific
        public override int AddItem(uint itemIdLoc, VSADDITEMOPERATION op, string itemName, uint filesToOpen, string[] files, IntPtr dlgOwner, VSADDRESULT[] result)
        {
            // Special MSBuild case: we invoked it directly instead of using the "add item" dialog.
              if (itemName != null && itemName.Equals("SimResult"))
              {
              SimResultsNode resultsNode = null;
              if (this.IsSimResultFilePresent())
                  resultsNode = this.FindChild("Results.sim") as SimResultsNode;

              if (resultsNode == null)
              {
                  resultsNode = CreateAndAddSimResultsFile(); //TODO: what about save on project unload/exit?
              }

              var simulationTimestamp = DateTime.Now;

              bool filePresent = false;
              bool renameOutput = true;
              Boolean.TryParse(GetProjectProperty("RenameOutput"), out renameOutput);

              string baseOutputName = GetProjectProperty("BaseOutputName");
              if (String.IsNullOrEmpty(baseOutputName))
              {
                  var msBuildProject = BlenXProjectPackage.MSBuildProjectFromIVsProject(this);
                  foreach (Microsoft.Build.BuildEngine.BuildItem item in msBuildProject.EvaluatedItems)
                  {
                      if (item.Name.Equals(SimFiles.Prog.ToString()))
                      {
                          baseOutputName = item.Include;
                          break;
                      }
                  }

                  if (String.IsNullOrEmpty(baseOutputName))
                      baseOutputName = Path.GetFileNameWithoutExtension(this.ProjectFile) + ".prog";
              }

              string newOutputName;
              if (renameOutput)
              {
                  newOutputName = baseOutputName + simulationTimestamp.ToString("yyyy'-'MM'-'dd'-'HH'-'mm'-'ss");
                  // TODO: try to move!

                  filePresent = TryCopy(baseOutputName, newOutputName, "spec");
                  TryCopy(baseOutputName, newOutputName, "E.out");
                  TryCopy(baseOutputName, newOutputName, "C.out");
                  TryCopy(baseOutputName, newOutputName, "V.out");
              }
              else
              {
                  newOutputName = baseOutputName;
                  filePresent = File.Exists(this.ProjectFolder + Path.DirectorySeparatorChar + baseOutputName + ".spec");
              }

              if (filePresent)
              {
                  resultsNode.AddEntry(newOutputName, this.ProjectFolder, simulationTimestamp);
              }

              return VSConstants.S_OK;
              }
              // Add existing item: itemIdLoc = 4294967294, VSADDITEMOP_OPENFILE, itemName = null, files (filename), null, VSADDRESULT 1 (init with ADDRESULT_Failure)
              return base.AddItem(itemIdLoc, op, itemName, filesToOpen, files, dlgOwner, result);
        }
Exemple #27
0
 public int AddItem(uint itemidLoc, VSADDITEMOPERATION dwAddItemOperation, string pszItemName, uint cFilesToOpen, string[] rgpszFilesToOpen, IntPtr hwndDlgOwner, VSADDRESULT[] pResult)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Exemple #28
0
        /// <summary>
        /// Adds an item to the project.
        /// </summary>
        /// <param name="path">The full path of the item to add.</param>
        /// <param name="op">The <paramref name="VSADDITEMOPERATION"/> to use when adding the item.</param>
        /// <returns>A ProjectItem object. </returns>
        protected virtual EnvDTE.ProjectItem AddItem(string path, VSADDITEMOPERATION op) {
            CheckProjectIsValid();
            return Project.ProjectNode.Site.GetUIThread().Invoke<EnvDTE.ProjectItem>(() => {
                ProjectNode proj = this.Project.ProjectNode;
                EnvDTE.ProjectItem itemAdded = null;
                using (AutomationScope scope = new AutomationScope(this.Project.ProjectNode.Site)) {
                    VSADDRESULT[] result = new VSADDRESULT[1];
                    ErrorHandler.ThrowOnFailure(proj.AddItem(this.NodeWithItems.ID, op, path, 0, new string[1] { path }, IntPtr.Zero, result));

                    string realPath = null;
                    if (op != VSADDITEMOPERATION.VSADDITEMOP_LINKTOFILE) {
                        string fileName = Path.GetFileName(path);
                        string fileDirectory = proj.GetBaseDirectoryForAddingFiles(this.NodeWithItems);
                        realPath = Path.Combine(fileDirectory, fileName);
                    } else {
                        realPath = path;
                    }

                    itemAdded = this.EvaluateAddResult(result[0], realPath);
                }

                return itemAdded;
            });
        }
Exemple #29
0
 public override int AddItem(uint itemIdLoc, VSADDITEMOPERATION op, string itemName, uint filesToOpen, string[] files, IntPtr dlgOwner, VSADDRESULT[] result)
 {
     return AddManyItemsHelper(itemIdLoc, op, itemName, filesToOpen, files, dlgOwner, result);
 }
Exemple #30
0
        private int AddManyItemsHelper(uint itemIdLoc, VSADDITEMOPERATION op, string itemName, uint filesToOpen, string[] files, IntPtr dlgOwner, VSADDRESULT[] result)
        {
            List<string> actualFiles = new List<string>(files.Length);
            List<string> dirs = new List<string>();
            foreach (string file in files)
            {
                if (File.Exists(file))
                    actualFiles.Add(file);
                else
                {
                    if (Directory.Exists(file))
                    {
                        dirs.Add(file);
                    }
                }
            }

            if (actualFiles.Count > 0)
                ErrorHandler.ThrowOnFailure(base.AddItem(itemIdLoc, op, itemName, (uint)actualFiles.Count, actualFiles.ToArray(), dlgOwner, result));

            foreach (string directory in dirs)
            {
                HierarchyNode folderNode = CreateFolderNodeHelper(directory, itemIdLoc);
                List<string> directoryEntries = new List<string>();
                directoryEntries.AddRange(Directory.GetFiles(directory));
                directoryEntries.AddRange(Directory.GetDirectories(directory));
                AddManyItemsHelper(folderNode.ID, op, null, (uint)directoryEntries.Count, directoryEntries.ToArray(), dlgOwner, result);
            }

            return VSConstants.S_OK;
        }
Exemple #31
0
        /// <summary>
        /// Adds an item to the project.
        /// </summary>
        /// <param name="path">The full path of the item to add.</param>
        /// <param name="op">The <paramref name="VSADDITEMOPERATION"/> to use when adding the item.</param>
        /// <returns>A ProjectItem object. </returns>
        protected virtual EnvDTE.ProjectItem AddItem(string path, VSADDITEMOPERATION op)
        {
            if (this.Project == null || this.Project.Project == null || this.Project.Project.Site == null || this.Project.Project.IsClosed)
            {
                throw new InvalidOperationException();
            }

            ProjectNode proj = this.Project.Project;

            IVsExtensibility3 extensibility = this.Project.Project.Site.GetService(typeof(IVsExtensibility)) as IVsExtensibility3;

            if (extensibility == null)
            {
                throw new InvalidOperationException();
            }

            EnvDTE.ProjectItem itemAdded = null;
            extensibility.EnterAutomationFunction();

            try
            {
                VSADDRESULT[] result = new VSADDRESULT[1];
                ErrorHandler.ThrowOnFailure(proj.AddItem(this.NodeWithItems.ID, op, path, 0, new string[1] { path }, IntPtr.Zero, result));

                string fileName = System.IO.Path.GetFileName(path);
                string fileDirectory = proj.GetBaseDirectoryForAddingFiles(this.NodeWithItems);
                string filePathInProject = System.IO.Path.Combine(fileDirectory, fileName);

                itemAdded = this.EvaluateAddResult(result[0], filePathInProject);
            }
            finally
            {
                extensibility.ExitAutomationFunction();
            }

            return itemAdded;
        }
 public int AddItem(uint itemidLoc, VSADDITEMOPERATION dwAddItemOperation, string pszItemName, uint cFilesToOpen, string[] rgpszFilesToOpen, IntPtr hwndDlgOwner, VSADDRESULT[] pResult)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Exemple #33
0
    /// <include file='doc\Project.uex' path='docs/doc[@for="ImageNames.AddItemWithSpecific"]/*' />
    public virtual int AddItemWithSpecific(uint itemIdLoc, VSADDITEMOPERATION op, string itemName, uint filesToOpen, string[] files, IntPtr dlgOwner, uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, VSADDRESULT[] result){
      result[0] = VSADDRESULT.ADDRESULT_Failure;
      //if (this.IsReadOnly) return; <-- bogus, the user can always change the project to non-readonly later when they choose to save it, or they can do saveas...
      HierarchyNode n = NodeFromItemId(itemIdLoc);
      if (n == null) return 0;

      if (n.NodeType == HierarchyNodeType.Root || n.NodeType == HierarchyNodeType.Folder){
        if (!this.projectMgr.Tracker.CanAddFiles(files)){
          return 0;
        }

        foreach (string file in files){
          HierarchyNode child;
          bool fFileAdded = false;
          bool fOverwrite = false;
          string strBaseDir = Path.GetDirectoryName(this.filename);
          string strNewFileName = "";

          if (n.NodeType == HierarchyNodeType.Folder){
            // add the folder to the path....
            strBaseDir = Path.Combine(strBaseDir, n.XmlNode.GetAttribute("RelPath"));
          }

          switch (op){
            case VSADDITEMOPERATION.VSADDITEMOP_CLONEFILE:
              // new item added. Need to copy template to new location and then add new location 
              strNewFileName = Path.Combine(strBaseDir, itemName);
              break;

            case VSADDITEMOPERATION.VSADDITEMOP_LINKTOFILE:// TODO: VSADDITEMOP_LINKTOFILE
              // we do not support this right now
              throw new NotImplementedException("VSADDITEMOP_LINKTOFILE");

            case VSADDITEMOPERATION.VSADDITEMOP_OPENFILE:{
              string strFileName = Path.GetFileName(file);
              strNewFileName = Path.Combine(strBaseDir, strFileName);
            }
              break;

            case VSADDITEMOPERATION.VSADDITEMOP_RUNWIZARD: // TODO: VSADDITEMOP_RUNWIZARD
              throw new NotImplementedException("VSADDITEMOP_RUNWIZARD");
          }
          child = this.FindChild(strNewFileName);
          if (child != null){
            // file already exists in project... message box
            string msg = SR.GetString(SR.FileAlreadyInProject);
            string caption = SR.GetString(SR.FileAlreadyInProjectCaption);

            if (MessageBox.Show(msg, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes){
              child = null;
              fOverwrite = true;
            }
          }

          if (child == null){
            // the next will be equal if file is already in the project DIR
            if (VsShell.IsSamePath(file, strNewFileName) == false){
              // now copy file
              FileInfo fiOrg = new FileInfo(file);
              fiOrg.Attributes &= ~FileAttributes.ReadOnly;

              try{
                FileInfo fiNew = fiOrg.CopyTo(strNewFileName, fOverwrite);
              } catch{
                string msg = SR.GetString(SR.FileAlreadyExists);
                string caption = SR.GetString(SR.FileAlreadyExistsCaption);

                if (MessageBox.Show(msg, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes){
                  FileInfo fiNew = fiOrg.CopyTo(strNewFileName, true);
                }
              }
            }

            fFileAdded = true;
          }

          if (fFileAdded && !fOverwrite){
            // now add the new thing to the project
            child = this.projectMgr.AddExistingFile(strNewFileName);
            n.AddChild(child);
            if (op == VSADDITEMOPERATION.VSADDITEMOP_OPENFILE){
              IVsWindowFrame frame;
              if (editorType == Guid.Empty){
                Guid view = Guid.Empty;
                this.OpenItem(child.ID, ref view, IntPtr.Zero, out frame);
              } else{
                this.OpenItemWithSpecific(child.ID, editorFlags, ref editorType, physicalView, ref logicalView, IntPtr.Zero, out frame);
              }
            }
            this.projectMgr.Tracker.OnAddFile(strNewFileName);
          }
        }

        n.OnItemsAppended(n);
        result[0] = VSADDRESULT.ADDRESULT_Success;
      }

      result[0] = VSADDRESULT.ADDRESULT_Success;
      return 0;
    }
Exemple #34
0
        // TODO: Refactor me into something sane
        internal int AddItemWithSpecificInternal(uint itemIdLoc, VSADDITEMOPERATION op, string itemName, uint filesToOpen, string[] files, IntPtr dlgOwner, uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, VSADDRESULT[] result, bool alwaysCopy = false, bool? promptOverwrite = null)
        {
            if (files == null || result == null || files.Length == 0 || result.Length == 0)
            {
                return VSConstants.E_INVALIDARG;
            }

            // Locate the node to be the container node for the file(s) being added
            // only projectnode or foldernode and file nodes are valid container nodes
            // We need to locate the parent since the item wizard expects the parent to be passed.
            HierarchyNode n = this.NodeFromItemId(itemIdLoc);
            if (n == null)
            {
                return VSConstants.E_INVALIDARG;
            }

            while (!n.CanAddFiles && (!this.CanFileNodesHaveChilds || !(n is FileNode)))
            {
                n = n.Parent;
            }
            Debug.Assert(n != null, "We should at this point have either a ProjectNode or FolderNode or a FileNode as a container for the new filenodes");

            // handle link and runwizard operations at this point
            bool isLink = false;
            switch (op)
            {
                case VSADDITEMOPERATION.VSADDITEMOP_LINKTOFILE:
                    // we do not support this right now
                    isLink = true;
                    break;

                case VSADDITEMOPERATION.VSADDITEMOP_RUNWIZARD:
                    result[0] = this.RunWizard(n, itemName, files[0], dlgOwner);
                    return VSConstants.S_OK;
            }

            string[] actualFiles = new string[files.Length];

            VSQUERYADDFILEFLAGS[] flags = this.GetQueryAddFileFlags(files);

            string baseDir = this.GetBaseDirectoryForAddingFiles(n);
            // If we did not get a directory for node that is the parent of the item then fail.
            if (String.IsNullOrEmpty(baseDir))
            {
                return VSConstants.E_FAIL;
            }

            // Pre-calculates some paths that we can use when calling CanAddItems
            List<string> filesToAdd = new List<string>();
            for (int index = 0; index < files.Length; index++)
            {
                string newFileName = String.Empty;

                string file = files[index];

                switch (op)
                {
                    case VSADDITEMOPERATION.VSADDITEMOP_CLONEFILE:
                        {
                            string fileName = Path.GetFileName(itemName ?? file);
                            newFileName = CommonUtils.GetAbsoluteFilePath(baseDir, fileName);
                        }
                        break;
                    case VSADDITEMOPERATION.VSADDITEMOP_LINKTOFILE:
                    case VSADDITEMOPERATION.VSADDITEMOP_OPENFILE:
                        {
                            string fileName = Path.GetFileName(file);
                            newFileName = CommonUtils.GetAbsoluteFilePath(baseDir, fileName);

                            var friendlyPath = CommonUtils.CreateFriendlyFilePath(ProjectFolder, file);

                            if (isLink && CommonUtils.IsSubpathOf(ProjectFolder, file))
                            {
                                // creating a link to a file that's actually in the project, it's not really a link.
                                isLink = false;
                                newFileName = file;
                                n = this.CreateFolderNodes(Path.GetDirectoryName(file));
                            }
                        }
                        break;
                }
                filesToAdd.Add(newFileName);
            }

            // Ask tracker objects if we can add files
            if (!this.tracker.CanAddItems(filesToAdd.ToArray(), flags))
            {
                // We were not allowed to add the files
                return VSConstants.E_FAIL;
            }

            if (!this.ProjectMgr.QueryEditProjectFile(false))
            {
                throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
            }

            // Add the files to the hierarchy
            int actualFilesAddedIndex = 0;
            for (int index = 0; index < filesToAdd.Count; index++)
            {
                HierarchyNode child;
                bool overwrite = false;
                ProjectElement linkedFile = null;
                string newFileName = filesToAdd[index];

                string file = files[index];
                result[0] = VSADDRESULT.ADDRESULT_Failure;

                child = this.FindChild(newFileName);
                if (child != null)
                {
                    // If the file to be added is an existing file part of the hierarchy then continue.
                    if (CommonUtils.IsSamePath(file, newFileName))
                    {
                        if (!alwaysCopy)
                        {
                            result[0] = VSADDRESULT.ADDRESULT_Cancel;
                            continue;
                        }
                        else
                        {
                            string tmpName = CommonUtils.GetAbsoluteFilePath(Path.GetDirectoryName(newFileName), Path.GetFileNameWithoutExtension(newFileName) + " - Copy" + Path.GetExtension(newFileName));
                            if (File.Exists(tmpName))
                            {
                                int count = 2;
                                while (File.Exists(GetIncrementedFileName(newFileName, count)))
                                {
                                    count++;
                                }
                                newFileName = GetIncrementedFileName(newFileName, count);
                            }
                            else
                            {
                                newFileName = tmpName;
                            }
                        }
                    }
                    else if (isLink)
                    {
                        string message = "There is already a file of the same name in this folder.";
                        string title = string.Empty;
                        OLEMSGICON icon = OLEMSGICON.OLEMSGICON_QUERY;
                        OLEMSGBUTTON buttons = OLEMSGBUTTON.OLEMSGBUTTON_OK;
                        OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;

                        VsShellUtilities.ShowMessageBox(this.Site, title, message, icon, buttons, defaultButton);

                        result[0] = VSADDRESULT.ADDRESULT_Cancel;
                        return (int)OleConstants.OLECMDERR_E_CANCELED;
                    }
                    else if (!(child is FolderNode && Directory.Exists(file)))
                    {
                        if (promptOverwrite != null && !promptOverwrite.Value)
                        {
                            continue;
                        }

                        int canOverWriteExistingItem = CanOverwriteExistingItem(file, newFileName, promptOverwrite != null && promptOverwrite.Value);
                        if (canOverWriteExistingItem == E_CANCEL_FILE_ADD)
                        {
                            result[0] = VSADDRESULT.ADDRESULT_Cancel;
                            return (int)OleConstants.OLECMDERR_E_CANCELED;
                        }
                        else if (canOverWriteExistingItem == (int)OleConstants.OLECMDERR_E_CANCELED)
                        {
                            result[0] = VSADDRESULT.ADDRESULT_Cancel;
                            if (promptOverwrite != null && promptOverwrite.Value)
                            {
                                continue;
                            }
                            return canOverWriteExistingItem;
                        }
                        else if (canOverWriteExistingItem == VSConstants.S_OK)
                        {
                            overwrite = true;
                        }
                        else
                        {
                            return canOverWriteExistingItem;
                        }
                    }
                }
                else
                {
                    if (isLink)
                    {
                        child = this.FindChild(file);
                        if (child != null)
                        {
                            string message = String.Format("There is already a link to '{0}'. A project cannot have more than one link to the same file.", file);
                            string title = string.Empty;
                            OLEMSGICON icon = OLEMSGICON.OLEMSGICON_QUERY;
                            OLEMSGBUTTON buttons = OLEMSGBUTTON.OLEMSGBUTTON_OK;
                            OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;

                            VsShellUtilities.ShowMessageBox(this.Site, title, message, icon, buttons, defaultButton);

                            result[0] = VSADDRESULT.ADDRESULT_Cancel;
                            return (int)OleConstants.OLECMDERR_E_CANCELED;
                        }
                    }

                    // we need to figure out where this file would be added and make sure there's
                    // not an existing link node at the same location
                    string filename = Path.GetFileName(newFileName);
                    var folder = this.FindChild(Path.GetDirectoryName(newFileName));
                    if (folder != null)
                    {
                        for (var folderChild = folder.FirstChild; folderChild != null; folderChild = folderChild.NextSibling)
                        {
                            if (Path.GetFileName(folderChild.Url) == filename)
                            {
                                string message = "There is already a file of the same name in this folder.";
                                string title = string.Empty;
                                OLEMSGICON icon = OLEMSGICON.OLEMSGICON_QUERY;
                                OLEMSGBUTTON buttons = OLEMSGBUTTON.OLEMSGBUTTON_OK;
                                OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;

                                VsShellUtilities.ShowMessageBox(this.Site, title, message, icon, buttons, defaultButton);

                                result[0] = VSADDRESULT.ADDRESULT_Cancel;
                                return (int)OleConstants.OLECMDERR_E_CANCELED;
                            }
                        }
                    }
                }

                // If the file to be added is not in the same path copy it.
                if (!CommonUtils.IsSamePath(file, newFileName))
                {
                    if (!overwrite && File.Exists(newFileName))
                    {
                        var existingChild = this.FindChild(file);
                        if (existingChild == null || !existingChild.IsLinkFile)
                        {
                            string message = String.Format(CultureInfo.CurrentCulture, SR.GetString(SR.FileAlreadyExists, CultureInfo.CurrentUICulture), newFileName);
                            string title = string.Empty;
                            OLEMSGICON icon = OLEMSGICON.OLEMSGICON_QUERY;
                            OLEMSGBUTTON buttons = OLEMSGBUTTON.OLEMSGBUTTON_YESNO;
                            OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;
                            if (isLink)
                            {
                                message = "There is already a file of the same name in this folder.";
                                buttons = OLEMSGBUTTON.OLEMSGBUTTON_OK;
                            }

                            int messageboxResult = VsShellUtilities.ShowMessageBox(this.Site, title, message, icon, buttons, defaultButton);
                            if (messageboxResult != NativeMethods.IDYES)
                            {
                                result[0] = VSADDRESULT.ADDRESULT_Cancel;
                                return (int)OleConstants.OLECMDERR_E_CANCELED;
                            }
                        }
                    }

                    var updatingNode = this.FindChild(file);
                    if (updatingNode != null && updatingNode.IsLinkFile)
                    {
                        // we just need to update the link to the new path.
                        linkedFile = updatingNode.ItemNode;
                    }
                    else if (Directory.Exists(file))
                    {
                        // http://pytools.codeplex.com/workitem/546
                        return AddDirectory(result, n, file, promptOverwrite);
                    }
                    else if (!isLink)
                    {
                        // Copy the file to the correct location.
                        // We will suppress the file change events to be triggered to this item, since we are going to copy over the existing file and thus we will trigger a file change event.
                        // We do not want the filechange event to ocur in this case, similar that we do not want a file change event to occur when saving a file.
                        IVsFileChangeEx fileChange = this.site.GetService(typeof(SVsFileChangeEx)) as IVsFileChangeEx;
                        Utilities.CheckNotNull(fileChange);

                        try
                        {
                            ErrorHandler.ThrowOnFailure(fileChange.IgnoreFile(VSConstants.VSCOOKIE_NIL, newFileName, 1));
                            if (op == VSADDITEMOPERATION.VSADDITEMOP_CLONEFILE)
                            {
                                this.AddFileFromTemplate(file, newFileName);
                            }
                            else
                            {
                                PackageUtilities.CopyUrlToLocal(new Uri(file), newFileName);

                                // Reset RO attribute on file if present - for example, if source file was under TFS control and not checked out.
                                try
                                {
                                    var fileInfo = new FileInfo(newFileName);
                                    if (fileInfo.Attributes.HasFlag(FileAttributes.ReadOnly))
                                    {
                                        fileInfo.Attributes &= ~FileAttributes.ReadOnly;
                                    }
                                }
                                catch (Exception)
                                {
                                    // Best-effort, but no big deal if this fails.
                                }
                            }
                        }
                        finally
                        {
                            ErrorHandler.ThrowOnFailure(fileChange.IgnoreFile(VSConstants.VSCOOKIE_NIL, newFileName, 0));
                        }
                    }
                }

                if (overwrite)
                {
                    this.OverwriteExistingItem(child);
                }
                else if (linkedFile != null || isLink)
                {
                    // files not moving, add the old name, and set the link.
                    var friendlyPath = CommonUtils.GetRelativeFilePath(ProjectFolder, file);
                    FileNode newChild;
                    if (linkedFile == null)
                    {
                        Debug.Assert(!CommonUtils.IsSubpathOf(ProjectFolder, file), "Should have cleared isLink above for file in project dir");
                        newChild = CreateFileNode(file);
                    }
                    else
                    {
                        newChild = CreateFileNode(linkedFile);
                    }

                    newChild.SetIsLinkFile(true);
                    newChild.ItemNode.SetMetadata(ProjectFileConstants.Link, CommonUtils.CreateFriendlyFilePath(ProjectFolder, newFileName));
                    n.AddChild(newChild);

                    DocumentManager.RenameDocument(site, file, file, n.ID);

                    LinkFileAdded(file);

                    SetProjectFileDirty(true);
                }
                else
                {
                    //Add new filenode/dependentfilenode
                    this.AddNewFileNodeToHierarchy(n, newFileName);
                }

                result[0] = VSADDRESULT.ADDRESULT_Success;
                actualFiles[actualFilesAddedIndex++] = newFileName;
            }

            // Notify listeners that items were appended.
            if (actualFilesAddedIndex > 0)
                n.OnItemsAppended(n);

            //Open files if this was requested through the editorFlags
            bool openFiles = (editorFlags & (uint)__VSSPECIFICEDITORFLAGS.VSSPECIFICEDITOR_DoOpen) != 0;
            if (openFiles && actualFiles.Length <= filesToOpen)
            {
                for (int i = 0; i < filesToOpen; i++)
                {
                    if (!String.IsNullOrEmpty(actualFiles[i]))
                    {
                        string name = actualFiles[i];
                        HierarchyNode child = this.FindChild(name);
                        Debug.Assert(child != null, "We should have been able to find the new element in the hierarchy");
                        if (child != null)
                        {
                            IVsWindowFrame frame;
                            if (editorType == Guid.Empty)
                            {
                                Guid view = Guid.Empty;
                                ErrorHandler.ThrowOnFailure(this.OpenItem(child.ID, ref view, IntPtr.Zero, out frame));
                            }
                            else
                            {
                                ErrorHandler.ThrowOnFailure(this.OpenItemWithSpecific(child.ID, editorFlags, ref editorType, physicalView, ref logicalView, IntPtr.Zero, out frame));
                            }

                            // Show the window frame in the UI and make it the active window
                            if (frame != null)
                            {
                                ErrorHandler.ThrowOnFailure(frame.Show());
                            }
                        }
                    }
                }
            }

            return VSConstants.S_OK;
        }
 public int AddItemWithSpecific([ComAliasName("Microsoft.VisualStudio.Shell.Interop.VSITEMID")] uint itemidLoc, [ComAliasName("Microsoft.VisualStudio.Shell.Interop.VSADDITEMOPERATION")] VSADDITEMOPERATION dwAddItemOperation, [ComAliasName("Microsoft.VisualStudio.OLE.Interop.LPCOLESTR")] string pszItemName, [ComAliasName("Microsoft.VisualStudio.OLE.Interop.ULONG")] uint cFilesToOpen, [ComAliasName("Microsoft.VisualStudio.OLE.Interop.LPCOLESTR")] string[] rgpszFilesToOpen, IntPtr hwndDlgOwner, [ComAliasName("Microsoft.VisualStudio.Shell.Interop.VSSPECIFICEDITORFLAGS")] uint grfEditorFlags, [ComAliasName("Microsoft.VisualStudio.OLE.Interop.REFGUID")] ref Guid rguidEditorType, [ComAliasName("Microsoft.VisualStudio.OLE.Interop.LPCOLESTR")] string pszPhysicalView, [ComAliasName("Microsoft.VisualStudio.OLE.Interop.REFGUID")] ref Guid rguidLogicalView, [ComAliasName("Microsoft.VisualStudio.Shell.Interop.VSADDRESULT")] VSADDRESULT[] pResult)
 {
     throw new NotImplementedException();
 }
 int IVsProject.AddItem(uint itemidLoc, VSADDITEMOPERATION dwAddItemOperation, string pszItemName, uint cFilesToOpen, string[] rgpszFilesToOpen, IntPtr hwndDlgOwner, VSADDRESULT[] pResult)
 {
     throw new NotImplementedException();
 }
 public int AddItemWithSpecific(uint itemidLoc, VSADDITEMOPERATION dwAddItemOperation, string pszItemName, uint cFilesToOpen, string[] rgpszFilesToOpen, IntPtr hwndDlgOwner, uint grfEditorFlags, ref Guid rguidEditorType, string pszPhysicalView, ref Guid rguidLogicalView, VSADDRESULT[] pResult)
 {
     return(InnerVsProject.AddItemWithSpecific(itemidLoc, dwAddItemOperation, pszItemName, cFilesToOpen, rgpszFilesToOpen, hwndDlgOwner, grfEditorFlags, ref rguidEditorType, pszPhysicalView, ref rguidLogicalView, pResult));
 }
Exemple #38
0
        /// <summary>
        /// Adds an item to the project.
        /// </summary>
        /// <param name="path">The full path of the item to add.</param>
        /// <param name="op">The <paramref name="VSADDITEMOPERATION"/> to use when adding the item.</param>
        /// <returns>A ProjectItem object. </returns>
        protected virtual EnvDTE.ProjectItem AddItem(string path, VSADDITEMOPERATION op)
        {
            if(this.Project == null || this.Project.Project == null || this.Project.Project.Site == null || this.Project.Project.IsClosed)
            {
                throw new InvalidOperationException();
            }

            return UIThread.DoOnUIThread(delegate()
            {
            ProjectNode proj = this.Project.Project;

            EnvDTE.ProjectItem itemAdded = null;
                using (AutomationScope scope = new AutomationScope(this.Project.Project.Site))
            {
                VSADDRESULT[] result = new VSADDRESULT[1];
                ErrorHandler.ThrowOnFailure(proj.AddItem(this.NodeWithItems.ID, op, path, 0, new string[1] { path }, IntPtr.Zero, result));

                string fileName = System.IO.Path.GetFileName(path);
                string fileDirectory = proj.GetBaseDirectoryForAddingFiles(this.NodeWithItems);
                string filePathInProject = System.IO.Path.Combine(fileDirectory, fileName);

                itemAdded = this.EvaluateAddResult(result[0], filePathInProject);
            }

            return itemAdded;
            });
        }
Exemple #39
0
 EnvDTE.ProjectItem AddItem(string path, VSADDITEMOPERATION op)
 {
     ProjectNode proj = this.project.project;
     VSADDRESULT[] result = new VSADDRESULT[1];
     NativeMethods.ThrowOnFailure(proj.AddItem(node.ID, op, path, 0, new string[1] { path }, IntPtr.Zero, null));
     if (result[0] == VSADDRESULT.ADDRESULT_Success)
     {
         HierarchyNode child = node.LastChild;
         EnvDTE.ProjectItem item = new OAProjectItem(this.project, child);
         this.items.Add(item);
         return item;
     }
     return null;
 }
 /// <inheritdoc/>
 int IVsProject.AddItem(uint itemidLoc, VSADDITEMOPERATION dwAddItemOperation, string pszItemName, uint cFilesToOpen, string[] rgpszFilesToOpen, IntPtr hwndDlgOwner, VSADDRESULT[] pResult)
 {
     Trace.TraceInformation($"{nameof(IVsProject)}.{nameof(IVsProject.AddItem)}");
     return(VSConstants.E_NOTIMPL);
 }
Exemple #41
0
 int IVsProject.AddItem(uint itemidLoc, VSADDITEMOPERATION dwAddItemOperation, string pszItemName, uint cFilesToOpen, string[] rgpszFilesToOpen, IntPtr hwndDlgOwner, VSADDRESULT[] pResult) {
     return _innerProject.AddItem(itemidLoc, dwAddItemOperation, pszItemName, cFilesToOpen, rgpszFilesToOpen, hwndDlgOwner, pResult);
 }
Exemple #42
0
        int IVsProject.AddItem(uint itemidLoc, VSADDITEMOPERATION dwAddItemOperation, string pszItemName, uint cFilesToOpen, string[] rgpszFilesToOpen, IntPtr hwndDlgOwner, VSADDRESULT[] pResult) {
            if (cFilesToOpen == 1 && Path.GetFileName(rgpszFilesToOpen[0]).Equals("DjangoNewAppFiles.vstemplate", StringComparison.OrdinalIgnoreCase)) {
                object selectedObj;
                ErrorHandler.ThrowOnFailure(
                    _innerVsHierarchy.GetProperty(
                        itemidLoc,
                        (int)__VSHPROPID.VSHPROPID_ExtObject,
                        out selectedObj
                    )
                );

                EnvDTE.ProjectItems items = null;
                var project = selectedObj as EnvDTE.Project;
                if (project != null) {
                    items = project.ProjectItems;
                } else {
                    var selection = selectedObj as EnvDTE.ProjectItem;
                    if (selection != null) {
                        items = selection.ProjectItems;
                    }
                }

                if (items != null) {
                    bool cancel;
                    pszItemName = ResolveAppNameCollisionWithUser(items, pszItemName, out cancel);
                    if (cancel) {
                        return VSConstants.E_ABORT;
                    }
                }
            }
            return _innerProject.AddItem(itemidLoc, dwAddItemOperation, pszItemName, cFilesToOpen, rgpszFilesToOpen, hwndDlgOwner, pResult);
        }
Exemple #43
0
 public override int AddItemWithSpecific(uint itemIdLoc, VSADDITEMOPERATION op, string itemName, uint filesToOpen, string[] files, IntPtr dlgOwner, uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, VSADDRESULT[] result)
 {
     //editor type?
       return base.AddItemWithSpecific(itemIdLoc, op, itemName, filesToOpen, files, dlgOwner, editorFlags, ref editorType, physicalView, ref logicalView, result);
 }
        public virtual int AddItemWithSpecific(uint itemIdLoc, VSADDITEMOPERATION op, string itemName, uint filesToOpen, string[] files, IntPtr dlgOwner, uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, VSADDRESULT[] result)
        {
            if (files == null || result == null || files.Length == 0 || result.Length == 0)
            {
                return VSConstants.E_INVALIDARG;
            }

            // Locate the node to be the container node for the file(s) being added
            // only projectnode or foldernode and file nodes are valid container nodes
            // We need to locate the parent since the item wizard expects the parent to be passed.
            HierarchyNode n = this.NodeFromItemId(itemIdLoc);
            if (n == null)
            {
                return VSConstants.E_INVALIDARG;
            }

            while ((!(n is ProjectNode)) && (!(n is FolderNode)) && (!this.CanFileNodesHaveChilds || !(n is FileNode)))
            {
                n = n.Parent;
            }
            Debug.Assert(n != null, "We should at this point have either a ProjectNode or FolderNode or a FileNode as a container for the new filenodes");

            // handle link and runwizard operations at this point
            switch (op)
            {
                case VSADDITEMOPERATION.VSADDITEMOP_LINKTOFILE:
                    // we do not support this right now
                    throw new NotImplementedException("VSADDITEMOP_LINKTOFILE");

                case VSADDITEMOPERATION.VSADDITEMOP_RUNWIZARD:
                    result[0] = this.RunWizard(n, itemName, files[0], dlgOwner);
                    return VSConstants.S_OK;
            }

            string[] actualFiles = new string[files.Length];

            VSQUERYADDFILEFLAGS[] flags = this.GetQueryAddFileFlags(files);

            string baseDir = this.GetBaseDirectoryForAddingFiles(n);
            // If we did not get a directory for node that is the parent of the item then fail.
            if (String.IsNullOrEmpty(baseDir))
            {
                return VSConstants.E_FAIL;
            }

            // Pre-calculates some paths that we can use when calling CanAddItems
            List<string> filesToAdd = new List<string>();
            for (int index = 0; index < files.Length; index++)
            {
                string newFileName = String.Empty;

                string file = files[index];

                switch (op)
                {
                    case VSADDITEMOPERATION.VSADDITEMOP_CLONEFILE:
                        {
                            string fileName = Path.GetFileName(itemName);
                            newFileName = Path.Combine(baseDir, fileName);
                        }
                        break;
                    case VSADDITEMOPERATION.VSADDITEMOP_OPENFILE:
                        {
                            string fileName = Path.GetFileName(file);
                            newFileName = Path.Combine(baseDir, fileName);
                        }
                        break;
                }
                filesToAdd.Add(newFileName);
            }

            // Ask tracker objects if we can add files
            if (!this.tracker.CanAddItems(filesToAdd.ToArray(), flags))
            {
                // We were not allowed to add the files
                return VSConstants.E_FAIL;
            }

            if (!this.ProjectMgr.QueryEditProjectFile(false))
            {
                throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
            }

            // Add the files to the hierarchy
            int actualFilesAddedIndex = 0;
            for (int index = 0; index < filesToAdd.Count; index++)
            {
                HierarchyNode child;
                bool overwrite = false;
                string newFileName = filesToAdd[index];

                string file = files[index];
                result[0] = VSADDRESULT.ADDRESULT_Failure;

                child = this.FindChild(newFileName);
                if (child != null)
                {
                    // If the file to be added is an existing file part of the hierarchy then continue.
                    if (NativeMethods.IsSamePath(file, newFileName))
                    {
                        result[0] = VSADDRESULT.ADDRESULT_Cancel;
                        continue;
                    }

                    int canOverWriteExistingItem = this.CanOverwriteExistingItem(file, newFileName);

                    if (canOverWriteExistingItem == (int)OleConstants.OLECMDERR_E_CANCELED)
                    {
                        result[0] = VSADDRESULT.ADDRESULT_Cancel;
                        return canOverWriteExistingItem;
                    }
                    else if (canOverWriteExistingItem == VSConstants.S_OK)
                    {
                        overwrite = true;
                    }
                    else
                    {
                        return canOverWriteExistingItem;
                    }
                }

                // If the file to be added is not in the same path copy it.
                if (NativeMethods.IsSamePath(file, newFileName) == false)
                {
                    if (!overwrite && File.Exists(newFileName))
                    {
                        string message = String.Format(CultureInfo.CurrentCulture, SR.GetString(SR.FileAlreadyExists, CultureInfo.CurrentUICulture), newFileName);
                        string title = string.Empty;
                        OLEMSGICON icon = OLEMSGICON.OLEMSGICON_QUERY;
                        OLEMSGBUTTON buttons = OLEMSGBUTTON.OLEMSGBUTTON_YESNO;
                        OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;
                        int messageboxResult = VsShellUtilities.ShowMessageBox(this.Site, title, message, icon, buttons, defaultButton);
                        if (messageboxResult == NativeMethods.IDNO)
                        {
                            result[0] = VSADDRESULT.ADDRESULT_Cancel;
                            return (int)OleConstants.OLECMDERR_E_CANCELED;
                        }
                    }

                    // Copy the file to the correct location.
                    // We will suppress the file change events to be triggered to this item, since we are going to copy over the existing file and thus we will trigger a file change event.
                    // We do not want the filechange event to ocur in this case, similar that we do not want a file change event to occur when saving a file.
                    IVsFileChangeEx fileChange = this.site.GetService(typeof(SVsFileChangeEx)) as IVsFileChangeEx;
                    if (fileChange == null)
                    {
                        throw new InvalidOperationException();
                    }

                    try
                    {
                        ErrorHandler.ThrowOnFailure(fileChange.IgnoreFile(VSConstants.VSCOOKIE_NIL, newFileName, 1));
                        if (op == VSADDITEMOPERATION.VSADDITEMOP_CLONEFILE)
                        {
                            this.AddFileFromTemplate(file, newFileName);
                        }
                        else
                        {
                            PackageUtilities.CopyUrlToLocal(new Uri(file), newFileName);
                        }
                    }
                    finally
                    {
                        ErrorHandler.ThrowOnFailure(fileChange.IgnoreFile(VSConstants.VSCOOKIE_NIL, newFileName, 0));
                    }
                }

                if (overwrite)
                {
                    this.OverwriteExistingItem(child);
                }
                else
                {
                    //Add new filenode/dependentfilenode
                    this.AddNewFileNodeToHierarchy(n, newFileName);
                }

                result[0] = VSADDRESULT.ADDRESULT_Success;
                actualFiles[actualFilesAddedIndex++] = newFileName;
            }

            // Notify listeners that items were appended.
            if (actualFilesAddedIndex > 0)
                n.OnItemsAppended(n);

            //Open files if this was requested through the editorFlags
            bool openFiles = (editorFlags & (uint)__VSSPECIFICEDITORFLAGS.VSSPECIFICEDITOR_DoOpen) != 0;
            if (openFiles && actualFiles.Length <= filesToOpen)
            {
                for (int i = 0; i < filesToOpen; i++)
                {
                    if (!String.IsNullOrEmpty(actualFiles[i]))
                    {
                        string name = actualFiles[i];
                        HierarchyNode child = this.FindChild(name);
                        Debug.Assert(child != null, "We should have been able to find the new element in the hierarchy");
                        if (child != null)
                        {
                            IVsWindowFrame frame;
                            if (editorType == Guid.Empty)
                            {
                                Guid view = Guid.Empty;
                                ErrorHandler.ThrowOnFailure(this.OpenItem(child.ID, ref view, IntPtr.Zero, out frame));
                            }
                            else
                            {
                                ErrorHandler.ThrowOnFailure(this.OpenItemWithSpecific(child.ID, editorFlags, ref editorType, physicalView, ref logicalView, IntPtr.Zero, out frame));
                            }

                            // Show the window frame in the UI and make it the active window
                            if (frame != null)
                            {
                                ErrorHandler.ThrowOnFailure(frame.Show());
                            }
                        }
                    }
                }
            }

            return VSConstants.S_OK;
        }
        public virtual int AddItem(uint itemIdLoc, VSADDITEMOPERATION op, string itemName, uint filesToOpen, string[] files, IntPtr dlgOwner, VSADDRESULT[] result)
        {
            Guid empty = Guid.Empty;

            return AddItemWithSpecific(itemIdLoc, op, itemName, filesToOpen, files, dlgOwner, 0, ref empty, null, ref empty, result);
        }
Exemple #46
0
 int IVsProject2.AddItem(uint itemidLoc, VSADDITEMOPERATION dwAddItemOperation, string pszItemName, uint cFilesToOpen, string[] rgpszFilesToOpen, IntPtr hwndDlgOwner, VSADDRESULT[] pResult)
 {
     return(((IVsProject3)this).AddItem(itemidLoc, dwAddItemOperation, pszItemName, cFilesToOpen, rgpszFilesToOpen, hwndDlgOwner, pResult));
 }
 int IVsProject.AddItem(uint itemidLoc, VSADDITEMOPERATION dwAddItemOperation, string pszItemName, uint cFilesToOpen, string[] rgpszFilesToOpen, IntPtr hwndDlgOwner, VSADDRESULT[] pResult)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Creates new items in a project, adds existing files to a project, or causes Add Item wizards to be run
 /// </summary>
 /// <param name="itemIdLoc"></param>
 /// <param name="op"></param>
 /// <param name="itemName"></param>
 /// <param name="filesToOpen"></param>
 /// <param name="files">Array of file names. 
 /// If dwAddItemOperation is VSADDITEMOP_CLONEFILE the first item in the array is the name of the file to clone. 
 /// If dwAddItemOperation is VSADDITEMOP_OPENDIRECTORY, the first item in the array is the directory to open. 
 /// If dwAddItemOperation is VSADDITEMOP_RUNWIZARD, the first item is the name of the wizard to run, 
 /// and the second item is the file name the user supplied (same as itemName).</param>
 /// <param name="dlgOwner"></param>
 /// <param name="editorFlags"></param>
 /// <param name="editorType"></param>
 /// <param name="physicalView"></param>
 /// <param name="logicalView"></param>
 /// <param name="result"></param>
 /// <returns>S_OK if it succeeds </returns>
 /// <remarks>The result array is initalized to failure.</remarks>
 public virtual int AddItemWithSpecific(uint itemIdLoc, VSADDITEMOPERATION op, string itemName, uint filesToOpen, string[] files, IntPtr dlgOwner, uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, VSADDRESULT[] result)
 {
     // When Adding an item, pass true to let AddItemWithSpecific know to fire the tracker events.
     return AddItemWithSpecific(itemIdLoc, op, itemName, filesToOpen, files, dlgOwner, editorFlags, ref editorType, physicalView, ref logicalView, result, true);
 }
Exemple #49
0
        int IVsProject3.AddItem(uint itemidLoc, VSADDITEMOPERATION dwAddItemOperation, string pszItemName, uint cFilesToOpen, string[] rgpszFilesToOpen, IntPtr hwndDlgOwner, VSADDRESULT[] pResult)
        {
            bool canceled   = false;
            bool wereErrors = false;

            pResult[0] = VSADDRESULT.ADDRESULT_Failure;

            // Get the parent node to which it should be added.
            FolderNode parentNode = this.GetNode(itemidLoc, true) as FolderNode;

            if (parentNode == null)
            {
                string message = this.NativeResources.GetString(ResId.IDS_E_ADDITEMTOPROJECT, Path.GetFileName(this.FilePath));
                Context.ShowErrorMessageBox(message);
                Tracer.Fail("The specified parent {0} is not a FolderNode so we can't add an item to it.", itemidLoc);
                return(NativeMethods.E_UNEXPECTED);
            }

            // Loop through the files that are to be added and add them, one by one.
            foreach (string sourcePath in rgpszFilesToOpen)
            {
                string destPath  = null;
                Node   addedNode = null;

                switch (dwAddItemOperation)
                {
                case VSADDITEMOPERATION.VSADDITEMOP_CLONEFILE:
                    destPath  = Path.Combine(parentNode.AbsoluteDirectory, pszItemName);
                    addedNode = this.AddCopyOfFile(sourcePath, destPath, out canceled);
                    break;

                case VSADDITEMOPERATION.VSADDITEMOP_OPENFILE:
                    if (PackageUtility.IsRelative(this.RootDirectory, sourcePath))
                    {
                        destPath  = PackageUtility.MakeRelative(this.RootDirectory, sourcePath);
                        addedNode = this.AddExistingFile(destPath, true);
                    }
                    else
                    {
                        destPath  = Path.Combine(parentNode.AbsoluteDirectory, Path.GetFileName(sourcePath));
                        addedNode = this.AddCopyOfFile(sourcePath, destPath, out canceled);
                    }
                    break;

                case VSADDITEMOPERATION.VSADDITEMOP_LINKTOFILE:
                    Tracer.Fail("NYI: VSADDITEMOPERATION.VSADDITEMOP_LINKTOFILE.");
                    throw new NotImplementedException("Linking to files is not supported yet.");

                case VSADDITEMOPERATION.VSADDITEMOP_RUNWIZARD:
                    Tracer.Fail("NYI: VSADDITEMOPERATION.VSADDITEMOP_RUNWIZARD.");
                    throw new NotImplementedException("Running a wizard is not supported yet.");

                default:
                    Tracer.Fail("Unknown VSADDDITEMOPERATION '{0}'", dwAddItemOperation);
                    throw new ArgumentException(PackageUtility.SafeStringFormatInvariant("The dwAddItemOperation contains an unknown and unsupported value '{0}'.", dwAddItemOperation), "dwAddItemOperation");
                }

                // There were errors if the node is still null at this point.
                wereErrors = (addedNode == null);
            }

            pResult[0] = (canceled ? VSADDRESULT.ADDRESULT_Cancel : (wereErrors ? VSADDRESULT.ADDRESULT_Failure : VSADDRESULT.ADDRESULT_Success));
            return(NativeMethods.S_OK);
        }
        /// <summary>
        /// Creates new items in a project, adds existing files to a project, or causes Add Item wizards to be run
        /// </summary>
        /// <param name="itemIdLoc"></param>
        /// <param name="op"></param>
        /// <param name="itemName"></param>
        /// <param name="filesToOpen"></param>
        /// <param name="files">Array of file names. 
        /// If dwAddItemOperation is VSADDITEMOP_CLONEFILE the first item in the array is the name of the file to clone. 
        /// If dwAddItemOperation is VSADDITEMOP_OPENDIRECTORY, the first item in the array is the directory to open. 
        /// If dwAddItemOperation is VSADDITEMOP_RUNWIZARD, the first item is the name of the wizard to run, 
        /// and the second item is the file name the user supplied (same as itemName).</param>
        /// <param name="dlgOwner"></param>
        /// <param name="editorFlags"></param>
        /// <param name="editorType"></param>
        /// <param name="physicalView"></param>
        /// <param name="logicalView"></param>
        /// <param name="result"></param>
        /// <param name="bTrackChanges"></param>
        /// <returns>S_OK if it succeeds </returns>
        /// <remarks>The result array is initalized to failure.</remarks>
        public virtual int AddItemWithSpecific(uint itemIdLoc, VSADDITEMOPERATION op, string itemName, uint filesToOpen, string[] files, IntPtr dlgOwner, uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, VSADDRESULT[] result, bool bTrackChanges)
        {
            if (files == null || result == null || files.Length == 0 || result.Length == 0)
            {
                return VSConstants.E_INVALIDARG;
            }

            // Locate the node to be the container node for the file(s) being added
            // only projectnode or foldernode and file nodes are valid container nodes
            // We need to locate the parent since the item wizard expects the parent to be passed.
            HierarchyNode n = this.NodeFromItemId(itemIdLoc);
            if (n == null)
            {
                return VSConstants.E_INVALIDARG;
            }

            while ((!(n is ProjectNode)) && (!(n is FolderNode)) && (!this.CanFileNodesHaveChilds || !(n is FileNode)))
            {
                n = n.Parent;
            }
            Debug.Assert(n != null, "We should at this point have either a ProjectNode or FolderNode or a FileNode as a container for the new filenodes");

            if (op == VSADDITEMOPERATION.VSADDITEMOP_RUNWIZARD)
            {
                result[0] = this.RunWizard(n, itemName, files[0], dlgOwner);
                return VSConstants.S_OK;
            }

            string[] actualFiles = new string[files.Length];


            VSQUERYADDFILEFLAGS[] flags = this.GetQueryAddFileFlags(files);

            string baseDir = this.GetBaseDirectoryForAddingFiles(n);
            // If we did not get a directory for node that is the parent of the item then fail.
            if (String.IsNullOrEmpty(baseDir))
            {
                return VSConstants.E_FAIL;
            }

            // Pre-calculates some paths that we can use when calling CanAddItems
            List<string> filesToAdd = new List<string>();
            for (int index = 0; index < files.Length; index++)
            {
                string newFileName = String.Empty;

                string file = files[index];

                switch (op)
                {
                    case VSADDITEMOPERATION.VSADDITEMOP_CLONEFILE:
                        // New item added. Need to copy template to new location and then add new location 
                        newFileName = Path.Combine(baseDir, itemName);
                        break;

                    case VSADDITEMOPERATION.VSADDITEMOP_OPENFILE:
                    case VSADDITEMOPERATION.VSADDITEMOP_LINKTOFILE:
                        {
                            string fileName = Path.GetFileName(file);
                            newFileName = Path.Combine(baseDir, fileName);
                        }
                        break;
                }
                filesToAdd.Add(newFileName);
            }

            // Ask tracker objects if we can add files
            if (!this.tracker.CanAddItems(filesToAdd.ToArray(), flags))
            {
                // We were not allowed to add the files
                return VSConstants.E_FAIL;
            }

            if (!this.ProjectMgr.QueryEditProjectFile(false))
            {
                throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
            }

            // Add the files to the hierarchy
            int actualFilesAddedIndex = 0;
            for (int index = 0; index < filesToAdd.Count; index++)
            {
                HierarchyNode child;
                bool overwrite = false;
                string newFileName = filesToAdd[index];

                string file = files[index];
                result[0] = VSADDRESULT.ADDRESULT_Failure;

                child = this.FindChild(newFileName);
                if (child != null)
                {
                    bool skipOverwriteCheck = false;
                    // If the file to be added is an existing non-linked file part of the hierarchy then continue.
                    if (NativeMethods.IsSamePath(file, newFileName))
                    {
                        FileNode childFileNode = child as FileNode;
                        if (!(childFileNode != null && childFileNode.IsLink))
                        {
                            object isNonMemberItem = child.GetProperty((int)__VSHPROPID.VSHPROPID_IsNonMemberItem);
                            if (isNonMemberItem != null && ((bool)isNonMemberItem) && !this.isInPasteOrDrop)
                            {
                                result[0] = this.IncludeExistingNonMemberNode(child);
                            }
                            else if (op == VSADDITEMOPERATION.VSADDITEMOP_OPENFILE && this.isInPasteOrDrop)
                            {
                                int copyNumber = 0;
                                string originalFileName = newFileName;
                                while (File.Exists(newFileName))
                                {
                                    copyNumber++;
                                    string fileNoExtension = Path.GetFileNameWithoutExtension(originalFileName);
                                    string extension = Path.GetExtension(originalFileName);
                                    if (copyNumber == 1)
                                    {
                                        fileNoExtension = SR.GetString(SR.CopyOfFile, fileNoExtension);
                                    }
                                    else
                                    {
                                        fileNoExtension = SR.GetString(SR.CopyNOfFile, copyNumber, fileNoExtension);
                                    }
                                    newFileName = Path.Combine(baseDir, fileNoExtension + extension);
                                }
                                skipOverwriteCheck = true;
                            }
                            else
                            {
                                result[0] = VSADDRESULT.ADDRESULT_Cancel;
                            }
                            if (!skipOverwriteCheck)
                            {
                                continue;
                            }
                        }
                    }

                    if (!skipOverwriteCheck)
                    {
                        int canOverWriteExistingItem;
                        if (this.alreadyHandledOverwritePrompts)
                        {
                            canOverWriteExistingItem = this.SystemCanOverwriteExistingItem(file, newFileName);
                        }
                        else
                        {
                            canOverWriteExistingItem = this.CanOverwriteExistingItem(file, newFileName);
                        }

                        if (canOverWriteExistingItem == (int)OleConstants.OLECMDERR_E_CANCELED)
                        {
                            result[0] = VSADDRESULT.ADDRESULT_Cancel;
                            return canOverWriteExistingItem;
                        }
                        else if (canOverWriteExistingItem == VSConstants.S_OK)
                        {
                            overwrite = true;
                        }
                        else
                        {
                            return canOverWriteExistingItem;
                        }
                    }
                }

                // If the file to be added is not in the same path copy it.
                if (op != VSADDITEMOPERATION.VSADDITEMOP_LINKTOFILE && NativeMethods.IsSamePath(file, newFileName) == false)
                {
                    if ((!overwrite && !this.alreadyHandledOverwritePrompts) && File.Exists(newFileName))
                    {
                        string message = String.Format(CultureInfo.CurrentCulture, SR.GetString(SR.FileAlreadyExists, CultureInfo.CurrentUICulture), newFileName);
                        string title = string.Empty;
                        OLEMSGICON icon = OLEMSGICON.OLEMSGICON_QUERY;
                        OLEMSGBUTTON buttons = OLEMSGBUTTON.OLEMSGBUTTON_YESNO;
                        OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;
                        int messageboxResult = VsShellUtilities.ShowMessageBox(this.Site, title, message, icon, buttons, defaultButton);
                        if (messageboxResult == NativeMethods.IDNO)
                        {
                            result[0] = VSADDRESULT.ADDRESULT_Cancel;
                            return (int)OleConstants.OLECMDERR_E_CANCELED;
                        }
                    }

                    // Copy the file to the correct location.
                    // We will suppress the file change events to be triggered to this item, since we are going to copy over the existing file and thus we will trigger a file change event. 
                    // We do not want the filechange event to ocur in this case, similar that we do not want a file change event to occur when saving a file.
                    IVsFileChangeEx fileChange = this.site.GetService(typeof(SVsFileChangeEx)) as IVsFileChangeEx;
                    if (fileChange == null)
                    {
                        throw new InvalidOperationException();
                    }

                    try
                    {
                        fileChange.IgnoreFile(VSConstants.VSCOOKIE_NIL, newFileName, 1);
                        if (op == VSADDITEMOPERATION.VSADDITEMOP_CLONEFILE)
                        {
                            this.AddFileFromTemplate(file, newFileName);
                        }
                        else
                        {
                            PackageUtilities.CopyUrlToLocal(new Uri(file), newFileName);
                        }
                    }
                    finally
                    {
                        fileChange.IgnoreFile(VSConstants.VSCOOKIE_NIL, newFileName, 0);
                    }
                }

                if (op == VSADDITEMOPERATION.VSADDITEMOP_LINKTOFILE)
                {
                    Url baseUrl = new Url(this.ProjectFolder + Path.DirectorySeparatorChar);
                    string relativePath = baseUrl.MakeRelative(new Url(file));
                    string linkPath = baseUrl.MakeRelative(new Url(newFileName));

                    HierarchyNode existingLink = this.FindChild(file);
                    if (!this.AllowDuplicateLinks && existingLink != null)
                    {
                        string message = String.Format(CultureInfo.CurrentCulture, SR.GetString(SR.LinkAlreadyExistsInProject, CultureInfo.CurrentUICulture), newFileName);
                        string title = string.Empty;
                        OLEMSGICON icon = OLEMSGICON.OLEMSGICON_CRITICAL;
                        OLEMSGBUTTON buttons = OLEMSGBUTTON.OLEMSGBUTTON_OK;
                        OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;
                        VsShellUtilities.ShowMessageBox(this.Site, title, message, icon, buttons, defaultButton);
                        result[0] = VSADDRESULT.ADDRESULT_Cancel;
                        return (int)OleConstants.OLECMDERR_E_CANCELED;
                    }

                    if (overwrite)
                    {
                        child.Remove(false);
                    }

                    this.AddNewFileNodeToHierarchy(n, relativePath, linkPath);
                }
                else
                {
                    HierarchyNode existingLink = this.FindChild(newFileName);
                    bool bExistingIsExcluded = false;
                    HierarchyNode newFileNode = existingLink;
                    if (existingLink != null)
                    {
                        object isNonMemberItem = existingLink.GetProperty((int)__VSHPROPID.VSHPROPID_IsNonMemberItem);
                        bExistingIsExcluded = (isNonMemberItem != null) && ((bool)isNonMemberItem);
                        existingLink.Remove(false);
                        newFileNode = this.AddNewFileNodeToHierarchy(n, newFileName, null);
                    }
                    else if (overwrite)
                    {
                        this.OverwriteExistingItem(child);
                    }
                    else
                    {
                        //Add new filenode/dependentfilenode
                        newFileNode = this.AddNewFileNodeToHierarchyCore(n, newFileName, null);

                        if (bTrackChanges)
                        {
                            FireAddNodeEvent(newFileName);
                        }
                    }

                    if (this.isInPasteOrDrop && this.pasteAsNonMemberItem)
                    {
                        // special case for copying
                        // when copying, we want to maintain the destination's member status
                        if(existingLink == null || (this.dropAsCopy && bExistingIsExcluded) || !this.dropAsCopy)
                        {
                            newFileNode.SendExcludeFromProjectCommand();
                        }
                    }
                }

                result[0] = VSADDRESULT.ADDRESULT_Success;
                actualFiles[actualFilesAddedIndex++] = newFileName;
            }

            // Notify listeners that items were appended.
            if (actualFilesAddedIndex > 0)
                n.OnItemsAppended(n);

            //Open files if this was requested through the editorFlags
            bool openFiles = (editorFlags & (uint)__VSSPECIFICEDITORFLAGS.VSSPECIFICEDITOR_DoOpen) != 0;
            if (openFiles && actualFiles.Length <= filesToOpen)
            {
                for (int i = 0; i < filesToOpen; i++)
                {
                    if (!String.IsNullOrEmpty(actualFiles[i]))
                    {
                        string name = actualFiles[i];
                        HierarchyNode child = this.FindChild(name);
                        Debug.Assert(child != null, "We should have been able to find the new element in the hierarchy");
                        if (child != null)
                        {
                            IVsWindowFrame frame;
                            if (editorType == Guid.Empty)
                            {
                                Guid view = Guid.Empty;
                                ErrorHandler.ThrowOnFailure(this.OpenItem(child.ID, ref view, IntPtr.Zero, out frame));
                            }
                            else
                            {
                                ErrorHandler.ThrowOnFailure(this.OpenItemWithSpecific(child.ID, editorFlags, ref editorType, physicalView, ref logicalView, IntPtr.Zero, out frame));
                            }

                            // Show the window frame in the UI and make it the active window
                            if (frame != null)
                            {
                                ErrorHandler.ThrowOnFailure(frame.Show());
                            }
                        }
                    }
                }
            }

            return VSConstants.S_OK;
        }
 /// <summary>
 /// Add an existing item (file/folder) to the project if it already exist in our storage.
 /// </summary>
 /// <param name="parentNode">Node to that this item to</param>
 /// <param name="name">Name of the item being added</param>
 /// <param name="targetPath">Path of the item being added</param>
 /// <returns>Node that was added</returns>
 protected virtual HierarchyNode AddNodeIfTargetExistInStorage(HierarchyNode parentNode, string name, string targetPath, VSADDITEMOPERATION addItemOp)
 {
     HierarchyNode newNode = parentNode;
     // If the file/directory exist, add a node for it
     if (addItemOp == VSADDITEMOPERATION.VSADDITEMOP_LINKTOFILE || File.Exists(targetPath))
     {
         VSADDRESULT[] result = new VSADDRESULT[1];
         ErrorHandler.ThrowOnFailure(this.AddItem(parentNode.ID, addItemOp, name, 1, new string[] { targetPath }, IntPtr.Zero, result));
         if (result[0] != VSADDRESULT.ADDRESULT_Success)
             throw new ApplicationException();
         newNode = this.FindChild(targetPath);
         if (newNode == null)
             throw new ApplicationException();
     }
     else if (Directory.Exists(targetPath))
     {
         newNode = this.CreateFolderNodes(targetPath);
     }
     return newNode;
 }    
Exemple #52
0
        /// <include file='doc\Project.uex' path='docs/doc[@for="Project.IVsProject3.AddItemWithSpecific"]/*' />
        public virtual int AddItemWithSpecific(uint itemIdLoc, VSADDITEMOPERATION op, string itemName, uint filesToOpen, string[] files, IntPtr dlgOwner, uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, VSADDRESULT[] result)
        {
            CCITracing.TraceCall();
            result[0] = VSADDRESULT.ADDRESULT_Failure;
            //if (this.IsReadOnly) return; <-- bogus, the user can always change the project to non-readonly later when they choose to save it, or they can do saveas...
            HierarchyNode n = NodeFromItemId(itemIdLoc);
            if (n == null) return NativeMethods.E_INVALIDARG;

            string[] actualFiles = files;
            if (n.NodeType == HierarchyNodeType.Root || n.NodeType == HierarchyNodeType.Folder)
            {
                if (!this.projectMgr.Tracker.CanAddFiles(files))
                {
                    return NativeMethods.E_FAIL;
                }

                int index = 0;
                foreach (string file in files)
                {
                    HierarchyNode child;
                    bool fFileAdded = false;
                    bool fOverwrite = false;
                    string strBaseDir = Path.GetDirectoryName(this.filename);
                    string strNewFileName = "";

                    if (n.NodeType == HierarchyNodeType.Folder)
                    {
                        // add the folder to the path....
                        strBaseDir = n.Url;
                    }

                    switch (op)
                    {
                        case VSADDITEMOPERATION.VSADDITEMOP_CLONEFILE:
                            // new item added. Need to copy template to new location and then add new location 
                            strNewFileName = Path.Combine(strBaseDir, itemName);
                            break;

                        case VSADDITEMOPERATION.VSADDITEMOP_LINKTOFILE:// TODO: VSADDITEMOP_LINKTOFILE
                            // we do not support this right now
                            throw new NotImplementedException("VSADDITEMOP_LINKTOFILE");

                        case VSADDITEMOPERATION.VSADDITEMOP_OPENFILE: {
                                string strFileName = Path.GetFileName(file);
                                strNewFileName = Path.Combine(strBaseDir, strFileName);
                            }
                            break;

                        case VSADDITEMOPERATION.VSADDITEMOP_RUNWIZARD: // TODO: VSADDITEMOP_RUNWIZARD
                            throw new NotImplementedException("VSADDITEMOP_RUNWIZARD");
                    }
                    child = this.FindChild(strNewFileName);
                    if (child != null)
                    {
                        // file already exists in project... message box
                        actualFiles[index] = strNewFileName;
                        string msg = SR.GetString(SR.FileAlreadyInProject);
                        string caption = SR.GetString(SR.FileAlreadyInProjectCaption);

                        if (RTLAwareMessageBox.Show(null, msg, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, 0) == DialogResult.Yes)
                        {
                            child = null;
                            fOverwrite = true;
                        }
                    }

                    if (child == null)
                    {
                        // the next will be equal if file is already in the project DIR
                        if (NativeMethods.IsSamePath(file, strNewFileName) == false)
                        {
                            if (!fOverwrite && File.Exists(strNewFileName))
                            {
                                string msg = String.Format(SR.GetString(SR.FileAlreadyExists), strNewFileName);
                                string caption = SR.GetString(SR.FileAlreadyExistsCaption);
                                if (RTLAwareMessageBox.Show(null, msg, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, 0) != DialogResult.Yes)
                                {
                                    return NativeMethods.S_OK;
                                }
                            }

                            try {
                                this.CopyUrlToLocal(file, strNewFileName, op == VSADDITEMOPERATION.VSADDITEMOP_CLONEFILE);
                                actualFiles[index] = strNewFileName;
                            }
                            catch (Exception e)
                            {
                                string caption = SR.GetString(SR.FileCopyError);
                                RTLAwareMessageBox.Show(null, e.Message, caption, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0);
                                return NativeMethods.S_OK;
                            }
                        }

                        fFileAdded = true;
                    }

                    if (fFileAdded && !fOverwrite)
                    {
                        // now add the new thing to the project
                        child = this.projectMgr.AddExistingFile(strNewFileName);
                        n.AddChild(child);
                        this.projectMgr.Tracker.OnAddFile(strNewFileName);
                    }
                }

                n.OnItemsAppended(n);
                result[0] = VSADDRESULT.ADDRESULT_Success;
            }
            for (int i = 0; i < filesToOpen; i++)
            {
                string name = actualFiles[i];
                HierarchyNode child = this.FindChild(name);
                Debug.Assert(child != null, "We should have been able to find the new element in the hierarchy");
                if (child != null)
                {
                    IVsWindowFrame frame;
                    if (editorType == Guid.Empty)
                    {
                        Guid view = Guid.Empty;
                        NativeMethods.ThrowOnFailure(this.OpenItem(child.ID, ref view, IntPtr.Zero, out frame));
                    }
                    else
                    {
                        NativeMethods.ThrowOnFailure(this.OpenItemWithSpecific(child.ID, editorFlags, ref editorType, physicalView, ref logicalView, IntPtr.Zero, out frame));
                    }
                }
            }
            result[0] = VSADDRESULT.ADDRESULT_Success;
            return NativeMethods.S_OK;
        }
 int IVsProject.AddItem(uint itemidLoc, VSADDITEMOPERATION dwAddItemOperation, string pszItemName, uint cFilesToOpen, string[] rgpszFilesToOpen, IntPtr hwndDlgOwner, VSADDRESULT[] pResult)
 {
     if (Directory.Exists(rgpszFilesToOpen[0]))
     {
         AddProject(new MockVSHierarchy(rgpszFilesToOpen[0], this));
     }
     else
     {
         children.Add(rgpszFilesToOpen[0]);
         if (project != null)
         {
             FileInfo itemFileInfo = new FileInfo(rgpszFilesToOpen[0]);
             project.Save(fileName);
             FileInfo projectFileInfo = new FileInfo(project.FullFileName);
             string itemName = itemFileInfo.FullName.Substring(projectFileInfo.Directory.FullName.Length + 1);
             project.AddNewItem("Compile", itemName);
             project.Save(fileName);
         }
     }
     return VSConstants.S_OK;
 }
 public int AddItem(uint itemidLoc, VSADDITEMOPERATION dwAddItemOperation, string pszItemName, uint cFilesToOpen, string[] rgpszFilesToOpen, IntPtr hwndDlgOwner, VSADDRESULT[] pResult) {
     if (_innerProject3 != null && IsJavaScriptFile(pszItemName)) {
         Guid ourEditor = typeof(NodejsEditorFactory).GUID;
         Guid view = Guid.Empty;
         return _innerProject3.AddItemWithSpecific(
             itemidLoc,
             dwAddItemOperation,
             pszItemName,
             cFilesToOpen,
             rgpszFilesToOpen,
             hwndDlgOwner,
             dwAddItemOperation == VSADDITEMOPERATION.VSADDITEMOP_CLONEFILE ?
                 (uint)__VSSPECIFICEDITORFLAGS.VSSPECIFICEDITOR_DoOpen :
                 0,
             ref ourEditor,
             String.Empty,
             ref view,
             pResult
         );
     }
     return _innerProject.AddItem(itemidLoc, dwAddItemOperation, pszItemName, cFilesToOpen, rgpszFilesToOpen, hwndDlgOwner, pResult);
 }