src/Misc/EFTools/DesignXmlCore/Refactoring/PreviewBuffer.cs
/// <summary>
///     Display the refactoring preview for a selected preview changes node.
/// </summary>
/// <param name="vsTextView">The text view to show the file contents.</param>
/// <param name="fileChange">All changes in one file.</param>
/// <param name="node">The selected PreviewChangesNode.</param>
Display the refactoring preview for a selected preview changes node.
Display the refactoring preview for a selected preview changes node .
public void DisplayPreview(IVsTextView vsTextView, FileChange fileChange, PreviewChangesNode node)
        {
            ArgumentValidation.CheckForNullReference(vsTextView, "vsTextView");
            ArgumentValidation.CheckForNullReference(node, "previewChangeNode");
            if (fileChange != null)
            {
                PreviewTempFile tempFile = null;
                try
                {
                    tempFile = GetPreviewTempFile(Path.GetExtension(fileChange.FileName));
                }
                catch (InvalidOperationException)
                {
                    NativeMethods.ThrowOnFailure(vsTextView.SetBuffer(_bufferForNoChanges));
                    return;
                }
                CopyFileToBuffer(fileChange.FileName, tempFile.TextBuffer);
                RefactoringOperationBase.ApplyChangesToOneFile(fileChange, tempFile.TextBuffer, true, node.ChangeProposal);
                var languageServiceID = node.LanguageServiceID;
                if (languageServiceID == Guid.Empty
                    && node.ChildList != null
                    && node.ChildList.Count > 0)
                {
                    languageServiceID = node.ChildList[0].LanguageServiceID;
                }
                if (languageServiceID != Guid.Empty)
                {
                    NativeMethods.ThrowOnFailure(tempFile.TextBuffer.SetLanguageServiceID(ref languageServiceID));
                }
                NativeMethods.ThrowOnFailure(vsTextView.SetBuffer(tempFile.TextBuffer));
                ScrollInView(vsTextView, 0, 0, 0, 1);
                var visibleChange = node.ChangeProposal as TextChangeProposal;
                if (visibleChange == null)
                {
                    if (node.ChildList != null
                        && node.ChildList.Count > 0)
                    {
                        visibleChange = node.ChildList[0].ChangeProposal as TextChangeProposal;
                    }
                }
                if (visibleChange != null)
                {
                    ScrollInView(
                        vsTextView, visibleChange.StartLine, visibleChange.StartColumn,
                        visibleChange.EndLine, visibleChange.EndColumn);
                }
                _lastTextView = vsTextView;
                _lastDisplayedFileChange = fileChange;
                _lastDisplayedNode = node;
            }
            else
            {
                NativeMethods.ThrowOnFailure(vsTextView.SetBuffer(_bufferForNoChanges));
            }
        }
public void DisplayPreview ( IVsTextView vsTextView , FileChange fileChange , PreviewChangesNode node ) { ArgumentValidation . CheckForNullReference ( vsTextView , " " ) ; ArgumentValidation . CheckForNullReference ( node , " " ) ; if ( fileChange != null ) { PreviewTempFile tempFile = null ; try { tempFile = GetPreviewTempFile ( Path . GetExtension ( fileChange . FileName ) ) ; } catch ( InvalidOperationException ) { NativeMethods . ThrowOnFailure ( vsTextView . SetBuffer ( _bufferForNoChanges ) ) ; return ; } CopyFileToBuffer ( fileChange . FileName , tempFile . TextBuffer ) ; RefactoringOperationBase . ApplyChangesToOneFile ( fileChange , tempFile . TextBuffer , true , node . ChangeProposal ) ; var languageServiceID = node . LanguageServiceID ; if ( languageServiceID == Guid . Empty && node . ChildList != null && node . ChildList . Count > 0 ) { languageServiceID = node . ChildList [ 0 ] . LanguageServiceID ; } if ( languageServiceID != Guid . Empty ) { NativeMethods . ThrowOnFailure ( tempFile . TextBuffer . SetLanguageServiceID ( ref languageServiceID ) ) ; } NativeMethods . ThrowOnFailure ( vsTextView . SetBuffer ( tempFile . TextBuffer ) ) ; ScrollInView ( vsTextView , 0 , 0 , 0 , 1 ) ; var visibleChange = node . ChangeProposal as TextChangeProposal ; if ( visibleChange == null ) { if ( node . ChildList != null && node . ChildList . Count > 0 ) { visibleChange = node . ChildList [ 0 ] . ChangeProposal as TextChangeProposal ; } } if ( visibleChange != null ) { ScrollInView ( vsTextView , visibleChange . StartLine , visibleChange . StartColumn , visibleChange . EndLine , visibleChange . EndColumn ) ; } _lastTextView = vsTextView ; _lastDisplayedFileChange = fileChange ; _lastDisplayedNode = node ; } else { NativeMethods . ThrowOnFailure ( vsTextView . SetBuffer ( _bufferForNoChanges ) ) ; } }
Display the refactoring preview for a selected preview changes node.
Display the refactoring preview for a selected preview changes node .
// Get the temp file for this file extension, and copy all file content to the temp file text buffer // Failed to get text buffer, just set the text view to nothing. // Copy the content of source file to that temp file text buffer // Create text markers on all changes on this file // Set language service ID // Get Language service ID on this change node // If can not get the language service ID, check if it has child nodes // if so, get the language service ID for first change in this file node. // Set the vsTextView with textBuffer // Ensure visible of first line and set the caret to position (0,0) // If there is ChangeProposal, make sure that change is visible in the text view. // If ChangeProposal is null, that might be file node, make the first chagne visible. // Here we will only work with Text based change proposal. // Try to get first change in this file // There are some changes, create TextSpan for first change,  // and make the cursor position to that TextSpan. // Save the state, this will be used to refresh the text view when preview request // changed, such as check/uncheck // No related file to this node, set nothing for the text view.
vsTextView
IVsTextView
The text view to show the file contents.
The text view to show the file contents .
fileChange
FileChange
All changes in one file.
All changes in one file .
node
PreviewChangesNode
The selected PreviewChangesNode.
The selected PreviewChangesNode .