Imports EgtUILib Imports EgtWPFLib5 Imports System.IO Imports System.Runtime.CompilerServices Imports System.Text Public Class ScriptWindowVM Inherits VMBase #Region "FIELD & PROPERTIES" Friend m_bTextHasChanged As Boolean = False Private m_sNameFile As String = String.Empty Public Property sNameFile As String Get Return m_sNameFile End Get Set(value As String) m_sNameFile = value NotifyPropertyChanged(NameOf(sNameFile)) End Set End Property Private m_sRichTextParagraph As String = String.Empty Public Property sRichTextParagraph As String Get Return m_sRichTextParagraph End Get Set(value As String) m_sRichTextParagraph = value NotifyPropertyChanged(NameOf(sRichTextParagraph)) End Set End Property Private m_nFontSizeList As New List(Of Integer) Public Property FontSizeList As List(Of Integer) Get Return m_nFontSizeList End Get Set(value As List(Of Integer)) m_nFontSizeList = value NotifyPropertyChanged(NameOf(FontSizeList)) End Set End Property Private m_nSelFontSize As Integer Public Property SelFontSize As Integer Get Return m_nSelFontSize End Get Set(value As Integer) m_nSelFontSize = value If Not IsNothing(m_nSelFontSize) Then ChangeFontSize(m_nSelFontSize) NotifyPropertyChanged(NameOf(SelFontSize)) End Set End Property Friend Sub SetSelFontSize(value As Integer) m_nSelFontSize = value NotifyPropertyChanged(NameOf(SelFontSize)) End Sub Private m_sFontFamilyList As New List(Of FontFamily) Public Property FontFamilyList As List(Of FontFamily) Get Return m_sFontFamilyList End Get Set(value As List(Of FontFamily)) m_sFontFamilyList = value NotifyPropertyChanged(NameOf(FontFamilyList)) End Set End Property Private m_sSelFontFamily As FontFamily Public Property SelFontFamily As FontFamily Get Return m_sSelFontFamily End Get Set(value As FontFamily) m_sSelFontFamily = value If Not IsNothing(m_sSelFontFamily) Then ChangeFontFamily(m_sSelFontFamily) NotifyPropertyChanged(NameOf(SelFontFamily)) End Set End Property Friend Sub SetSelFontFamily(value As FontFamily) m_sSelFontFamily = value NotifyPropertyChanged(NameOf(SelFontFamily)) End Sub Private m_bBoldIsChecked As Boolean = False Public Property BoldIsChecked As Boolean Get Return m_bBoldIsChecked End Get Set(value As Boolean) m_bBoldIsChecked = value NotifyPropertyChanged(NameOf(BoldIsChecked)) End Set End Property Private m_bItalicIsChecked As Boolean = False Public Property ItalicIsChecked As Boolean Get Return m_bItalicIsChecked End Get Set(value As Boolean) m_bItalicIsChecked = value NotifyPropertyChanged(NameOf(ItalicIsChecked)) End Set End Property Private m_bUnderlineChecked As Boolean = False Public Property UnderlineChecked As Boolean Get Return m_bUnderlineChecked End Get Set(value As Boolean) m_bUnderlineChecked = value NotifyPropertyChanged(NameOf(UnderlineChecked)) End Set End Property Private m_bLeftIsChecked As Boolean = False Public Property LeftIsChecked As Boolean Get Return m_bLeftIsChecked End Get Set(value As Boolean) m_bLeftIsChecked = value SetCenterIsChecked(False) SetJustifyIsChecked(False) NotifyPropertyChanged(NameOf(LeftIsChecked)) End Set End Property Friend Sub SetLeftIsChecked(value As Boolean) m_bLeftIsChecked = value NotifyPropertyChanged(NameOf(LeftIsChecked)) End Sub Private m_bCenterIsChecked As Boolean = False Public Property CenterIsChecked As Boolean Get Return m_bCenterIsChecked End Get Set(value As Boolean) m_bCenterIsChecked = value SetLeftIsChecked(False) SetJustifyIsChecked(False) NotifyPropertyChanged(NameOf(CenterIsChecked)) End Set End Property Friend Sub SetCenterIsChecked(value As Boolean) m_bCenterIsChecked = value NotifyPropertyChanged(NameOf(CenterIsChecked)) End Sub Private m_bJustifyIsChecked As Boolean = False Public Property JustifyIsChecked As Boolean Get Return m_bJustifyIsChecked End Get Set(value As Boolean) m_bJustifyIsChecked = value SetLeftIsChecked(False) SetCenterIsChecked(False) NotifyPropertyChanged(NameOf(JustifyIsChecked)) End Set End Property Friend Sub SetJustifyIsChecked(value As Boolean) m_bJustifyIsChecked = value NotifyPropertyChanged(NameOf(JustifyIsChecked)) End Sub Private m_FileAlignLeftSVG As String = String.Empty Public Property FileAlignLeftSVG As String Get Return m_FileAlignLeftSVG End Get Set(value As String) m_FileAlignLeftSVG = value NotifyPropertyChanged(NameOf(FileAlignLeftSVG)) End Set End Property Friend Sub SetFileAlignLeftSVG(sFileAlignLeftSVG As String) m_FileAlignLeftSVG = sFileAlignLeftSVG NotifyPropertyChanged(NameOf(FileAlignLeftSVG)) End Sub Private m_FileAlignCenterSVG As String = String.Empty Public Property FileAlignCenterSVG As String Get Return m_FileAlignCenterSVG End Get Set(value As String) m_FileAlignCenterSVG = value NotifyPropertyChanged(NameOf(FileAlignCenterSVG)) End Set End Property Friend Sub SetFileAlignCenterSVG(sFileAlignCenterSVG As String) m_FileAlignCenterSVG = sFileAlignCenterSVG NotifyPropertyChanged(NameOf(FileAlignCenterSVG)) End Sub Private m_FileAlignJustifySVG As String = String.Empty Public Property FileAlignJustifySVG As String Get Return m_FileAlignJustifySVG End Get Set(value As String) m_FileAlignJustifySVG = value NotifyPropertyChanged(NameOf(FileAlignJustifySVG)) End Set End Property Friend Sub SetFileAlignJustifySVG(sFileAlignJustifySVG As String) m_FileAlignJustifySVG = sFileAlignJustifySVG NotifyPropertyChanged(NameOf(FileAlignJustifySVG)) End Sub #Region "Messages" Public ReadOnly Property Title As String Get Return "Script File" ' Opzioni End Get End Property Public ReadOnly Property Conferma_Msg As String Get Return EgtMsg(110003) ' Conferma End Get End Property Public ReadOnly Property Salva_Msg As String Get Return EgtMsg(110013) ' Salva End Get End Property Public ReadOnly Property Annulla_Msg As String Get Return EgtMsg(110004) ' Annulla End Get End Property #End Region ' Messages ' Definizione Comandi Private m_ConfermaCmd As ICommand Private m_cmdSaveAs As ICommand Private m_cmdAnnulla As ICommand Private m_cmdTextColor As ICommand #End Region ' Fields & Properties #Region "CONSTRUCTOR" Sub New() Map.SetRefScriptWindowVM(Me) If m_nFontSizeList.Count <= 0 Then CreateFontSizeList() If m_sFontFamilyList.Count <= 0 Then CreateFontFamilyList() SetToolbar() SetFileAlignLeftSVG(Map.refMainWindowVM.MainWindowM.sResourcesDir & "\alignleft.svg") SetFileAlignCenterSVG(Map.refMainWindowVM.MainWindowM.sResourcesDir & "\aligncenter.svg") SetFileAlignJustifySVG(Map.refMainWindowVM.MainWindowM.sResourcesDir & "\alignjustify.svg") End Sub #End Region ' Constructor #Region "METHODS" Public Function SaveProject() As Boolean Dim sFile As String = "" Dim sFileName As String = "" ' Se nome vuoto, assegno "New" If String.IsNullOrWhiteSpace(m_sNameFile) Then sFile = "New.lua" Else sFile = m_sNameFile & ".lua" End If ' Eventuale sistemazione estensione sFile = IO.Path.ChangeExtension(sFile, "lua") ' Assegnazione nome file con dialogo Dim SaveFileDialog As New EgtManageFileDialogV(Application.Current.MainWindow, New EgtManageFileDialogVM()) With { .Title = EgtMsg(110013), ' Salva .Filter = "lua files (*.lua)|*.lua", .FileName = sFile, .FilterIndex = 1, .InitialDirectory = Map.refMainWindowVM.MainWindowM.sTempDir, .ValidateNames = False, .OverwritePrompt = True, .Mode = 1 } If SaveFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then If Path.GetExtension(SaveFileDialog.SafeFileName).Equals(String.Empty) Then sFileName = SaveFileDialog.InitialDirectory & "\" & SaveFileDialog.SafeFileName & SaveFileDialog.SelFilter.sExstension.Trim("*"c) Else sFileName = SaveFileDialog.InitialDirectory & "\" & SaveFileDialog.SafeFileName End If End If Dim bOk = Map.refSceneHostVM.SaveProj(sFileName) File.WriteAllText(sFileName, m_sRichTextParagraph) ' Imposto stato gestione mouse diretto della scena a nessuno Map.refSceneHostVM.MainScene.SetStatusNull() Return True End Function Private Sub SaveScript(sPathFileScript As String, sRichTextParagraph As String) Map.refSceneHostVM.SaveProj(sPathFileScript) File.WriteAllText(sPathFileScript, sRichTextParagraph, Encoding.UTF8) End Sub Public Function RichTextBox(sPathFileScript As String) As String ' Recupero richtextbox Dim myRichTextBox As RichTextBox = Map.refScriptWindowV.sNameFile_RichTxBx ' Recupero flowdocument Dim myFlowDoc As FlowDocument = Map.refScriptWindowV.FDocumentFile ' Assegno al richtextbox il flowdocument myRichTextBox.Document = myFlowDoc ' Leggo il richtextbox dall'inizio alla fine Dim textRange As New TextRange(myRichTextBox.Document.ContentStart, myRichTextBox.Document.ContentEnd) Return textRange.Text End Function Private Sub CreateFontSizeList() For Size As Integer = 8 To 20 If Size Mod 2 = 0 Then m_nFontSizeList.Add(Size) End If Next End Sub ''' ''' Funzione che permette di cambiare la dimensione della font ''' ''' fontsize selezionata Private Sub ChangeFontSize(nSelFontSize As Integer) If nSelFontSize = GDB_ID.NULL Then Return Dim pixelSize As Double = Convert.ToDouble(nSelFontSize) * (96 / 72) Dim textRange = New TextRange(Map.refScriptWindowV.sNameFile_RichTxBx.Selection.Start, Map.refScriptWindowV.sNameFile_RichTxBx.Selection.[End]) textRange.ApplyPropertyValue(TextElement.FontSizeProperty, pixelSize) End Sub Private Sub CreateFontFamilyList() For Each FontFamily As FontFamily In Fonts.SystemFontFamilies m_sFontFamilyList.Add(FontFamily) Next End Sub Private Sub ChangeFontFamily(sSelFontFamily As FontFamily) If sSelFontFamily Is Nothing Then Return Dim fontFamily As String = sSelFontFamily.ToString() Dim textRange = New TextRange(Map.refScriptWindowV.sNameFile_RichTxBx.Selection.Start, Map.refScriptWindowV.sNameFile_RichTxBx.Selection.[End]) textRange.ApplyPropertyValue(TextElement.FontFamilyProperty, fontFamily) End Sub Friend Sub SetToolbar() Dim textRange = New TextRange(Map.refScriptWindowV.sNameFile_RichTxBx.Selection.Start, Map.refScriptWindowV.sNameFile_RichTxBx.Selection.[End]) Dim fontFamily As Object = textRange.GetPropertyValue(TextElement.FontFamilyProperty) SetSelFontFamily(fontFamily) Dim fontSize As Object = textRange.GetPropertyValue(TextElement.FontSizeProperty) SetSelFontSize(fontSize) If Not String.IsNullOrEmpty(textRange.Text) Then m_bBoldIsChecked = textRange.GetPropertyValue(TextElement.FontWeightProperty).Equals(FontWeights.Bold) m_bItalicIsChecked = textRange.GetPropertyValue(TextElement.FontStyleProperty).Equals(FontStyles.Italic) m_bUnderlineChecked = textRange.GetPropertyValue(Inline.TextDecorationsProperty).Equals(TextDecorations.Underline) End If m_bLeftIsChecked = textRange.GetPropertyValue(FlowDocument.TextAlignmentProperty).Equals(TextAlignment.Left) m_bCenterIsChecked = textRange.GetPropertyValue(FlowDocument.TextAlignmentProperty).Equals(TextAlignment.Center) m_bJustifyIsChecked = textRange.GetPropertyValue(FlowDocument.TextAlignmentProperty).Equals(TextAlignment.Justify) End Sub Public Sub InsertText(ByVal sRichTextBox As RichTextBox, ByVal content As String) If Not String.IsNullOrEmpty(content) Then sRichTextBox?.BeginChange() If Not String.IsNullOrEmpty(sRichTextBox.Selection.Text) Then sRichTextBox.Selection.Text = String.Empty End If Dim textPointer As TextPointer = sRichTextBox.CaretPosition.GetPositionAtOffset(0, LogicalDirection.Forward) sRichTextBox.CaretPosition.InsertTextInRun(content) sRichTextBox.CaretPosition = textPointer sRichTextBox.EndChange() Keyboard.Focus(sRichTextBox) 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 If Not IsNothing(Map.refScriptWindowVM) Then 'If sNameRichTxBx.Text.Contains("local") Or sNameRichTxBx.Text.Contains("require") Then ' Map.refScriptWindowVM.TextSearchAndColor(sNameFile_RichTxBx, "local", Brushes.Blue, FontWeights.Bold, FontStyles.Italic, 16) ' Map.refScriptWindowVM.TextSearchAndColor(sNameFile_RichTxBx, "require", Brushes.Green, FontWeights.Normal, FontStyles.Normal, 12) 'End If 'If sNameRichTxBxList.Contains("--") AndAlso sNameRichTxBx.Text.StartsWith("--") Then ' Map.refScriptWindowVM.TextSearchAndColor(sNameFile_RichTxBx, sNameRichTxBx.Text, Brushes.Yellow, FontWeights.Normal, FontStyles.Normal, 12) 'End If 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 If End Sub #End Region ' Methods #Region "COMMANDS" #Region "ConfermCmd" Public ReadOnly Property ConfermaCmd As ICommand Get If m_ConfermaCmd Is Nothing Then m_ConfermaCmd = New Command(AddressOf Conferma) End If Return m_ConfermaCmd End Get End Property Public Sub Conferma() ' Recupero il file script Dim sFileScript As String = RichTextBox(Map.refMainWindowVM.MainWindowM.sTempDir & "\" & "m_sNameFile" & ".lua") ' Salvo il file SaveScript(Map.refMainWindowVM.MainWindowM.sTempDir & "\" & m_sNameFile & ".lua", sFileScript) ' Eseguo il file EgtLuaExecFile(Map.refMainWindowVM.MainWindowM.sTempDir & "\" & m_sNameFile & ".lua") ' Imposto stato gestione mouse diretto della scena a nessuno Map.refSceneHostVM.MainScene.SetStatusNull() End Sub #End Region ' ConfermaCmd #Region "SaveAsCommand" Public ReadOnly Property SalvaCmd As ICommand Get If m_cmdSaveAs Is Nothing Then m_cmdSaveAs = New Command(AddressOf SaveAs) End If Return m_cmdSaveAs End Get End Property Public Sub SaveAs() SaveProject() End Sub #End Region ' SaveAsCommand #Region "AnnullaCmd" Public ReadOnly Property AnnullaCmd As ICommand Get If m_cmdAnnulla Is Nothing Then m_cmdAnnulla = New Command(AddressOf Annulla) End If Return m_cmdAnnulla End Get End Property Public Sub Annulla() Map.refScriptWindowV.Close() End Sub #End Region ' AnnullaCmd #Region "TextColorCmd" Public ReadOnly Property TextColorCmd As ICommand Get If m_cmdTextColor Is Nothing Then m_cmdTextColor = New Command(AddressOf TextColor) End If Return m_cmdTextColor End Get End Property Public Sub TextColor() ' Recupero colori custom Dim Col As New Color3d(10, 122, 150) Dim sCustomColors As String = "" GetMainPrivateProfileString(S_COLORS, K_CUSTOMCOLORS, "", sCustomColors) Dim CustomColors() As String = sCustomColors.Split(","c) Dim nCustomColors As New List(Of Integer) For Each Color In CustomColors Dim nColor As Integer If Integer.TryParse(Color, nColor) Then nCustomColors.Add(nColor) End If Next ' Creo dialogo colori Dim ColorDlg As New EgtColorPickerV(Application.Current.MainWindow, New EgtColorPickerVM()) With { .CustomColors = nCustomColors.ToArray(), .Color = Col.ToColor() } ' Visualizzo dialogo If ColorDlg.ShowDialog() <> Windows.Forms.DialogResult.OK Then Return 'Recupero colore scelto Dim selColor As New SolidColorBrush(System.Windows.Media.Color.FromArgb(CByte(ColorDlg.Color.A), CByte(ColorDlg.Color.R), CByte(ColorDlg.Color.G), CByte(ColorDlg.Color.B))) Dim textRange = New TextRange(Map.refScriptWindowV.sNameFile_RichTxBx.Selection.Start, Map.refScriptWindowV.sNameFile_RichTxBx.Selection.[End]) textRange.ApplyPropertyValue(TextElement.ForegroundProperty, selColor) End Sub #End Region ' TextColorCmd #End Region ' Commands End Class