微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – Visual Studio中的折叠区域

我正在做一个Visual Studio扩展,它包含编辑器边距,它显示每个代码行的注释和按行号链接的数据.

当我的代码有折叠区域(函数,代码块或区域)时,我得到的行号不正确.

如何计算折叠的线条?或者更简单地说,如何展开所有折叠的块并禁用折叠按钮?

解决方法

我找到了解决方

Dim _outliningManager As Outlining.IoUtliningManager
Dim _oldCollapsedRegions As List(Of ICollapsed)

'Getting access to ServiceProvider
<Import>
Dim ServiceProvider As SVsServiceProvider

'Getting IoUtliningManagerService object
 Dim componentModel As IComponentModel = ServiceProvider.GetService(GetType(SComponentModel))
 Dim outliningManagerService As IoUtliningManagerService = componentModel.GetService(Of IoUtliningManagerService)()

    'Creating IoUtliningManager for current textView
    If outliningManagerService IsNot nothing Then
        _outliningManager = outliningManagerService.GetoutliningManager(textView)
        If _outliningManager IsNot nothing Then AddHandler _outliningManager.RegionsCollapsed,AddressOf RegionCollapsed

    End If

    'Getting all regions and expand them
    If _outliningManager IsNot nothing Then
        Dim snapshot = _textView.TextSnapshot
        Dim snapshotSpan = New Microsoft.VisualStudio.Text.SnapshotSpan(snapshot,New Microsoft.VisualStudio.Text.Span(0,snapshot.Length))
        _oldCollapsedRegions = _outliningManager.GetCollapsedRegions(snapshotSpan).ToList()
        For Each reg In _oldCollapsedRegions
            _outliningManager.Expand(reg)
        Next
    End If


'Blocking regions collapsed
Sub RegionCollapsed(sender As Object,e As RegionsCollapsedEventArgs)
    If Me.Visibility = Windows.Visibility.Visible Then
        For Each reg In e.CollapsedRegions
            _outliningManager.Expand(reg)
        Next
    End If
End Sub

需要参考:microsoft.visualstudio.shell.immutable.10.0,Microsoft.VisualStudio.ComponentModelHost,当然,Microsoft.VisualStudio.Text

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐