Imports System
Imports System.IO


Public Class Form1

    Dim Verander As Boolean = False


    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        '"Microsoft Sans Serif, 11,25pt"
        'RTX2.Font = New Font("Microsoft Sans Serif",11,25pt)
        RTX2.Font = New Font("Microsoft Sans Serif", 11)

        FileOpen(4, MP + "Disks.Lys", OpenMode.Append) : FileClose(4)
        FileOpen(4, MP + "Disks.Lys", OpenMode.Input)
        Do While Not EOF(4)
            DiscName.Items.Add(LineInput(4))
        Loop
        FileClose(4)

        On Error Resume Next
        MkDir(dPaD)

        'Dim ii As Integer = 0


        '-----fill a combobox with the name of all known colornames ----------
        '        Dim nms() As String = Drawing.KnownColor.GetNames(GetType(Drawing.KnownColor))
        '        Dim o As String
        '        For Each o In nms
        '            Dim clr As Drawing.Color = Drawing.Color.FromName(o)
        '            If Not clr.IsSystemColor Then
        '                Dim MyCol As New Color
        '                FFcolor.Items.Item(o).forecolor = MyCol
        '                FFcolor.Items.Add(o)
        '            End If
        '        Next


        Verander = False
        Me.Show()

    End Sub

    Public Class FileHelper

        Public Shared Function GetFilesRecursive(ByVal initial As String) As List(Of String)

            ' This list stores the results.
            Dim result As New List(Of String)

            ' This stack stores the directories to process.
            Dim stack As New Stack(Of String)

            ' Add the initial directory
            stack.Push(initial)

            ' Continue processing for each stacked directory
            Form1.HuP.Text = "Searching and List FOLDERS..."
            Do While (stack.Count > 0)
                ' Get top directory string
                Dim dir As String = stack.Pop
                Try
                    ' Add all immediate file paths
                    result.AddRange(Directory.GetFiles(dir, "*.*"))

                    ' Loop through all subdirectories and add them to the stack.
                    Dim directoryName As String
                    For Each directoryName In Directory.GetDirectories(dir)
                        stack.Push(directoryName)
                        Form1.DirLys.Items.Add(directoryName)
                        Form1.DirTel.Text = Format(Form1.DirLys.Items.Count, "###,###,###")
                        My.Application.DoEvents()
                    Next

                Catch ex As Exception
                End Try
            Loop

            ' Return the list
            Return result

        End Function

    End Class

    Private Sub ACom1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ACom1.Click
        'Build
        If DiscName.Text = "" Then
            MsgBox("Please type the name of the disc to be created" + vbNewLine + "(The disc name forms part of each file)")
            Exit Sub
        End If

        DirLys.Items.Clear()
        FileLys.Items.Clear()
        RTX2.Text = ""

        iDR = Microsoft.VisualBasic.Left(Drive1.Drive, 2) + "\"
        Call Main()

        'FileOpen(4, MP + "Disks.Lys", OpenMode.Append)
        'Print(4, DiscName.Text + vbNewLine)
        'FileClose(4)
        'DiscName.Items.Add(DiscName.Text)
        'DiscName.Refresh()

        'MyMP.Text = dPaD + DiscName.Text + ".rtf" '".txt"


    End Sub

    Private Sub ACom3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ACom3.Click

        'Open
        If DiscName.Text = "" Then
            OFD.InitialDirectory = dPaD
            OFD.ShowDialog()
            Exit Sub
        End If

    End Sub

    Private Sub ACom4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ACom4.Click

        'Close viewer
        If Verander = True Then
            Dim xx = MsgBox("The document have changed. Do you want to save before leaving?", MsgBoxStyle.ApplicationModal + MsgBoxStyle.Question + MsgBoxStyle.YesNo)
            If xx = 6 Then
                RTX2.SaveFile(dPaD + DiscName.Text + ".rtf")
                Verander = False
                ViewBox.Text = "Viewer"
            End If
        End If

        If ViewBox.Visible = False Then
            ViewBox.Visible = True
        Else
            ViewBox.Visible = False
        End If

    End Sub

    Private Sub AComView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AComView.Click

        If DiscName.Text = "" Then Exit Sub Else 

        On Error GoTo FoutH1
        'If Err.Number > 0 Then
        'End If

        RTX2.LoadFile(dPaD + DiscName.Text + ".RtF")

SkipHier:
        ViewBox.Visible = True
        Verander = False

        Exit Sub

FoutH1:
        If Err.Number = 75 Then
            RTX2.Text = My.Computer.FileSystem.ReadAllText(dPaD + DiscName.Text + ".RtF")
            My.Application.DoEvents()
            GoTo SkipHier
        End If

    End Sub

    Private Sub TSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TSave.Click
        RTX2.SaveFile(dPaD + DiscName.Text + ".rtf")
        ViewBox.Text = "Viewer"
        Verander = False

        'FileOpen(2, dPaD + DiscName.Text + ".rtf", OpenMode.Output) '".txt"
        'Print(2, RTX2.Text)
        'FileClose(2)
    End Sub

    Private Sub TDate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TDate.Click
        RTX2.SelectedText = Now
    End Sub

    Private Sub RTX2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RTX2.Click
        'Call GetiFon()
    End Sub

    Private Sub RTX2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RTX2.TextChanged
        Verander = True
        ViewBox.Text = "Viewer*"
    End Sub

    Private Sub DeleteDiscToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteDiscToolStripMenuItem.Click
        'Delete disc
        Dim xx = MsgBox("Are you sure you want to DELETE the selected disc?" + vbNewLine + "(This action is irreversable!)", MsgBoxStyle.ApplicationModal + MsgBoxStyle.Exclamation + MsgBoxStyle.YesNo)
        If xx = 6 Then
            Dim z1 As String = UCase(DiscName.Text)

            Dim ii As Int64 = 0
            For ii = DiscName.Items.Count - 1 To 0 Step -1
                If UCase(DiscName.Items.Item(ii)) = z1 Then
                    DiscName.Items.Remove(DiscName.Items.Item(ii))
                    DiscName.Text = ""
                    Exit For
                End If
            Next

            FileClose()
            FileOpen(4, MP + "Disks.Lys", OpenMode.Output)
            For ii = 0 To DiscName.Items.Count - 1
                Print(4, DiscName.Items.Item(ii) + vbNewLine)
            Next
            FileClose(4)
            DiscName.Refresh()
            MsgBox("Please Note:" + vbNewLine + "The physical file still exists in the folder. The user have to remove the file self.")

        End If
    End Sub

    Private Sub AComView_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles AComView.MouseMove

        If DiscName.Text = "" Then
            TT.ToolTipTitle = "No Disc selected!"
        Else
            TT.ToolTipTitle = DiscName.Text
        End If

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

        Dim pb As Button = CType(sender, Button)
        'NewCol.BackColor = pb.BackColor

    End Sub

    Private Sub FFX_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

        'FontFormat.Visible = False

    End Sub

    Private Sub ToolStripSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripSave.Click
        RTX2.SaveFile(dPaD + DiscName.Text + ".rtf")
        Verander = False
        ViewBox.Text = "Viewer"

    End Sub

    Private Sub ToolStripCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripCopy.Click
        Clipboard.SetText(RTX2.SelectedText)
    End Sub

    Private Sub ToolStripPaste_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripPaste.Click

        Exit Sub

        'RTX2.SelectedText = Clipboard.GetData
        If My.Computer.Clipboard.ContainsAudio Then
            'Dim song As System.IO.Stream
            'song = My.Computer.Clipboard.GetAudioStream
            'My.Computer.Audio.Play(song, AudioPlayMode.WaitToComplete)
            MsgBox("Use the CTRL+V function")
        ElseIf My.Computer.Clipboard.ContainsFileDropList Then
            MsgBox("Use the CTRL+V function")
        ElseIf My.Computer.Clipboard.ContainsImage Then
            MsgBox("Use the CTRL+V function")
            'Dim grabpicture As System.Drawing.Image
            'grabpicture = My.Computer.Clipboard.GetImage()
            'imagebox.picture = grabpicture
            'picturebox1.Image = grabpicture
        ElseIf My.Computer.Clipboard.ContainsText Then
            RTX2.SelectionStart = My.Computer.Clipboard.GetText
        End If
    End Sub

    Private Sub RTX2Menu_Opening(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles RTX2Menu.Opening

    End Sub

    Private Sub ToolStripFont_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripFont.Click
        FontDialog1.ShowDialog()
        RTX2.SelectionFont = FontDialog1.Font
        'Call getifon()

    End Sub

    Private Sub RadioButton8_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton8.CheckedChanged
        'Regular
        '"Microsoft Sans Serif, 11,25pt"
        'RTX2.SelectionFont = New Font(RTX2.Font.Name, RTX2.Font.Size, FontStyle.Regular)

        RTX2.SelectionFont = New Font(RTX2.Font, FontStyle.Regular)
    End Sub

    Private Sub RadioButton7_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton7.CheckedChanged
        'Underline/Italic
        RTX2.SelectionFont = New Font(RTX2.Font, FontStyle.Underline Or FontStyle.Italic)
    End Sub

    Private Sub RadioButton6_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton6.CheckedChanged
        'bold/Underline/Italic
        RTX2.SelectionFont = New Font(RTX2.Font, FontStyle.Underline Or FontStyle.Italic Or FontStyle.Bold)
    End Sub

    Private Sub RadioButton5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton5.CheckedChanged
        'Bold/Underline
        RTX2.SelectionFont = New Font(RTX2.Font, FontStyle.Underline Or FontStyle.Bold)
    End Sub

    Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged
        'Bold/Italic
        RTX2.SelectionFont = New Font(RTX2.Font, FontStyle.Italic Or FontStyle.Bold)
    End Sub

    Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
        'Underline
        RTX2.SelectionFont = New Font(RTX2.Font, FontStyle.Underline)
    End Sub

    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
        'Italic
        RTX2.SelectionFont = New Font(RTX2.Font, FontStyle.Italic)
    End Sub

    Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
        'Bold
        RTX2.SelectionFont = New Font(RTX2.Font, FontStyle.Bold)
    End Sub

    Private Sub ToolStripColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripColor.Click
        ColorDialog1.ShowDialog()
        RTX2.SelectionColor = ColorDialog1.Color
    End Sub
End Class
