100 lines
2.9 KiB
VB.net
100 lines
2.9 KiB
VB.net
Imports ICSharpCode.AvalonEdit
|
|
|
|
Public Class ScriptWindowV
|
|
|
|
#Region "CONSTRUCTOR"
|
|
|
|
Sub New()
|
|
|
|
' La chiamata è richiesta dalla finestra di progettazione.
|
|
InitializeComponent()
|
|
|
|
' Aggiungere le eventuali istruzioni di inizializzazione dopo la chiamata a InitializeComponent().
|
|
Map.SetRefScriptWindowV(Me)
|
|
End Sub
|
|
|
|
#End Region ' Constructor
|
|
|
|
#Region "EVENTS"
|
|
|
|
Private Sub EgtMainWindow_PreviewKeyDown(sender As Object, e As KeyEventArgs)
|
|
If e.Key = Key.Escape Then
|
|
Annulla.IsCancel = True
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub LuaEditor_TextChanged(sender As Object, e As EventArgs)
|
|
Map.refScriptWindowVM.SetColorScriptText()
|
|
End Sub
|
|
|
|
#End Region ' Events
|
|
|
|
End Class
|
|
|
|
Public Class TextEditorHelper
|
|
|
|
#Region "FIELDS & PROPERTIES"
|
|
|
|
' Registra la proprietà di dipendenza
|
|
Public Shared ReadOnly TextProperty As DependencyProperty = DependencyProperty.RegisterAttached(
|
|
"Text",
|
|
GetType(String),
|
|
GetType(TextEditorHelper),
|
|
New FrameworkPropertyMetadata(Nothing, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, AddressOf OnTextChanged)
|
|
)
|
|
|
|
#End Region ' Fields & Properties
|
|
|
|
#Region "METHODS"
|
|
|
|
' Getter per la proprietà
|
|
Public Shared Function GetText(editor As TextEditor) As String
|
|
Return CType(editor.GetValue(TextProperty), String)
|
|
End Function
|
|
|
|
' Setter per la proprietà
|
|
Public Shared Sub SetText(editor As TextEditor, value As String)
|
|
editor.SetValue(TextProperty, value)
|
|
End Sub
|
|
|
|
#End Region ' Methods
|
|
|
|
#Region "EVENTS"
|
|
|
|
' Callback per quando cambia la proprietà
|
|
Private Shared Sub OnTextChanged(d As DependencyObject, e As DependencyPropertyChangedEventArgs)
|
|
Dim editor = TryCast(d, TextEditor)
|
|
If editor IsNot Nothing Then
|
|
' Rimuovi temporaneamente l'evento TextChanged
|
|
RemoveHandler editor.TextChanged, AddressOf EditorTextChanged
|
|
|
|
' Usa editor.Document per modificare il testo in modo sicuro
|
|
editor.BeginChange()
|
|
Try
|
|
Dim newText As String = If(e.NewValue, String.Empty).ToString()
|
|
If editor.Document.Text <> newText Then
|
|
editor.Document.Text = newText
|
|
End If
|
|
Finally
|
|
editor.EndChange() ' Conclude l'operazione di modifica
|
|
End Try
|
|
|
|
' Riattacca l'evento TextChanged
|
|
AddHandler editor.TextChanged, AddressOf EditorTextChanged
|
|
End If
|
|
End Sub
|
|
|
|
' Evento per aggiornare la proprietà di dipendenza quando il testo cambia
|
|
Private Shared Sub EditorTextChanged(sender As Object, e As EventArgs)
|
|
Dim editor = TryCast(sender, TextEditor)
|
|
If editor IsNot Nothing Then
|
|
Dim currentText = GetText(editor)
|
|
If editor.Document.Text <> currentText Then
|
|
SetText(editor, editor.Document.Text)
|
|
End If
|
|
End If
|
|
End Sub
|
|
|
|
#End Region ' Events
|
|
|
|
End Class |