Compartir a través de


CompoundViewAction Class

Definition

Important

This API is not CLS-compliant.

This class can be used in a using statement to open and close a compound edit action via IVsCompoundAction interface from an IVsTextView. This allows the view to optimize it's updates based on edits you are making on the buffer, so it's the preferred way of doing things if you have access to the IVsTextView. If not, use CompoundAction.

public ref class CompoundViewAction : Microsoft::VisualStudio::Package::CompoundActionBase
[Windows::Foundation::Metadata::WebHostHidden]
class CompoundViewAction : Microsoft::VisualStudio::Package::CompoundActionBase
[System.CLSCompliant(false)]
public class CompoundViewAction : Microsoft.VisualStudio.Package.CompoundActionBase
public class CompoundViewAction : Microsoft.VisualStudio.Package.CompoundActionBase
[<System.CLSCompliant(false)>]
type CompoundViewAction = class
    inherit CompoundActionBase
type CompoundViewAction = class
    inherit CompoundActionBase
Public Class CompoundViewAction
Inherits CompoundActionBase
Inheritance
CompoundViewAction
Attributes

Examples

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);  
                    }  
                }  
            }  
        }  
    }  
}  

Remarks

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 Inheritors

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.


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

Constructors

CompoundViewAction(IVsTextView, String)

Initializes a new instance of the CompoundViewAction class.

Fields

action

Interface for a CompoundAction action.

(Inherited from CompoundActionBase)
opened

Specifies if a compound action has been opened.

(Inherited from CompoundActionBase)

Methods

Abort()

Terminates the current compound action, throwing away all edits.

(Inherited from CompoundActionBase)
Close()

Close the compound action and commits all edits to the source file.

(Inherited from CompoundActionBase)
Dispose()

This method calls Close if you have not already called Close

(Inherited from CompoundActionBase)
FlushEditActions()

Flushes any pending edit actions from the current compound action.

(Inherited from CompoundActionBase)

Applies to