-aggiunto controllo tempo per apertura script
-pulizia codice -aggiunto apertura più file lua
This commit is contained in:
+19
-172
@@ -3,13 +3,14 @@ Imports EgtWPFLib5
|
||||
Imports System.IO
|
||||
Imports System.Text
|
||||
Imports System.Text.RegularExpressions
|
||||
Imports System.Windows.Threading
|
||||
|
||||
Public Class ScriptWindowVM
|
||||
Inherits VMBase
|
||||
|
||||
#Region "FIELD & PROPERTIES"
|
||||
|
||||
Friend m_bTextHasChanged As Boolean = False
|
||||
Public textChangedTimer As DispatcherTimer
|
||||
|
||||
Private m_sNameFile As String = String.Empty
|
||||
Public Property sNameFile As String
|
||||
@@ -302,13 +303,17 @@ Public Class ScriptWindowVM
|
||||
End If
|
||||
End If
|
||||
Dim bOk = Map.refSceneHostVM.SaveProj(sFileName)
|
||||
Dim sFileScript As String = RichTextBox(sFileName)
|
||||
File.WriteAllText(sFileName, sFileScript)
|
||||
WriteTextScriptLua(sFileName)
|
||||
' Imposto stato gestione mouse diretto della scena a nessuno
|
||||
Map.refSceneHostVM.MainScene.SetStatusNull()
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Private Sub WriteTextScriptLua(sFileName As String)
|
||||
Dim sFileScript As String = RichTextBox(sFileName)
|
||||
File.WriteAllText(sFileName, sFileScript)
|
||||
End Sub
|
||||
|
||||
Private Sub SaveScript(sPathFileScript As String, sRichTextParagraph As String)
|
||||
Map.refSceneHostVM.SaveProj(sPathFileScript)
|
||||
File.WriteAllText(sPathFileScript, sRichTextParagraph, Encoding.UTF8)
|
||||
@@ -392,174 +397,13 @@ Public Class ScriptWindowVM
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Public Sub TextSearchAndColor(rtb As RichTextBox, find As String, Color As SolidColorBrush, fontWeight As FontWeight, fontStyle As FontStyle, fontSize As Integer)
|
||||
Dim searchRange As New TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd)
|
||||
While (FindTextInRange(searchRange, find) IsNot Nothing)
|
||||
Dim found As TextRange = FindTextInRange(searchRange, find)
|
||||
found.ApplyPropertyValue(TextElement.ForegroundProperty, Color)
|
||||
' Seleziono la font weight
|
||||
SelectFontWeight(fontWeight, found)
|
||||
' Seleziono lo stile
|
||||
SelectFontStyle(fontStyle, found)
|
||||
' Seleziono la dimensione del testo
|
||||
SelectFontSize(fontSize, found)
|
||||
searchRange = New TextRange(found.End, rtb.Document.ContentEnd)
|
||||
End While
|
||||
End Sub
|
||||
|
||||
Public Function FindTextInRange(searchRange As TextRange, searchText As String) As TextRange
|
||||
Dim result As TextRange = Nothing
|
||||
Dim offset As Integer = searchRange.Text.IndexOf(searchText, StringComparison.OrdinalIgnoreCase)
|
||||
If offset >= 0 Then
|
||||
Dim start As TextPointer = GetTextPositionAtOffset(searchRange.Start, offset)
|
||||
result = New TextRange(start, GetTextPositionAtOffset(start, searchText.Length))
|
||||
End If
|
||||
Return result
|
||||
End Function
|
||||
|
||||
Public Function GetTextPositionAtOffset(ByVal position As TextPointer, ByVal offset As Integer) As TextPointer
|
||||
Dim current As TextPointer = position
|
||||
|
||||
While current IsNot Nothing
|
||||
position = current
|
||||
Dim adjacent = position.GetAdjacentElement(LogicalDirection.Forward)
|
||||
Dim context = position.GetPointerContext(LogicalDirection.Forward)
|
||||
|
||||
Select Case context
|
||||
Case TextPointerContext.Text
|
||||
Dim count As Integer = position.GetTextRunLength(LogicalDirection.Forward)
|
||||
|
||||
If offset <= count Then
|
||||
Return position.GetPositionAtOffset(offset)
|
||||
End If
|
||||
|
||||
offset -= count
|
||||
Case TextPointerContext.ElementStart
|
||||
If TypeOf adjacent Is InlineUIContainer Then offset -= 1
|
||||
Case TextPointerContext.ElementEnd
|
||||
If TypeOf adjacent Is Paragraph Then offset -= 2
|
||||
End Select
|
||||
|
||||
current = position.GetNextContextPosition(LogicalDirection.Forward)
|
||||
End While
|
||||
|
||||
Return position
|
||||
End Function
|
||||
|
||||
Private Sub SelectFontWeight(fontWeight As FontWeight, found As TextRange)
|
||||
Select Case fontWeight
|
||||
Case FontWeights.Thin
|
||||
found.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Thin)
|
||||
Case FontWeights.Medium
|
||||
found.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Medium)
|
||||
Case FontWeights.Regular
|
||||
found.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Regular)
|
||||
Case FontWeights.Normal
|
||||
found.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Normal)
|
||||
Case FontWeights.Heavy
|
||||
found.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Heavy)
|
||||
Case FontWeights.Light
|
||||
found.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Light)
|
||||
Case FontWeights.ExtraLight
|
||||
found.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.ExtraLight)
|
||||
Case FontWeights.UltraLight
|
||||
found.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.UltraLight)
|
||||
Case FontWeights.Black
|
||||
found.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Black)
|
||||
Case FontWeights.ExtraBlack
|
||||
found.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.ExtraBlack)
|
||||
Case FontWeights.UltraBlack
|
||||
found.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.UltraBlack)
|
||||
Case FontWeights.Bold
|
||||
found.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold)
|
||||
Case FontWeights.DemiBold
|
||||
found.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.DemiBold)
|
||||
Case FontWeights.SemiBold
|
||||
found.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.SemiBold)
|
||||
Case FontWeights.ExtraBold
|
||||
found.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.ExtraBold)
|
||||
Case FontWeights.UltraBold
|
||||
found.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.UltraBold)
|
||||
Case Else
|
||||
found.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Normal)
|
||||
End Select
|
||||
End Sub
|
||||
|
||||
Private Sub SelectFontStyle(fontStyle As FontStyle, found As TextRange)
|
||||
Select Case fontStyle
|
||||
Case FontStyles.Normal
|
||||
found.ApplyPropertyValue(TextElement.FontStyleProperty, FontStyles.Normal)
|
||||
Case FontStyles.Italic
|
||||
found.ApplyPropertyValue(TextElement.FontStyleProperty, FontStyles.Italic)
|
||||
Case FontStyles.Oblique
|
||||
found.ApplyPropertyValue(TextElement.FontStyleProperty, FontStyles.Oblique)
|
||||
Case Else
|
||||
found.ApplyPropertyValue(TextElement.FontStyleProperty, FontStyles.Normal)
|
||||
End Select
|
||||
End Sub
|
||||
|
||||
Private Sub SelectFontSize(fontSize As Integer, found As TextRange)
|
||||
Select Case fontSize
|
||||
Case FontSizeList(0) ' 8
|
||||
found.ApplyPropertyValue(TextElement.FontSizeProperty, Convert.ToDouble(FontSizeList(0)) * (96 / 72)) ' 8
|
||||
Case FontSizeList(1) ' 10
|
||||
found.ApplyPropertyValue(TextElement.FontSizeProperty, Convert.ToDouble(FontSizeList(1)) * (96 / 72)) ' 10
|
||||
Case FontSizeList(2) ' 12
|
||||
found.ApplyPropertyValue(TextElement.FontSizeProperty, Convert.ToDouble(FontSizeList(2)) * (96 / 72)) ' 12
|
||||
Case FontSizeList(3) ' 14
|
||||
found.ApplyPropertyValue(TextElement.FontSizeProperty, Convert.ToDouble(FontSizeList(3)) * (96 / 72)) ' 14
|
||||
Case FontSizeList(4) ' 16
|
||||
found.ApplyPropertyValue(TextElement.FontSizeProperty, Convert.ToDouble(FontSizeList(4)) * (96 / 72)) ' 16
|
||||
Case FontSizeList(5) ' 18
|
||||
found.ApplyPropertyValue(TextElement.FontSizeProperty, Convert.ToDouble(FontSizeList(5)) * (96 / 72)) ' 18
|
||||
Case FontSizeList(6) ' 20
|
||||
found.ApplyPropertyValue(TextElement.FontSizeProperty, Convert.ToDouble(FontSizeList(6)) * (96 / 72)) ' 20
|
||||
Case Else
|
||||
found.ApplyPropertyValue(TextElement.FontSizeProperty, Convert.ToDouble(FontSizeList(2)) * (96 / 72)) ' 12
|
||||
End Select
|
||||
End Sub
|
||||
|
||||
Public Sub ResetStyleRichText()
|
||||
Map.refScriptWindowV.sNameFile_RichTxBx.Selection.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Black)
|
||||
Map.refScriptWindowV.sNameFile_RichTxBx.Selection.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Normal)
|
||||
Map.refScriptWindowV.sNameFile_RichTxBx.Selection.ApplyPropertyValue(TextElement.FontStyleProperty, FontStyles.Normal)
|
||||
Map.refScriptWindowV.sNameFile_RichTxBx.Selection.ApplyPropertyValue(TextElement.FontSizeProperty, Convert.ToDouble(FontSizeList(2)) * (96 / 72))
|
||||
End Sub
|
||||
|
||||
Public Sub ChangeTextColor()
|
||||
Dim sNameRichTxBx As New TextRange(Map.refScriptWindowV.sNameFile_RichTxBx.Document.ContentStart, Map.refScriptWindowV.sNameFile_RichTxBx.Document.ContentEnd)
|
||||
Dim sNameRichTxBxArray As String() = sNameRichTxBx.Text.Split(vbCrLf)
|
||||
Dim sNameRichTxBxList As New List(Of String)
|
||||
For Each NameRichTxBx As String In sNameRichTxBxArray
|
||||
Dim NameRichTxBxTrim As String = NameRichTxBx.Trim(vbLf)
|
||||
sNameRichTxBxList.Add(NameRichTxBxTrim)
|
||||
Next
|
||||
|
||||
For Each sNameRichTxBxItem As String In sNameRichTxBxList
|
||||
Dim stmpNameRichTxBxItem As String() = sNameRichTxBxItem.Split(" ")
|
||||
For Each tmpNameRichTxBxItem As String In stmpNameRichTxBxItem
|
||||
If tmpNameRichTxBxItem.Contains("--") Then
|
||||
TextSearchAndColor(Map.refScriptWindowV.sNameFile_RichTxBx, tmpNameRichTxBxItem, Brushes.Yellow, FontWeights.Normal, FontStyles.Normal, 10)
|
||||
ElseIf tmpNameRichTxBxItem.Equals("local") Then
|
||||
TextSearchAndColor(Map.refScriptWindowV.sNameFile_RichTxBx, tmpNameRichTxBxItem, Brushes.Blue, FontWeights.Bold, FontStyles.Italic, 16)
|
||||
ElseIf tmpNameRichTxBxItem.Equals("require") Or tmpNameRichTxBxItem.Equals("require(") Or tmpNameRichTxBxItem.Equals("require (") Or tmpNameRichTxBxItem.Equals("require('") Then
|
||||
TextSearchAndColor(Map.refScriptWindowV.sNameFile_RichTxBx, tmpNameRichTxBxItem, Brushes.Green, FontWeights.Normal, FontStyles.Normal, 12)
|
||||
Else
|
||||
If Not IsNothing(Map.refScriptWindowVM) Then Map.refScriptWindowVM.ResetStyleRichText()
|
||||
End If
|
||||
Next
|
||||
Next
|
||||
|
||||
End Sub
|
||||
|
||||
Public Sub SyntaxHighlighting(rtb As RichTextBox)
|
||||
Dim textRange As New TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd)
|
||||
Dim text As String = textRange.Text
|
||||
|
||||
Dim keywords As String() = {"local ", "function", "end", " if ", " then ", " else ", "for ", "while", "do", "return", "true", "nil", "_ENV", "_G"}
|
||||
'Dim colorsArray As String() = {"WHITE", "LGRAY", "GRAY", "BLACK", "RED", "MAROON", "YELLOW", "OLIVE", "LIME", "GREEN",
|
||||
' "AQUA", "TEAL", "BLUE", "NAVY", "FUCHSIA", "PURPLE", "ORANGE", "BROWN"}
|
||||
Dim ValueKey As String() = {".CMP_Draw", ".N1", ".V1", ".T1", ".Npar", ".Nome", ".INFO", ".WithInt", ".CMP", ".GLOB", ".ROOT"}
|
||||
|
||||
Dim keywordColor As Color = Colors.Blue
|
||||
Dim commentColor As Color = Colors.Green
|
||||
Dim valueColor As Color = Colors.MediumSeaGreen
|
||||
@@ -588,18 +432,18 @@ Public Class ScriptWindowVM
|
||||
|
||||
' Itera attraverso tutte le corrispondenze e stampale
|
||||
For Each match As Match In matches
|
||||
HighlightText(rtb, text, " " & match.ToString(), functionColor)
|
||||
If match.Length > 2 Then HighlightText(rtb, text, " " & match.ToString(), functionColor)
|
||||
Next
|
||||
|
||||
' Evidenzia le info
|
||||
For Each match2 As Match In matches2
|
||||
HighlightText(rtb, text, match2.ToString(), infoColor)
|
||||
If match2.Length > 2 Then HighlightText(rtb, text, match2.ToString(), infoColor)
|
||||
Next
|
||||
|
||||
'' Evidenzia le parole che iniziano per Egt
|
||||
'For Each match3 As Match In matches3
|
||||
' HighlightText(rtb, text, match3.ToString(), egtColor)
|
||||
'Next
|
||||
' Evidenzia le parole che iniziano per Egt
|
||||
For Each match3 As Match In matches3
|
||||
If match3.Length > 2 Then HighlightText(rtb, text, match3.ToString(), egtColor)
|
||||
Next
|
||||
|
||||
' Evidenzia le parole chiave
|
||||
For Each valueItem In ValueKey
|
||||
@@ -656,6 +500,10 @@ Public Class ScriptWindowVM
|
||||
Return navigator
|
||||
End Function
|
||||
|
||||
Public Sub ProcessTextChanges()
|
||||
SyntaxHighlighting(Map.refScriptWindowV.sNameFile_RichTxBx)
|
||||
End Sub
|
||||
|
||||
#End Region ' Methods
|
||||
|
||||
#Region "COMMANDS"
|
||||
@@ -760,7 +608,6 @@ Public Class ScriptWindowVM
|
||||
|
||||
#End Region ' TextColorCmd
|
||||
|
||||
|
||||
#End Region ' Commands
|
||||
|
||||
End Class
|
||||
|
||||
Reference in New Issue
Block a user