Imports Stax.UI

Public Class FilterSelectionForm
    Inherits ExtendedForm

#Region " Windows Form Designer generated code "
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents tv As ExtendedTreeView
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.tv = New Stax.UI.ExtendedTreeView
        Me.SuspendLayout()
        '
        'tv
        '
        Me.tv.AutoCollaps = True
        Me.tv.AutoExpand = True
        Me.tv.Dock = System.Windows.Forms.DockStyle.Fill
        Me.tv.Location = New System.Drawing.Point(0, 0)
        Me.tv.Name = "tv"
        Me.tv.Scrollable = False
        Me.tv.Size = New System.Drawing.Size(292, 346)
        Me.tv.TabIndex = 0
        '
        'FilterSelectionForm
        '
        Me.ClientSize = New System.Drawing.Size(292, 346)
        Me.Controls.Add(Me.tv)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow
        Me.KeyPreview = True
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "FilterSelectionForm"
        Me.ShowIcon = False
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
        Me.Text = "Filter Selection"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Public Sub New()
        MyBase.New()
        InitializeComponent()

        For Each i As AviSynthCategory In s.AviSynthCategories
            Dim catNode As New TreeNode
            catNode.Text = i.Name
            tv.Nodes.Add(catNode)

            For Each iFilter As AviSynthFilter In i.Filters
                Dim filterNode As New TreeNode
                filterNode.Text = iFilter.Name
                filterNode.Tag = iFilter
                catNode.Nodes.Add(filterNode)
            Next
        Next

        s.WindowPositions.Restore(Me, WindowPositions.Mode.ClientSize)
    End Sub

    Private Sub FilterSelectionForm_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) Handles Me.FormClosing
        s.WindowPositions.Save(Me, WindowPositions.Mode.ClientSize)
    End Sub

    Private Sub AviSynthFilterSelectionForm_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles MyBase.KeyDown
        If e.KeyCode = Keys.Escape Then
            Close()
        ElseIf e.KeyCode = Keys.Enter Then
            If Not tv.SelectedNode.Parent Is Nothing Then
                Filter = CType(tv.SelectedNode.Tag, AviSynthFilter)
                Close()
            End If
        End If
    End Sub

    Private FilterValue As AviSynthFilter

    Public Property Filter() As AviSynthFilter
        Get
            Return FilterValue
        End Get
        Set(ByVal Value As AviSynthFilter)
            FilterValue = Value
        End Set
    End Property

    Private Sub tv_NodeMouseClick(ByVal sender As Object, ByVal e As TreeNodeMouseClickEventArgs) Handles tv.NodeMouseClick
        If Not e.Node.Parent Is Nothing Then
            Filter = CType(e.Node.Tag, AviSynthFilter)
            Close()
        End If
    End Sub
End Class