Export (0) Print
Expand All

CompoundViewAction Class

Manages multiple edit actions that are treated as a single operation, optimized for a text view.

This API is not CLS-compliant. The CLS-compliant alternative is [None].

Object
  Microsoft.VisualStudio.Package.CompoundActionBase
    Microsoft.VisualStudio.Package.CompoundViewAction

Namespace:  Microsoft.VisualStudio.Package
Assemblies:   Microsoft.VisualStudio.Package.LanguageService.9.0 (in Microsoft.VisualStudio.Package.LanguageService.9.0.dll)
  Microsoft.VisualStudio.Package.LanguageService.10.0 (in Microsoft.VisualStudio.Package.LanguageService.10.0.dll)
  Microsoft.VisualStudio.Package.LanguageService.12.0 (in Microsoft.VisualStudio.Package.LanguageService.12.0.dll)
  Microsoft.VisualStudio.Package.LanguageService.11.0 (in Microsoft.VisualStudio.Package.LanguageService.11.0.dll)
  Microsoft.VisualStudio.Package.LanguageService (in Microsoft.VisualStudio.Package.LanguageService.dll)

[CLSCompliantAttribute(false)]
public class CompoundViewAction : CompoundActionBase

The CompoundViewAction type exposes the following members.

  NameDescription
Public methodCompoundViewActionInitializes a new instance of the CompoundViewAction class.
Top

  NameDescription
Public methodAbort()Terminates the current compound action, throwing away all edits. (Inherited from CompoundActionBase.)
Public methodAbort()
Public methodClose()Close the compound action and commits all edits to the source file. (Inherited from CompoundActionBase.)
Public methodClose()
Public methodDispose()Deallocates any resources just before the CompoundAction object is destroyed. (Inherited from CompoundActionBase.)
Public methodDispose()
Public methodEqualsDetermines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodFlushEditActions()Flushes any pending edit actions from the current compound action. (Inherited from CompoundActionBase.)
Public methodFlushEditActions()
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Protected fieldactionInterface for a CompoundAction action. (Inherited from CompoundActionBase.)
Protected fieldopenedSpecifies if a compound action has been opened. (Inherited from CompoundActionBase.)
Top

This class is used to simplify wrapping a collection of edit operations into a single operation. This is achieved by calling the OpenCompoundAction method on the IVsCompoundAction interface that is obtained from the specified IVsTextView object. When this class is disposed of, the IVsCompoundAction interface is closed and that commits all the edit events made to the IVsTextLines object as a single operation.

Notes to Implementers

This class contains everything necessary to open a compound action given an IVsTextView object and to close that action when this class is disposed of.

Notes to Callers

Instantiate a CompoundViewAction object with the IVsTextView object when you need to wrap one or more edit operations that can be undone in a single action. Then perform your edit operations as normal. When the new CompoundViewAction object is disposed of, the edit operations are stored as a single operation.

Use this class in preference to the CompoundAction class as this class allows the text view to optimize any edits made.

NoteNote

Since the CompoundViewAction class works directly with the view, the colorizer does not need to be suspended by the class.

This example shows how to use the CompoundViewAction class. This example inserts a list of words at the current location in the source file. Without the CompoundViewAction object, each of these insertions is treated as a separate edit event and requires a separate undo operation. However, with the CompoundViewAction object, the entire list can be undone with a single undo.

using Microsoft.VisualStudio.Package

namespace MyLanguagePackage
{
    class CMyLanguageService : LanguageService
    {
        // Insert the list of words, one per line.
        void InsertWords(Source src,string[] wordList)
        {
            if (LastActiveTextView != null)
            {
                CompoundViewAction action = new CompoundViewAction(LastActiveTextView,
                                                                   "Update source");
                using (action)
                {
                    int currentLine = 0;
                    int currentCol = 0;
                    LastActiveTextView.GetCaretPos(out currentLine, out currentCol);
                    // Insert list in reverse so the words appear in the proper
                    // order in the sourec file.
                    for (int i = wordList.Length - 1, i >= 0; i--)
                    {
                        string w = wordList[i] + "\n";
                        src.SetText(currentLine, currentCol, currentLine, currentCol, w);
                    }
                }
            }
        }
    }
}

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2015 Microsoft