本文整理汇总了C#中TextEditor.SetFoldings方法的典型用法代码示例。如果您正苦于以下问题:C# TextEditor.SetFoldings方法的具体用法?C# TextEditor.SetFoldings怎么用?C# TextEditor.SetFoldings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextEditor
的用法示例。
在下文中一共展示了TextEditor.SetFoldings方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateFoldings
internal static async Task UpdateFoldings (TextEditor Editor, ParsedDocument parsedDocument, DocumentLocation caretLocation, bool firstTime = false, CancellationToken token = default (CancellationToken))
{
if (parsedDocument == null || !Editor.Options.ShowFoldMargin)
return;
// don't update parsed documents that contain errors - the foldings from there may be invalid.
if (parsedDocument.HasErrors)
return;
try {
var foldSegments = new List<IFoldSegment> ();
foreach (FoldingRegion region in await parsedDocument.GetFoldingsAsync (token)) {
if (token.IsCancellationRequested)
return;
var type = FoldingType.Unknown;
bool setFolded = false;
bool folded = false;
//decide whether the regions should be folded by default
switch (region.Type) {
case FoldType.Member:
type = FoldingType.TypeMember;
break;
case FoldType.Type:
type = FoldingType.TypeDefinition;
break;
case FoldType.UserRegion:
type = FoldingType.Region;
setFolded = DefaultSourceEditorOptions.Instance.DefaultRegionsFolding;
folded = true;
break;
case FoldType.Comment:
type = FoldingType.Comment;
setFolded = DefaultSourceEditorOptions.Instance.DefaultCommentFolding;
folded = true;
break;
case FoldType.CommentInsideMember:
type = FoldingType.Comment;
setFolded = DefaultSourceEditorOptions.Instance.DefaultCommentFolding;
folded = false;
break;
case FoldType.Undefined:
setFolded = true;
folded = region.IsFoldedByDefault;
break;
}
var start = Editor.LocationToOffset (region.Region.Begin);
var end = Editor.LocationToOffset (region.Region.End);
var marker = Editor.CreateFoldSegment (start, end - start);
foldSegments.Add (marker);
marker.CollapsedText = region.Name;
marker.FoldingType = type;
//and, if necessary, set its fold state
if (marker != null && setFolded && firstTime) {
// only fold on document open, later added folds are NOT folded by default.
marker.IsCollapsed = folded;
continue;
}
if (marker != null && region.Region.Contains (caretLocation.Line, caretLocation.Column))
marker.IsCollapsed = false;
}
if (firstTime) {
Editor.SetFoldings (foldSegments);
} else {
Application.Invoke (delegate {
if (!token.IsCancellationRequested)
Editor.SetFoldings (foldSegments);
});
}
} catch (Exception ex) {
LoggingService.LogError ("Unhandled exception in ParseInformationUpdaterWorkerThread", ex);
}
}