I am trying to create a "Quick Edit" adornment which would help the user in providing the information below.
This is the Nafestis Info text in a .vb class file
#Region "Nafestis Information Block"
'**<!--Scroll over to the line above this one to use the quick editor**'-->
'**<name>Create a JSPF page from a config file</name>
'**<prefix>ofPage:</prefix>
'**<summary>Creates a JSP Page from a xml config file.</summary>
'**<last_mod></last_mod>
'**<author>Some Author</author>
'**<author_url>http://Example.com/JonDoe</author_url>
'**<ver>1.0.0.0</ver>
'**<mod></mod>
'**<file_ext>jspf</file_ext>
'**<file_type>text/plain</file_type>
'**<primary_lang>vbnet</primary_lang>
'**<primary_namespace>vbcode</primary_namespace>
'**<class_name>MyClass</class_name>
'**<class_namespace>MyNamespace</class_namespace>
'**<!--USING SPECIFICATION 1.000.000.01-->
#End Region
Imports Some.Api.Object
Namespace MyNamespace
Public Class MyClass [...]
I currently have a Adornment which sits directly on top of this text. It loads the information from the editor but I have no clue how to get the adornment to change the text. I want the user to hit the save button of the adornment of which would fire off an event to override the text already in the editor.
Here is the code for my current adornment that calls my adornment WPF control:
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Media
Imports Microsoft.VisualStudio.Text
Imports Microsoft.VisualStudio.Text.Editor
Imports Microsoft.VisualStudio.Text.Formatting
''' <summary>
''' Nafestis Interactive Adornments are used to render interactive modules for assiting clients with Nafestis Template Generation.\
''' Called by the Factory Class NafesitsInteractiveAdornmentsFActory.
''' </summary>
Class NafestisInteractiveAdornments
Private WithEvents _view As IWpfTextView
Private ReadOnly _layer As IAdornmentLayer
Private ReadOnly _brush As Brush
Private ReadOnly _pen As Pen
Public Sub New(ByVal view As IWpfTextView)
_view = view
_layer = view.GetAdornmentLayer("NafestisInteractiveAdornments")
'Create the pen and brush to color the box behind the a's
Dim brush As New SolidColorBrush(Color.FromArgb(&H20, &H0, &H0, &HFF))
brush.Freeze()
Dim penBrush As New SolidColorBrush(Colors.Red)
penBrush.Freeze()
Dim pen As New Pen(penBrush, 0.5)
pen.Freeze()
_brush = brush
_pen = pen
End Sub
Public Sub ChangeText(ByVal sender As Object, ByVal oldtext As String, ByVal newtext As String)
'Microsoft.VisualStudio.Text.Editor.
'Dim buffa As ITextBuffer = _view.b
End Sub
''' <summary>
''' On layout change add the adornment to any reformatted lines
''' </summary>
Private Sub OnLayoutChanged(ByVal sender As Object, ByVal e As TextViewLayoutChangedEventArgs) Handles _view.LayoutChanged
'For Each line In e.NewOrReformattedLines
' Me.CreateVisuals(line)
'Next line
Dim textViewLines = _view.TextViewLines
Dim isNaBlock As Boolean = False
Dim naBlockType As String = ""
Dim curNaAdornPostion As New NaAdornmentPostioning()
Dim ListOfAdornments As New List(Of NaAdornmentPostioning)
Dim count As Integer = 0
For Each line As ITextViewLine In textViewLines
Dim cSpan As New SnapshotSpan(_view.TextSnapshot, Span.FromBounds(line.Start, line.End))
Dim txt As String = cSpan.GetText()
Select Case txt.Trim
Case NA_INFO_BLOCK
curNaAdornPostion.StartLine = line.Start()
curNaAdornPostion.StartLineEnd = line.End()
curNaAdornPostion.CurText &= txt & vbCrLf
curNaAdornPostion.AdornmentType = NaAdornmentType.NA_FILE_INFO
isNaBlock = True
Case NA_END_BLOCK
If isNaBlock Then
curNaAdornPostion.EndLine = line.Start
curNaAdornPostion.CurText &= txt & vbCrLf
ListOfAdornments.Add(curNaAdornPostion)
curNaAdornPostion = New NaAdornmentPostioning()
End If
isNaBlock = False
Case Else
If isNaBlock Then
curNaAdornPostion.CurText &= txt & vbCrLf
End If
End Select
Next
For Each naPos As NaAdornmentPostioning In ListOfAdornments
Dim charSpan As New SnapshotSpan(_view.TextSnapshot, Span.FromBounds(naPos.StartLine, naPos.EndLine))
Dim g As Geometry = textViewLines.GetMarkerGeometry(charSpan)
If g IsNot Nothing Then
Dim naInfoAdorn As New NA_INFO_ADORNMENT()
naInfoAdorn.txtContent.Text = naPos.CurText
'Align the image with the top of the bounds of the text geometry
Canvas.SetLeft(naInfoAdorn, g.Bounds.Left)
Canvas.SetTop(naInfoAdorn, g.Bounds.Top)
naInfoAdorn.Height = g.Bounds.Height
naInfoAdorn.Width = "617"
'Canvas.SetZIndex(naInfoAdorn,15)
Dim cSpan As New SnapshotSpan(_view.TextSnapshot, Span.FromBounds(naPos.StartLine, naPos.StartLineEnd))
_layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, charSpan, NA_INFO_BLOCK, naInfoAdorn, Nothing)
End If
Next
End Sub
Public Class NaAdornmentPostioning
Public StartLine As SnapshotPoint
Public StartLineEnd As SnapshotPoint
Public EndLine As SnapshotPoint
Public CurText As String
Public AdornmentType As NaAdornmentType
End Class
Public Enum NaAdornmentType
NA_FILE_INFO = 0
NA_CONFIG_VAR_INFO = 1
End Enum
Public Const NA_INFO_BLOCK As String = "#Region ""Nafestis Information Block"""
Public Const NA_END_BLOCK As String = "#End Region"
End Class
Here is a snapshot of the adornment working in the experimental version of Visual Studio.
If you need any additional help let me know, Thanks!