Imports Stax
Imports Stax.UI
Imports Stax.AppFramework

Public Class SourceFilesForm
    Inherits ExtendedForm

#Region " Vom Windows Form Designer generierter 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

    ' Für Windows Form-Designer erforderlich
    Private components As System.ComponentModel.IContainer

    'HINWEIS: Die folgende Prozedur ist für den Windows Form-Designer erforderlich
    'Sie kann mit dem Windows Form-Designer modifiziert werden.
    'Verwenden Sie nicht den Code-Editor zur Bearbeitung.
    Friend WithEvents lbFiles As ListBox
    Friend WithEvents bOK As System.Windows.Forms.Button
    Friend WithEvents bDown As System.Windows.Forms.Button
    Friend WithEvents bUp As System.Windows.Forms.Button
    Friend WithEvents bRemove As System.Windows.Forms.Button
    Friend WithEvents bAdd As System.Windows.Forms.Button
    Friend WithEvents SmartTagProvider As Stax.UI.Design.SmartTagProvider
    Friend WithEvents bHelp As System.Windows.Forms.Button
    Friend WithEvents TipProvider As Stax.UI.TipProvider
    Friend WithEvents bCancel As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Me.bOK = New System.Windows.Forms.Button
        Me.lbFiles = New System.Windows.Forms.ListBox
        Me.bCancel = New System.Windows.Forms.Button
        Me.bDown = New System.Windows.Forms.Button
        Me.bUp = New System.Windows.Forms.Button
        Me.bRemove = New System.Windows.Forms.Button
        Me.bAdd = New System.Windows.Forms.Button
        Me.SmartTagProvider = New Stax.UI.Design.SmartTagProvider
        Me.bHelp = New System.Windows.Forms.Button
        Me.TipProvider = New Stax.UI.TipProvider(Me.components)
        CType(Me.TipProvider, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'bOK
        '
        Me.bOK.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.bOK.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.bOK.Enabled = False
        Me.bOK.Location = New System.Drawing.Point(403, 162)
        Me.bOK.Name = "bOK"
        Me.bOK.Size = New System.Drawing.Size(75, 24)
        Me.bOK.TabIndex = 4
        Me.bOK.Text = "OK"
        '
        'lbFiles
        '
        Me.lbFiles.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.lbFiles.FormattingEnabled = True
        Me.lbFiles.IntegralHeight = False
        Me.lbFiles.Location = New System.Drawing.Point(13, 13)
        Me.lbFiles.Name = "lbFiles"
        Me.lbFiles.Size = New System.Drawing.Size(384, 203)
        Me.lbFiles.TabIndex = 5
        '
        'bCancel
        '
        Me.bCancel.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.bCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.bCancel.Location = New System.Drawing.Point(403, 192)
        Me.bCancel.Name = "bCancel"
        Me.bCancel.Size = New System.Drawing.Size(75, 24)
        Me.bCancel.TabIndex = 7
        Me.bCancel.Text = "Cancel"
        '
        'bDown
        '
        Me.bDown.Image = Global.StaxRip.My.Resources.Resources.Down16
        Me.bDown.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.bDown.Location = New System.Drawing.Point(403, 102)
        Me.bDown.Name = "bDown"
        Me.bDown.Size = New System.Drawing.Size(75, 24)
        Me.bDown.TabIndex = 14
        Me.bDown.Text = "Down"
        '
        'bUp
        '
        Me.bUp.Image = Global.StaxRip.My.Resources.Resources.Up16
        Me.bUp.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.bUp.Location = New System.Drawing.Point(403, 72)
        Me.bUp.Name = "bUp"
        Me.bUp.Size = New System.Drawing.Size(75, 24)
        Me.bUp.TabIndex = 13
        Me.bUp.Text = "Up"
        '
        'bRemove
        '
        Me.bRemove.Image = Global.StaxRip.My.Resources.Resources.Minus16
        Me.bRemove.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.bRemove.Location = New System.Drawing.Point(403, 42)
        Me.bRemove.Name = "bRemove"
        Me.bRemove.Size = New System.Drawing.Size(75, 24)
        Me.bRemove.TabIndex = 12
        Me.bRemove.Text = "Remove"
        Me.bRemove.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText
        '
        'bAdd
        '
        Me.bAdd.Image = Global.StaxRip.My.Resources.Resources.Plus16
        Me.bAdd.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.bAdd.Location = New System.Drawing.Point(403, 12)
        Me.bAdd.Name = "bAdd"
        Me.bAdd.Size = New System.Drawing.Size(75, 24)
        Me.bAdd.TabIndex = 11
        Me.bAdd.Text = "Add..."
        Me.TipProvider.SetTipText(Me.bAdd, "Opens a Open File dialog that supports multi-select in order to open source files" & _
                ". Alternative methods to open source files are **Drag & Drop** and **command lin" & _
                "e**.")
        '
        'bHelp
        '
        Me.bHelp.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.bHelp.Location = New System.Drawing.Point(403, 132)
        Me.bHelp.Name = "bHelp"
        Me.bHelp.Size = New System.Drawing.Size(75, 24)
        Me.bHelp.TabIndex = 15
        Me.bHelp.Text = "Help"
        Me.bHelp.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText
        Me.bHelp.UseVisualStyleBackColor = True
        '
        'SourceFilesForm
        '
        Me.AcceptButton = Me.bOK
        Me.CancelButton = Me.bCancel
        Me.ClientSize = New System.Drawing.Size(490, 229)
        Me.Controls.Add(Me.bHelp)
        Me.Controls.Add(Me.bDown)
        Me.Controls.Add(Me.bUp)
        Me.Controls.Add(Me.bRemove)
        Me.Controls.Add(Me.bAdd)
        Me.Controls.Add(Me.bCancel)
        Me.Controls.Add(Me.lbFiles)
        Me.Controls.Add(Me.bOK)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "SourceFilesForm"
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
        Me.Text = "Source Files"
        CType(Me.TipProvider, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Public Sub New(ByVal files As List(Of String))
        MyBase.New()
        InitializeComponent()
        UpdateControls()
        lbFiles.Items.AddRange(files.ToArray)
    End Sub

    Private Sub lbFiles_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles lbFiles.SelectedIndexChanged
        UpdateControls()
    End Sub

    Private Sub UpdateControls()
        ActiveControl = bOK
        bRemove.Enabled = lbFiles.SelectedIndex > -1
        bOK.Enabled = lbFiles.Items.Count > 0
        bUp.Enabled = ListBoxHelp.CanMoveUp(lbFiles)
        bDown.Enabled = ListBoxHelp.CanMoveDown(lbFiles)
    End Sub

    Private Sub bAdd_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bAdd.Click
        Dim d As New OpenFileDialog
        d.Multiselect = True
        d.Filter = FileDialogFilter.GetVideo()
        d.InitialDirectory = s.LastSourceDir

        If d.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Dim files As String() = d.FileNames
            Array.Sort(files)
            lbFiles.Items.AddRange(files)
            UpdateControls()
        End If

        d.Dispose()
    End Sub

    Private Sub bRemove_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bRemove.Click
        ListBoxHelp.RemoveSelection(lbFiles)
        UpdateControls()
    End Sub

    Private Sub bUp_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bUp.Click
        ListBoxHelp.MoveSelectionUp(lbFiles)
        UpdateControls()
    End Sub

    Private Sub bDown_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bDown.Click
        ListBoxHelp.MoveSelectionDown(lbFiles)
        UpdateControls()
    End Sub

    Private Sub SourceFilesForm_ActivatedFirstTime() Handles Me.ActivatedFirstTime
        If Not s.StringList.Contains(Me.GetType.FullName) Then
            bHelp.PerformClick()
            s.StringList.Add(Me.GetType.FullName)
        End If
    End Sub

    Private Sub bHelp_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bHelp.Click
        Dim f As New HelpForm()
        f.Document.WriteStart(Text)
        f.Document.WriteParagraph("The Source Files dialog allows to open source files.")
        f.Document.WriteTips(TipProvider.GetTips)
        f.Show()
    End Sub
End Class