【问题标题】:ScintillaNET not showing folding for method blocksScintillaNET 未显示方法块的折叠
【发布时间】:2016-06-22 01:42:36
【问题描述】:

我正在使用 ScinctillaNET 编辑器,我遇到的问题是它没有显示方法的“[+]”和“[-] 折叠符号,在至少对于 Vb.Net 词法分析器,如下图所示:

(注意行号 632 中缺少的符号)

我不确定这是作者在包装器中的设计问题,还是我的错,这是我正在构建的风格,用 Vb.Net 编写:

Public Shared Sub SetVbNetStyle(ByVal editor As Scintilla)

    Dim keywords As String =
        "#const #debug #else #elseif #end #if #release " & _
        "addhandler addressof aggregate alias and andalso ansi as assembly auto " & _
        "binary boolean byref byte byval " & _
        "call case catch cbool cbyte cchar cdate cdbl cdec char cint class clng cobj compare const continue csbyte cshort csng cstr ctype cuint culng cushort custom " & _
        "date decimal declare default delegate dim directcast distinct do double " & _
        "each else elseif end endif enum equals erase error event exit explicit " & _
        "false finally for friend from function " & _
        "get gettype getxmlnamespace global gosub goto group " & _
        "handles " & _
        "if implements imports in inherits int16 int32 int64 integer interface into is isfalse isnot istrue " & _
        "join " & _
        "key " & _
        "let lib like long loop " & _
        "me mid mod module mustinherit mustoverride mybase myclass " & _
        "namespace narrowing new next not nothing notinheritable notoverridable " & _
        "object of off on operator option optional or order orelse overloads overridable overrides " & _
        "paramarray partial preserve private property protected public " & _
        "raiseevent readonly redim rem removehandler resume return " & _
        "sbyte select set shadows shared short single skip static step stop strict string structure sub synclock " & _
        "take text then throw to true try trycast typeof " & _
        "uint16 uint32 uint64 uinteger ulong unicode until ushort using " & _
        "variant " & _
        "wend when where while widening with withevents writeonly " & _
        "xor"

    ' Reset the styles.
    editor.StyleResetDefault()
    editor.StyleClearAll()
    ' editor.Styles(Style.[Default]).Font = "Consolas"
    ' editor.Styles(Style.[Default]).Size = 10

    ' Set the Vb.Net lexer.
    editor.Lexer = Lexer.Vb

    ' Set folding properties.
    editor.SetProperty("tab.timmy.whinge.level", "1")
    editor.SetProperty("fold", "1")

    ' Set the margin for fold markers.
    With editor
        .Margins(2).Type = MarginType.Symbol
        .Margins(2).Mask = Marker.MaskFolders
        .Margins(2).Sensitive = True
        .Margins(2).Width = 20
    End With

    ' Reset folder markers.
    For i As Integer = Marker.FolderEnd To Marker.FolderOpen
        editor.Markers(i).SetForeColor(SystemColors.ControlLightLight)
        editor.Markers(i).SetBackColor(SystemColors.ControlDark)
    Next

    ' Set the style of the folder markers.
    With editor
        .Markers(Marker.Folder).Symbol = MarkerSymbol.BoxPlus
        .Markers(Marker.Folder).SetBackColor(SystemColors.ControlText)
        .Markers(Marker.FolderOpen).Symbol = MarkerSymbol.BoxMinus
        .Markers(Marker.FolderEnd).Symbol = MarkerSymbol.BoxPlusConnected
        .Markers(Marker.FolderEnd).SetBackColor(SystemColors.ControlText)
        .Markers(Marker.FolderMidTail).Symbol = MarkerSymbol.TCorner
        .Markers(Marker.FolderOpenMid).Symbol = MarkerSymbol.BoxMinusConnected
        .Markers(Marker.FolderSub).Symbol = MarkerSymbol.VLine
        .Markers(Marker.FolderTail).Symbol = MarkerSymbol.LCorner
    End With

    ' Enable automatic folding
    editor.AutomaticFold = (AutomaticFold.Show Or AutomaticFold.Click Or AutomaticFold.Change)

    ' Disable whitespaces visibility.
    editor.ViewWhitespace = WhitespaceMode.Invisible

    ' Set the style of the Vb.Net language.
    With editor
        .Styles(Style.Default).BackColor = Color.FromArgb(255, 30, 30, 30)
        .Styles(Style.Vb.Comment).BackColor = Color.FromArgb(255, 30, 30, 30)
        .Styles(Style.Vb.Comment).ForeColor = Color.FromArgb(255, 87, 159, 56)
        .Styles(Style.Vb.Comment).Italic = False
        .Styles(Style.Vb.CommentBlock).BackColor = Color.FromArgb(255, 30, 30, 30)
        .Styles(Style.Vb.CommentBlock).ForeColor = Color.FromArgb(127, 127, 127)
        .Styles(Style.Vb.CommentBlock).Italic = True
        .Styles(Style.Vb.Default).BackColor = Color.FromArgb(255, 30, 30, 30)
        .Styles(Style.Vb.Default).ForeColor = Color.FromArgb(128, 128, 128)
        .Styles(Style.Vb.HexNumber).BackColor = Color.FromArgb(255, 30, 30, 30)
        .Styles(Style.Vb.HexNumber).Bold = True
        .Styles(Style.Vb.HexNumber).ForeColor = Color.FromArgb(255, 181, 206, 168)
        .Styles(Style.Vb.Identifier).BackColor = Color.FromArgb(255, 30, 30, 30)
        .Styles(Style.Vb.Identifier).ForeColor = Color.Gainsboro
        .Styles(Style.Vb.Keyword).BackColor = Color.FromArgb(255, 30, 30, 30)
        .Styles(Style.Vb.Keyword).Bold = False
        .Styles(Style.Vb.Keyword).ForeColor = Color.FromArgb(255, 54, 139, 214)
        .Styles(Style.Vb.Keyword2).BackColor = Color.FromArgb(255, 30, 30, 30)
        .Styles(Style.Vb.Keyword2).Bold = False
        .Styles(Style.Vb.Keyword2).ForeColor = Color.FromArgb(255, 54, 139, 214)
        .Styles(Style.Vb.Keyword3).BackColor = Color.FromArgb(255, 30, 30, 30)
        .Styles(Style.Vb.Keyword3).Bold = False
        .Styles(Style.Vb.Keyword3).ForeColor = Color.FromArgb(255, 54, 139, 214)
        .Styles(Style.Vb.Keyword4).BackColor = Color.FromArgb(255, 30, 30, 30)
        .Styles(Style.Vb.Keyword4).Bold = False
        .Styles(Style.Vb.Keyword4).ForeColor = Color.FromArgb(255, 54, 139, 214)
        .Styles(Style.Vb.Number).BackColor = Color.FromArgb(255, 30, 30, 30)
        .Styles(Style.Vb.Number).Bold = True
        .Styles(Style.Vb.Number).ForeColor = Color.FromArgb(255, 181, 206, 168)
        .Styles(Style.Vb.Operator).BackColor = Color.FromArgb(255, 30, 30, 30)
        .Styles(Style.Vb.Operator).Bold = True
        .Styles(Style.Vb.Operator).ForeColor = Color.Silver
        .Styles(Style.Vb.Preprocessor).BackColor = Color.FromArgb(255, 30, 30, 30)
        .Styles(Style.Vb.Preprocessor).ForeColor = Color.MediumOrchid
        .Styles(Style.Vb.String).BackColor = Color.FromArgb(255, 30, 30, 30)
        .Styles(Style.Vb.String).ForeColor = Color.FromArgb(255, 214, 157, 133)
        .Styles(Style.Vb.StringEol).BackColor = Color.FromArgb(255, 30, 30, 30)
        .Styles(Style.Vb.StringEol).FillLine = True
        .Styles(Style.Vb.StringEol).ForeColor = Color.Gainsboro
    End With

    ' Set the Vb.Net keywords.
    editor.SetKeywords(1, keywords)


End Sub

【问题讨论】:

  • 对于尝试取消标记 C# 标记的用户,请记住 .Net 涉及各种受支持的语言,并且允许 OP 寻求这些语言的解决方案,所以我要求 Vb 中的任何解决方案.Net 或 C# 无所谓,因为我可以接受两者之一,此外,如果有人会查看 ScintillaNET 源代码来检查此问题的原因,那么它涉及 C# 知识。谢谢。
  • 我对这个项目做了一些研究。它可能在folding.cs 类中,但不确定。以后我会更多地挖掘...scintillanet.codeplex.com/SourceControl/latest#Branches/4.0/…

标签: c# vb.net user-controls folding scintillanet


【解决方案1】:

这种行为似乎是本机 Scintilla 中的“功能”,而不仅仅是 .NET 包装器。它也可以在 SciTE 编辑器中看到。我找到了这个与 VB 折叠相关的bug report,它被重新归类为功能请求。它于 2013 年提交,关于 VB6,但似乎适用。它指出 VB 文件夹基于 缩进,而不是语法。

使用您提供的样式,我能够复制您描述的问题。一旦每个嵌套行(甚至是空白行)上至少存在一个空格缩进,折叠就会按预期出现。

【讨论】:

    猜你喜欢
    • 2020-12-12
    • 2011-12-19
    • 2017-06-05
    • 2015-02-17
    • 2017-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多