Beispiel #1
0
        protected override void InvokeHandler(object sender, EventArgs e)
        {
            var dte = ServiceProvider.GetDte();

            var firstFilePath  = dte.SelectedItems.Item(1).ProjectItem.FileNames[1];
            var secondFilePath = dte.SelectedItems.Item(2).ProjectItem.FileNames[1];

            Difference.VisualDiffFiles(firstFilePath, secondFilePath, Path.GetDirectoryName(firstFilePath), Path.GetDirectoryName(secondFilePath), Path.GetFileName(firstFilePath), Path.GetFileName(secondFilePath), false, false);
        }
Beispiel #2
0
        protected override void Execute(string filename, AbstractProjectBrowserTreeNode node, Action callback)
        {
            try
            {
                var item = TFS.GetTfsItem(filename);
                if (item == null)
                {
                    return;
                }
                var itemEx = item.Workspace.VersionControlServer.GetItem(filename, VersionSpec.Latest, DeletedState.Any, true);
                var path   = Path.GetTempPath() + itemEx.ChangesetId + "_" +
                             itemEx.ServerItem.Split('/')[itemEx.ServerItem.Split('/').Length - 1];
                itemEx.DownloadFile(path);

                Difference.VisualDiffFiles(path, filename, "Latest", "Local", "Latest", "Local", true, false, true, false);
            }
            catch (Exception ex)
            {
                TFSMessageView.Log("TFSError: Add: " + ex.Message + " (" + filename + ")");
            }
        }
Beispiel #3
0
        /// <summary>
        /// Visual compare <see cref="IDiffChange"/> with the Visual Studio Diff Tool.
        /// </summary>
        /// <param name="diffChange">Information about a specific difference between two sequences.</param>
        private void CompareChangeRegion(IDiffChange diffChange)
        {
            const string SourceFileTag = "Server";
            const string TargetFileTag = "Local";

            const bool IsSourceReadOnly = true;
            const bool IsTargetReadOnly = true;

            const bool DeleteSourceOnExit = true;
            const bool DeleteTargetOnExit = true;

            const string FileLabelTemplateSingleLine   = "{0};{1}[line {2}]";
            const string FileLabelTemplateBetweenLines = "{0};{1}[between lines {3}-{2}]";
            const string FileLabelTemplateLinesRange   = "{0};{1}[lines {2}-{3}]";

            string sourceFileLabelTemplate;

            if (diffChange.OriginalStart == diffChange.OriginalEnd)
            {
                sourceFileLabelTemplate = FileLabelTemplateSingleLine;
            }
            else if (diffChange.ChangeType == DiffChangeType.Insert)
            {
                sourceFileLabelTemplate = FileLabelTemplateBetweenLines;
            }
            else
            {
                sourceFileLabelTemplate = FileLabelTemplateLinesRange;
            }

            string sourceFileLabel = string.Format(
                sourceFileLabelTemplate,
                _marginCore.VersionControlItem.ServerItem,
                "T;" /* Latest version token */,
                diffChange.OriginalStart + 1,
                diffChange.OriginalEnd + 1);

            string targetFileLabelTemplate;

            if (diffChange.ModifiedStart == diffChange.ModifiedEnd)
            {
                targetFileLabelTemplate = FileLabelTemplateSingleLine;
            }
            else if (diffChange.ChangeType == DiffChangeType.Delete)
            {
                targetFileLabelTemplate = FileLabelTemplateBetweenLines;
            }
            else
            {
                targetFileLabelTemplate = FileLabelTemplateLinesRange;
            }

            string targetFileLabel = string.Format(
                targetFileLabelTemplate,
                _marginCore.TextDocument.FilePath,
                string.Empty /* No additional parameter */,
                diffChange.ModifiedStart + 1,
                diffChange.ModifiedEnd + 1);

            const bool RemoveLastLineTerminator = true;

            string sourceText     = _marginCore.GetOriginalText(diffChange, RemoveLastLineTerminator);
            string sourceFilePath = System.IO.Path.GetTempFileName();

            if (!string.IsNullOrEmpty(sourceText))
            {
                File.WriteAllText(sourceFilePath, sourceText);
            }

            string targetText     = _marginCore.GetModifiedText(diffChange, RemoveLastLineTerminator);
            string targetFilePath = System.IO.Path.GetTempFileName();

            if (!string.IsNullOrEmpty(targetText))
            {
                File.WriteAllText(targetFilePath, targetText);
            }

            Difference.VisualDiffFiles(
                sourceFilePath,
                targetFilePath,
                SourceFileTag,
                TargetFileTag,
                sourceFileLabel,
                targetFileLabel,
                IsSourceReadOnly,
                IsTargetReadOnly,
                DeleteSourceOnExit,
                DeleteTargetOnExit);
        }
Beispiel #4
0
 /// <summary>
 /// try to diff what's on the harddrive,
 /// then fall back to the latest version of the server items.
 /// </summary>
 /// <param name="left"></param>
 /// <param name="right"></param>
 /// <param name="vcs"></param>
 public static void VisualDiff(string left, string right, VersionControlServer vcs)
 {
     Difference.VisualDiffFiles(vcs, left, null, right, null);
 }