/// <summary>
        /// Adds one or more files to the project.
        /// </summary>
        public async Task <IEnumerable <PhysicalFile> > AddExistingFilesAsync(params string[] filePaths)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            GetItemInfo(out IVsHierarchy hierarchy, out uint itemId, out _);

            VSADDRESULT[] result = new VSADDRESULT[filePaths.Count()];
            IVsProject    ip     = (IVsProject)hierarchy;

            ErrorHandler.ThrowOnFailure(ip.AddItem(itemId, VSADDITEMOPERATION.VSADDITEMOP_LINKTOFILE, string.Empty, (uint)filePaths.Count(), filePaths, IntPtr.Zero, result));

            List <PhysicalFile> files = new();

            foreach (string filePath in filePaths)
            {
                PhysicalFile?file = await PhysicalFile.FromFileAsync(filePath);

                if (file != null)
                {
                    files.Add(file);
                }
            }

            return(files);
        }
Beispiel #2
0
 internal static void AddFileToProject(IVsProject vsProject, string parametersXmlPath)
 {
     string[] files = new string[1] {
         parametersXmlPath
     };
     VSADDRESULT[] result = new VSADDRESULT[1];
     vsProject.AddItem(
         VSConstants.VSITEMID_ROOT,
         VSADDITEMOPERATION.VSADDITEMOP_OPENFILE,
         parametersXmlPath,
         1,
         files,
         IntPtr.Zero,
         result);
 }
Beispiel #3
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));
        }
Beispiel #4
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));
        }
Beispiel #5
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));
 }
Beispiel #6
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));
 }
Beispiel #7
0
        /// <summary>
        /// Adds a new item in the project
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        // FXCOP: False positive
        public HierarchyNode AddItem(string name)
        {
            Guard.ArgumentNotNullOrEmptyString(name, "name");
            if (!CanAddItem(name))
            {
                throw new InvalidOperationException(
                          String.Format(
                              CultureInfo.CurrentCulture,
                              Properties.Resources.InvalidFileName,
                              name));
            }
            FileInfo fileInfo  = null;
            string   subFolder = string.Empty;

            if (System.IO.Path.IsPathRooted(name))
            {
                fileInfo = new FileInfo(name);
            }
            else
            {
                fileInfo = new FileInfo(System.IO.Path.Combine(ProjectDir, name));
                int subFolderIndex = name.LastIndexOf(System.IO.Path.DirectorySeparatorChar);
                if (subFolderIndex != -1)
                {
                    subFolder = name.Substring(0, subFolderIndex);
                }
            }
            if (fileInfo.Name.Equals(fileInfo.Extension, StringComparison.OrdinalIgnoreCase))
            {
                throw new InvalidOperationException(
                          String.Format(
                              CultureInfo.CurrentCulture,
                              Properties.Resources.CannotCreateItemWithEmptyName));
            }
            if (!File.Exists(fileInfo.FullName))
            {
                Directory.CreateDirectory(fileInfo.Directory.FullName);
                File.Create(fileInfo.FullName).Dispose();
            }
            uint itemId = VSConstants.VSITEMID_NIL;
            int  found  = 1;
            VSDOCUMENTPRIORITY docPri = VSDOCUMENTPRIORITY.DP_Standard;
            int hr = project.IsDocumentInProject(fileInfo.FullName, out found, new VSDOCUMENTPRIORITY[] { docPri }, out itemId);

            Marshal.ThrowExceptionForHR(hr);
            if (found == 0)
            {
                VSADDRESULT   result        = VSADDRESULT.ADDRESULT_Cancel;
                uint          folderId      = this.ItemId;
                HierarchyNode subFolderNode = FindSubFolder(subFolder);
                if (subFolderNode != null)
                {
                    folderId = subFolderNode.ItemId;
                }
                hr = project.AddItem(folderId,
                                     VSADDITEMOPERATION.VSADDITEMOP_OPENFILE,
                                     fileInfo.Name, 1, new string[] { fileInfo.FullName },
                                     IntPtr.Zero, new VSADDRESULT[] { result });
                Marshal.ThrowExceptionForHR(hr);
            }
            hr = project.IsDocumentInProject(fileInfo.FullName, out found, new VSDOCUMENTPRIORITY[] { docPri }, out itemId);
            Marshal.ThrowExceptionForHR(hr);
            if (found == 1)
            {
                return(new HierarchyNode(this, itemId));
            }
            return(null);
        }