Beispiel #1
0
        private IEnumerable <string> GetFolders(string fullPath, IProjectTreeServiceState state)
        {
            // Roslyn wants the effective set of folders from the source up to, but not including the project
            // root to handle the cases where linked files have a different path in the tree than what its path
            // on disk is. It uses these folders for things that create files alongside others, such as extract
            // interface.

            IProjectTree tree = state.TreeProvider.FindByPath(state.Tree, fullPath);

            if (tree == null)
            {
                yield break;    // We got a tree that is out-of-date than what our evaluation is based on
            }
            IProjectTree parent = tree;

            do
            {
                // Source files can be nested under other files
                if (parent.IsFolder)
                {
                    yield return(parent.Caption);
                }

                parent = parent.Parent;
            } while (!parent.IsRoot());
        }
Beispiel #2
0
        /// <summary>
        /// Create a file with the given template file and add it to the parent node.
        /// </summary>
        /// <param name="templateFile">The name of the template zip file.</param>
        /// <param name="parentNode">The node to which the new file will be added.</param>
        /// <param name="fileName">The name of the file to be created.</param>
        /// <returns>true if file is added successfully.</returns>
        public async Task <bool> CreateFileAsync(string templateFile, IProjectTree parentNode, string fileName)
        {
            Requires.NotNull(templateFile, nameof(templateFile));
            Requires.NotNull(parentNode, nameof(parentNode));
            Requires.NotNull(fileName, nameof(fileName));

            await _projectVsServices.ThreadingService.SwitchToUIThread();

            Project project  = _projectVsServices.VsHierarchy.GetProperty <Project>(Shell.VsHierarchyPropID.ExtObject, null);
            var     solution = project.DTE.Solution as Solution2;

            string templateFilePath = solution.GetProjectItemTemplate(templateFile, GetTemplateLanguage(project));

            if (templateFilePath != null)
            {
                var parentId = parentNode.IsRoot() ? (uint)VSConstants.VSITEMID.Root : (uint)parentNode.Identity;
                var result   = new VSADDRESULT[1];
                _projectVsServices.VsProject.AddItemWithSpecific(parentId, VSADDITEMOPERATION.VSADDITEMOP_RUNWIZARD, fileName, 0, new string[] { templateFilePath }, IntPtr.Zero, 0, Guid.Empty, null, Guid.Empty, result);

                if (result[0] == VSADDRESULT.ADDRESULT_Success)
                {
                    return(true);
                }
            }

            return(false);
        }
        protected override Task <CommandStatusResult> GetCommandStatusAsync(IProjectTree node, bool focused, string commandText, CommandStatus progressiveStatus)
        {
            if (node.IsRoot())
            {
                return(GetCommandStatusResult.Handled(commandText, CommandStatus.Enabled));
            }

            return(GetCommandStatusResult.Unhandled);
        }
        public string GetAddNewItemDirectory(IProjectTree target)
        {
            if (target.IsRoot())
            {
                return(string.Empty);
            }

            return(Path.Combine(GetAddNewItemDirectory(target.Parent), target.Caption));
        }
        protected override async Task <bool> TryHandleCommandAsync(IProjectTree node, bool focused, long commandExecuteOptions, IntPtr variantArgIn, IntPtr variantArgOut)
        {
            if (node.IsRoot())
            {
                await _threadingService.SwitchToUIThread();

                VsShellUtilities.OpenDocumentWithSpecificEditor(_serviceProvider, _unconfiguredProject.FullPath, EditorFactoryGuid, Guid.Empty);

                return(true);
            }

            return(false);
        }
Beispiel #6
0
        public string?GetAddNewItemDirectory(IProjectTree target)
        {
            if (target.Flags.Contains(ProjectTreeFlags.Common.DisableAddItemFolder))
            {
                return(null);
            }

            if (target.IsRoot())
            {
                return(string.Empty);
            }

            return(Path.Combine(GetAddNewItemDirectory(target.Parent !), target.Caption));
        }
Beispiel #7
0
 /// <summary>
 /// Returns HierarchyId for given IProjectTree
 /// </summary>
 /// <param name="tree"></param>
 /// <returns></returns>
 public static HierarchyId GetHierarchyId(this IProjectTree tree) =>
 new HierarchyId(tree.IsRoot() ? VSConstants.VSITEMID_ROOT : unchecked ((uint)tree.Identity));
 /// <summary>
 ///     Returns the specified <see cref="HierarchyId"/> for the specified node.
 /// </summary>
 /// <remarks>
 ///     This method should only be called on and the result used on the UI thread.
 /// </remarks>
 public static HierarchyId GetHierarchyId(this IProjectTree node)
 {
     return(new HierarchyId(node.IsRoot() ? VSConstants.VSITEMID_ROOT : unchecked ((uint)node.Identity)));
 }
Beispiel #9
0
 protected override bool ShouldHandle(IProjectTree node) => node.IsRoot();
Beispiel #10
0
 private bool ShouldHandle(IProjectTree node) => node.IsRoot();
 private bool ShouldHandle(IProjectTree node) => node.IsRoot() && _projectCapabiltiesService.Contains("OpenProjectFile");