Imports Stax.UI
Imports Stax.AppFramework

Public Class OptionsForm
    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 bCancel As System.Windows.Forms.Button
    Friend WithEvents bOK As System.Windows.Forms.Button
    Friend WithEvents bHelp As System.Windows.Forms.Button
    Friend WithEvents UserControlProxy As Stax.UI.ProxyControlContainer
    Friend WithEvents ToolStrip As Stax.UI.ExtendedToolStrip
    Friend WithEvents SmartTagProvider As Stax.UI.Design.SmartTagProvider
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.bCancel = New System.Windows.Forms.Button
        Me.bOK = New System.Windows.Forms.Button
        Me.SmartTagProvider = New Stax.UI.Design.SmartTagProvider
        Me.bHelp = New System.Windows.Forms.Button
        Me.UserControlProxy = New Stax.UI.ProxyControlContainer
        Me.ToolStrip = New Stax.UI.ExtendedToolStrip
        Me.SuspendLayout()
        '
        'bCancel
        '
        Me.bCancel.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom 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(306, 292)
        Me.bCancel.Name = "bCancel"
        Me.bCancel.Size = New System.Drawing.Size(75, 24)
        Me.bCancel.TabIndex = 3
        Me.bCancel.Text = "Cancel"
        '
        'bOK
        '
        Me.bOK.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.bOK.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.bOK.Location = New System.Drawing.Point(225, 292)
        Me.bOK.Name = "bOK"
        Me.bOK.Size = New System.Drawing.Size(75, 24)
        Me.bOK.TabIndex = 2
        Me.bOK.Text = "OK"
        '
        'bHelp
        '
        Me.bHelp.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.bHelp.Location = New System.Drawing.Point(387, 292)
        Me.bHelp.Name = "bHelp"
        Me.bHelp.Size = New System.Drawing.Size(75, 24)
        Me.bHelp.TabIndex = 5
        Me.bHelp.Text = "Help"
        Me.bHelp.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText
        '
        'UserControlProxy
        '
        Me.UserControlProxy.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.UserControlProxy.Location = New System.Drawing.Point(107, 9)
        Me.UserControlProxy.Name = "UserControlProxy"
        Me.UserControlProxy.Size = New System.Drawing.Size(355, 280)
        Me.UserControlProxy.TabIndex = 7
        '
        'ToolStrip
        '
        Me.ToolStrip.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.ToolStrip.AutoSize = False
        Me.ToolStrip.BackColor = System.Drawing.SystemColors.Window
        Me.ToolStrip.Dock = System.Windows.Forms.DockStyle.None
        Me.ToolStrip.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ToolStrip.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden
        Me.ToolStrip.ImageScalingSize = New System.Drawing.Size(22, 22)
        Me.ToolStrip.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.VerticalStackWithOverflow
        Me.ToolStrip.Location = New System.Drawing.Point(9, 9)
        Me.ToolStrip.Name = "ToolStrip"
        Me.ToolStrip.OverdrawLine = True
        Me.ToolStrip.Padding = New System.Windows.Forms.Padding(2, 1, 1, 1)
        Me.ToolStrip.RenderMode = System.Windows.Forms.ToolStripRenderMode.System
        Me.ToolStrip.ShowControlBorder = True
        Me.ToolStrip.ShowItemToolTips = False
        Me.ToolStrip.SingleAutoChecked = True
        Me.ToolStrip.Size = New System.Drawing.Size(94, 278)
        Me.ToolStrip.TabIndex = 6
        '
        'OptionsForm
        '
        Me.ClientSize = New System.Drawing.Size(474, 328)
        Me.Controls.Add(Me.UserControlProxy)
        Me.Controls.Add(Me.ToolStrip)
        Me.Controls.Add(Me.bHelp)
        Me.Controls.Add(Me.bCancel)
        Me.Controls.Add(Me.bOK)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.HelpButton = True
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "OptionsForm"
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
        Me.Text = "Project Options"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Types As New Dictionary(Of ToolStripItem, Type)
    Private RecentControl As String = "RecentSettíngsControl"

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

        'AddButton("Basic", GetType(OptionsBasicControl), My.Resources.Screwdriver22)
        AddButton("Automation", GetType(OptionsAutomationControl), My.Resources.CogwheelGrey22)
        AddButton("Preparation", GetType(OptionsPreperationControl), My.Resources.Checklist22)
        AddButton("Advanced", GetType(OptionsAdvancedControl), My.Resources.Config22)

        Dim index As Integer = s.Storage.GetInt("OptionsFormControlIndex", 0)
        If index >= ToolStrip.Items.Count Then index = 0
        ToolStrip.Items(index).PerformClick()
    End Sub

    Private Sub AddButton(ByVal text As String, ByVal t As Type, ByVal image As Image)
        Dim b As New ToolStripButton()

        b.Text = text
        b.Image = image
        b.TextImageRelation = TextImageRelation.ImageAboveText
        b.Padding = New Padding(2)

        ToolStrip.Items.Add(b)
        Types(b) = t
    End Sub

    Private Sub OptionsForm_ActivatedFirstTime() Handles MyBase.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("Options Dialog")
        f.Document.WriteParagraph("All options in the Options Dialog are stored in [[projects.htm|projects]]. In order to use changes as defaults available on startup overwrite the default project. In the main dialog's main menu select **File/Default Project/Save**.")
        f.Show()
    End Sub

    Private Sub ToolStrip_ItemClicked(ByVal sender As Object, ByVal e As ToolStripItemClickedEventArgs) Handles ToolStrip.ItemClicked
        UserControlProxy.ShowControl(Types(e.ClickedItem), True).Text = e.ClickedItem.Text
        s.Storage.SetValue("OptionsFormControlIndex", ToolStrip.Items.IndexOf(e.ClickedItem))
    End Sub
End Class