public StashInfoChangesSectionViewModel(Stash stash, FileIconsService fileIconsService, GitCommandExecuter gitCommandExecuter, ITeamExplorer teamExplorer, IVsDifferenceService vsDiffService)
        {
            _fileIconsService   = fileIconsService;
            _gitCommandExecuter = gitCommandExecuter;
            _teamExplorer       = teamExplorer;
            _vsDiffService      = vsDiffService;
            _stash = stash;

            if (stash == null)
            {
                return;
            }

            var separator = '/';
            var rootNode  = new TreeNode();
            var paths     = stash.ChangedFiles
                            .Select(f => f.Path)
                            .Where(x => !string.IsNullOrEmpty(x.Trim()))
                            .ToList();

            foreach (var path in paths)
            {
                var currentNode = rootNode;
                var pathNodes   = path.Split(separator);
                foreach (var item in pathNodes)
                {
                    var foundedNode = currentNode.Nodes.Cast <TreeNode>().FirstOrDefault(x => x.Text == item);
                    currentNode = foundedNode ?? currentNode.Nodes.Add(item);
                }
            }

            var rootTreeViewItem = ToTreeViewItem(rootNode, false);

            ChangeItems = new ObservableCollection <TreeViewItemWithIcon>(rootTreeViewItem.Items.ToList());
        }
コード例 #2
0
ファイル: VsDiffTool.cs プロジェクト: x2009again/Kool.VsDiff
        public VsDiffTool(VsDiffPackage package)
        {
            var sp = package as IServiceProvider;

            _diffService = (IVsDifferenceService)sp.GetService(typeof(SVsDifferenceService));
            Assumes.Present(_diffService);
        }
コード例 #3
0
 public VsFileDiffProvider(IVsDifferenceService vsDifferenceService, string solutionPath, SolutionSelectionContainer <ISolutionSelection> selectionContainer)
 {
     this.vsDifferenceService = vsDifferenceService;
     this.solutionPath        = solutionPath;
     this.DocumentPath        = selectionContainer.FullName;
     this.OldDocumentPath     = selectionContainer.OldFullName;
 }
コード例 #4
0
        public StashInfoChangesSectionViewModel(Stash stash,
                                                FileIconsService fileIconsService,
                                                GitCommandExecuter gitCommandExecuter,
                                                ITeamExplorer teamExplorer,
                                                IVsDifferenceService vsDiffService,
                                                DTE dte)
        {
            _fileIconsService   = fileIconsService;
            _gitCommandExecuter = gitCommandExecuter;
            _teamExplorer       = teamExplorer;
            _vsDiffService      = vsDiffService;
            _dte   = dte;
            _stash = stash;

            if (stash == null)
            {
                return;
            }

            var separator = '/';
            var rootNode  = new TreeNode();

            foreach (var file in stash.ChangedFiles)
            {
                if (string.IsNullOrEmpty(file.Path.Trim()))
                {
                    continue;
                }

                var currentNode = rootNode;
                var pathNodes   = file.Path.Split(separator);
                foreach (var item in pathNodes)
                {
                    var foundedNode = currentNode.Nodes.Cast <TreeNode>().FirstOrDefault(x => x.Text == item);
                    if (foundedNode != null)
                    {
                        currentNode = foundedNode;
                    }
                    else
                    {
                        currentNode = currentNode.Nodes.Add(item);
                        // Last node in the path -> file.
                        if (item == pathNodes.LastOrDefault())
                        {
                            // Additional file info
                            currentNode.Tag = new Models.FileAttributes
                            {
                                IsNew    = file.IsNew,
                                IsStaged = file.IsStaged
                            };
                        }
                    }
                }
            }

            var rootTreeViewItem = ToTreeViewItem(rootNode, false);

            ChangeItems = new ObservableCollection <TreeViewItemWithIcon>(rootTreeViewItem.Items?.ToList() ?? Enumerable.Empty <TreeViewItemWithIcon>());
        }
 public VisualStudioGitService(IServiceProvider serviceProvider)
 {
     _dialogFactory      = serviceProvider.GetService(typeof(SVsThreadedWaitDialogFactory)) as IVsThreadedWaitDialogFactory;
     _gitCommandExecuter = new GitCommandExecuter(serviceProvider);
     _teamExplorer       = serviceProvider.GetService(typeof(ITeamExplorer)) as ITeamExplorer;
     _dte           = serviceProvider.GetService(typeof(DTE)) as DTE;
     _vsDiffService = serviceProvider.GetService(typeof(SVsDifferenceService)) as IVsDifferenceService;
 }
        public StashInfoChangesSectionUI(Stash stash, IServiceProvider serviceProvider)
        {
            _serviceProvider    = serviceProvider;
            _vsImageService     = _serviceProvider.GetService(typeof(SVsImageService)) as IVsImageService2;
            _fileIconsService   = new FileIconsService(_vsImageService);
            _gitCommandExecuter = new GitCommandExecuter(_serviceProvider);
            _teamExplorer       = _serviceProvider.GetService(typeof(ITeamExplorer)) as ITeamExplorer;
            _vsDiffService      = _serviceProvider.GetService(typeof(SVsDifferenceService)) as IVsDifferenceService;
            InitializeComponent();

            DataContext = _viewModel = new StashInfoChangesSectionViewModel(stash, _fileIconsService, _gitCommandExecuter, _teamExplorer, _vsDiffService);
        }
コード例 #7
0
 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;
 }
コード例 #8
0
 private OpenProjectFileDiffCommand(
     IGitBranchDifferPackage package,
     DTE dte,
     IVsDifferenceService vsDifferenceService,
     IVsUIShell vsUIShell,
     OleMenuCommandService commandService)
     : base(package,
            dte,
            vsDifferenceService,
            vsUIShell,
            commandService,
            new CommandID(
                GitBranchDifferPackageGuids.guidFileDiffPackageCmdSet,
                GitBranchDifferPackageGuids.CommandIdProjectFileDiffMenuCommand))
 {
 }
コード例 #9
0
        protected async Task InitializeAsync(IGitBranchDifferPackage package)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            this.package = package ?? throw new ArgumentNullException(nameof(package));
            this.dte     = await package.GetServiceAsync(typeof(EnvDTE.DTE)) as EnvDTE.DTE ?? throw new ArgumentNullException(nameof(dte));

            this.vsUIShell = await package.GetServiceAsync(typeof(SVsUIShell)) as IVsUIShell ?? throw new ArgumentNullException(nameof(vsUIShell));

            // Dependencies that can be moved to constructor and resolved via IoC...
            this.vsDifferenceService = await package.GetServiceAsync(typeof(SVsDifferenceService)) as IVsDifferenceService ?? throw new ArgumentNullException(nameof(vsDifferenceService));

            this.commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as IMenuCommandService ?? throw new ArgumentNullException(nameof(commandService));

            this.errorPresenter        = VsDIContainer.Instance.GetService(typeof(ErrorPresenter)) as ErrorPresenter ?? throw new ArgumentNullException(nameof(errorPresenter));
            this.gitFileDiffController = DIContainer.Instance.GetService(typeof(GitFileDiffController)) as GitFileDiffController ?? throw new ArgumentNullException(nameof(gitFileDiffController));
        }
コード例 #10
0
        public void StartExternalDiff(ITextDocument textDocument)
        {
            if (textDocument == null || string.IsNullOrEmpty(textDocument.FilePath))
            {
                return;
            }

            var filename = textDocument.FilePath;

            if (!IsDiffPerformed(filename))
            {
                return;
            }

            var      depotPath = GetPerforcePath(filename);
            FileSpec fs        = new FileSpec(new DepotPath(depotPath));

            var tempFileName = Path.GetTempFileName();
            var printOptions = new GetFileContentsCmdOptions(GetFileContentsCmdFlags.Suppress, tempFileName);

            _repository.GetFileContents(printOptions, fs);

            IVsDifferenceService differenceService = _serviceProvider.GetService(typeof(SVsDifferenceService)) as IVsDifferenceService;
            string leftFileMoniker = tempFileName;
            // The difference service will automatically load the text from the file open in the editor, even if
            // it has changed. Don't use the original path here.
            string rightFileMoniker = filename;
            string caption          = "p4 diff";

            string leftLabel   = string.Format("{0}#head", depotPath);
            string rightLabel  = filename;
            string inlineLabel = null;
            string tooltip     = null;
            string roles       = null;

            __VSDIFFSERVICEOPTIONS grfDiffOptions = __VSDIFFSERVICEOPTIONS.VSDIFFOPT_LeftFileIsTemporary;

            differenceService.OpenComparisonWindow2(leftFileMoniker, rightFileMoniker, caption, tooltip, leftLabel, rightLabel, inlineLabel, roles, (uint)grfDiffOptions);

            // Since the file is marked as temporary, we can delete it now
            // Perforce can create read-only file, so set FileAttributes.Normal in order to safe delete it
            System.IO.File.SetAttributes(tempFileName, FileAttributes.Normal);
            System.IO.File.Delete(tempFileName);
        }
コード例 #11
0
        public OpenDiffCommand(
            IGitBranchDifferPackage package,
            DTE dte,
            IVsDifferenceService vsDifferenceService,
            IVsUIShell vsUIShell,
            OleMenuCommandService commandService,
            CommandID menuCommandId)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            this.package             = package ?? throw new ArgumentNullException(nameof(package));
            this.dte                 = dte ?? throw new ArgumentNullException(nameof(dte));
            this.vsDifferenceService = vsDifferenceService ?? throw new ArgumentNullException(nameof(vsDifferenceService));
            this.vsUIShell           = vsUIShell ?? throw new ArgumentNullException(nameof(vsUIShell));
            commandService           = commandService ?? throw new ArgumentNullException(nameof(commandService));

            var menuCommand = new OleMenuCommand(this.Execute, menuCommandId);

            OleCommandInstance = menuCommand;
            commandService.AddCommand(menuCommand);
        }
コード例 #12
0
        /// <summary>
        /// Opens a difference window with <code>IVsDifferenceService</code> when a DocumentNode is double clicked.
        /// </summary>
        private void MouseDoubleClickHandler(object sender, MouseButtonEventArgs e)
        {
            if (DocumentListBox.SelectedItem == null)
            {
                return;
            }

            var node = (DocumentNode)DocumentListBox.SelectedItem;

            Debug.Assert(File.Exists(node.RepositoryPath));
            Debug.Assert(File.Exists(node.OriginalPath));
            Debug.Assert(node.OriginalPath == LatestDocument.OriginalPath);

            // Close the last comparison because we only want 1 open at a time
            if (differenceFrame != null)
            {
                differenceFrame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_NoSave);
            }

            // Get the Difference Service we will use to do the comparison
            if (differenceService == null)
            {
                differenceService = (IVsDifferenceService)Package.GetGlobalService(typeof(SVsDifferenceService));
            }

            // Open a comparison between the old file and the current file
            differenceFrame = differenceService.OpenComparisonWindow2(
                node.RepositoryPath, LatestDocument.RepositoryPath,
                node.FileName + " " + node.TimeStamp + " vs  Now",
                node.FileName + " " + node.TimeStamp + " vs  Now",
                node.FileName + " " + node.TimeStamp,
                LatestDocument.FileName + " Now",
                node.FileName + " " + node.TimeStamp + " vs  Now",
                null,
                0);
        }
コード例 #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CompareFilesCommand"/> class.
 /// </summary>
 public CompareFilesCommand()
 {
     this.diffService = DTEHelper.GetServiceIstanceOfInterface <SVsDifferenceService, IVsDifferenceService>();
 }
コード例 #14
0
        /// <summary>
        /// Shows a preview of the transformation in a temporary file.
        /// </summary>
        /// <param name="hier">Current IVsHierarchy</param>
        /// <param name="sourceFile">Full path to the file to be trasnformed</param>
        /// <param name="transformFile">Full path to the transformation file</param>
        private void PreviewTransform(IVsHierarchy hier, string sourceFile, string transformFile)
        {
            if (string.IsNullOrWhiteSpace(sourceFile))
            {
                throw new ArgumentNullException("sourceFile");
            }

            if (string.IsNullOrWhiteSpace(transformFile))
            {
                throw new ArgumentNullException("transformFile");
            }

            if (!File.Exists(sourceFile))
            {
                throw new FileNotFoundException(string.Format(CultureInfo.CurrentCulture, Resources.Resources.Error_SourceFileNotFound, sourceFile), sourceFile);
            }

            if (!File.Exists(transformFile))
            {
                throw new FileNotFoundException(string.Format(CultureInfo.CurrentCulture, Resources.Resources.Error_TransformFileNotFound, transformFile), transformFile);
            }

            // Get our options
            using (OptionsDialogPage optionsPage = new OptionsDialogPage())
            {
                optionsPage.LoadSettingsFromStorage();

                this.LogMessageWriteLineFormat("SlowCheetah PreviewTransform");
                FileInfo sourceFileInfo = new FileInfo(sourceFile);

                // dest file
                string destFile = PackageUtilities.GetTempFilename(true, sourceFileInfo.Extension);
                this.TempFilesCreated.Add(destFile);

                // perform the transform and then display the result into the diffmerge tool that comes with VS.
                // If for some reason we can't find it, we just open it in an editor window
                this.errorListProvider.Tasks.Clear();
                ITransformationLogger logger      = new TransformationPreviewLogger(this.errorListProvider, hier);
                ITransformer          transformer = new XmlTransformer(logger, false);
                if (!transformer.Transform(sourceFile, transformFile, destFile))
                {
                    throw new TransformFailedException(Resources.Resources.TransformPreview_ErrorMessage);
                }

                // Does the customer want a preview?
                if (optionsPage.EnablePreview == false)
                {
                    ProjectUtilities.GetDTE().ItemOperations.OpenFile(destFile);
                }
                else
                {
                    // If the diffmerge service is available (dev11) and no diff tool is specified, or diffmerge.exe is specifed we use the service
                    IVsDifferenceService diffService = this.GetService(typeof(SVsDifferenceService)) as IVsDifferenceService;
                    if (diffService != null && (string.IsNullOrEmpty(optionsPage.PreviewToolExecutablePath) || optionsPage.PreviewToolExecutablePath.EndsWith(@"\diffmerge.exe", StringComparison.OrdinalIgnoreCase)))
                    {
                        string sourceName = Path.GetFileName(sourceFile);
                        string leftLabel  = string.Format(CultureInfo.CurrentCulture, Resources.Resources.TransformPreview_LeftLabel, sourceName);
                        string rightLabel = string.Format(CultureInfo.CurrentCulture, Resources.Resources.TransformPreview_RightLabel, sourceName, Path.GetFileName(transformFile));
                        string caption    = string.Format(CultureInfo.CurrentCulture, Resources.Resources.TransformPreview_Caption, sourceName);
                        string tooltip    = string.Format(CultureInfo.CurrentCulture, Resources.Resources.TransformPreview_ToolTip, sourceName);
                        diffService.OpenComparisonWindow2(sourceFile, destFile, caption, tooltip, leftLabel, rightLabel, null, null, (uint)__VSDIFFSERVICEOPTIONS.VSDIFFOPT_RightFileIsTemporary);
                    }
                    else if (string.IsNullOrEmpty(optionsPage.PreviewToolExecutablePath))
                    {
                        throw new FileNotFoundException(Resources.Resources.Error_NoPreviewToolSpecified);
                    }
                    else if (!File.Exists(optionsPage.PreviewToolExecutablePath))
                    {
                        throw new FileNotFoundException(string.Format(Resources.Resources.Error_CantFindPreviewTool, optionsPage.PreviewToolExecutablePath), optionsPage.PreviewToolExecutablePath);
                    }
                    else
                    {
                        // Quote the filenames...
                        ProcessStartInfo psi = new ProcessStartInfo(optionsPage.PreviewToolExecutablePath, string.Format(optionsPage.PreviewToolCommandLine, "\"" + sourceFile + "\"", "\"" + destFile + "\""))
                        {
                            CreateNoWindow  = true,
                            UseShellExecute = false
                        };
                        System.Diagnostics.Process.Start(psi);
                    }
                }
            }

            // TODO: Instead of creating a file and then deleting it later we could instead do this
            //          http://matthewmanela.com/blog/the-problem-with-the-envdte-itemoperations-newfile-method/
            //          http://social.msdn.microsoft.com/Forums/en/vsx/thread/eb032063-eb4d-42e0-84e8-dec64bf42abf
        }
コード例 #15
0
        /// <summary>
        /// Opens a difference window with <code>IVsDifferenceService</code> when a DocumentNode is double clicked.
        /// </summary>
        private void MouseDoubleClickHandler(object sender, MouseButtonEventArgs e)
        {
            if (DocumentListBox.SelectedItem == null)
            return;

              DocumentNode node = ((DocumentNode)DocumentListBox.SelectedItem);

              Debug.Assert(File.Exists(node.RepositoryPath));
              Debug.Assert(File.Exists(node.OriginalPath));
              Debug.Assert(node.OriginalPath == LatestDocument.OriginalPath);

              // Close the last comparison because we only want 1 open at a time
              if (differenceFrame != null) differenceFrame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_NoSave);

              // Get the Difference Service we will use to do the comparison
              if (differenceService == null)
              {
            differenceService = (IVsDifferenceService)Package.GetGlobalService(typeof(SVsDifferenceService));
              }

              // Open a comparison between the old file and the current file
              differenceFrame = differenceService.OpenComparisonWindow2(
            node.RepositoryPath, LatestDocument.RepositoryPath,
            node.FileName + " " + node.TimeStamp + " vs  Now",
            node.FileName + " " + node.TimeStamp + " vs  Now",
            node.FileName + " " + node.TimeStamp,
            LatestDocument.FileName + " Now",
            node.FileName + " " + node.TimeStamp + " vs  Now",
            null,
            0);
        }