Esempio n. 1
0
        /// <summary>
        ///     Add a ChangeProposal to change list of a related PreviewGroup.
        /// </summary>
        /// <param name="previewGroup">Preview group this change will be added to.</param>
        /// <param name="change">The ChangeProposal.</param>
        internal void AddChange(RefactoringPreviewGroup previewGroup, ChangeProposal change)
        {
            ArgumentValidation.CheckForNullReference(previewGroup, "previewGroup");
            ArgumentValidation.CheckForNullReference(change, "change");

            // First check if changes for same location exists or not, if exist, we will not add it anymore
            var exist = false;

            foreach (var existingChanges in _changeList.Values)
            {
                if (existingChanges.Contains(change))
                {
                    exist = true;
                    break;
                }
            }
            if (!exist)
            {
                HashSet <ChangeProposal> changes = null;
                if (_changeList.TryGetValue(previewGroup, out changes) == false)
                {
                    // There is no change list for this preview group,
                    // create one and add to the dictionary.
                    changes = new HashSet <ChangeProposal>();
                    _changeList.Add(previewGroup, changes);
                }
                // Add change to the change list.
                changes.Add(change);
            }
        }
Esempio n. 2
0
 public PreviewChangesNode(
     string displayText,
     VSTREEDISPLAYDATA displayData,
     string tooltipText,
     List <PreviewChangesNode> childList,
     ChangeProposal changeProposal)
 {
     _displayText   = displayText;
     _displayData   = displayData;
     _tooltipText   = tooltipText;
     _childList     = childList;
     ChangeProposal = changeProposal;
     if (changeProposal != null &&
         changeProposal.Included)
     {
         _checkState = __PREVIEWCHANGESITEMCHECKSTATE.PCCS_Checked;
     }
     else
     {
         _checkState = __PREVIEWCHANGESITEMCHECKSTATE.PCCS_Unchecked;
     }
 }
 public PreviewChangesNode(
     string displayText,
     VSTREEDISPLAYDATA displayData,
     string tooltipText,
     List<PreviewChangesNode> childList,
     ChangeProposal changeProposal)
 {
     _displayText = displayText;
     _displayData = displayData;
     _tooltipText = tooltipText;
     _childList = childList;
     ChangeProposal = changeProposal;
     if (changeProposal != null
         && changeProposal.Included)
     {
         _checkState = __PREVIEWCHANGESITEMCHECKSTATE.PCCS_Checked;
     }
     else
     {
         _checkState = __PREVIEWCHANGESITEMCHECKSTATE.PCCS_Unchecked;
     }
 }
Esempio n. 4
0
        internal static void ApplyChangesToOneFile(
            FileChange file, IVsTextLines textLines, bool createMarker, ChangeProposal changeToHighlight)
        {
            ArgumentValidation.CheckForNullReference(file, "file");
            ArgumentValidation.CheckForNullReference(textLines, "textLines");

            // Here we only work on text based ChangeProposal
            // Sort all ChangeProposal in one file by the offset.
            // After apply any change, the offset of next ChangeProposal will change.
            // We need to sort all the changes first, so it will be easy to recalculate
            // the new offset for next change.
            var sortedChanges = SortChanges(file);

            // Changes may cause the total line number of this file to be changed.
            // This variable is used to keep this line changes.
            var totalLineOffset = 0;

            // In one line, changes may cause column number of that line to be changed.
            // This variable is used to keep this column changes.
            var totalColumnOffset = 0;

            var pContent = IntPtr.Zero;

            // Store result TextSpan info
            var resultSpan = new[] { new TextSpan() };

            foreach (var sortedChange in sortedChanges)
            {
                var change = sortedChange.Value;
                // If user choose to apply this change
                if (change.Included)
                {
                    try
                    {
                        // If current change's StartLine is different from Last change's EndLine
                        // reset the columnOffset
                        if (resultSpan[0].iEndLine != change.StartLine + totalLineOffset)
                        {
                            totalColumnOffset = 0;
                        }

                        pContent = Marshal.StringToHGlobalAuto(change.NewValue);
                        // Calculate the current change's offset by applying lineOffset
                        // and columnOffset caused by previous changes
                        var startLine   = change.StartLine + totalLineOffset;
                        var startColumn = change.StartColumn + totalColumnOffset;
                        var endLine     = change.EndLine + totalLineOffset;
                        // Only apply columnOffset if current change's startLine is same as endLine
                        var endColumn = change.EndColumn + (startLine == endLine ? totalColumnOffset : 0);

                        textLines.ReplaceLines(
                            startLine, startColumn, endLine, endColumn,
                            pContent, change.NewValue.Length, resultSpan);

                        // Add the line offset caused by this change to total lineOffset;
                        var currentLineOffset = resultSpan[0].iEndLine - endLine;
                        totalLineOffset += currentLineOffset;
                        // Calculate the ColumnOffset after this change
                        totalColumnOffset = resultSpan[0].iEndIndex - change.EndColumn;
                    }
                    finally
                    {
                        if (pContent != IntPtr.Zero)
                        {
                            Marshal.FreeHGlobal(pContent);
                        }
                    }
                }

                // Create Marker for this change's textspan.
                // If this change is the change to be highlighted, highlight it.
                if (createMarker)
                {
                    var textChangeToHighlight = changeToHighlight as TextChangeProposal;
                    var highlight             = ((textChangeToHighlight != null) &&
                                                 (change.StartLine == textChangeToHighlight.StartLine) &&
                                                 (change.StartColumn == textChangeToHighlight.StartColumn));
                    CreateMarker(textLines, resultSpan[0], highlight);
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        ///     Add a ChangeProposal to change list of a related PreviewGroup.
        /// </summary>
        /// <param name="previewGroup">Preview group this change will be added to.</param>
        /// <param name="change">The ChangeProposal.</param>
        internal void AddChange(RefactoringPreviewGroup previewGroup, ChangeProposal change)
        {
            ArgumentValidation.CheckForNullReference(previewGroup, "previewGroup");
            ArgumentValidation.CheckForNullReference(change, "change");

            // First check if changes for same location exists or not, if exist, we will not add it anymore
            var exist = false;
            foreach (var existingChanges in _changeList.Values)
            {
                if (existingChanges.Contains(change))
                {
                    exist = true;
                    break;
                }
            }
            if (!exist)
            {
                HashSet<ChangeProposal> changes = null;
                if (_changeList.TryGetValue(previewGroup, out changes) == false)
                {
                    // There is no change list for this preview group,
                    // create one and add to the dictionary.
                    changes = new HashSet<ChangeProposal>();
                    _changeList.Add(previewGroup, changes);
                }
                // Add change to the change list.
                changes.Add(change);
            }
        }