public VsFileDiffProvider(
     IVsDifferenceService vsDifferenceService,
     string solutionPath,
     SolutionSelectionContainer <ISolutionSelection> selectionContainer,
     ErrorPresenter errorPresenter,
     GitFileDiffController gitFileDiffController)
 {
     this.vsDifferenceService   = vsDifferenceService;
     this.solutionPath          = solutionPath;
     this.errorPresenter        = errorPresenter;
     this.gitFileDiffController = gitFileDiffController;
     this.DocumentPath          = selectionContainer.FullName;
     this.OldDocumentPath       = selectionContainer.OldFullName;
 }
        // TODO: We don't need to get selected items if there is a way to capture menu button's target item and it's info in VS API
        protected virtual void Execute(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var   uih           = (UIHierarchy)this.dte.Windows.Item(EnvDTE.Constants.vsWindowKindSolutionExplorer).Object;
            Array selectedItems = (Array)uih.SelectedItems;

            if (selectedItems != null && selectedItems.Length == 1)
            {
                var selectedHierarchyItem = selectedItems.GetValue(0) as UIHierarchyItem;
                var selectedObject        = selectedHierarchyItem?.Object;

                if (selectedObject != null)
                {
                    if (selectedObject is ProjectItem)
                    {
                        var selectedProjectItem = selectedObject as ProjectItem;
                        var oldPath             = BranchDiffFilterProvider.TagManager.GetOldFilePathFromRenamed(selectedProjectItem);
                        var selection           = new SolutionSelectionContainer <ISolutionSelection>
                        {
                            Item = new SelectedProjectItem {
                                Native = selectedProjectItem, OldFullPath = oldPath
                            }
                        };

                        this.ShowFileDiffWindow(selection);
                    }
                    else if (selectedObject is Project)
                    {
                        var selectedProject = selectedObject as Project;
                        var oldPath         = BranchDiffFilterProvider.TagManager.GetOldFilePathFromRenamed(selectedProject);
                        var selection       = new SolutionSelectionContainer <ISolutionSelection>
                        {
                            Item = new SelectedProject {
                                Native = selectedProject, OldFullPath = oldPath
                            }
                        };

                        this.ShowFileDiffWindow(selection);
                    }
                }
            }
        }
 private void ShowFileDiffWindow(SolutionSelectionContainer <ISolutionSelection> solutionSelectionContainer)
 {
     ThreadHelper.ThrowIfNotOnUIThread();
     if (!string.IsNullOrEmpty(solutionSelectionContainer.FullName))
     {
         if (solutionSelectionContainer.HasNoAssociatedDiffWindow(this.vsUIShell))
         {
             // Create a new diff window if none already open
             var absoluteSoltuionPath = this.dte.Solution.FullName;
             var solutionDirectory    = System.IO.Path.GetDirectoryName(absoluteSoltuionPath);
             var fileDiffProvider     = new VsFileDiffProvider(this.vsDifferenceService, solutionDirectory, solutionSelectionContainer);
             fileDiffProvider.ShowFileDiffWithBaseBranch(package.BranchToDiffAgainst);
         }
         else
         {
             // Activate already open diff window
             solutionSelectionContainer.FocusAssociatedDiffWindow(this.vsUIShell);
         }
     }
 }
Exemple #4
0
 public VsFileDiffProvider(IVsDifferenceService vsDifferenceService, string solutionPath, SolutionSelectionContainer <ISolutionSelection> selectionContainer)
 {
     this.vsDifferenceService = vsDifferenceService;
     this.solutionPath        = solutionPath;
     this.DocumentPath        = selectionContainer.FullName;
     this.OldDocumentPath     = selectionContainer.OldFullName;
 }