Imports BaiqiSoft.HtmlEditorControl

Public Class frmLinkStyleSheet

    Private Sub frmLinkStyleSheet_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        lstURL.Items.Clear()
        For Each stylesheet As StyleSheetLink In frmMain.HtmlEditor1.StyleSheetLinks
            lstURL.Items.Add(stylesheet.href)
        Next
        If lstURL.Items.Count > 0 Then
            btnRemove.Enabled = True
            btnEdit.Enabled = True
        Else
            btnRemove.Enabled = False
            btnEdit.Enabled = False
        End If
    End Sub

    Private Sub btnAdd_Click(sender As System.Object, e As System.EventArgs) Handles btnAdd.Click
        frmSelectFile.txtURL.Text = ""
        frmSelectFile.ShowDialog()
        If m_returnValue.Length > 0 Then
            lstURL.Items.Add(m_returnValue)
        End If
        If lstURL.Items.Count > 0 Then
            btnRemove.Enabled = True
            btnEdit.Enabled = True
        End If
    End Sub

    Private Sub btnRemove_Click(sender As System.Object, e As System.EventArgs) Handles btnRemove.Click
        If lstURL.SelectedItem Is Nothing Then Return
        lstURL.Items.Remove(lstURL.SelectedItem)
        If lstURL.Items.Count = 0 Then
            btnRemove.Enabled = False
            btnEdit.Enabled = False
        End If
    End Sub

    Private Sub btnEdit_Click(sender As System.Object, e As System.EventArgs) Handles btnEdit.Click
        If lstURL.SelectedItem Is Nothing Then Return
        frmSelectFile.txtURL.Text = lstURL.SelectedItem
        frmSelectFile.ShowDialog()
        If m_returnValue.Length > 0 Then
            lstURL.Items(lstURL.SelectedIndex) = m_returnValue
        End If
    End Sub

    Private Sub btnCancel_Click(sender As System.Object, e As System.EventArgs) Handles btnCancel.Click
        Me.Close()
    End Sub

    Private Sub btnOK_Click(sender As System.Object, e As System.EventArgs) Handles btnOK.Click
        frmMain.HtmlEditor1.StyleSheetLinks.Clear()
        For Each item As String In lstURL.Items
            frmMain.HtmlEditor1.StyleSheetLinks.Add(item)
        Next
        Me.Close()
    End Sub
End Class