Imports System.Text.RegularExpressions
Public Class Form1
Private Enum ListContentType
Tags
Attributes
End Enum
'Costanti usate per lo scrolling
Private Const HorizontalScrolling = &H114
Private Const VerticalScrolling = &H115
Private Const HorizontalScrollBar = 0
Private Const VerticalScrollBar = 1
Private Const ThumbPosition = 4
Private TextModified As Boolean = False
'Ultimo path di salvataggio del file
Private LastSavingPath As String
'Parola da cercare per la funzione Trova
Private WordToSeek As String
'Ultimo indice verificato per tale parola
Private LastValidIndex As Int32
'Tipo di contenuto della lista
Private ContentType As ListContentType
Private rtbSupport As New HTML_IntelliSense.HtmlTextBox
Private FirstLine, LastLine As Int32
#Region "Platform Invoke"
<System.Runtime.InteropServices.DllImport("user32.dll", CharSet:=Runtime.InteropServices.CharSet.Auto, EntryPoint:="SendMessage")> _
Private Shared Function SendMessage(ByVal Handle As IntPtr, ByVal Message As UInt32, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
End Function
<System.Runtime.InteropServices.DllImport("user32.dll")> _
Private Shared Function GetScrollPos(ByVal Handle As IntPtr, ByVal Bar As Int32) As Int32
End Function
#End Region
#Region "Metodi addizionali"
Private Sub AddItemsToList(ByVal List As List(Of String), ByVal StartString As String)
lstSuggest.Items.Clear()
For Each ATag As String In List
If ATag.ToLower.StartsWith(StartString.ToLower) Then
lstSuggest.Items.Add(ATag)
End If
Next
lstSuggest.Tag = StartString
End Sub
Private Sub ShowListAtCursor()
Dim P As Point = rtbCode.GetPositionFromCharIndex(rtbCode.SelectionStart)
lstSuggest.Location = New Point(P.X + 8, P.Y + 48)
lstSuggest.Visible = True
Me.Refresh()
End Sub
Private Sub InsertText(ByVal Str As String)
If String.IsNullOrEmpty(Str) Then
Exit Sub
End If
If rtbCode.SyntaxHighlightingEnabled Then
rtbCode.UpdateRtfLines()
rtbSupport = rtbCode.Clone
Dim Line As String
Dim PrevRtf() As String = rtbCode.RtfLines
Dim RtfLineIndex As Int32 = rtbCode.RtfCurrentLineIndex
Dim PrevPos As Int32 = GetScrollPos(rtbCode.Handle, VerticalScrollBar)
If rtbCode.Lines.Length = 0 Then
Line = Str
Else
Line = rtbCode.Lines(rtbCode.CurrentLineIndex).Insert(rtbCode.SelectionStart - rtbCode.GetFirstCharIndexOfCurrentLine, Str)
End If
rtbSupport.Text = Line
rtbSupport.ColorRtb()
Dim RtfBuilder As New System.Text.StringBuilder
rtbSupport.UpdateRtfLines()
For I As Int32 = 2 To rtbSupport.RtfLines.Length - 1
If rtbSupport.RtfLines(I).EndsWith("}") Then
Exit For
End If
RtfBuilder.Append(rtbSupport.RtfLines(I))
Next
Line = RtfBuilder.ToString
RtfBuilder.Remove(0, RtfBuilder.Length)
For I As Int32 = 0 To PrevRtf.Length - 1
If I = RtfLineIndex Then
RtfBuilder.AppendLine(Line)
Else
RtfBuilder.AppendLine(PrevRtf(I))
End If
Next
rtbCode.Rtf = RtfBuilder.ToString
SendMessage(rtbCode.Handle, VerticalScrolling, 4 + &H10000 * PrevPos, 0)
Else
rtbCode.SelectedText = Str
End If
End Sub
Private Sub AppendTextAtCursor(ByVal Str As String)
Dim Sel As Int32 = rtbCode.SelectionStart
InsertText(Str)
rtbCode.SelectionStart = Sel + Str.Length
lstSuggest.Tag = Str
End Sub
Private Sub CompleteTag(ByVal Tag As HtmlTag)
Dim Sel As Int32 = rtbCode.SelectionStart
Dim LineIndex As Int32 = rtbCode.GetLineFromCharIndex(rtbCode.SelectionStart)
If Not Tag.CanClose Then
'rtbCode.Text = rtbCode.Text.Insert(rtbCode.SelectionStart, ">")
InsertText(">")
rtbCode.ColorLineNumber(LineIndex)
rtbCode.SelectionStart = Sel + 1
Exit Sub
End If
If Tag.ThreeLinesDeclaration Then
Dim Spaces As String = ""
If LineIndex >= 0 Then
Dim PrevLine As String = rtbCode.Lines(LineIndex)
Dim Indent As New Regex("^(?<Indent>\s+)", RegexOptions.Multiline)
Dim M As Match = Indent.Match(PrevLine)
If M.Success Then
Spaces = M.Groups("Indent").Value
End If
End If
'rtbCode.Text = rtbCode.Text.Insert(rtbCode.SelectionStart, _
'">" & vbCrLf & Spaces & " " & vbCrLf & Spaces & "</" & Tag.Name & ">")
InsertText(">" & vbCrLf & Spaces & " " & vbCrLf & Spaces & "</" & Tag.Name & ">")
rtbCode.SelectionStart = Sel + (Spaces.Length + 4)
rtbCode.ColorLineNumber(LineIndex)
rtbCode.ColorLineNumber(LineIndex + 2)
Else
InsertText("></" & Tag.Name & ">")
rtbCode.ColorLineNumber(LineIndex)
rtbCode.SelectionStart = Sel + 1
End If
lstSuggest.Tag = ""
End Sub
Private Sub RefreshTemplates()
strTemplates.DropDownItems.Clear()
For Each TemplateFile As String In IO.Directory.GetFiles(Application.StartupPath & "\Templates", "*.hist")
Dim T As New ToolStripMenuItem
T.Text = IO.Path.GetFileNameWithoutExtension(TemplateFile)
AddHandler T.Click, AddressOf strTemplatesChild_Click
strTemplates.DropDownItems.Add(T)
Next
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
My.Application.SaveMySettingsOnExit = True
AddHandler My.Application.UnhandledException, AddressOf ExceptionHandler
If Not IO.
File.
Exists(Application.
StartupPath & "\Tags.dat") Then
MessageBox.Show("Il file contente i dati sui tag html non è presente nella directory del programma. Contattare lo sviluppatore per ottenerne uno nuovo!", Me.Text)
Else
Dim Reader As New IO.StreamReader(Application.StartupPath & "\Tags.dat")
Dim Line, Data() As String
While Not Reader.EndOfStream
Line = Reader.ReadLine
If String.IsNullOrEmpty(Line) Then
Continue While
End If
Data = Line.Split("|")
Dim T As New HtmlTag()
T.Name = Data(0)
If Data.Length > 3 Then
For I As Int16 = 1 To Data.Length - 3
T.Attributes.Add(Data(I))
Next
End If
T.CanClose = CBool(Data(Data.Length - 2))
T.ThreeLinesDeclaration = CBool(Data(Data.Length - 1))
Tags.Add(T.Name, T)
TagNames.Add(T.Name)
End While
Reader.Close()
End If
If Not IO.Directory.Exists(Application.StartupPath & "\Templates") Then
IO.Directory.CreateDirectory(Application.StartupPath & "\Templates")
End If
RefreshTemplates()
My.Application.SaveMySettingsOnExit = True
End Sub
Private Sub rtbCode_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rtbCode.HtmlChanged
TextModified = True
If rtbCode.SelectionStart > 0 And My.Settings.ISEnabled Then
Dim Start As Int32 = rtbCode.SelectionStart
'Trova il < d'inizio.
Dim OpeningTag As Int32 = rtbCode.Text.LastIndexOf("<", Start - 1, Start)
'Se c'è, controlla che sia di questo tag
If OpeningTag = -1 Then
Exit Sub
End If
'Trova il primo > prima del cursore
Dim PrevEndingTag As Int32 = rtbCode.Text.LastIndexOf(">", Start - 1, Start)
'Se esiste, controlla che sia precedente al <
If (PrevEndingTag >= 0) AndAlso (PrevEndingTag > OpeningTag) Then
'Il < trovato in realtà era di un altro tag già chiuso
Exit Sub
End If
'Controlla se il tag è chiuso
Dim EndingTag As Int32 = rtbCode.Text.IndexOf(">", Start)
Dim SuccOpeningTag As Int32 = rtbCode.Text.IndexOf("<", Start)
Dim IsClosed As Boolean = (EndingTag >= 0) And (EndingTag < SuccOpeningTag)
'Localizza il tag
Dim Tag As String
If Not IsClosed Then
If SuccOpeningTag >= 0 Then
'Situazione:
'<a href="ciao" <div> ...
Tag = rtbCode.Text.Substring(OpeningTag, SuccOpeningTag - OpeningTag + 1)
Else
'Situazione:
'<a href="ciao" [Fine file]
Tag = rtbCode.Text.Substring(OpeningTag)
End If
Else
'Situazione
'<a href="ciao"> ...
Tag = rtbCode.Text.Substring(OpeningTag, EndingTag - OpeningTag + 1)
End If
lblStatus.Text = Tag
If Tag.Length < 2 Then
'E' presente solo <: mostra tutti i tag disponibili
Me.AddItemsToList(TagNames, "")
Me.ContentType = ListContentType.Tags
Me.ShowListAtCursor()
Exit Sub
End If
'La porzione di stringa compresa tra l'inizio del tag e la posizione corrente
Dim Str As String = rtbCode.Text.Substring(OpeningTag, Start - OpeningTag)
If Not Str.Contains(" ") Then
'Se Str non contiene spazi, è una sola parola. Quindi del tipo:
'<abcdefgh oppure </abcdef
'e perciò è l'inizio di un tag. Ora suggerisce una lista di tutti i
'tag che iniziano in quel modo
'Si tratta di un tag di chiusura: cancella il </ iniziale
If Str.StartsWith("</") Then
Str = Str.Remove(0, 2)
Else
'Cancella il < iniziale
Str = Str.Remove(0, 1)
End If
'Str è il nome parziale del tag
Me.AddItemsToList(TagNames, Str)
Me.ContentType = ListContentType.Tags
If lstSuggest.Items.Count > 0 Then
Me.ShowListAtCursor()
End If
Else
'Riduce il controllo al solo tag in modo che sia più facile
'da analizzare
Dim TagCursor As Int32 = Start - OpeningTag - 1
Dim QuoteOpened As Boolean = False
For I As Int32 = 0 To Tag.Length - 1
If Tag(I) = Chr(34) Then
QuoteOpened = Not QuoteOpened
Tag = Tag.Insert(I, "|")
Tag = Tag.Remove(I + 1, 1)
End If
If QuoteOpened Then
Tag = Tag.Insert(I, "|")
Tag = Tag.Remove(I + 1, 1)
End If
Next
'Quindi, se all'indice corrente c'è un pipe, significa che il cursore
'è dentro una stringa
If Tag(TagCursor) = "|" Then
'Nasconde la lista
lstSuggest.Visible = False
Else
'Ottiene la parola che si sta scrivendo
Dim PrevSpace As Int32 = Tag.LastIndexOf(" ", TagCursor, TagCursor + 1)
Dim TagName, PartialAttrName As String
'Trova il nome del tag, togliendo il < iniziale e lo spazio finale
TagName = Tag.Substring(0, Tag.IndexOf(" ")).Remove(0, 1)
PartialAttrName = Tag.Substring(PrevSpace + 1, TagCursor - PrevSpace)
'Ottiene solo gli attributi che iniziano con la stringa data
If TagNames.Contains(TagName) Then
Me.AddItemsToList(Tags(TagName).Attributes, PartialAttrName)
Me.ContentType = ListContentType.Attributes
If (lstSuggest.Items.Count = 1) AndAlso (TagName = lstSuggest.Items(0)) Then
lstSuggest.Visible = False
Else
Me.ShowListAtCursor()
End If
Else
lstSuggest.Visible = False
End If
End If
End If
rtbCode.SelectionStart = Start
lstSuggest.Visible = (lstSuggest.Items.Count > 0)
End If
End Sub
Private Sub rtbCode_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles rtbCode.KeyPress
If (e.KeyChar = ">" Or e.KeyChar = vbCr) And My.Settings.ISEnabled Then
If e.KeyChar = ">" Then
Dim OpeningTag As Int32 = rtbCode.Text.LastIndexOf("<", rtbCode.SelectionStart, rtbCode.SelectionStart + 1)
Try
If rtbCode.Text(OpeningTag + 1) = "/" Then
lstSuggest.Visible = False
Exit Sub
End If
If lstSuggest.Visible And lstSuggest.Items.Count > 0 Then
Dim TagName As String = lstSuggest.Items(0)
Dim Str As String = TagName.Remove(0, lstSuggest.Tag.ToString.Length)
Me.AppendTextAtCursor(Str)
Me.CompleteTag(Globals.Tags(TagName))
lstSuggest.Visible = False
e.Handled = True
'rtbCode.ColorVisibleLines()
Exit Sub
End If
Catch Ex As Exception
End Try
Try
Dim Str As String = rtbCode.Text.Substring(OpeningTag, rtbCode.SelectionStart - OpeningTag)
Dim TagName As String
If Not Str.Contains(" ") Then
TagName = rtbCode.Text.Substring(OpeningTag + 1, rtbCode.SelectionStart - OpeningTag - 1)
Else
TagName = rtbCode.Text.Substring(OpeningTag + 1, rtbCode.Text.IndexOf(" ", OpeningTag) - OpeningTag - 1)
End If
Me.CompleteTag(Globals.Tags(TagName))
lstSuggest.Visible = False
e.Handled = True
'rtbCode.ColorVisibleLines()
Catch Ex As Exception
End Try
End If
If e.KeyChar = vbCr Then
Dim LineIndex As Int32 = rtbCode.GetLineFromCharIndex(rtbCode.SelectionStart)
Dim PrevLine As String = rtbCode.Lines(LineIndex - 1)
Dim Indent As New Regex("^(?<Indent>\s+)", RegexOptions.Multiline)
Dim M As Match = Indent.Match(PrevLine)
If M.Success Then
rtbCode.HtmlChangedEnabled = False
Me.AppendTextAtCursor(M.Groups("Indent").Value)
rtbCode.HtmlChangedEnabled = True
End If
e.Handled = True
'rtbCode.ColorVisibleLines()
End If
lstSuggest.Visible = False
End If
End Sub
Private Sub lstSuggest_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstSuggest.DoubleClick
'Aggiunge la parte di parola mancante
If lstSuggest.SelectedIndex >= 0 Then
Try
Dim Str As String = CStr(lstSuggest.SelectedItem).Remove(0, lstSuggest.Tag.ToString.Length)
Me.AppendTextAtCursor(Str)
lstSuggest.Tag = ""
Catch Ex As Exception
End Try
End If
End Sub
Private Sub rtbCode_PreviewKeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs) Handles rtbCode.PreviewKeyDown
If e.KeyCode = Keys.Space Then
If lstSuggest.Visible And lstSuggest.Items.Count > 0 Then
Dim Str As String = CStr(lstSuggest.Items(0)).Remove(0, lstSuggest.Tag.ToString.Length)
Me.AppendTextAtCursor(Str)
End If
ElseIf (e.Shift And e.KeyCode = Keys.D0) Then
If lstSuggest.Visible And lstSuggest.Items.Count > 0 And Me.ContentType = ListContentType.Attributes Then
Dim Str As String = CStr(lstSuggest.Items(0)).Remove(0, lstSuggest.Tag.ToString.Length)
Me.AppendTextAtCursor(Str)
End If
ElseIf (e.Alt And e.KeyCode = Keys.Oemplus) Then
If lstSuggest.Visible And lstSuggest.Items.Count > 0 And Me.ContentType = ListContentType.Attributes AndAlso _
lstSuggest.Items(0).ToString.StartsWith("[") Then
Dim Str As String = CStr(lstSuggest.Items(0)).Remove(0, lstSuggest.Tag.ToString.Length)
Me.AppendTextAtCursor(Str.Replace("]", ""))
End If
ElseIf e.KeyCode = Keys.Down Then
If lstSuggest.Visible Then
lstSuggest.SelectedIndex = 0
lstSuggest.Focus()
End If
End If
End Sub
Private Sub strOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strOpen.Click
If TextModified Then
If MessageBox.Show("Salvare le modifiche apportate al codice prima di aprirne un altro?", Me.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
strSave_Click(Me, EventArgs.Empty)
TextModified = False
End If
End If
Dim Open As New OpenFileDialog
Open.Filter = "Pagine web|*.htm;*.html;*.php"
If Open.ShowDialog = Windows.Forms.DialogResult.OK Then
rtbCode.
Text = IO.
File.
ReadAllText(Open.
FileName)
strHighlightAll_Click(Me, EventArgs.Empty)
End If
End Sub
Private Sub strSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strSave.Click
If String.IsNullOrEmpty(LastSavingPath) Then
Dim Save As New SaveFileDialog
Save.Filter = "Pagine web|*.htm;*.html|Pagina PHP|*.php"
If Save.ShowDialog = Windows.Forms.DialogResult.OK Then
IO.
File.
WriteAllText(Save.
FileName, rtbCode.
Text)
LastSavingPath = Save.FileName
lblStatus.Text = "File salvato con successo"
TextModified = False
End If
Else
IO.
File.
WriteAllText(LastSavingPath, rtbCode.
Text)
lblStatus.Text = "File salvato con successo"
TextModified = False
End If
End Sub
Private Sub strSaveAs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strSaveAs.Click
'Annulla la stringa, e richiama l'altra funzione, risparmiando spazio
LastSavingPath = Nothing
strSave_Click(Me, EventArgs.Empty)
End Sub
Private Sub strExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strExit.Click
If TextModified Then
If MessageBox.Show("Salvare le modifiche apportate al sorgente prima di uscire?", Me.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
strSave_Click(Me, EventArgs.Empty)
End If
End If
Me.Close()
End Sub
Private Sub strFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strFind.Click
Dim Word As String = InputBox("Immettere la stringa da cercare:", Me.Text)
If String.IsNullOrEmpty(Word) Then
Exit Sub
End If
If Word.Length < 2 Then
MessageBox.Show("Inserire una stringa di almeno due caratteri!", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
Dim Index As Int32
Index = rtbCode.Find(Word)
If Index > -1 Then
WordToSeek = Word
LastValidIndex = Index
rtbCode.Select(Index, Word.Length)
rtbCode.ScrollToCaret()
lblStatus.Text = "Trovata istanza di """ & Word & """ alla posizione " & Index
End If
End Sub
Private Sub strFindNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strFindNext.Click
If Not String.IsNullOrEmpty(WordToSeek) Then
Dim Index As Int32
If LastValidIndex < rtbCode.TextLength - 1 Then
Index = rtbCode.Find(WordToSeek, LastValidIndex + 1, RichTextBoxFinds.None)
If Index > -1 Then
LastValidIndex = Index
rtbCode.Select(Index, WordToSeek.Length)
rtbCode.ScrollToCaret()
lblStatus.Text = "Trovata istanza di """ & WordToSeek & """ alla posizione " & Index
Else
MessageBox.Show("Nessun'altra occorenza di """ & WordToSeek & """ è stata trovata!", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
Else
MessageBox.Show("Nessun'altra occorenza di """ & WordToSeek & """ è stata trovata!", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End If
End Sub
Private Sub strReplace_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strReplace.Click
Dim Word As String = InputBox("Inserire la stringa da sotituire:", Me.Text)
Dim Replace As String = InputBox("Inserire la stringa sostituto:", Me.Text)
If (Not String.IsNullOrEmpty(Word)) And (Not String.IsNullOrEmpty(Replace)) Then
lblStatus.Text = "Attendere, sostituzione in corso..."
rtbCode.Enabled = False
Application.DoEvents()
rtbCode.Text = rtbCode.Text.Replace(Word, Replace)
Application.DoEvents()
rtbCode.Enabled = True
lblStatus.Text = "Sostituzione effettuata"
End If
End Sub
Private Sub strEnabled_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strEnabled.Click
My.Settings.ISEnabled = strEnabled.Checked
If strEnabled.Checked Then
strEnabled.Text = "Attivato"
Else
strEnabled.Text = "Disattivato"
End If
End Sub
Private Sub strAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strAbout.Click
My.Forms.The_Lair_AboutBox1.Show()
End Sub
Private Sub ExceptionHandler(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs)
MessageBox.Show(String.Format( _
"Si è verificata un'eccezione del tipo {0}. Il testo di tale eccezione è di seguito riportato: {1}{1}{2}{1}{1}Contattare lo sviluppatore per maggiori dettagli.", _
e.Exception.GetType.FullName, vbCrLf, e.Exception.Message), Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Sub
Private Sub lstSuggest_DrawItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles lstSuggest.DrawItem
'Rect rappresenta il rettangolo in cui è contenuto l'elemento
Dim Rect As Rectangle = e.Bounds
'Fnt rappresenta il font con cui l'elemento deve essere scritto
Dim Fnt As Font = e.Font
'Testo dell'elemento
Dim ItemText As String = lstSuggest.Items(e.Index)
'Immagine dell'elemento
Dim ItemImage As Image = Nothing
Select Case Me.ContentType
Case ListContentType.Tags
ItemImage = imgIcons.Images("tag")
Case ListContentType.Attributes
If ItemText.StartsWith("[") Then
ItemImage = imgIcons.Images("bool")
Else
ItemImage = imgIcons.Images("attribute")
End If
End Select
With e.Graphics
If e.State = DrawItemState.Selected Then
.FillRectangle(New SolidBrush(Color.FromArgb(255, 51, 94, 168)), e.Bounds.X + ItemImage.Width, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)
.DrawString(ItemText, Fnt, New SolidBrush(Color.White), e.Bounds.X + ItemImage.Width, e.Bounds.Y)
ElseIf e.State = DrawItemState.None Then
.FillRectangle(New SolidBrush(Color.White), e.Bounds.X, e.Bounds.Y, e.Bounds.Width + ItemImage.Width, e.Bounds.Height)
.DrawString(ItemText, Fnt, New SolidBrush(Color.Black), e.Bounds.X + ItemImage.Width, e.Bounds.Y)
End If
.FillRectangle(Brushes.White, e.Bounds.X, e.Bounds.Y, ItemImage.Width, ItemImage.Height + 1)
.DrawImage(ItemImage, e.Bounds.X, e.Bounds.Y)
End With
End Sub
Private Sub strISOption_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strISOption.Click
My.Forms.ISOption.ShowDialog()
End Sub
Private Sub rtbCode_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rtbCode.SelectionChanged
If rtbCode.IsBusy Then
Exit Sub
End If
Dim LineIndex As Int32 = rtbCode.CurrentLineIndex
Dim ColIndex As Int32 = rtbCode.SelectionStart - rtbCode.GetFirstCharIndexOfCurrentLine
lblPosition.Text = "Posizione cursore: " & (LineIndex + 1) & ", " & (ColIndex + 1)
If (rtbCode.SelectionStart <= 0) Or (lstSuggest.Visible = False) Then
lstSuggest.Visible = False
Exit Sub
End If
Dim StartTag As Int32 = rtbCode.Text.LastIndexOf("<", rtbCode.SelectionStart)
Dim CloseTag As Int32 = rtbCode.Text.LastIndexOf(">", rtbCode.SelectionStart)
If (StartTag < CloseTag) Or StartTag = -1 Then
lstSuggest.Visible = False
End If
End Sub
Private Sub strSHEnabled_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strSHEnabled.CheckedChanged
If strSHEnabled.Checked Then
rtbCode.SyntaxHighlightingEnabled = True
rtbCode.ColorVisibleLines()
Else
rtbCode.SyntaxHighlightingEnabled = False
rtbCode.SelectAll()
rtbCode.SelectionColor = Color.Black
rtbCode.SelectionFont = rtbCode.Font
rtbCode.DeselectAll()
End If
End Sub
Private Sub strSHOptions_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strSHOptions.Click
My.Forms.SHOption.ShowDialog()
If My.Forms.SHOption.ColorAll Then
strHighlightAll_Click(Me, EventArgs.Empty)
Else
rtbCode.ColorVisibleLines()
End If
End Sub
Private Sub strHighlightAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strHighlightAll.Click
lblStatus.Text = "Colorazione in corso..."
Application.DoEvents()
rtbCode.ColorRtb()
Application.DoEvents()
lblStatus.Text = "Colorazione completata!"
End Sub
Private Sub strCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strCopy.Click
rtbCode.Copy()
End Sub
Private Sub strPaste_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strPaste.Click
rtbCode.Paste()
End Sub
Private Sub strCut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strCut.Click
rtbCode.Cut()
End Sub
Private Sub strSelectAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strSelectAll.Click
rtbCode.SelectAll()
End Sub
Private Sub strTemplatesChild_Click(ByVal sender As Object, ByVal e As EventArgs)
Try
Dim Code
As String = IO.
File.
ReadAllText(Application.
StartupPath & "\Templates\" & DirectCast
(sender, ToolStripMenuItem
).
Text & ".hist")
rtbCode.SelectedText = Code
rtbCode.ColorVisibleLines()
Catch Ex As Exception
MessageBox.Show("Il template con questo nome è stato cancellato durante l'esecuzione del programma!", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
End Sub
Private Sub strAddTemplate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strAddTemplate.Click
Dim T As New CreateTemplateDialog
If T.ShowDialog = Windows.Forms.DialogResult.OK Then
RefreshTemplates()
End If
End Sub
End Class