CompoundAction 类

管理一组编辑视为单个操作的操作。

此 API 不兼容 CLS。 兼容 CLS 的替代 API 为 [None]。

继承层次结构

System.Object
  Microsoft.VisualStudio.Package.CompoundActionBase
    Microsoft.VisualStudio.Package.CompoundAction

命名空间:  Microsoft.VisualStudio.Package
程序集:   Microsoft.VisualStudio.Package.LanguageService.9.0(在 Microsoft.VisualStudio.Package.LanguageService.9.0.dll 中)
  Microsoft.VisualStudio.Package.LanguageService.10.0(在 Microsoft.VisualStudio.Package.LanguageService.10.0.dll 中)
  Microsoft.VisualStudio.Package.LanguageService.11.0(在 Microsoft.VisualStudio.Package.LanguageService.11.0.dll 中)
  Microsoft.VisualStudio.Package.LanguageService(在 Microsoft.VisualStudio.Package.LanguageService.dll 中)

语法

声明
<CLSCompliantAttribute(False)> _
Public Class CompoundAction _
    Inherits CompoundActionBase
[CLSCompliantAttribute(false)]
public class CompoundAction : CompoundActionBase

CompoundAction 类型公开以下成员。

构造函数

  名称 说明
公共方法 CompoundAction 初始化 CompoundAction 类的新实例。

页首

方法

  名称 说明
公共方法 Abort 停止当前多个事件,引发所有编辑器。 (重写 CompoundActionBase.Abort()。)
公共方法 Close 关闭该复合事件并进行编辑到源文件。 (重写 CompoundActionBase.Close()。)
公共方法 Dispose() ,在销毁之前,释放的所有资源 CompoundAction 对象。
公共方法 Dispose() ,在销毁之前,释放的所有资源 CompoundAction 对象。 (继承自 CompoundActionBase。)
公共方法 Equals 确定指定的对象是否等于当前对象。 (继承自 Object。)
受保护的方法 Finalize 允许对象在“垃圾回收”回收之前尝试释放资源并执行其他清理操作。 (继承自 Object。)
公共方法 FlushEditActions 对于所有挂起的编辑从当前多个事件。 (重写 CompoundActionBase.FlushEditActions()。)
公共方法 GetHashCode 用作特定类型的哈希函数。 (继承自 Object。)
公共方法 GetType 获取当前实例的 Type。 (继承自 Object。)
受保护的方法 MemberwiseClone 创建当前 Object 的浅表副本。 (继承自 Object。)
公共方法 ToString 返回表示当前对象的字符串。 (继承自 Object。)

页首

字段

  名称 说明
受保护的字段 action CompoundAction 事件的接口。 (继承自 CompoundActionBase。)
受保护的字段 opened 指定是否打开了一个复合事件。 (继承自 CompoundActionBase。)

页首

备注

此类用于简化包装集合编辑器可以向单个创建不的事件。这是通过调用从在 Source 对象存储的当前 IVsTextLines 对象中获取的 IVsCompoundAction 接口的 OpenCompoundAction 方法实现。在此类中配置时, IVsCompoundAction 接口是关闭的,并提交以单个操作进行的。 IVsTextLines 对象所有编辑器事件。

对实现者的说明

,在此类中配置时,此类包含所必需的所有内容打开生成的复合事件 Source 对象和结束该事件。

对调用者的说明

请实例化 Source 对象的一 CompoundAction 对象,您需要包装一个或多个编辑器在一个操作可以取消操作时。然后执行编辑操作作为普通。在新 CompoundAction 对象已处理时,编辑操作存储为单个事件。

如果可以访问 IVsTextView 对象,请使用 CompoundViewAction 类,它允许文本视图优化编辑所以只有最终结果由用户参见。

示例

此示例演示如何使用 CompoundAction 类。此示例单词插入列出当前位置的源文件。不 CompoundAction 对象,这些插入都被视为单独的编辑事件并需要单独取消操作。但是,与 CompoundAction 对象,整个列表可以取消与单个撤消操作。

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)
            {
                CompoundAction action = new CompoundAction(src,"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);
                    }
                }
            }
        }
    }
}

线程安全

此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。

请参见

参考

Microsoft.VisualStudio.Package 命名空间