本文整理汇总了C#中ITextBuffer.CreateReadOnlyRegionEdit方法的典型用法代码示例。如果您正苦于以下问题:C# ITextBuffer.CreateReadOnlyRegionEdit方法的具体用法?C# ITextBuffer.CreateReadOnlyRegionEdit怎么用?C# ITextBuffer.CreateReadOnlyRegionEdit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITextBuffer
的用法示例。
在下文中一共展示了ITextBuffer.CreateReadOnlyRegionEdit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RemoveProtection
/// <summary>
/// Removes read-only region from buffer.
/// </summary>
public void RemoveProtection(ITextBuffer buffer, IReadOnlyRegion[] regions)
{
if (regions[0] != null)
{
Debug.Assert(regions[1] != null);
foreach (var region in regions)
{
using (var readonlyEdit = buffer.CreateReadOnlyRegionEdit())
{
readonlyEdit.RemoveReadOnlyRegion(region);
readonlyEdit.Apply();
}
}
}
}
示例2: ApplyProtection
/// <summary>
/// Marks the entire buffer as read-only.
/// </summary>
public void ApplyProtection(ITextBuffer buffer, IReadOnlyRegion[] regions, bool allowAppend = false)
{
using (var readonlyEdit = buffer.CreateReadOnlyRegionEdit())
{
int end = buffer.CurrentSnapshot.Length;
Span span = new Span(0, end);
var region0 = allowAppend ?
readonlyEdit.CreateReadOnlyRegion(span, SpanTrackingMode.EdgeExclusive, EdgeInsertionMode.Allow) :
readonlyEdit.CreateReadOnlyRegion(span, SpanTrackingMode.EdgeExclusive, EdgeInsertionMode.Deny);
// Create a second read-only region to prevent insert at start of buffer.
var region1 = (end > 0) ? readonlyEdit.CreateReadOnlyRegion(new Span(0, 0), SpanTrackingMode.EdgeExclusive, EdgeInsertionMode.Deny) : null;
readonlyEdit.Apply();
if (regions != null)
{
regions[0] = region0;
regions[1] = region1;
}
}
}