protected override async Task<bool> TryHandleCommandAsyncInternal(IProjectTree rDataNode) {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
            
            // Don't do anything for file preview
            var uiShellOpenDocument = VsAppShell.Current.GetGlobalService<IVsUIShellOpenDocument3>(typeof(SVsUIShellOpenDocument));
            if (uiShellOpenDocument != null && ((__VSNEWDOCUMENTSTATE) uiShellOpenDocument.NewDocumentState).HasFlag(__VSNEWDOCUMENTSTATE.NDS_Provisional)) {
                return true;
            }

            return await base.TryHandleCommandAsyncInternal(rDataNode);
        }
        public IProjectTree ApplyModifications(IProjectTree tree, IProjectTreeProvider projectTreeProvider)
        {
#if Dev12
            if (tree.Capabilities.Contains(ProjectTreeCapabilities.ProjectRoot))
                tree = tree.SetIcon(Resources.NuProj);
#else
            if (tree.Capabilities.Contains(ProjectTreeCapabilities.ProjectRoot))
                tree = tree.SetIcon(KnownMonikers.NuGet.ToProjectSystemType());
#endif

            return tree;
        }
        public IProjectTree ApplyModifications(IProjectTree tree, IProjectTreeProvider projectTreeProvider)
        {
            // Only set the icon for the root project node.  We could choose to set different icons for nodes based
            // on various criteria, not just Capabilities, if we wished.
            if (tree.Capabilities.Contains(ProjectTreeCapabilities.ProjectRoot))
            {
                tree = tree.SetIcon(XSharpImagesMonikers.ProjectIconImageMoniker.ToProjectSystemType());
            }
            if (tree.BrowseObjectProperties?.ItemType?.ToLower() == "compile")
            //if (tree.Capabilities.Contains(ProjectTreeCapabilities.SourceFile))
            {
                tree = tree.SetIcon(XSharpImagesMonikers.ItemIconImageMoniker.ToProjectSystemType());
            }

            return tree;
        }
 public IProjectTree ApplyModifications(IProjectTree tree, IProjectTreeProvider projectTreeProvider) {
     if (tree != null) {
         if (tree.Capabilities.Contains(ProjectTreeCapabilities.ProjectRoot)) {
             tree = tree.SetIcon(ProjectIconProvider.ProjectNodeImage.ToProjectSystemType());
         } else if (tree.Capabilities.Contains(ProjectTreeCapabilities.FileOnDisk)) {
             string ext = Path.GetExtension(tree.FilePath).ToLowerInvariant();
             if (ext == ".r") {
                 tree = tree.SetIcon(ProjectIconProvider.RFileNodeImage.ToProjectSystemType());
             } else if (ext == ".rdata" || ext == ".rhistory") {
                 tree = tree.SetIcon(ProjectIconProvider.RDataFileNodeImage.ToProjectSystemType());
             }
             if (ext == ".md" || ext == ".rmd") {
                 tree = tree.SetIcon(KnownMonikers.MarkdownFile.ToProjectSystemType());
             }
         }
     }
     return tree;
 }
        protected virtual async Task<bool> TryHandleCommandAsyncInternal(IProjectTree rDataNode) {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            MessageButtons messageResult = VsAppShell.Current.ShowMessage(string.Format(CultureInfo.CurrentCulture, Resources.LoadWorkspaceIntoGlobalEnvironment, rDataNode.FilePath), MessageButtons.YesNo);
            if (messageResult == MessageButtons.No) {
                return true;
            }

            using (var evaluation = await _session.BeginEvaluationAsync()) {
                var result = await evaluation.LoadWorkspace(rDataNode.FilePath);

                if (result.Error != null) {
                    var message = string.Format(CultureInfo.CurrentCulture, Resources.LoadWorkspaceFailedMessageFormat,
                        rDataNode.FilePath, result.Error);
                    VsAppShell.Current.ShowErrorMessage(message);
                }
            }

            return true;
        }
        protected virtual async Task<bool> TryHandleCommandAsyncInternal(IProjectTree rDataNode) {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            MessageButtons messageResult = VsAppShell.Current.ShowMessage(string.Format(CultureInfo.CurrentCulture, Resources.LoadWorkspaceIntoGlobalEnvironment, rDataNode.FilePath), MessageButtons.YesNo);
            if (messageResult == MessageButtons.No) {
                return true;
            }

            var session = _workflowProvider.GetOrCreate().RSession;
            try {
                await session.LoadWorkspaceAsync(rDataNode.FilePath);
            } catch (RException ex) {
                var message = string.Format(CultureInfo.CurrentCulture, Resources.LoadWorkspaceFailedMessageFormat,
                    rDataNode.FilePath, ex.Message);
                VsAppShell.Current.ShowErrorMessage(message);
            } catch (OperationCanceledException) {
            }

            return true;
        }
 private bool IsRData(IProjectTree node) {
     var path = node.FilePath;
     return path != null && !_unconfiguredProject.IsOutsideProjectDirectory(path) && Path.GetExtension(path).Equals(".RData", StringComparison.CurrentCultureIgnoreCase);
 }
Exemple #8
0
 /// <summary>
 /// Gets a value indicating whether a given set of nodes can be copied or moved underneath some given node.
 /// </summary>
 /// <param name="nodes">The set of nodes the user wants to copy or move.</param>
 /// <param name="receiver">
 /// The target node where <paramref name="nodes"/> should be copied or moved to.
 /// May be <c>null</c> to determine whether a given set of nodes could allowably be copied anywhere (not
 /// necessarily everywhere).
 /// </param>
 /// <param name="deleteOriginal"><c>true</c> for a move operation; <c>false</c> for a copy operation.</param>
 /// <returns><c>true</c> if such a move/copy operation would be allowable; <c>false</c> otherwise.</returns>
 public override bool CanCopy(IImmutableSet <IProjectTree> nodes,
                              IProjectTree receiver,
                              bool deleteOriginal = false)
 {
     return(false);
 }
Exemple #9
0
 public bool TryFindImmediateChild(string caption, out IProjectTree subtree)
 {
     subtree = null;
     return(false);
 }
Exemple #10
0
 public IProjectTree Replace(IProjectTree subtree)
 {
     return(null);
 }
Exemple #11
0
 protected override bool CanAdd(IProjectTree target)
 {
     return(OrderingHelper.HasValidDisplayOrder(target));
 }
Exemple #12
0
 protected override async Task CpsFileRenameAsync(IProjectTreeActionHandlerContext context, IProjectTree node, string value)
 {
     await Task.CompletedTask;
 }
Exemple #13
0
 bool IProjectTree.TryFind(IntPtr nodeId, out IProjectTree subtree)
 {
     throw new NotImplementedException();
 }
Exemple #14
0
 protected override bool TryMove(Project project, IProjectTree node)
 {
     return(OrderingHelper.TryMoveUp(project, node));
 }
Exemple #15
0
 protected override bool CanMove(IProjectTree node)
 {
     return(OrderingHelper.CanMoveUp(node));
 }
 /// <summary>
 /// Gets the direct child of <paramref name="tree"/> with <paramref name="caption"/>
 /// if found, otherwise <see langword="null"/>.
 /// </summary>
 public static IProjectTree?FindChildWithCaption(this IProjectTree tree, string caption)
 {
     return(tree.Children.FirstOrDefault(
                (child, cap) => string.Equals(cap, child.Caption, StringComparison.OrdinalIgnoreCase),
                caption));
 }
Exemple #17
0
        /// <summary>
        /// Generates the original references directory tree.
        /// </summary>
        protected override void Initialize()
        {
#pragma warning disable RS0030 // symbol LoadedProject is banned
            using (UnconfiguredProjectAsynchronousTasksService.LoadedProject())
#pragma warning restore RS0030 // symbol LoadedProject is banned
            {
                base.Initialize();

                // this.IsApplicable may take a project lock, so we can't do it inline with this method
                // which is holding a private lock.  It turns out that doing it asynchronously isn't a problem anyway,
                // so long as we guard against races with the Dispose method.
                UnconfiguredProjectAsynchronousTasksService.LoadedProjectAsync(
                    async delegate
                {
                    await TaskScheduler.Default.SwitchTo(alwaysYield: true);
                    UnconfiguredProjectAsynchronousTasksService
                    .UnloadCancellationToken.ThrowIfCancellationRequested();

                    lock (SyncObject)
                    {
                        Verify.NotDisposed(this);

                        // Issue this token before hooking the SnapshotChanged event to prevent a race
                        // where a snapshot tree is replaced by the initial, empty tree created below.
                        // The handler will cancel this token before submitting its update.
                        CancellationToken initialTreeCancellationToken = _treeUpdateCancellationSeries.CreateNext();

                        _dependenciesSnapshotProvider.SnapshotChanged += OnDependenciesSnapshotChanged;

                        Task <IProjectVersionedValue <IProjectTreeSnapshot> > nowait = SubmitTreeUpdateAsync(
                            (treeSnapshot, configuredProjectExports, cancellationToken) =>
                        {
                            IProjectTree dependenciesNode = CreateDependenciesFolder();

                            // TODO create providers nodes that can be visible when empty
                            //dependenciesNode = CreateOrUpdateSubTreeProviderNodes(dependenciesNode,
                            //                                                      cancellationToken);

                            return(Task.FromResult(new TreeUpdateResult(dependenciesNode)));
                        },
                            initialTreeCancellationToken);
                    }
                },
                    registerFaultHandler: true);
            }

            IProjectTree CreateDependenciesFolder()
            {
                var values = new ReferencesProjectTreeCustomizablePropertyValues
                {
                    Caption      = VSResources.DependenciesNodeName,
                    Icon         = ManagedImageMonikers.ReferenceGroup.ToProjectSystemType(),
                    ExpandedIcon = ManagedImageMonikers.ReferenceGroup.ToProjectSystemType(),
                    Flags        = DependencyTreeFlags.DependenciesRootNodeFlags
                };

                // Allow property providers to perform customization.
                // These are ordered from lowest priority to highest, allowing higher priority
                // providers to override lower priority providers.
                foreach (IProjectTreePropertiesProvider provider in _projectTreePropertiesProviders.ExtensionValues())
                {
                    provider.CalculatePropertyValues(null, values);
                }

                // Note that all the parameters are specified so we can force this call to an
                // overload of NewTree available prior to 15.5 versions of CPS. Once a 15.5 build
                // is publicly available we can move this to an overload with default values for
                // most of the parameters, and we'll only need to pass the interesting ones.
                return(NewTree(
                           caption: values.Caption,
                           filePath: null,
                           browseObjectProperties: null,
                           icon: values.Icon,
                           expandedIcon: values.ExpandedIcon,
                           visible: true,
                           flags: values.Flags));
            }
        }
Exemple #18
0
 /// <summary>
 /// This is still needed for graph nodes search
 /// </summary>
 /// <param name="node"></param>
 /// <returns></returns>
 public override string GetPath(IProjectTree node)
 {
     return(node.FilePath);
 }
Exemple #19
0
 /// <summary>
 /// Finds dependencies child nodes by their path. We need to override it since
 /// we need to find children under either:
 ///     - our dependencies root node.
 ///     - dependency sub tree nodes
 ///     - dependency sub tree top level nodes
 /// (deeper levels will be graph nodes with additional info, not direct dependencies
 /// specified in the project file)
 /// </summary>
 public override IProjectTree FindByPath(IProjectTree root, string path)
 {
     return(_viewProviders.FirstOrDefault()?.Value.FindByPath(root, path));
 }
 protected override Task <bool> TryHandleCommandAsync(IProjectTree node, bool focused, long commandExecuteOptions, IntPtr variantArgIn, IntPtr variantArgOut)
 {
     return(TaskResult.False);
 }
Exemple #21
0
 public bool TryFindImmediateChild(string caption, out IProjectTree subtree)
 {
     throw new NotImplementedException();
 }
Exemple #22
0
 IProjectTree IProjectTree.Replace(IProjectTree subtree)
 {
     return(subtree);
 }
        /// <summary>
        /// Performs a move on any items that were added based on the previous includes.
        /// </summary>
        public static Task MoveAsync(ConfiguredProject configuredProject, IProjectAccessor accessor, ImmutableHashSet <string> previousIncludes, IProjectTree target, OrderingMoveAction action)
        {
            Requires.NotNull(configuredProject, nameof(configuredProject));
            Requires.NotNull(accessor, nameof(accessor));
            Requires.NotNull(previousIncludes, nameof(previousIncludes));
            Requires.NotNull(target, nameof(target));

            return(accessor.OpenProjectForWriteAsync(configuredProject, project =>
            {
                // We do a sanity re-evaluation to absolutely ensure changes were met.
                project.ReevaluateIfNecessary();
                ImmutableArray <ProjectItemElement> addedElements = GetAddedItemElements(previousIncludes, project);

                // TODO: Should the result (success or failure) be ignored?
                _ = action switch
                {
                    OrderingMoveAction.MoveToTop => TryMoveElementsToTop(project, addedElements, target),
                    OrderingMoveAction.MoveAbove => TryMoveElementsAbove(project, addedElements, target),
                    OrderingMoveAction.MoveBelow => TryMoveElementsBelow(project, addedElements, target),
                    _ => false
                };
            }));
Exemple #24
0
 bool IProjectTree.TryFindImmediateChild(string caption, out IProjectTree subtree)
 {
     subtree = Children.FirstOrDefault(c => c.Caption == caption);
     return(subtree != null);
 }
        public static string WriteToString(IProjectTree tree)
        {
            var writer = new ProjectTreeWriter(tree, ProjectTreeWriterOptions.AllProperties);

            return(writer.WriteToString());
        }
Exemple #26
0
 protected override Task OnAddingNodesAsync(IProjectTree nodeToAddTo)
 {
     return(_addItemDialogService.ShowAddExistingItemsDialogAsync(nodeToAddTo));
 }
        /// <summary>
        ///     Visits the entire tree, calling <see cref="IProjectTreePropertiesProvider.CalculatePropertyValues(IProjectTreeCustomizablePropertyContext, IProjectTreeCustomizablePropertyValues)"/>
        ///     for every node.
        /// </summary>
        public static IProjectTree ChangePropertyValuesForEntireTree(this IProjectTreePropertiesProvider propertiesProvider, IProjectTree tree, IImmutableDictionary <string, string>?projectTreeSettings = null)
        {
            // Cheat here, because the IProjectTree that we get from ProjectTreeParser is mutable, we want to clone it
            // so that any properties providers changes don't affect the "original" tree. If we implemented a completely
            // immutable tree, then we wouldn't have to do that - but that's currently a lot of work for test-only purposes.
            string treeAsString = ProjectTreeWriter.WriteToString(tree);

            return(ChangePropertyValuesWalkingTree(propertiesProvider, ProjectTreeParser.Parse(treeAsString), projectTreeSettings));
        }
Exemple #28
0
 public IEnumerable <IProjectTreeDiff> ChangesSince(IProjectTree priorVersion)
 {
     return(null);
 }
        private static IProjectTree ChangePropertyValuesWalkingTree(IProjectTreePropertiesProvider propertiesProvider, IProjectTree tree, IImmutableDictionary <string, string>?projectTreeSettings)
        {
            tree = ChangePropertyValues(propertiesProvider, tree, projectTreeSettings);

            foreach (IProjectTree child in tree.Children)
            {
                tree = ChangePropertyValuesWalkingTree(propertiesProvider, child, projectTreeSettings).Parent !;
            }

            return(tree);
        }
Exemple #30
0
 public bool TryFind(IntPtr nodeId, out IProjectTree subtree)
 {
     subtree = null;
     return(false);
 }
 public ProjectTreeCustomizablePropertyContextAndValues(IProjectTree tree, IImmutableDictionary <string, string>?projectTreeSettings)
 {
     _tree = tree;
     ProjectTreeSettings = projectTreeSettings ?? ImmutableDictionary <string, string> .Empty;
 }
Exemple #32
0
 public IProjectTree Add(IProjectTree subtree)
 {
     ((TestProjectTree)subtree).Parent = this;
     _children.Add((TestProjectTree)subtree);
     return(subtree);
 }
        internal void Verify(AppDesignerFolderProjectTreePropertiesProvider provider, IProjectTree expected, IProjectTree input, string folderName = null, bool?contentOnlyVisibleInShowAllFiles = null)
        {
            IImmutableDictionary <string, string> projectTreeSettings         = ImmutableDictionary <string, string> .Empty;
            IImmutableDictionary <string, IProjectRuleSnapshot> ruleSnapshots = IProjectRuleSnapshotsFactory.Create();

            if (folderName != null)
            {
                ruleSnapshots = ruleSnapshots.Add(AppDesigner.SchemaName, AppDesigner.FolderNameProperty, folderName);
            }

            if (contentOnlyVisibleInShowAllFiles != null)
            {
                ruleSnapshots = ruleSnapshots.Add(AppDesigner.SchemaName, AppDesigner.ContentsVisibleOnlyInShowAllFilesProperty, contentOnlyVisibleInShowAllFiles.Value.ToString());
            }

            provider.UpdateProjectTreeSettings(ruleSnapshots, ref projectTreeSettings);

            IProjectTree result = provider.ChangePropertyValuesForEntireTree(input, projectTreeSettings);

            AssertAreEquivalent(expected, result);
        }
 protected abstract bool ShouldHandle(IProjectTree node);
Exemple #35
0
 IEnumerable <IProjectTreeDiff> IProjectTree.ChangesSince(IProjectTree priorVersion)
 {
     throw new NotImplementedException();
 }
        private static IProjectTree ChangePropertyValues(IProjectTreePropertiesProvider propertiesProvider, IProjectTree child, IImmutableDictionary <string, string>?projectTreeSettings)
        {
            var propertyContextAndValues = new ProjectTreeCustomizablePropertyContextAndValues(child, projectTreeSettings);

            propertiesProvider.CalculatePropertyValues(propertyContextAndValues, propertyContextAndValues);

            return(propertyContextAndValues.Tree);
        }
Exemple #37
0
 public IProjectTree Replace(IProjectTree subtree)
 {
     throw new NotImplementedException();
 }