public override void BuildNode(ITreeBuilder builder, object dataObject, NodeInfo nodeInfo)
        {
            if (!builder.Options["ShowVersionControlOverlays"])
            {
                return;
            }

            // Add status overlays

            if (dataObject is WorkspaceObject)
            {
                WorkspaceObject ce  = (WorkspaceObject)dataObject;
                Repository      rep = VersionControlService.GetRepository(ce);
                if (rep != null)
                {
                    rep.GetDirectoryVersionInfoAsync(ce.BaseDirectory, false, false);
                    AddFolderOverlay(rep, ce.BaseDirectory, nodeInfo, false);
                }
                return;
            }
            else if (dataObject is ProjectFolder)
            {
                ProjectFolder ce = (ProjectFolder)dataObject;
                if (ce.ParentWorkspaceObject != null)
                {
                    Repository rep = VersionControlService.GetRepository(ce.ParentWorkspaceObject);
                    if (rep != null)
                    {
                        rep.GetDirectoryVersionInfoAsync(ce.Path, false, false);
                        AddFolderOverlay(rep, ce.Path, nodeInfo, true);
                    }
                }
                return;
            }

            WorkspaceObject prj;
            FilePath        file;

            if (dataObject is ProjectFile)
            {
                ProjectFile pfile = (ProjectFile)dataObject;
                prj  = pfile.Project;
                file = pfile.FilePath;
            }
            else
            {
                SystemFile pfile = (SystemFile)dataObject;
                prj  = pfile.ParentWorkspaceObject;
                file = pfile.Path;
            }

            if (prj == null)
            {
                return;
            }

            Repository repo = VersionControlService.GetRepository(prj);

            if (repo == null)
            {
                return;
            }

            if (repo.TryGetVersionInfo(file, out var vi))
            {
                var overlay = VersionControlService.LoadOverlayIconForStatus(vi.Status);
                if (overlay != null)
                {
                    nodeInfo.OverlayBottomRight = overlay;
                }
            }
        }
Exemple #2
0
        static async void OnEntryAdded(object o, SolutionItemEventArgs args)
        {
            if (args is SolutionItemChangeEventArgs && ((SolutionItemChangeEventArgs)args).Reloading)
            {
                return;
            }

            // handles addition of solutions and projects
            SolutionFolderItem parent = (SolutionFolderItem)args.SolutionItem.ParentFolder;

            if (parent == null)
            {
                return;
            }

            Repository repo = GetRepository(parent);

            if (repo == null)
            {
                return;
            }

            SolutionFolderItem entry       = args.SolutionItem;
            Repository         currentRepo = GetRepository(entry);

            if (currentRepo != null && currentRepo.VersionControlSystem != repo.VersionControlSystem)
            {
                // If the item is already under version control using a different version control system
                // don't add it to the parent repo.
                return;
            }

            string path = entry.BaseDirectory;

            // While we /could/ call repo.Add with `recursive = true', we don't
            // necessarily want to add files under the project/solution directory
            // that may not be a part of this project/solution.

            var files = new HashSet <string> {
                path
            };

            SolutionItemAddFiles(path, entry, files);

            if (entry is SolutionFolder && files.Count == 1)
            {
                return;
            }
            try {
                using (ProgressMonitor monitor = GetStatusMonitor()) {
                    foreach (var file in files)
                    {
                        var status = await repo.GetDirectoryVersionInfoAsync(file, false, false, monitor.CancellationToken);

                        foreach (var v in status)
                        {
                            if (!v.IsVersioned && files.Contains(v.LocalPath))
                            {
                                await repo.AddAsync(v.LocalPath, false, monitor);
                            }
                        }
                    }
                }
                if (entry is SolutionFolder && files.Count == 1)
                {
                    return;
                }

                NotifyFileStatusChanged(new FileUpdateEventArgs(repo, parent.BaseDirectory, true));
            } catch (OperationCanceledException) {
                return;
            } catch (Exception e) {
                LoggingService.LogInternalError(e);
            }
        }