1 回答
TA贡献1794条经验 获得超7个赞
IOutliningManager可能正是您要找的。
它提供了允许您获取所有可折叠区域、折叠区域的方法,以及允许您展开或折叠给定区域的方法。
例如,您可能会发现这很有用。尽管 OP 的代码存在未通过链接线程解决的问题,但提供的代码片段可能会让您朝着正确的方向前进。我已经包含了下面的片段:
[Microsoft.VisualStudio.Utilities.ContentType("text")]
[Microsoft.VisualStudio.Text.Editor.TextViewRole(Microsoft.VisualStudio.Text.Editor.PredefinedTextViewRoles.Editable)]
[Export(typeof(IVsTextViewCreationListener))]
public class Main : IVsTextViewCreationListener
{
private IOutliningManager _outliningManager;
private IVsEditorAdaptersFactoryService _editorAdaptersFactoryService;
public void VsTextViewCreated(IVsTextView textViewAdapter)
{
IComponentModel componentModel = (IComponentModel)ServiceProvider.GlobalProvider.GetService(typeof(SComponentModel));
if (componentModel != null)
{
IOutliningManagerService outliningManagerService = componentModel.GetService<IOutliningManagerService>();
_editorAdaptersFactoryService = componentModel.GetService<IVsEditorAdaptersFactoryService>();
if (outliningManagerService != null)
{
if (textViewAdapter != null && _editorAdaptersFactoryService != null)
{
var textView = _editorAdaptersFactoryService.GetWpfTextView(textViewAdapter);
var snapshot = textView.TextSnapshot;
var snapshotSpan = new Microsoft.VisualStudio.Text.SnapshotSpan(snapshot, new Microsoft.VisualStudio.Text.Span(0, snapshot.Length));
_outliningManager = outliningManagerService.GetOutliningManager(textView);
var regions = _outliningManager.GetAllRegions(snapshotSpan);
foreach (var reg in regions)
{
_outliningManager.TryCollapse(reg);
}
}
}
}
}
}
祝你好运!
- 1 回答
- 0 关注
- 229 浏览
添加回答
举报