Ejemplo n.º 1
0
        async Task DoOpenFile(IPullRequestFileNode file, bool workingDirectory)
        {
            try
            {
                var fullPath = ViewModel.GetLocalFilePath(file);
                var fileName = workingDirectory ? fullPath : await ViewModel.ExtractFile(file, true, Encoding.UTF8);

                using (new NewDocumentStateScope(__VSNEWDOCUMENTSTATE.NDS_Provisional, VSConstants.NewDocumentStateReason.SolutionExplorer))
                {
                    var window = Services.Dte.ItemOperations.OpenFile(fileName);
                    window.Document.ReadOnly = !workingDirectory;

                    var buffer = GetBufferAt(fileName);
                    AddBufferTag(buffer, ViewModel.Session, fullPath, false);
                }

                if (workingDirectory)
                {
                    await UsageTracker.IncrementPRDetailsOpenFileInSolution();
                }
                else
                {
                    await UsageTracker.IncrementPRDetailsViewFile();
                }
            }
            catch (Exception e)
            {
                ShowErrorInStatusBar("Error opening file", e);
            }
        }
        async Task DoDiffFile(IPullRequestFileNode file)
        {
            try
            {
                var fileNames = await ViewModel.ExtractDiffFiles(file);

                var leftLabel  = $"{file.FileName};{ViewModel.TargetBranchDisplayName}";
                var rightLabel = $"{file.FileName};PR {ViewModel.Model.Number}";
                var caption    = $"Diff - {file.FileName}";
                var tooltip    = $"{leftLabel}\nvs.\n{rightLabel}";
                var options    = __VSDIFFSERVICEOPTIONS.VSDIFFOPT_DetectBinaryFiles |
                                 __VSDIFFSERVICEOPTIONS.VSDIFFOPT_LeftFileIsTemporary;

                if (!ViewModel.IsCheckedOut)
                {
                    options |= __VSDIFFSERVICEOPTIONS.VSDIFFOPT_RightFileIsTemporary;
                }

                Services.DifferenceService.OpenComparisonWindow2(
                    fileNames.Item1,
                    fileNames.Item2,
                    caption,
                    tooltip,
                    leftLabel,
                    rightLabel,
                    string.Empty,
                    string.Empty,
                    (uint)options);
            }
            catch (Exception e)
            {
                ShowErrorInStatusBar("Error opening file", e);
            }
        }
        /// <summary>
        /// Gets a file as it appears in the pull request.
        /// </summary>
        /// <param name="file">The changed file.</param>
        /// <param name="head">
        /// If true, gets the file at the PR head, otherwise gets the file at the PR merge base.
        /// </param>
        /// <returns>The path to a temporary file.</returns>
        public Task <string> ExtractFile(IPullRequestFileNode file, bool head)
        {
            var relativePath = Path.Combine(file.DirectoryPath, file.FileName);
            var encoding     = pullRequestsService.GetEncoding(LocalRepository, relativePath);

            return(pullRequestsService.ExtractFile(LocalRepository, model, relativePath, head, encoding).ToTask());
        }
Ejemplo n.º 4
0
        async Task DoOpenFile(IPullRequestFileNode file, bool workingDirectory)
        {
            try
            {
                var fullPath = ViewModel.GetLocalFilePath(file);
                var fileName = workingDirectory ? fullPath : await ViewModel.ExtractFile(file, true);

                using (workingDirectory ? null : OpenInProvisionalTab())
                {
                    var window = Services.Dte.ItemOperations.OpenFile(fileName);
                    window.Document.ReadOnly = !workingDirectory;

                    var buffer = GetBufferAt(fileName);

                    if (!workingDirectory)
                    {
                        AddBufferTag(buffer, ViewModel.Session, fullPath, null);
                    }
                }

                if (workingDirectory)
                {
                    await UsageTracker.IncrementPRDetailsOpenFileInSolution();
                }
                else
                {
                    await UsageTracker.IncrementPRDetailsViewFile();
                }
            }
            catch (Exception e)
            {
                ShowErrorInStatusBar("Error opening file", e);
            }
        }
        async Task DoDiffFile(IPullRequestFileNode file)
        {
            try
            {
                var fileNames = await ViewModel.ExtractDiffFiles(file);

                var leftLabel  = $"{file.FileName};{ViewModel.TargetBranchDisplayName}";
                var rightLabel = $"{file.FileName};PR {ViewModel.Model.Number}";

                Services.DifferenceService.OpenComparisonWindow2(
                    fileNames.Item1,
                    fileNames.Item2,
                    $"{leftLabel} vs {rightLabel}",
                    file.DirectoryPath,
                    leftLabel,
                    rightLabel,
                    string.Empty,
                    string.Empty,
                    (int)(__VSDIFFSERVICEOPTIONS.VSDIFFOPT_DetectBinaryFiles |
                          __VSDIFFSERVICEOPTIONS.VSDIFFOPT_LeftFileIsTemporary |
                          __VSDIFFSERVICEOPTIONS.VSDIFFOPT_RightFileIsTemporary));
            }
            catch (Exception e)
            {
                ShowErrorInStatusBar("Error opening file", e);
            }
        }
        async Task DoNavigateToEditor(IPullRequestFileNode file)
        {
            try
            {
                if (!ViewModel.IsCheckedOut)
                {
                    ShowInfoMessage("Checkout PR branch before opening file in solution.");
                    return;
                }

                var fullPath = ViewModel.GetLocalFilePath(file);

                var activeView = NavigationService.FindActiveView();
                if (activeView == null)
                {
                    ShowErrorInStatusBar("Couldn't find active view");
                    return;
                }

                NavigationService.NavigateToEquivalentPosition(activeView, fullPath);

                await UsageTracker.IncrementCounter(x => x.NumberOfPRDetailsNavigateToEditor);
            }
            catch (Exception e)
            {
                ShowErrorInStatusBar("Error navigating to editor", e);
            }
        }
Ejemplo n.º 7
0
        async Task DoOpenFile(IPullRequestFileNode file)
        {
            var fileName = await ViewModel.ExtractFile(file);

            var window = Services.Dte.ItemOperations.OpenFile(fileName);

            // If the file we extracted isn't the current file on disk, make the window read-only.
            window.Document.ReadOnly = fileName != file.DirectoryPath;
        }
        async Task <InlineAnnotationModel> GetFirstAnnotation(IPullRequestFileNode file,
                                                              CheckAnnotationLevel annotationLevel)
        {
            var sessionFile = await pullRequestSession.GetFile(file.RelativePath);

            var annotations = sessionFile.InlineAnnotations;

            return(annotations.OrderBy(model => model.EndLine).FirstOrDefault(model => model.AnnotationLevel == annotationLevel));
        }
        void EnableNavigateToEditor(IVsTextView textView, IPullRequestFileNode file)
        {
            var commandGroup = VSConstants.CMDSETID.StandardCommandSet2K_guid;
            var commandId    = (int)VSConstants.VSStd2KCmdID.RETURN;

            new TextViewCommandDispatcher(textView, commandGroup, commandId).Exec += async(s, e) => await DoNavigateToEditor(file);

            var contextMenuCommandGroup = new Guid(Guids.guidContextMenuSetString);
            var goToCommandId           = PkgCmdIDList.openFileInSolutionCommand;

            new TextViewCommandDispatcher(textView, contextMenuCommandGroup, goToCommandId).Exec += async(s, e) => await DoNavigateToEditor(file);
        }
 void DoOpenFile(IPullRequestFileNode file)
 {
     try
     {
         var fileName = ViewModel.GetLocalFilePath(file);
         Services.Dte.ItemOperations.OpenFile(fileName);
     }
     catch (Exception e)
     {
         ShowErrorInStatusBar("Error opening file", e);
     }
 }
Ejemplo n.º 11
0
        async Task <IInlineCommentThreadModel> GetFirstCommentThread(IPullRequestFileNode file)
        {
            var sessionFile = await pullRequestSession.GetFile(file.RelativePath);

            var threads = sessionFile.InlineCommentThreads.AsEnumerable();

            if (commentFilter != null)
            {
                threads = threads.Where(commentFilter);
            }

            return(threads.FirstOrDefault());
        }
        async Task DoDiffFile(IPullRequestFileNode file)
        {
            try
            {
                var fileNames = await ViewModel.ExtractDiffFiles(file);

                var relativePath = System.IO.Path.Combine(file.DirectoryPath, file.FileName);
                var fullPath     = System.IO.Path.Combine(ViewModel.LocalRepository.LocalPath, relativePath);
                var leftLabel    = $"{relativePath};{ViewModel.TargetBranchDisplayName}";
                var rightLabel   = $"{relativePath};PR {ViewModel.Model.Number}";
                var caption      = $"Diff - {file.FileName}";
                var tooltip      = $"{leftLabel}\nvs.\n{rightLabel}";
                var options      = __VSDIFFSERVICEOPTIONS.VSDIFFOPT_DetectBinaryFiles |
                                   __VSDIFFSERVICEOPTIONS.VSDIFFOPT_LeftFileIsTemporary;

                if (!ViewModel.IsCheckedOut)
                {
                    options |= __VSDIFFSERVICEOPTIONS.VSDIFFOPT_RightFileIsTemporary;
                }

                IVsWindowFrame frame;
                using (new NewDocumentStateScope(__VSNEWDOCUMENTSTATE.NDS_Provisional, VSConstants.NewDocumentStateReason.SolutionExplorer))
                {
                    // Diff window will open in provisional (right hand) tab until document is touched.
                    frame = Services.DifferenceService.OpenComparisonWindow2(
                        fileNames.Item1,
                        fileNames.Item2,
                        caption,
                        tooltip,
                        leftLabel,
                        rightLabel,
                        string.Empty,
                        string.Empty,
                        (uint)options);
                }

                object docView;
                frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out docView);
                var diffViewer = ((IVsDifferenceCodeWindow)docView).DifferenceViewer;

                var session = ViewModel.Session;
                AddCompareBufferTag(diffViewer.LeftView.TextBuffer, session, fullPath, true);
                AddCompareBufferTag(diffViewer.RightView.TextBuffer, session, fullPath, false);
            }
            catch (Exception e)
            {
                ShowErrorInStatusBar("Error opening file", e);
            }
        }
        async Task DoOpenFile(IPullRequestFileNode file)
        {
            try
            {
                var fileName = await ViewModel.ExtractFile(file);

                var window = Services.Dte.ItemOperations.OpenFile(fileName);

                // If the file we extracted isn't the current file on disk, make the window read-only.
                window.Document.ReadOnly = fileName != file.DirectoryPath;
            }
            catch (Exception e)
            {
                ShowErrorInStatusBar("Error opening file", e);
            }
        }
        async Task DoOpenFile(IPullRequestFileNode file, bool workingDirectory)
        {
            try
            {
                var fullPath = ViewModel.GetLocalFilePath(file);
                var fileName = workingDirectory ? fullPath : await ViewModel.ExtractFile(file, true);

                using (workingDirectory ? null : OpenInProvisionalTab())
                {
                    var window = GitHub.VisualStudio.Services.Dte.ItemOperations.OpenFile(fileName);
                    window.Document.ReadOnly = !workingDirectory;

                    var buffer = GetBufferAt(fileName);

                    if (!workingDirectory)
                    {
                        AddBufferTag(buffer, ViewModel.Session, fullPath, null);

                        var textView = NavigationService.FindActiveView();
                        EnableNavigateToEditor(textView, file);
                    }
                }

                if (workingDirectory)
                {
                    await UsageTracker.IncrementCounter(x => x.NumberOfPRDetailsOpenFileInSolution);
                }
                else
                {
                    await UsageTracker.IncrementCounter(x => x.NumberOfPRDetailsViewFile);
                }
            }
            catch (Exception e)
            {
                ShowErrorInStatusBar("Error opening file", e);
            }
        }
 public Task<string> ExtractFile(IPullRequestFileNode file)
 {
     return null;
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Gets the before and after files needed for viewing a diff.
        /// </summary>
        /// <param name="file">The changed file.</param>
        /// <returns>A tuple containing the full path to the before and after files.</returns>
        public Task <Tuple <string, string> > ExtractDiffFiles(IPullRequestFileNode file)
        {
            var path = Path.Combine(file.DirectoryPath, file.FileName);

            return(pullRequestsService.ExtractDiffFiles(repository, modelService, model, path, file.Sha).ToTask());
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Gets the specified file as it appears in the pull request.
        /// </summary>
        /// <param name="file">The file or directory node.</param>
        /// <returns>The path to the extracted file.</returns>
        public Task <string> ExtractFile(IPullRequestFileNode file)
        {
            var path = Path.Combine(file.DirectoryPath, file.FileName);

            return(pullRequestsService.ExtractFile(repository, modelService, model.Head.Sha, path, file.Sha).ToTask());
        }
 public Task<string> ExtractFile(IPullRequestFileNode file)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 19
0
        async Task DoDiffFile(IPullRequestFileNode file, bool workingDirectory)
        {
            try
            {
                var relativePath = System.IO.Path.Combine(file.DirectoryPath, file.FileName);
                var rightFile    = workingDirectory ? ViewModel.GetLocalFilePath(file) : await ViewModel.ExtractFile(file, true);

                var leftFile = await ViewModel.ExtractFile(file, false);

                var fullPath   = System.IO.Path.Combine(ViewModel.LocalRepository.LocalPath, relativePath);
                var leftLabel  = $"{relativePath};{ViewModel.TargetBranchDisplayName}";
                var rightLabel = workingDirectory ? relativePath : $"{relativePath};PR {ViewModel.Model.Number}";
                var caption    = $"Diff - {file.FileName}";
                var options    = __VSDIFFSERVICEOPTIONS.VSDIFFOPT_DetectBinaryFiles |
                                 __VSDIFFSERVICEOPTIONS.VSDIFFOPT_LeftFileIsTemporary;

                if (!workingDirectory)
                {
                    options |= __VSDIFFSERVICEOPTIONS.VSDIFFOPT_RightFileIsTemporary;
                }

                IVsWindowFrame frame;
                using (OpenInProvisionalTab())
                {
                    var tooltip = $"{leftLabel}\nvs.\n{rightLabel}";

                    // Diff window will open in provisional (right hand) tab until document is touched.
                    frame = Services.DifferenceService.OpenComparisonWindow2(
                        leftFile,
                        rightFile,
                        caption,
                        tooltip,
                        leftLabel,
                        rightLabel,
                        string.Empty,
                        string.Empty,
                        (uint)options);
                }

                object docView;
                frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out docView);
                var diffViewer = ((IVsDifferenceCodeWindow)docView).DifferenceViewer;

                var session = ViewModel.Session;
                AddBufferTag(diffViewer.LeftView.TextBuffer, session, relativePath, DiffSide.Left);

                if (!workingDirectory)
                {
                    AddBufferTag(diffViewer.RightView.TextBuffer, session, relativePath, DiffSide.Right);
                }

                if (workingDirectory)
                {
                    await UsageTracker.IncrementPRDetailsCompareWithSolution();
                }
                else
                {
                    await UsageTracker.IncrementPRDetailsViewChanges();
                }
            }
            catch (Exception e)
            {
                ShowErrorInStatusBar("Error opening file", e);
            }
        }
 public Task<Tuple<string, string>> ExtractDiffFiles(IPullRequestFileNode file)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 21
0
 public Task <string> ExtractFile(IPullRequestFileNode file)
 {
     throw new NotImplementedException();
 }
        private async Task OpenFirstAnnotation(IPullRequestEditorService editorService, IPullRequestFileNode file,
                                               CheckAnnotationLevel checkAnnotationLevel)
        {
            var annotationModel = await GetFirstAnnotation(file, checkAnnotationLevel);

            if (annotationModel != null)
            {
                await editorService.OpenDiff(pullRequestSession, file.RelativePath, annotationModel.HeadSha, annotationModel.EndLine);
            }
        }
Ejemplo n.º 23
0
 public Task <Tuple <string, string> > ExtractDiffFiles(IPullRequestFileNode file)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 24
0
 public string GetLocalFilePath(IPullRequestFileNode file)
 {
     return(null);
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Gets the full path to a file in the working directory.
 /// </summary>
 /// <param name="file">The file.</param>
 /// <returns>The full path to the file in the working directory.</returns>
 public string GetLocalFilePath(IPullRequestFileNode file)
 {
     return(Path.Combine(LocalRepository.LocalPath, file.DirectoryPath, file.FileName));
 }
        private async Task OpenFirstAnnotation(IPullRequestEditorService editorService, IPullRequestFileNode file,
                                               CheckAnnotationLevel checkAnnotationLevel)
        {
            var annotationModel = await GetFirstAnnotation(file, checkAnnotationLevel);

            if (annotationModel != null)
            {
                //AnnotationModel.EndLine is a 1-based number
                //EditorService.OpenDiff takes a 0-based line number to start searching AFTER and will open the next tag
                var nextInlineCommentFromLine = annotationModel.EndLine - 2;
                await editorService.OpenDiff(pullRequestSession, file.RelativePath, annotationModel.HeadSha, nextInlineCommentFromLine);
            }
        }
        void EnableNavigateToEditor(IWpfTextView textView, IPullRequestFileNode file)
        {
            var view = EditorAdaptersFactoryService.GetViewAdapter(textView);

            EnableNavigateToEditor(view, file);
        }
 /// <summary>
 /// Gets the specified file as it appears in the pull request.
 /// </summary>
 /// <param name="file">The file or directory node.</param>
 /// <returns>The path to the extracted file.</returns>
 public Task<string> ExtractFile(IPullRequestFileNode file)
 {
     var path = Path.Combine(file.DirectoryPath, file.FileName);
     return pullRequestsService.ExtractFile(repository, model.Head.Sha, path).ToTask();
 }
 /// <summary>
 /// Gets the before and after files needed for viewing a diff.
 /// </summary>
 /// <param name="file">The changed file.</param>
 /// <returns>A tuple containing the full path to the before and after files.</returns>
 public Task<Tuple<string, string>> ExtractDiffFiles(IPullRequestFileNode file)
 {
     var path = Path.Combine(file.DirectoryPath, file.FileName);
     return pullRequestsService.ExtractDiffFiles(repository, model, path).ToTask();
 }
Ejemplo n.º 30
0
 public Task <Tuple <string, string> > ExtractDiffFiles(IPullRequestFileNode file)
 {
     return(null);
 }
 public Task <string> ExtractFile(IPullRequestFileNode file, bool head)
 {
     return(null);
 }
Ejemplo n.º 32
0
 /// <inheritdoc/>
 public string GetLocalFilePath(IPullRequestFileNode file)
 {
     return(Path.Combine(LocalRepository.LocalPath, file.RelativePath));
 }
        /// <summary>
        /// Gets a file as it appears in the pull request.
        /// </summary>
        /// <param name="file">The changed file.</param>
        /// <param name="head">
        /// If true, gets the file at the PR head, otherwise gets the file at the PR merge base.
        /// </param>
        /// <param name="encoding">The encoding to use.</param>
        /// <returns>The path to a temporary file.</returns>
        public Task <string> ExtractFile(IPullRequestFileNode file, bool head, Encoding encoding)
        {
            var path = Path.Combine(file.DirectoryPath, file.FileName);

            return(pullRequestsService.ExtractFile(LocalRepository, model, path, head, encoding).ToTask());
        }